1#ifndef YAZE_APP_EDITOR_OVERWORLD_UNDO_ACTIONS_H_
2#define YAZE_APP_EDITOR_OVERWORLD_UNDO_ACTIONS_H_
8#include <unordered_map>
12#include "absl/status/status.h"
13#include "absl/strings/str_format.h"
57 std::function<
void()> refresh_fn)
63 timestamp_(std::chrono::steady_clock::now()) {}
65 absl::Status
Undo()
override {
67 return absl::InternalError(
"Overworld pointer is null");
71 world_tiles[change.x][change.y] = change.old_tile_id;
76 return absl::OkStatus();
79 absl::Status
Redo()
override {
81 return absl::InternalError(
"Overworld pointer is null");
85 world_tiles[change.x][change.y] = change.new_tile_id;
90 return absl::OkStatus();
94 return absl::StrFormat(
"Paint %d tile%s on map %d",
101 return sizeof(*this) +
106 const auto* prev_paint =
108 if (!prev_paint)
return false;
109 if (prev_paint->map_id_ !=
map_id_)
return false;
110 if (prev_paint->world_ !=
world_)
return false;
112 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
123 std::unordered_map<int64_t, size_t> coord_index;
125 int64_t key = (
static_cast<int64_t
>(
tile_changes_[i].x) << 32) |
127 coord_index[key] = i;
130 for (
const auto& prev_change : prev_paint.tile_changes_) {
131 int64_t key = (
static_cast<int64_t
>(prev_change.x) << 32) |
132 static_cast<int64_t
>(prev_change.y);
133 auto it = coord_index.find(key);
134 if (it != coord_index.end()) {
136 tile_changes_[it->second].old_tile_id = prev_change.old_tile_id;
Undoable action for painting tiles on the overworld map.
std::function< void()> refresh_fn_
size_t MemoryUsage() const override
Approximate memory footprint for budget enforcement.
void MergeWith(UndoAction &prev) override
bool CanMergeWith(const UndoAction &prev) const override
static constexpr int kMergeWindowMs
Merge window: consecutive paints within this duration become one step.
OverworldTilePaintAction(int map_id, int world, std::vector< OverworldTileChange > tile_changes, zelda3::Overworld *overworld, std::function< void()> refresh_fn)
std::string Description() const override
Human-readable description (e.g., "Paint 12 tiles on map 5")
std::vector< OverworldTileChange > tile_changes_
const std::vector< OverworldTileChange > & tile_changes() const
absl::Status Redo() override
zelda3::Overworld * overworld_
std::chrono::steady_clock::time_point timestamp_
absl::Status Undo() override
Abstract base for all undoable actions (Command pattern)
Represents the full Overworld data, light and dark world.
OverworldBlockset & GetMapTiles(int world_type)
A single tile coordinate + old/new value pair for undo/redo.