yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::OverworldTilePaintAction Class Reference

Undoable action for painting tiles on the overworld map. More...

#include <overworld_undo_actions.h>

Inheritance diagram for yaze::editor::OverworldTilePaintAction:
Collaboration diagram for yaze::editor::OverworldTilePaintAction:

Public Member Functions

 OverworldTilePaintAction (int map_id, int world, std::vector< OverworldTileChange > tile_changes, zelda3::Overworld *overworld, std::function< void()> refresh_fn, std::function< void(int)> refresh_map_fn={}, bool allow_merge=true)
 
absl::Status Undo () override
 
absl::Status Redo () override
 
std::string Description () const override
 Human-readable description (e.g., "Paint 12 tiles on map 5")
 
size_t MemoryUsage () const override
 Approximate memory footprint for budget enforcement.
 
bool CanMergeWith (const UndoAction &prev) const override
 
void MergeWith (UndoAction &prev) override
 
int map_id () const
 
int world () const
 
const std::vector< OverworldTileChange > & tile_changes () const
 
- Public Member Functions inherited from yaze::editor::UndoAction
virtual ~UndoAction ()=default
 

Static Public Attributes

static constexpr int kMergeWindowMs = 500
 Merge window: consecutive paints within this duration become one step.
 

Private Member Functions

void RefreshChangedMaps () const
 

Static Private Member Functions

static uint64_t CoordinateKey (const OverworldTileChange &change)
 
static std::vector< OverworldTileChange > NormalizeChanges (std::vector< OverworldTileChange > changes)
 

Private Attributes

bool allow_merge_
 
int map_id_
 
int world_
 
std::vector< OverworldTileChange > tile_changes_
 
zelda3::Overworld * overworld_
 
std::function< void()> refresh_fn_
 
std::function< void(int)> refresh_map_fn_
 
std::chrono::steady_clock::time_point timestamp_
 

Detailed Description

Undoable action for painting tiles on the overworld map.

Captures a batch of tile changes (from a single paint stroke or rectangle fill) with both old and new values so that Undo() and Redo() are fully self-contained.

Consecutive paint actions in the same world within kMergeWindowMs are merged into a single undo step via CanMergeWith/MergeWith.

Definition at line 47 of file overworld_undo_actions.h.

Constructor & Destructor Documentation

◆ OverworldTilePaintAction()

yaze::editor::OverworldTilePaintAction::OverworldTilePaintAction ( int map_id,
int world,
std::vector< OverworldTileChange > tile_changes,
zelda3::Overworld * overworld,
std::function< void()> refresh_fn,
std::function< void(int)> refresh_map_fn = {},
bool allow_merge = true )
inline
Parameters
map_idOverworld map index where painting occurred
worldWorld index (0=Light, 1=Dark, 2=Special)
tile_changesVector of individual tile changes with old+new values
overworldNon-owning pointer to the Overworld data layer
refresh_fnCallback to refresh map visuals after undo/redo
refresh_map_fnOptional callback for each changed map; supersedes refresh_fn when provided

Definition at line 61 of file overworld_undo_actions.h.

Member Function Documentation

◆ Undo()

absl::Status yaze::editor::OverworldTilePaintAction::Undo ( )
inlineoverridevirtual

Implements yaze::editor::UndoAction.

Definition at line 76 of file overworld_undo_actions.h.

References yaze::zelda3::Overworld::GetMapTiles(), overworld_, RefreshChangedMaps(), tile_changes_, and world_.

Here is the call graph for this function:

◆ Redo()

absl::Status yaze::editor::OverworldTilePaintAction::Redo ( )
inlineoverridevirtual

Implements yaze::editor::UndoAction.

Definition at line 88 of file overworld_undo_actions.h.

References yaze::zelda3::Overworld::GetMapTiles(), overworld_, RefreshChangedMaps(), tile_changes_, and world_.

Here is the call graph for this function:

◆ Description()

std::string yaze::editor::OverworldTilePaintAction::Description ( ) const
inlineoverridevirtual

Human-readable description (e.g., "Paint 12 tiles on map 5")

Implements yaze::editor::UndoAction.

Definition at line 100 of file overworld_undo_actions.h.

References map_id_, and tile_changes_.

◆ MemoryUsage()

size_t yaze::editor::OverworldTilePaintAction::MemoryUsage ( ) const
inlineoverridevirtual

Approximate memory footprint for budget enforcement.

Reimplemented from yaze::editor::UndoAction.

