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} // namespace yaze
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
47struct GfxGroupWorkspaceState;
48class GlobalEditorContext;
49class WorkspaceWindowManager;
50class ToastManager;
51class UserSettings;
52class StatusBar;
53
72 Rom* rom = nullptr;
74
75 // Check if context is valid for operations
76 bool IsValid() const { return rom != nullptr && game_data != nullptr; }
77 bool HasRom() const { return rom != nullptr; }
78 bool HasGameData() const { return game_data != nullptr; }
79
80 // Implicit conversion to bool for quick validity checks
81 explicit operator bool() const { return IsValid(); }
82};
83
115// Shared clipboard for cross-editor copy/paste operations.
118 std::vector<int> overworld_tile16_ids;
121
122 void Clear() {
123 has_overworld_tile16 = false;
124 overworld_tile16_ids.clear();
125 overworld_width = 0;
127 }
128};
129
130// Data-layer dependencies: ROM, game data, project, session identity.
132 Rom* rom = nullptr;
137 size_t session_id = 0;
138
139 EditorContext context() const { return {rom, game_data}; }
140 bool HasContext() const { return rom != nullptr && game_data != nullptr; }
141};
142
143// UI-layer dependencies: panel/popup/toast/shortcut managers.
154
165 // --- Core (data-layer) dependencies ---
166 Rom* rom = nullptr;
171 size_t session_id = 0;
174
175 // --- UI-layer dependencies ---
184
185 // --- Specialized dependencies ---
188 void* custom_data = nullptr;
189
190 // Extract sub-structs for passing to components that only need a subset.
199
200 EditorContext context() const { return {rom, game_data}; }
201 bool HasContext() const { return rom != nullptr && game_data != nullptr; }
202};
203
204enum class EditorType {
205 kUnknown,
206 kAssembly,
207 kDungeon,
208 kEmulator,
209 kGraphics,
210 kMusic,
212 kPalette,
213 kScreen,
214 kSprite,
215 kMessage,
216 kHex,
217 kAgent,
218 kSettings,
219};
220
221constexpr std::array<const char*, 14> kEditorNames = {
222 "Unknown", "Assembly", "Dungeon", "Emulator", "Graphics",
223 "Music", "Overworld", "Palette", "Screen", "Sprite",
224 "Message", "Hex", "Agent", "Settings",
225};
226
227constexpr size_t kEditorTypeCount =
228 static_cast<size_t>(EditorType::kSettings) + 1;
229
230inline size_t EditorTypeIndex(EditorType type) {
231 return static_cast<size_t>(type);
232}
233
240class Editor {
241 public:
242 Editor() = default;
243 virtual ~Editor() = default;
244
245 virtual void SetDependencies(const EditorDependencies& deps) {
246 dependencies_ = deps;
247 }
248
249 // Set GameData for Zelda3-specific data access
253
254 // Initialization of the editor, no ROM assets.
255 virtual void Initialize() = 0;
256
257 // Initialization of ROM assets.
258 virtual absl::Status Load() = 0;
259
260 // Save the editor state.
261 virtual absl::Status Save() = 0;
262
263 // Update the editor state, ran every frame.
264 virtual absl::Status Update() = 0;
265
266 virtual absl::Status Cut() = 0;
267 virtual absl::Status Copy() = 0;
268 virtual absl::Status Paste() = 0;
269
270 virtual absl::Status Undo() = 0;
271 virtual absl::Status Redo() = 0;
272
273 // Undo description for toast feedback (queries editor's UndoManager)
274 virtual std::string GetUndoDescription() const {
276 }
277 virtual std::string GetRedoDescription() const {
279 }
280
281 const UndoManager& undo_manager() const { return undo_manager_; }
282
283 virtual absl::Status Find() = 0;
284
285 virtual absl::Status Clear() { return absl::OkStatus(); }
286
287 // Push editor-specific context into the shared status bar.
288 // Called each frame on the currently active editor by EditorManager.
289 // Default no-op; override to surface cursor/selection/zoom/mode/custom
290 // segments via StatusBar's Set* setters.
291 virtual void ContributeStatus(StatusBar* /*status_bar*/) {}
292
293 EditorType type() const { return type_; }
294
295 bool* active() { return &active_; }
296 void set_active(bool active) { active_ = active; }
298
299 // ROM loading state helpers (default implementations)
300 virtual bool IsRomLoaded() const { return false; }
301 virtual std::string GetRomStatus() const {
302 return "ROM state not implemented";
303 }
304
305 // Accessors for common dependencies
306 Rom* rom() const { return dependencies_.rom; }
308
309 // Get bundled context for sub-components
311 bool HasContext() const { return dependencies_.HasContext(); }
312
313 protected:
314 bool active_ = false;
318
319 // Helper method to create session-aware card titles for multi-session support
320 std::string MakePanelTitle(const std::string& base_title) const {
321 if (dependencies_.session_id > 0) {
322 return absl::StrFormat("%s [S%zu]", base_title, dependencies_.session_id);
323 }
324 return base_title;
325 }
326
327 // Helper method to create session-aware card IDs for multi-session support
328 std::string MakeWindowId(const std::string& base_id) const {
329 if (dependencies_.session_id > 0) {
330 return absl::StrFormat("s%zu.%s", dependencies_.session_id, base_id);
331 }
332 return base_id;
333 }
334
335 // Helper method for ROM access with safety check
336 template <typename T>
337 absl::StatusOr<T> SafeRomAccess(std::function<T()> accessor,
338 const std::string& operation = "") const {
339 if (!IsRomLoaded()) {
340 return absl::FailedPreconditionError(
341 operation.empty() ? "ROM not loaded"
342 : absl::StrFormat("%s: ROM not loaded", operation));
343 }
344 try {
345 return accessor();
346 } catch (const std::exception& e) {
347 return absl::InternalError(absl::StrFormat(
348 "%s: %s", operation.empty() ? "ROM access failed" : operation,
349 e.what()));
350 }
351 }
352};
353
354} // namespace editor
355} // namespace yaze
356
357#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:240
virtual void SetGameData(zelda3::GameData *game_data)
Definition editor.h:250
bool HasContext() const
Definition editor.h:311
virtual absl::Status Cut()=0
virtual absl::Status Copy()=0
virtual void ContributeStatus(StatusBar *)
Definition editor.h:291
virtual absl::Status Redo()=0
EditorContext context() const
Definition editor.h:310
UndoManager undo_manager_
Definition editor.h:317
virtual std::string GetRedoDescription() const
Definition editor.h:277
const UndoManager & undo_manager() const
Definition editor.h:281
virtual void SetDependencies(const EditorDependencies &deps)
Definition editor.h:245
std::string MakeWindowId(const std::string &base_id) const
Definition editor.h:328
virtual void Initialize()=0
Rom * rom() const
Definition editor.h:306
zelda3::GameData * game_data() const
Definition editor.h:307
EditorDependencies dependencies_
Definition editor.h:316
virtual absl::Status Clear()
Definition editor.h:285
EditorType type() const
Definition editor.h:293
void set_active(bool active)
Definition editor.h:296
virtual ~Editor()=default
virtual std::string GetRomStatus() const
Definition editor.h:301
EditorType type_
Definition editor.h:315
virtual absl::Status Save()=0
virtual bool IsRomLoaded() const
Definition editor.h:300
std::string MakePanelTitle(const std::string &base_title) const
Definition editor.h:320
absl::StatusOr< T > SafeRomAccess(std::function< T()> accessor, const std::string &operation="") const
Definition editor.h:337
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:274
Instance-based runtime context replacing ContentRegistry::Context.
A session-aware status bar displayed at the bottom of the application.
Definition status_bar.h:54
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.
Central registry for all editor cards with session awareness and dependency injection.
A class for emulating and debugging SNES games.
Definition emulator.h:41
Defines an abstract interface for all rendering operations.
Definition irenderer.h:60
constexpr std::array< const char *, 14 > kEditorNames
Definition editor.h:221
size_t EditorTypeIndex(EditorType type)
Definition editor.h:230
constexpr size_t kEditorTypeCount
Definition editor.h:227
zelda3::GameData * game_data
Definition editor.h:133
EditorContext context() const
Definition editor.h:139
GlobalEditorContext * global_context
Definition editor.h:136
project::YazeProject * project
Definition editor.h:134
core::VersionManager * version_manager
Definition editor.h:135
Lightweight view into the essential runtime context (Rom + GameData)
Definition editor.h:71
bool HasGameData() const
Definition editor.h:78
zelda3::GameData * game_data
Definition editor.h:73
Unified dependency container for all editor types.
Definition editor.h:164
project::YazeProject * project
Definition editor.h:168
GlobalEditorContext * global_context
Definition editor.h:170
SharedClipboard * shared_clipboard
Definition editor.h:181
gfx::IRenderer * renderer
Definition editor.h:186
ShortcutManager * shortcut_manager
Definition editor.h:180
core::VersionManager * version_manager
Definition editor.h:169
zelda3::GameData * game_data
Definition editor.h:167
EditorContext context() const
Definition editor.h:200
CoreDependencies GetCoreDeps() const
Definition editor.h:191
UIDependencies GetUIDeps() const
Definition editor.h:195
WorkspaceWindowManager * window_manager
Definition editor.h:176
GfxGroupWorkspaceState * gfx_group_workspace
Definition editor.h:173
Per-ROM-session UI state shared by all GfxGroupEditor surfaces.
std::vector< int > overworld_tile16_ids
Definition editor.h:118
UndoManager * undo_manager
Definition editor.h:147
ToastManager * toast_manager
Definition editor.h:146
ShortcutManager * shortcut_manager
Definition editor.h:149
UserSettings * user_settings
Definition editor.h:151
WorkspaceWindowManager * window_manager
Definition editor.h:145
SharedClipboard * shared_clipboard
Definition editor.h:150
PopupManager * popup_manager
Definition editor.h:148
Modern project structure with comprehensive settings consolidation.
Definition project.h:164