diff options
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/battles')
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java index 50bb1bd..9fe66f8 100644 --- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java +++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java @@ -1,8 +1,13 @@ package ch.asynk.rustanddust.game.battles; import java.util.Random; +import java.io.StringWriter; + +import com.badlogic.gdx.utils.Json; +import com.badlogic.gdx.utils.JsonValue; +import com.badlogic.gdx.utils.JsonReader; +import com.badlogic.gdx.utils.JsonWriter.OutputType; -import ch.asynk.rustanddust.game.Ctrl; import ch.asynk.rustanddust.game.Battle; import ch.asynk.rustanddust.game.Player; import ch.asynk.rustanddust.game.State; @@ -19,6 +24,8 @@ public abstract class BattleCommon implements Battle { protected final static Random random = new Random(System.currentTimeMillis()); + private final static StringWriter writer = new StringWriter(2048); + protected final Factory factory; protected int _id; @@ -101,14 +108,20 @@ public abstract class BattleCommon implements Battle public void load(int turn, String payload) { this.turnCount = turn; - map.load(payload, players); + JsonValue root = new JsonReader().parse(payload); + map.load(root, players); this.currentPlayer = players[0]; } @Override public String unload(boolean full) { - return map.unload(full, getPlayer(), getOpponent()); + Json json = new Json(OutputType.json); + writer.getBuffer().setLength(0); + json.setWriter(writer); + map.unload(json, full, getPlayer(), getOpponent()); + writer.flush(); + return writer.toString(); } @Override |