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"
15
16// Forward declaration in yaze::core namespace
17namespace yaze {
18namespace core {
19class VersionManager;
20}
21}
22
23namespace yaze {
24
25// Forward declarations
26class Rom;
27namespace gfx {
28class IRenderer;
29}
30namespace emu {
31class Emulator;
32}
33namespace project {
34struct YazeProject;
35} // namespace project
36namespace zelda3 {
37struct GameData;
38} // namespace zelda3
39
44namespace editor {
45
46// Forward declarations
47class GlobalEditorContext;
48class PanelManager;
49class ToastManager;
50class UserSettings;
51class StatusBar;
52
71 Rom* rom = nullptr;
73
74 // Check if context is valid for operations
75 bool IsValid() const { return rom != nullptr && game_data != nullptr; }
76 bool HasRom() const { return rom != nullptr; }
77 bool HasGameData() const { return game_data != nullptr; }
78
79 // Implicit conversion to bool for quick validity checks
80 explicit operator bool() const { return IsValid(); }
81};
82
114// Shared clipboard for cross-editor copy/paste operations.
117 std::vector<int> overworld_tile16_ids;
120
121 void Clear() {
122 has_overworld_tile16 = false;
123 overworld_tile16_ids.clear();
124 overworld_width = 0;
126 }
127};
128
129// Data-layer dependencies: ROM, game data, project, session identity.
131 Rom* rom = nullptr;
136 size_t session_id = 0;
137
138 EditorContext context() const { return {rom, game_data}; }
139 bool HasContext() const { return rom != nullptr && game_data != nullptr; }
140};
141
142// UI-layer dependencies: panel/popup/toast/shortcut managers.
153
164 // --- Core (data-layer) dependencies ---
165 Rom* rom = nullptr;
170 size_t session_id = 0;
171
172 // --- UI-layer dependencies ---
181
182 // --- Specialized dependencies ---
185 void* custom_data = nullptr;
186
187 // Extract sub-structs for passing to components that only need a subset.
195
196 EditorContext context() const { return {rom, game_data}; }
197 bool HasContext() const { return rom != nullptr && game_data != nullptr; }
198};
199
200enum class EditorType {
201 kUnknown,
202 kAssembly,
203 kDungeon,
204 kEmulator,
205 kGraphics,
206 kMusic,
208 kPalette,
209 kScreen,
210 kSprite,
211 kMessage,
212 kHex,
213 kAgent,
214 kSettings,
215};
216
217constexpr std::array<const char*, 14> kEditorNames = {
218 "Unknown", "Assembly", "Dungeon", "Emulator", "Graphics",
219 "Music", "Overworld", "Palette", "Screen", "Sprite",
220 "Message", "Hex", "Agent", "Settings",
221};
222
223constexpr size_t kEditorTypeCount =
224 static_cast<size_t>(EditorType::kSettings) + 1;
225
226inline size_t EditorTypeIndex(EditorType type) {
227 return static_cast<size_t>(type);
228}
229
236class Editor {
237 public:
238 Editor() = default;
239 virtual ~Editor() = default;
240
241 virtual void SetDependencies(const EditorDependencies& deps) {
242 dependencies_ = deps;
243 }
244
245 // Set GameData for Zelda3-specific data access
249
250 // Initialization of the editor, no ROM assets.
251 virtual void Initialize() = 0;
252
253 // Initialization of ROM assets.
254 virtual absl::Status Load() = 0;
255
256 // Save the editor state.
257 virtual absl::Status Save() = 0;
258
259 // Update the editor state, ran every frame.
260 virtual absl::Status Update() = 0;
261
262 virtual absl::Status Cut() = 0;
263 virtual absl::Status Copy() = 0;
264 virtual absl::Status Paste() = 0;
265
266 virtual absl::Status Undo() = 0;
267 virtual absl::Status Redo() = 0;
268
269 // Undo description for toast feedback (queries editor's UndoManager)
270 virtual std::string GetUndoDescription() const {
272 }
273 virtual std::string GetRedoDescription() const {
275 }
276
277 const UndoManager& undo_manager() const { return undo_manager_; }
278
279 virtual absl::Status Find() = 0;
280
281 virtual absl::Status Clear() { return absl::OkStatus(); }
282
283 EditorType type() const { return type_; }
284
285 bool* active() { return &active_; }
286 void set_active(bool active) { active_ = active; }
288
289 // ROM loading state helpers (default implementations)
290 virtual bool IsRomLoaded() const { return false; }
291 virtual std::string GetRomStatus() const {
292 return "ROM state not implemented";
293 }
294
295 // Accessors for common dependencies
296 Rom* rom() const { return dependencies_.rom; }
298
299 // Get bundled context for sub-components
301 bool HasContext() const { return dependencies_.HasContext(); }
302
303 protected:
304 bool active_ = false;
308
309 // Helper method to create session-aware card titles for multi-session support
310 std::string MakePanelTitle(const std::string& base_title) const {
311 if (dependencies_.session_id > 0) {
312 return absl::StrFormat("%s [S%zu]", base_title, dependencies_.session_id);
313 }
314 return base_title;
315 }
316
317 // Helper method to create session-aware card IDs for multi-session support
318 std::string MakePanelId(const std::string& base_id) const {
319 if (dependencies_.session_id > 0) {
320 return absl::StrFormat("s%zu.%s", dependencies_.session_id, base_id);
321 }
322 return base_id;
323 }
324
325 // Helper method for ROM access with safety check
326 template <typename T>
327 absl::StatusOr<T> SafeRomAccess(std::function<T()> accessor,
328 const std::string& operation = "") const {
329 if (!IsRomLoaded()) {
330 return absl::FailedPreconditionError(
331 operation.empty() ? "ROM not loaded"
332 : absl::StrFormat("%s: ROM not loaded", operation));
333 }
334 try {
335 return accessor();
336 } catch (const std::exception& e) {
337 return absl::InternalError(absl::StrFormat(
338 "%s: %s", operation.empty() ? "ROM access failed" : operation,
339 e.what()));
340 }
341 }
342};
343
344} // namespace editor
345} // namespace yaze
346
347#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:28
Manages project versioning (Git) and ROM artifact snapshots.
Interface for editor classes.
Definition editor.h:236
virtual void SetGameData(zelda3::GameData *game_data)
Definition editor.h:246
bool HasContext() const
Definition editor.h:301
virtual absl::Status Cut()=0
virtual absl::Status Copy()=0
virtual absl::Status Redo()=0
EditorContext context() const
Definition editor.h:300
UndoManager undo_manager_
Definition editor.h:307
virtual std::string GetRedoDescription() const
Definition editor.h:273
const UndoManager & undo_manager() const
Definition editor.h:277
virtual void SetDependencies(const EditorDependencies &deps)
Definition editor.h:241
virtual void Initialize()=0
Rom * rom() const
Definition editor.h:296
zelda3::GameData * game_data() const
Definition editor.h:297
EditorDependencies dependencies_
Definition editor.h:306
virtual absl::Status Clear()
Definition editor.h:281
EditorType type() const
Definition editor.h:283
void set_active(bool active)
Definition editor.h:286
virtual ~Editor()=default
virtual std::string GetRomStatus() const
Definition editor.h:291
EditorType type_
Definition editor.h:305
virtual absl::Status Save()=0
std::string MakePanelId(const std::string &base_id) const
Definition editor.h:318
virtual bool IsRomLoaded() const
Definition editor.h:290
std::string MakePanelTitle(const std::string &base_title) const
Definition editor.h:310
absl::StatusOr< T > SafeRomAccess(std::function< T()> accessor, const std::string &operation="") const
Definition editor.h:327
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
virtual std::string GetUndoDescription() const
Definition editor.h:270
Instance-based runtime context replacing ContentRegistry::Context.
Central registry for all editor cards with session awareness and dependency injection.
A session-aware status bar displayed at the bottom of the application.
Definition status_bar.h:39
Manages undo/redo stacks for a single editor.
std::string GetRedoDescription() const
Description of the action that would be redone (for UI)
std::string GetUndoDescription() const
Description of the action that would be undone (for UI)
Manages user preferences and settings persistence.
A class for emulating and debugging SNES games.
Definition emulator.h:40
Defines an abstract interface for all rendering operations.
Definition irenderer.h:60
constexpr std::array< const char *, 14 > kEditorNames
Definition editor.h:217
size_t EditorTypeIndex(EditorType type)
Definition editor.h:226
constexpr size_t kEditorTypeCount
Definition editor.h:223
zelda3::GameData * game_data
Definition editor.h:132
EditorContext context() const
Definition editor.h:138
GlobalEditorContext * global_context
Definition editor.h:135
project::YazeProject * project
Definition editor.h:133
core::VersionManager * version_manager
Definition editor.h:134
Lightweight view into the essential runtime context (Rom + GameData)
Definition editor.h:70
bool HasGameData() const
Definition editor.h:77
zelda3::GameData * game_data
Definition editor.h:72
Unified dependency container for all editor types.
Definition editor.h:163
project::YazeProject * project
Definition editor.h:167
GlobalEditorContext * global_context
Definition editor.h:169
SharedClipboard * shared_clipboard
Definition editor.h:178
gfx::IRenderer * renderer
Definition editor.h:183
ShortcutManager * shortcut_manager
Definition editor.h:177
core::VersionManager * version_manager
Definition editor.h:168
zelda3::GameData * game_data
Definition editor.h:166
EditorContext context() const
Definition editor.h:196
CoreDependencies GetCoreDeps() const
Definition editor.h:188
UIDependencies GetUIDeps() const
Definition editor.h:191
std::vector< int > overworld_tile16_ids
Definition editor.h:117
UndoManager * undo_manager
Definition editor.h:146
PanelManager * panel_manager
Definition editor.h:144
ToastManager * toast_manager
Definition editor.h:145
ShortcutManager * shortcut_manager
Definition editor.h:148
UserSettings * user_settings
Definition editor.h:150
SharedClipboard * shared_clipboard
Definition editor.h:149
PopupManager * popup_manager
Definition editor.h:147
Modern project structure with comprehensive settings consolidation.
Definition project.h:120