yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
editor_registry.cc
Go to the documentation of this file.
1#include "editor_registry.h"
2
3#include <unordered_set>
4
5#include "absl/strings/str_format.h"
6#include "app/editor/editor.h"
7
8namespace yaze {
9namespace editor {
10
11// Static mappings for editor types
12const std::unordered_map<EditorType, std::string>
14 {EditorType::kOverworld, "Overworld"},
15 {EditorType::kGraphics, "Graphics"},
16 {EditorType::kPalette, "Palette"},
17 {EditorType::kSprite, "Sprite"},
18 {EditorType::kScreen, "Screen"},
19 {EditorType::kMessage, "Message"},
20 {EditorType::kMusic, "Music"},
21 {EditorType::kAssembly, "Assembly"},
22 {EditorType::kEmulator, "Emulator"},
23 {EditorType::kHex, "Hex"},
24 {EditorType::kAgent, "Agent"},
25 {EditorType::kSettings, "System"}};
26
27const std::unordered_map<EditorType, std::string> EditorRegistry::kEditorNames =
28 {{EditorType::kDungeon, "Dungeon Editor"},
29 {EditorType::kOverworld, "Overworld Editor"},
30 {EditorType::kGraphics, "Graphics Editor"},
31 {EditorType::kPalette, "Palette Editor"},
32 {EditorType::kSprite, "Sprite Editor"},
33 {EditorType::kScreen, "Screen Editor"},
34 {EditorType::kMessage, "Message Editor"},
35 {EditorType::kMusic, "Music Editor"},
36 {EditorType::kAssembly, "Assembly Editor"},
37 {EditorType::kEmulator, "Emulator Editor"},
38 {EditorType::kHex, "Hex Editor"},
39 {EditorType::kAgent, "Agent Editor"},
40 {EditorType::kSettings, "Settings Editor"}};
41
42const std::unordered_map<EditorType, bool> EditorRegistry::kPanelBasedEditors =
43 {
48 {EditorType::kSprite, true},
49 {EditorType::kScreen, true},
51 {EditorType::kMusic, true},
54 {EditorType::kHex, true},
55 {EditorType::kAgent, true}, // Agent: Panel-based UI
56 {EditorType::kSettings, false} // Settings: Sidebar panel
57};
58
60 auto it = kPanelBasedEditors.find(type);
61 return it != kPanelBasedEditors.end() && it->second;
62}
63
65 auto it = kEditorCategories.find(type);
66 if (it != kEditorCategories.end()) {
67 return it->second;
68 }
69 return "Unknown";
70}
71
73 const std::string& category) {
74 for (const auto& [type, cat] : kEditorCategories) {
75 if (cat == category) {
76 return type; // Return first match
77 }
78 }
79 return EditorType::kSettings; // Default fallback
80}
81
82std::vector<std::string> EditorRegistry::GetAllEditorCategories() {
83 // Returns all editor categories in preferred display order for the sidebar
84 // This is a fixed list to ensure consistent ordering
85 return {
86 "Overworld", // Primary map editing
87 "Dungeon", // Dungeon/room editing
88 "Graphics", // Graphics sheet editing
89 "Palette", // Color palette editing
90 "Sprite", // Sprite editing
91 "Message", // Text/dialogue editing
92 "Screen", // Screen/title editing
93 "Music", // Music/SPC editing
94 "Assembly", // Code editing
95 "Memory", // Hex editor (uses "Memory" category for cards)
96 "Emulator", // Game testing
97 "Agent" // AI Agent
98 };
99}
100
103 jump_to_room_callback_(room_id);
104 } else {
106 if (it != registered_editors_.end() && it->second) {
107 // Fallback logging if no callback registered
108 printf("[EditorRegistry] JumpToDungeonRoom(%d) called (no callback)\n",
109 room_id);
110 }
111 }
112}
113
116 jump_to_map_callback_(map_id);
117 } else {
119 if (it != registered_editors_.end() && it->second) {
120 // Fallback logging if no callback registered
121 printf("[EditorRegistry] JumpToOverworldMap(%d) called (no callback)\n",
122 map_id);
123 }
124 }
125}
126
128 ValidateEditorType(editor_type);
129
130 auto it = registered_editors_.find(editor_type);
131 if (it != registered_editors_.end() && it->second) {
132 // Deactivate all other editors
133 for (auto& [type, editor] : registered_editors_) {
134 if (type != editor_type && editor) {
135 editor->set_active(false);
136 }
137 }
138
139 // Activate the target editor
140 it->second->set_active(true);
141 printf("[EditorRegistry] Switched to %s\n",
142 GetEditorDisplayName(editor_type).c_str());
143 }
144}
145
147 for (auto& [type, editor] : registered_editors_) {
148 if (editor && IsPanelBasedEditor(type)) {
149 // TODO: Hide cards for this editor
150 printf("[EditorRegistry] Hiding cards for %s\n",
151 GetEditorDisplayName(type).c_str());
152 }
153 }
154}
155
157 ValidateEditorType(editor_type);
158
159 if (IsPanelBasedEditor(editor_type)) {
160 // TODO: Show cards for this editor
161 printf("[EditorRegistry] Showing cards for %s\n",
162 GetEditorDisplayName(editor_type).c_str());
163 }
164}
165
167 ValidateEditorType(editor_type);
168
169 if (IsPanelBasedEditor(editor_type)) {
170 // TODO: Toggle cards for this editor
171 printf("[EditorRegistry] Toggling cards for %s\n",
172 GetEditorDisplayName(editor_type).c_str());
173 }
174}
175
177 const std::string& category) const {
178 std::vector<EditorType> editors;
179
180 for (const auto& [type, cat] : kEditorCategories) {
181 if (cat == category) {
182 editors.push_back(type);
183 }
184 }
185
186 return editors;
187}
188
189std::vector<std::string> EditorRegistry::GetAvailableCategories() const {
190 std::vector<std::string> categories;
191 std::unordered_set<std::string> seen;
192
193 for (const auto& [type, category] : kEditorCategories) {
194 if (seen.find(category) == seen.end()) {
195 categories.push_back(category);
196 seen.insert(category);
197 }
198 }
199
200 return categories;
201}
202
204 auto it = kEditorNames.find(type);
205 if (it != kEditorNames.end()) {
206 return it->second;
207 }
208 return "Unknown Editor";
209}
210
212 ValidateEditorType(type);
213
214 if (!editor) {
215 throw std::invalid_argument("Editor pointer cannot be null");
216 }
217
218 registered_editors_[type] = editor;
219 printf("[EditorRegistry] Registered %s\n",
220 GetEditorDisplayName(type).c_str());
221}
222
224 ValidateEditorType(type);
225
226 auto it = registered_editors_.find(type);
227 if (it != registered_editors_.end()) {
228 registered_editors_.erase(it);
229 printf("[EditorRegistry] Unregistered %s\n",
230 GetEditorDisplayName(type).c_str());
231 }
232}
233
235 ValidateEditorType(type);
236
237 auto it = registered_editors_.find(type);
238 if (it != registered_editors_.end()) {
239 return it->second;
240 }
241 return nullptr;
242}
243
245 ValidateEditorType(type);
246
247 auto it = registered_editors_.find(type);
248 if (it != registered_editors_.end() && it->second) {
249 return it->second->active();
250 }
251 return false;
252}
253
255 ValidateEditorType(type);
256
257 auto it = registered_editors_.find(type);
258 if (it != registered_editors_.end() && it->second) {
259 return it->second->active();
260 }
261 return false;
262}
263
265 ValidateEditorType(type);
266
267 auto it = registered_editors_.find(type);
268 if (it != registered_editors_.end() && it->second) {
269 it->second->set_active(active);
270 }
271}
272
274 return kEditorCategories.find(type) != kEditorCategories.end();
275}
276
278 if (!IsValidEditorType(type)) {
279 throw std::invalid_argument(
280 absl::StrFormat("Invalid editor type: %d", static_cast<int>(type)));
281 }
282}
283
284} // namespace editor
285} // namespace yaze
void RegisterEditor(EditorType type, Editor *editor)
static const std::unordered_map< EditorType, std::string > kEditorNames
static EditorType GetEditorTypeFromCategory(const std::string &category)
static const std::unordered_map< EditorType, std::string > kEditorCategories
void ValidateEditorType(EditorType type) const
static std::vector< std::string > GetAllEditorCategories()
Get all editor categories in display order for sidebar.
std::vector< EditorType > GetEditorsInCategory(const std::string &category) const
static bool IsPanelBasedEditor(EditorType type)
void ShowEditorPanels(EditorType editor_type)
void SetEditorActive(EditorType type, bool active)
std::string GetEditorDisplayName(EditorType type) const
void ToggleEditorPanels(EditorType editor_type)
void UnregisterEditor(EditorType type)
bool IsEditorActive(EditorType type) const
bool IsValidEditorType(EditorType type) const
bool IsEditorVisible(EditorType type) const
std::function< void(int)> jump_to_room_callback_
void SwitchToEditor(EditorType editor_type)
std::vector< std::string > GetAvailableCategories() const
void JumpToDungeonRoom(int room_id)
std::function< void(int)> jump_to_map_callback_
static const std::unordered_map< EditorType, bool > kPanelBasedEditors
Editor * GetEditor(EditorType type) const
static std::string GetEditorCategory(EditorType type)
std::unordered_map< EditorType, Editor * > registered_editors_
Interface for editor classes.
Definition editor.h:179