The Battle for Wesnoth  1.19.7+dev
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ng::depcheck::manager Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ manager()

ng::depcheck::manager::manager ( const game_config_view gamecfg,
bool  mp 
)

Member Function Documentation

◆ change_era()

bool ng::depcheck::manager::change_era ( const std::string &  id)
private

◆ change_era_dialog()

std::string ng::depcheck::manager::change_era_dialog ( const std::vector< std::string > &  eras)
private

Display a dialog requesting the user to select a new era.

Parameters
erasthe possible options (ids)
Returns
the selected era's id or empty string if the user refused to select any

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().

◆ change_modifications()

bool ng::depcheck::manager::change_modifications ( const std::vector< std::string > &  modifications)
private

Attempts to change the selected modifications.

Parameters
modificationsthe list of the modifications' ids
Returns
true if the selection was changed; false if not

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().

◆ change_scenario()

bool ng::depcheck::manager::change_scenario ( const std::string &  id)
private

Attempts to change the selected scenario.

Parameters
idthe scenario's id
Returns
true if the selection was changed; false if not

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().

◆ change_scenario_dialog()

std::string ng::depcheck::manager::change_scenario_dialog ( const std::vector< std::string > &  scenarios)
private

Display a dialog requesting the user to select a new scenario.

Parameters
scenariosthe possible options (ids)
Returns
the selected scenario's id or empty string if the user refused to select any

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().

◆ disable_mods_dialog()

bool ng::depcheck::manager::disable_mods_dialog ( const std::vector< std::string > &  mods,
const std::string &  requester = _("A component") 
)
private

Display a dialog requesting confirmation for disabling some modifications.

Parameters
modsthe list of modifications to be disabled
requesterthe add-on's name which requests the action to be done
Returns
true, if the user accepted the change, false if not

Definition at line 448 of file depcheck.cpp.

References depinfo_, and config::find_mandatory_child().

Referenced by change_era(), and change_scenario().

◆ does_conflict()

bool ng::depcheck::manager::does_conflict ( const elem elem1,
const elem elem2,
bool  directonly = false 
) const
private

Decides if two components are conflicting or not.

Parameters
elem1the first component
elem2the second component
directonlywhether the function should ignore any possible conflicts between the components' dependencies.
Returns
true if e1 and e2 conflict, false if not

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().

◆ does_require()

bool ng::depcheck::manager::does_require ( const elem elem1,
const elem elem2 
) const
private

Decides whether e1 requires e2.

Parameters
elem1a component; by definition, passing a modification here makes no sense
elem2another component; by definition, passing anything else than a modification here makes no sense
Returns
true if e2 is required by e1, false if not

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().

◆ enable_mods_dialog()

bool ng::depcheck::manager::enable_mods_dialog ( const std::vector< std::string > &  mods,
const std::string &  requester = _("A component") 
)
private

Display a dialog requesting confirmation for enabling some modifications.

Parameters
modsthe list of modifications to be enabled
requesterthe add-on's name which requests the action to be done
Returns
true, if the user accepted the change, false if not

Definition at line 438 of file depcheck.cpp.

References depinfo_, and config::find_mandatory_child().

Referenced by change_era(), and change_scenario().

◆ exists()

bool ng::depcheck::manager::exists ( const elem e) const
private

Decides whether a certain component is installed or not.

Parameters
ethe component
Returns
true if the component exists false if not

Definition at line 145 of file depcheck.cpp.

References config::child_range(), depinfo_, and e.

Referenced by does_conflict(), and get_required_not_installed().

◆ failure_dialog()

void ng::depcheck::manager::failure_dialog ( const std::string &  msg)
private

Shows an error message.

Parameters
msgthe 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().

◆ find_name_for()

std::string ng::depcheck::manager::find_name_for ( const elem e) const
private

Look up the name of a given component.

Parameters
ethe component
Returns
the name of 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().

◆ get_conflicting_enabled()

std::vector< std::string > ng::depcheck::manager::get_conflicting_enabled ( const elem e) const
private

Get the list of modifications which are conflicting a certain component and are currently enabled.

Parameters
ethe component
Returns
the list of the modifications' ids

Definition at line 208 of file depcheck.cpp.

References does_conflict(), e, and mods_.

Referenced by change_era(), and change_scenario().

◆ get_era()

const std::string& ng::depcheck::manager::get_era ( ) const
inline

Returns the selected era.

Returns
the id of the era

Definition at line 109 of file depcheck.hpp.

References era_.

◆ get_era_index()

int ng::depcheck::manager::get_era_index ( ) const

Returns the selected era.

Returns
the index of the 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().

◆ get_modifications()

const std::vector<std::string>& ng::depcheck::manager::get_modifications ( ) const
inline

Returns the enabled modifications.

Returns
the ids of the modifications

Definition at line 123 of file depcheck.hpp.

References mods_.

Referenced by gui2::dialogs::mp_create_game::sync_with_depcheck().

◆ get_required()

std::vector< std::string > ng::depcheck::manager::get_required ( const elem e) const
private

Get the list of modifications required by a certain component.

Parameters
ethe component
Returns
the list of the modifications' ids

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().

◆ get_required_not_enabled()

std::vector< std::string > ng::depcheck::manager::get_required_not_enabled ( const elem e) const
private

Get the list of modifications which are required by a certain component, but aren't currently enabled.

Parameters
ethe component
Returns
the list of the modifications' ids

Definition at line 194 of file depcheck.cpp.

References utils::contains(), e, get_required(), and mods_.

Referenced by change_era(), and change_scenario().

◆ get_required_not_installed()

std::vector< std::string > ng::depcheck::manager::get_required_not_installed ( const elem e) const
private

Get the list of modifications which are required by a certain component, but currently unavailable on the computer.

Parameters
ethe component
Returns
the list of the modifications' ids

Definition at line 162 of file depcheck.cpp.

References e, exists(), and get_required().

Referenced by change_era(), and change_scenario().

◆ get_scenario()

const std::string& ng::depcheck::manager::get_scenario ( ) const
inline

Returns the selected scenario.

Returns
the id of the scenario

Definition at line 116 of file depcheck.hpp.

References scenario_.

Referenced by gui2::dialogs::mp_create_game::sync_with_depcheck().

◆ get_scenario_index()

int ng::depcheck::manager::get_scenario_index ( ) const

Returns the selected scenario.

Returns
the index of the scenario

Definition at line 412 of file depcheck.cpp.

References config::child_range(), depinfo_, i, and scenario_.

◆ insert_element()

void ng::depcheck::manager::insert_element ( component_type  type,
const config data,
int  index = 0 
)

Adds a new element to the manager's database.

Parameters
typethe type of the element
dataa config object containing the dependency info for the element
indexwhere 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.

◆ is_modification_active() [1/2]

bool ng::depcheck::manager::is_modification_active ( const std::string &  id) const

Tells whether a certain mod is activated.

Parameters
idthe string id of the mod
Returns
true if activated, false is not

Definition at line 433 of file depcheck.cpp.

References utils::find(), and mods_.

◆ is_modification_active() [2/2]

bool ng::depcheck::manager::is_modification_active ( int  index) const

Tells whether a certain mod is activated.

Parameters
indexthe index of the mod
Returns
true if activated, false is not

Definition at line 427 of file depcheck.cpp.

References depinfo_, utils::find(), utf8::index(), config::mandatory_child(), and mods_.

Referenced by gui2::dialogs::mp_create_game::on_mod_toggle().

◆ revert()

void ng::depcheck::manager::revert ( )
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().

◆ save_state()

void ng::depcheck::manager::save_state ( )
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().

◆ try_era()

void ng::depcheck::manager::try_era ( const std::string &  id,
bool  force = false 
)

Tries to set the selected era.

Parameters
idthe id of the era
forcewhether 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().

◆ try_era_by_index()

void ng::depcheck::manager::try_era_by_index ( int  index,
bool  force = false 
)

Tries to set the selected era.

Parameters
indexthe index of the era
forcewhether to skip dependency check

Definition at line 388 of file depcheck.cpp.

References depinfo_, utf8::index(), config::mandatory_child(), and try_era().

◆ try_modification_by_id()

void ng::depcheck::manager::try_modification_by_id ( const std::string &  id,
bool  activate,
bool  force = false 
)

Tries to enable/disable a specific modification.

Parameters
idthe id of the modification
activateactivate or deactivate
forcewhether to skip dependency check

Definition at line 370 of file depcheck.cpp.

References utils::find(), mods_, and try_modifications().

◆ try_modifications()

void ng::depcheck::manager::try_modifications ( const std::vector< std::string > &  ids,
bool  force = false 
)

Tries to set the enabled modifications.

Parameters
idsthe ids of the modifications
forcewhether 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().

◆ try_scenario()

void ng::depcheck::manager::try_scenario ( const std::string &  id,
bool  force = false 
)

Tries to set the selected scenario.

Parameters
idthe id of the scenario
forcewhether 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().

◆ try_scenario_by_index()

void ng::depcheck::manager::try_scenario_by_index ( int  index,
bool  force = false 
)

Tries to set the selected scenario.

Parameters
indexthe index of the scenario
forcewhether to skip dependency check

Definition at line 393 of file depcheck.cpp.

References depinfo_, utf8::index(), config::mandatory_child(), and try_scenario().

Member Data Documentation

◆ depinfo_

config ng::depcheck::manager::depinfo_
private

◆ era_

std::string ng::depcheck::manager::era_
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().

◆ mods_

std::vector<std::string> ng::depcheck::manager::mods_
private

◆ prev_era_

std::string ng::depcheck::manager::prev_era_
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().

◆ prev_mods_

std::vector<std::string> ng::depcheck::manager::prev_mods_
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().

◆ prev_scenario_

std::string ng::depcheck::manager::prev_scenario_
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().

◆ scenario_

std::string ng::depcheck::manager::scenario_
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().


The documentation for this class was generated from the following files: