-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoreSettings.java
261 lines (221 loc) · 6.03 KB
/
CoreSettings.java
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package com.hexensemble.mildred.system;
import java.io.IOException;
import java.util.ArrayList;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.XmlReader;
import com.badlogic.gdx.utils.XmlWriter;
/**
* Core settings.
*
* @author HexEnsemble
* @author www.hexensemble.com
* @version 1.0.1
* @since Alpha 2.0.0
*/
public class CoreSettings {
/**
* Title.
*/
public static final String TITLE = "Mildred";
/**
* Author.
*/
public static final String AUTHOR = "HexEnsemble";
/**
* Version.
*/
public static final String VERSION = "Version 1.0.1";
/**
* Version date.
*/
public static final String DATE = "15-May-2019";
/**
* Copyright.
*/
public static final String COPYRIGHT = "\u00a9 Copyright 2016 HexEnsemble. Published under licence by Hot Baked Goods.";
/**
* Settings file path.
*/
public static final String SETTINGS_FILE = "/.mildred/settings.xml";
/**
* Save file 1 path.
*/
public static final String SAVE_FILE_1 = "/.mildred/savegame1.json";
/**
* Save file 2 path.
*/
public static final String SAVE_FILE_2 = "/.mildred/savegame2.json";
/**
* Save file 3 path.
*/
public static final String SAVE_FILE_3 = "/.mildred/savegame3.json";
/**
* Virtual tile size.
*/
public static final float V_TILE_SIZE = 1;
/**
* Virtual screen width.
*/
public static final float V_WIDTH = 32;
/**
* Virtual screen height.
*/
public static final float V_HEIGHT = 24;
/**
* Virtual tile grid width.
*/
public static final float V_TILE_GRID_WIDTH = 64;
/**
* Virtual tile grid height.
*/
public static final float V_TILE_GRID_HEIGHT = 48;
/**
* Pixel tile size.
*/
public static final float P_TILE_SIZE = 32;
/**
* Pixel screen width.
*/
public static final float P_WIDTH = V_WIDTH * P_TILE_SIZE;
/**
* Pixel screen height.
*/
public static final float P_HEIGHT = V_HEIGHT * P_TILE_SIZE;
/**
* HTML screen width.
*/
public static final int HTML_WIDTH = 800;
/**
* HTML screen height.
*/
public static final int HTML_HEIGHT = 600;
/**
* Screen width.
*/
public static int width;
/**
* Screen height.
*/
public static int height;
/**
* Fullscreen on/off.
*/
public static boolean fullscreen;
/**
* vSync on/off.
*/
public static boolean vSync;
/**
* Show FPS on/off.
*/
public static boolean fps;
/**
* Sound volume.
*/
public static float sfxVol;
/**
* Music volume.
*/
public static float musicVol;
/**
* Active save slot.
*/
public static int saveSlot;
/**
* Use custom level(s).
*/
public static boolean customLevel;
/**
* Custom level list.
*/
public static ArrayList<String> customLevelList;
/**
* Initialize.
*
*/
public CoreSettings() {
}
public static void load() {
if (Gdx.files.isExternalStorageAvailable()) {
FileHandle settingsFile = Gdx.files.external(SETTINGS_FILE);
XmlReader reader = new XmlReader();
if (!settingsFile.exists()) {
width = 800;
height = 600;
fullscreen = false;
vSync = false;
fps = false;
sfxVol = 1;
musicVol = 1;
save();
} else {
for (int i = 0; i < reader.parse(settingsFile).getChildCount(); i++) {
if (reader.parse(settingsFile).getChild(i).getAttribute("key").contains("width")) {
width = Integer.parseInt((reader.parse(settingsFile).getChild(i).getText()));
}
if (reader.parse(settingsFile).getChild(i).getAttribute("key").contains("height")) {
height = Integer.parseInt((reader.parse(settingsFile).getChild(i).getText()));
}
if (reader.parse(settingsFile).getChild(i).getAttribute("key").contains("fullscreen")) {
fullscreen = Boolean.parseBoolean((reader.parse(settingsFile).getChild(i).getText()));
}
if (reader.parse(settingsFile).getChild(i).getAttribute("key").contains("vsync")) {
vSync = Boolean.parseBoolean((reader.parse(settingsFile).getChild(i).getText()));
}
if (reader.parse(settingsFile).getChild(i).getAttribute("key").contains("fps")) {
fps = Boolean.parseBoolean((reader.parse(settingsFile).getChild(i).getText()));
}
if (reader.parse(settingsFile).getChild(i).getAttribute("key").contains("sfx")) {
sfxVol = Float.parseFloat((reader.parse(settingsFile).getChild(i).getText()));
}
if (reader.parse(settingsFile).getChild(i).getAttribute("key").contains("music")) {
musicVol = Float.parseFloat((reader.parse(settingsFile).getChild(i).getText()));
}
}
boolean soundSetting = false;
boolean musicSetting = false;
for (int i = 0; i < reader.parse(settingsFile).getChildCount(); i++) {
if (reader.parse(settingsFile).getChild(i).getAttribute("key").contains("sfx")) {
soundSetting = true;
}
if (reader.parse(settingsFile).getChild(i).getAttribute("key").contains("music")) {
musicSetting = true;
}
}
if (!soundSetting) {
sfxVol = 1;
save();
}
if (!musicSetting) {
musicVol = 1;
save();
}
}
} else {
width = HTML_WIDTH;
height = HTML_HEIGHT;
fullscreen = false;
vSync = false;
fps = false;
sfxVol = 1;
musicVol = 1;
}
}
public static void save() {
FileHandle settingsFile = Gdx.files.external(SETTINGS_FILE);
XmlWriter writer = new XmlWriter(settingsFile.writer(false));
try {
writer.text("<?xml version=" + "\"1.0\"" + " encoding=" + "\"UTF-8\"" + " standalone=" + "\"no\"" + "?>");
writer.text("<!DOCTYPE properties SYSTEM " + "\"http://java.sun.com/dtd/properties.dtd\"" + ">");
writer.element("properties").element("entry").attribute("key", "width").text(width).pop().element("entry")
.attribute("key", "height").text(height).pop().element("entry").attribute("key", "fullscreen")
.text(fullscreen).pop().element("entry").attribute("key", "vsync").text(vSync).pop()
.element("entry").attribute("key", "fps").text(fps).pop().element("entry").attribute("key", "sfx")
.text(sfxVol).pop().element("entry").attribute("key", "music").text(musicVol).pop().pop();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}