The Battle for Wesnoth  1.19.0-dev
Public Member Functions | Private Attributes | List of all members
game_events::event_handler Class Reference

#include <handlers.hpp>

Public Member Functions

 event_handler (const std::string &types, const std::string &id="")
 
std::vector< std::string > names (const variable_set *vars) const
 
const std::string & names_raw () const
 
bool disabled () const
 
bool is_menu_item () const
 
void disable ()
 Flag this handler as disabled. More...
 
void handle_event (const queued_event &event_info, game_lua_kernel &lk)
 Handles the queued event, according to our WML instructions. More...
 
bool filter_event (const queued_event &event_info) const
 
const configarguments () const
 
const std::string & id () const
 
const double & priority () const
 
bool empty () const
 
bool repeatable () const
 
void write_config (config &cfg, bool include_nonserializable=false) const
 
void set_repeatable (bool repeat=true)
 
void set_priority (double priority)
 
void set_menu_item (bool imi)
 
void set_arguments (const config &cfg)
 
void read_filters (const config &cfg)
 
void add_filter (std::unique_ptr< event_filter > &&filter)
 
void register_wml_event (game_lua_kernel &lk)
 
void set_event_ref (int idx, bool has_preloaded)
 

Private Attributes

bool first_time_only_
 
bool is_menu_item_
 
bool disabled_
 
bool is_lua_
 Tracks whether the event was registered from the Lua API. More...
 
bool has_preloaded_
 Tracks whether the event was registered before or after the Lua preload event fired. More...
 
int event_ref_
 
double priority_
 
config args_
 
std::vector< std::shared_ptr< event_filter > > filters_
 
std::string id_
 
std::string types_
 

Detailed Description

Definition at line 53 of file handlers.hpp.

Constructor & Destructor Documentation

◆ event_handler()

game_events::event_handler::event_handler ( const std::string &  types,
const std::string &  id = "" 
)

Definition at line 55 of file handlers.cpp.

Member Function Documentation

◆ add_filter()

void game_events::event_handler::add_filter ( std::unique_ptr< event_filter > &&  filter)

Definition at line 373 of file handlers.cpp.

References filters_.

Referenced by read_filters().

◆ arguments()

const config& game_events::event_handler::arguments ( ) const
inline

Definition at line 87 of file handlers.hpp.

References args_.

◆ disable()

void game_events::event_handler::disable ( )

Flag this handler as disabled.

Definition at line 95 of file handlers.cpp.

References disabled_.

Referenced by handle_event().

◆ disabled()

bool game_events::event_handler::disabled ( ) const
inline

Definition at line 64 of file handlers.hpp.

References disabled_.

◆ empty()

bool game_events::event_handler::empty ( ) const

Definition at line 90 of file handlers.cpp.

References args_, and config::empty().

◆ filter_event()

bool game_events::event_handler::filter_event ( const queued_event event_info) const

Definition at line 119 of file handlers.cpp.

References filters_.

◆ handle_event()

void game_events::event_handler::handle_event ( const queued_event event_info,
game_lua_kernel lk 
)

Handles the queued event, according to our WML instructions.

Parameters
[in]event_infoInformation about the event that needs handling.
[in]lkThe lua kernel to run the WML command.

Definition at line 101 of file handlers.cpp.

References args_, sound::commit_music_changes(), DBG_NG, disable(), disabled_, event_ref_, first_time_only_, id_, is_menu_item_, and game_lua_kernel::run_wml_event().

◆ id()

const std::string& game_events::event_handler::id ( ) const
inline

Definition at line 92 of file handlers.hpp.

References id_.

◆ is_menu_item()

bool game_events::event_handler::is_menu_item ( ) const
inline

Definition at line 69 of file handlers.hpp.

References is_menu_item_.

◆ names()

std::vector< std::string > game_events::event_handler::names ( const variable_set vars) const

◆ names_raw()

const std::string& game_events::event_handler::names_raw ( ) const
inline

Definition at line 59 of file handlers.hpp.

References types_.

◆ priority()

const double& game_events::event_handler::priority ( ) const
inline

