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
99 return EnsureEditorCreated(type);
100}
101
103 if (type == EditorType::kUnknown) {
104 return nullptr;
105 }
106
107 if (auto it = editors_.find(type); it != editors_.end()) {
108 return it->second.get();
109 }
110 return nullptr;
111}
112
114 if (type == EditorType::kUnknown) {
115 return nullptr;
116 }
117
118 if (auto* editor = FindEditor(type)) {
119 return editor;
120 }
121
122 auto factory_it = editor_factories_.find(type);
123 if (factory_it == editor_factories_.end()) {
124 return nullptr;
125 }
126
127 auto editor = factory_it->second();
128 if (!editor) {
129 return nullptr;
130 }
131
132 if (dependencies_.has_value()) {
134 }
135 if (game_data_ != nullptr) {
136 editor->SetGameData(game_data_);
137 }
138 if (type == EditorType::kSettings && user_settings_ != nullptr) {
139 if (auto* settings_panel = static_cast<SettingsPanel*>(editor.get())) {
140 settings_panel->SetUserSettings(user_settings_);
141 }
142 }
143
144 Editor* editor_ptr = editor.get();
145 editors_[type] = std::move(editor);
146
147 if (ShouldTrackAsActiveEditor(type)) {
148 const_cast<EditorSet*>(this)->TrackActiveEditor(editor_ptr);
149 }
150
151 return editor_ptr;
152}
153
155 switch (type) {
165 return true;
166 default:
167 return false;
168 }
169}
170
172 if (editor == nullptr) {
173 return;
174 }
175 if (std::find(active_editors_.begin(), active_editors_.end(), editor) ==
176 active_editors_.end()) {
177 active_editors_.push_back(editor);
178 }
179}
180
181void EditorSet::OpenAssemblyFolder(const std::string& folder_path) const {
182 if (auto* editor = GetAssemblyEditor()) {
183 editor->OpenFolder(folder_path);
184 }
185}
186
187void EditorSet::ChangeActiveAssemblyFile(std::string_view path) const {
188 if (auto* editor = GetAssemblyEditor()) {
189 editor->ChangeActiveFile(path);
190 }
191}
192
194 if (auto* editor =
196 return editor->asar_wrapper();
197 }
198 return nullptr;
199}
200
201const std::map<std::string, core::AsarSymbol>& EditorSet::GetAssemblySymbols()
202 const {
203 static const std::map<std::string, core::AsarSymbol> kEmpty;
204 if (auto* editor =
206 return editor->symbols();
207 }
208 return kEmpty;
209}
210
212 if (auto* editor =
214 return editor->LoadedRoomCount();
215 }
216 return 0;
217}
218
220 if (auto* editor =
222 return editor->TotalRoomCount();
223 }
224 return 0;
225}
226
227std::vector<std::pair<uint32_t, uint32_t>>
229 if (auto* editor =
231 return editor->CollectWriteRanges();
232 }
233 return {};
234}
235
237 if (auto* editor =
239 return &editor->overworld();
240 }
241 return nullptr;
242}
243
244// Deprecated named accessors
246 return GetEditorAs<AssemblyEditor>(EditorType::kAssembly);
247}
249 return GetEditorAs<DungeonEditorV2>(EditorType::kDungeon);
250}
252 return GetEditorAs<GraphicsEditor>(EditorType::kGraphics);
253}
255 return GetEditorAs<MusicEditor>(EditorType::kMusic);
256}
258 return GetEditorAs<OverworldEditor>(EditorType::kOverworld);
259}
261 return GetEditorAs<PaletteEditor>(EditorType::kPalette);
262}
264 return GetEditorAs<ScreenEditor>(EditorType::kScreen);
265}
267 return GetEditorAs<SpriteEditor>(EditorType::kSprite);
268}
270 return GetEditorAs<SettingsPanel>(EditorType::kSettings);
271}
273 return GetEditorAs<MessageEditor>(EditorType::kMessage);
274}
276 return GetEditorAs<MemoryEditor>(EditorType::kHex);
277}
278
279RomSession::RomSession(UserSettings* user_settings, size_t session_id,
280 EditorRegistry* editor_registry)
281 : game_data(&rom),
282 editors(&rom, &game_data, user_settings, session_id, editor_registry) {}
283
284RomSession::RomSession(Rom&& r, UserSettings* user_settings, size_t session_id,
285 EditorRegistry* editor_registry)
286 : rom(std::move(r)),
287 game_data(&rom),
288 editors(&rom, &game_data, user_settings, session_id, editor_registry) {
291}
292
296
297std::string RomSession::GetDisplayName() const {
298 if (!custom_name.empty()) {
299 return custom_name;
300 }
301 return rom.title().empty() ? "Untitled Session" : rom.title();
302}
303
304} // 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:157
auto title() const
Definition rom.h:149
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: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