Definition at line 105 of file overworld_undo_actions.h.

References tile_changes_.

◆ CanMergeWith()

bool yaze::editor::OverworldTilePaintAction::CanMergeWith ( const UndoAction & ) const
inlineoverridevirtual

Whether this action can merge with the previous action on the stack. Called only when both actions have the same concrete type.

Reimplemented from yaze::editor::UndoAction.

Definition at line 109 of file overworld_undo_actions.h.

References allow_merge_, kMergeWindowMs, overworld_, timestamp_, and world_.

◆ MergeWith()

void yaze::editor::OverworldTilePaintAction::MergeWith ( UndoAction & )
inlineoverridevirtual

Absorb the previous action into this one. Precondition: CanMergeWith(prev) returned true.

Reimplemented from yaze::editor::UndoAction.

Definition at line 128 of file overworld_undo_actions.h.

References CoordinateKey(), tile_changes_, and timestamp_.

Here is the call graph for this function:

◆ map_id()

int yaze::editor::OverworldTilePaintAction::map_id ( ) const
inline

Definition at line 158 of file overworld_undo_actions.h.

References map_id_.

Referenced by RefreshChangedMaps().

◆ world()

int yaze::editor::OverworldTilePaintAction::world ( ) const
inline

Definition at line 159 of file overworld_undo_actions.h.

References world_.

◆ tile_changes()

const std::vector< OverworldTileChange > & yaze::editor::OverworldTilePaintAction::tile_changes ( ) const
inline

Definition at line 160 of file overworld_undo_actions.h.

References tile_changes_.

◆ CoordinateKey()

static uint64_t yaze::editor::OverworldTilePaintAction::CoordinateKey ( const OverworldTileChange & change)
inlinestaticprivate

◆ NormalizeChanges()

static std::vector< OverworldTileChange > yaze::editor::OverworldTilePaintAction::NormalizeChanges ( std::vector< OverworldTileChange > changes)
inlinestaticprivate

Definition at line 170 of file overworld_undo_actions.h.

References CoordinateKey().

Here is the call graph for this function:

◆ RefreshChangedMaps()

void yaze::editor::OverworldTilePaintAction::RefreshChangedMaps ( ) const
inlineprivate

Definition at line 189 of file overworld_undo_actions.h.

References yaze::zelda3::kNumOverworldMaps, map_id(), refresh_fn_, refresh_map_fn_, tile_changes_, and world_.

Referenced by Redo(), and Undo().

Here is the call graph for this function:

Member Data Documentation

◆ kMergeWindowMs

constexpr int yaze::editor::OverworldTilePaintAction::kMergeWindowMs = 500
staticconstexpr

Merge window: consecutive paints within this duration become one step.

Definition at line 50 of file overworld_undo_actions.h.

Referenced by CanMergeWith().

◆ allow_merge_

bool yaze::editor::OverworldTilePaintAction::allow_merge_
private

Definition at line 208 of file overworld_undo_actions.h.

Referenced by CanMergeWith().

◆ map_id_

int yaze::editor::OverworldTilePaintAction::map_id_
private

Definition at line 209 of file overworld_undo_actions.h.

Referenced by Description(), and map_id().

◆ world_

int yaze::editor::OverworldTilePaintAction::world_
private

Definition at line 210 of file overworld_undo_actions.h.

Referenced by CanMergeWith(), Redo(), RefreshChangedMaps(), Undo(), and world().

◆ tile_changes_

std::vector<OverworldTileChange> yaze::editor::OverworldTilePaintAction::tile_changes_
private

◆ overworld_

zelda3::Overworld* yaze::editor::OverworldTilePaintAction::overworld_
private

Definition at line 212 of file overworld_undo_actions.h.

Referenced by CanMergeWith(), Redo(), and Undo().

◆ refresh_fn_

std::function<void()> yaze::editor::OverworldTilePaintAction::refresh_fn_
private

Definition at line 213 of file overworld_undo_actions.h.

Referenced by RefreshChangedMaps().

◆ refresh_map_fn_

std::function<void(int)> yaze::editor::OverworldTilePaintAction::refresh_map_fn_
private

Definition at line 214 of file overworld_undo_actions.h.

Referenced by RefreshChangedMaps().

◆ timestamp_

std::chrono::steady_clock::time_point yaze::editor::OverworldTilePaintAction::timestamp_
private

Definition at line 215 of file overworld_undo_actions.h.

Referenced by CanMergeWith(), and MergeWith().


The documentation for this class was generated from the following file: