Skip to content

Commit

Permalink
Create Engine: added is_campaign helper to simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Feb 1, 2018
1 parent 30172c8 commit b888713
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/game_initialization/create_engine.cpp
Expand Up @@ -357,7 +357,7 @@ bool create_engine::current_level_has_side_data()
// however, leave open the possibility of scenarios that require preprocessing before their
// side data is accessible, but that's an unlikely occurrence.
//
if(current_level_type_ == level::TYPE::CAMPAIGN || current_level_type_ == level::TYPE::SP_CAMPAIGN) {
if(is_campaign()) {
return true;
}

Expand Down Expand Up @@ -774,7 +774,7 @@ void create_engine::init_extras(const MP_EXTRA extra_type)
new_extras_metadata->description = extra["description"].str();
new_extras_metadata->cfg = &extra;

extras.push_back(std::move(new_extras_metadata));
extras.push_back(std::move(new_extras_metadata));
}
else {
//TODO: use a more visible error message.
Expand Down
6 changes: 6 additions & 0 deletions src/game_initialization/create_engine.hpp
Expand Up @@ -354,6 +354,12 @@ class create_engine
return current_level_type_;
}

/** Wrapper to simplify the is-type-campaign-or-sp-campaign check. */
bool is_campaign() const
{
return current_level_type_ == level::TYPE::CAMPAIGN || current_level_type_ == level::TYPE::SP_CAMPAIGN;
}

void set_current_level(const size_t index);

void set_current_era_index(const size_t index, bool force = false);
Expand Down
4 changes: 1 addition & 3 deletions src/gui/dialogs/multiplayer/mp_create_game.cpp
Expand Up @@ -826,9 +826,7 @@ bool mp_create_game::dialog_exit_hook(window& /*window*/)
return false;
}

if(create_engine_.current_level_type() != ng::level::TYPE::CAMPAIGN &&
create_engine_.current_level_type() != ng::level::TYPE::SP_CAMPAIGN
) {
if(!create_engine_.is_campaign()) {
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions src/gui/dialogs/multiplayer/mp_options_helper.cpp
Expand Up @@ -67,10 +67,9 @@ void mp_options_helper::update_all_options()

void mp_options_helper::update_game_options()
{
const ng::level::TYPE current_type = create_engine_.current_level_type();
std::string type;

if(current_type == ng::level::TYPE::CAMPAIGN || current_type == ng::level::TYPE::SP_CAMPAIGN) {
if(create_engine_.is_campaign()) {
type = "campaign";
} else {
type = "multiplayer";
Expand Down

0 comments on commit b888713

Please sign in to comment.