diff options
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/ctrl')
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/ctrl/Solo.java | 70 |
1 files changed, 14 insertions, 56 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java index 54d2310..29a8755 100644 --- a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java +++ b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java @@ -7,8 +7,6 @@ import ch.asynk.rustanddust.game.Ctrl; public class Solo extends Ctrl { - private int gameId; - public Solo(final RustAndDust game) { super(game); @@ -17,8 +15,8 @@ public class Solo extends Ctrl @Override public void init() { - gameId = game.config.gameId; - if (gameId == game.db.NO_RECORD) { + GameRecord r = loadState(); + if (r == null) { int me = game.backend.getMyId(); int other = game.backend.getOpponentId(); gameId = game.db.storeGameGetId(other, battle.getId(), game.config.gameMode.i); @@ -27,68 +25,28 @@ public class Solo extends Ctrl battle.initialDeployment(); synched = true; } else { - GameRecord r = loadState(); - if (r != null) { - load(Marshal.Mode.STATE, r.state); - load(Marshal.Mode.ORDERS, r.orders); - battle.getMap().clearMarshalUnits(); - synched = r.synched; - r.dispose(); - } else - System.err.println("TODO : null GameRecord"); + 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() { GameRecord r = null; - switch (game.config.loadMode) { - case LOAD: - r = game.db.loadGame(gameId); - break; - case REPLAY_LAST: - r = game.db.loadLastTurn(gameId); - break; + gameId = game.config.gameId; + switch (game.config.loadMode) + { + case NEW: break; + case RESUME: r = game.db.loadGame(gameId); break; + case REPLAY_CURRENT: r = game.db.loadLastTurn(gameId); break; case REPLAY_ALL: // TODO REPLAY_ALL break; } return r; } - - @Override - public void orderProcessedCb() - { - if (!isLoading()) - storeOrders(); - } - - @Override - protected void actionDoneCb() - { - storeState(); - } - - @Override - protected void turnDoneCb() - { - storeOrders(); - storeState(); - storeTurn(); - } - - private void storeState() - { - game.db.storeGameState(gameId, battle.getTurnCount(), battle.getPlayer().id, unload(Marshal.Mode.STATE)); - } - - private void storeOrders() - { - game.db.storeGameOrders(gameId, battle.getTurnCount(), battle.getPlayer().id, unload(Marshal.Mode.ORDERS)); - } - - private void storeTurn() - { - game.db.storeLastTurn(gameId); - } } |