Definition at line 97 of file handlers.hpp.

References priority_.

Referenced by set_priority().

◆ read_filters()

void game_events::event_handler::read_filters ( const config cfg)

◆ register_wml_event()

void game_events::event_handler::register_wml_event ( game_lua_kernel lk)

Definition at line 378 of file handlers.cpp.

References event_ref_, and game_lua_kernel::save_wml_event().

◆ repeatable()

bool game_events::event_handler::repeatable ( ) const
inline

Definition at line 104 of file handlers.hpp.

References first_time_only_.

◆ set_arguments()

void game_events::event_handler::set_arguments ( const config cfg)
inline

Definition at line 128 of file handlers.hpp.

References args_.

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

◆ set_event_ref()

void game_events::event_handler::set_event_ref ( int  idx,
bool  has_preloaded 
)

Definition at line 383 of file handlers.cpp.

References event_ref_, has_preloaded_, and is_lua_.

◆ set_menu_item()

void game_events::event_handler::set_menu_item ( bool  imi)
inline

Definition at line 123 of file handlers.hpp.

References is_menu_item_.

◆ set_priority()

void game_events::event_handler::set_priority ( double  priority)
inline

Definition at line 119 of file handlers.hpp.

References priority(), and priority_.

◆ set_repeatable()

void game_events::event_handler::set_repeatable ( bool  repeat = true)
inline

Definition at line 114 of file handlers.hpp.

References first_time_only_.

◆ write_config()

void game_events::event_handler::write_config ( config cfg,
bool  include_nonserializable = false 
) const

Member Data Documentation

◆ args_

config game_events::event_handler::args_
private

Definition at line 162 of file handlers.hpp.

Referenced by arguments(), empty(), handle_event(), set_arguments(), and write_config().

◆ disabled_

bool game_events::event_handler::disabled_
private

Definition at line 142 of file handlers.hpp.

Referenced by disable(), disabled(), handle_event(), and write_config().

◆ event_ref_

int game_events::event_handler::event_ref_
private

Definition at line 160 of file handlers.hpp.

Referenced by handle_event(), register_wml_event(), and set_event_ref().

◆ filters_

std::vector<std::shared_ptr<event_filter> > game_events::event_handler::filters_
private

Definition at line 163 of file handlers.hpp.

Referenced by add_filter(), filter_event(), and write_config().

◆ first_time_only_

bool game_events::event_handler::first_time_only_
private

Definition at line 140 of file handlers.hpp.

Referenced by handle_event(), repeatable(), set_repeatable(), and write_config().

◆ has_preloaded_

bool game_events::event_handler::has_preloaded_
private

Tracks whether the event was registered before or after the Lua preload event fired.

This allows a warning to be issued in cases that will break saved games.

Rationale: Events where the filter or action is a Lua function cannot be serialized. Therefore, if a saved game relies on it being serialized, it will fail. Events registered during or before preload do not need to be serialized, because when a saved game is loaded, the preload event re-triggers and re-registers the event. This is actually a common use-case for the Lua events API. So, this flag allows avoiding false positives in the warning message.

Definition at line 159 of file handlers.hpp.

Referenced by set_event_ref(), and write_config().

◆ id_

std::string game_events::event_handler::id_
private

Definition at line 164 of file handlers.hpp.

Referenced by handle_event(), id(), and write_config().

◆ is_lua_

bool game_events::event_handler::is_lua_
private

Tracks whether the event was registered from the Lua API.

This allows a warning to be issued in cases that will break saved games.

Definition at line 147 of file handlers.hpp.

Referenced by set_event_ref(), and write_config().

◆ is_menu_item_

bool game_events::event_handler::is_menu_item_
private

Definition at line 141 of file handlers.hpp.

Referenced by handle_event(), is_menu_item(), and set_menu_item().

◆ priority_

double game_events::event_handler::priority_
private

Definition at line 161 of file handlers.hpp.

Referenced by priority(), set_priority(), and write_config().

◆ types_

std::string game_events::event_handler::types_
private

Definition at line 164 of file handlers.hpp.

Referenced by names(), names_raw(), and write_config().


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