Skip to content

Commit

Permalink
Revert "Save custom options data in a more concise way"
Browse files Browse the repository at this point in the history
This reverts commit e3db7cc. Turns out the
id = value syntax did not work for options in an array since '.' is not a
valid config key name.
  • Loading branch information
Vultraz committed May 15, 2018
1 parent 2d9e02c commit 1097bad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/gui/dialogs/multiplayer/mp_options_helper.cpp
Expand Up @@ -41,15 +41,9 @@ mp_options_helper::mp_options_helper(window& window, ng::create_engine& create_e
, options_data_()
{
for(const auto& c : preferences::options().all_children_range()) {
// Parse old [option] tag range syntax.
for(const auto& saved_option : c.cfg.child_range("option")) {
options_data_[c.cfg["id"]][saved_option["id"]] = saved_option["value"];
}

// Parse new [options] id = value syntax.
for(const auto& saved_option : c.cfg.child_or_empty("options").attribute_range()) {
options_data_[c.cfg["id"]][saved_option.first] = saved_option.second;
}
}

update_all_options();
Expand Down Expand Up @@ -331,8 +325,14 @@ config mp_options_helper::get_options_config()
for(const auto& source : visible_options_) {
config& mod = options.add_child(source.level_type);
mod["id"] = source.id;

#if 0
// TODO: enable this as soon as we drop the old mp configure screen.
mod.add_child("options", options_data_[source.id]);
#else
for(const auto& option : options_data_[source.id].attribute_range()) {
mod.add_child("option", config {"id", option.first, "value", option.second});
}
#endif
}

return options;
Expand Down
10 changes: 0 additions & 10 deletions src/saved_game.cpp
Expand Up @@ -390,23 +390,13 @@ void saved_game::expand_mp_options()

for(modevents_entry& mod : mods) {
if(const config& cfg = this->mp_settings().options.find_child(mod.type, "id", mod.id)) {
// Parse old [option] tag range syntax.
for(const config& option : cfg.child_range("option")) {
try {
variable_access_create(option["id"], variables).as_scalar() = option["value"];
} catch(const invalid_variablename_exception&) {
ERR_NG << "variable " << option["id"] << "cannot be set to " << option["value"] << std::endl;
}
}

// Parse new [options] id = value syntax.
for(const auto& option : cfg.child_or_empty("options").attribute_range()) {
try {
variable_access_create(option.first, variables).as_scalar() = option.second;
} catch(const invalid_variablename_exception&) {
ERR_NG << "variable " << option.first << "cannot be set to " << option.second << std::endl;
}
}
} else {
LOG_NG << "Couldn't find [" << mod.type << "] with id=" << mod.id << " for [option]s" << std::endl;
}
Expand Down

0 comments on commit 1097bad

Please sign in to comment.