diff options
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java | 19 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java | 25 |
2 files changed, 22 insertions, 22 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 diff --git a/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java b/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java index ec02762..6e2fd1e 100644 --- a/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java +++ b/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java @@ -1,12 +1,8 @@ package ch.asynk.rustanddust.game.map; -import java.io.StringWriter; - import com.badlogic.gdx.graphics.Texture; 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.engine.Tile; import ch.asynk.rustanddust.engine.Path; @@ -28,7 +24,6 @@ import ch.asynk.rustanddust.game.Engagement; public abstract class Map5Marshal extends Map4Orders { - private static StringWriter writer = new StringWriter(2048); private static UnitList units = new UnitList(30); public Map5Marshal(final RustAndDust game, Texture map, SelectedTile hex) @@ -36,12 +31,8 @@ public abstract class Map5Marshal extends Map4Orders super(game, map, hex); } - public String unload(boolean full, Player player, Player opponent) + public void unload(Json json, boolean full, Player player, Player opponent) { - Json json = new Json(OutputType.json); - writer.getBuffer().setLength(0); - json.setWriter(writer); - json.writeObjectStart(); if (full) { json.writeObjectStart("map"); @@ -56,9 +47,6 @@ public abstract class Map5Marshal extends Map4Orders unload(json, orders); json.writeArrayEnd(); json.writeObjectEnd(); - - writer.flush(); - return writer.toString(); } // player @@ -266,14 +254,13 @@ public abstract class Map5Marshal extends Map4Orders } // LOAD - public void load(String payload, Player[] players) + public void load(JsonValue v, Player[] players) { units.clear(); - JsonValue root = new JsonReader().parse(payload); - loadMap(root.get("map")); - players[0] = loadPlayer(root.get("players").get(0)); - players[1] = loadPlayer(root.get("players").get(1)); - loadOrders(root.get("orders")); + loadMap(v.get("map")); + players[0] = loadPlayer(v.get("players").get(0)); + players[1] = loadPlayer(v.get("players").get(1)); + loadOrders(v.get("orders")); units.clear(); } |