Skip to content

Commit 9b6552b

Browse files
committed
Load/Save preferences support.
1 parent daa7ae3 commit 9b6552b

14 files changed

+122
-74
lines changed

blade-engine/src/com/bladecoder/engine/BladeEngine.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void loadGame(String baseFolder) {
8888

8989
if (baseFolder != null) {
9090
EngineAssetManager.setAssetFolder(baseFolder);
91-
Config.load();
91+
Config.getInstance().load();
9292
}
9393

9494
try {
@@ -105,15 +105,15 @@ public void loadGame(String baseFolder) {
105105
@Override
106106
public void create() {
107107
if (!debug)
108-
debug = Config.getProperty(Config.DEBUG_PROP, debug);
108+
debug = Config.getInstance().getProperty(Config.DEBUG_PROP, debug);
109109

110110
if (debug)
111111
EngineLogger.setDebug();
112112

113113
EngineLogger.debug("GAME CREATE");
114114

115115
if (forceRes == null)
116-
forceRes = Config.getProperty(Config.FORCE_RES_PROP, forceRes);
116+
forceRes = Config.getInstance().getProperty(Config.FORCE_RES_PROP, forceRes);
117117

118118
if (forceRes != null) {
119119
EngineAssetManager.getInstance().forceResolution(forceRes);
@@ -123,10 +123,10 @@ public void create() {
123123

124124
if (EngineLogger.debugMode()) {
125125
if (chapter == null)
126-
chapter = Config.getProperty(Config.CHAPTER_PROP, chapter);
126+
chapter = Config.getInstance().getProperty(Config.CHAPTER_PROP, chapter);
127127

128128
if (testScene == null) {
129-
testScene = Config.getProperty(Config.TEST_SCENE_PROP, testScene);
129+
testScene = Config.getInstance().getProperty(Config.TEST_SCENE_PROP, testScene);
130130
}
131131

132132
if (testScene != null || chapter != null) {
@@ -142,7 +142,7 @@ public void create() {
142142
}
143143

144144
if (gameState == null)
145-
gameState = Config.getProperty(Config.LOAD_GAMESTATE_PROP, gameState);
145+
gameState = Config.getInstance().getProperty(Config.LOAD_GAMESTATE_PROP, gameState);
146146

147147
if (gameState != null) {
148148
try {
@@ -165,7 +165,7 @@ public void create() {
165165
}
166166

167167
if (recordName == null)
168-
recordName = Config.getProperty(Config.PLAY_RECORD_PROP, recordName);
168+
recordName = Config.getInstance().getProperty(Config.PLAY_RECORD_PROP, recordName);
169169

170170
if (recordName != null) {
171171
ui.getRecorder().setFilename(recordName);

blade-engine/src/com/bladecoder/engine/actions/IfPropertyAction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public boolean run(VerbRunner cb) {
4242
String valDest = w.getCustomProperty(name);
4343

4444
if (valDest == null)
45-
valDest = Config.getProperty(name, null);
45+
valDest = Config.getInstance().getProperty(name, null);
46+
47+
if (valDest == null)
48+
valDest = Config.getInstance().getPref(name, null);
4649

4750
if (!ActionUtils.compareNullStr(value, valDest)) {
4851
gotoElse(cb);

blade-engine/src/com/bladecoder/engine/assets/EngineAssetManager.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,10 @@ public static EngineAssetManager getInstance() {
134134
/**
135135
* Creates a EngineAssetManager instance for edition. That is:
136136
*
137-
* - Puts a PathResolver to locate the assets through an absolute path -
138-
* Puts assets scale to "1"
137+
* - Puts a PathResolver to locate the assets through an absolute path - Puts
138+
* assets scale to "1"
139139
*
140-
* @param base
141-
* is the project base folder
140+
* @param base is the project base folder
142141
*/
143142
public static void createEditInstance(String base) {
144143
if (instance != null)
@@ -152,8 +151,7 @@ public static void createEditInstance(String base) {
152151
/**
153152
* All assets will be searched in the selected folder.
154153
*
155-
* @param base
156-
* The asset base folder
154+
* @param base The asset base folder
157155
*/
158156
public static void setAssetFolder(String base) {
159157
if (instance != null)
@@ -194,8 +192,7 @@ public FileHandle getModelFile(String filename) {
194192
}
195193

196194
/**
197-
* Returns a file in the asset directory SEARCHING in the resolution
198-
* directories
195+
* Returns a file in the asset directory SEARCHING in the resolution directories
199196
*/
200197
public FileHandle getResAsset(String filename) {
201198
return resResolver.resolve(filename);
@@ -256,6 +253,7 @@ public Texture getTexture(String filename) {
256253
return get(filename, Texture.class);
257254
}
258255

256+
@Override
259257
public void dispose() {
260258
super.dispose();
261259
instance = null;
@@ -356,20 +354,20 @@ public boolean assetExists(String filename) {
356354
}
357355

358356
private Resolution[] getResolutions(FileHandleResolver resolver, int worldWidth, int worldHeight) {
359-
ArrayList<Resolution> rl = new ArrayList<Resolution>();
357+
ArrayList<Resolution> rl = new ArrayList<>();
360358

361359
String list[] = null;
362-
363-
String configRes = Config.getProperty(Config.RESOLUTIONS, null);
364-
365-
if(configRes != null) {
360+
361+
String configRes = Config.getInstance().getProperty(Config.RESOLUTIONS, null);
362+
363+
if (configRes != null) {
366364
list = configRes.split(",");
367365
} else {
368366
list = listAssetFiles("ui");
369367
}
370-
368+
371369
for (String name : list) {
372-
370+
373371
try {
374372
float scale = Float.parseFloat(name);
375373

@@ -384,6 +382,7 @@ private Resolution[] getResolutions(FileHandleResolver resolver, int worldWidth,
384382
}
385383

386384
Collections.sort(rl, new Comparator<Resolution>() {
385+
@Override
387386
public int compare(Resolution a, Resolution b) {
388387
return a.portraitWidth - b.portraitWidth;
389388
}
@@ -443,8 +442,8 @@ public String[] listAssetFiles(String base) {
443442
private String[] getFilesFromJar(String base) {
444443
URL dirURL = EngineAssetManager.class.getResource(base);
445444

446-
Set<String> result = new HashSet<String>(); // avoid duplicates in case
447-
// it is a subdirectory
445+
Set<String> result = new HashSet<>(); // avoid duplicates in case
446+
// it is a subdirectory
448447

449448
if (dirURL.getProtocol().equals("jar")) {
450449
/* A JAR path */
@@ -488,15 +487,21 @@ private String[] getFilesFromJar(String base) {
488487
}
489488

490489
public FileHandle getUserFile(String filename) {
490+
String desktopFolder = Config.getInstance().getProperty(Config.TITLE_PROP, DESKTOP_PREFS_DIR);
491+
return getUserFile(filename, desktopFolder);
492+
}
493+
494+
public FileHandle getUserFile(String filename, String desktopFolder) {
491495
FileHandle file = null;
492496

493-
if (Gdx.app.getType() == ApplicationType.Desktop || Gdx.app.getType() == ApplicationType.Applet) {
494-
String dir = Config.getProperty(Config.TITLE_PROP, DESKTOP_PREFS_DIR);
497+
if (Gdx.app.getType() == ApplicationType.Desktop) {
498+
String dir = desktopFolder != null ? desktopFolder : DESKTOP_PREFS_DIR;
499+
495500
dir.replace(" ", "");
496501

497502
StringBuilder sb = new StringBuilder();
498503
sb.append(".").append(dir).append("/").append(filename);
499-
504+
500505
if (System.getProperty("os.name").toLowerCase().contains("mac")
501506
&& System.getenv("HOME").contains("Containers")) {
502507

@@ -515,12 +520,12 @@ public FileHandle getUserFile(String filename) {
515520
public FileHandle getUserFolder() {
516521
FileHandle file = null;
517522

518-
if (Gdx.app.getType() == ApplicationType.Desktop || Gdx.app.getType() == ApplicationType.Applet) {
519-
String dir = Config.getProperty(Config.TITLE_PROP, DESKTOP_PREFS_DIR);
523+
if (Gdx.app.getType() == ApplicationType.Desktop) {
524+
String dir = Config.getInstance().getProperty(Config.TITLE_PROP, DESKTOP_PREFS_DIR);
520525
dir.replace(" ", "");
521526

522527
StringBuilder sb = new StringBuilder(".");
523-
528+
524529
if (System.getProperty("os.name").toLowerCase().contains("mac")
525530
&& System.getenv("HOME").contains("Containers")) {
526531

@@ -529,7 +534,7 @@ public FileHandle getUserFolder() {
529534

530535
file = Gdx.files.external(sb.append(dir).toString());
531536
}
532-
537+
533538
} else {
534539
file = Gdx.files.local(NOT_DESKTOP_PREFS_DIR);
535540
}

blade-engine/src/com/bladecoder/engine/model/TextManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class TextManager implements Serializable {
4646
public static final float RECT_MARGIN = 18f;
4747
public static final float RECT_BORDER = 2f;
4848

49-
public static final boolean AUTO_HIDE_TEXTS = Config.getProperty(Config.AUTO_HIDE_TEXTS, true);
49+
public static final boolean AUTO_HIDE_TEXTS = Config.getInstance().getProperty(Config.AUTO_HIDE_TEXTS, true);
5050

5151
private float inScreenTime;
5252
private Text currentText = null;

blade-engine/src/com/bladecoder/engine/serialization/WorldSerialization.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public void saveGameState(String filename, boolean screenshot) throws IOExceptio
257257
public void write(Json json) {
258258
BladeJson bjson = (BladeJson) json;
259259

260-
json.writeValue(Config.BLADE_ENGINE_VERSION_PROP, Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, null));
260+
json.writeValue(Config.BLADE_ENGINE_VERSION_PROP, Config.getInstance().getProperty(Config.BLADE_ENGINE_VERSION_PROP, null));
261261

262262
if (bjson.getMode() == Mode.MODEL) {
263263
SortedMap<String, SoundDesc> sortedSounds = new TreeMap<>();
@@ -271,7 +271,7 @@ public void write(Json json) {
271271
json.writeValue("initScene", w.getInitScene());
272272

273273
} else {
274-
json.writeValue(Config.VERSION_PROP, Config.getProperty(Config.VERSION_PROP, null));
274+
json.writeValue(Config.VERSION_PROP, Config.getInstance().getProperty(Config.VERSION_PROP, null));
275275

276276
SortedMap<String, Scene> sortedScenes = new TreeMap<>();
277277
sortedScenes.putAll(w.getScenes());
@@ -313,9 +313,9 @@ public void read(Json json, JsonValue jsonData) {
313313
BladeJson bjson = (BladeJson) json;
314314
if (bjson.getMode() == Mode.MODEL) {
315315
if (bladeVersion != null
316-
&& !bladeVersion.equals(Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
316+
&& !bladeVersion.equals(Config.getInstance().getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
317317
EngineLogger.debug("Model Engine Version v" + bladeVersion + " differs from Current Engine Version v"
318-
+ Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
318+
+ Config.getInstance().getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
319319
}
320320

321321
// SOUNDS
@@ -360,10 +360,10 @@ public void read(Json json, JsonValue jsonData) {
360360
cacheSounds();
361361
} else {
362362
if (bladeVersion != null
363-
&& !bladeVersion.equals(Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
363+
&& !bladeVersion.equals(Config.getInstance().getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
364364
EngineLogger
365365
.debug("Saved Game Engine Version v" + bladeVersion + " differs from Current Engine Version v"
366-
+ Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
366+
+ Config.getInstance().getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
367367
}
368368

369369
String currentChapter = json.readValue("chapter", String.class, jsonData);

blade-engine/src/com/bladecoder/engine/ui/DebugScreen.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,11 @@ public void clicked(InputEvent event, float x, float y) {
407407
table.add(botGroup2);
408408

409409
// ------------- VERSION LABEL NOT IN TABLE
410-
String versionString = Config.getProperty(Config.TITLE_PROP, "title unspecified") + " v"
411-
+ Config.getProperty(Config.VERSION_PROP, "unspecified") + "\n" + "Blade Engine: v"
412-
+ Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, "unspecified") + "\n" + "libGdx: v"
413-
+ Config.getProperty("gdxVersion", "unspecified") + "\n" + "RoboVM: v"
414-
+ Config.getProperty("roboVMVersion", "unspecified") + "\n";
410+
String versionString = Config.getInstance().getProperty(Config.TITLE_PROP, "title unspecified") + " v"
411+
+ Config.getInstance().getProperty(Config.VERSION_PROP, "unspecified") + "\n" + "Blade Engine: v"
412+
+ Config.getInstance().getProperty(Config.BLADE_ENGINE_VERSION_PROP, "unspecified") + "\n" + "libGdx: v"
413+
+ Config.getInstance().getProperty("gdxVersion", "unspecified") + "\n" + "RoboVM: v"
414+
+ Config.getInstance().getProperty("roboVMVersion", "unspecified") + "\n";
415415
// + "Gdx.app.getVersion: " + Gdx.app.getVersion();
416416

417417
Label version = new Label(versionString, ui.getSkin(), "debug");

blade-engine/src/com/bladecoder/engine/ui/HelpScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void dispose() {
116116
public void show() {
117117
final Locale locale = ui.getWorld().getI18N().getCurrentLocale();
118118
String filename = null;
119-
UIModes uiMode = UIModes.valueOf(Config.getProperty(Config.UI_MODE, "TWO_BUTTONS").toUpperCase(Locale.ENGLISH));
119+
UIModes uiMode = UIModes.valueOf(Config.getInstance().getProperty(Config.UI_MODE, "TWO_BUTTONS").toUpperCase(Locale.ENGLISH));
120120

121121
if (Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen) && uiMode == UIModes.TWO_BUTTONS) {
122122
uiMode = UIModes.PIE;

blade-engine/src/com/bladecoder/engine/ui/InventoryUI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ public enum InventoryPos {
6464

6565
private final ScenePointer pointer;
6666

67-
private boolean singleAction = Config.getProperty(Config.SINGLE_ACTION_INVENTORY, false);
67+
private boolean singleAction = Config.getInstance().getProperty(Config.SINGLE_ACTION_INVENTORY, false);
6868

6969
public InventoryUI(SceneScreen scr, ScenePointer pointer) {
7070
style = scr.getUI().getSkin().get(InventoryUIStyle.class);
7171
sceneScreen = scr;
7272
this.pointer = pointer;
7373

7474
inventoryPos = InventoryPos
75-
.valueOf(Config.getProperty(Config.INVENTORY_POS_PROP, "DOWN").toUpperCase(Locale.ENGLISH));
75+
.valueOf(Config.getInstance().getProperty(Config.INVENTORY_POS_PROP, "DOWN").toUpperCase(Locale.ENGLISH));
7676

77-
autosize = Config.getProperty(Config.INVENTORY_AUTOSIZE_PROP, true);
77+
autosize = Config.getInstance().getProperty(Config.INVENTORY_AUTOSIZE_PROP, true);
7878

7979
addListener(new InputListener() {
8080
@Override

blade-engine/src/com/bladecoder/engine/ui/MenuScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public boolean keyUp(InputEvent event, int keycode) {
168168

169169
if (style.showTitle && style.titleStyle != null) {
170170

171-
Label title = new Label(Config.getProperty(Config.TITLE_PROP, "Adventure Blade Engine"), skin,
171+
Label title = new Label(Config.getInstance().getProperty(Config.TITLE_PROP, "Adventure Blade Engine"), skin,
172172
style.titleStyle);
173173

174174
title.setAlignment(getAlign());
@@ -338,7 +338,7 @@ public void clicked(InputEvent event, float x, float y) {
338338
iconStackTable.pack();
339339
stage.addActor(iconStackTable);
340340

341-
Label version = new Label("v" + Config.getProperty(Config.VERSION_PROP, " unspecified"), skin);
341+
Label version = new Label("v" + Config.getInstance().getProperty(Config.VERSION_PROP, " unspecified"), skin);
342342
version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize());
343343
version.addListener(new ClickListener() {
344344
int count = 0;

blade-engine/src/com/bladecoder/engine/ui/TesterBot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class TesterBot {
6262

6363
public TesterBot(World w) {
6464
this.w = w;
65-
inventoryAction = !Config.getProperty(Config.SINGLE_ACTION_INVENTORY, false);
65+
inventoryAction = !Config.getInstance().getProperty(Config.SINGLE_ACTION_INVENTORY, false);
6666
}
6767

6868
public void update(float d) {

blade-engine/src/com/bladecoder/engine/ui/TextManagerUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ private void calcPos() {
134134
}
135135

136136
// CHAR ICON CALCS
137-
if (text.type == Text.Type.SUBTITLE && !Config.getProperty(Config.CHARACTER_ICON_ATLAS, "").equals("")
137+
if (text.type == Text.Type.SUBTITLE && !Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, "").equals("")
138138
&& text.actorId != null) {
139-
charIcon = EngineAssetManager.getInstance().getRegion(Config.getProperty(Config.CHARACTER_ICON_ATLAS, null),
139+
charIcon = EngineAssetManager.getInstance().getRegion(Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, null),
140140
text.actorId);
141141

142142
if (charIcon != null) {

blade-engine/src/com/bladecoder/engine/ui/UI.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public TesterBot getTesterBot() {
104104
}
105105

106106
private BladeScreen getCustomScreenInstance(String prop, Class<?> defaultClass) {
107-
String clsName = Config.getProperty(prop, null);
107+
String clsName = Config.getInstance().getProperty(prop, null);
108108
Class<?> instanceClass = defaultClass;
109109

110110
if (clsName != null && !clsName.isEmpty()) {
@@ -193,8 +193,8 @@ private void loadAssets() {
193193

194194
skin.load(skinFile);
195195

196-
if (!Config.getProperty(Config.CHARACTER_ICON_ATLAS, "").equals("")) {
197-
EngineAssetManager.getInstance().loadAtlas(Config.getProperty(Config.CHARACTER_ICON_ATLAS, null));
196+
if (!Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, "").equals("")) {
197+
EngineAssetManager.getInstance().loadAtlas(Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, null));
198198
EngineAssetManager.getInstance().finishLoading();
199199
}
200200
}
@@ -222,8 +222,8 @@ public void dispose() {
222222
RectangleRenderer.dispose();
223223
Utils3D.dispose();
224224

225-
if (!Config.getProperty(Config.CHARACTER_ICON_ATLAS, "").equals(""))
226-
EngineAssetManager.getInstance().disposeAtlas(Config.getProperty(Config.CHARACTER_ICON_ATLAS, null));
225+
if (!Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, "").equals(""))
226+
EngineAssetManager.getInstance().disposeAtlas(Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, null));
227227

228228
// DISPOSE ALL SCREENS
229229
for (BladeScreen s : screens)

0 commit comments

Comments
 (0)