yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
user_settings.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SYSTEM_USER_SETTINGS_H_
2#define YAZE_APP_EDITOR_SYSTEM_USER_SETTINGS_H_
3
4#include <string>
5#include <unordered_map>
6#include <unordered_set>
7#include <utility>
8#include <vector>
9
10#include "absl/status/status.h"
11
12namespace yaze {
13namespace editor {
14
19 public:
20 struct Preferences {
21 struct AiHost {
22 std::string id;
23 std::string label;
24 std::string base_url;
25 std::string api_type; // openai, ollama, gemini, lmstudio, grpc
26 bool supports_vision = false;
27 bool supports_tools = true;
28 bool supports_streaming = true;
29 bool allow_insecure = false;
30 std::string api_key; // Optional plaintext key (desktop/non-keychain)
31 std::string
32 credential_id; // Keychain reference (never store secrets here)
33 };
34
36 std::string name;
37 std::string model;
38 float temperature = 0.25f;
39 float top_p = 0.95f;
41 bool supports_vision = false;
42 bool supports_tools = true;
43 };
44
45 // General
46 float font_global_scale = 1.0f;
47 bool backup_rom = false;
48 bool save_new_auto = true;
49 bool autosave_enabled = true;
50 float autosave_interval = 300.0f;
52 std::string last_rom_path;
53 std::string last_project_path;
57
58 // Welcome screen animation preferences. Match the defaults hard-coded in
59 // WelcomeScreen so first-run behavior is unchanged.
65
66 // Accessibility / interaction
67 bool reduced_motion = false;
68 int switch_motion_profile = 1; // 0=Snappy, 1=Standard, 2=Relaxed
69
70 // Theme (last applied theme persists across restart; empty = default)
71 std::string last_theme_name;
72
73 // UI language (locale code, e.g. "en"/"fr"; matches assets/i18n/<code>.json)
74 std::string language_locale = "en";
75
76 // Font (index into ImGui::GetIO().Fonts->Fonts, typically 0..4)
78
79 // Editor Behavior
80 bool backup_before_save = true;
81 int default_editor = 0; // 0=None, 1=Overworld, 2=Dungeon, 3=Graphics
82
83 // Performance
84 bool vsync = true;
85 int target_fps = 60;
86 int cache_size_mb = 512;
88
89 // AI Agent
91 0; // Legacy default provider (0=Ollama, 1=Gemini, 2=Mock)
92 std::string ai_model;
93 std::string ollama_url = "http://localhost:11434";
94 std::string gemini_api_key;
95 std::string openai_api_key;
96 std::string anthropic_api_key;
97 float ai_temperature = 0.7f;
98 int ai_max_tokens = 2048;
99 bool ai_proactive = true;
100 bool ai_auto_learn = true;
101 bool ai_multimodal = true;
102 std::vector<AiHost> ai_hosts;
103 std::string active_ai_host_id;
104 std::vector<AiModelProfile> ai_profiles;
105 std::string active_ai_profile;
107 std::vector<std::string> ai_model_paths;
108
109 // CLI Logging
110 int log_level = 1; // 0=Debug, 1=Info, 2=Warning, 3=Error, 4=Fatal
111 bool log_to_file = false;
112 std::string log_file_path;
113 bool log_ai_requests = true;
116 bool log_proposals = true;
117
118 // Filesystem (iOS + remote workflows)
119 std::vector<std::string> project_root_paths;
121 bool use_files_app = true;
122 bool use_icloud_sync = true;
123
124 // Shortcut Overrides
125 // Maps panel_id -> shortcut string (e.g., "dungeon.room_selector" -> "Ctrl+Shift+R")
126 std::unordered_map<std::string, std::string> panel_shortcuts;
127 // Maps global action id -> shortcut string (e.g., "Open", "Save")
128 std::unordered_map<std::string, std::string> global_shortcuts;
129 // Maps editor-scoped action id -> shortcut string (keyed by editor namespace)
130 std::unordered_map<std::string, std::string> editor_shortcuts;
131
132 // Sidebar State
133 bool sidebar_visible = true; // Controls Activity Bar visibility
134 bool sidebar_panel_expanded = true; // Controls Side Panel visibility
135 float sidebar_panel_width = 0.0f; // 0 = responsive default
138 std::string sidebar_active_category; // Last active category
139
140 // Sidebar customization (Phase 4): user-controlled category order,
141 // hidden set (filtered out of the rail), and pinned set (pinned-first).
142 std::vector<std::string> sidebar_order;
143 std::unordered_set<std::string> sidebar_hidden;
144 std::unordered_set<std::string> sidebar_pinned;
145
146 // Status Bar
148 false; // Show status bar at bottom (disabled by default)
149
150 // Dungeon workbench layout: which side of the workbench window the
151 // inspector pane occupies. "right" (default) places selectors on the left
152 // and inspector on the right (Layout C / ZScream-style); "left" mirrors it.
153 // Read by dungeon_workbench_content at draw time. Persisted as a string so
154 // a future "top" / "bottom" / "floating" extension does not require a
155 // migration of existing settings files.
156 std::string dungeon_inspector_side = "right";
157
158 // Panel Visibility State (per editor type)
159 // Maps editor_type_name -> (panel_id -> visible)
160 // e.g., "Overworld" -> {"overworld.tile16_selector" -> true, ...}
161 std::unordered_map<std::string, std::unordered_map<std::string, bool>>
163
164 // Pinned panels (persists across sessions)
165 // Maps panel_id -> pinned
166 std::unordered_map<std::string, bool> pinned_panels;
167 std::unordered_map<std::string, float> right_panel_widths;
168
169 // Named layouts (user-saved workspace configurations)
170 // Maps layout_name -> (panel_id -> visible)
171 std::unordered_map<std::string, std::unordered_map<std::string, bool>>
173
174 // Named DockTree layouts authored in the Layout Designer.
175 // Maps layout_name -> JSON-serialized DockTree (schema v1).
176 // Kept as opaque strings so UserSettings does not have to understand
177 // DockTree internals; the designer parses/re-serializes via
178 // layout_designer::DockTreeFromJson / DockTreeToJson.
179 std::unordered_map<std::string, std::string> named_layouts;
180
181 // Name of the last DockTree layout applied to the live dockspace.
182 // Empty string => nothing to auto-apply on startup. Mirrors the
183 // `last_theme_name` persistence pattern.
185 };
186
187 UserSettings();
188
189 absl::Status Load();
190 absl::Status Save();
191
192 // Applies a one-time layout defaults migration when target_revision is newer
193 // than persisted settings. Returns true when defaults were reset.
194 bool ApplyPanelLayoutDefaultsRevision(int target_revision);
195
196 static constexpr int kLatestPanelLayoutDefaultsRevision = 21;
197
198 Preferences& prefs() { return prefs_; }
199 const Preferences& prefs() const { return prefs_; }
200
201 // Dungeon workbench inspector placement. Returns the persisted value
202 // verbatim ("right" / "left"), defaulting to "right" if the value is empty
203 // or unrecognized so callers can switch on it without a null check.
204 std::string GetDungeonInspectorSide() const;
205 // Sets the inspector placement. Accepts "right" or "left"; any other value
206 // is normalized to "right". Caller must invoke Save() to persist.
207 void SetDungeonInspectorSide(std::string side);
208
209 // Testing hook: redirect Load/Save to a caller-specified path. Production
210 // code should never call this; it only exists so unit tests can exercise
211 // JSON round-trip without touching the user's real settings file.
212 void SetSettingsFilePathForTesting(std::string path) {
213 settings_file_path_ = std::move(path);
214 }
215
216 private:
220};
221
222} // namespace editor
223} // namespace yaze
224
225#endif // YAZE_APP_EDITOR_SYSTEM_USER_SETTINGS_H_
Manages user preferences and settings persistence.
const Preferences & prefs() const
bool ApplyPanelLayoutDefaultsRevision(int target_revision)
void SetSettingsFilePathForTesting(std::string path)
std::string GetDungeonInspectorSide() const
void SetDungeonInspectorSide(std::string side)
static constexpr int kLatestPanelLayoutDefaultsRevision
std::string legacy_settings_file_path_
std::vector< std::string > project_root_paths
std::unordered_map< std::string, std::string > panel_shortcuts
std::unordered_map< std::string, std::string > named_layouts
std::unordered_map< std::string, std::unordered_map< std::string, bool > > saved_layouts
std::vector< AiModelProfile > ai_profiles
std::unordered_set< std::string > sidebar_pinned
std::vector< std::string > sidebar_order
std::unordered_map< std::string, float > right_panel_widths
std::unordered_map< std::string, std::string > editor_shortcuts
std::vector< std::string > ai_model_paths
std::unordered_map< std::string, std::string > global_shortcuts
std::unordered_map< std::string, std::unordered_map< std::string, bool > > panel_visibility_state
std::unordered_map< std::string, bool > pinned_panels
std::unordered_set< std::string > sidebar_hidden