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 "absl/strings/str_format.h"
4#include "app/editor/editor.h"
5#include <unordered_set>
6
7namespace yaze {
8namespace editor {
9
10// Static mappings for editor types
11const std::unordered_map<EditorType, std::string> EditorRegistry::kEditorCategories = {
12 {EditorType::kDungeon, "Dungeon"},
13 {EditorType::kOverworld, "Overworld"},
14 {EditorType::kGraphics, "Graphics"},
15 {EditorType::kPalette, "Palette"},
16 {EditorType::kSprite, "Sprite"},
17 {EditorType::kScreen, "Screen"},
18 {EditorType::kMessage, "Message"},
19 {EditorType::kMusic, "Music"},
20 {EditorType::kAssembly, "Assembly"},
21 {EditorType::kEmulator, "Emulator"},
22 {EditorType::kHex, "Hex"},
23 {EditorType::kAgent, "Agent"},
24 {EditorType::kSettings, "System"}
25};
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};
42
43const std::unordered_map<EditorType, bool> EditorRegistry::kCardBasedEditors = {
48 {EditorType::kSprite, true},
49 {EditorType::kScreen, true},
51 {EditorType::kMusic, true},
54 {EditorType::kHex, true},
55 {EditorType::kAgent, false}, // Agent: Traditional UI
56 {EditorType::kSettings, true} // Settings: Now card-based for better organization
57};
58
60 auto it = kCardBasedEditors.find(type);
61 return it != kCardBasedEditors.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 for (const auto& [type, cat] : kEditorCategories) {
74 if (cat == category) {
75 return type; // Return first match
76 }
77 }
78 return EditorType::kSettings; // Default fallback
79}
80
83 if (it != registered_editors_.end() && it->second) {
84 // TODO: Implement dungeon room jumping
85 // This would typically call a method on the dungeon editor
86 printf("[EditorRegistry] Jumping to dungeon room %d\n", room_id);
87 }
88}
89
92 if (it != registered_editors_.end() && it->second) {
93 // TODO: Implement overworld map jumping
94 // This would typically call a method on the overworld editor
95 printf("[EditorRegistry] Jumping to overworld map %d\n", map_id);
96 }
97}
98
100 ValidateEditorType(editor_type);
101
102 auto it = registered_editors_.find(editor_type);
103 if (it != registered_editors_.end() && it->second) {
104 // Deactivate all other editors
105 for (auto& [type, editor] : registered_editors_) {
106 if (type != editor_type && editor) {
107 editor->set_active(false);
108 }
109 }
110
111 // Activate the target editor
112 it->second->set_active(true);
113 printf("[EditorRegistry] Switched to %s\n", GetEditorDisplayName(editor_type).c_str());
114 }
115}
116
118 for (auto& [type, editor] : registered_editors_) {
119 if (editor && IsCardBasedEditor(type)) {
120 // TODO: Hide cards for this editor
121 printf("[EditorRegistry] Hiding cards for %s\n", GetEditorDisplayName(type).c_str());
122 }
123 }
124}
125
127 ValidateEditorType(editor_type);
128
129 if (IsCardBasedEditor(editor_type)) {
130 // TODO: Show cards for this editor
131 printf("[EditorRegistry] Showing cards for %s\n", GetEditorDisplayName(editor_type).c_str());
132 }
133}
134
136 ValidateEditorType(editor_type);
137
138 if (IsCardBasedEditor(editor_type)) {
139 // TODO: Toggle cards for this editor
140 printf("[EditorRegistry] Toggling cards for %s\n", GetEditorDisplayName(editor_type).c_str());
141 }
142}
143
144std::vector<EditorType> EditorRegistry::GetEditorsInCategory(const std::string& category) const {
145 std::vector<EditorType> editors;
146
147 for (const auto& [type, cat] : kEditorCategories) {
148 if (cat == category) {
149 editors.push_back(type);
150 }
151 }
152
153 return editors;
154}
155
156std::vector<std::string> EditorRegistry::GetAvailableCategories() const {
157 std::vector<std::string> categories;
158 std::unordered_set<std::string> seen;
159
160 for (const auto& [type, category] : kEditorCategories) {
161 if (seen.find(category) == seen.end()) {
162 categories.push_back(category);
163 seen.insert(category);
164 }
165 }
166
167 return categories;
168}
169
171 auto it = kEditorNames.find(type);
172 if (it != kEditorNames.end()) {
173 return it->second;
174 }
175 return "Unknown Editor";
176}
177
179 ValidateEditorType(type);
180
181 if (!editor) {
182 throw std::invalid_argument("Editor pointer cannot be null");
183 }
184
185 registered_editors_[type] = editor;
186 printf("[EditorRegistry] Registered %s\n", GetEditorDisplayName(type).c_str());
187}
188
190 ValidateEditorType(type);
191
192 auto it = registered_editors_.find(type);
193 if (it != registered_editors_.end()) {
194 registered_editors_.erase(it);
195 printf("[EditorRegistry] Unregistered %s\n", GetEditorDisplayName(type).c_str());
196 }
197}
198
200 ValidateEditorType(type);
201
202 auto it = registered_editors_.find(type);
203 if (it != registered_editors_.end()) {
204 return it->second;
205 }
206 return nullptr;
207}
208
210 ValidateEditorType(type);
211
212 auto it = registered_editors_.find(type);
213 if (it != registered_editors_.end() && it->second) {
214 return it->second->active();
215 }
216 return false;
217}
218
220 ValidateEditorType(type);
221
222 auto it = registered_editors_.find(type);
223 if (it != registered_editors_.end() && it->second) {
224 return it->second->active();
225 }
226 return false;
227}
228
230 ValidateEditorType(type);
231
232 auto it = registered_editors_.find(type);
233 if (it != registered_editors_.end() && it->second) {
234 it->second->set_active(active);
235 }
236}
237
239 return kEditorCategories.find(type) != kEditorCategories.end();
240}
241
243 if (!IsValidEditorType(type)) {
244 throw std::invalid_argument(
245 absl::StrFormat("Invalid editor type: %d", static_cast<int>(type)));
246 }
247}
248
249} // namespace editor
250} // 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 ToggleEditorCards(EditorType editor_type)
void ValidateEditorType(EditorType type) const
std::vector< EditorType > GetEditorsInCategory(const std::string &category) const
void SetEditorActive(EditorType type, bool active)
std::string GetEditorDisplayName(EditorType type) const
void UnregisterEditor(EditorType type)
bool IsEditorActive(EditorType type) const
void JumpToOverworldMap(int map_id)
bool IsValidEditorType(EditorType type) const
static const std::unordered_map< EditorType, bool > kCardBasedEditors
bool IsEditorVisible(EditorType type) const
static bool IsCardBasedEditor(EditorType type)
void ShowEditorCards(EditorType editor_type)
void SwitchToEditor(EditorType editor_type)
std::vector< std::string > GetAvailableCategories() const
void JumpToDungeonRoom(int room_id)
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:122
Main namespace for the application.
Definition controller.cc:20