yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
session_types.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SESSION_TYPES_H_
2#define YAZE_APP_EDITOR_SESSION_TYPES_H_
3
4#include <array>
5#include <cstdint>
6#include <functional>
7#include <map>
8#include <memory>
9#include <optional>
10#include <string>
11#include <string_view>
12#include <unordered_map>
13#include <utility>
14#include <vector>
15
17#include "app/editor/editor.h"
19#include "core/asar_wrapper.h" // For AsarSymbol (backend-agnostic symbol shape)
20#include "core/features.h"
21#include "core/project.h"
22#include "rom/rom.h"
23#include "zelda3/game_data.h"
24
25namespace yaze::core {
26class AsarWrapper;
27class VersionManager;
28} // namespace yaze::core
29
30namespace yaze::zelda3 {
31class Overworld;
32}
33
34namespace yaze::editor {
35
36class EditorDependencies;
37class EditorRegistry;
38class UserSettings;
39
40// Forward declarations for legacy accessors
41class AssemblyEditor;
42class MemoryEditor;
43class DungeonEditorV2;
44class GraphicsEditor;
45class ScreenEditor;
46class MessageEditor;
47class MusicEditor;
48class OverworldEditor;
49class PaletteEditor;
50class SpriteEditor;
51class SettingsPanel;
52
57class EditorSet {
58 public:
59 explicit EditorSet(Rom* rom = nullptr, zelda3::GameData* game_data = nullptr,
60 UserSettings* user_settings = nullptr,
61 size_t session_id = 0,
62 EditorRegistry* editor_registry = nullptr);
64
65 void set_user_settings(UserSettings* settings);
66 void SetGameData(zelda3::GameData* game_data);
67
68 void ApplyDependencies(const EditorDependencies& dependencies);
69
70 size_t session_id() const { return session_id_; }
71
72 // Generic accessors
73 Editor* GetEditor(EditorType type) const;
74 // Returns an already-created editor without materializing a lazy editor.
75 Editor* GetExistingEditor(EditorType type) const { return FindEditor(type); }
76
77 template <typename T>
78 T* GetEditorAs(EditorType type) const {
79 return static_cast<T*>(GetEditor(type));
80 }
81
82 // Convenience helpers that avoid requiring concrete editor headers.
83 // Prefer these from higher-level systems (EditorManager, UI) to keep compile
84 // dependencies minimal.
85 void OpenAssemblyFolder(const std::string& folder_path) const;
86 void ChangeActiveAssemblyFile(std::string_view path) const;
88
89 // Backend-agnostic accessor for assembly symbols (works for both Asar
90 // and z3dk backends). Returns the assembly editor's last-known symbol
91 // table. Empty if no editor / no assemble has happened yet.
92 const std::map<std::string, core::AsarSymbol>& GetAssemblySymbols() const;
93 int LoadedDungeonRoomCount() const;
94 int TotalDungeonRoomCount() const;
95 std::vector<std::pair<uint32_t, uint32_t>> CollectDungeonWriteRanges() const;
97
98 // Deprecated named accessors (legacy compatibility)
99 [[deprecated("Use GetEditorAs<AssemblyEditor>(EditorType::kAssembly)")]]
101 [[deprecated("Use GetEditorAs<DungeonEditorV2>(EditorType::kDungeon)")]]
103 [[deprecated("Use GetEditorAs<GraphicsEditor>(EditorType::kGraphics)")]]
105 [[deprecated("Use GetEditorAs<MusicEditor>(EditorType::kMusic)")]]
107 [[deprecated("Use GetEditorAs<OverworldEditor>(EditorType::kOverworld)")]]
109 [[deprecated("Use GetEditorAs<PaletteEditor>(EditorType::kPalette)")]]
111 [[deprecated("Use GetEditorAs<ScreenEditor>(EditorType::kScreen)")]]
113 [[deprecated("Use GetEditorAs<SpriteEditor>(EditorType::kSprite)")]]
115 [[deprecated("Use GetEditorAs<SettingsPanel>(EditorType::kSettings)")]]
117 [[deprecated("Use GetEditorAs<MessageEditor>(EditorType::kMessage)")]]
119 [[deprecated("Use GetEditorAs<MemoryEditor>(EditorType::kHex)")]]
121
127 return gfx_group_workspace_.get();
128 }
129
130 std::vector<Editor*> active_editors_;
131
132 private:
133 using EditorFactory = std::function<std::unique_ptr<Editor>()>;
134
135 Editor* FindEditor(EditorType type) const;
137 bool ShouldTrackAsActiveEditor(EditorType type) const;
138 void TrackActiveEditor(Editor* editor);
139
140 size_t session_id_ = 0;
141 Rom* rom_ = nullptr;
145
146 std::optional<EditorDependencies> dependencies_;
147 mutable std::unordered_map<EditorType, std::unique_ptr<Editor>> editors_;
148 std::unordered_map<EditorType, EditorFactory> editor_factories_;
149
150 std::unique_ptr<GfxGroupWorkspaceState> gfx_group_workspace_;
151};
152
162 std::string custom_name; // User-defined session name
163 std::string filepath; // ROM filepath for duplicate detection
164 core::FeatureFlags::Flags feature_flags; // Per-session feature flags
165 // Full project/save policy snapshot for this ROM. An empty optional means
166 // the session has not yet been bound to a project context and must not save.
167 std::optional<project::YazeProject> project_context;
168 bool project_dirty = false;
169 // A restored backup is staged for inspection and must never be committed by
170 // the periodic autosave path. Explicit Save ROM / Save As clears this flag.
173 // VersionManager keeps a raw project pointer internally, so its lifetime
174 // must be tied to the stable, session-owned project_context above. Editors
175 // cache this pointer for their entire lifetime.
176 std::unique_ptr<core::VersionManager> version_manager;
177 bool game_data_loaded = false;
178 std::array<bool, kEditorTypeCount> editor_initialized{};
179 std::array<bool, kEditorTypeCount> editor_assets_loaded{};
180
181 RomSession() = default;
182 RomSession(UserSettings* user_settings, size_t session_id,
183 EditorRegistry* editor_registry = nullptr);
184 explicit RomSession(Rom&& r, UserSettings* user_settings = nullptr,
185 size_t session_id = 0,
186 EditorRegistry* editor_registry = nullptr);
187 ~RomSession();
188
189 size_t session_id() const { return editors.session_id(); }
190
191 // Get display name (custom name or ROM title)
192 std::string GetDisplayName() const;
193};
194
195} // namespace yaze::editor
196
197#endif // YAZE_APP_EDITOR_SESSION_TYPES_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
Modern C++ wrapper for Asar 65816 assembler integration.
Text editor for modifying assembly code.
DungeonEditorV2 - Simplified dungeon editor using component delegation.
Manages editor types, categories, and lifecycle.
Contains a complete set of editors for a single ROM instance.
std::optional< EditorDependencies > dependencies_
MemoryEditor * GetMemoryEditor() const
T * GetEditorAs(EditorType type) const
std::unordered_map< EditorType, std::unique_ptr< Editor > > editors_
DungeonEditorV2 * GetDungeonEditor() const
void OpenAssemblyFolder(const std::string &folder_path) const
MusicEditor * GetMusicEditor() const
ScreenEditor * GetScreenEditor() const
void SetGameData(zelda3::GameData *game_data)
Editor * GetExistingEditor(EditorType type) const
bool ShouldTrackAsActiveEditor(EditorType type) const
core::AsarWrapper * GetAsarWrapper() const
std::unique_ptr< GfxGroupWorkspaceState > gfx_group_workspace_
void TrackActiveEditor(Editor *editor)
void ChangeActiveAssemblyFile(std::string_view path) const
size_t session_id() const
void ApplyDependencies(const EditorDependencies &dependencies)
const std::map< std::string, core::AsarSymbol > & GetAssemblySymbols() const
EditorSet(Rom *rom=nullptr, zelda3::GameData *game_data=nullptr, UserSettings *user_settings=nullptr, size_t session_id=0, EditorRegistry *editor_registry=nullptr)
Editor * EnsureEditorCreated(EditorType type) const
SpriteEditor * GetSpriteEditor() const
UserSettings * user_settings_
Editor * GetEditor(EditorType type) const
GraphicsEditor * GetGraphicsEditor() const
int LoadedDungeonRoomCount() const
Editor * FindEditor(EditorType type) const
PaletteEditor * GetPaletteEditor() const
std::unordered_map< EditorType, EditorFactory > editor_factories_
const GfxGroupWorkspaceState * gfx_group_workspace() const
EditorRegistry * editor_registry_
void set_user_settings(UserSettings *settings)
zelda3::Overworld * GetOverworldData() const
GfxGroupWorkspaceState * gfx_group_workspace()
MessageEditor * GetMessageEditor() const
std::function< std::unique_ptr< Editor >()> EditorFactory
int TotalDungeonRoomCount() const
SettingsPanel * GetSettingsPanel() const
std::vector< Editor * > active_editors_
zelda3::GameData * game_data_
OverworldEditor * GetOverworldEditor() const
AssemblyEditor * GetAssemblyEditor() const
std::vector< std::pair< uint32_t, uint32_t > > CollectDungeonWriteRanges() const
Interface for editor classes.
Definition editor.h:245
Allows the user to edit graphics sheets from the game or view prototype graphics.
A class for editing music data in a Rom.
Main UI class for editing overworld maps in A Link to the Past.
Allows the user to view and edit in game palettes.
The ScreenEditor class allows the user to edit a variety of screens in the game or create a custom me...
Manages the settings UI displayed in the right sidebar.
Allows the user to edit sprites.
Manages user preferences and settings persistence.
Represents the full Overworld data, light and dark world.
Definition overworld.h:389
Editors are the view controllers for the application.
Zelda 3 specific classes and functions.
Unified dependency container for all editor types.
Definition editor.h:169
Per-ROM-session UI state shared by all GfxGroupEditor surfaces.
Represents a single session, containing a ROM and its associated editors.
core::FeatureFlags::Flags feature_flags
ProjectFileEditorState project_file_editor_state
std::array< bool, kEditorTypeCount > editor_initialized
zelda3::GameData game_data
std::unique_ptr< core::VersionManager > version_manager
std::array< bool, kEditorTypeCount > editor_assets_loaded
std::string GetDisplayName() const
std::optional< project::YazeProject > project_context