mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 21:31:51 +09:00
making copy of the savegame immediately after the initial save
This commit is contained in:
@@ -18,6 +18,9 @@ import net.torvald.terrarum.tvda.VirtualDisk
|
||||
import net.torvald.terrarum.ui.ConsoleWindow
|
||||
import net.torvald.util.SortedArrayList
|
||||
import org.khelekore.prtree.*
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.locks.Lock
|
||||
|
||||
/**
|
||||
@@ -357,6 +360,25 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies most recent `save` to `save.1`, leaving `save` for overwriting, previous `save.1` will be copied to `save.2`
|
||||
*/
|
||||
fun makeSavegameBackupCopy() {
|
||||
try {
|
||||
File(App.defaultSaveDir, INGAME.savegameNickname+".1").copyTo(
|
||||
File(App.defaultSaveDir, INGAME.savegameNickname+".2"), // don't use .bak as it's used by the savecracker
|
||||
true
|
||||
)
|
||||
} catch (e: NoSuchFileException) {}
|
||||
try {
|
||||
File(App.defaultSaveDir, INGAME.savegameNickname).copyTo(
|
||||
File(App.defaultSaveDir, INGAME.savegameNickname+".1"), // don't use .bak as it's used by the savecracker
|
||||
true
|
||||
)
|
||||
} catch (e: NoSuchFileException) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// simple euclidean norm, squared
|
||||
private val actorDistanceCalculator = DistanceCalculator<ActorWithBody> { t: ActorWithBody, p: PointND ->
|
||||
|
||||
@@ -313,9 +313,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
)
|
||||
|
||||
// make initial savefile
|
||||
// pause()
|
||||
WriteSavegame.immediate(savegameArchive, File(App.defaultSaveDir, savegameNickname), this) {
|
||||
// resume()
|
||||
makeSavegameBackupCopy()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,11 +85,9 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
screen = 3; gameMenuButtons.deselect()
|
||||
full.handler.lockToggle()
|
||||
full.lockTransition()
|
||||
// make backup of the old save
|
||||
File(App.defaultSaveDir, INGAME.savegameNickname).copyTo(
|
||||
File(App.defaultSaveDir, INGAME.savegameNickname+".1"), // don't use .bak as it's used by the savecracker
|
||||
true
|
||||
)
|
||||
|
||||
INGAME.makeSavegameBackupCopy()
|
||||
|
||||
// save the game
|
||||
WriteSavegame(INGAME.savegameArchive, File(App.defaultSaveDir, INGAME.savegameNickname), Terrarum.ingame!! as TerrarumIngame) {
|
||||
// callback:
|
||||
|
||||
Reference in New Issue
Block a user