summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/game/ctrl
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-05-03 15:31:32 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-05-03 15:31:32 +0200
commit79793cf2dd5cad2af5fa513a7213292d2ee53f86 (patch)
tree306e849be86d992a543e42c8e8ddec80d24795a6 /core/src/ch/asynk/rustanddust/game/ctrl
parentcff800a98e8aec4e454c5dc84fd4249b7127a1fd (diff)
downloadRustAndDust-79793cf2dd5cad2af5fa513a7213292d2ee53f86.zip
RustAndDust-79793cf2dd5cad2af5fa513a7213292d2ee53f86.tar.gz
OMG: add event queue, messages, replay, bounce animation, complete states rewrite ...
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/ctrl')
-rw-r--r--core/src/ch/asynk/rustanddust/game/ctrl/Solo.java70
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);
- }
}