mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 21:44:05 +09:00
added snapshot to versioning scheme
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum.savegame
|
||||
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.Snapshot
|
||||
import net.torvald.terrarum.serialise.toUint
|
||||
import net.torvald.terrarum.serialise.toUlong
|
||||
import java.io.*
|
||||
@@ -389,6 +390,16 @@ removefile:
|
||||
fa.close()
|
||||
}
|
||||
|
||||
fun setSaveSnapshotVersion(snapshot: Snapshot?) {
|
||||
val fa = RandomAccessFile(diskFile, "rwd")
|
||||
fa.seek(51L)
|
||||
if (snapshot == null)
|
||||
fa.write(byteArrayOf(0, 0))
|
||||
else
|
||||
fa.write(snapshot.toBytes())
|
||||
fa.close()
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Save type (0b 0000 00ab)
|
||||
* b: unset - full save; set - quicksave (only applicable to worlds -- quicksave just means the disk is in dirty state)
|
||||
@@ -418,6 +429,17 @@ removefile:
|
||||
return fa.read().also { fa.close() }
|
||||
}
|
||||
|
||||
fun getSaveSnapshotVersion(): Snapshot? {
|
||||
val fa = RandomAccessFile(diskFile, "rwd")
|
||||
fa.seek(52L)
|
||||
|
||||
val b1 = fa.read().toByte()
|
||||
val b2 = fa.read().toByte().also { fa.close() }
|
||||
|
||||
return if (b1 == b2 && b1 == 0.toByte()) null
|
||||
else Snapshot(byteArrayOf(b1, b2))
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun getDiskName(charset: Charset): String {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum.savegame
|
||||
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.Snapshot
|
||||
import net.torvald.terrarum.savegame.VDSaveKind.PLAYER_DATA
|
||||
import net.torvald.terrarum.savegame.VDSaveKind.WORLD_DATA
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
@@ -79,7 +80,15 @@ Version 254 is a customised version of TEVD tailored to be used as a savegame fo
|
||||
Int8 Savefile Origin Flags (lower nybble: persistent, upper nybble: can be removed if conditions are met)
|
||||
0: Created in-game
|
||||
16: Imported (will be removed once the file is loaded by the player and saved in-game)
|
||||
Int8[12] Extra info bytes reserved for future usage
|
||||
Int16 Snapshot Number
|
||||
0b A_yyyyyyy wwwwww_aa
|
||||
where:
|
||||
y: Current Year - 2000 (2023 -> 23)
|
||||
w: ISO Week Number (1-53)
|
||||
Aaa: Alphabet (a->000, b->001, ... e->100, f->101, ..., h->111)
|
||||
e.g. 23w40f is encoded as 1_0010111 101000_01
|
||||
Int8[10] Extra info bytes reserved for future usage
|
||||
|
||||
-- END extraInfoBytes --
|
||||
UInt8[236] Rest of the long disk name (268 bytes total)
|
||||
|
||||
@@ -156,6 +165,25 @@ class VirtualDisk(
|
||||
var saveOrigin: Int
|
||||
set(value) { extraInfoBytes[3] = value.toByte() }
|
||||
get() = extraInfoBytes[3].toUint()
|
||||
var snapshot: Snapshot?
|
||||
set(value) {
|
||||
if (value == null) {
|
||||
extraInfoBytes[4] = 0
|
||||
extraInfoBytes[5] = 0
|
||||
}
|
||||
else {
|
||||
value.toBytes().forEachIndexed { index, byte ->
|
||||
extraInfoBytes[4+index] = byte
|
||||
}
|
||||
}
|
||||
}
|
||||
get() {
|
||||
return if (extraInfoBytes[4] == extraInfoBytes[5] && extraInfoBytes[4] == 0.toByte()) null
|
||||
else {
|
||||
Snapshot(extraInfoBytes.sliceArray(4..5))
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDiskName(charset: Charset) = diskName.toCanonicalString(charset)
|
||||
val root: DiskEntry
|
||||
get() = entries[0]!!
|
||||
|
||||
Reference in New Issue
Block a user