Skip to content

Commit

Permalink
CommonPrefs class
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhael-Danilov committed Jan 4, 2025
1 parent af9ea97 commit 84864dd
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,6 @@ public enum Preferences {

INSTANCE;

public static final String KEY_LANDSCAPE = "landscape";
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_CHALLENGES = "challenges";
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_CLASSIC_TTF_FONT = "classic_ttf_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_MOVE_TIMEOUT = "move_timeout";
public static final String KEY_USE_PLAY_GAMES = "use_play_games";
public static final String KEY_PLAY_GAMES_CONNECT_FAILURES = "play_games_connect_failures";

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_TILES_QUESTION_ASKED = "tiles_question_asked";

public static final String KEY_USE_SMOOTH_CAMERA = "use_smooth_camera";



private SharedPreferences prefs;

private final Map<String, Integer> intCache = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import android.annotation.SuppressLint;

import com.nyrds.platform.support.Ads;
import com.nyrds.platform.EventCollector;
import com.nyrds.platform.audio.MusicManager;
import com.nyrds.platform.audio.Sample;
import com.nyrds.platform.game.Game;
import com.nyrds.platform.game.RemixedDungeon;
import com.nyrds.platform.gfx.SystemText;
import com.nyrds.platform.storage.CommonPrefs;
import com.nyrds.platform.storage.Preferences;
import com.nyrds.platform.support.Ads;
import com.nyrds.platform.util.StringsManager;
import com.nyrds.util.ModdingMode;
import com.watabou.pixeldungeon.Assets;
Expand All @@ -23,119 +24,119 @@

public class GamePreferences {
public static void zoom(double value) {
Preferences.INSTANCE.put(Preferences.KEY_ZOOM, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_ZOOM, value);
}

public static double zoom() {
return Preferences.INSTANCE.getDouble(Preferences.KEY_ZOOM, 0);
return Preferences.INSTANCE.getDouble(CommonPrefs.KEY_ZOOM, 0);
}

public static void music(boolean value) {
MusicManager.INSTANCE.enable(value);
Preferences.INSTANCE.put(Preferences.KEY_MUSIC, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_MUSIC, value);
}

public static boolean music() {
return Preferences.INSTANCE.getBoolean(Preferences.KEY_MUSIC, true);
return Preferences.INSTANCE.getBoolean(CommonPrefs.KEY_MUSIC, true);
}

public static void soundFx(boolean value) {
Sample.INSTANCE.enable(value);
Preferences.INSTANCE.put(Preferences.KEY_SOUND_FX, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_SOUND_FX, value);
}

public static boolean soundFx() {
return Preferences.INSTANCE.getBoolean(Preferences.KEY_SOUND_FX, true);
return Preferences.INSTANCE.getBoolean(CommonPrefs.KEY_SOUND_FX, true);
}

public static void brightness(boolean value) {
Preferences.INSTANCE.put(Preferences.KEY_BRIGHTNESS, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_BRIGHTNESS, value);
if (GameLoop.scene() instanceof GameScene) {
((GameScene) GameLoop.scene()).brightness(value);
}
}

public static boolean brightness() {
return Preferences.INSTANCE.getBoolean(Preferences.KEY_BRIGHTNESS,
return Preferences.INSTANCE.getBoolean(CommonPrefs.KEY_BRIGHTNESS,
false);
}

private static void donated(int value) {
Preferences.INSTANCE.put(Preferences.KEY_DONATED, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_DONATED, value);
}

public static int donated() {
return Preferences.INSTANCE.getInt(Preferences.KEY_DONATED, 0);
return Preferences.INSTANCE.getInt(CommonPrefs.KEY_DONATED, 0);
}

public static void lastClass(int value) {
Preferences.INSTANCE.put(Preferences.KEY_LAST_CLASS, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_LAST_CLASS, value);
}

public static int lastClass() {
return Preferences.INSTANCE.getInt(Preferences.KEY_LAST_CLASS, 0);
return Preferences.INSTANCE.getInt(CommonPrefs.KEY_LAST_CLASS, 0);
}

public static void intro(boolean value) {
Preferences.INSTANCE.put(Preferences.KEY_INTRO, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_INTRO, value);
}

public static boolean intro() {
return Preferences.INSTANCE.getBoolean(Preferences.KEY_INTRO, true);
return Preferences.INSTANCE.getBoolean(CommonPrefs.KEY_INTRO, true);
}

public static String uiLanguage() {
String deviceLocale = Locale.getDefault().getLanguage();
EventCollector.setSessionData("device_locale", deviceLocale);
return Preferences.INSTANCE.getString(Preferences.KEY_LOCALE,
return Preferences.INSTANCE.getString(CommonPrefs.KEY_LOCALE,
deviceLocale);
}

public static void uiLanguage(String lang) {
Preferences.INSTANCE.put(Preferences.KEY_LOCALE, lang);
Preferences.INSTANCE.put(CommonPrefs.KEY_LOCALE, lang);

setSelectedLanguage();
GameLoop.resetScene();
}

public static void version(int value) {
Preferences.INSTANCE.put( Preferences.KEY_VERSION, value );
Preferences.INSTANCE.put( CommonPrefs.KEY_VERSION, value );
}

public static int version() {
return Preferences.INSTANCE.getInt( Preferences.KEY_VERSION, 0 );
return Preferences.INSTANCE.getInt( CommonPrefs.KEY_VERSION, 0 );
}

public static void versionString(String value) {
Preferences.INSTANCE.put( Preferences.KEY_VERSION_STRING, value );
Preferences.INSTANCE.put( CommonPrefs.KEY_VERSION_STRING, value );
}

public static String versionString() {
return Preferences.INSTANCE.getString( Preferences.KEY_VERSION_STRING, Utils.UNKNOWN);
return Preferences.INSTANCE.getString( CommonPrefs.KEY_VERSION_STRING, Utils.UNKNOWN);
}

public static void fontScale(int value) {
Preferences.INSTANCE.put(Preferences.KEY_FONT_SCALE, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_FONT_SCALE, value);
SystemText.updateFontScale();
}

public static int fontScale() {
return Preferences.INSTANCE.getInt(Preferences.KEY_FONT_SCALE, 0);
return Preferences.INSTANCE.getInt(CommonPrefs.KEY_FONT_SCALE, 0);
}

public static boolean classicFont() {
boolean val = Preferences.INSTANCE.getBoolean(Preferences.KEY_CLASSIC_FONT, false);
boolean val = Preferences.INSTANCE.getBoolean(CommonPrefs.KEY_CLASSIC_FONT, false);
ModdingMode.setClassicTextRenderingMode(val);
return val;
}

public static void classicFont(boolean value) {
ModdingMode.setClassicTextRenderingMode(value);
Preferences.INSTANCE.put(Preferences.KEY_CLASSIC_FONT, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_CLASSIC_FONT, value);
}

public static void activeMod(String mod) {
Preferences.INSTANCE.put(Preferences.KEY_ACTIVE_MOD, mod);
Preferences.INSTANCE.put(CommonPrefs.KEY_ACTIVE_MOD, mod);
ModdingMode.selectMod(activeMod());

setSelectedLanguage();
Expand All @@ -146,21 +147,21 @@ public static void activeMod(String mod) {
}

public static String activeMod() {
return Preferences.INSTANCE.getString(Preferences.KEY_ACTIVE_MOD, ModdingMode.REMIXED);
return Preferences.INSTANCE.getString(CommonPrefs.KEY_ACTIVE_MOD, ModdingMode.REMIXED);
}

public static boolean realtime() {
return Preferences.INSTANCE.getBoolean(Preferences.KEY_REALTIME, false);
return Preferences.INSTANCE.getBoolean(CommonPrefs.KEY_REALTIME, false);
}

public static void realtime(boolean value) {
Preferences.INSTANCE.put(Preferences.KEY_REALTIME, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_REALTIME, value);
}

// *** IMMERSIVE MODE ****
@SuppressLint("NewApi")
public static void immerse(boolean value) {
Preferences.INSTANCE.put(Preferences.KEY_IMMERSIVE, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_IMMERSIVE, value);

GameLoop.runOnMainThread(() -> {
RemixedDungeon.updateImmersiveMode();
Expand All @@ -170,7 +171,7 @@ public static void immerse(boolean value) {

public static boolean immersed() {
return Preferences.INSTANCE
.getBoolean(Preferences.KEY_IMMERSIVE, true);
.getBoolean(CommonPrefs.KEY_IMMERSIVE, true);
}

/*
Expand Down Expand Up @@ -202,11 +203,11 @@ public static void setDifficulty(int _difficulty) {

//--- Move timeouts
public static int moveTimeout() {
return Preferences.INSTANCE.getInt(Preferences.KEY_MOVE_TIMEOUT, Integer.MAX_VALUE);
return Preferences.INSTANCE.getInt(CommonPrefs.KEY_MOVE_TIMEOUT, Integer.MAX_VALUE);
}

public static void moveTimeout(int value) {
Preferences.INSTANCE.put(Preferences.KEY_MOVE_TIMEOUT,value);
Preferences.INSTANCE.put(CommonPrefs.KEY_MOVE_TIMEOUT,value);
}

public static int limitTimeoutIndex(int value) {
Expand All @@ -218,33 +219,33 @@ public static double getMoveTimeout() {
}

public static int quickSlots() {
return Preferences.INSTANCE.getInt(Preferences.KEY_QUICKSLOTS, -1);
return Preferences.INSTANCE.getInt(CommonPrefs.KEY_QUICKSLOTS, -1);
}

public static void quickSlots(int slots) {
Preferences.INSTANCE.put(Preferences.KEY_QUICKSLOTS, slots);
Preferences.INSTANCE.put(CommonPrefs.KEY_QUICKSLOTS, slots);
if (GameLoop.scene() instanceof GameScene) {
((GameScene) GameLoop.scene()).updateToolbar(false);
}
}

public static String toolStyle() {
return Preferences.INSTANCE.getString(Preferences.KEY_TOOL_STYLE, Tool.Size.Std.name());
return Preferences.INSTANCE.getString(CommonPrefs.KEY_TOOL_STYLE, Tool.Size.Std.name());
}

public static void toolStyle(String style) {
Preferences.INSTANCE.put(Preferences.KEY_TOOL_STYLE, style);
Preferences.INSTANCE.put(CommonPrefs.KEY_TOOL_STYLE, style);
if (GameLoop.scene() instanceof GameScene) {
((GameScene) GameLoop.scene()).updateToolbar(true);
}
}

public static Boolean handedness() {
return Preferences.INSTANCE.getBoolean(Preferences.KEY_HANDEDNESS, false);
return Preferences.INSTANCE.getBoolean(CommonPrefs.KEY_HANDEDNESS, false);
}

public static void handedness(Boolean left) {
Preferences.INSTANCE.put(Preferences.KEY_HANDEDNESS, left);
Preferences.INSTANCE.put(CommonPrefs.KEY_HANDEDNESS, left);
if (GameLoop.scene() instanceof GameScene) {
((GameScene) GameLoop.scene()).updateToolbar(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.nyrds.pixeldungeon.game.GameLoop;
import com.nyrds.pixeldungeon.game.GamePreferences;
import com.nyrds.pixeldungeon.ml.R;
import com.nyrds.platform.storage.CommonPrefs;
import com.nyrds.platform.storage.Preferences;
import com.nyrds.platform.util.StringsManager;
import com.watabou.pixeldungeon.scenes.GameScene;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void onDefault(Selector s) {
private void uiZoom(float value, Selector s) {
PixelScene.uiCamera.updateFullscreenCameraZoom(value);
((GameScene) GameLoop.scene()).updateUiCamera();
Preferences.INSTANCE.put(Preferences.KEY_UI_ZOOM, value);
Preferences.INSTANCE.put(CommonPrefs.KEY_UI_ZOOM, value);

float zoom = PixelScene.uiCamera.zoom;
s.enable(zoom < PixelScene.maxZoom, zoom > PixelScene.minZoom, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.nyrds.LuaInterface;
import com.nyrds.pixeldungeon.ml.R;
import com.nyrds.platform.storage.CommonPrefs;
import com.nyrds.platform.storage.Preferences;
import com.nyrds.util.GuiProperties;
import com.watabou.noosa.Image;
Expand Down Expand Up @@ -66,12 +67,12 @@ public void onClick() {

@LuaInterface
public boolean shownBefore() {
return Preferences.INSTANCE.getBoolean(Preferences.KEY_TILES_QUESTION_ASKED, false);
return Preferences.INSTANCE.getBoolean(CommonPrefs.KEY_TILES_QUESTION_ASKED, false);
}

private void setTilesMode(boolean newTiles) {
Preferences.INSTANCE.put(Preferences.KEY_TILES_QUESTION_ASKED, true);
Preferences.INSTANCE.put(Preferences.KEY_USE_ISOMETRIC_TILES, newTiles);
Preferences.INSTANCE.put(CommonPrefs.KEY_TILES_QUESTION_ASKED, true);
Preferences.INSTANCE.put(CommonPrefs.KEY_USE_ISOMETRIC_TILES, newTiles);
Dungeon.setIsometricMode(newTiles);
hide();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.nyrds.platform.storage;

public class CommonPrefs {
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_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_USE_ISOMETRIC_TILES = "use_isometric_tiles";
public static final String KEY_TILES_QUESTION_ASKED = "tiles_question_asked";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package com.watabou.pixeldungeon;

import com.nyrds.pixeldungeon.ml.R;
import com.nyrds.platform.storage.CommonPrefs;
import com.nyrds.platform.storage.Preferences;
import com.nyrds.platform.util.StringsManager;
import com.watabou.pixeldungeon.utils.Utils;
Expand Down Expand Up @@ -170,7 +171,7 @@ public class Assets {
static {
Bundle premiumSettings;
try {
premiumSettings = new Bundle(Preferences.INSTANCE.getString(Preferences.KEY_PREMIUM_SETTINGS, Utils.EMPTY_STRING));
premiumSettings = new Bundle(Preferences.INSTANCE.getString(CommonPrefs.KEY_PREMIUM_SETTINGS, Utils.EMPTY_STRING));
chromeType = premiumSettings.getInt(KEY_CHROME);
statusType = premiumSettings.getInt(KEY_STATUS);
toolbarType = premiumSettings.getInt(KEY_TOOLBAR);
Expand Down Expand Up @@ -249,7 +250,7 @@ public static void use(String assetKind, int index) {
premiumSettings.put(KEY_TOOLBAR, toolbarType);
premiumSettings.put(KEY_BANNERS, bannersType);

Preferences.INSTANCE.put(Preferences.KEY_PREMIUM_SETTINGS, premiumSettings.serialize());
Preferences.INSTANCE.put(CommonPrefs.KEY_PREMIUM_SETTINGS, premiumSettings.serialize());
}

public static String getTitle() {
Expand Down
Loading

0 comments on commit 84864dd

Please sign in to comment.