From d8826739bfc85be9b2d9f7fb0a00e3fb0c8a59a4 Mon Sep 17 00:00:00 2001 From: scawful Date: Fri, 11 Apr 2025 16:54:47 -0400 Subject: [PATCH] Refactor editor classes to accept a ROM pointer in constructors, enhancing dependency management and initialization across all editor types. --- src/app/editor/code/assembly_editor.h | 11 ++++++++++- src/app/editor/code/memory_editor.h | 14 ++++++++++++-- src/app/editor/dungeon/dungeon_editor.h | 14 ++++++++++++-- src/app/editor/editor_manager.h | 20 ++++++++++---------- src/app/editor/graphics/graphics_editor.h | 20 +++++++++++++++----- src/app/editor/graphics/palette_editor.h | 12 ++++++++++-- src/app/editor/graphics/screen_editor.h | 13 +++++++++---- src/app/editor/music/music_editor.h | 19 ++++++++++++++----- src/app/editor/sprite/sprite_editor.h | 14 ++++++++++++-- src/app/editor/system/settings_editor.h | 19 +++++++++++++++---- 10 files changed, 119 insertions(+), 37 deletions(-) diff --git a/src/app/editor/code/assembly_editor.h b/src/app/editor/code/assembly_editor.h index 7f888aba..faab158a 100644 --- a/src/app/editor/code/assembly_editor.h +++ b/src/app/editor/code/assembly_editor.h @@ -6,6 +6,7 @@ #include "app/editor/editor.h" #include "app/gui/modules/text_editor.h" #include "app/gui/style.h" +#include "app/rom.h" namespace yaze { namespace editor { @@ -22,7 +23,7 @@ struct FolderItem { */ class AssemblyEditor : public Editor { public: - AssemblyEditor() { + explicit AssemblyEditor(Rom* rom = nullptr) : rom_(rom) { text_editor_.SetLanguageDefinition(gui::GetAssemblyLanguageDef()); text_editor_.SetPalette(TextEditor::GetDarkPalette()); text_editor_.SetShowWhitespaces(false); @@ -54,6 +55,12 @@ class AssemblyEditor : public Editor { void OpenFolder(const std::string &folder_path); + // Set the ROM pointer + void set_rom(Rom* rom) { rom_ = rom; } + + // Get the ROM pointer + Rom* rom() const { return rom_; } + private: void DrawFileMenu(); void DrawEditMenu(); @@ -71,6 +78,8 @@ class AssemblyEditor : public Editor { std::string current_file_; FolderItem current_folder_; TextEditor text_editor_; + + Rom* rom_; }; } // namespace editor diff --git a/src/app/editor/code/memory_editor.h b/src/app/editor/code/memory_editor.h index ceeca751..94423ad3 100644 --- a/src/app/editor/code/memory_editor.h +++ b/src/app/editor/code/memory_editor.h @@ -2,7 +2,6 @@ #define YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H #include "app/core/platform/file_dialog.h" -#include "app/editor/code/memory_editor.h" #include "app/gui/input.h" #include "app/rom.h" #include "imgui/imgui.h" @@ -15,7 +14,9 @@ namespace editor { using ImGui::SameLine; using ImGui::Text; -struct MemoryEditorWithDiffChecker : public SharedRom { +struct MemoryEditorWithDiffChecker { + explicit MemoryEditorWithDiffChecker(Rom* rom = nullptr) : rom_(rom) {} + void Update(bool &show_memory_editor) { static MemoryEditor mem_edit; static MemoryEditor comp_edit; @@ -56,6 +57,15 @@ struct MemoryEditorWithDiffChecker : public SharedRom { ImGui::End(); } + + // Set the ROM pointer + void set_rom(Rom* rom) { rom_ = rom; } + + // Get the ROM pointer + Rom* rom() const { return rom_; } + + private: + Rom* rom_; }; } // namespace editor diff --git a/src/app/editor/dungeon/dungeon_editor.h b/src/app/editor/dungeon/dungeon_editor.h index d346b49d..d7c46f47 100644 --- a/src/app/editor/dungeon/dungeon_editor.h +++ b/src/app/editor/dungeon/dungeon_editor.h @@ -38,9 +38,11 @@ constexpr ImGuiTableFlags kDungeonTableFlags = * tile selector, and object renderer. Additionally, it handles loading room * entrances, calculating usage statistics, and rendering set usage. */ -class DungeonEditor : public Editor, public SharedRom { +class DungeonEditor : public Editor { public: - DungeonEditor() { type_ = EditorType::kDungeon; } + explicit DungeonEditor(Rom* rom = nullptr) : rom_(rom) { + type_ = EditorType::kDungeon; + } void Initialize() override; absl::Status Load() override; @@ -55,6 +57,12 @@ class DungeonEditor : public Editor, public SharedRom { void add_room(int i) { active_rooms_.push_back(i); } + // Set the ROM pointer + void set_rom(Rom* rom) { rom_ = rom; } + + // Get the ROM pointer + Rom* rom() const { return rom_; } + private: absl::Status RefreshGraphics(); @@ -138,6 +146,8 @@ class DungeonEditor : public Editor, public SharedRom { std::unordered_map room_palette_; absl::Status status_; + + Rom* rom_; }; } // namespace editor diff --git a/src/app/editor/editor_manager.h b/src/app/editor/editor_manager.h index d8b60de4..3ca3304b 100644 --- a/src/app/editor/editor_manager.h +++ b/src/app/editor/editor_manager.h @@ -112,17 +112,17 @@ class EditorManager { class EditorSet { public: explicit EditorSet(Rom* rom) - : assembly_editor_(), - dungeon_editor_(), - graphics_editor_(), - music_editor_(), + : assembly_editor_(rom), + dungeon_editor_(rom), + graphics_editor_(rom), + music_editor_(rom), overworld_editor_(*rom), - palette_editor_(), - screen_editor_(), - sprite_editor_(), - settings_editor_(), - message_editor_(), - memory_editor_() { + palette_editor_(rom), + screen_editor_(rom), + sprite_editor_(rom), + settings_editor_(rom), + message_editor_(rom), + memory_editor_(rom) { active_editors_ = {&overworld_editor_, &dungeon_editor_, &graphics_editor_, &palette_editor_, &sprite_editor_, &message_editor_, &music_editor_, &screen_editor_, &settings_editor_, diff --git a/src/app/editor/graphics/graphics_editor.h b/src/app/editor/graphics/graphics_editor.h index de333f1c..f0564e91 100644 --- a/src/app/editor/graphics/graphics_editor.h +++ b/src/app/editor/graphics/graphics_editor.h @@ -54,20 +54,28 @@ const std::string kSuperDonkeySprites[] = { * drawing toolsets, palette controls, clipboard imports, experimental features, * and memory editor. */ -class GraphicsEditor : public SharedRom, public Editor { +class GraphicsEditor : public Editor { public: - GraphicsEditor() { type_ = EditorType::kGraphics; } + explicit GraphicsEditor(Rom* rom = nullptr) : rom_(rom) { + type_ = EditorType::kGraphics; + } void Initialize() override; absl::Status Load() override; + absl::Status Save() override { return absl::UnimplementedError("Save"); } absl::Status Update() override; - absl::Status Undo() override { return absl::UnimplementedError("Undo"); } - absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Cut() override { return absl::UnimplementedError("Cut"); } absl::Status Copy() override { return absl::UnimplementedError("Copy"); } absl::Status Paste() override { return absl::UnimplementedError("Paste"); } + absl::Status Undo() override { return absl::UnimplementedError("Undo"); } + absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Find() override { return absl::UnimplementedError("Find"); } - absl::Status Save() override { return absl::UnimplementedError("Save"); } + + // Set the ROM pointer + void set_rom(Rom* rom) { rom_ = rom; } + + // Get the ROM pointer + Rom* rom() const { return rom_; } private: enum class GfxEditMode { @@ -195,6 +203,8 @@ class GraphicsEditor : public SharedRom, public Editor { ImVec2(gfx::kTilesheetWidth * 4, gfx::kTilesheetHeight * 0x10 * 4), gui::CanvasGridSize::k16x16}; absl::Status status_; + + Rom* rom_; }; } // namespace editor diff --git a/src/app/editor/graphics/palette_editor.h b/src/app/editor/graphics/palette_editor.h index a518c6eb..1d65a0b2 100644 --- a/src/app/editor/graphics/palette_editor.h +++ b/src/app/editor/graphics/palette_editor.h @@ -77,9 +77,9 @@ absl::Status DisplayPalette(gfx::SnesPalette& palette, bool loaded); * @class PaletteEditor * @brief Allows the user to view and edit in game palettes. */ -class PaletteEditor : public SharedRom, public Editor { +class PaletteEditor : public Editor { public: - PaletteEditor() { + explicit PaletteEditor(Rom* rom = nullptr) : rom_(rom) { type_ = EditorType::kPalette; custom_palette_.push_back(gfx::SnesColor(0x7FFF)); } @@ -106,6 +106,12 @@ class PaletteEditor : public SharedRom, public Editor { void DrawModifiedColors(); + // Set the ROM pointer + void set_rom(Rom* rom) { rom_ = rom; } + + // Get the ROM pointer + Rom* rom() const { return rom_; } + private: absl::Status HandleColorPopup(gfx::SnesPalette& palette, int i, int j, int n); @@ -119,6 +125,8 @@ class PaletteEditor : public SharedRom, public Editor { ImVec4 saved_palette_[256] = {}; palette_internal::PaletteEditorHistory history_; + + Rom* rom_; }; } // namespace editor diff --git a/src/app/editor/graphics/screen_editor.h b/src/app/editor/graphics/screen_editor.h index f6747b37..6daf802f 100644 --- a/src/app/editor/graphics/screen_editor.h +++ b/src/app/editor/graphics/screen_editor.h @@ -28,12 +28,10 @@ namespace editor { * * The screens that can be edited include the title screen, naming screen, * overworld map, inventory menu, and more. - * - * The class inherits from the SharedRom class. */ -class ScreenEditor : public SharedRom, public Editor { +class ScreenEditor : public Editor { public: - ScreenEditor() { + explicit ScreenEditor(Rom* rom = nullptr) : rom_(rom) { screen_canvas_.SetCanvasSize(ImVec2(512, 512)); type_ = EditorType::kScreen; } @@ -48,10 +46,17 @@ class ScreenEditor : public SharedRom, public Editor { absl::Status Paste() override { return absl::UnimplementedError("Paste"); } absl::Status Find() override { return absl::UnimplementedError("Find"); } absl::Status Save() override { return absl::UnimplementedError("Save"); } + + // Set the ROM pointer + void set_rom(Rom* rom) { rom_ = rom; } + + // Get the ROM pointer + Rom* rom() const { return rom_; } absl::Status SaveDungeonMaps(); private: + Rom* rom_; void DrawTitleScreenEditor(); void DrawNamingScreenEditor(); void DrawOverworldMapEditor(); diff --git a/src/app/editor/music/music_editor.h b/src/app/editor/music/music_editor.h index ebe87023..f04d5eaa 100644 --- a/src/app/editor/music/music_editor.h +++ b/src/app/editor/music/music_editor.h @@ -54,22 +54,31 @@ const ImGuiTableFlags music_editor_flags_ = ImGuiTableFlags_SizingFixedFit | * @class MusicEditor * @brief A class for editing music data in a Rom. */ -class MusicEditor : public SharedRom, public Editor { +class MusicEditor : public Editor { public: - MusicEditor() { type_ = EditorType::kMusic; } + explicit MusicEditor(Rom* rom = nullptr) : rom_(rom) { + type_ = EditorType::kMusic; + } void Initialize() override; absl::Status Load() override; + absl::Status Save() override { return absl::UnimplementedError("Save"); } absl::Status Update() override; - absl::Status Undo() override { return absl::UnimplementedError("Undo"); } - absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Cut() override { return absl::UnimplementedError("Cut"); } absl::Status Copy() override { return absl::UnimplementedError("Copy"); } absl::Status Paste() override { return absl::UnimplementedError("Paste"); } + absl::Status Undo() override { return absl::UnimplementedError("Undo"); } + absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Find() override { return absl::UnimplementedError("Find"); } - absl::Status Save() override { return absl::UnimplementedError("Save"); } + + // Set the ROM pointer + void set_rom(Rom* rom) { rom_ = rom; } + + // Get the ROM pointer + Rom* rom() const { return rom_; } private: + Rom* rom_; void DrawChannels(); void DrawPianoStaff(); void DrawPianoRoll(); diff --git a/src/app/editor/sprite/sprite_editor.h b/src/app/editor/sprite/sprite_editor.h index 4facb580..58e72182 100644 --- a/src/app/editor/sprite/sprite_editor.h +++ b/src/app/editor/sprite/sprite_editor.h @@ -33,9 +33,11 @@ constexpr ImGuiTableFlags kSpriteTableFlags = * This class provides functionality for updating the sprite editor, drawing the * editor table, drawing the sprite canvas, and drawing the current sheets. */ -class SpriteEditor : public SharedRom, public Editor { +class SpriteEditor : public Editor { public: - SpriteEditor() { type_ = EditorType::kSprite; } + explicit SpriteEditor(Rom* rom = nullptr) : rom_(rom) { + type_ = EditorType::kSprite; + } void Initialize() override; absl::Status Load() override; @@ -47,6 +49,12 @@ class SpriteEditor : public SharedRom, public Editor { absl::Status Paste() override { return absl::UnimplementedError("Paste"); } absl::Status Find() override { return absl::UnimplementedError("Find"); } absl::Status Save() override { return absl::UnimplementedError("Save"); } + + // Set the ROM pointer + void set_rom(Rom* rom) { rom_ = rom; } + + // Get the ROM pointer + Rom* rom() const { return rom_; } private: void DrawVanillaSpriteEditor(); @@ -105,6 +113,8 @@ class SpriteEditor : public SharedRom, public Editor { std::vector custom_sprites_; /**< Sprites. */ absl::Status status_; /**< Status. */ + + Rom* rom_; }; } // namespace editor diff --git a/src/app/editor/system/settings_editor.h b/src/app/editor/system/settings_editor.h index df4ec965..5f4a5f59 100644 --- a/src/app/editor/system/settings_editor.h +++ b/src/app/editor/system/settings_editor.h @@ -3,6 +3,7 @@ #include "absl/status/status.h" #include "app/editor/editor.h" +#include "app/rom.h" #include "imgui/imgui.h" namespace yaze { @@ -206,19 +207,29 @@ static void ShowExampleAppPropertyEditor(bool* p_open) { class SettingsEditor : public Editor { public: - SettingsEditor() : Editor() { type_ = EditorType::kSettings; } + explicit SettingsEditor(Rom* rom = nullptr) : rom_(rom) { + type_ = EditorType::kSettings; + } + void Initialize() override; absl::Status Load() override; + absl::Status Save() override { return absl::UnimplementedError("Save"); } absl::Status Update() override; - absl::Status Undo() override { return absl::UnimplementedError("Undo"); } - absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Cut() override { return absl::UnimplementedError("Cut"); } absl::Status Copy() override { return absl::UnimplementedError("Copy"); } absl::Status Paste() override { return absl::UnimplementedError("Paste"); } + absl::Status Undo() override { return absl::UnimplementedError("Undo"); } + absl::Status Redo() override { return absl::UnimplementedError("Redo"); } absl::Status Find() override { return absl::UnimplementedError("Find"); } - absl::Status Save() override { return absl::UnimplementedError("Save"); } + + // Set the ROM pointer + void set_rom(Rom* rom) { rom_ = rom; } + + // Get the ROM pointer + Rom* rom() const { return rom_; } private: + Rom* rom_; void DrawGeneralSettings(); void DrawKeyboardShortcuts(); };