Skip to content

Commit

Permalink
Load/Save preferences support.
Browse files Browse the repository at this point in the history
  • Loading branch information
bladecoder committed Jan 9, 2020
1 parent daa7ae3 commit 9b6552b
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 74 deletions.
14 changes: 7 additions & 7 deletions blade-engine/src/com/bladecoder/engine/BladeEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void loadGame(String baseFolder) {

if (baseFolder != null) {
EngineAssetManager.setAssetFolder(baseFolder);
Config.load();
Config.getInstance().load();
}

try {
Expand All @@ -105,15 +105,15 @@ public void loadGame(String baseFolder) {
@Override
public void create() {
if (!debug)
debug = Config.getProperty(Config.DEBUG_PROP, debug);
debug = Config.getInstance().getProperty(Config.DEBUG_PROP, debug);

if (debug)
EngineLogger.setDebug();

EngineLogger.debug("GAME CREATE");

if (forceRes == null)
forceRes = Config.getProperty(Config.FORCE_RES_PROP, forceRes);
forceRes = Config.getInstance().getProperty(Config.FORCE_RES_PROP, forceRes);

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

if (EngineLogger.debugMode()) {
if (chapter == null)
chapter = Config.getProperty(Config.CHAPTER_PROP, chapter);
chapter = Config.getInstance().getProperty(Config.CHAPTER_PROP, chapter);

if (testScene == null) {
testScene = Config.getProperty(Config.TEST_SCENE_PROP, testScene);
testScene = Config.getInstance().getProperty(Config.TEST_SCENE_PROP, testScene);
}

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

if (gameState == null)
gameState = Config.getProperty(Config.LOAD_GAMESTATE_PROP, gameState);
gameState = Config.getInstance().getProperty(Config.LOAD_GAMESTATE_PROP, gameState);

if (gameState != null) {
try {
Expand All @@ -165,7 +165,7 @@ public void create() {
}

if (recordName == null)
recordName = Config.getProperty(Config.PLAY_RECORD_PROP, recordName);
recordName = Config.getInstance().getProperty(Config.PLAY_RECORD_PROP, recordName);

if (recordName != null) {
ui.getRecorder().setFilename(recordName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public boolean run(VerbRunner cb) {
String valDest = w.getCustomProperty(name);

if (valDest == null)
valDest = Config.getProperty(name, null);
valDest = Config.getInstance().getProperty(name, null);

if (valDest == null)
valDest = Config.getInstance().getPref(name, null);

if (!ActionUtils.compareNullStr(value, valDest)) {
gotoElse(cb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ public static EngineAssetManager getInstance() {
/**
* Creates a EngineAssetManager instance for edition. That is:
*
* - Puts a PathResolver to locate the assets through an absolute path -
* Puts assets scale to "1"
* - Puts a PathResolver to locate the assets through an absolute path - Puts
* assets scale to "1"
*
* @param base
* is the project base folder
* @param base is the project base folder
*/
public static void createEditInstance(String base) {
if (instance != null)
Expand All @@ -152,8 +151,7 @@ public static void createEditInstance(String base) {
/**
* All assets will be searched in the selected folder.
*
* @param base
* The asset base folder
* @param base The asset base folder
*/
public static void setAssetFolder(String base) {
if (instance != null)
Expand Down Expand Up @@ -194,8 +192,7 @@ public FileHandle getModelFile(String filename) {
}

/**
* Returns a file in the asset directory SEARCHING in the resolution
* directories
* Returns a file in the asset directory SEARCHING in the resolution directories
*/
public FileHandle getResAsset(String filename) {
return resResolver.resolve(filename);
Expand Down Expand Up @@ -256,6 +253,7 @@ public Texture getTexture(String filename) {
return get(filename, Texture.class);
}

@Override
public void dispose() {
super.dispose();
instance = null;
Expand Down Expand Up @@ -356,20 +354,20 @@ public boolean assetExists(String filename) {
}

private Resolution[] getResolutions(FileHandleResolver resolver, int worldWidth, int worldHeight) {
ArrayList<Resolution> rl = new ArrayList<Resolution>();
ArrayList<Resolution> rl = new ArrayList<>();

String list[] = null;
String configRes = Config.getProperty(Config.RESOLUTIONS, null);
if(configRes != null) {

String configRes = Config.getInstance().getProperty(Config.RESOLUTIONS, null);

if (configRes != null) {
list = configRes.split(",");
} else {
list = listAssetFiles("ui");
}

for (String name : list) {

try {
float scale = Float.parseFloat(name);

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

Collections.sort(rl, new Comparator<Resolution>() {
@Override
public int compare(Resolution a, Resolution b) {
return a.portraitWidth - b.portraitWidth;
}
Expand Down Expand Up @@ -443,8 +442,8 @@ public String[] listAssetFiles(String base) {
private String[] getFilesFromJar(String base) {
URL dirURL = EngineAssetManager.class.getResource(base);

Set<String> result = new HashSet<String>(); // avoid duplicates in case
// it is a subdirectory
Set<String> result = new HashSet<>(); // avoid duplicates in case
// it is a subdirectory

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

public FileHandle getUserFile(String filename) {
String desktopFolder = Config.getInstance().getProperty(Config.TITLE_PROP, DESKTOP_PREFS_DIR);
return getUserFile(filename, desktopFolder);
}

public FileHandle getUserFile(String filename, String desktopFolder) {
FileHandle file = null;

if (Gdx.app.getType() == ApplicationType.Desktop || Gdx.app.getType() == ApplicationType.Applet) {
String dir = Config.getProperty(Config.TITLE_PROP, DESKTOP_PREFS_DIR);
if (Gdx.app.getType() == ApplicationType.Desktop) {
String dir = desktopFolder != null ? desktopFolder : DESKTOP_PREFS_DIR;

dir.replace(" ", "");

StringBuilder sb = new StringBuilder();
sb.append(".").append(dir).append("/").append(filename);

if (System.getProperty("os.name").toLowerCase().contains("mac")
&& System.getenv("HOME").contains("Containers")) {

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

if (Gdx.app.getType() == ApplicationType.Desktop || Gdx.app.getType() == ApplicationType.Applet) {
String dir = Config.getProperty(Config.TITLE_PROP, DESKTOP_PREFS_DIR);
if (Gdx.app.getType() == ApplicationType.Desktop) {
String dir = Config.getInstance().getProperty(Config.TITLE_PROP, DESKTOP_PREFS_DIR);
dir.replace(" ", "");

StringBuilder sb = new StringBuilder(".");

if (System.getProperty("os.name").toLowerCase().contains("mac")
&& System.getenv("HOME").contains("Containers")) {

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

file = Gdx.files.external(sb.append(dir).toString());
}

} else {
file = Gdx.files.local(NOT_DESKTOP_PREFS_DIR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TextManager implements Serializable {
public static final float RECT_MARGIN = 18f;
public static final float RECT_BORDER = 2f;

public static final boolean AUTO_HIDE_TEXTS = Config.getProperty(Config.AUTO_HIDE_TEXTS, true);
public static final boolean AUTO_HIDE_TEXTS = Config.getInstance().getProperty(Config.AUTO_HIDE_TEXTS, true);

private float inScreenTime;
private Text currentText = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void saveGameState(String filename, boolean screenshot) throws IOExceptio
public void write(Json json) {
BladeJson bjson = (BladeJson) json;

json.writeValue(Config.BLADE_ENGINE_VERSION_PROP, Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, null));
json.writeValue(Config.BLADE_ENGINE_VERSION_PROP, Config.getInstance().getProperty(Config.BLADE_ENGINE_VERSION_PROP, null));

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

} else {
json.writeValue(Config.VERSION_PROP, Config.getProperty(Config.VERSION_PROP, null));
json.writeValue(Config.VERSION_PROP, Config.getInstance().getProperty(Config.VERSION_PROP, null));

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

// SOUNDS
Expand Down Expand Up @@ -360,10 +360,10 @@ public void read(Json json, JsonValue jsonData) {
cacheSounds();
} else {
if (bladeVersion != null
&& !bladeVersion.equals(Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
&& !bladeVersion.equals(Config.getInstance().getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""))) {
EngineLogger
.debug("Saved Game Engine Version v" + bladeVersion + " differs from Current Engine Version v"
+ Config.getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
+ Config.getInstance().getProperty(Config.BLADE_ENGINE_VERSION_PROP, ""));
}

String currentChapter = json.readValue("chapter", String.class, jsonData);
Expand Down
10 changes: 5 additions & 5 deletions blade-engine/src/com/bladecoder/engine/ui/DebugScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ public void clicked(InputEvent event, float x, float y) {
table.add(botGroup2);

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

Label version = new Label(versionString, ui.getSkin(), "debug");
Expand Down
2 changes: 1 addition & 1 deletion blade-engine/src/com/bladecoder/engine/ui/HelpScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void dispose() {
public void show() {
final Locale locale = ui.getWorld().getI18N().getCurrentLocale();
String filename = null;
UIModes uiMode = UIModes.valueOf(Config.getProperty(Config.UI_MODE, "TWO_BUTTONS").toUpperCase(Locale.ENGLISH));
UIModes uiMode = UIModes.valueOf(Config.getInstance().getProperty(Config.UI_MODE, "TWO_BUTTONS").toUpperCase(Locale.ENGLISH));

if (Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen) && uiMode == UIModes.TWO_BUTTONS) {
uiMode = UIModes.PIE;
Expand Down
6 changes: 3 additions & 3 deletions blade-engine/src/com/bladecoder/engine/ui/InventoryUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ public enum InventoryPos {

private final ScenePointer pointer;

private boolean singleAction = Config.getProperty(Config.SINGLE_ACTION_INVENTORY, false);
private boolean singleAction = Config.getInstance().getProperty(Config.SINGLE_ACTION_INVENTORY, false);

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

inventoryPos = InventoryPos
.valueOf(Config.getProperty(Config.INVENTORY_POS_PROP, "DOWN").toUpperCase(Locale.ENGLISH));
.valueOf(Config.getInstance().getProperty(Config.INVENTORY_POS_PROP, "DOWN").toUpperCase(Locale.ENGLISH));

autosize = Config.getProperty(Config.INVENTORY_AUTOSIZE_PROP, true);
autosize = Config.getInstance().getProperty(Config.INVENTORY_AUTOSIZE_PROP, true);

addListener(new InputListener() {
@Override
Expand Down
4 changes: 2 additions & 2 deletions blade-engine/src/com/bladecoder/engine/ui/MenuScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public boolean keyUp(InputEvent event, int keycode) {

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

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

title.setAlignment(getAlign());
Expand Down Expand Up @@ -338,7 +338,7 @@ public void clicked(InputEvent event, float x, float y) {
iconStackTable.pack();
stage.addActor(iconStackTable);

Label version = new Label("v" + Config.getProperty(Config.VERSION_PROP, " unspecified"), skin);
Label version = new Label("v" + Config.getInstance().getProperty(Config.VERSION_PROP, " unspecified"), skin);
version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize());
version.addListener(new ClickListener() {
int count = 0;
Expand Down
2 changes: 1 addition & 1 deletion blade-engine/src/com/bladecoder/engine/ui/TesterBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class TesterBot {

public TesterBot(World w) {
this.w = w;
inventoryAction = !Config.getProperty(Config.SINGLE_ACTION_INVENTORY, false);
inventoryAction = !Config.getInstance().getProperty(Config.SINGLE_ACTION_INVENTORY, false);
}

public void update(float d) {
Expand Down
4 changes: 2 additions & 2 deletions blade-engine/src/com/bladecoder/engine/ui/TextManagerUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ private void calcPos() {
}

// CHAR ICON CALCS
if (text.type == Text.Type.SUBTITLE && !Config.getProperty(Config.CHARACTER_ICON_ATLAS, "").equals("")
if (text.type == Text.Type.SUBTITLE && !Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, "").equals("")
&& text.actorId != null) {
charIcon = EngineAssetManager.getInstance().getRegion(Config.getProperty(Config.CHARACTER_ICON_ATLAS, null),
charIcon = EngineAssetManager.getInstance().getRegion(Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, null),
text.actorId);

if (charIcon != null) {
Expand Down
10 changes: 5 additions & 5 deletions blade-engine/src/com/bladecoder/engine/ui/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public TesterBot getTesterBot() {
}

private BladeScreen getCustomScreenInstance(String prop, Class<?> defaultClass) {
String clsName = Config.getProperty(prop, null);
String clsName = Config.getInstance().getProperty(prop, null);
Class<?> instanceClass = defaultClass;

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

skin.load(skinFile);

if (!Config.getProperty(Config.CHARACTER_ICON_ATLAS, "").equals("")) {
EngineAssetManager.getInstance().loadAtlas(Config.getProperty(Config.CHARACTER_ICON_ATLAS, null));
if (!Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, "").equals("")) {
EngineAssetManager.getInstance().loadAtlas(Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, null));
EngineAssetManager.getInstance().finishLoading();
}
}
Expand Down Expand Up @@ -222,8 +222,8 @@ public void dispose() {
RectangleRenderer.dispose();
Utils3D.dispose();

if (!Config.getProperty(Config.CHARACTER_ICON_ATLAS, "").equals(""))
EngineAssetManager.getInstance().disposeAtlas(Config.getProperty(Config.CHARACTER_ICON_ATLAS, null));
if (!Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, "").equals(""))
EngineAssetManager.getInstance().disposeAtlas(Config.getInstance().getProperty(Config.CHARACTER_ICON_ATLAS, null));

// DISPOSE ALL SCREENS
for (BladeScreen s : screens)
Expand Down
Loading

0 comments on commit 9b6552b

Please sign in to comment.