diff options
Diffstat (limited to 'core')
-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");; + } } |