summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/game/Config.java
blob: cc148db1f81eef9ce59fe34e28e3d0df50edcf51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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 {
        CHITS("chits", 0),
        TANKS("tanks", 1);
        public String s;
        public int i;
        Graphics(String s, int i)
        {
            this.s = s;
            this.i = i;
        }
        public Graphics next()
        {
            if (this == TANKS)
                return CHITS;
            return TANKS;
        }
        public Graphics get(int i)
        {
            if (i == CHITS.i)
                return CHITS;
            else if (i == TANKS.i)
                return TANKS;
            return null;
        }
    };

    public enum GameMode
    {
        SOLO("Solo", 0),
        PVE("Player vs AI", 1),
        PVP("Player vs Player", 2);
        public String s;
        public int i;
        GameMode(String s, int i)
        {
            this.s = s;
            this.i = i;
        }
        public GameMode next()
        {
            if (this == SOLO)
                return PVE;
            if (this == PVE)
                return PVP;
            return SOLO;
        }
        public static GameMode from(int i)
        {
            GameMode r = SOLO;
            switch(i) {
                case 1: r = PVE; break;
                case 2: r = PVP; break;
            }
            return r;
        }
    };

    public GameMode gameMode;
    public boolean showMoves;
    public boolean showTargets;
    public boolean showMoveAssists;
    public boolean showEnemyPossibilities;
    public boolean autoPath;
    public boolean debug;
    public Battle battle;
    public float fxVolume;
    public Graphics graphics;

    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;
        this.debug = false;
        this.autoPath = true;
        this.showMoves = true;
        this.showTargets = true;
        this.showMoveAssists = true;
        this.showEnemyPossibilities = false;
        this.graphics = Graphics.CHITS;
        this.battle = null;
        this.fxVolume = 1f;
    }

    public boolean gameModeImplemented()
    {
        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();
        return writer.toString();
    }

    public void load(String payload)
    {
        if (payload == null) return;
        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");;
    }
}