Note to all triers: It's not guaranteed that the specified component will be selected (if the user denies to perform dependency resolution, all changes will be reverted). More...
#include <depcheck.hpp>
Classes | |
struct | elem |
represents a component (era, modification or scenario) More... | |
Public Member Functions | |
manager (const game_config_view &gamecfg, bool mp) | |
void | try_era (const std::string &id, bool force=false) |
Tries to set the selected era. More... | |
void | try_scenario (const std::string &id, bool force=false) |
Tries to set the selected scenario. More... | |
void | try_modifications (const std::vector< std::string > &ids, bool force=false) |
Tries to set the enabled modifications. More... | |
void | try_modification_by_id (const std::string &id, bool activate, bool force=false) |
Tries to enable/disable a specific modification. More... | |
void | try_era_by_index (int index, bool force=false) |
Tries to set the selected era. More... | |
void | try_scenario_by_index (int index, bool force=false) |
Tries to set the selected scenario. More... | |
const std::string & | get_era () const |
Returns the selected era. More... | |
const std::string & | get_scenario () const |
Returns the selected scenario. More... | |
const std::vector< std::string > & | get_modifications () const |
Returns the enabled modifications. More... | |
bool | is_modification_active (int index) const |
Tells whether a certain mod is activated. More... | |
bool | is_modification_active (const std::string id) const |
Tells whether a certain mod is activated. More... | |
int | get_era_index () const |
Returns the selected era. More... | |
int | get_scenario_index () const |
Returns the selected scenario. More... | |
void | insert_element (component_type type, const config &data, int index=0) |
Adds a new element to the manager's database. More... | |
Private Member Functions | |
void | save_state () |
saves the current values of era_, scenarios_ and mods_ More... | |
void | revert () |
restores the lastly saved values of era_, scenarios_ and mods_ More... | |
bool | change_scenario (const std::string &id) |
Attempts to change the selected scenario. More... | |
bool | change_era (const std::string &id) |
Attempts to change the selected era. More... | |
bool | change_modifications (const std::vector< std::string > &modifications) |
Attempts to change the selected modifications. More... | |
bool | does_conflict (const elem &elem1, const elem &elem2, bool directonly=false) const |
Decides if two components are conflicting or not. More... | |
bool | does_require (const elem &elem1, const elem &elem2) const |
Decides whether e1 requires e2. More... | |
std::vector< std::string > | get_required (const elem &e) const |
Get the list of modifications required by a certain component. More... | |
std::vector< std::string > | get_required_not_enabled (const elem &e) const |
Get the list of modifications which are required by a certain component, but aren't currently enabled. More... | |
std::vector< std::string > | get_conflicting_enabled (const elem &e) const |
Get the list of modifications which are conflicting a certain component and are currently enabled. More... | |
std::vector< std::string > | get_required_not_installed (const elem &e) const |
Get the list of modifications which are required by a certain component, but currently unavailable on the computer. More... | |
bool | enable_mods_dialog (const std::vector< std::string > &mods, const std::string &requester=_("A component")) |
Display a dialog requesting confirmation for enabling some modifications. More... | |
bool | disable_mods_dialog (const std::vector< std::string > &mods, const std::string &requester=_("A component")) |
Display a dialog requesting confirmation for disabling some modifications. More... | |
std::string | change_era_dialog (const std::vector< std::string > &eras) |
Display a dialog requesting the user to select a new era. More... | |
std::string | change_scenario_dialog (const std::vector< std::string > &scenarios) |
Display a dialog requesting the user to select a new scenario. More... | |
void | failure_dialog (const std::string &msg) |
Shows an error message. More... | |
bool | exists (const elem &e) const |
Decides whether a certain component is installed or not. More... | |
std::string | find_name_for (const elem &e) const |
Look up the name of a given component. More... | |
Private Attributes | |
config | depinfo_ |
holds all required info about the components and their dependencies More... | |
std::string | era_ |
the id of the currently selected era More... | |
std::string | scenario_ |
the id of the currently selected scenario More... | |
std::vector< std::string > | mods_ |
the ids of the currently selected modifications More... | |
std::string | prev_era_ |
used by save_state() and revert() to backup/restore era_ More... | |
std::string | prev_scenario_ |
used by save_state() and revert() to backup/restore scenario_ More... | |
std::vector< std::string > | prev_mods_ |
used by save_state() and revert() to backup/restore mods_ More... | |
Note to all triers: It's not guaranteed that the specified component will be selected (if the user denies to perform dependency resolution, all changes will be reverted).
Consequently, it's essential to check the selected values after calling any trier.
Note to ctor & insert_element: Please note that the ctor collects data for scenario elements from "multiplayer" nodes, while insert_element from "scenario" nodes.
Definition at line 49 of file depcheck.hpp.
ng::depcheck::manager::manager | ( | const game_config_view & | gamecfg, |
bool | mp | ||
) |
Definition at line 61 of file depcheck.cpp.
References config::add_child(), game_config_view::child_range(), DBG_MP, depinfo_, string_enums::enum_base< Definition >::get_enum(), and lg::info().
|
private |
Attempts to change the selected era.
id | the era's id |
Definition at line 581 of file depcheck.cpp.
References _(), change_scenario(), change_scenario_dialog(), config::child_range(), utils::contains(), depinfo_, disable_mods_dialog(), does_conflict(), enable_mods_dialog(), era_, failure_dialog(), find_name_for(), get_conflicting_enabled(), get_required_not_enabled(), get_required_not_installed(), i, id, utils::join(), mods_, wfl::msg(), and scenario_.
Referenced by change_modifications(), change_scenario(), and try_era().
|
private |
Display a dialog requesting the user to select a new era.
eras | the possible options (ids) |
Definition at line 458 of file depcheck.cpp.
References depinfo_, ng::depcheck::ERA, config::find_mandatory_child(), gui2::dialogs::depcheck_select_new::result(), and gui2::dialogs::modal_dialog::show().
Referenced by change_modifications(), and change_scenario().
|
private |
Attempts to change the selected modifications.
modifications | the list of the modifications' ids |
Definition at line 649 of file depcheck.cpp.
References _(), c, change_era(), change_era_dialog(), change_scenario(), change_scenario_dialog(), config::child_range(), utils::contains(), depinfo_, does_conflict(), era_, failure_dialog(), i, ng::depcheck::manager::elem::id, mods_, s, and scenario_.
Referenced by try_modifications().
|
private |
Attempts to change the selected scenario.
id | the scenario's id |
Definition at line 512 of file depcheck.cpp.
References _(), change_era(), change_era_dialog(), config::child_range(), utils::contains(), depinfo_, disable_mods_dialog(), does_conflict(), enable_mods_dialog(), era_, failure_dialog(), find_name_for(), get_conflicting_enabled(), get_required_not_enabled(), get_required_not_installed(), i, id, utils::join(), mods_, wfl::msg(), and scenario_.
Referenced by change_era(), change_modifications(), and try_scenario().
|
private |
Display a dialog requesting the user to select a new scenario.
scenarios | the possible options (ids) |
Definition at line 474 of file depcheck.cpp.
References depinfo_, config::find_mandatory_child(), gui2::dialogs::depcheck_select_new::result(), ng::depcheck::SCENARIO, and gui2::dialogs::modal_dialog::show().
Referenced by change_era(), and change_modifications().
|
private |
Display a dialog requesting confirmation for disabling some modifications.
mods | the list of modifications to be disabled |
requester | the add-on's name which requests the action to be done |
Definition at line 448 of file depcheck.cpp.
References depinfo_, and config::find_mandatory_child().
Referenced by change_era(), and change_scenario().
|
private |
Decides if two components are conflicting or not.
elem1 | the first component |
elem2 | the second component |
directonly | whether the function should ignore any possible conflicts between the components' dependencies. |
Definition at line 221 of file depcheck.cpp.
References utils::contains(), depinfo_, does_require(), exists(), config::find_mandatory_child(), get_required(), config::has_attribute(), ng::depcheck::manager::elem::id, s, utils::split(), and ng::depcheck::manager::elem::type.
Referenced by change_era(), change_modifications(), change_scenario(), and get_conflicting_enabled().
Decides whether e1 requires e2.
elem1 | a component; by definition, passing a modification here makes no sense |
elem2 | another component; by definition, passing anything else than a modification here makes no sense |
Definition at line 320 of file depcheck.cpp.
References utils::contains(), data, depinfo_, config::find_mandatory_child(), ng::depcheck::manager::elem::id, utils::split(), and ng::depcheck::manager::elem::type.
Referenced by does_conflict().
|
private |
Display a dialog requesting confirmation for enabling some modifications.
mods | the list of modifications to be enabled |
requester | the add-on's name which requests the action to be done |
Definition at line 438 of file depcheck.cpp.
References depinfo_, and config::find_mandatory_child().
Referenced by change_era(), and change_scenario().
|
private |
Decides whether a certain component is installed or not.
e | the component |
Definition at line 145 of file depcheck.cpp.
References config::child_range(), depinfo_, and e.
Referenced by does_conflict(), and get_required_not_installed().
|
private |
Shows an error message.
msg | the message to be displayed |
Definition at line 489 of file depcheck.cpp.
References _(), wfl::msg(), and gui2::show_message().
Referenced by change_era(), change_modifications(), and change_scenario().
|
private |
Look up the name of a given component.
e | the component |
Definition at line 156 of file depcheck.cpp.
References depinfo_, e, and config::find_mandatory_child().
Referenced by change_era(), and change_scenario().
|
private |
Get the list of modifications which are conflicting a certain component and are currently enabled.
e | the component |
Definition at line 208 of file depcheck.cpp.
References does_conflict(), e, and mods_.
Referenced by change_era(), and change_scenario().
|
inline |
Returns the selected era.
Definition at line 109 of file depcheck.hpp.
References era_.
int ng::depcheck::manager::get_era_index | ( | ) | const |
Returns the selected era.
Definition at line 398 of file depcheck.cpp.
References config::child_range(), depinfo_, era_, and i.
Referenced by gui2::dialogs::mp_create_game::sync_with_depcheck().
|
inline |
Returns the enabled modifications.
Definition at line 123 of file depcheck.hpp.
References mods_.
Referenced by gui2::dialogs::mp_create_game::sync_with_depcheck().
|
private |
Get the list of modifications required by a certain component.
e | the component |
Definition at line 177 of file depcheck.cpp.
References data, depinfo_, e, config::find_mandatory_child(), and utils::split().
Referenced by does_conflict(), get_required_not_enabled(), and get_required_not_installed().
|
private |
Get the list of modifications which are required by a certain component, but aren't currently enabled.
e | the component |
Definition at line 194 of file depcheck.cpp.
References utils::contains(), e, get_required(), and mods_.
Referenced by change_era(), and change_scenario().
|
private |
Get the list of modifications which are required by a certain component, but currently unavailable on the computer.
e | the component |
Definition at line 162 of file depcheck.cpp.
References e, exists(), and get_required().
Referenced by change_era(), and change_scenario().
|
inline |
Returns the selected scenario.
Definition at line 116 of file depcheck.hpp.
References scenario_.
Referenced by gui2::dialogs::mp_create_game::sync_with_depcheck().
int ng::depcheck::manager::get_scenario_index | ( | ) | const |
Returns the selected scenario.
Definition at line 412 of file depcheck.cpp.
References config::child_range(), depinfo_, i, and scenario_.
void ng::depcheck::manager::insert_element | ( | component_type | type, |
const config & | data, | ||
int | index = 0 |
||
) |
Adds a new element to the manager's database.
type | the type of the element |
data | a config object containing the dependency info for the element |
index | where to insert the element |
Definition at line 494 of file depcheck.cpp.
References config::add_child_at(), data, depinfo_, ng::depcheck::ERA, utf8::index(), ng::depcheck::MODIFICATION, and ng::depcheck::SCENARIO.
bool ng::depcheck::manager::is_modification_active | ( | const std::string | id | ) | const |
Tells whether a certain mod is activated.
id | the string id of the mod |
Definition at line 433 of file depcheck.cpp.
References mods_.
bool ng::depcheck::manager::is_modification_active | ( | int | index | ) | const |
Tells whether a certain mod is activated.
index | the index of the mod |
Definition at line 427 of file depcheck.cpp.
References depinfo_, utf8::index(), config::mandatory_child(), and mods_.
Referenced by gui2::dialogs::mp_create_game::on_mod_toggle().
|
private |
restores the lastly saved values of era_, scenarios_ and mods_
Definition at line 137 of file depcheck.cpp.
References DBG_MP, era_, mods_, prev_era_, prev_mods_, prev_scenario_, and scenario_.
Referenced by try_era(), try_modifications(), and try_scenario().
|
private |
saves the current values of era_, scenarios_ and mods_
Definition at line 129 of file depcheck.cpp.
References DBG_MP, era_, mods_, prev_era_, prev_mods_, prev_scenario_, and scenario_.
Referenced by try_era(), try_modifications(), and try_scenario().
void ng::depcheck::manager::try_era | ( | const std::string & | id, |
bool | force = false |
||
) |
Tries to set the selected era.
id | the id of the era |
force | whether to skip dependency check |
Definition at line 337 of file depcheck.cpp.
References change_era(), era_, id, revert(), and save_state().
Referenced by try_era_by_index().
void ng::depcheck::manager::try_era_by_index | ( | int | index, |
bool | force = false |
||
) |
Tries to set the selected era.
index | the index of the era |
force | whether to skip dependency check |
Definition at line 388 of file depcheck.cpp.
References depinfo_, utf8::index(), config::mandatory_child(), and try_era().
void ng::depcheck::manager::try_modification_by_id | ( | const std::string & | id, |
bool | activate, | ||
bool | force = false |
||
) |
Tries to enable/disable a specific modification.
id | the id of the modification |
activate | activate or deactivate |
force | whether to skip dependency check |
Definition at line 370 of file depcheck.cpp.
References mods_, and try_modifications().
void ng::depcheck::manager::try_modifications | ( | const std::vector< std::string > & | ids, |
bool | force = false |
||
) |
Tries to set the enabled modifications.
ids | the ids of the modifications |
force | whether to skip dependency check |
Definition at line 359 of file depcheck.cpp.
References change_modifications(), mods_, revert(), and save_state().
Referenced by try_modification_by_id().
void ng::depcheck::manager::try_scenario | ( | const std::string & | id, |
bool | force = false |
||
) |
Tries to set the selected scenario.
id | the id of the scenario |
force | whether to skip dependency check |
Definition at line 348 of file depcheck.cpp.
References change_scenario(), id, revert(), save_state(), and scenario_.
Referenced by try_scenario_by_index().
void ng::depcheck::manager::try_scenario_by_index | ( | int | index, |
bool | force = false |
||
) |
Tries to set the selected scenario.
index | the index of the scenario |
force | whether to skip dependency check |
Definition at line 393 of file depcheck.cpp.
References depinfo_, utf8::index(), config::mandatory_child(), and try_scenario().
|
private |
holds all required info about the components and their dependencies
Definition at line 186 of file depcheck.hpp.
Referenced by change_era(), change_era_dialog(), change_modifications(), change_scenario(), change_scenario_dialog(), disable_mods_dialog(), does_conflict(), does_require(), enable_mods_dialog(), exists(), find_name_for(), get_era_index(), get_required(), get_scenario_index(), insert_element(), is_modification_active(), manager(), try_era_by_index(), and try_scenario_by_index().
|
private |
the id of the currently selected era
Definition at line 189 of file depcheck.hpp.
Referenced by change_era(), change_modifications(), change_scenario(), get_era(), get_era_index(), revert(), save_state(), and try_era().
|
private |
the ids of the currently selected modifications
Definition at line 195 of file depcheck.hpp.
Referenced by change_era(), change_modifications(), change_scenario(), get_conflicting_enabled(), get_modifications(), get_required_not_enabled(), is_modification_active(), revert(), save_state(), try_modification_by_id(), and try_modifications().
|
private |
used by save_state() and revert() to backup/restore era_
Definition at line 198 of file depcheck.hpp.
Referenced by revert(), and save_state().
|
private |
used by save_state() and revert() to backup/restore mods_
Definition at line 204 of file depcheck.hpp.
Referenced by revert(), and save_state().
|
private |
used by save_state() and revert() to backup/restore scenario_
Definition at line 201 of file depcheck.hpp.
Referenced by revert(), and save_state().
|
private |
the id of the currently selected scenario
Definition at line 192 of file depcheck.hpp.
Referenced by change_era(), change_modifications(), change_scenario(), get_scenario(), get_scenario_index(), revert(), save_state(), and try_scenario().