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
142 public:
143 using RestoreFn = std::function<void(int room_id, const WaterFillSnapshot&)>;
144
146 WaterFillSnapshot after, RestoreFn restore)
147 : room_id_(room_id),
148 before_(std::move(before)),
149 after_(std::move(after)),
150 restore_(std::move(restore)) {}
151
152 absl::Status Undo() override {
153 if (!restore_) {
154 return absl::InternalError("DungeonWaterFillAction: no restore callback");
155 }
157 return absl::OkStatus();
158 }
159
160 absl::Status Redo() override {
161 if (!restore_) {
162 return absl::InternalError("DungeonWaterFillAction: no restore callback");
163 }
165 return absl::OkStatus();
166 }
167
168 std::string Description() const override {
169 return absl::StrFormat("Edit room %03X water fill", room_id_);
170 }
171
172 size_t MemoryUsage() const override {
173 return before_.offsets.size() * sizeof(uint16_t) +
174 after_.offsets.size() * sizeof(uint16_t) + sizeof(before_) +
175 sizeof(after_);
176 }
177
178 bool CanMergeWith(const UndoAction& /*prev*/) const override { return false; }
179
180 private:
185};
186
187} // namespace editor
188} // namespace yaze
189
190#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_
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