From a0dd313e0cb7da4a2f5120e7fe512d6d51c42930 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 12 Jun 2026 18:09:27 +0200 Subject: [PATCH] Centralize retained preference keys --- docs/modernization/debt.md | 3 + src/legacy_preference_storage.cpp | 128 +++++++++++++++++++++++------- 2 files changed, 103 insertions(+), 28 deletions(-) diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index eb528b2..3991e0d 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -298,6 +298,9 @@ agent or engineer to remove them without reconstructing context from chat. - 2026-06-12: DEBT-0045/0046/0052/0058 were narrowed again. The retained preference storage header now exposes only named snapshots/operations; generic key/value helpers are local to `src/legacy_preference_storage.cpp`. +- 2026-06-12: DEBT-0045/0046/0052/0058 were narrowed again. Retained preference + keys are centralized as local constants inside `src/legacy_preference_storage.cpp`, + with all typed legacy `Settings` calls routed through local helper functions. - 2026-06-05: DEBT-0056 was narrowed. `src/asset.h` no longer exposes Android SDK types or forward declarations; retained Android asset-manager and asset handles are stored as opaque pointers and cast only inside `src/asset.cpp`, diff --git a/src/legacy_preference_storage.cpp b/src/legacy_preference_storage.cpp index 6a4b57f..844686d 100644 --- a/src/legacy_preference_storage.cpp +++ b/src/legacy_preference_storage.cpp @@ -8,11 +8,83 @@ namespace pp::panopainter { namespace { +constexpr const char* kRunCounterKey = "run_counter"; +constexpr const char* kAutoTimelapseKey = "auto-timelapse"; +constexpr const char* kVrControllersEnabledKey = "vr-controllers-enabled"; +constexpr const char* kViewportScaleKey = "vp-scale"; +constexpr const char* kShowCursorKey = "show-cursor"; +constexpr const char* kUiRightToLeftKey = "ui-rtl"; +constexpr const char* kUiStateKey = "ui"; +constexpr const char* kUiScaleKey = "ui-scale"; +constexpr const char* kWindowShowCommandKey = "window-show-cmd"; +constexpr const char* kWindowRectKey = "window-rect"; +constexpr const char* kWhatsNewIdKey = "whatsnew-id"; + +bool has_legacy_preference_key(const char* key) +{ + return Settings::has(key); +} + +int read_legacy_integer_preference(const char* key) +{ + return Settings::value(key); +} + +int read_legacy_integer_preference_or(const char* key, int default_value) +{ + return Settings::value_or(key, default_value); +} + +float read_legacy_float_preference(const char* key) +{ + return Settings::value(key); +} + +float read_legacy_float_preference_or(const char* key, float default_value) +{ + return Settings::value_or(key, default_value); +} + +bool read_legacy_boolean_preference_or(const char* key, bool default_value) +{ + return Settings::value_or(key, default_value); +} + +glm::ivec4 read_legacy_ivec4_preference(const char* key) +{ + return Settings::value(key); +} + +std::shared_ptr read_legacy_descriptor_preference(const char* key) +{ + return Settings::get(key); +} + +void set_legacy_integer_preference(const char* key, int value) +{ + Settings::set(key, Serializer::Integer(value)); +} + void set_legacy_boolean_preference(const char* key, bool value) { Settings::set(key, Serializer::Boolean(value)); } +void set_legacy_float_preference(const char* key, float value) +{ + Settings::set(key, Serializer::Float(value)); +} + +void set_legacy_ivec4_preference(const char* key, const glm::ivec4& value) +{ + Settings::set(key, Serializer::IVec4(value)); +} + +void set_legacy_descriptor_preference(const char* key, const Serializer::Descriptor& value) +{ + Settings::set(key, value); +} + void save_legacy_boolean_preference(const char* key, bool value) { set_legacy_boolean_preference(key, value); @@ -21,7 +93,7 @@ void save_legacy_boolean_preference(const char* key, bool value) void save_legacy_float_preference(const char* key, float value) { - Settings::set(key, Serializer::Float(value)); + set_legacy_float_preference(key, value); Settings::save(); } @@ -35,100 +107,100 @@ bool load_legacy_preferences() LegacyStartupPreferenceSnapshot read_legacy_startup_preferences(bool default_vr_controllers_enabled) { return { - Settings::value("run_counter"), - Settings::value_or("auto-timelapse", true), - Settings::value_or("vr-controllers-enabled", default_vr_controllers_enabled), + read_legacy_integer_preference(kRunCounterKey), + read_legacy_boolean_preference_or(kAutoTimelapseKey, true), + read_legacy_boolean_preference_or(kVrControllersEnabledKey, default_vr_controllers_enabled), }; } LegacyCanvasPreferenceSnapshot read_legacy_canvas_preferences() { return { - Settings::value_or("vp-scale", 1.0F), - Settings::value_or("show-cursor", 0), + read_legacy_float_preference_or(kViewportScaleKey, 1.0F), + read_legacy_integer_preference_or(kShowCursorKey, 0), }; } LegacyUiPreferenceSnapshot read_legacy_ui_preferences() { LegacyUiPreferenceSnapshot snapshot; - snapshot.has_rtl = Settings::has("ui-rtl"); + snapshot.has_rtl = has_legacy_preference_key(kUiRightToLeftKey); if (snapshot.has_rtl) - snapshot.rtl = Settings::value("ui-rtl"); - if (Settings::has("ui")) - snapshot.state = Settings::get("ui"); + snapshot.rtl = read_legacy_integer_preference(kUiRightToLeftKey); + if (has_legacy_preference_key(kUiStateKey)) + snapshot.state = read_legacy_descriptor_preference(kUiStateKey); return snapshot; } LegacyWindowPreferenceSnapshot read_legacy_window_preferences(int default_show_command) { LegacyWindowPreferenceSnapshot snapshot; - snapshot.has_ui_scale = Settings::has("ui-scale"); + snapshot.has_ui_scale = has_legacy_preference_key(kUiScaleKey); if (snapshot.has_ui_scale) - snapshot.ui_scale = Settings::value("ui-scale"); - snapshot.show_command = Settings::value_or("window-show-cmd", default_show_command); - snapshot.has_window_rect = Settings::has("window-rect"); + snapshot.ui_scale = read_legacy_float_preference(kUiScaleKey); + snapshot.show_command = read_legacy_integer_preference_or(kWindowShowCommandKey, default_show_command); + snapshot.has_window_rect = has_legacy_preference_key(kWindowRectKey); if (snapshot.has_window_rect) - snapshot.window_rect = Settings::value("window-rect"); + snapshot.window_rect = read_legacy_ivec4_preference(kWindowRectKey); return snapshot; } void save_legacy_ui_scale_preference(float scale) { - Settings::set("ui-scale", Serializer::Float(scale)); + set_legacy_float_preference(kUiScaleKey, scale); Settings::save(); } void set_legacy_ui_state_preferences(const Serializer::Descriptor& state, bool right_to_left) { - Settings::set("ui", state); - Settings::set("ui-rtl", Serializer::Boolean(right_to_left)); + set_legacy_descriptor_preference(kUiStateKey, state); + set_legacy_boolean_preference(kUiRightToLeftKey, right_to_left); } void set_legacy_window_preferences(int show_command, const glm::ivec4& window_rect) { - Settings::set("window-show-cmd", Serializer::Integer(show_command)); - Settings::set("window-rect", Serializer::IVec4(window_rect)); + set_legacy_integer_preference(kWindowShowCommandKey, show_command); + set_legacy_ivec4_preference(kWindowRectKey, window_rect); } int legacy_whatsnew_id_or(int default_value) { - return Settings::value_or("whatsnew-id", default_value); + return read_legacy_integer_preference_or(kWhatsNewIdKey, default_value); } void clear_legacy_whatsnew_id() { - Settings::unset("whatsnew-id"); + Settings::unset(kWhatsNewIdKey); } void set_legacy_whatsnew_id(int page_id) { - Settings::set("whatsnew-id", Serializer::Integer(page_id)); + set_legacy_integer_preference(kWhatsNewIdKey, page_id); } void set_legacy_startup_run_counter(int value) { - Settings::set("run_counter", Serializer::Integer(value)); + set_legacy_integer_preference(kRunCounterKey, value); } void save_legacy_vr_controllers_enabled(bool enabled) { - save_legacy_boolean_preference("vr-controllers-enabled", enabled); + save_legacy_boolean_preference(kVrControllersEnabledKey, enabled); } void save_legacy_auto_timelapse_enabled(bool enabled) { - save_legacy_boolean_preference("auto-timelapse", enabled); + save_legacy_boolean_preference(kAutoTimelapseKey, enabled); } void save_legacy_canvas_viewport_density(float density) { - save_legacy_float_preference("vp-scale", density); + save_legacy_float_preference(kViewportScaleKey, density); } void save_legacy_canvas_cursor_mode(int mode) { - Settings::set("show-cursor", Serializer::Integer(mode)); + set_legacy_integer_preference(kShowCursorKey, mode); Settings::save(); }