Implemented save time recording

This commit is contained in:
Anuken
2018-07-17 10:42:44 -04:00
parent d7812ec030
commit c2c2551607
10 changed files with 42 additions and 9 deletions

View File

@@ -27,7 +27,7 @@ allprojects {
gdxVersion = '1.9.8' gdxVersion = '1.9.8'
roboVMVersion = '2.3.0' roboVMVersion = '2.3.0'
aiVersion = '1.8.1' aiVersion = '1.8.1'
uCoreVersion = '27f83f3522e30c8f58e9fa4fe4764d5cd03195c7' uCoreVersion = 'e4eec58b02'
getVersionString = { getVersionString = {
String buildVersion = getBuildVersion() String buildVersion = getBuildVersion()

View File

@@ -156,6 +156,7 @@ text.save.map=Map: {0}
text.save.wave=Wave {0} text.save.wave=Wave {0}
text.save.difficulty=Difficulty: {0} text.save.difficulty=Difficulty: {0}
text.save.date=Last Saved: {0} text.save.date=Last Saved: {0}
text.save.playtime=Playtime: {0}
text.confirm=Confirm text.confirm=Confirm
text.delete=Delete text.delete=Delete
text.ok=OK text.ok=OK

View File

@@ -21,7 +21,7 @@ public class CraftingBlocks extends BlockList implements ContentList{
health = 70; health = 70;
result = Items.carbide; result = Items.carbide;
craftTime = 45f; craftTime = 45f;
burnDuration = 46f; burnDuration = 45f;
useFlux = true; useFlux = true;
consumes.items(new ItemStack[]{new ItemStack(Items.tungsten, 3)}); consumes.items(new ItemStack[]{new ItemStack(Items.tungsten, 3)});

View File

@@ -5,6 +5,7 @@ import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.EventType.StateChangeEvent; import io.anuke.mindustry.game.EventType.StateChangeEvent;
import io.anuke.mindustry.game.GameMode; import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.game.TeamInfo; import io.anuke.mindustry.game.TeamInfo;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Events;
public class GameState{ public class GameState{
@@ -23,6 +24,10 @@ public class GameState{
state = astate; state = astate;
} }
public boolean isPaused(){
return is(State.paused) && !Net.active();
}
public boolean is(State astate){ public boolean is(State astate){
return state == astate; return state == astate;
} }

View File

@@ -283,7 +283,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
public void draw(){ public void draw(){
if((debug && (!showPlayer || !showUI)) || dead) return; 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; walktime += Timers.delta() * movement.len() / 0.7f * getFloorOn().speedMultiplier;
baseRotation = Mathf.slerpDelta(baseRotation, movement.angle(), 0.13f); baseRotation = Mathf.slerpDelta(baseRotation, movement.angle(), 0.13f);
} }

View File

@@ -2,6 +2,7 @@ package io.anuke.mindustry.game;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.game.EventType.StateChangeEvent; import io.anuke.mindustry.game.EventType.StateChangeEvent;
import io.anuke.mindustry.io.SaveIO; 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.Events;
import io.anuke.ucore.core.Settings; import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Strings;
import io.anuke.ucore.util.ThreadArray; import io.anuke.ucore.util.ThreadArray;
import java.io.IOException; import java.io.IOException;
@@ -23,6 +25,9 @@ public class Saves{
private boolean saving; private boolean saving;
private float time; private float time;
private long totalPlaytime;
private long lastTimestamp;
public Saves(){ public Saves(){
Events.on(StateChangeEvent.class, (prev, state) -> { Events.on(StateChangeEvent.class, (prev, state) -> {
if(state == State.menu){ if(state == State.menu){
@@ -35,8 +40,7 @@ public class Saves{
saves.clear(); saves.clear();
int[] slots = Settings.getJson("save-slots", int[].class); int[] slots = Settings.getJson("save-slots", int[].class);
for(int i = 0; i < slots.length; i++){ for(int index : slots){
int index = slots[i];
if(SaveIO.isSaveValid(index)){ if(SaveIO.isSaveValid(index)){
SaveSlot slot = new SaveSlot(index); SaveSlot slot = new SaveSlot(index);
saves.add(slot); saves.add(slot);
@@ -53,6 +57,14 @@ public class Saves{
public void update(){ public void update(){
SaveSlot current = this.current; 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()){ if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave()){
time += Timers.delta(); time += Timers.delta();
if(time > Settings.getInt("saveinterval") * 60){ if(time > Settings.getInt("saveinterval") * 60){
@@ -75,6 +87,10 @@ public class Saves{
} }
} }
public long getTotalPlaytime(){
return totalPlaytime;
}
public void resetSave(){ public void resetSave(){
current = null; current = null;
} }
@@ -132,6 +148,7 @@ public class Saves{
SaveIO.loadFromSlot(index); SaveIO.loadFromSlot(index);
meta = SaveIO.getData(index); meta = SaveIO.getData(index);
current = this; current = this;
totalPlaytime = meta.timePlayed;
} }
public void save(){ public void save(){
@@ -140,6 +157,10 @@ public class Saves{
current = this; current = this;
} }
public String getPlayTime(){
return Strings.formatMillis(current == this ? totalPlaytime : meta.timePlayed);
}
public String getDate(){ public String getDate(){
return meta.date; return meta.date;
} }

View File

@@ -15,12 +15,13 @@ public abstract class SaveFileVersion{
public SaveMeta getData(DataInputStream stream) throws IOException{ public SaveMeta getData(DataInputStream stream) throws IOException{
long time = stream.readLong(); //read last saved time long time = stream.readLong(); //read last saved time
long playtime = stream.readLong();
int build = stream.readInt(); int build = stream.readInt();
byte mode = stream.readByte(); //read the gamemode byte mode = stream.readByte(); //read the gamemode
String map = stream.readUTF(); //read the map String map = stream.readUTF(); //read the map
int wave = stream.readInt(); //read the wave int wave = stream.readInt(); //read the wave
byte difficulty = stream.readByte(); //read the difficulty 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; public abstract void read(DataInputStream stream) throws IOException;

View File

@@ -13,15 +13,17 @@ public class SaveMeta{
public int version; public int version;
public int build; public int build;
public String date; public String date;
public long timePlayed;
public GameMode mode; public GameMode mode;
public Map map; public Map map;
public int wave; public int wave;
public Difficulty difficulty; 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.version = version;
this.build = build; this.build = build;
this.date = Platform.instance.format(new Date(date)); this.date = Platform.instance.format(new Date(date));
this.timePlayed = timePlayed;
this.mode = GameMode.values()[mode]; this.mode = GameMode.values()[mode];
this.map = world.maps().getByName(map); this.map = world.maps().getByName(map);
this.wave = wave; this.wave = wave;

View File

@@ -25,8 +25,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import static io.anuke.mindustry.Vars.state; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.world;
public class Save16 extends SaveFileVersion{ public class Save16 extends SaveFileVersion{
@@ -37,6 +36,7 @@ public class Save16 extends SaveFileVersion{
@Override @Override
public void read(DataInputStream stream) throws IOException{ public void read(DataInputStream stream) throws IOException{
stream.readLong(); //time stream.readLong(); //time
stream.readLong(); //total playtime
stream.readInt(); //build stream.readInt(); //build
//general state //general state
@@ -154,6 +154,7 @@ public class Save16 extends SaveFileVersion{
//--META-- //--META--
stream.writeInt(version); //version id stream.writeInt(version); //version id
stream.writeLong(TimeUtils.millis()); //last saved stream.writeLong(TimeUtils.millis()); //last saved
stream.writeLong(headless ? 0 : control.getSaves().getTotalPlaytime()); //playtime
stream.writeInt(Version.build); //build stream.writeInt(Version.build); //build
//--GENERAL STATE-- //--GENERAL STATE--

View File

@@ -124,6 +124,8 @@ public class LoadDialog extends FloatingDialog{
button.row(); button.row();
button.label(() -> Bundles.format("text.save.autosave", color + Bundles.get(slot.isAutosave() ? "text.on" : "text.off"))); button.label(() -> Bundles.format("text.save.autosave", color + Bundles.get(slot.isAutosave() ? "text.on" : "text.off")));
button.row(); 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.add(Bundles.format("text.save.date", color + slot.getDate())).colspan(2).padTop(5).right();
button.row(); button.row();
modifyButton(button, slot); modifyButton(button, slot);