The Battle for Wesnoth  1.19.25+dev
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
actions::undo_action_container Class Reference

#include <undo_action.hpp>

Classes

struct  subaction_factory
 

Public Types

using t_factory = std::function< t_step_ptr(const config &)>
 
using t_factory_map = std::map< std::string, t_factory >
 

Public Member Functions

 undo_action_container ()
 
bool empty () const
 
t_stepssteps ()
 
bool undo (int side)
 
void write (config &cfg)
 
void read (const config &cfg)
 Creates the list of undo steps based on a config. More...
 
void add (t_step_ptr &&action)
 
void combine_moves ()
 Merges consecutive undo::move_action steps that form one continuous path into a single step. More...
 
void set_unit_id_diff (int id_diff)
 

Static Public Member Functions

static t_factory_mapget_factories ()
 

Private Types

using t_step_ptr = std::unique_ptr< undo_action >
 
using t_steps = std::vector< t_step_ptr >
 

Private Attributes

t_steps steps_
 
int unit_id_diff_
 

Detailed Description

Definition at line 30 of file undo_action.hpp.

Member Typedef Documentation

◆ t_factory

Definition at line 62 of file undo_action.hpp.

◆ t_factory_map

Definition at line 63 of file undo_action.hpp.

◆ t_step_ptr

using actions::undo_action_container::t_step_ptr = std::unique_ptr<undo_action>
private

Definition at line 32 of file undo_action.hpp.

◆ t_steps

Definition at line 33 of file undo_action.hpp.

Constructor & Destructor Documentation

◆ undo_action_container()

actions::undo_action_container::undo_action_container ( )

Definition at line 42 of file undo_action.cpp.

Member Function Documentation

◆ add()

void actions::undo_action_container::add ( t_step_ptr &&  action)

Definition at line 61 of file undo_action.cpp.

References steps_.

Referenced by read().

◆ combine_moves()

void actions::undo_action_container::combine_moves ( )

Merges consecutive undo::move_action steps that form one continuous path into a single step.

Merges runs of consecutive undo::move_action steps that together form one continuous path (each one picking up exactly where the previous left off) into a single step covering the whole stretch.

See the .cpp file for why this is safe and useful.

move_unit() records one move_action per hex so that, when undoing, any [on_undo] event handlers interleaved between hexes still fire in the correct order relative to the unit's position. That splitting serves no purpose across a stretch where nothing was interleaved, so this collapses those stretches back into one step - which both undoes (and later animates) as a single continuous motion, and avoids writing one redundant step per hex to the save file.

Definition at line 78 of file undo_action.cpp.

References actions::shroud_clearing_action::route, and steps_.

◆ empty()

bool actions::undo_action_container::empty ( ) const
inline

Definition at line 42 of file undo_action.hpp.

References steps_.

◆ get_factories()

undo_action_container::t_factory_map & actions::undo_action_container::get_factories ( )
static

◆ read()

void actions::undo_action_container::read ( const config cfg)

Creates the list of undo steps based on a config.

Throws bad_lexical_cast or config::error if it cannot parse the config properly.

Definition at line 99 of file undo_action.cpp.

References add(), cfg, config::child_range(), utils::find(), and get_factories().

◆ set_unit_id_diff()

void actions::undo_action_container::set_unit_id_diff ( int  id_diff)
inline

Definition at line 57 of file undo_action.hpp.

References unit_id_diff_.

◆ steps()

t_steps& actions::undo_action_container::steps ( )
inline

Definition at line 43 of file undo_action.hpp.

References steps_.

◆ undo()

bool actions::undo_action_container::undo ( int  side)

◆ write()

void actions::undo_action_container::write ( config cfg)

Definition at line 109 of file undo_action.cpp.

References config::add_child(), cfg, and steps_.

Member Data Documentation

◆ steps_

t_steps actions::undo_action_container::steps_
private

Definition at line 35 of file undo_action.hpp.

Referenced by add(), combine_moves(), empty(), steps(), undo(), and write().

◆ unit_id_diff_

int actions::undo_action_container::unit_id_diff_
private

Definition at line 36 of file undo_action.hpp.

Referenced by set_unit_id_diff(), and undo().


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