From 7a583d4157bd91a0d088968edd438b055cf41c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 10 May 2016 13:50:06 +0200 Subject: Solo: clean up loadState(), get ready for REPLAY_BATTLE --- core/src/ch/asynk/rustanddust/game/ctrl/Solo.java | 40 ++++++++++++++--------- 1 file 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; } } -- cgit v1.1-2-g2b99