make sure after loading a limitedsaves game that it is saved to the quickslot before deleting the savegame file

This commit is contained in:
Gonk
2019-12-23 23:58:42 +01:00
parent 2d9cf8e364
commit 5ae78dd2fb
2 changed files with 8 additions and 3 deletions

View File

@@ -160,8 +160,7 @@ public final class MainActivity
}
private boolean save(int slot) {
final Player player = world.model.player;
return Savegames.saveWorld(world, this, slot, getString(R.string.savegame_currenthero_displayinfo, player.getLevel(), player.getTotalExperience(), player.getGold()));
return Savegames.saveWorld(world, this, slot);
}
@Override

View File

@@ -25,6 +25,7 @@ import android.os.Environment;
import android.os.SystemClock;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.Constants;
@@ -45,8 +46,9 @@ public final class Savegames {
, cheatingDetected
}
public static boolean saveWorld(WorldContext world, Context androidContext, int slot, String displayInfo) {
public static boolean saveWorld(WorldContext world, Context androidContext, int slot) {
try {
final String displayInfo = androidContext.getString(R.string.savegame_currenthero_displayinfo, world.model.player.getLevel(), world.model.player.getTotalExperience(), world.model.player.getGold());
if (slot != SLOT_QUICKSAVE && !world.model.statistics.hasUnlimitedSaves()) {
world.model.player.savedVersion++;
}
@@ -105,6 +107,10 @@ public final class Savegames {
LoadSavegameResult result = loadWorld(androidContext.getResources(), world, controllers, fos, fh);
fos.close();
if (result == LoadSavegameResult.success && slot != SLOT_QUICKSAVE && !world.model.statistics.hasUnlimitedSaves()) {
// save to the quicksave slot before deleting the file
if (!saveWorld(world, androidContext, SLOT_QUICKSAVE)) {
return LoadSavegameResult.unknownError;
}
getSlotFile(slot).delete();
writeCheatCheck(androidContext, DENY_LOADING_BECAUSE_GAME_IS_CURRENTLY_PLAYED, fh.playerId);
}