yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_undo_actions.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_UNDO_ACTIONS_H_
2#define YAZE_APP_EDITOR_DUNGEON_UNDO_ACTIONS_H_
3
4#include <cstddef>
5#include <cstdint>
6#include <functional>
7#include <string>
8#include <utility>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "absl/strings/str_format.h"
16
17namespace yaze {
18namespace editor {
19
30 public:
31 using RestoreFn =
32 std::function<void(int room_id, const std::vector<zelda3::RoomObject>&,
33 const std::vector<size_t>& selected_indices)>;
34
35 DungeonObjectsAction(int room_id, std::vector<zelda3::RoomObject> before,
36 std::vector<size_t> before_selection,
37 std::vector<zelda3::RoomObject> after,
38 std::vector<size_t> after_selection, RestoreFn restore)
39 : room_id_(room_id),
40 before_(std::move(before)),
41 before_selection_(std::move(before_selection)),
42 after_(std::move(after)),
43 after_selection_(std::move(after_selection)),
44 restore_(std::move(restore)) {}
45
46 absl::Status Undo() override {
47 if (!restore_) {
48 return absl::InternalError("DungeonObjectsAction: no restore callback");
49 }
51 return absl::OkStatus();
52 }
53
54 absl::Status Redo() override {
55 if (!restore_) {
56 return absl::InternalError("DungeonObjectsAction: no restore callback");
57 }
59 return absl::OkStatus();
60 }
61
62 std::string Description() const override {
63 return absl::StrFormat("Edit room %03X objects", room_id_);
64 }
65
66 size_t MemoryUsage() const override {
67 // Rough estimate: each RoomObject is ~40-80 bytes
68 return (before_.size() + after_.size()) * sizeof(zelda3::RoomObject) +
69 (before_selection_.size() + after_selection_.size()) *
70 sizeof(size_t);
71 }
72
73 bool CanMergeWith(const UndoAction& /*prev*/) const override {
74 // Object edits are already grouped per mutation (drag, delete, etc.)
75 // so merging is not needed.
76 return false;
77 }
78
79 private:
81 std::vector<zelda3::RoomObject> before_;
82 std::vector<size_t> before_selection_;
83 std::vector<zelda3::RoomObject> after_;
84 std::vector<size_t> after_selection_;
86};
87
89 uint8_t sram_bit_mask = 0; // Bit in $7EF411 (0x00 = Auto/unspecified)
90 std::vector<uint16_t> offsets; // Each offset = Y*64 + X (0..4095)
91};
92
94 public:
95 using RestoreFn =
96 std::function<void(int room_id, const zelda3::CustomCollisionMap&)>;
97
100 RestoreFn restore)
101 : room_id_(room_id),
102 before_(std::move(before)),
103 after_(std::move(after)),
104 restore_(std::move(restore)) {}
105
106 absl::Status Undo() override {
107 if (!restore_) {
108 return absl::InternalError(
109 "DungeonCustomCollisionAction: no restore callback");
110 }
112 return absl::OkStatus();
113 }
114
115 absl::Status Redo() override {
116 if (!restore_) {
117 return absl::InternalError(
118 "DungeonCustomCollisionAction: no restore callback");
119 }
121 return absl::OkStatus();
122 }
123
124 std::string Description() const override {
125 return absl::StrFormat("Edit room %03X custom collision", room_id_);
126 }
127
128 size_t MemoryUsage() const override {
129 return sizeof(before_) + sizeof(after_);
130 }
131
132 bool CanMergeWith(const UndoAction& /*prev*/) const override { return false; }
133
134 private:
139};
140
145
147 public:
148 using RestoreFn = std::function<absl::Status(
149 const std::vector<DungeonCustomCollisionSnapshot>&)>;
150
152 std::vector<DungeonCustomCollisionSnapshot> before,
153 std::vector<DungeonCustomCollisionSnapshot> after, RestoreFn restore)
154 : before_(std::move(before)),
155 after_(std::move(after)),
156 restore_(std::move(restore)) {}
157
158 absl::Status Undo() override {
159 if (!restore_) {
160 return absl::InternalError(
161 "DungeonCustomCollisionBatchAction: no restore callback");
162 }
163 return restore_(before_);
164 }
165
166 absl::Status Redo() override {
167 if (!restore_) {
168 return absl::InternalError(
169 "DungeonCustomCollisionBatchAction: no restore callback");
170 }
171 return restore_(after_);
172 }
173
174 std::string Description() const override {
175 return absl::StrFormat("Generate minecart collision for %d rooms",
176 static_cast<int>(after_.size()));
177 }
178
179 size_t MemoryUsage() const override {
180 return (before_.size() + after_.size()) *
182 }
183
184 bool CanMergeWith(const UndoAction& /*prev*/) const override { return false; }
185
186 private:
187 std::vector<DungeonCustomCollisionSnapshot> before_;
188 std::vector<DungeonCustomCollisionSnapshot> after_;
190};
191
193 public:
194 using RestoreFn = std::function<void(int room_id, const WaterFillSnapshot&)>;
195
197 WaterFillSnapshot after, RestoreFn restore)
198 : room_id_(room_id),
199 before_(std::move(before)),
200 after_(std::move(after)),
201 restore_(std::move(restore)) {}
202
203 absl::Status Undo() override {
204 if (!restore_) {
205 return absl::InternalError("DungeonWaterFillAction: no restore callback");
206 }
208 return absl::OkStatus();
209 }
210
211 absl::Status Redo() override {
212 if (!restore_) {
213 return absl::InternalError("DungeonWaterFillAction: no restore callback");
214 }
216 return absl::OkStatus();
217 }
218
219 std::string Description() const override {
220 return absl::StrFormat("Edit room %03X water fill", room_id_);
221 }
222
223 size_t MemoryUsage() const override {
224 return before_.offsets.size() * sizeof(uint16_t) +
225 after_.offsets.size() * sizeof(uint16_t) + sizeof(before_) +
226 sizeof(after_);
227 }
228
229 bool CanMergeWith(const UndoAction& /*prev*/) const override { return false; }
230
231 private:
236};
237
238} // namespace editor
239} // namespace yaze
240
241#endif // YAZE_APP_EDITOR_DUNGEON_UNDO_ACTIONS_H_
size_t MemoryUsage() const override
Approximate memory footprint for budget enforcement.
std::string Description() const override
Human-readable description (e.g., "Paint 12 tiles on map 5")
std::function< void(int room_id, const zelda3::CustomCollisionMap &)> RestoreFn
DungeonCustomCollisionAction(int room_id, zelda3::CustomCollisionMap before, zelda3::CustomCollisionMap after, RestoreFn restore)
bool CanMergeWith(const UndoAction &) const override
size_t MemoryUsage() const override
Approximate memory footprint for budget enforcement.
std::string Description() const override
Human-readable description (e.g., "Paint 12 tiles on map 5")
std::vector< DungeonCustomCollisionSnapshot > after_
bool CanMergeWith(const UndoAction &) const override
std::vector< DungeonCustomCollisionSnapshot > before_
std::function< absl::Status( const std::vector< DungeonCustomCollisionSnapshot > &)> RestoreFn
DungeonCustomCollisionBatchAction(std::vector< DungeonCustomCollisionSnapshot > before, std::vector< DungeonCustomCollisionSnapshot > after, RestoreFn restore)
Undoable action for dungeon room object edits.
std::vector< zelda3::RoomObject > after_
std::vector< zelda3::RoomObject > before_
std::function< void(int room_id, const std::vector< zelda3::RoomObject > &, const std::vector< size_t > &selected_indices)> RestoreFn
bool CanMergeWith(const UndoAction &) const override
size_t MemoryUsage() const override
Approximate memory footprint for budget enforcement.
std::string Description() const override
Human-readable description (e.g., "Paint 12 tiles on map 5")
DungeonObjectsAction(int room_id, std::vector< zelda3::RoomObject > before, std::vector< size_t > before_selection, std::vector< zelda3::RoomObject > after, std::vector< size_t > after_selection, RestoreFn restore)
std::string Description() const override
Human-readable description (e.g., "Paint 12 tiles on map 5")
std::function< void(int room_id, const WaterFillSnapshot &)> RestoreFn
bool CanMergeWith(const UndoAction &) const override
size_t MemoryUsage() const override
Approximate memory footprint for budget enforcement.
DungeonWaterFillAction(int room_id, WaterFillSnapshot before, WaterFillSnapshot after, RestoreFn restore)
Abstract base for all undoable actions (Command pattern)
Definition undo_action.h:20