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 <array>
5#include <cstdint>
6#include <map>
7#include <memory>
8#include <string>
9#include <unordered_map>
10#include <vector>
11
12#include "absl/status/status.h"
13#include "absl/strings/str_format.h"
14#include "app/editor/editor.h"
22#include "dungeon_room_loader.h"
24#include "imgui/imgui.h"
27#include "rom/rom.h"
29#include "zelda3/dungeon/room.h"
32#include "zelda3/game_data.h"
33
34namespace yaze {
35namespace editor {
36
37class MinecartTrackEditorPanel;
38
78class DungeonEditorV2 : public Editor {
79 public:
80 explicit DungeonEditorV2(Rom* rom = nullptr)
83 if (rom) {
85 for (auto& room : rooms_) {
86 room.SetRom(rom);
87 }
88 }
89 }
90
91 ~DungeonEditorV2() override;
92
95 dependencies_.game_data = game_data; // Also set base class dependency
99 }
101 dungeon_editor_system_->SetGameData(game_data);
102 }
103 for (auto& room : rooms_) {
104 room.SetGameData(game_data);
105 }
106 // Note: Canvas viewer game data is set lazily in GetViewerForRoom
107 // but we should update existing viewers
108 for (auto& [id, viewer] : room_viewers_) {
109 if (viewer)
110 viewer->SetGameData(game_data);
111 }
112 }
113
114 // Editor interface
115 void Initialize(gfx::IRenderer* renderer, Rom* rom);
116 void Initialize() override;
117 absl::Status Load();
118 absl::Status Update() override;
119 absl::Status Undo() override;
120 absl::Status Redo() override;
121 absl::Status Cut() override;
122 absl::Status Copy() override;
123 absl::Status Paste() override;
124 absl::Status Find() override { return absl::UnimplementedError("Find"); }
125 absl::Status Save() override;
126
127 // ROM management
128 void SetRom(Rom* rom) {
129 rom_ = rom;
132
133 // Propagate ROM to all rooms
134 if (rom) {
135 for (auto& room : rooms_) {
136 room.SetRom(rom);
137 }
138 }
139
140 // Reset viewers on ROM change
141 room_viewers_.clear();
142
143 // Create render service if needed
144 if (rom && rom->is_loaded() && !render_service_) {
146 std::make_unique<emu::render::EmulatorRenderService>(rom);
147 render_service_->Initialize();
148 }
149 }
150 Rom* rom() const { return rom_; }
151
152 // Room management
153 void add_room(int room_id);
154 void FocusRoom(int room_id);
155
156 // Agent/Automation controls
157 void SelectObject(int obj_id);
158 void SetAgentMode(bool enabled);
159
160 // ROM state
161 bool IsRomLoaded() const override { return rom_ && rom_->is_loaded(); }
162 std::string GetRomStatus() const override {
163 if (!rom_)
164 return "No ROM loaded";
165 if (!rom_->is_loaded())
166 return "ROM failed to load";
167 return absl::StrFormat("ROM loaded: %s", rom_->title());
168 }
169
170 // Show a panel by its card_id using PanelManager
171 void ShowPanel(const std::string& card_id) {
174 }
175 }
176
177 // Panel card IDs for programmatic access
178 static constexpr const char* kControlPanelId = "dungeon.control_panel";
179 static constexpr const char* kRoomSelectorId = "dungeon.room_selector";
180 static constexpr const char* kEntranceListId = "dungeon.entrance_list";
181 static constexpr const char* kRoomMatrixId = "dungeon.room_matrix";
182 static constexpr const char* kRoomGraphicsId = "dungeon.room_graphics";
183 static constexpr const char* kObjectToolsId = "dungeon.object_tools";
184 static constexpr const char* kPaletteEditorId = "dungeon.palette_editor";
185
186 // Public accessors for WASM API and automation
188 const ImVector<int>& active_rooms() const {
190 }
194
195 private:
197
198 // Draw the Room Panels
199 void DrawRoomPanels();
200 void DrawRoomTab(int room_id);
201
202 // Texture processing (critical for rendering)
204
205 // Room selection callback
206 void OnRoomSelected(int room_id, bool request_focus = true);
207 void OnEntranceSelected(int entrance_id);
208
209 // Swap room in current panel (for arrow navigation)
210 void SwapRoomInPanel(int old_room_id, int new_room_id);
211
212 // Object placement callback
213 void HandleObjectPlaced(const zelda3::RoomObject& obj);
214
215 // Helper to get or create a viewer for a specific room
217
218 // Data
221 std::array<zelda3::Room, 0x128> rooms_;
222 std::array<zelda3::RoomEntrance, 0x8C> entrances_;
223
224 // Current selection state
226
227 // Active room tabs and card tracking for jump-to
228 ImVector<int> active_rooms_;
230
232
233 // Palette management
238
239 // Components - these do all the work
242 // canvas_viewer_ removed in favor of room_viewers_
243 std::map<int, std::unique_ptr<DungeonCanvasViewer>> room_viewers_;
244
246 // Panel pointers - these are owned by PanelManager when available.
247 // Store pointers for direct access to panel methods.
253
254 // Fallback ownership for tests when PanelManager is not available.
255 // In production, this remains nullptr and panels are owned by PanelManager.
256 std::unique_ptr<ObjectEditorPanel> owned_object_editor_panel_;
257 std::unique_ptr<zelda3::DungeonEditorSystem> dungeon_editor_system_;
258 std::unique_ptr<emu::render::EmulatorRenderService> render_service_;
259
260 bool is_loaded_ = false;
261
262 // Docking class for room windows to dock together
263 ImGuiWindowClass room_window_class_;
264
265 // Shared dock ID for all room panels to auto-dock together
266 ImGuiID room_dock_id_ = 0;
267
268 // Dynamic room cards - created per open room
269 std::unordered_map<int, std::shared_ptr<gui::PanelWindow>> room_cards_;
270
271 // Undo/Redo history: store snapshots of room objects
272 std::unordered_map<int, std::vector<std::vector<zelda3::RoomObject>>>
274 std::unordered_map<int, std::vector<std::vector<zelda3::RoomObject>>>
276
277 // Pending room swap (deferred until after draw phase completes)
278 struct PendingSwap {
279 int old_room_id = -1;
280 int new_room_id = -1;
281 bool pending = false;
282 };
284
285 void PushUndoSnapshot(int room_id);
286 absl::Status RestoreFromSnapshot(int room_id,
287 std::vector<zelda3::RoomObject> snapshot);
288 void ClearRedo(int room_id);
289 void ProcessPendingSwap(); // Process deferred swap after draw
290};
291
292} // namespace editor
293} // namespace yaze
294
295#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.