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};
27
37 zelda3::DungeonMap map_data{0, 0, 0, {}, {}};
38 std::vector<std::array<std::string, zelda3::kNumRooms>> labels;
39};
40
48 int tile16_id = 0;
49 std::array<gfx::TileInfo, 4> tile_info;
50};
51
63
73 public:
74 using RestoreFn = std::function<void(const ScreenSnapshot&)>;
75
77 RestoreFn restore, std::string description)
78 : before_(std::move(before)),
79 after_(std::move(after)),
80 restore_(std::move(restore)),
81 description_(std::move(description)) {}
82
83 absl::Status Undo() override {
84 if (!restore_) {
85 return absl::InternalError("ScreenEditAction: no restore callback");
86 }
88 return absl::OkStatus();
89 }
90
91 absl::Status Redo() override {
92 if (!restore_) {
93 return absl::InternalError("ScreenEditAction: no restore callback");
94 }
96 return absl::OkStatus();
97 }
98
99 std::string Description() const override { return description_; }
100
101 size_t MemoryUsage() const override {
102 size_t size = sizeof(before_) + sizeof(after_);
103 // Account for vector storage in dungeon map snapshots
104 for (const auto& floor : before_.dungeon_map.map_data.floor_rooms)
105 size += floor.size();
106 for (const auto& floor : before_.dungeon_map.map_data.floor_gfx)
107 size += floor.size();
108 for (const auto& floor : after_.dungeon_map.map_data.floor_rooms)
109 size += floor.size();
110 for (const auto& floor : after_.dungeon_map.map_data.floor_gfx)
111 size += floor.size();
112 return size;
113 }
114
115 bool CanMergeWith(const UndoAction& /*prev*/) const override { return false; }
116
117 private:
121 std::string description_;
122};
123
124} // namespace editor
125} // namespace yaze
126
127#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
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