yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
screen_undo_actions.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_SCREEN_UNDO_ACTIONS_H_
2#define YAZE_APP_EDITOR_GRAPHICS_SCREEN_UNDO_ACTIONS_H_
3
4#include <array>
5#include <cstddef>
6#include <cstdint>
7#include <functional>
8#include <string>
9#include <utility>
10#include <vector>
11
12#include "absl/status/status.h"
16
17namespace yaze {
18namespace editor {
19
23enum class ScreenEditType {
24 kDungeonMap, // Dungeon map room/gfx layout
25 kTile16Edit, // Tile16 composition modification
26 kMenuTilemap, // 2bpp menu tilemap (Menu Tilemap panel) edit
27};
28
38 int floor_index = 0;
39 zelda3::DungeonMap map_data{0, 0, 0, {}, {}};
40 std::vector<std::array<std::string, zelda3::kNumRooms>> labels;
41};
42
50 int tile16_id = 0;
51 std::array<gfx::TileInfo, 4> tile_info;
52};
53
62 std::string path;
63 std::vector<uint8_t> bytes;
64};
65
79
89 public:
90 using RestoreFn = std::function<void(const ScreenSnapshot&)>;
91
93 RestoreFn restore, std::string description)
94 : before_(std::move(before)),
95 after_(std::move(after)),
96 restore_(std::move(restore)),
97 description_(std::move(description)) {}
98
99 absl::Status Undo() override {
100 if (!restore_) {
101 return absl::InternalError("ScreenEditAction: no restore callback");
102 }
104 return absl::OkStatus();
105 }
106
107 absl::Status Redo() override {
108 if (!restore_) {
109 return absl::InternalError("ScreenEditAction: no restore callback");
110 }
112 return absl::OkStatus();
113 }
114
115 std::string Description() const override { return description_; }
116
117 size_t MemoryUsage() const override {
118 size_t size = sizeof(before_) + sizeof(after_);
119 // Account for vector storage in dungeon map snapshots
120 for (const auto& floor : before_.dungeon_map.map_data.floor_rooms)
121 size += floor.size();
122 for (const auto& floor : before_.dungeon_map.map_data.floor_gfx)
123 size += floor.size();
124 for (const auto& floor : after_.dungeon_map.map_data.floor_rooms)
125 size += floor.size();
126 for (const auto& floor : after_.dungeon_map.map_data.floor_gfx)
127 size += floor.size();
128 size += before_.menu_tilemap.bytes.size();
129 size += after_.menu_tilemap.bytes.size();
130 return size;
131 }
132
133 bool CanMergeWith(const UndoAction& /*prev*/) const override { return false; }
134
135 private:
139 std::string description_;
140};
141
142} // namespace editor
143} // namespace yaze
144
145#endif // YAZE_APP_EDITOR_GRAPHICS_SCREEN_UNDO_ACTIONS_H_
Undoable action for screen editor edits.
std::function< void(const ScreenSnapshot &)> RestoreFn
std::string Description() const override
Human-readable description (e.g., "Paint 12 tiles on map 5")
ScreenEditAction(ScreenSnapshot before, ScreenSnapshot after, RestoreFn restore, std::string description)
bool CanMergeWith(const UndoAction &) const override
size_t MemoryUsage() const override
Approximate memory footprint for budget enforcement.
Abstract base for all undoable actions (Command pattern)
Definition undo_action.h:20
ScreenEditType
Which screen type the snapshot belongs to.
Snapshot of dungeon map editing state for undo/redo.
std::vector< std::array< std::string, zelda3::kNumRooms > > labels
Snapshot of a Menu Tilemap document's raw bytes for undo/redo.
Unified screen editor snapshot.
Snapshot of tile16 composition state for undo/redo.
std::array< gfx::TileInfo, 4 > tile_info
DungeonMap represents the map menu for a dungeon.
Definition dungeon_map.h:54
std::vector< std::array< uint8_t, kNumRooms > > floor_rooms
Definition dungeon_map.h:58
std::vector< std::array< uint8_t, kNumRooms > > floor_gfx
Definition dungeon_map.h:59