mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 21:31:51 +09:00
new savegame scheme suggestion
This commit is contained in:
@@ -929,8 +929,14 @@ public class App implements ApplicationListener {
|
||||
public static String operationSystem;
|
||||
/** %appdata%/Terrarum, without trailing slash */
|
||||
public static String defaultDir;
|
||||
/** defaultDir + "/Saves", without trailing slash */
|
||||
public static String defaultSaveDir;
|
||||
/** For Demo version only. defaultDir + "/Saves", without trailing slash */
|
||||
public static String saveDir;
|
||||
/** For shared materials (e.g. image of a computer disk). defaultDir + "/Shared", without trailing slash */
|
||||
public static String saveSharedDir;
|
||||
/** For the main game where any players can access any world (unless flagged as private). defaultDir + "/Players", without trailing slash */
|
||||
public static String playersDir;
|
||||
/** For the main game. defaultDir + "/Worlds", without trailing slash */
|
||||
public static String worldsDir;
|
||||
/** defaultDir + "/config.json" */
|
||||
public static String configDir;
|
||||
public static RunningEnvironment environment;
|
||||
@@ -958,8 +964,10 @@ public class App implements ApplicationListener {
|
||||
defaultDir = System.getProperty("user.home") + "/.Terrarum";
|
||||
}
|
||||
|
||||
// defaultSaveDir = defaultDir + "/Players"; // as per the save format in the game's planning
|
||||
defaultSaveDir = defaultDir + "/Saves"; // for the demo release
|
||||
saveDir = defaultDir + "/Saves"; // for the demo release
|
||||
saveSharedDir = defaultDir + "/Shared";
|
||||
playersDir = defaultDir + "/Players";
|
||||
worldsDir = defaultDir + "/Worlds";
|
||||
configDir = defaultDir + "/config.json";
|
||||
|
||||
System.out.println(String.format("os.name = %s (with identifier %s)", OSName, operationSystem));
|
||||
@@ -969,7 +977,7 @@ public class App implements ApplicationListener {
|
||||
}
|
||||
|
||||
private static void createDirs() {
|
||||
File[] dirs = {new File(defaultSaveDir)};
|
||||
File[] dirs = {new File(saveDir)};
|
||||
|
||||
for (File it : dirs) {
|
||||
if (!it.exists())
|
||||
|
||||
@@ -368,23 +368,23 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
fun makeSavegameBackupCopy() {
|
||||
try {
|
||||
// do not overwrite clean .2 with dirty .1
|
||||
val file2 = File(App.defaultSaveDir, INGAME.savegameNickname+".3")
|
||||
val file1 = File(App.defaultSaveDir, INGAME.savegameNickname+".2")
|
||||
val file2 = File(App.saveDir, INGAME.savegameNickname + ".3")
|
||||
val file1 = File(App.saveDir, INGAME.savegameNickname + ".2")
|
||||
val flags2 = FileInputStream(file2).let { it.skip(49L); val r = it.read(); it.close(); r }
|
||||
val flags1 = FileInputStream(file1).let { it.skip(49L); val r = it.read(); it.close(); r }
|
||||
if (!(flags2 == 0 && flags1 != 0) || !file2.exists()) file1.copyTo(file2, true)
|
||||
} catch (e: NoSuchFileException) {} catch (e: FileNotFoundException) {}
|
||||
try {
|
||||
// do not overwrite clean .2 with dirty .1
|
||||
val file2 = File(App.defaultSaveDir, INGAME.savegameNickname+".2")
|
||||
val file1 = File(App.defaultSaveDir, INGAME.savegameNickname+".1")
|
||||
val file2 = File(App.saveDir, INGAME.savegameNickname + ".2")
|
||||
val file1 = File(App.saveDir, INGAME.savegameNickname + ".1")
|
||||
val flags2 = FileInputStream(file2).let { it.skip(49L); val r = it.read(); it.close(); r }
|
||||
val flags1 = FileInputStream(file1).let { it.skip(49L); val r = it.read(); it.close(); r }
|
||||
if (!(flags2 == 0 && flags1 != 0) || !file2.exists()) file1.copyTo(file2, true)
|
||||
} catch (e: NoSuchFileException) {} catch (e: FileNotFoundException) {}
|
||||
try {
|
||||
File(App.defaultSaveDir, INGAME.savegameNickname).copyTo(
|
||||
File(App.defaultSaveDir, INGAME.savegameNickname+".1"), // don't use .bak as it's used by the savecracker
|
||||
File(App.saveDir, INGAME.savegameNickname).copyTo(
|
||||
File(App.saveDir, INGAME.savegameNickname + ".1"), // don't use .bak as it's used by the savecracker
|
||||
true
|
||||
)
|
||||
} catch (e: NoSuchFileException) {}
|
||||
@@ -392,7 +392,7 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
|
||||
|
||||
|
||||
fun getSaveFileMain() = File(App.defaultSaveDir, savegameNickname)
|
||||
fun getSaveFileMain() = File(App.saveDir, savegameNickname)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.util.CircularArray
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import java.util.logging.Level
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.round
|
||||
|
||||
@@ -244,7 +243,7 @@ object Terrarum : Disposable {
|
||||
|
||||
val currentSaveDir: File
|
||||
get() {
|
||||
val file = File(defaultSaveDir + "/test")
|
||||
val file = File(saveDir + "/test")
|
||||
|
||||
// failsafe?
|
||||
if (!file.exists()) file.mkdir()
|
||||
@@ -683,7 +682,7 @@ class Codex : KVHashMap() {
|
||||
|
||||
fun AppUpdateListOfSavegames() {
|
||||
App.savegames.clear()
|
||||
File(App.defaultSaveDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.map { file ->
|
||||
File(App.saveDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.map { file ->
|
||||
try {
|
||||
DiskSkimmer(file, Common.CHARSET, true)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ object Save : ConsoleCommand {
|
||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||
val savename = args[1].trim()
|
||||
val disk = VDUtil.createNewDisk(1L shl 60, savename, Common.CHARSET)
|
||||
val file = File(App.defaultSaveDir + "/${args[1]}")
|
||||
val file = File(App.saveDir + "/${args[1]}")
|
||||
|
||||
WriteSavegame(disk, file, ingame, false)
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
INGAME.makeSavegameBackupCopy()
|
||||
|
||||
// save the game
|
||||
WriteSavegame(INGAME.savegameArchive, File(App.defaultSaveDir, INGAME.savegameNickname), Terrarum.ingame!! as TerrarumIngame, false) {
|
||||
WriteSavegame(INGAME.savegameArchive, File(App.saveDir, INGAME.savegameNickname), Terrarum.ingame!! as TerrarumIngame, false) {
|
||||
// callback:
|
||||
System.gc()
|
||||
screen = 0
|
||||
|
||||
Reference in New Issue
Block a user