The Battle for Wesnoth  1.17.12+dev
Public Types | Public Member Functions | Private Attributes | List of all members
game_events::manager Class Reference

The game event manager loads the scenario configuration object, and ensures that events are handled according to the scenario configuration for its lifetime. More...

#include <manager.hpp>

Public Types

using event_func_t = std::function< void(game_events::manager &, handler_ptr &)>
 

Public Member Functions

 manager (const manager &)=delete
 
manageroperator= (const manager &)=delete
 
 manager ()
 
void read_scenario (const config &scenario_cfg, game_lua_kernel &lk)
 
 ~manager ()
 
void add_event_handler_from_wml (const config &handler, game_lua_kernel &lk, bool is_menu_item=false)
 Create an event handler from an [event] tag. More...
 
pending_event_handler add_event_handler_from_lua (const std::string &name, const std::string &id, bool repeat=false, bool is_menu_item=false)
 Create an empty event handler. More...
 
void remove_event_handler (const std::string &id)
 Removes an event handler. More...
 
const handler_ptr get_event_handler_by_id (const std::string &id)
 Gets an event handler by ID. More...
 
void add_events (const config::const_child_itors &cfgs, game_lua_kernel &lk, const std::string &type=std::string())
 
void write_events (config &cfg, bool include_nonserializable=false) const
 
void execute_on_events (const std::string &event_id, event_func_t func)
 
bool is_event_running () const
 
game_events::wml_event_pumppump ()
 
game_events::wmi_managerwml_menu_items ()
 

Private Attributes

const std::unique_ptr< event_handlersevent_handlers_
 
std::set< std::string > unit_wml_ids_
 
const std::unique_ptr< game_events::wml_event_pumppump_
 
game_events::wmi_manager wml_menu_items_
 

Detailed Description

The game event manager loads the scenario configuration object, and ensures that events are handled according to the scenario configuration for its lifetime.

Thus, a manager object should be created when a scenario is played, and destroyed at the end of the scenario. If a second manager object is created before destroying the previous one, the game will crash with an assertion failure.

Definition at line 46 of file manager.hpp.

Member Typedef Documentation

◆ event_func_t

Definition at line 81 of file manager.hpp.

Constructor & Destructor Documentation

◆ manager() [1/2]

game_events::manager::manager ( const manager )
delete

◆ manager() [2/2]

game_events::manager::manager ( )
explicit

Definition at line 120 of file manager.cpp.

◆ ~manager()

game_events::manager::~manager ( )

Definition at line 144 of file manager.cpp.

Member Function Documentation

◆ add_event_handler_from_lua()

pending_event_handler game_events::manager::add_event_handler_from_lua ( const std::string &  name,
const std::string &  id,
bool  repeat = false,
bool  is_menu_item = false 
)

Create an empty event handler.

Expects the caller to finish setting up the event.

Definition at line 101 of file manager.cpp.

Referenced by game_lua_kernel::intf_add_event(), and game_lua_kernel::intf_add_event_simple().

◆ add_event_handler_from_wml()

void game_events::manager::add_event_handler_from_wml ( const config handler,
game_lua_kernel lk,
bool  is_menu_item = false 
)

◆ add_events()

void game_events::manager::add_events ( const config::const_child_itors cfgs,
game_lua_kernel lk,
const std::string &  type = std::string() 
)

Definition at line 148 of file manager.cpp.

References add_event_handler_from_wml(), unit_wml_ids_, and WRN_NG.

Referenced by unit::advance_to(), and unit::init().

◆ execute_on_events()

void game_events::manager::execute_on_events ( const std::string &  event_id,
manager::event_func_t  func 
)

◆ get_event_handler_by_id()

const handler_ptr game_events::manager::get_event_handler_by_id ( const std::string &  id)

Gets an event handler by ID.

Gets an event handler by id.

Definition at line 113 of file manager.cpp.

◆ is_event_running()

bool game_events::manager::is_event_running ( ) const

Definition at line 246 of file manager.cpp.

Referenced by write_events().

◆ operator=()

manager& game_events::manager::operator= ( const manager )
delete

◆ pump()

game_events::wml_event_pump & game_events::manager::pump ( )

◆ read_scenario()

void game_events::manager::read_scenario ( const config scenario_cfg,
game_lua_kernel lk 
)

◆ remove_event_handler()

void game_events::manager::remove_event_handler ( const std::string &  id)

Removes an event handler.

Definition at line 107 of file manager.cpp.

Referenced by game_events::wml_menu_item::finish_handler(), and game_events::wml_menu_item::update_command().

◆ wml_menu_items()

game_events::wmi_manager& game_events::manager::wml_menu_items ( )
inline

Definition at line 88 of file manager.hpp.

References wml_menu_items_.

◆ write_events()

void game_events::manager::write_events ( config cfg,
bool  include_nonserializable = false 
) const

Member Data Documentation

◆ event_handlers_

const std::unique_ptr<event_handlers> game_events::manager::event_handlers_
private

Definition at line 49 of file manager.hpp.

Referenced by execute_on_events(), and write_events().

◆ pump_

const std::unique_ptr<game_events::wml_event_pump> game_events::manager::pump_
private

Definition at line 52 of file manager.hpp.

Referenced by pump().

◆ unit_wml_ids_

std::set<std::string> game_events::manager::unit_wml_ids_
private

Definition at line 50 of file manager.hpp.

Referenced by add_events(), read_scenario(), and write_events().

◆ wml_menu_items_

game_events::wmi_manager game_events::manager::wml_menu_items_
private

Definition at line 53 of file manager.hpp.

Referenced by read_scenario(), wml_menu_items(), and write_events().


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