save deletion works but gui is still wip

This commit is contained in:
minjaesong
2023-06-28 11:05:28 +09:00
parent 370583d1af
commit 1745bb16db
4 changed files with 42 additions and 4 deletions

View File

@@ -1139,6 +1139,11 @@ public class App implements ApplicationListener {
public static RunningEnvironment environment;
/** defaultDir + "/Recycled/Players" */
public static String recycledPlayersDir;
/** defaultDir + "/Recycled/Worlds" */
public static String recycledWorldsDir;
private static void getDefaultDirectory() {
String OS = OSName.toUpperCase();
if (OS.contains("WIN")) {
@@ -1168,6 +1173,8 @@ public class App implements ApplicationListener {
worldsDir = defaultDir + "/Worlds";
configDir = defaultDir + "/config.json";
loadOrderDir = defaultDir + "/LoadOrder.txt";
recycledPlayersDir = defaultDir + "/Recycled/Players";
recycledWorldsDir = defaultDir + "/Recycled/Worlds";
System.out.println(String.format("os.name = %s (with identifier %s)", OSName, operationSystem));
System.out.println(String.format("os.version = %s", OSVersion));
@@ -1177,10 +1184,12 @@ public class App implements ApplicationListener {
private static void createDirs() {
File[] dirs = {
new File(saveDir),
// new File(saveDir),
new File(saveSharedDir),
new File(playersDir),
new File(worldsDir)
new File(worldsDir),
new File(recycledPlayersDir),
new File(recycledWorldsDir),
};
for (File it : dirs) {

View File

@@ -3,6 +3,10 @@ package net.torvald.terrarum
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.savegame.DiskSkimmer
import java.io.File
import java.io.IOException
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import kotlin.io.path.Path
/**
* Created by minjaesong on 2023-06-24.
@@ -35,6 +39,16 @@ class SavegameCollection(files0: List<DiskSkimmer>) {
return files.first()
}
fun moveToRecycle(basedir: String) {
files.forEach {
try {
Files.move(it.diskFile.toPath(), Path(basedir, it.diskFile.name), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING)
}
catch (e: IOException) {
e.printStackTrace()
}
}
}
}
class SavegameCollectionPair(player: SavegameCollection?, world: SavegameCollection?) {

View File

@@ -505,8 +505,8 @@ class UIItemPlayerCells(
private var lastPlayTime: String = "????-??-?? --:--:--"
private var totalPlayTime: String = "--h--m--s"
private lateinit var playerUUID: UUID
private lateinit var worldUUID: UUID
lateinit var playerUUID: UUID; private set
lateinit var worldUUID: UUID; private set
init {
skimmer.getFile(SAVEGAMEINFO)?.bytes?.let {

View File

@@ -174,6 +174,21 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
confirmBackButton.clickOnceListener = { _,_ ->
remoCon.openUI(UILoadSavegame(remoCon))
}
confirmDeleteButton.clickOnceListener = { _,_ ->
val pu = buttonSelectedForDeletion!!.playerUUID
val wu = buttonSelectedForDeletion!!.worldUUID
App.savegamePlayers[pu]?.moveToRecycle(App.recycledPlayersDir)?.let {
App.sortedPlayers.remove(pu)
App.savegamePlayers.remove(pu)
App.savegamePlayersName.remove(pu)
}
App.savegameWorlds[wu]?.moveToRecycle(App.recycledWorldsDir)?.let {
App.sortedSavegameWorlds.remove(wu)
App.savegameWorlds.remove(wu)
App.savegameWorldsName.remove(wu)
}
remoCon.openUI(UILoadSavegame(remoCon))
}
}
override fun advanceMode(button: UIItem) {