yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_CORE_EDITOR_H
2#define YAZE_APP_CORE_EDITOR_H
3
4#include <array>
5#include <cstddef>
6#include <functional>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "absl/status/statusor.h"
11#include "absl/strings/str_format.h"
14
15// Forward declaration in yaze::core namespace
16namespace yaze {
17namespace core {
18class VersionManager;
19}
20}
21
22namespace yaze {
23
24// Forward declarations
25class Rom;
26namespace gfx {
27class IRenderer;
28}
29namespace emu {
30class Emulator;
31}
32namespace project {
33struct YazeProject;
34} // namespace project
35namespace zelda3 {
36struct GameData;
37} // namespace zelda3
38
43namespace editor {
44
45// Forward declarations
46class PanelManager;
47class ToastManager;
48class UserSettings;
49
68 Rom* rom = nullptr;
70
71 // Check if context is valid for operations
72 bool IsValid() const { return rom != nullptr && game_data != nullptr; }
73 bool HasRom() const { return rom != nullptr; }
74 bool HasGameData() const { return game_data != nullptr; }
75
76 // Implicit conversion to bool for quick validity checks
77 explicit operator bool() const { return IsValid(); }
78};
79
114 std::vector<int> overworld_tile16_ids;
117
118 void Clear() {
119 has_overworld_tile16 = false;
120 overworld_tile16_ids.clear();
121 overworld_width = 0;
123 }
124 };
125
126 Rom* rom = nullptr;
127 zelda3::GameData* game_data = nullptr; // Zelda3-specific game state
136 size_t session_id = 0;
137
140
141 void* custom_data = nullptr;
142
143 // Get lightweight context for passing to sub-components
144 EditorContext context() const { return {rom, game_data}; }
145
146 // Check if essential context is available
147 bool HasContext() const { return rom != nullptr && game_data != nullptr; }
148};
149
150enum class EditorType {
151 kUnknown,
152 kAssembly,
153 kDungeon,
154 kEmulator,
155 kGraphics,
156 kMusic,
158 kPalette,
159 kScreen,
160 kSprite,
161 kMessage,
162 kHex,
163 kAgent,
164 kSettings,
165};
166
167constexpr std::array<const char*, 14> kEditorNames = {
168 "Unknown", "Assembly", "Dungeon", "Emulator", "Graphics",
169 "Music", "Overworld", "Palette", "Screen", "Sprite",
170 "Message", "Hex", "Agent", "Settings",
171};
172
179class Editor {
180 public:
181 Editor() = default;
182 virtual ~Editor() = default;
183
185
186 // Set GameData for Zelda3-specific data access
190
191 // Initialization of the editor, no ROM assets.
192 virtual void Initialize() = 0;
193
194 // Initialization of ROM assets.
195 virtual absl::Status Load() = 0;
196
197 // Save the editor state.
198 virtual absl::Status Save() = 0;
199
200 // Update the editor state, ran every frame.
201 virtual absl::Status Update() = 0;
202
203 virtual absl::Status Cut() = 0;
204 virtual absl::Status Copy() = 0;
205 virtual absl::Status Paste() = 0;
206
207 virtual absl::Status Undo() = 0;
208 virtual absl::Status Redo() = 0;
209
210 virtual absl::Status Find() = 0;
211
212 virtual absl::Status Clear() { return absl::OkStatus(); }
213
214 EditorType type() const { return type_; }
215
216 bool* active() { return &active_; }
217 void set_active(bool active) { active_ = active; }
219
220 // ROM loading state helpers (default implementations)
221 virtual bool IsRomLoaded() const { return false; }
222 virtual std::string GetRomStatus() const {
223 return "ROM state not implemented";
224 }
225
226 // Accessors for common dependencies
227 Rom* rom() const { return dependencies_.rom; }
229
230 // Get bundled context for sub-components
232 bool HasContext() const { return dependencies_.HasContext(); }
233
234 protected:
235 bool active_ = false;
238
239 // Helper method to create session-aware card titles for multi-session support
240 std::string MakePanelTitle(const std::string& base_title) const {
241 if (dependencies_.session_id > 0) {
242 return absl::StrFormat("%s [S%zu]", base_title, dependencies_.session_id);
243 }
244 return base_title;
245 }
246
247 // Helper method to create session-aware card IDs for multi-session support
248 std::string MakePanelId(const std::string& base_id) const {
249 if (dependencies_.session_id > 0) {
250 return absl::StrFormat("s%zu.%s", dependencies_.session_id, base_id);
251 }
252 return base_id;
253 }
254
255 // Helper method for ROM access with safety check
256 template <typename T>
257 absl::StatusOr<T> SafeRomAccess(std::function<T()> accessor,
258 const std::string& operation = "") const {
259 if (!IsRomLoaded()) {
260 return absl::FailedPreconditionError(
261 operation.empty() ? "ROM not loaded"
262 : absl::StrFormat("%s: ROM not loaded", operation));
263 }
264 try {
265 return accessor();
266 } catch (const std::exception& e) {
267 return absl::InternalError(absl::StrFormat(
268 "%s: %s", operation.empty() ? "ROM access failed" : operation,
269 e.what()));
270 }
271 }
272};
273
274} // namespace editor
275} // namespace yaze
276
277#endif // YAZE_APP_CORE_EDITOR_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
Manages project versioning (Git) and ROM artifact snapshots.
Interface for editor classes.
Definition editor.h:179
virtual void SetGameData(zelda3::GameData *game_data)
Definition editor.h:187
bool HasContext() const
Definition editor.h:232
virtual absl::Status Cut()=0
virtual absl::Status Copy()=0
virtual absl::Status Redo()=0
EditorContext context() const
Definition editor.h:231
virtual void Initialize()=0
Rom * rom() const
Definition editor.h:227
zelda3::GameData * game_data() const
Definition editor.h:228
EditorDependencies dependencies_
Definition editor.h:237
virtual absl::Status Clear()
Definition editor.h:212
EditorType type() const
Definition editor.h:214
void set_active(bool active)
Definition editor.h:217
virtual ~Editor()=default
virtual std::string GetRomStatus() const
Definition editor.h:222
EditorType type_
Definition editor.h:236
virtual absl::Status Save()=0
std::string MakePanelId(const std::string &base_id) const
Definition editor.h:248
virtual bool IsRomLoaded() const
Definition editor.h:221
void SetDependencies(const EditorDependencies &deps)
Definition editor.h:184
std::string MakePanelTitle(const std::string &base_title) const
Definition editor.h:240
absl::StatusOr< T > SafeRomAccess(std::function< T()> accessor, const std::string &operation="") const
Definition editor.h:257
virtual absl::Status Find()=0
virtual absl::Status Paste()=0
virtual absl::Status Load()=0
virtual absl::Status Update()=0
virtual absl::Status Undo()=0
Central registry for all editor cards with session awareness and dependency injection.
Manages user preferences and settings persistence.
A class for emulating and debugging SNES games.
Definition emulator.h:39
Defines an abstract interface for all rendering operations.
Definition irenderer.h:40
constexpr std::array< const char *, 14 > kEditorNames
Definition editor.h:167
Lightweight view into the essential runtime context (Rom + GameData)
Definition editor.h:67
bool HasGameData() const
Definition editor.h:74
zelda3::GameData * game_data
Definition editor.h:69
Unified dependency container for all editor types.
Definition editor.h:111
project::YazeProject * project
Definition editor.h:134
SharedClipboard * shared_clipboard
Definition editor.h:132
gfx::IRenderer * renderer
Definition editor.h:138
ShortcutManager * shortcut_manager
Definition editor.h:131
core::VersionManager * version_manager
Definition editor.h:135
zelda3::GameData * game_data
Definition editor.h:127
EditorContext context() const
Definition editor.h:144
Modern project structure with comprehensive settings consolidation.
Definition project.h:84