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"
20
21namespace yaze::editor {
22
24 UserSettings* user_settings, size_t session_id,
25 EditorRegistry* editor_registry)
26 : session_id_(session_id),
27 rom_(rom),
28 game_data_(game_data),
29 user_settings_(user_settings),
30 editor_registry_(editor_registry),
31 gfx_group_workspace_(std::make_unique<GfxGroupWorkspaceState>()) {
32 auto register_factory = [&](EditorType type, auto&& fallback) {
33 editor_factories_[type] =
34 [this, type,
35 fallback = std::forward<decltype(fallback)>(
36 fallback)]() mutable -> std::unique_ptr<Editor> {
37 if (editor_registry_) {
38 if (auto created = editor_registry_->CreateEditor(type, rom_)) {
39 return created;
40 }
41 }
42 return fallback();
43 };
44 };
45
46 register_factory(EditorType::kAssembly,
47 [this]() { return std::make_unique<AssemblyEditor>(rom_); });
48 register_factory(EditorType::kDungeon, [this]() {
49 return std::make_unique<DungeonEditorV2>(rom_);
50 });
51 register_factory(EditorType::kGraphics,
52 [this]() { return std::make_unique<GraphicsEditor>(rom_); });
53 register_factory(EditorType::kMusic,
54 [this]() { return std::make_unique<MusicEditor>(rom_); });
55 register_factory(EditorType::kOverworld, [this]() {
56 return std::make_unique<OverworldEditor>(rom_);
57 });
58 register_factory(EditorType::kPalette,
59 [this]() { return std::make_unique<PaletteEditor>(rom_); });
60 register_factory(EditorType::kScreen,
61 [this]() { return std::make_unique<ScreenEditor>(rom_); });
62 register_factory(EditorType::kSprite,
63 [this]() { return std::make_unique<SpriteEditor>(rom_); });
64 register_factory(EditorType::kMessage,
65 [this]() { return std::make_unique<MessageEditor>(rom_); });
66 register_factory(EditorType::kHex,
67 [this]() { return std::make_unique<MemoryEditor>(rom_); });
68 register_factory(EditorType::kSettings,
69 []() { return std::make_unique<SettingsPanel>(); });
70}
71
72EditorSet::~EditorSet() = default;
73
75 user_settings_ = settings;
76 if (auto* panel = GetSettingsPanel()) {
77 panel->SetUserSettings(settings);
78 }
79}
80
82 game_data_ = game_data;
83 for (auto& [type, editor] : editors_) {
84 (void)type;
85 editor->SetGameData(game_data_);
86 }
87}
88
90 dependencies_ = dependencies;
91 for (auto& [type, editor] : editors_) {
92 editor->SetDependencies(dependencies);
93 }
94}
95
97 return EnsureEditorCreated(type);
98}
99
101 if (type == EditorType::kUnknown) {
102 return nullptr;
103 }
104
105 if (auto it = editors_.find(type); it != editors_.end()) {
106 return it->second.get();
107 }
108 return nullptr;
109}
110
112 if (type == EditorType::kUnknown) {
113 return nullptr;
114 }
115
116 if (auto* editor = FindEditor(type)) {
117 return editor;
118 }
119
120 auto factory_it = editor_factories_.find(type);
121 if (factory_it == editor_factories_.end()) {
122 return nullptr;
123 }
124
125 auto editor = factory_it->second();
126 if (!editor) {
127 return nullptr;
128 }
129
130 if (dependencies_.has_value()) {
132 }
133 if (game_data_ != nullptr) {
134 editor->SetGameData(game_data_);
135 }
136 if (type == EditorType::kSettings && user_settings_ != nullptr) {
137 if (auto* settings_panel = static_cast<SettingsPanel*>(editor.get())) {
138 settings_panel->SetUserSettings(user_settings_);
139 }
140 }
141
142 Editor* editor_ptr = editor.get();
143 editors_[type] = std::move(editor);
144
145 if (ShouldTrackAsActiveEditor(type)) {
146 const_cast<EditorSet*>(this)->TrackActiveEditor(editor_ptr);
147 }
148
149 return editor_ptr;
150}
151
153 switch (type) {
163 return true;
164 default:
165 return false;
166 }
167}
168
170 if (editor == nullptr) {
171 return;
172 }
173 if (std::find(active_editors_.begin(), active_editors_.end(), editor) ==
174 active_editors_.end()) {
175 active_editors_.push_back(editor);
176 }
177}
178
179void EditorSet::OpenAssemblyFolder(const std::string& folder_path) const {
180 if (auto* editor = GetAssemblyEditor()) {
181 editor->OpenFolder(folder_path);
182 }
183}
184
185void EditorSet::ChangeActiveAssemblyFile(std::string_view path) const {
186 if (auto* editor = GetAssemblyEditor()) {
187 editor->ChangeActiveFile(path);
188 }
189}
190
192 if (auto* editor =
194 return editor->asar_wrapper();
195 }
196 return nullptr;
197}
198
199const std::map<std::string, core::AsarSymbol>&
201 static const std::map<std::string, core::AsarSymbol> kEmpty;
202 if (auto* editor =
204 return editor->symbols();
205 }
206 return kEmpty;
207}
208
210 if (auto* editor =
212 return editor->LoadedRoomCount();
213 }
214 return 0;
215}
216
218 if (auto* editor =
220 return editor->TotalRoomCount();
221 }
222 return 0;
223}
224
225std::vector<std::pair<uint32_t, uint32_t>>
227 if (auto* editor =
229 return editor->CollectWriteRanges();
230 }
231 return {};
232}
233
235 if (auto* editor =
237 return &editor->overworld();
238 }
239 return nullptr;
240}
241
242// Deprecated named accessors
244 return GetEditorAs<AssemblyEditor>(EditorType::kAssembly);
245}
247 return GetEditorAs<DungeonEditorV2>(EditorType::kDungeon);
248}
250 return GetEditorAs<GraphicsEditor>(EditorType::kGraphics);
251}
253 return GetEditorAs<MusicEditor>(EditorType::kMusic);
254}
256 return GetEditorAs<OverworldEditor>(EditorType::kOverworld);
257}
259 return GetEditorAs<PaletteEditor>(EditorType::kPalette);
260}
262 return GetEditorAs<ScreenEditor>(EditorType::kScreen);
263}
265 return GetEditorAs<SpriteEditor>(EditorType::kSprite);
266}
268 return GetEditorAs<SettingsPanel>(EditorType::kSettings);
269}
271 return GetEditorAs<MessageEditor>(EditorType::kMessage);
272}
274 return GetEditorAs<MemoryEditor>(EditorType::kHex);
275}
276
277RomSession::RomSession(Rom&& r, UserSettings* user_settings, size_t session_id,
278 EditorRegistry* editor_registry)
279 : rom(std::move(r)),
280 game_data(&rom),
281 editors(&rom, &game_data, user_settings, session_id, editor_registry) {
284}
285
286std::string RomSession::GetDisplayName() const {
287 if (!custom_name.empty()) {
288 return custom_name;
289 }
290 return rom.title().empty() ? "Untitled Session" : rom.title();
291}
292
293} // 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.
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 ShouldTrackAsActiveEditor(EditorType type) const
core::AsarWrapper * GetAsarWrapper() const
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
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:240
virtual void SetDependencies(const EditorDependencies &deps)
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:261
Editors are the view controllers for the application.
Unified dependency container for all editor types.
Definition editor.h:164
Per-ROM-session UI state shared by all GfxGroupEditor surfaces.
core::FeatureFlags::Flags feature_flags
std::string GetDisplayName() const