Fix saving time mode state, delete save after loading
This commit is contained in:
parent
8a103f9533
commit
6ab176cbc3
3 changed files with 8 additions and 5 deletions
Binary file not shown.
|
@ -123,17 +123,18 @@ public class TimeScorer extends BaseScorer implements BinSerializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutputStream out) throws IOException {
|
public void write(DataOutputStream out) throws IOException {
|
||||||
// startTime, highScoreTime, deadTime
|
// current/dead offset ("how long until we die"), highScoreTime
|
||||||
out.writeLong(startTime);
|
out.writeLong(TimeUtils.nanoTime() - startTime);
|
||||||
out.writeInt(highScoreTime);
|
out.writeInt(highScoreTime);
|
||||||
out.writeLong(deadTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInputStream in) throws IOException {
|
public void read(DataInputStream in) throws IOException {
|
||||||
startTime = in.readLong();
|
// We need to use the offset, since the start time
|
||||||
|
// is different and we couldn't save absolute values
|
||||||
|
long deadOffset = in.readLong();
|
||||||
|
deadTime = startTime + deadOffset;
|
||||||
highScoreTime = in.readInt();
|
highScoreTime = in.readInt();
|
||||||
deadTime = in.readLong();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
|
@ -278,6 +278,8 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
||||||
if (handle.exists()) {
|
if (handle.exists()) {
|
||||||
try {
|
try {
|
||||||
BinSerializer.deserialize(this, handle.read());
|
BinSerializer.deserialize(this, handle.read());
|
||||||
|
// After it's been loaded, delete the save file
|
||||||
|
deleteSave();
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException ignored) { }
|
} catch (IOException ignored) { }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue