#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_steps & | steps () |
| 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_map & | get_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_ |
Definition at line 30 of file undo_action.hpp.
| using actions::undo_action_container::t_factory = std::function<t_step_ptr(const config&)> |
Definition at line 62 of file undo_action.hpp.
| using actions::undo_action_container::t_factory_map = std::map<std::string, t_factory> |
Definition at line 63 of file undo_action.hpp.
|
private |
Definition at line 32 of file undo_action.hpp.
|
private |
Definition at line 33 of file undo_action.hpp.
| actions::undo_action_container::undo_action_container | ( | ) |
Definition at line 42 of file undo_action.cpp.
| void actions::undo_action_container::add | ( | t_step_ptr && | action | ) |
| 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_.
|
inline |
Definition at line 42 of file undo_action.hpp.
References steps_.
|
static |
Definition at line 116 of file undo_action.cpp.
Referenced by read(), and actions::undo_action_container::subaction_factory< T >::subaction_factory().
| 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().
|
inline |
Definition at line 57 of file undo_action.hpp.
References unit_id_diff_.
|
inline |
Definition at line 43 of file undo_action.hpp.
References steps_.
| bool actions::undo_action_container::undo | ( | int | side | ) |
Definition at line 48 of file undo_action.cpp.
References ERR_NG, resources::gameboard, n_unit::id_manager::get_save_id(), utils::views::reverse, n_unit::id_manager::set_save_id(), steps_, unit_id_diff_, and game_board::unit_id_manager().
| void actions::undo_action_container::write | ( | config & | cfg | ) |
Definition at line 109 of file undo_action.cpp.
References config::add_child(), cfg, and steps_.
|
private |
Definition at line 35 of file undo_action.hpp.
Referenced by add(), combine_moves(), empty(), steps(), undo(), and write().
|
private |
Definition at line 36 of file undo_action.hpp.
Referenced by set_unit_id_diff(), and undo().