diff --git a/RemixedDungeon/src/main/java/com/nyrds/pixeldungeon/windows/WndUiSettings.java b/RemixedDungeon/src/main/java/com/nyrds/pixeldungeon/windows/WndUiSettings.java index 5146eece7d..56b0d8907c 100644 --- a/RemixedDungeon/src/main/java/com/nyrds/pixeldungeon/windows/WndUiSettings.java +++ b/RemixedDungeon/src/main/java/com/nyrds/pixeldungeon/windows/WndUiSettings.java @@ -3,6 +3,7 @@ import com.nyrds.pixeldungeon.game.GameLoop; import com.nyrds.pixeldungeon.game.GamePreferences; +import com.nyrds.pixeldungeon.ml.BuildConfig; import com.nyrds.pixeldungeon.ml.R; import com.nyrds.platform.game.RemixedDungeon; import com.nyrds.platform.util.StringsManager; @@ -15,14 +16,15 @@ public class WndUiSettings extends WndMenuCommon { @Override protected void createItems() { - menuItems.add( new MenuCheckBox(R.string.WndSettings_Immersive, GamePreferences.immersed()) { - @Override - protected void onClick() { - super.onClick(); - GamePreferences.immerse(checked()); - } - }); - + if(BuildConfig.FLAVOR_platform.equals(Utils.PLATFORM_ANDROID)) { + menuItems.add(new MenuCheckBox(R.string.WndSettings_Immersive, GamePreferences.immersed()) { + @Override + protected void onClick() { + super.onClick(); + GamePreferences.immerse(checked()); + } + }); + } if(!GamePreferences.classicFont()){ menuItems.add(createTextScaleButtons()); } diff --git a/RemixedDungeon/src/main/java/com/watabou/pixeldungeon/utils/Utils.java b/RemixedDungeon/src/main/java/com/watabou/pixeldungeon/utils/Utils.java index 6179ba2c1b..f9e672ecf3 100644 --- a/RemixedDungeon/src/main/java/com/watabou/pixeldungeon/utils/Utils.java +++ b/RemixedDungeon/src/main/java/com/watabou/pixeldungeon/utils/Utils.java @@ -24,6 +24,7 @@ public class Utils { public static final String UNKNOWN = "unknown"; public static final String EMPTY_STRING = ""; public static final String[] EMPTY_STRING_ARRAY = new String[0]; + public static final String PLATFORM_ANDROID = "android"; @NotNull diff --git a/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/app/RemixedDungeonApp.java b/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/app/RemixedDungeonApp.java index 0b35838976..89fc3cfa70 100644 --- a/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/app/RemixedDungeonApp.java +++ b/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/app/RemixedDungeonApp.java @@ -2,8 +2,8 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; -import com.nyrds.pixeldungeon.game.GameLoop; import com.nyrds.platform.game.RemixedDungeon; +import com.nyrds.platform.util.PUtil; import java.io.IOException; @@ -54,6 +54,8 @@ public static void restartApp() { // Create the command to restart the application String[] command = new String[]{java,"--add-opens", "java.base/java.util=ALL-UNNAMED", "-Dhttps.protocols=TLSv1.2", "-cp", classPath, mainClass}; + PUtil.slog("app", "Restarting application with command: " + String.join(" ", command)); + // Execute the command Process process = runtime.exec(command); diff --git a/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/storage/Preferences.java b/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/storage/Preferences.java index 6361055481..1db5de7c94 100644 --- a/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/storage/Preferences.java +++ b/RemixedDungeonDesktop/src/libgdx/java/com/nyrds/platform/storage/Preferences.java @@ -1,7 +1,13 @@ package com.nyrds.platform.storage; -import com.badlogic.gdx.Gdx; - +import org.hjson.JsonObject; +import org.hjson.JsonValue; +import org.hjson.Stringify; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -9,34 +15,30 @@ public enum Preferences { INSTANCE; - public static final String KEY_IMMERSIVE = "immersive"; - public static final String KEY_MUSIC = "music"; - public static final String KEY_SOUND_FX = "soundfx"; - public static final String KEY_ZOOM = "zoom"; - public static final String KEY_LAST_CLASS = "last_class"; - public static final String KEY_DONATED = "donated"; - public static final String KEY_INTRO = "intro"; - public static final String KEY_BRIGHTNESS = "brightness"; - public static final String KEY_LOCALE = "locale"; - public static final String KEY_QUICKSLOTS = "quickslots"; - public static final String KEY_VERSION = "version"; - public static final String KEY_FONT_SCALE = "font_scale"; - public static final String KEY_CLASSIC_FONT = "classic_font"; + public static final String KEY_IMMERSIVE = "immersive"; + public static final String KEY_MUSIC = "music"; + public static final String KEY_SOUND_FX = "soundfx"; + public static final String KEY_ZOOM = "zoom"; + public static final String KEY_LAST_CLASS = "last_class"; + public static final String KEY_DONATED = "donated"; + public static final String KEY_INTRO = "intro"; + public static final String KEY_BRIGHTNESS = "brightness"; + public static final String KEY_LOCALE = "locale"; + public static final String KEY_QUICKSLOTS = "quickslots"; + public static final String KEY_VERSION = "version"; + public static final String KEY_FONT_SCALE = "font_scale"; + public static final String KEY_CLASSIC_FONT = "classic_font"; public static final String KEY_PREMIUM_SETTINGS = "premium_settings"; - public static final String KEY_REALTIME = "realtime"; - public static final String KEY_ACTIVE_MOD = "active_mod"; - public static final String KEY_COLLECT_STATS = "collect_stats"; + public static final String KEY_REALTIME = "realtime"; + public static final String KEY_ACTIVE_MOD = "active_mod"; + public static final String KEY_COLLECT_STATS = "collect_stats"; public static final String KEY_MOVE_TIMEOUT = "move_timeout"; public static final String KEY_USE_PLAY_GAMES = "use_play_games"; - public static final String KEY_UI_ZOOM = "ui_zoom"; public static final String KEY_VERSION_STRING = "version_string"; public static final String KEY_TOOL_STYLE = "tool_style"; public static final String KEY_HANDEDNESS = "handedness"; - - public static final String KEY_EU_CONSENT_LEVEL = "eu_consent_level"; public static final String KEY_USE_ISOMETRIC_TILES = "use_isometric_tiles"; - public static final String KEY_ISOMETRIC_TILES_PRESENTED = "isometric_tiles_presented"; public static final String KEY_TILES_QUESTION_ASKED = "tiles_question_asked"; private final Map intCache = new HashMap<>(); @@ -44,98 +46,94 @@ public enum Preferences { private final Map boolCache = new HashMap<>(); private final Map doubleCache = new HashMap<>(); - com.badlogic.gdx.Preferences prefs = Gdx.app.getPreferences("RemixedDungeon"); + private final File preferencesFile = new File("preferences.hjson"); + private JsonObject preferencesJson; - public int getInt(String key, int defValue) { + Preferences() { + loadPreferences(); + } + + private void loadPreferences() { + if (preferencesFile.exists()) { + try (FileReader reader = new FileReader(preferencesFile)) { + preferencesJson = JsonValue.readHjson(reader).asObject(); + } catch (IOException e) { + preferencesJson = new JsonObject(); + } + } else { + preferencesJson = new JsonObject(); + } + } + private void savePreferences() { + try (FileWriter writer = new FileWriter(preferencesFile)) { + preferencesJson.writeTo(writer, Stringify.HJSON); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public int getInt(String key, int defValue) { if (intCache.containsKey(key)) { return intCache.get(key); } - String defVal = Integer.toString(defValue); - String propVal = getString(key, defVal); - int value; - try { - value = Integer.parseInt(propVal); - } catch (NumberFormatException e) { - put(key, defValue); - value = defValue; - } - intCache.put(key,value); + int value = preferencesJson.getInt(key, defValue); + intCache.put(key, value); return value; } public double getDouble(String key, double defValue) { - - if(doubleCache.containsKey(key)) { + if (doubleCache.containsKey(key)) { return doubleCache.get(key); } - String defVal = Double.toString(defValue); - String propVal = getString(key, defVal); - - double value; - try { - value = Double.parseDouble(propVal); - } catch (NumberFormatException e) { - put(key, defValue); - value = defValue; - } - + double value = preferencesJson.getDouble(key, defValue); doubleCache.put(key, value); return value; } public boolean getBoolean(String key, boolean defValue) { - - if(boolCache.containsKey(key)) { + if (boolCache.containsKey(key)) { return boolCache.get(key); } - String defVal = Boolean.toString(defValue); - String propVal = getString(key, defVal); - boolean value = Boolean.parseBoolean(propVal); + boolean value = preferencesJson.getBoolean(key, defValue); boolCache.put(key, value); return value; } public String getString(String key, String defValue) { - - if(stringCache.containsKey(key)) { + if (stringCache.containsKey(key)) { return stringCache.get(key); } - return prefs.getString(key, defValue); + String value = preferencesJson.getString(key, defValue); + stringCache.put(key, value); + return value; } public void put(String key, int value) { - - intCache.put(key,value); - - String val = Integer.toString(value); - put(key, val); + intCache.put(key, value); + preferencesJson.set(key, value); + savePreferences(); } public void put(String key, double value) { - - doubleCache.put(key,value); - - String val = Double.toString(value); - put(key, val); + doubleCache.put(key, value); + preferencesJson.set(key, value); + savePreferences(); } public void put(String key, boolean value) { - - boolCache.put(key,value); - - String val = Boolean.toString(value); - put(key, val); + boolCache.put(key, value); + preferencesJson.set(key, value); + savePreferences(); } - public void put(String key, String value) { stringCache.put(key, value); - prefs.putString(key, value); - prefs.flush(); + preferencesJson.set(key, value); + savePreferences(); } -} +} \ No newline at end of file diff --git a/RemixedDungeonDesktop/src/market_none/java/com/nyrds/pixeldungeon/ml/BuildConfig.java b/RemixedDungeonDesktop/src/market_none/java/com/nyrds/pixeldungeon/ml/BuildConfig.java index d80a298b36..e500061c12 100644 --- a/RemixedDungeonDesktop/src/market_none/java/com/nyrds/pixeldungeon/ml/BuildConfig.java +++ b/RemixedDungeonDesktop/src/market_none/java/com/nyrds/pixeldungeon/ml/BuildConfig.java @@ -2,7 +2,6 @@ public class BuildConfig { public static final boolean DEBUG = false; - //public static final String ASSETS_PATH = "../assets/"; - public static final String ASSETS_PATH = "./"; public static final String SAVES_PATH = "./saves/"; + public static final String FLAVOR_platform = "desktop"; }