yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_editor_system.cc
Go to the documentation of this file.
2
3#include <chrono>
4
5namespace yaze {
6namespace zelda3 {
7
9 : rom_(rom), game_data_(game_data) {}
10
12 if (rom_ == nullptr) {
13 return absl::InvalidArgumentError("ROM is null");
14 }
15
16 // Initialize object editor
17 object_editor_ = std::make_shared<DungeonObjectEditor>(rom_);
18 RETURN_IF_ERROR(object_editor_->InitializeEditor());
19
20 return absl::OkStatus();
21}
22
23absl::Status DungeonEditorSystem::LoadDungeon(int dungeon_id) {
25 editor_state_.is_dirty = false;
26 editor_state_.last_save_time = std::chrono::steady_clock::now();
27 return absl::OkStatus();
28}
29
31 if (!rom_) return absl::InvalidArgumentError("ROM is null");
32
33 for (int i = 0; i < NumberOfRooms; ++i) {
34 auto status = SaveRoomData(i);
35 if (!status.ok()) {
36 return status;
37 }
38 }
39
40 editor_state_.is_dirty = false;
41 editor_state_.last_save_time = std::chrono::steady_clock::now();
42
43 return absl::OkStatus();
44}
45
46absl::Status DungeonEditorSystem::SaveRoom(int room_id) {
47 return SaveRoomData(room_id);
48}
49
50absl::Status DungeonEditorSystem::ReloadRoom(int room_id) {
51 return LoadRoomData(room_id);
52}
53
54absl::Status DungeonEditorSystem::SetCurrentRoom(int room_id) {
55 if (room_id < 0 || room_id >= NumberOfRooms) {
56 return absl::InvalidArgumentError("Invalid room ID");
57 }
58
60 return absl::OkStatus();
61}
62
66
67absl::StatusOr<Room> DungeonEditorSystem::GetRoom(int room_id) {
68 if (room_id < 0 || room_id >= NumberOfRooms) {
69 return absl::InvalidArgumentError("Invalid room ID");
70 }
71
72 return Room(room_id, rom_, game_data_);
73}
74
75std::shared_ptr<DungeonObjectEditor> DungeonEditorSystem::GetObjectEditor() {
76 if (!object_editor_) {
77 object_editor_ = std::make_shared<DungeonObjectEditor>(rom_);
78 }
79 return object_editor_;
80}
81
83 if (object_editor_) {
84 return object_editor_->Undo();
85 }
86
87 if (!CanUndo()) {
88 return absl::FailedPreconditionError("Nothing to undo");
89 }
90
91 return absl::OkStatus();
92}
93
95 if (object_editor_) {
96 return object_editor_->Redo();
97 }
98
99 if (!CanRedo()) {
100 return absl::FailedPreconditionError("Nothing to redo");
101 }
102
103 return absl::OkStatus();
104}
105
106bool DungeonEditorSystem::CanUndo() const { return !undo_history_.empty(); }
107
108bool DungeonEditorSystem::CanRedo() const { return !redo_history_.empty(); }
109
111 undo_history_.clear();
112 redo_history_.clear();
113}
114
118
122
124
126
128 rom_ = rom;
129 if (object_editor_) {
130 object_editor_->SetROM(rom);
131 }
132}
133
135 if (object_editor_) {
136 object_editor_->SetExternalRoom(room);
137 }
138}
139
141 if (!object_editor_) {
142 object_editor_ = std::make_shared<DungeonObjectEditor>(rom_);
143 }
144 return object_editor_->InitializeEditor();
145}
146
147absl::Status DungeonEditorSystem::LoadRoomData(int room_id) {
148 if (!rom_) return absl::InvalidArgumentError("ROM is null");
149
150 // Room loading is handled by the Room class itself
151 // This method exists for consistency with the API
152 return absl::OkStatus();
153}
154
155absl::Status DungeonEditorSystem::SaveRoomData(int room_id) {
156 if (!rom_) return absl::InvalidArgumentError("ROM is null");
157
158 // Check if this is the currently edited room in the ObjectEditor
159 if (object_editor_ && object_editor_->GetRoom().id() == room_id) {
160 Room* room = object_editor_->GetMutableRoom();
161 if (room) {
162 return room->SaveObjects();
163 }
164 }
165
166 return absl::OkStatus();
167}
168
169std::unique_ptr<DungeonEditorSystem> CreateDungeonEditorSystem(
170 Rom* rom, GameData* game_data) {
171 return std::make_unique<DungeonEditorSystem>(rom, game_data);
172}
173
174} // namespace zelda3
175} // namespace yaze
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
void SetRoomChangedCallback(RoomChangedCallback callback)
std::shared_ptr< DungeonObjectEditor > object_editor_
DungeonEditorSystem(Rom *rom, GameData *game_data=nullptr)
std::shared_ptr< DungeonObjectEditor > GetObjectEditor()
absl::Status SetCurrentRoom(int room_id)
absl::Status LoadDungeon(int dungeon_id)
std::function< void(int room_id)> RoomChangedCallback
absl::StatusOr< Room > GetRoom(int room_id)
absl::Status SaveObjects()
Definition room.cc:1377
constexpr int NumberOfRooms
Definition room.h:70
std::unique_ptr< DungeonEditorSystem > CreateDungeonEditorSystem(Rom *rom, GameData *game_data)
Factory function to create dungeon editor system.
#define RETURN_IF_ERROR(expr)
Definition snes.cc:22
std::chrono::steady_clock::time_point last_save_time