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 = {
47 {EditorType::kSprite, true},
48 {EditorType::kScreen, true},
50 {EditorType::kMusic, true},
53 {EditorType::kHex, true},
54 {EditorType::kAgent, true}, // Agent: Panel-based UI
56 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", room_id);
109 }
110 }
111}
112
115 jump_to_map_callback_(map_id);
116 } else {
118 if (it != registered_editors_.end() && it->second) {
119 // Fallback logging if no callback registered
120 printf("[EditorRegistry] JumpToOverworldMap(%d) called (no callback)\n", map_id);
121 }
122 }
123}
124
126 ValidateEditorType(editor_type);
127
128 auto it = registered_editors_.find(editor_type);
129 if (it != registered_editors_.end() && it->second) {
130 // Deactivate all other editors
131 for (auto& [type, editor] : registered_editors_) {
132 if (type != editor_type && editor) {
133 editor->set_active(false);
134 }
135 }
136
137 // Activate the target editor
138 it->second->set_active(true);
139 printf("[EditorRegistry] Switched to %s\n",
140 GetEditorDisplayName(editor_type).c_str());
141 }
142}
143
145 for (auto& [type, editor] : registered_editors_) {
146 if (editor && IsPanelBasedEditor(type)) {
147 // TODO: Hide cards for this editor
148 printf("[EditorRegistry] Hiding cards for %s\n",
149 GetEditorDisplayName(type).c_str());
150 }
151 }
152}
153
155 ValidateEditorType(editor_type);
156
157 if (IsPanelBasedEditor(editor_type)) {
158 // TODO: Show cards for this editor
159 printf("[EditorRegistry] Showing cards for %s\n",
160 GetEditorDisplayName(editor_type).c_str());
161 }
162}
163
165 ValidateEditorType(editor_type);
166
167 if (IsPanelBasedEditor(editor_type)) {
168 // TODO: Toggle cards for this editor
169 printf("[EditorRegistry] Toggling cards for %s\n",
170 GetEditorDisplayName(editor_type).c_str());
171 }
172}
173
175 const std::string& category) const {
176 std::vector<EditorType> editors;
177
178 for (const auto& [type, cat] : kEditorCategories) {
179 if (cat == category) {
180 editors.push_back(type);
181 }
182 }
183
184 return editors;
185}
186
187std::vector<std::string> EditorRegistry::GetAvailableCategories() const {
188 std::vector<std::string> categories;
189 std::unordered_set<std::string> seen;
190
191 for (const auto& [type, category] : kEditorCategories) {
192 if (seen.find(category) == seen.end()) {
193 categories.push_back(category);
194 seen.insert(category);
195 }
196 }
197
198 return categories;
199}
200
202 auto it = kEditorNames.find(type);
203 if (it != kEditorNames.end()) {
204 return it->second;
205 }
206 return "Unknown Editor";
207}
208
210 ValidateEditorType(type);
211
212 if (!editor) {
213 throw std::invalid_argument("Editor pointer cannot be null");
214 }
215
216 registered_editors_[type] = editor;
217 printf("[EditorRegistry] Registered %s\n",
218 GetEditorDisplayName(type).c_str());
219}
220
222 ValidateEditorType(type);
223
224 auto it = registered_editors_.find(type);
225 if (it != registered_editors_.end()) {
226 registered_editors_.erase(it);
227 printf("[EditorRegistry] Unregistered %s\n",
228 GetEditorDisplayName(type).c_str());
229 }
230}
231
233 ValidateEditorType(type);
234
235 auto it = registered_editors_.find(type);
236 if (it != registered_editors_.end()) {
237 return it->second;
238 }
239 return nullptr;
240}
241
243 ValidateEditorType(type);
244
245 auto it = registered_editors_.find(type);
246 if (it != registered_editors_.end() && it->second) {
247 return it->second->active();
248 }
249 return false;
250}
251
253 ValidateEditorType(type);
254
255 auto it = registered_editors_.find(type);
256 if (it != registered_editors_.end() && it->second) {
257 return it->second->active();
258 }
259 return false;
260}
261
263 ValidateEditorType(type);
264
265 auto it = registered_editors_.find(type);
266 if (it != registered_editors_.end() && it->second) {
267 it->second->set_active(active);
268 }
269}
270
272 return kEditorCategories.find(type) != kEditorCategories.end();
273}
274
276 if (!IsValidEditorType(type)) {
277 throw std::invalid_argument(
278 absl::StrFormat("Invalid editor type: %d", static_cast<int>(type)));
279 }
280}
281
282} // namespace editor
283} // 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