From 32daf8c19f359a98bcb41019bd891e4c33b59654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 9 Feb 2016 23:27:21 +0100 Subject: Config: add String unload(), void load(String payload) --- core/src/ch/asynk/rustanddust/game/Config.java | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) 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");; + } } -- cgit v1.1-2-g2b99