yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_editor_v2.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_EDITOR_V2_H
2#define YAZE_APP_EDITOR_DUNGEON_EDITOR_V2_H
3
4#include <map>
5#include <memory>
6#include <unordered_map>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "absl/strings/str_format.h"
11#include "app/editor/editor.h"
19#include "dungeon_room_loader.h"
21#include "imgui/imgui.h"
24#include "rom/rom.h"
26#include "zelda3/dungeon/room.h"
28#include "zelda3/game_data.h"
29
30namespace yaze {
31namespace editor {
32
33class MinecartTrackEditorPanel;
34
74class DungeonEditorV2 : public Editor {
75 public:
76 explicit DungeonEditorV2(Rom* rom = nullptr)
79 if (rom) {
81 for (auto& room : rooms_) {
82 room.SetRom(rom);
83 }
84 }
85 }
86
87 ~DungeonEditorV2() override;
88
91 dependencies_.game_data = game_data; // Also set base class dependency
95 }
98 }
99 for (auto& room : rooms_) {
100 room.SetGameData(game_data);
101 }
102 // Note: Canvas viewer game data is set lazily in GetViewerForRoom
103 // but we should update existing viewers
104 for (auto& [id, viewer] : room_viewers_) {
105 if (viewer) viewer->SetGameData(game_data);
106 }
107 }
108
109 // Editor interface
110 void Initialize(gfx::IRenderer* renderer, Rom* rom);
111 void Initialize() override;
112 absl::Status Load();
113 absl::Status Update() override;
114 absl::Status Undo() override;
115 absl::Status Redo() override;
116 absl::Status Cut() override;
117 absl::Status Copy() override;
118 absl::Status Paste() override;
119 absl::Status Find() override { return absl::UnimplementedError("Find"); }
120 absl::Status Save() override;
121
122 // ROM management
123 void SetRom(Rom* rom) {
124 rom_ = rom;
127
128 // Propagate ROM to all rooms
129 if (rom) {
130 for (auto& room : rooms_) {
131 room.SetRom(rom);
132 }
133 }
134
135 // Reset viewers on ROM change
136 room_viewers_.clear();
137
138 // Create render service if needed
139 if (rom && rom->is_loaded() && !render_service_) {
141 std::make_unique<emu::render::EmulatorRenderService>(rom);
142 render_service_->Initialize();
143 }
144 }
145 Rom* rom() const { return rom_; }
146
147 // Room management
148 void add_room(int room_id);
149 void FocusRoom(int room_id);
150
151 // Agent/Automation controls
152 void SelectObject(int obj_id);
153 void SetAgentMode(bool enabled);
154
155 // ROM state
156 bool IsRomLoaded() const override { return rom_ && rom_->is_loaded(); }
157 std::string GetRomStatus() const override {
158 if (!rom_) return "No ROM loaded";
159 if (!rom_->is_loaded()) return "ROM failed to load";
160 return absl::StrFormat("ROM loaded: %s", rom_->title());
161 }
162
163 // Show a panel by its card_id using PanelManager
164 void ShowPanel(const std::string& card_id) {
167 }
168 }
169
170 // Panel card IDs for programmatic access
171 static constexpr const char* kControlPanelId = "dungeon.control_panel";
172 static constexpr const char* kRoomSelectorId = "dungeon.room_selector";
173 static constexpr const char* kEntranceListId = "dungeon.entrance_list";
174 static constexpr const char* kRoomMatrixId = "dungeon.room_matrix";
175 static constexpr const char* kRoomGraphicsId = "dungeon.room_graphics";
176 static constexpr const char* kObjectToolsId = "dungeon.object_tools";
177 static constexpr const char* kPaletteEditorId = "dungeon.palette_editor";
178
179 // Public accessors for WASM API and automation
181 const ImVector<int>& active_rooms() const {
183 }
187
188 private:
190
191 // Draw the Room Panels
192 void DrawRoomPanels();
193 void DrawRoomTab(int room_id);
194
195 // Texture processing (critical for rendering)
197
198 // Room selection callback
199 void OnRoomSelected(int room_id, bool request_focus = true);
200 void OnEntranceSelected(int entrance_id);
201
202 // Swap room in current panel (for arrow navigation)
203 void SwapRoomInPanel(int old_room_id, int new_room_id);
204
205 // Object placement callback
206 void HandleObjectPlaced(const zelda3::RoomObject& obj);
207
208 // Helper to get or create a viewer for a specific room
210
211 // Data
214 std::array<zelda3::Room, 0x128> rooms_;
215 std::array<zelda3::RoomEntrance, 0x8C> entrances_;
216
217 // Current selection state
219
220 // Active room tabs and card tracking for jump-to
221 ImVector<int> active_rooms_;
223
225
226 // Palette management
231
232 // Components - these do all the work
235 // canvas_viewer_ removed in favor of room_viewers_
236 std::map<int, std::unique_ptr<DungeonCanvasViewer>> room_viewers_;
237
239 // Panel pointers - these are owned by PanelManager when available.
240 // Store pointers for direct access to panel methods.
246
247 // Fallback ownership for tests when PanelManager is not available.
248 // In production, this remains nullptr and panels are owned by PanelManager.
249 std::unique_ptr<ObjectEditorPanel> owned_object_editor_panel_;
250 std::unique_ptr<zelda3::DungeonEditorSystem> dungeon_editor_system_;
251 std::unique_ptr<emu::render::EmulatorRenderService> render_service_;
252
253 bool is_loaded_ = false;
254
255 // Docking class for room windows to dock together
256 ImGuiWindowClass room_window_class_;
257
258 // Shared dock ID for all room panels to auto-dock together
259 ImGuiID room_dock_id_ = 0;
260
261 // Dynamic room cards - created per open room
262 std::unordered_map<int, std::shared_ptr<gui::PanelWindow>> room_cards_;
263
264 // Undo/Redo history: store snapshots of room objects
265 std::unordered_map<int, std::vector<std::vector<zelda3::RoomObject>>>
267 std::unordered_map<int, std::vector<std::vector<zelda3::RoomObject>>>
269
270 // Pending room swap (deferred until after draw phase completes)
271 struct PendingSwap {
272 int old_room_id = -1;
273 int new_room_id = -1;
274 bool pending = false;
275 };
277
278 void PushUndoSnapshot(int room_id);
279 absl::Status RestoreFromSnapshot(int room_id,
280 std::vector<zelda3::RoomObject> snapshot);
281 void ClearRedo(int room_id);
282 void ProcessPendingSwap(); // Process deferred swap after draw
283};
284
285} // namespace editor
286} // namespace yaze
287
288#endif // YAZE_APP_EDITOR_DUNGEON_EDITOR_V2_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
bool is_loaded() const
Definition rom.h:128
auto title() const
Definition rom.h:133
DungeonEditorV2 - Simplified dungeon editor using component delegation.
class MinecartTrackEditorPanel * minecart_track_editor_panel_
static constexpr const char * kControlPanelId
std::array< zelda3::Room, 0x128 > rooms_
class ItemEditorPanel * item_editor_panel_
std::unordered_map< int, std::vector< std::vector< zelda3::RoomObject > > > undo_history_
std::array< zelda3::RoomEntrance, 0x8C > entrances_
gfx::PaletteGroup current_palette_group_
void OnEntranceSelected(int entrance_id)
static constexpr const char * kEntranceListId
class SpriteEditorPanel * sprite_editor_panel_
void HandleObjectPlaced(const zelda3::RoomObject &obj)
std::unique_ptr< ObjectEditorPanel > owned_object_editor_panel_
std::string GetRomStatus() const override
std::unique_ptr< zelda3::DungeonEditorSystem > dungeon_editor_system_
void OnRoomSelected(int room_id, bool request_focus=true)
DungeonRoomGraphicsPanel * room_graphics_panel_
ObjectEditorPanel * object_editor_panel_
std::map< int, std::unique_ptr< DungeonCanvasViewer > > room_viewers_
bool IsRomLoaded() const override
gui::PaletteEditorWidget palette_editor_
void ShowPanel(const std::string &card_id)
absl::Status Paste() override
void SwapRoomInPanel(int old_room_id, int new_room_id)
absl::Status RestoreFromSnapshot(int room_id, std::vector< zelda3::RoomObject > snapshot)
static constexpr const char * kObjectToolsId
DungeonCanvasViewer * GetViewerForRoom(int room_id)
absl::Status Update() override
absl::Status Find() override
std::unique_ptr< emu::render::EmulatorRenderService > render_service_
std::unordered_map< int, std::vector< std::vector< zelda3::RoomObject > > > redo_history_
std::unordered_map< int, std::shared_ptr< gui::PanelWindow > > room_cards_
void SetGameData(zelda3::GameData *game_data) override
static constexpr const char * kRoomGraphicsId
static constexpr const char * kRoomMatrixId
ObjectEditorPanel * object_editor_panel() const
static constexpr const char * kRoomSelectorId
const ImVector< int > & active_rooms() const
static constexpr const char * kPaletteEditorId
EditorPanel for displaying room graphics blocks.
Manages loading and saving of dungeon room data.
void SetGameData(zelda3::GameData *game_data)
Handles room and entrance selection UI.
const ImVector< int > & active_rooms() const
Interface for editor classes.
Definition editor.h:179
zelda3::GameData * game_data() const
Definition editor.h:228
EditorDependencies dependencies_
Definition editor.h:237
EditorType type_
Definition editor.h:236
EditorPanel for placing and managing dungeon pot items.
Unified panel for dungeon object editing.
void SetGameData(zelda3::GameData *game_data)
bool ShowPanel(size_t session_id, const std::string &base_card_id)
EditorPanel for placing and managing dungeon sprites.
Defines an abstract interface for all rendering operations.
Definition irenderer.h:40
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
std::unique_ptr< DungeonEditorSystem > CreateDungeonEditorSystem(Rom *rom, GameData *game_data)
Factory function to create dungeon editor system.
zelda3::GameData * game_data
Definition editor.h:127
Represents a group of palettes.