summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-05-10 13:50:06 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-05-10 13:50:06 +0200
commit7a583d4157bd91a0d088968edd438b055cf41c6b (patch)
tree66c6ee99e01cf5a5c28c3b8268778a85efd789ee /core/src
parente1410b3d1c31cae419082df57a148e120aa4142c (diff)
downloadRustAndDust-7a583d4157bd91a0d088968edd438b055cf41c6b.zip
RustAndDust-7a583d4157bd91a0d088968edd438b055cf41c6b.tar.gz
Solo: clean up loadState(), get ready for REPLAY_BATTLE
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/rustanddust/game/ctrl/Solo.java40
1 files changed, 24 insertions, 16 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java
index 0d29d6d..19dd390 100644
--- a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java
+++ b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java
@@ -15,8 +15,7 @@ public class Solo extends Ctrl
@Override
public void init()
{
- GameRecord r = loadState();
- if (r == null) {
+ if (!loadState()) {
int me = game.backend.getMyId();
int other = game.backend.getOpponentId();
gameId = game.db.storeGameGetId(other, battle.getId(), game.config.gameMode.i);
@@ -24,29 +23,38 @@ public class Solo extends Ctrl
battle.getOpponent().id = other;
battle.initialDeployment(this);
synched = true;
- } else {
- load(Marshal.Mode.MAP, r.map);
- load(Marshal.Mode.PLAYERS, r.players);
- load(Marshal.Mode.ORDERS, r.orders);
- battle.getMap().clearMarshalUnits();
- synched = r.synched;
- r.dispose();
}
}
- private GameRecord loadState()
+ private boolean loadState()
{
GameRecord r = null;
gameId = game.config.gameId;
+
switch (game.config.loadMode)
{
- case NEW: break;
- case RESUME: r = game.db.loadGame(gameId); break;
- case REPLAY_LAST: r = game.db.loadLastTurn(gameId); break;
- case REPLAY_BATTLE:
- // TODO REPLAY_BATTLE
+ case NEW: break;
+ case RESUME: r = game.db.loadGame(gameId); break;
+ case REPLAY_LAST: r = game.db.loadLastTurn(gameId); break;
+ case REPLAY_BATTLE: r = game.db.loadTurn(gameId, 0); break;
+ }
+
+ if (r == null)
+ return false;
+
+ load(Marshal.Mode.MAP, r.map);
+ load(Marshal.Mode.PLAYERS, r.players);
+ load(Marshal.Mode.ORDERS, r.orders);
+ switch (game.config.loadMode)
+ {
+ case REPLAY_BATTLE: break;
+ default:
+ battle.getMap().clearMarshalUnits();
break;
}
- return r;
+ synched = r.synched;
+ r.dispose();
+
+ return true;
}
}