Campaign Difficulty: split constructor code into an out-of-class function
This allows other areas of the code to cleanly parse the legacy difficulties format.
This commit is contained in:
parent
8c68d2a253
commit
312a80e55e
2 changed files with 25 additions and 11 deletions
|
@ -72,23 +72,19 @@ namespace gui2
|
|||
|
||||
REGISTER_DIALOG(campaign_difficulty)
|
||||
|
||||
tcampaign_difficulty::tcampaign_difficulty(
|
||||
const config& campaign)
|
||||
: difficulties_()
|
||||
, campaign_id_(campaign["id"])
|
||||
, selected_difficulty_()
|
||||
config generate_difficulty_config(const config& source)
|
||||
{
|
||||
set_restore(true);
|
||||
config result;
|
||||
|
||||
// Populate local config with difficulty children
|
||||
difficulties_.append_children(campaign, "difficulty");
|
||||
result.append_children(source, "difficulty");
|
||||
|
||||
// Convert legacy format to new-style config if latter not present
|
||||
if(difficulties_.empty()) {
|
||||
if(result.empty()) {
|
||||
WRN_WML << "[campaign] difficulties,difficulty_descriptions= is deprecated. Use [difficulty] instead" << std::endl;
|
||||
|
||||
std::vector<std::string> difficulty_list = utils::split(campaign["difficulties"]);
|
||||
std::vector<std::string> difficulty_opts = utils::split(campaign["difficulty_descriptions"], ';');
|
||||
std::vector<std::string> difficulty_list = utils::split(source["difficulties"]);
|
||||
std::vector<std::string> difficulty_opts = utils::split(source["difficulty_descriptions"], ';');
|
||||
|
||||
if(difficulty_opts.size() != difficulty_list.size()) {
|
||||
difficulty_opts = difficulty_list;
|
||||
|
@ -106,9 +102,21 @@ tcampaign_difficulty::tcampaign_difficulty(
|
|||
temp["default"] = parsed.is_default();
|
||||
temp["old_markup"] = true; // To prevent double parentheses in the dialog
|
||||
|
||||
difficulties_.add_child("difficulty", temp);
|
||||
result.add_child("difficulty", temp);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
tcampaign_difficulty::tcampaign_difficulty(const config& campaign)
|
||||
: difficulties_()
|
||||
, campaign_id_(campaign["id"])
|
||||
, selected_difficulty_()
|
||||
{
|
||||
set_restore(true);
|
||||
|
||||
difficulties_ = generate_difficulty_config(campaign);
|
||||
}
|
||||
|
||||
void tcampaign_difficulty::pre_show(twindow& window)
|
||||
|
|
|
@ -23,6 +23,12 @@
|
|||
namespace gui2
|
||||
{
|
||||
|
||||
/**
|
||||
* Helper function to convert old difficulty markup. Declared outside class to allow other
|
||||
* classes to make use of it.
|
||||
*/
|
||||
config generate_difficulty_config(const config& source);
|
||||
|
||||
class tcampaign_difficulty : public tdialog
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Reference in a new issue