mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-21 20:44:24 +00:00
Include non-serializable events in the gamestate inspector
Since they're non-serializable, the code can't be shown, but the fact that unspecified Lua code is present will be shown.
This commit is contained in:
parent
5a184bbb40
commit
865eface07
@ -122,7 +122,7 @@ bool event_handler::filter_event(const queued_event& ev) const
|
||||
});
|
||||
}
|
||||
|
||||
void event_handler::write_config(config &cfg) const
|
||||
void event_handler::write_config(config &cfg, bool include_nonserializable) const
|
||||
{
|
||||
if(disabled_) {
|
||||
WRN_NG << "Tried to serialize disabled event, skipping";
|
||||
@ -131,24 +131,33 @@ void event_handler::write_config(config &cfg) const
|
||||
static const char* log_append_preload = " - this will not break saves since it was registered during or before preload\n";
|
||||
static const char* log_append_postload = " - this will break saves because it was registered after preload\n";
|
||||
if(is_lua_) {
|
||||
static const char* log = "Skipping serialization of an event with action bound to Lua code";
|
||||
if(has_preloaded_){
|
||||
WRN_NG << log << log_append_postload;
|
||||
lg::log_to_chat() << log << log_append_postload;
|
||||
if(include_nonserializable) {
|
||||
cfg["nonserializable"] = true;
|
||||
cfg.add_child("lua")["code"] = "<function>";
|
||||
} else {
|
||||
LOG_NG << log << log_append_preload;
|
||||
static const char* log = "Skipping serialization of an event with action bound to Lua code";
|
||||
if(has_preloaded_){
|
||||
WRN_NG << log << log_append_postload;
|
||||
lg::log_to_chat() << log << log_append_postload;
|
||||
} else {
|
||||
LOG_NG << log << log_append_preload;
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(!std::all_of(filters_.begin(), filters_.end(), std::mem_fn(&event_filter::can_serialize))) {
|
||||
static const char* log = "Skipping serialization of an event with filter bound to Lua code";
|
||||
if(has_preloaded_) {
|
||||
WRN_NG << log << log_append_postload;
|
||||
lg::log_to_chat() << log << log_append_postload;
|
||||
if(include_nonserializable) {
|
||||
cfg["nonserializable"] = true;
|
||||
} else {
|
||||
LOG_NG << log << log_append_preload;
|
||||
static const char* log = "Skipping serialization of an event with filter bound to Lua code";
|
||||
if(has_preloaded_) {
|
||||
WRN_NG << log << log_append_postload;
|
||||
lg::log_to_chat() << log << log_append_postload;
|
||||
} else {
|
||||
LOG_NG << log << log_append_preload;
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(!types_.empty()) cfg["name"] = types_;
|
||||
if(!id_.empty()) cfg["id"] = id_;
|
||||
|
@ -101,7 +101,10 @@ public:
|
||||
return !first_time_only_;
|
||||
}
|
||||
|
||||
void write_config(config& cfg) const;
|
||||
// Normally non-serializable events are skipped when serializing (with a warning).
|
||||
// If include_nonserializable is true, the game attempts to serialize them anyway.
|
||||
// This will produce output that kind of looks like the event but would not deserialize to the same event.
|
||||
void write_config(config& cfg, bool include_nonserializable = false) const;
|
||||
|
||||
void set_repeatable(bool repeat = true)
|
||||
{
|
||||
|
@ -165,7 +165,7 @@ void manager::add_events(const config::const_child_itors& cfgs, game_lua_kernel&
|
||||
}
|
||||
}
|
||||
|
||||
void manager::write_events(config& cfg) const
|
||||
void manager::write_events(config& cfg, bool include_nonserializable) const
|
||||
{
|
||||
for(const handler_ptr& eh : event_handlers_->get_active()) {
|
||||
if(!eh || eh->is_menu_item()) {
|
||||
@ -184,7 +184,7 @@ void manager::write_events(config& cfg) const
|
||||
assert(!eh->disabled());
|
||||
}
|
||||
|
||||
eh->write_config(cfg.add_child("event"));
|
||||
eh->write_config(cfg.add_child("event"), include_nonserializable);
|
||||
}
|
||||
|
||||
cfg["unit_wml_ids"] = utils::join(unit_wml_ids_);
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
|
||||
void add_events(const config::const_child_itors& cfgs, game_lua_kernel& lk, const std::string& type = std::string());
|
||||
|
||||
void write_events(config& cfg) const;
|
||||
void write_events(config& cfg, bool include_nonserializable=false) const;
|
||||
|
||||
using event_func_t = std::function<void(game_events::manager&, handler_ptr&)>;
|
||||
void execute_on_events(const std::string& event_id, event_func_t func);
|
||||
|
@ -490,7 +490,7 @@ const display_context& single_mode_controller::dc() const {
|
||||
event_mode_controller::event_mode_controller(gamestate_inspector::controller& c)
|
||||
: single_mode_controller(c)
|
||||
{
|
||||
single_mode_controller::events().write_events(events);
|
||||
single_mode_controller::events().write_events(events, true);
|
||||
}
|
||||
|
||||
void variable_mode_controller::show_list(tree_view_node& node)
|
||||
|
@ -3701,6 +3701,9 @@ struct lua_event_filter : public game_events::event_filter
|
||||
{
|
||||
lk.clear_wml_event(ref_);
|
||||
}
|
||||
void serialize(config& cfg) const override {
|
||||
cfg.add_child("filter_lua")["code"] = "<function>";
|
||||
}
|
||||
private:
|
||||
game_lua_kernel& lk;
|
||||
int ref_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user