summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-03-22 15:48:41 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-03-22 15:48:41 +0100
commitc822ee999fd7aea0f796b732ba8e458304c728a7 (patch)
tree11e305eec59f92a009e5d45029ab40ce48e62554 /core/src/ch/asynk
parent95ddd472d09244612b70e5c62f35a52c6185df7b (diff)
downloadRustAndDust-c822ee999fd7aea0f796b732ba8e458304c728a7.zip
RustAndDust-c822ee999fd7aea0f796b732ba8e458304c728a7.tar.gz
Battle: unload turnCount into JSON
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/rustanddust/game/Battle.java2
-rw-r--r--core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java14
-rw-r--r--core/src/ch/asynk/rustanddust/game/ctrl/Solo.java4
3 files changed, 13 insertions, 7 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Battle.java b/core/src/ch/asynk/rustanddust/game/Battle.java
index a545573..eb5b086 100644
--- a/core/src/ch/asynk/rustanddust/game/Battle.java
+++ b/core/src/ch/asynk/rustanddust/game/Battle.java
@@ -42,5 +42,5 @@ public interface Battle extends Marshal
public String unload(Marshal.Mode mode);
- public void load(Marshal.Mode mode, int turn, String payload);
+ public void load(Marshal.Mode mode, String payload);
}
diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
index e0afc5f..968c657 100644
--- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
+++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
@@ -106,9 +106,8 @@ public abstract class BattleCommon implements Battle
}
@Override
- public void load(Marshal.Mode mode, int turn, String payload)
+ public void load(Marshal.Mode mode, String payload)
{
- this.turnCount = turn;
JsonValue root = new JsonReader().parse(payload);
load(mode, root);
this.currentPlayer = players[0];
@@ -117,8 +116,11 @@ public abstract class BattleCommon implements Battle
@Override
public void load(Marshal.Mode mode, JsonValue value)
{
- if((mode == Marshal.Mode.FULL) || (mode == Marshal.Mode.STATE))
+ if((mode == Marshal.Mode.FULL) || (mode == Marshal.Mode.STATE)) {
+ JsonValue v = value.get("battle");
+ this.turnCount = v.getInt("turnCount");
map.loadPlayers(value, players);
+ }
map.load(mode, value);
}
@@ -137,8 +139,12 @@ public abstract class BattleCommon implements Battle
public void unload(Marshal.Mode mode, Json json)
{
json.writeObjectStart();
- if((mode == Marshal.Mode.FULL) || (mode == Marshal.Mode.STATE))
+ if((mode == Marshal.Mode.FULL) || (mode == Marshal.Mode.STATE)) {
+ json.writeObjectStart("battle");
+ json.writeValue("turnCount", turnCount);
+ json.writeObjectEnd();
map.unloadPlayers(json, getPlayer(), getOpponent());
+ }
map.unload(mode, json);
json.writeObjectEnd();
}
diff --git a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java
index d7cda5c..5473cd5 100644
--- a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java
+++ b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java
@@ -28,8 +28,8 @@ public class Solo extends Ctrl
} else {
GameRecord r = game.db.loadGame(gameId);
if (r != null) {
- battle.load(Marshal.Mode.STATE, r.turn, r.state);
- battle.load(Marshal.Mode.ORDERS, r.turn, r.orders);
+ battle.load(Marshal.Mode.STATE, r.state);
+ battle.load(Marshal.Mode.ORDERS, r.orders);
battle.getMap().clearMarshalUnits();
r.dispose();
} else