Bugfixes / Rework of save discovery system

This commit is contained in:
Anuken
2019-10-27 14:58:26 -04:00
parent d969741f90
commit e103d62b75
12 changed files with 99 additions and 117 deletions
@@ -670,28 +670,25 @@ public class ServerControl implements ApplicationListener{
if(state.is(State.playing)){
err("Already hosting. Type 'stop' to stop hosting first.");
return;
}else if(!Strings.canParseInt(arg[0])){
err("Invalid save slot '{0}'.", arg[0]);
return;
}
int slot = Strings.parseInt(arg[0]);
FileHandle file = saveDirectory.child(arg[0] + "." + saveExtension);
if(!SaveIO.isSaveValid(slot)){
if(!SaveIO.isSaveValid(file)){
err("No (valid) save data found for slot.");
return;
}
Core.app.post(() -> {
try{
SaveIO.loadFromSlot(slot);
SaveIO.load(file);
state.rules.zone = null;
info("Save loaded.");
host();
state.set(State.playing);
}catch(Throwable t){
err("Failed to load save. Outdated or corrupt file.");
}
info("Save loaded.");
host();
state.set(State.playing);
});
});
@@ -699,18 +696,25 @@ public class ServerControl implements ApplicationListener{
if(!state.is(State.playing)){
err("Not hosting. Host a game first.");
return;
}else if(!Strings.canParseInt(arg[0])){
err("Invalid save slot '{0}'.", arg[0]);
return;
}
FileHandle file = saveDirectory.child(arg[0] + "." + saveExtension);
Core.app.post(() -> {
int slot = Strings.parseInt(arg[0]);
SaveIO.saveToSlot(slot);
info("Saved to slot {0}.", slot);
SaveIO.save(file);
info("Saved to {0}.", file);
});
});
handler.register("saves", "List all saves in the save directory.", arg -> {
info("Save files: ");
for(FileHandle file : saveDirectory.list()){
if(file.extension().equals(saveExtension)){
info("| &ly{0}", file.nameWithoutExtension());
}
}
});
handler.register("gameover", "Force a game over.", arg -> {
if(state.is(State.menu)){
info("Not playing a map.");