Skip to content

Commit

Permalink
small create_engine simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf authored and GregoryLundberg committed Nov 30, 2017
1 parent b935b8c commit 56791ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
14 changes: 5 additions & 9 deletions src/game_initialization/create_engine.cpp
Expand Up @@ -230,7 +230,6 @@ create_engine::create_engine(CVideo& v, saved_game& state)
: current_level_type_()
, current_level_index_(0)
, current_era_index_(0)
, current_mod_index_(0)
, level_name_filter_()
, player_count_filter_(1)
, type_map_()
Expand Down Expand Up @@ -519,12 +518,9 @@ level& create_engine::current_level() const
return *type_map_.at(current_level_type_.v).games[current_level_index_];
}

const create_engine::extras_metadata& create_engine::current_extra(const MP_EXTRA extra_type) const
const create_engine::extras_metadata& create_engine::current_era() const
{
const size_t index = (extra_type == ERA) ?
current_era_index_ : current_mod_index_;

return *get_const_extras_by_type(extra_type)[index];
return *get_const_extras_by_type(ERA)[current_era_index_];
}

void create_engine::set_current_level(const size_t index)
Expand Down Expand Up @@ -556,10 +552,10 @@ void create_engine::set_current_era_index(const size_t index, bool force)
dependency_manager_->try_era_by_index(index, force);
}

bool create_engine::toggle_current_mod(bool force)
bool create_engine::toggle_mod(int index, bool force)
{
bool is_active = dependency_manager_->is_modification_active(current_mod_index_);
dependency_manager_->try_modification_by_index(current_mod_index_, !is_active, force);
bool is_active = dependency_manager_->is_modification_active(index);
dependency_manager_->try_modification_by_index(index, !is_active, force);

state_.mp_settings().active_mods = dependency_manager_->get_modifications();

Expand Down
14 changes: 2 additions & 12 deletions src/game_initialization/create_engine.hpp
Expand Up @@ -343,7 +343,7 @@ class create_engine
std::vector<size_t> get_filtered_level_indices(level::TYPE type) const;

level& current_level() const;
const extras_metadata& current_extra(const MP_EXTRA extra_type) const;
const extras_metadata& current_era() const;

void set_current_level_type(const level::TYPE type)
{
Expand All @@ -358,27 +358,18 @@ class create_engine
void set_current_level(const size_t index);

void set_current_era_index(const size_t index, bool force = false);
void set_current_mod_index(const size_t index)
{
current_mod_index_ = index;
}

size_t current_era_index() const
{
return current_era_index_;
}

size_t current_mod_index() const
{
return current_mod_index_;
}

const config& curent_era_cfg() const;

const std::vector<extras_metadata_ptr>& get_const_extras_by_type(const MP_EXTRA extra_type) const;
std::vector<extras_metadata_ptr>& get_extras_by_type(const MP_EXTRA extra_type);

bool toggle_current_mod(bool force = false);
bool toggle_mod(int index, bool force = false);

bool generator_assigned() const;
bool generator_has_settings() const;
Expand Down Expand Up @@ -418,7 +409,6 @@ class create_engine
size_t current_level_index_;

size_t current_era_index_;
size_t current_mod_index_;

std::string level_name_filter_;
int player_count_filter_;
Expand Down
3 changes: 1 addition & 2 deletions src/gui/dialogs/campaign_selection.cpp
Expand Up @@ -358,8 +358,7 @@ void campaign_selection::mod_toggled(window& window)

for(unsigned i = 0; i < mod_states_.size(); i++) {
if(mod_states_[i]) {
engine_.set_current_mod_index(i);
engine_.toggle_current_mod();
engine_.toggle_mod(i);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/gui/dialogs/multiplayer/mp_create_game.cpp
Expand Up @@ -515,8 +515,7 @@ void mp_create_game::on_tab_select(window& window)

void mp_create_game::on_mod_toggle(window& window, const int index)
{
create_engine_.set_current_mod_index(index);
create_engine_.toggle_current_mod();
create_engine_.toggle_mod(index);

sync_with_depcheck(window);

Expand All @@ -527,7 +526,7 @@ void mp_create_game::on_era_select(window& window)
{
create_engine_.set_current_era_index(find_widget<menu_button>(&window, "eras", false).get_value());

find_widget<menu_button>(&window, "eras", false).set_tooltip(create_engine_.current_extra(ng::create_engine::ERA).description);
find_widget<menu_button>(&window, "eras", false).set_tooltip(create_engine_.current_era().description);

sync_with_depcheck(window);

Expand Down Expand Up @@ -812,7 +811,7 @@ void mp_create_game::post_show(window& window)
prefs::set_modifications(create_engine_.active_mods());
prefs::set_level_type(create_engine_.current_level_type().v);
prefs::set_level(create_engine_.current_level().id());
prefs::set_era(create_engine_.current_extra(ng::create_engine::ERA).id);
prefs::set_era(create_engine_.current_era().id);

create_engine_.prepare_for_era_and_mods();

Expand Down

0 comments on commit 56791ee

Please sign in to comment.