From c822ee999fd7aea0f796b732ba8e458304c728a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 22 Mar 2016 15:48:41 +0100 Subject: Battle: unload turnCount into JSON --- core/src/ch/asynk/rustanddust/game/Battle.java | 2 +- .../ch/asynk/rustanddust/game/battles/BattleCommon.java | 14 ++++++++++---- core/src/ch/asynk/rustanddust/game/ctrl/Solo.java | 4 ++-- 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 -- cgit v1.1-2-g2b99