34 : session_id_(session_id),
36 game_data_(game_data),
37 user_settings_(user_settings),
38 editor_registry_(editor_registry),
40 auto register_factory = [&](
EditorType type,
auto&& fallback) {
43 fallback = std::forward<decltype(fallback)>(
44 fallback)]()
mutable -> std::unique_ptr<Editor> {
55 [
this]() {
return std::make_unique<AssemblyEditor>(
rom_); });
57 return std::make_unique<DungeonEditorV2>(
rom_);
60 [
this]() {
return std::make_unique<GraphicsEditor>(
rom_); });
62 [
this]() {
return std::make_unique<MusicEditor>(
rom_); });
64 return std::make_unique<OverworldEditor>(
rom_);
67 [
this]() {
return std::make_unique<PaletteEditor>(
rom_); });
69 [
this]() {
return std::make_unique<ScreenEditor>(
rom_); });
71 [
this]() {
return std::make_unique<SpriteEditor>(
rom_); });
73 [
this]() {
return std::make_unique<MessageEditor>(
rom_); });
75 [
this]() {
return std::make_unique<MemoryEditor>(
rom_); });
77 []() {
return std::make_unique<SettingsPanel>(); });
79 []() {
return std::make_unique<PlanningEditor>(); });
87 panel->SetUserSettings(settings);
93 for (
auto& [type, editor] :
editors_) {
101 for (
auto& [type, editor] :
editors_) {
102 editor->SetDependencies(dependencies);
111 for (
auto& [type, editor] :
editors_) {
113 editor->PrepareForSessionTeardown();
127 return it->second.get();
146 auto editor = factory_it->second();
158 dungeon->SetRoomGraphicsOverworldProvider(
163 int slot) -> absl::StatusOr<zelda3::MainGroupUsageReport> {
165 return absl::FailedPreconditionError(
"No loaded graphics session");
168 std::map<int, uint8_t> explicit_main;
171 dungeon->rooms().ForEachLoaded([&](
int id,
const zelda3::Room& room) {
177 rooms, explicit_main,
181 [
this](
int group) -> absl::StatusOr<zelda3::RoomsetUsageReport> {
183 return absl::FailedPreconditionError(
"No loaded graphics session");
186 return dungeon->GetRoomGraphicsUsage(group);
191 if (
auto* graphics =
dynamic_cast<GraphicsEditor*
>(editor.get())) {
192 graphics->SetRoomUsageProvider([
this]() {
198 dungeon->VisitGraphicsUsageRooms([&](
int id,
zelda3::Room& room,
199 const std::string& provenance,
200 bool current,
int entrance_slot) {
202 &room, provenance, current, entrance_slot});
211 return overworld && overworld->is_loaded() && overworld->rom() ==
rom_
215 graphics->SetMainGraphicsUsageCallback(main_usage);
216 graphics->SetRoomsetGraphicsUsageCallback(roomset_usage);
219 overworld->SetMainGraphicsUsageCallback(main_usage);
220 overworld->SetRoomsetGraphicsUsageCallback(roomset_usage);
223 if (
auto* settings_panel =
static_cast<SettingsPanel*
>(editor.get())) {
228 Editor* editor_ptr = editor.get();
257 if (editor ==
nullptr) {
268 editor->OpenFolder(folder_path);
274 editor->ChangeActiveFile(path);
281 return editor->asar_wrapper();
288 static const std::map<std::string, core::AsarSymbol> kEmpty;
291 return editor->symbols();
299 return editor->LoadedRoomCount();
307 return editor->TotalRoomCount();
312std::vector<std::pair<uint32_t, uint32_t>>
316 return editor->CollectWriteRanges();
326 return diff.ok() && diff->any();
332 return editor->HasPendingGraphicsChanges();
340 return editor->HasPendingSpriteChanges();
347 return editor->HasPendingScreenChanges();
355 editor->InvalidateRomBackedState();
369 if (editor->HasPendingProjectDraftChanges())
374 return editor->HasPendingProjectDraftChanges();
388 return editor ? editor->
Save() : absl::OkStatus();
409 return absl::OkStatus();
415 editor->ProjectSaveCommitted();
418 editor->ProjectSaveCommitted();
425 editor->DiscardProjectDraftChanges();
432 return &editor->overworld();
475 editors(&rom, &game_data, user_settings, session_id, editor_registry) {}
481 editors(&rom, &game_data, user_settings, session_id, editor_registry) {
488 std::string bytes(
reinterpret_cast<const char*
>(rom.
copier_header().data()),
490 bytes.append(
reinterpret_cast<const char*
>(rom.
data()), rom.
size());
499 auto path = std::filesystem::path(
rom.
filename()).lexically_normal();
500 path.make_preferred();
501 const std::string editing_source = preserve_editing_source &&
rom_baseline
512 std::make_unique<std::array<gfx::Bitmap, zelda3::kNumGfxSheets>>(
520 bitmap.set_data(std::vector<uint8_t>(pixels.begin(), pixels.end()));
531 if (arena.gfx_sheets_owner() == &
game_data) {
532 arena.BindGraphicsSheets(
nullptr,
nullptr);
536 arena.RetireBitmap(bitmap);
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
const std::vector< uint8_t > & copier_header() const
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.
bool session_teardown_prepared_
std::optional< EditorDependencies > dependencies_
MemoryEditor * GetMemoryEditor() const
void InvalidateScreenRomBackedState()
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
void DiscardPlanningProjectDraft()
bool HasPendingPlanningProjectDraftChanges() const
bool ShouldTrackAsActiveEditor(EditorType type) const
core::AsarWrapper * GetAsarWrapper() const
bool HasPendingBuildProjectDraftChanges() const
void TrackActiveEditor(Editor *editor)
void ProjectSaveCommitted()
absl::Status PrepareProjectSave(bool publish_lyra=true)
void ChangeActiveAssemblyFile(std::string_view path) const
void ApplyDependencies(const EditorDependencies &dependencies)
const std::map< std::string, core::AsarSymbol > & GetAssemblySymbols() const
void PrepareForSessionTeardown()
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
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.
virtual void SetDependencies(const EditorDependencies &deps)
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.
absl::Status Save() override
bool HasPendingProjectDraftChanges() const
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.
void BindGraphicsSheets(GraphicsSheets *sheets, const void *owner)
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.
bool HasSheet(uint16_t sheet) const
True when the buffer holds all 4096 bytes of sheet.
absl::Span< const uint8_t > Sheet(uint16_t sheet) const
The sheet's 4096 pixels, or an empty span when it is not held.
uint8_t spriteset() const
uint8_t render_entrance_blockset() const
std::string ComputeSourceArtifactSha256(std::string_view content)
std::map< int, LiveRoomContext > LiveRoomContexts
Editors are the view controllers for the application.
std::string ComputeRomFileBytesSha256(const Rom &rom)
RomIdentityHashes ComputeRomIdentityHashes(const uint8_t *data, size_t size)
absl::StatusOr< RoomsetUsageReport > DescribeRoomsetUsage(Rom &rom, GameData &game_data, int roomset, const std::map< int, RoomGfxInfo > &rooms, const Overworld *live_overworld)
absl::StatusOr< MainGroupUsageReport > DescribeMainGroupUsage(Rom &rom, GameData &game_data, int group, int slot, const std::map< int, RoomGfxInfo > &rooms, const std::map< int, uint8_t > &explicit_room_main, const Overworld *live_overworld)
absl::StatusOr< GfxGroupDiff > DiffGfxGroups(const Rom &rom, const GameData &data)
std::map< int, RoomGfxInfo > CollectRoomGfx(const Rom &rom)
#define RETURN_IF_ERROR(expr)
Unified dependency container for all editor types.
Per-ROM-session UI state shared by all GfxGroupEditor surfaces.
std::unique_ptr< std::array< gfx::Bitmap, zelda3::kNumGfxSheets > > graphics_display_
core::FeatureFlags::Flags feature_flags
void ActivateGraphicsDisplay()
void CaptureRomIdentity(bool preserve_editing_source=false)
bool HasPendingGfxGroupChanges() const
std::optional< RomBaselineIdentity > rom_baseline
void ResetGraphicsDisplay()
zelda3::GameData game_data
void ReloadGraphicsDisplay()
std::string GetDisplayName() const
std::array< gfx::Bitmap, kNumGfxSheets > gfx_bitmaps
GraphicsSheetStore sheet_store