yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
session_types.cc
Go to the documentation of this file.
2
6#include "app/editor/editor.h"
18
19namespace yaze::editor {
20
22 UserSettings* user_settings, size_t session_id,
23 EditorRegistry* editor_registry)
24 : session_id_(session_id), game_data_(game_data) {
25 auto create_editor = [&](EditorType type,
26 auto&& fallback) -> std::unique_ptr<Editor> {
27 if (editor_registry) {
28 if (auto created = editor_registry->CreateEditor(type, rom)) {
29 return created;
30 }
31 }
32 return fallback();
33 };
34
36 create_editor(EditorType::kAssembly,
37 [&]() { return std::make_unique<AssemblyEditor>(rom); });
39 create_editor(EditorType::kDungeon,
40 [&]() { return std::make_unique<DungeonEditorV2>(rom); });
42 create_editor(EditorType::kGraphics,
43 [&]() { return std::make_unique<GraphicsEditor>(rom); });
45 create_editor(EditorType::kMusic,
46 [&]() { return std::make_unique<MusicEditor>(rom); });
48 create_editor(EditorType::kOverworld,
49 [&]() { return std::make_unique<OverworldEditor>(rom); });
51 create_editor(EditorType::kPalette,
52 [&]() { return std::make_unique<PaletteEditor>(rom); });
54 create_editor(EditorType::kScreen,
55 [&]() { return std::make_unique<ScreenEditor>(rom); });
57 create_editor(EditorType::kSprite,
58 [&]() { return std::make_unique<SpriteEditor>(rom); });
60 create_editor(EditorType::kMessage,
61 [&]() { return std::make_unique<MessageEditor>(rom); });
63 create_editor(EditorType::kHex,
64 [&]() { return std::make_unique<MemoryEditor>(rom); });
66 create_editor(EditorType::kSettings,
67 [&]() { return std::make_unique<SettingsPanel>(); });
68
69 // Propagate game_data to editors that need it
70 if (game_data) {
71 GetDungeonEditor()->SetGameData(game_data);
72 GetGraphicsEditor()->SetGameData(game_data);
73 GetOverworldEditor()->SetGameData(game_data);
74 }
75
82}
83
84EditorSet::~EditorSet() = default;
85
89
91 for (auto& [type, editor] : editors_) {
92 editor->SetDependencies(dependencies);
93 }
94}
95
97 auto it = editors_.find(type);
98 if (it != editors_.end()) {
99 return it->second.get();
100 }
101 return nullptr;
102}
103
104void EditorSet::OpenAssemblyFolder(const std::string& folder_path) const {
105 if (auto* editor = GetAssemblyEditor()) {
106 editor->OpenFolder(folder_path);
107 }
108}
109
110void EditorSet::ChangeActiveAssemblyFile(std::string_view path) const {
111 if (auto* editor = GetAssemblyEditor()) {
112 editor->ChangeActiveFile(path);
113 }
114}
115
117 if (auto* editor = GetAssemblyEditor()) {
118 return editor->asar_wrapper();
119 }
120 return nullptr;
121}
122
124 if (auto* editor = GetDungeonEditor()) {
125 return editor->LoadedRoomCount();
126 }
127 return 0;
128}
129
131 if (auto* editor = GetDungeonEditor()) {
132 return editor->TotalRoomCount();
133 }
134 return 0;
135}
136
137std::vector<std::pair<uint32_t, uint32_t>> EditorSet::CollectDungeonWriteRanges()
138 const {
139 if (auto* editor = GetDungeonEditor()) {
140 return editor->CollectWriteRanges();
141 }
142 return {};
143}
144
146 if (auto* editor = GetOverworldEditor()) {
147 return &editor->overworld();
148 }
149 return nullptr;
150}
151
152// Deprecated named accessors
154 return GetEditorAs<AssemblyEditor>(EditorType::kAssembly);
155}
157 return GetEditorAs<DungeonEditorV2>(EditorType::kDungeon);
158}
160 return GetEditorAs<GraphicsEditor>(EditorType::kGraphics);
161}
163 return GetEditorAs<MusicEditor>(EditorType::kMusic);
164}
166 return GetEditorAs<OverworldEditor>(EditorType::kOverworld);
167}
169 return GetEditorAs<PaletteEditor>(EditorType::kPalette);
170}
172 return GetEditorAs<ScreenEditor>(EditorType::kScreen);
173}
175 return GetEditorAs<SpriteEditor>(EditorType::kSprite);
176}
178 return GetEditorAs<SettingsPanel>(EditorType::kSettings);
179}
181 return GetEditorAs<MessageEditor>(EditorType::kMessage);
182}
184 return GetEditorAs<MemoryEditor>(EditorType::kHex);
185}
186
187RomSession::RomSession(Rom&& r, UserSettings* user_settings, size_t session_id,
188 EditorRegistry* editor_registry)
189 : rom(std::move(r)),
190 game_data(&rom),
191 editors(&rom, &game_data, user_settings, session_id, editor_registry) {
194}
195
196std::string RomSession::GetDisplayName() const {
197 if (!custom_name.empty()) {
198 return custom_name;
199 }
200 return rom.title().empty() ? "Untitled Session" : rom.title();
201}
202
203} // namespace yaze::editor
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
auto filename() const
Definition rom.h:145
auto title() const
Definition rom.h:137
Modern C++ wrapper for Asar 65816 assembler integration.
Text editor for modifying assembly code.
DungeonEditorV2 - Simplified dungeon editor using component delegation.
void SetGameData(zelda3::GameData *game_data) override
Manages editor types, categories, and lifecycle.
std::unique_ptr< Editor > CreateEditor(EditorType type, Rom *rom) const
MemoryEditor * GetMemoryEditor() 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
core::AsarWrapper * GetAsarWrapper() const
void ChangeActiveAssemblyFile(std::string_view path) const
void ApplyDependencies(const EditorDependencies &dependencies)
EditorSet(Rom *rom=nullptr, zelda3::GameData *game_data=nullptr, UserSettings *user_settings=nullptr, size_t session_id=0, EditorRegistry *editor_registry=nullptr)
SpriteEditor * GetSpriteEditor() const
Editor * GetEditor(EditorType type) const
GraphicsEditor * GetGraphicsEditor() const
int LoadedDungeonRoomCount() const
PaletteEditor * GetPaletteEditor() const
void set_user_settings(UserSettings *settings)
zelda3::Overworld * GetOverworldData() const
MessageEditor * GetMessageEditor() const
int TotalDungeonRoomCount() const
SettingsPanel * GetSettingsPanel() const
std::vector< Editor * > active_editors_
OverworldEditor * GetOverworldEditor() const
AssemblyEditor * GetAssemblyEditor() const
std::vector< std::pair< uint32_t, uint32_t > > CollectDungeonWriteRanges() const
Interface for editor classes.
Definition editor.h:236
Allows the user to edit graphics sheets from the game or view prototype graphics.
void SetGameData(zelda3::GameData *game_data) override
A class for editing music data in a Rom.
Main UI class for editing overworld maps in A Link to the Past.
void SetGameData(zelda3::GameData *game_data) override
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.
void SetUserSettings(UserSettings *settings)
Allows the user to edit sprites.
Manages user preferences and settings persistence.
Represents the full Overworld data, light and dark world.
Definition overworld.h:261
Editors are the view controllers for the application.
Unified dependency container for all editor types.
Definition editor.h:163
core::FeatureFlags::Flags feature_flags
std::string GetDisplayName() const