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 <functional>
5#include <cstdint>
6#include <string>
7#include <utility>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "absl/strings/str_format.h"
15
16namespace yaze {
17namespace editor {
18
29 public:
30 using RestoreFn = std::function<void(int room_id,
31 const std::vector<zelda3::RoomObject>&)>;
32
34 std::vector<zelda3::RoomObject> before,
35 std::vector<zelda3::RoomObject> after,
36 RestoreFn restore)
37 : room_id_(room_id),
38 before_(std::move(before)),
39 after_(std::move(after)),
40 restore_(std::move(restore)) {}
41
42 absl::Status Undo() override {
43 if (!restore_) {
44 return absl::InternalError("DungeonObjectsAction: no restore callback");
45 }
47 return absl::OkStatus();
48 }
49
50 absl::Status Redo() override {
51 if (!restore_) {
52 return absl::InternalError("DungeonObjectsAction: no restore callback");
53 }
55 return absl::OkStatus();
56 }
57
58 std::string Description() const override {
59 return absl::StrFormat("Edit room %03X objects", room_id_);
60 }
61
62 size_t MemoryUsage() const override {
63 // Rough estimate: each RoomObject is ~40-80 bytes
64 return (before_.size() + after_.size()) * sizeof(zelda3::RoomObject);
65 }
66
67 bool CanMergeWith(const UndoAction& /*prev*/) const override {
68 // Object edits are already grouped per mutation (drag, delete, etc.)
69 // so merging is not needed.
70 return false;
71 }
72
73 private:
75 std::vector<zelda3::RoomObject> before_;
76 std::vector<zelda3::RoomObject> after_;
78};
79
81 uint8_t sram_bit_mask = 0; // Bit in $7EF411 (0x00 = Auto/unspecified)
82 std::vector<uint16_t> offsets; // Each offset = Y*64 + X (0..4095)
83};
84
86 public:
87 using RestoreFn =
88 std::function<void(int room_id, const zelda3::CustomCollisionMap&)>;
89
92 RestoreFn restore)
93 : room_id_(room_id),
94 before_(std::move(before)),
95 after_(std::move(after)),
96 restore_(std::move(restore)) {}
97
98 absl::Status Undo() override {
99 if (!restore_) {
100 return absl::InternalError(
101 "DungeonCustomCollisionAction: no restore callback");
102 }
104 return absl::OkStatus();
105 }
106
107 absl::Status Redo() override {
108 if (!restore_) {
109 return absl::InternalError(
110 "DungeonCustomCollisionAction: no restore callback");
111 }
113 return absl::OkStatus();
114 }
115
116 std::string Description() const override {
117 return absl::StrFormat("Edit room %03X custom collision", room_id_);
118 }
119
120 size_t MemoryUsage() const override {
121 return sizeof(before_) + sizeof(after_);
122 }
123
124 bool CanMergeWith(const UndoAction& /*prev*/) const override { return false; }
125
126 private:
131};
132
134 public:
135 using RestoreFn =
136 std::function<void(int room_id, const WaterFillSnapshot&)>;
137
139 WaterFillSnapshot after, RestoreFn restore)
140 : room_id_(room_id),
141 before_(std::move(before)),
142 after_(std::move(after)),
143 restore_(std::move(restore)) {}
144
145 absl::Status Undo() override {
146 if (!restore_) {
147 return absl::InternalError("DungeonWaterFillAction: no restore callback");
148 }
150 return absl::OkStatus();
151 }
152
153 absl::Status Redo() override {
154 if (!restore_) {
155 return absl::InternalError("DungeonWaterFillAction: no restore callback");
156 }
158 return absl::OkStatus();
159 }
160
161 std::string Description() const override {
162 return absl::StrFormat("Edit room %03X water fill", room_id_);
163 }
164
165 size_t MemoryUsage() const override {
166 return before_.offsets.size() * sizeof(uint16_t) +
167 after_.offsets.size() * sizeof(uint16_t) + sizeof(before_) +
168 sizeof(after_);
169 }
170
171 bool CanMergeWith(const UndoAction& /*prev*/) const override { return false; }
172
173 private:
178};
179
180} // namespace editor
181} // namespace yaze
182
183#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
Undoable action for dungeon room object edits.
std::vector< zelda3::RoomObject > after_
std::vector< zelda3::RoomObject > before_
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::function< void(int room_id, const std::vector< zelda3::RoomObject > &)> RestoreFn
DungeonObjectsAction(int room_id, std::vector< zelda3::RoomObject > before, std::vector< zelda3::RoomObject > after, RestoreFn restore)
std::string Description() const override
Human-readable description (e.g., "Paint 12 tiles on map 5")
bool CanMergeWith(const UndoAction &) const override
size_t MemoryUsage() const override
Approximate memory footprint for budget enforcement.
std::function< void(int room_id, const WaterFillSnapshot &)> RestoreFn
DungeonWaterFillAction(int room_id, WaterFillSnapshot before, WaterFillSnapshot after, RestoreFn restore)
Abstract base for all undoable actions (Command pattern)
Definition undo_action.h:20