summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/game/battles
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-03-21 09:00:50 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-03-21 09:00:50 +0100
commitd387eef4ef69c4c816a77fa1f828a904e7ea4f55 (patch)
tree88d92856ccde773625fe064e5336ab436176b4bd /core/src/ch/asynk/rustanddust/game/battles
parent3a809a54c34415c197e79086170a55561d2c1b8a (diff)
downloadRustAndDust-d387eef4ef69c4c816a77fa1f828a904e7ea4f55.zip
RustAndDust-d387eef4ef69c4c816a77fa1f828a904e7ea4f55.tar.gz
BattleCommon,Map5Marshal: move JsonWriter & JsonReader usage from Map to Battle
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/battles')
-rw-r--r--core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java19
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