Implemented save time recording
This commit is contained in:
@@ -21,7 +21,7 @@ public class CraftingBlocks extends BlockList implements ContentList{
|
||||
health = 70;
|
||||
result = Items.carbide;
|
||||
craftTime = 45f;
|
||||
burnDuration = 46f;
|
||||
burnDuration = 45f;
|
||||
useFlux = true;
|
||||
|
||||
consumes.items(new ItemStack[]{new ItemStack(Items.tungsten, 3)});
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.anuke.mindustry.game.Difficulty;
|
||||
import io.anuke.mindustry.game.EventType.StateChangeEvent;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.mindustry.game.TeamInfo;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.core.Events;
|
||||
|
||||
public class GameState{
|
||||
@@ -23,6 +24,10 @@ public class GameState{
|
||||
state = astate;
|
||||
}
|
||||
|
||||
public boolean isPaused(){
|
||||
return is(State.paused) && !Net.active();
|
||||
}
|
||||
|
||||
public boolean is(State astate){
|
||||
return state == astate;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
public void draw(){
|
||||
if((debug && (!showPlayer || !showUI)) || dead) return;
|
||||
|
||||
if(!movement.isZero() && moved){
|
||||
if(!movement.isZero() && moved && !state.isPaused()){
|
||||
walktime += Timers.delta() * movement.len() / 0.7f * getFloorOn().speedMultiplier;
|
||||
baseRotation = Mathf.slerpDelta(baseRotation, movement.angle(), 0.13f);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.game;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.game.EventType.StateChangeEvent;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
@@ -10,6 +11,7 @@ import io.anuke.mindustry.maps.Map;
|
||||
import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
import io.anuke.ucore.util.ThreadArray;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -23,6 +25,9 @@ public class Saves{
|
||||
private boolean saving;
|
||||
private float time;
|
||||
|
||||
private long totalPlaytime;
|
||||
private long lastTimestamp;
|
||||
|
||||
public Saves(){
|
||||
Events.on(StateChangeEvent.class, (prev, state) -> {
|
||||
if(state == State.menu){
|
||||
@@ -35,8 +40,7 @@ public class Saves{
|
||||
saves.clear();
|
||||
int[] slots = Settings.getJson("save-slots", int[].class);
|
||||
|
||||
for(int i = 0; i < slots.length; i++){
|
||||
int index = slots[i];
|
||||
for(int index : slots){
|
||||
if(SaveIO.isSaveValid(index)){
|
||||
SaveSlot slot = new SaveSlot(index);
|
||||
saves.add(slot);
|
||||
@@ -53,6 +57,14 @@ public class Saves{
|
||||
public void update(){
|
||||
SaveSlot current = this.current;
|
||||
|
||||
if(current != null && !state.is(State.menu)
|
||||
&& !(state.isPaused() && ui.hasDialog())){
|
||||
if(lastTimestamp != 0){
|
||||
totalPlaytime += TimeUtils.timeSinceMillis(lastTimestamp);
|
||||
}
|
||||
lastTimestamp = TimeUtils.millis();
|
||||
}
|
||||
|
||||
if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave()){
|
||||
time += Timers.delta();
|
||||
if(time > Settings.getInt("saveinterval") * 60){
|
||||
@@ -75,6 +87,10 @@ public class Saves{
|
||||
}
|
||||
}
|
||||
|
||||
public long getTotalPlaytime(){
|
||||
return totalPlaytime;
|
||||
}
|
||||
|
||||
public void resetSave(){
|
||||
current = null;
|
||||
}
|
||||
@@ -132,6 +148,7 @@ public class Saves{
|
||||
SaveIO.loadFromSlot(index);
|
||||
meta = SaveIO.getData(index);
|
||||
current = this;
|
||||
totalPlaytime = meta.timePlayed;
|
||||
}
|
||||
|
||||
public void save(){
|
||||
@@ -140,6 +157,10 @@ public class Saves{
|
||||
current = this;
|
||||
}
|
||||
|
||||
public String getPlayTime(){
|
||||
return Strings.formatMillis(current == this ? totalPlaytime : meta.timePlayed);
|
||||
}
|
||||
|
||||
public String getDate(){
|
||||
return meta.date;
|
||||
}
|
||||
|
||||
@@ -15,12 +15,13 @@ public abstract class SaveFileVersion{
|
||||
|
||||
public SaveMeta getData(DataInputStream stream) throws IOException{
|
||||
long time = stream.readLong(); //read last saved time
|
||||
long playtime = stream.readLong();
|
||||
int build = stream.readInt();
|
||||
byte mode = stream.readByte(); //read the gamemode
|
||||
String map = stream.readUTF(); //read the map
|
||||
int wave = stream.readInt(); //read the wave
|
||||
byte difficulty = stream.readByte(); //read the difficulty
|
||||
return new SaveMeta(version, time, build, mode, map, wave, Difficulty.values()[difficulty]);
|
||||
return new SaveMeta(version, time, playtime, build, mode, map, wave, Difficulty.values()[difficulty]);
|
||||
}
|
||||
|
||||
public abstract void read(DataInputStream stream) throws IOException;
|
||||
|
||||
@@ -13,15 +13,17 @@ public class SaveMeta{
|
||||
public int version;
|
||||
public int build;
|
||||
public String date;
|
||||
public long timePlayed;
|
||||
public GameMode mode;
|
||||
public Map map;
|
||||
public int wave;
|
||||
public Difficulty difficulty;
|
||||
|
||||
public SaveMeta(int version, long date, int build, int mode, String map, int wave, Difficulty difficulty){
|
||||
public SaveMeta(int version, long date, long timePlayed, int build, int mode, String map, int wave, Difficulty difficulty){
|
||||
this.version = version;
|
||||
this.build = build;
|
||||
this.date = Platform.instance.format(new Date(date));
|
||||
this.timePlayed = timePlayed;
|
||||
this.mode = GameMode.values()[mode];
|
||||
this.map = world.maps().getByName(map);
|
||||
this.wave = wave;
|
||||
|
||||
@@ -25,8 +25,7 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Save16 extends SaveFileVersion{
|
||||
|
||||
@@ -37,6 +36,7 @@ public class Save16 extends SaveFileVersion{
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
stream.readLong(); //time
|
||||
stream.readLong(); //total playtime
|
||||
stream.readInt(); //build
|
||||
|
||||
//general state
|
||||
@@ -154,6 +154,7 @@ public class Save16 extends SaveFileVersion{
|
||||
//--META--
|
||||
stream.writeInt(version); //version id
|
||||
stream.writeLong(TimeUtils.millis()); //last saved
|
||||
stream.writeLong(headless ? 0 : control.getSaves().getTotalPlaytime()); //playtime
|
||||
stream.writeInt(Version.build); //build
|
||||
|
||||
//--GENERAL STATE--
|
||||
|
||||
@@ -124,6 +124,8 @@ public class LoadDialog extends FloatingDialog{
|
||||
button.row();
|
||||
button.label(() -> Bundles.format("text.save.autosave", color + Bundles.get(slot.isAutosave() ? "text.on" : "text.off")));
|
||||
button.row();
|
||||
button.label(() -> Bundles.format("text.save.playtime", color + slot.getPlayTime()));
|
||||
button.row();
|
||||
button.add(Bundles.format("text.save.date", color + slot.getDate())).colspan(2).padTop(5).right();
|
||||
button.row();
|
||||
modifyButton(button, slot);
|
||||
|
||||
Reference in New Issue
Block a user