diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-09 23:27:21 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-09 23:27:21 +0100 |
commit | 32daf8c19f359a98bcb41019bd891e4c33b59654 (patch) | |
tree | de634f990ce795ee4e192a1c014929a89a8884c9 /core/src/ch/asynk/rustanddust/game | |
parent | 1c6155aeaf587dfdd959472c8ed71785ee54f1d2 (diff) | |
download | RustAndDust-32daf8c19f359a98bcb41019bd891e4c33b59654.zip RustAndDust-32daf8c19f359a98bcb41019bd891e4c33b59654.tar.gz |
Config: add String unload(), void load(String payload)
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game')
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/Config.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Config.java b/core/src/ch/asynk/rustanddust/game/Config.java index 6e7001b..fccd142 100644 --- a/core/src/ch/asynk/rustanddust/game/Config.java +++ b/core/src/ch/asynk/rustanddust/game/Config.java @@ -1,5 +1,12 @@ package ch.asynk.rustanddust.game; +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; + public class Config { public enum Graphics { @@ -63,6 +70,8 @@ public class Config public static String [] fxStrings = { "OFF", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "ON" }; + private static StringWriter writer = new StringWriter(256); + public Config() { this.gameMode = GameMode.SOLO; @@ -81,4 +90,41 @@ public class Config { return (gameMode == GameMode.SOLO); } + + public String unload() + { + Json json = new Json(OutputType.json); + writer.getBuffer().setLength(0); + json.setWriter(writer); + + json.writeObjectStart(); + json.writeValue("mode", gameMode); + json.writeValue("debug", debug); + json.writeValue("autoPath", autoPath); + json.writeValue("showMoves", showMoves); + json.writeValue("showTargets", showTargets); + json.writeValue("showMoveAssists", showMoveAssists); + json.writeValue("showEnemyPossibilities", showEnemyPossibilities); + json.writeValue("graphics", graphics); + json.writeValue("fxVolume", fxVolume); + json.writeObjectEnd(); + + writer.flush(); + System.err.println(writer.toString().length()); + return writer.toString(); + } + + public void load(String payload) + { + JsonValue root = new JsonReader().parse(payload); + this.gameMode = GameMode.valueOf(root.getString("mode")); + this.debug = root.getBoolean("debug"); + this.autoPath = root.getBoolean("autoPath"); + this.showMoves = root.getBoolean("showMoves"); + this.showTargets = root.getBoolean("showTargets"); + this.showMoveAssists = root.getBoolean("showMoveAssists"); + this.showEnemyPossibilities = root.getBoolean("showEnemyPossibilities"); + this.graphics = Graphics.valueOf(root.getString("graphics")); + this.fxVolume = root.getFloat("fxVolume");; + } } |