From 72249b1bb3530a50b89359aa8bb37708651fd25f Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Wed, 22 Jun 2022 09:31:55 -0400 Subject: [PATCH] Fix non-serializable events being serialized as an empty [event] tag --- src/game_events/manager.cpp | 6 +++++- src/game_events/manager.hpp | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/game_events/manager.cpp b/src/game_events/manager.cpp index 51c6d2df35e..43af152825a 100644 --- a/src/game_events/manager.cpp +++ b/src/game_events/manager.cpp @@ -184,7 +184,11 @@ void manager::write_events(config& cfg, bool include_nonserializable) const assert(!eh->disabled()); } - eh->write_config(cfg.add_child("event"), include_nonserializable); + config event_cfg; + eh->write_config(event_cfg, include_nonserializable); + if(!event_cfg.empty()) { + cfg.add_child("event", std::move(event_cfg)); + } } cfg["unit_wml_ids"] = utils::join(unit_wml_ids_); diff --git a/src/game_events/manager.hpp b/src/game_events/manager.hpp index a1540adaa6d..2ece9b91946 100644 --- a/src/game_events/manager.hpp +++ b/src/game_events/manager.hpp @@ -73,6 +73,9 @@ public: void add_events(const config::const_child_itors& cfgs, game_lua_kernel& lk, const std::string& type = std::string()); + // 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_events(config& cfg, bool include_nonserializable=false) const; using event_func_t = std::function;