#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 config & | arguments () 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_ |
Definition at line 52 of file handlers.hpp.
game_events::event_handler::event_handler | ( | const std::string & | types, |
const std::string & | id = "" |
||
) |
Definition at line 55 of file handlers.cpp.
void game_events::event_handler::add_filter | ( | std::unique_ptr< event_filter > && | filter | ) |
|
inline |
Definition at line 86 of file handlers.hpp.
References args_.
void game_events::event_handler::disable | ( | ) |
Flag this handler as disabled.
Definition at line 100 of file handlers.cpp.
References disabled_.
Referenced by handle_event().
|
inline |
Definition at line 63 of file handlers.hpp.
References disabled_.
bool game_events::event_handler::empty | ( | ) | const |
Definition at line 95 of file handlers.cpp.
References args_, and config::empty().
bool game_events::event_handler::filter_event | ( | const queued_event & | event_info | ) | const |
Definition at line 124 of file handlers.cpp.
References filters_.
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.
[in] | event_info | Information about the event that needs handling. |
[in] | lk | The lua kernel to run the WML command. |
Definition at line 106 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().
|
inline |
Definition at line 91 of file handlers.hpp.
References id_.
|
inline |
Definition at line 68 of file handlers.hpp.
References is_menu_item_.
std::vector< std::string > game_events::event_handler::names | ( | const variable_set * | vars | ) | const |
Definition at line 69 of file handlers.cpp.
References utils::interpolate_variables_into_string(), utils::might_contain_variables(), utils::split(), game_events::event_handlers::standardize_name(), and types_.
|
inline |
Definition at line 58 of file handlers.hpp.
References types_.
|
inline |
void game_events::event_handler::read_filters | ( | const config & | cfg | ) |
Definition at line 363 of file handlers.cpp.
References add_filter(), config::all_children_view(), vconfig::empty_vconfig(), config::has_attribute(), and game_events::make_filter().
void game_events::event_handler::register_wml_event | ( | game_lua_kernel & | lk | ) |
Definition at line 383 of file handlers.cpp.
References event_ref_, and game_lua_kernel::save_wml_event().
|
inline |
Definition at line 103 of file handlers.hpp.
References first_time_only_.
|
inline |
Definition at line 127 of file handlers.hpp.
References args_.
Referenced by game_lua_kernel::intf_add_event(), and game_lua_kernel::intf_add_event_simple().
void game_events::event_handler::set_event_ref | ( | int | idx, |
bool | has_preloaded | ||
) |
Definition at line 388 of file handlers.cpp.
References event_ref_, has_preloaded_, and is_lua_.
|
inline |
Definition at line 122 of file handlers.hpp.
References is_menu_item_.
|
inline |
Definition at line 118 of file handlers.hpp.
References priority(), and priority_.
|
inline |
Definition at line 113 of file handlers.hpp.
References first_time_only_.
void game_events::event_handler::write_config | ( | config & | cfg, |
bool | include_nonserializable = false |
||
) | const |
Definition at line 131 of file handlers.cpp.
References config::add_child(), config::append(), args_, game_events::event_filter::can_serialize(), disabled_, filters_, first_time_only_, has_preloaded_, id_, is_lua_, LOG_NG, lg::log_to_chat(), priority_, types_, and WRN_NG.
|
private |
Definition at line 161 of file handlers.hpp.
Referenced by arguments(), empty(), handle_event(), set_arguments(), and write_config().
|
private |
Definition at line 141 of file handlers.hpp.
Referenced by disable(), disabled(), handle_event(), and write_config().
|
private |
Definition at line 159 of file handlers.hpp.
Referenced by handle_event(), register_wml_event(), and set_event_ref().
|
private |
Definition at line 162 of file handlers.hpp.
Referenced by add_filter(), filter_event(), and write_config().
|
private |
Definition at line 139 of file handlers.hpp.
Referenced by handle_event(), repeatable(), set_repeatable(), and write_config().
|
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 158 of file handlers.hpp.
Referenced by set_event_ref(), and write_config().
|
private |
Definition at line 163 of file handlers.hpp.
Referenced by handle_event(), id(), and write_config().
|
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 146 of file handlers.hpp.
Referenced by set_event_ref(), and write_config().
|
private |
Definition at line 140 of file handlers.hpp.
Referenced by handle_event(), is_menu_item(), and set_menu_item().
|
private |
Definition at line 160 of file handlers.hpp.
Referenced by priority(), set_priority(), and write_config().
|
private |
Definition at line 163 of file handlers.hpp.
Referenced by names(), names_raw(), and write_config().