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 "util/rom_hash.h"
24#include "zelda3/game_data.h"
25
26namespace yaze::core {
27class AsarWrapper;
28class VersionManager;
29} // namespace yaze::core
30
31namespace yaze::zelda3 {
32class Overworld;
33}
34
35namespace yaze::editor {
36
37class EditorDependencies;
38class EditorRegistry;
39class UserSettings;
40
41// Forward declarations for legacy accessors
42class AssemblyEditor;
43class MemoryEditor;
44class DungeonEditorV2;
45class GraphicsEditor;
46class ScreenEditor;
47class MessageEditor;
48class MusicEditor;
49class OverworldEditor;
50class PaletteEditor;
51class SpriteEditor;
52class SettingsPanel;
53
58class EditorSet {
59 public:
60 explicit EditorSet(Rom* rom = nullptr, zelda3::GameData* game_data = nullptr,
61 UserSettings* user_settings = nullptr,
62 size_t session_id = 0,
63 EditorRegistry* editor_registry = nullptr);
65
66 void set_user_settings(UserSettings* settings);
67 void SetGameData(zelda3::GameData* game_data);
68
69 void ApplyDependencies(const EditorDependencies& dependencies);
70
71 // Give materialized editors one terminal detach pass while their external
72 // WorkspaceWindowManager panels are still alive.
74
75 size_t session_id() const { return session_id_; }
76
77 // Generic accessors
78 Editor* GetEditor(EditorType type) const;
79 // Returns an already-created editor without materializing a lazy editor.
80 Editor* GetExistingEditor(EditorType type) const { return FindEditor(type); }
81
82 template <typename T>
83 T* GetEditorAs(EditorType type) const {
84 return static_cast<T*>(GetEditor(type));
85 }
86
87 // Convenience helpers that avoid requiring concrete editor headers.
88 // Prefer these from higher-level systems (EditorManager, UI) to keep compile
89 // dependencies minimal.
90 void OpenAssemblyFolder(const std::string& folder_path) const;
91 void ChangeActiveAssemblyFile(std::string_view path) const;
93
94 // Backend-agnostic accessor for assembly symbols (works for both Asar
95 // and z3dk backends). Returns the assembly editor's last-known symbol
96 // table. Empty if no editor / no assemble has happened yet.
97 const std::map<std::string, core::AsarSymbol>& GetAssemblySymbols() const;
98 int LoadedDungeonRoomCount() const;
99 int TotalDungeonRoomCount() const;
100 std::vector<std::pair<uint32_t, uint32_t>> CollectDungeonWriteRanges() const;
101 bool HasPendingGraphicsChanges() const;
102 bool HasPendingSpriteChanges() const;
103 bool HasPendingScreenChanges() const;
104 // Reset cached Screen Editor models only when that lazy editor already
105 // exists. ROM replacement must not materialize an otherwise-unused editor.
108 // Project drafts other than Planning, whose plan is a live reference rather
109 // than a build input.
112 absl::Status SavePlanningProjectDraft();
113 absl::Status PrepareProjectSave(bool publish_lyra = true);
117
118 // Deprecated named accessors (legacy compatibility)
119 [[deprecated("Use GetEditorAs<AssemblyEditor>(EditorType::kAssembly)")]]
121 [[deprecated("Use GetEditorAs<DungeonEditorV2>(EditorType::kDungeon)")]]
123 [[deprecated("Use GetEditorAs<GraphicsEditor>(EditorType::kGraphics)")]]
125 [[deprecated("Use GetEditorAs<MusicEditor>(EditorType::kMusic)")]]
127 [[deprecated("Use GetEditorAs<OverworldEditor>(EditorType::kOverworld)")]]
129 [[deprecated("Use GetEditorAs<PaletteEditor>(EditorType::kPalette)")]]
131 [[deprecated("Use GetEditorAs<ScreenEditor>(EditorType::kScreen)")]]
133 [[deprecated("Use GetEditorAs<SpriteEditor>(EditorType::kSprite)")]]
135 [[deprecated("Use GetEditorAs<SettingsPanel>(EditorType::kSettings)")]]
137 [[deprecated("Use GetEditorAs<MessageEditor>(EditorType::kMessage)")]]
139 [[deprecated("Use GetEditorAs<MemoryEditor>(EditorType::kHex)")]]
141
147 return gfx_group_workspace_.get();
148 }
149
150 std::vector<Editor*> active_editors_;
151
152 private:
153 using EditorFactory = std::function<std::unique_ptr<Editor>()>;
154
155 Editor* FindEditor(EditorType type) const;
157 bool ShouldTrackAsActiveEditor(EditorType type) const;
158 void TrackActiveEditor(Editor* editor);
159
160 size_t session_id_ = 0;
161 Rom* rom_ = nullptr;
165
166 std::optional<EditorDependencies> dependencies_;
167 mutable std::unordered_map<EditorType, std::unique_ptr<Editor>> editors_;
168 std::unordered_map<EditorType, EditorFactory> editor_factories_;
170
171 std::unique_ptr<GfxGroupWorkspaceState> gfx_group_workspace_;
172};
173
176 std::string normalized_path;
177 // Retained across our own saves, reset when loading/replacing ROM bytes.
179 // SHA-256 of the backing file bytes (copier header included) as loaded or
180 // last written by this session; empty when the ROM was already dirty.
181 std::string backing_sha256;
182};
183
184// SHA-256 of the bytes SaveToFile writes for this ROM, copier header included.
185std::string ComputeRomFileBytesSha256(const Rom& rom);
186
194 // Identity of loaded/committed bytes, independent of pending raw/model edits.
195 // Empty sessions have no baseline. Session activation must never capture it.
196 std::optional<RomBaselineIdentity> rom_baseline;
197 void CaptureRomIdentity(bool preserve_editing_source = false);
198
200 // Display copies have stable addresses across user and per-frame activation.
201 // Authored pixels remain in game_data.sheet_store; loaded palette colors stay
202 // in game_data.gfx_bitmaps. Allocate only after graphics are loaded.
206
208 std::string custom_name; // User-defined session name
209 std::string filepath; // ROM filepath for duplicate detection
210 core::FeatureFlags::Flags feature_flags; // Per-session feature flags
211 // Full project/save policy snapshot for this ROM. An empty optional means
212 // the session has not yet been bound to a project context and must not save.
213 std::optional<project::YazeProject> project_context;
214 bool project_dirty = false;
215 // A build-owned project Save persisted, but its native-save receipt is not
216 // yet published. The next Save retries completion without new edits.
219
220 // True when the gfx group tables (blocksets, spritesets, palettesets) in
221 // game_data differ from the ROM buffer. Derived from the data, so every
222 // edit path counts without extra dirty flags.
223 bool HasPendingGfxGroupChanges() const;
224 // A restored backup is staged for inspection and must never be committed by
225 // the periodic autosave path. Explicit Save ROM / Save As clears this flag.
228 // VersionManager keeps a raw project pointer internally, so its lifetime
229 // must be tied to the stable, session-owned project_context above. Editors
230 // cache this pointer for their entire lifetime.
231 std::unique_ptr<core::VersionManager> version_manager;
232 bool game_data_loaded = false;
233 std::array<bool, kEditorTypeCount> editor_initialized{};
234 std::array<bool, kEditorTypeCount> editor_assets_loaded{};
235
236 RomSession() = default;
237 RomSession(UserSettings* user_settings, size_t session_id,
238 EditorRegistry* editor_registry = nullptr);
239 explicit RomSession(Rom&& r, UserSettings* user_settings = nullptr,
240 size_t session_id = 0,
241 EditorRegistry* editor_registry = nullptr);
242 ~RomSession();
243
244 private:
245 std::unique_ptr<std::array<gfx::Bitmap, zelda3::kNumGfxSheets>>
247
248 public:
249 size_t session_id() const { return editors.session_id(); }
250
251 // Get display name (custom name or ROM title)
252 std::string GetDisplayName() const;
253};
254
255} // namespace yaze::editor
256
257#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:52
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_
bool HasPendingSpriteChanges() const
DungeonEditorV2 * GetDungeonEditor() const
void OpenAssemblyFolder(const std::string &folder_path) const
MusicEditor * GetMusicEditor() const
ScreenEditor * GetScreenEditor() const
void SetGameData(zelda3::GameData *game_data)
bool HasPendingProjectDraftChanges() const
Editor * GetExistingEditor(EditorType type) const
bool HasPendingPlanningProjectDraftChanges() const
bool ShouldTrackAsActiveEditor(EditorType type) const
core::AsarWrapper * GetAsarWrapper() const
std::unique_ptr< GfxGroupWorkspaceState > gfx_group_workspace_
bool HasPendingBuildProjectDraftChanges() const
void TrackActiveEditor(Editor *editor)
absl::Status PrepareProjectSave(bool publish_lyra=true)
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
bool HasPendingGraphicsChanges() const
bool HasPendingScreenChanges() 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
absl::Status SavePlanningProjectDraft()
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:252
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.
Editors are the view controllers for the application.
std::string ComputeRomFileBytesSha256(const Rom &rom)
Zelda 3 specific classes and functions.
Unified dependency container for all editor types.
Definition editor.h:170
Per-ROM-session UI state shared by all GfxGroupEditor surfaces.
util::RomIdentityHashes hashes
Represents a single session, containing a ROM and its associated editors.
std::unique_ptr< std::array< gfx::Bitmap, zelda3::kNumGfxSheets > > graphics_display_
core::FeatureFlags::Flags feature_flags
ProjectFileEditorState project_file_editor_state
void CaptureRomIdentity(bool preserve_editing_source=false)
bool HasPendingGfxGroupChanges() const
std::optional< RomBaselineIdentity > rom_baseline
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