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
3#include <algorithm>
4
8#include "app/editor/editor.h"
22
23namespace yaze::editor {
24
26 UserSettings* user_settings, size_t session_id,
27 EditorRegistry* editor_registry)
28 : session_id_(session_id),
29 rom_(rom),
30 game_data_(game_data),
31 user_settings_(user_settings),
32 editor_registry_(editor_registry),
33 gfx_group_workspace_(std::make_unique<GfxGroupWorkspaceState>()) {
34 auto register_factory = [&](EditorType type, auto&& fallback) {
35 editor_factories_[type] =
36 [this, type,
37 fallback = std::forward<decltype(fallback)>(
38 fallback)]() mutable -> std::unique_ptr<Editor> {
39 if (editor_registry_) {
40 if (auto created = editor_registry_->CreateEditor(type, rom_)) {
41 return created;
42 }
43 }
44 return fallback();
45 };
46 };
47
48 register_factory(EditorType::kAssembly,
49 [this]() { return std::make_unique<AssemblyEditor>(rom_); });
50 register_factory(EditorType::kDungeon, [this]() {
51 return std::make_unique<DungeonEditorV2>(rom_);
52 });
53 register_factory(EditorType::kGraphics,
54 [this]() { return std::make_unique<GraphicsEditor>(rom_); });
55 register_factory(EditorType::kMusic,
56 [this]() { return std::make_unique<MusicEditor>(rom_); });
57 register_factory(EditorType::kOverworld, [this]() {
58 return std::make_unique<OverworldEditor>(rom_);
59 });
60 register_factory(EditorType::kPalette,
61 [this]() { return std::make_unique<PaletteEditor>(rom_); });
62 register_factory(EditorType::kScreen,
63 [this]() { return std::make_unique<ScreenEditor>(rom_); });
64 register_factory(EditorType::kSprite,
65 [this]() { return std::make_unique<SpriteEditor>(rom_); });
66 register_factory(EditorType::kMessage,
67 [this]() { return std::make_unique<MessageEditor>(rom_); });
68 register_factory(EditorType::kHex,
69 [this]() { return std::make_unique<MemoryEditor>(rom_); });
70 register_factory(EditorType::kSettings,
71 []() { return std::make_unique<SettingsPanel>(); });
72}
73
74EditorSet::~EditorSet() = default;
75
77 user_settings_ = settings;
78 if (auto* panel = GetSettingsPanel()) {
79 panel->SetUserSettings(settings);
80 }
81}
82
84 game_data_ = game_data;
85 for (auto& [type, editor] : editors_) {
86 (void)type;
87 editor->SetGameData(game_data_);
88 }
89}
90
92 dependencies_ = dependencies;
93 for (auto& [type, editor] : editors_) {
94 editor->SetDependencies(dependencies);
95 }
96}
97
100 return;
101 }
103 for (auto& [type, editor] : editors_) {
104 (void)type;
105 editor->PrepareForSessionTeardown();
106 }
107}
108
110 return EnsureEditorCreated(type);
111}
112
114 if (type == EditorType::kUnknown) {
115 return nullptr;
116 }
117
118 if (auto it = editors_.find(type); it != editors_.end()) {
119 return it->second.get();
120 }
121 return nullptr;
122}
123
125 if (type == EditorType::kUnknown) {
126 return nullptr;
127 }
128
129 if (auto* editor = FindEditor(type)) {
130 return editor;
131 }
132
133 auto factory_it = editor_factories_.find(type);
134 if (factory_it == editor_factories_.end()) {
135 return nullptr;
136 }
137
138 auto editor = factory_it->second();
139 if (!editor) {
140 return nullptr;
141 }
142
143 if (dependencies_.has_value()) {
145 }
146 if (game_data_ != nullptr) {
147 editor->SetGameData(game_data_);
148 }
149 if (type == EditorType::kSettings && user_settings_ != nullptr) {
150 if (auto* settings_panel = static_cast<SettingsPanel*>(editor.get())) {
151 settings_panel->SetUserSettings(user_settings_);
152 }
153 }
154
155 Editor* editor_ptr = editor.get();
156 editors_[type] = std::move(editor);
157
158 if (ShouldTrackAsActiveEditor(type)) {
159 const_cast<EditorSet*>(this)->TrackActiveEditor(editor_ptr);
160 }
161
162 return editor_ptr;
163}
164
166 switch (type) {
176 return true;
177 default:
178 return false;
179 }
180}
181
183 if (editor == nullptr) {
184 return;
185 }
186 if (std::find(active_editors_.begin(), active_editors_.end(), editor) ==
187 active_editors_.end()) {
188 active_editors_.push_back(editor);
189 }
190}
191
192void EditorSet::OpenAssemblyFolder(const std::string& folder_path) const {
193 if (auto* editor = GetAssemblyEditor()) {
194 editor->OpenFolder(folder_path);
195 }
196}
197
198void EditorSet::ChangeActiveAssemblyFile(std::string_view path) const {
199 if (auto* editor = GetAssemblyEditor()) {
200 editor->ChangeActiveFile(path);
201 }
202}
203
205 if (auto* editor =
207 return editor->asar_wrapper();
208 }
209 return nullptr;
210}
211
212const std::map<std::string, core::AsarSymbol>& EditorSet::GetAssemblySymbols()
213 const {
214 static const std::map<std::string, core::AsarSymbol> kEmpty;
215 if (auto* editor =
217 return editor->symbols();
218 }
219 return kEmpty;
220}
221
223 if (auto* editor =
225 return editor->LoadedRoomCount();
226 }
227 return 0;
228}
229
231 if (auto* editor =
233 return editor->TotalRoomCount();
234 }
235 return 0;
236}
237
238std::vector<std::pair<uint32_t, uint32_t>>
240 if (auto* editor =
242 return editor->CollectWriteRanges();
243 }
244 return {};
245}
246
248 if (auto* editor =
250 return editor->HasPendingGraphicsChanges();
251 }
252 return false;
253}
254
256 if (auto* editor =
258 return editor->HasPendingScreenChanges();
259 }
260 return false;
261}
262
264 if (auto* editor =
266 editor->InvalidateRomBackedState();
267 }
268}
269
271 if (auto* editor =
273 return editor->HasPendingProjectDraftChanges();
274 }
275 return false;
276}
277
279 if (auto* editor =
281 return editor->PrepareProjectSave();
282 }
283 return absl::OkStatus();
284}
285
287 if (auto* editor =
289 return &editor->overworld();
290 }
291 return nullptr;
292}
293
294// Deprecated named accessors
296 return GetEditorAs<AssemblyEditor>(EditorType::kAssembly);
297}
299 return GetEditorAs<DungeonEditorV2>(EditorType::kDungeon);
300}
302 return GetEditorAs<GraphicsEditor>(EditorType::kGraphics);
303}
305 return GetEditorAs<MusicEditor>(EditorType::kMusic);
306}
308 return GetEditorAs<OverworldEditor>(EditorType::kOverworld);
309}
311 return GetEditorAs<PaletteEditor>(EditorType::kPalette);
312}
314 return GetEditorAs<ScreenEditor>(EditorType::kScreen);
315}
317 return GetEditorAs<SpriteEditor>(EditorType::kSprite);
318}
320 return GetEditorAs<SettingsPanel>(EditorType::kSettings);
321}
323 return GetEditorAs<MessageEditor>(EditorType::kMessage);
324}
326 return GetEditorAs<MemoryEditor>(EditorType::kHex);
327}
328
329RomSession::RomSession(UserSettings* user_settings, size_t session_id,
330 EditorRegistry* editor_registry)
331 : game_data(&rom),
332 editors(&rom, &game_data, user_settings, session_id, editor_registry) {}
333
334RomSession::RomSession(Rom&& r, UserSettings* user_settings, size_t session_id,
335 EditorRegistry* editor_registry)
336 : rom(std::move(r)),
337 game_data(&rom),
338 editors(&rom, &game_data, user_settings, session_id, editor_registry) {
341}
342
346
347std::string RomSession::GetDisplayName() const {
348 if (!custom_name.empty()) {
349 return custom_name;
350 }
351 return rom.title().empty() ? "Untitled Session" : rom.title();
352}
353
354} // 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:175
auto title() const
Definition rom.h:167
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.
std::unique_ptr< Editor > CreateEditor(EditorType type, Rom *rom) const
Contains a complete set of editors for a single ROM instance.
std::optional< EditorDependencies > dependencies_
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
void SetGameData(zelda3::GameData *game_data)
bool HasPendingProjectDraftChanges() const
bool ShouldTrackAsActiveEditor(EditorType type) const
core::AsarWrapper * GetAsarWrapper() const
absl::Status PrepareProjectSave()
void TrackActiveEditor(Editor *editor)
void ChangeActiveAssemblyFile(std::string_view path) 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_
EditorRegistry * editor_registry_
void set_user_settings(UserSettings *settings)
zelda3::Overworld * GetOverworldData() const
MessageEditor * GetMessageEditor() const
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
virtual void SetDependencies(const EditorDependencies &deps)
Definition editor.h:250
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.
static PaletteManager & Get()
Get the singleton instance.
void ReleaseSession(const zelda3::GameData *game_data)
Forget all palette tracking for a closing or reloaded ROM session.
Represents the full Overworld data, light and dark world.
Definition overworld.h:389
Editors are the view controllers for the application.
Unified dependency container for all editor types.
Definition editor.h:169
Per-ROM-session UI state shared by all GfxGroupEditor surfaces.
core::FeatureFlags::Flags feature_flags
zelda3::GameData game_data
std::string GetDisplayName() const