diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/WorldSetup.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/WorldSetup.java index 0a7349887..8750a87d0 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/WorldSetup.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/WorldSetup.java @@ -26,7 +26,7 @@ public final class WorldSetup { public int loadFromSlot = Savegames.SLOT_QUICKSAVE; public boolean isSceneReady = false; public String newHeroName; - private int loadResult; + private Savegames.LoadSavegameResult loadResult; public WorldSetup(WorldContext world, ControllerContext controllers, Context androidContext) { this.world = world; @@ -105,7 +105,7 @@ public final class WorldSetup { if (world.model != null) world.resetForNewGame(); if (createNewCharacter) { createNewWorld(); - loadResult = Savegames.LOAD_RESULT_SUCCESS; + loadResult = Savegames.LoadSavegameResult.success; } else { loadResult = continueWorld(); } @@ -126,7 +126,7 @@ public final class WorldSetup { onSceneLoadedListener = null; if (o == null) return; - if (loadResult == Savegames.LOAD_RESULT_SUCCESS) { + if (loadResult == Savegames.LoadSavegameResult.success) { o.onSceneLoaded(); } else { o.onSceneLoadFailed(loadResult); @@ -136,7 +136,7 @@ public final class WorldSetup { }).execute(); } - private int continueWorld() { + private Savegames.LoadSavegameResult continueWorld() { Context ctx = androidContext.get(); return Savegames.loadWorld(world, controllers, ctx, loadFromSlot); } @@ -154,7 +154,7 @@ public final class WorldSetup { public interface OnSceneLoadedListener { void onSceneLoaded(); - void onSceneLoadFailed(int loadResult); + void onSceneLoadFailed(Savegames.LoadSavegameResult loadResult); } public interface OnResourcesLoadedListener { void onResourcesLoaded(); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java index d62782d42..07da04227 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java @@ -58,7 +58,7 @@ public final class LoadSaveActivity extends Activity implements OnClickListener slotList.removeView(slotTemplateButton); slotList.removeView(createNewSlot); - addSavegameSlotButtons(slotList, params, Savegames.getUsedSavegameSlots(this)); + addSavegameSlotButtons(slotList, params, Savegames.getUsedSavegameSlots()); if (!isLoading) { Button b = new Button(this); @@ -86,7 +86,7 @@ public final class LoadSaveActivity extends Activity implements OnClickListener public void loadsave(int slot) { if (slot == SLOT_NUMBER_CREATE_NEW_SLOT) { - List usedSlots = Savegames.getUsedSavegameSlots(this); + List usedSlots = Savegames.getUsedSavegameSlots(); if (usedSlots.isEmpty()) slot = SLOT_NUMBER_FIRST_SLOT; else slot = Collections.max(usedSlots) + 1; } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadingActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadingActivity.java index c5b565656..2d87be8e8 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadingActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadingActivity.java @@ -55,9 +55,9 @@ public final class LoadingActivity extends Activity implements OnResourcesLoaded } @Override - public void onSceneLoadFailed(int loadResult) { + public void onSceneLoadFailed(Savegames.LoadSavegameResult loadResult) { progressDialog.dismiss(); - if (loadResult == Savegames.LOAD_RESULT_FUTURE_VERSION) { + if (loadResult == Savegames.LoadSavegameResult.savegameIsFromAFutureVersion) { showLoadingFailedDialog(R.string.dialog_loading_failed_incorrectversion); } else { showLoadingFailedDialog(R.string.dialog_loading_failed_message); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/StartScreenActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/StartScreenActivity.java index 077e810b9..14389c272 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/StartScreenActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/StartScreenActivity.java @@ -161,7 +161,7 @@ public final class StartScreenActivity extends Activity { Dialogs.showNewVersion(this); } - boolean hasSavegames = !Savegames.getUsedSavegameSlots(this).isEmpty(); + boolean hasSavegames = !Savegames.getUsedSavegameSlots().isEmpty(); startscreen_load.setEnabled(hasSavegames); } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java index ea33128b3..1ac070391 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java @@ -20,9 +20,11 @@ import java.util.regex.Pattern; public final class Savegames { public static final int SLOT_QUICKSAVE = 0; - public static final int LOAD_RESULT_SUCCESS = 0; - public static final int LOAD_RESULT_UNKNOWN_ERROR = 1; - public static final int LOAD_RESULT_FUTURE_VERSION = 2; + public static enum LoadSavegameResult { + success + , unknownError + , savegameIsFromAFutureVersion + } public static boolean saveWorld(WorldContext world, Context androidContext, int slot, String displayInfo) { try { @@ -42,10 +44,10 @@ public final class Savegames { return false; } } - public static int loadWorld(WorldContext world, ControllerContext controllers, Context androidContext, int slot) { + public static LoadSavegameResult loadWorld(WorldContext world, ControllerContext controllers, Context androidContext, int slot) { try { FileInputStream fos = getInputFile(androidContext, slot); - int result = loadWorld(androidContext.getResources(), world, controllers, fos); + LoadSavegameResult result = loadWorld(androidContext.getResources(), world, controllers, fos); fos.close(); return result; } catch (IOException e) { @@ -56,7 +58,7 @@ public final class Savegames { e.printStackTrace(pw); L.log("Load error: " + sw.toString()); } - return LOAD_RESULT_UNKNOWN_ERROR; + return LoadSavegameResult.unknownError; } } @@ -99,10 +101,10 @@ public final class Savegames { dest.close(); } - public static int loadWorld(Resources res, WorldContext world, ControllerContext controllers, InputStream inState) throws IOException { + public static LoadSavegameResult loadWorld(Resources res, WorldContext world, ControllerContext controllers, InputStream inState) throws IOException { DataInputStream src = new DataInputStream(inState); final FileHeader header = new FileHeader(src); - if (header.fileversion > AndorsTrailApplication.CURRENT_VERSION) return LOAD_RESULT_FUTURE_VERSION; + if (header.fileversion > AndorsTrailApplication.CURRENT_VERSION) return LoadSavegameResult.savegameIsFromAFutureVersion; world.maps.readFromParcel(src, world, controllers, header.fileversion); world.model = new ModelContainer(src, world, controllers, header.fileversion); @@ -110,7 +112,7 @@ public final class Savegames { onWorldLoaded(res, world, controllers); - return LOAD_RESULT_SUCCESS; + return LoadSavegameResult.success; } private static void onWorldLoaded(Resources res, WorldContext world, ControllerContext controllers) {