don't write unset attributes in the scenario editor

This commit is contained in:
gfgtdf 2020-09-12 00:42:53 +02:00
parent ef888206da
commit 6157603ed9
4 changed files with 23 additions and 12 deletions

View file

@ -241,7 +241,7 @@ void context_manager::edit_scenario_dialog()
std::string description = context.get_description();
int turns = context.get_time_manager()->number_of_turns();
int xp_mod = context.get_xp_mod();
int xp_mod = context.get_xp_mod() ? *context.get_xp_mod() : 70;
bool victory = context.victory_defeated();
bool random = context.random_start_time();

View file

@ -72,7 +72,7 @@ map_context::map_context(const editor_map& map, bool pure_map, const config& sch
, scenario_id_()
, scenario_name_()
, scenario_description_()
, xp_mod_(70)
, xp_mod_()
, victory_defeated_(true)
, random_time_(false)
, active_area_(-1)
@ -104,7 +104,7 @@ map_context::map_context(const game_config_view& game_config, const std::string&
, scenario_id_()
, scenario_name_()
, scenario_description_()
, xp_mod_(70)
, xp_mod_()
, victory_defeated_(true)
, random_time_(false)
, active_area_(-1)
@ -328,8 +328,9 @@ void map_context::load_scenario(const game_config_view& game_config)
scenario_name_ = scenario["name"].str();
scenario_description_ = scenario["description"].str();
xp_mod_ = scenario["experience_modifier"].to_int();
if(const config::attribute_value* experience_modifier = scenario.get("experience_modifier")) {
xp_mod_ = experience_modifier->to_int();
}
victory_defeated_ = scenario["victory_when_enemies_defeated"].to_bool(true);
random_time_ = scenario["random_start_time"].to_bool(false);
@ -476,8 +477,12 @@ config map_context::to_config()
scenario["name"] = t_string(scenario_name_);
scenario["description"] = scenario_description_;
scenario["experience_modifier"] = xp_mod_;
scenario["victory_when_enemies_defeated"] = victory_defeated_;
if(xp_mod_) {
scenario["experience_modifier"] = *xp_mod_;
}
if(victory_defeated_) {
scenario["victory_when_enemies_defeated"] = *victory_defeated_;
}
scenario["random_start_time"] = random_time_;
scenario.append(tod_manager_->to_config());

View file

@ -25,6 +25,8 @@
#include "overlay.hpp"
#include "display_context.hpp"
#include <boost/optional.hpp>
#include <vector>
class game_config_view;
@ -312,10 +314,10 @@ public:
const t_string get_default_context_name() const;
int get_xp_mod() const { return xp_mod_; }
boost::optional<int> get_xp_mod() const { return xp_mod_; }
bool random_start_time() const { return random_time_; }
bool victory_defeated() const { return victory_defeated_; }
bool victory_defeated() const { return !victory_defeated_ || *victory_defeated_; }
bool is_embedded() const { return embedded_; }
@ -494,8 +496,9 @@ private:
std::string scenario_id_, scenario_name_, scenario_description_;
int xp_mod_;
bool victory_defeated_, random_time_;
boost::optional<int> xp_mod_;
boost::optional<bool> victory_defeated_;
bool random_time_;
int active_area_;

View file

@ -109,7 +109,10 @@ config tod_manager::to_config() const
config cfg;
cfg["turn_at"] = turn_;
cfg["turns"] = num_turns_;
cfg["current_time"] = currentTime_;
//this 'if' is for the editor.
if(times_.size() != 0) {
cfg["current_time"] = currentTime_;
}
cfg["random_start_time"] = random_tod_;
cfg["it_is_a_new_turn"] = !has_turn_event_fired_;
if (has_cfg_liminal_bonus_)