32 #define DBG_MP LOG_STREAM(debug, log_mp_create_depcheck)
37 void copy_keys(
config& out,
const config&
in,
const std::string&
type,
bool copy_force_key =
false)
39 if(
in.has_attribute(
"allow_" +
type)) {
41 }
else if(
in.has_attribute(
"disallow_" +
type)) {
42 out[
"disallow_" +
type] =
in[
"disallow_" +
type];
45 if(
in.has_attribute(
"ignore_incompatible_" +
type)) {
46 out[
"ignore_incompatible_" +
type] =
in[
"ignore_incompatible_" +
type];
50 if(
in.has_attribute(
"force_" +
type)) {
70 DBG_MP <<
"Initializing the dependency manager";
75 if((
type != component_availability::type::mp ||
mp) && (
type != component_availability::type::sp || !
mp)) {
77 info[
"id"] = cfg[
"id"];
78 info[
"name"] = cfg[
"name"];
80 copy_keys(
info, cfg,
"scenario");
81 copy_keys(
info, cfg,
"era");
82 copy_keys(
info, cfg,
"modification");
91 if((
type != component_availability::type::mp ||
mp) && (
type != component_availability::type::sp || !
mp)) {
93 info[
"id"] = cfg[
"id"];
94 info[
"name"] = cfg[
"name"];
96 copy_keys(
info, cfg,
"scenario");
97 copy_keys(
info, cfg,
"modification",
true);
104 if(cfg[
"allow_new_game"].to_bool(
true)) {
106 info[
"id"] = cfg[
"id"];
107 info[
"name"] = cfg[
"name"];
109 copy_keys(
info, cfg,
"era");
110 copy_keys(
info, cfg,
"modification",
true);
118 info[
"id"] = cfg[
"id"];
119 info[
"name"] = cfg[
"name"];
120 info[
"allow_era_choice"] = cfg[
"allow_era_choice"];
122 copy_keys(
info, cfg,
"era");
123 copy_keys(
info, cfg,
"modification",
true);
131 DBG_MP <<
"Saving current state";
139 DBG_MP <<
"Restoring previous state";
148 if(cfg[
"id"] ==
e.id) {
164 std::vector<std::string> result;
168 for(
const std::string& str : items) {
170 result.push_back(str);
179 std::vector<std::string> result;
181 if(
e.type ==
"modification") {
187 if(
data.has_attribute(
"force_modification")) {
197 std::vector<std::string> result;
199 for(std::string str : required) {
201 result.push_back(str);
210 std::vector<std::string> result;
212 for(
const std::string& mod :
mods_) {
214 result.push_back(mod);
238 std::vector<std::string> ignored =
utils::split(data1[
"ignore_incompatible_" + elem2.
type]);
246 std::vector<std::string> ignored =
utils::split(data2[
"ignore_incompatible_" + elem1.
type]);
253 if((elem1.
type ==
"era" && data2[
"allow_era_choice"].to_bool(
false)) ||(elem2.
type ==
"era" && data1[
"allow_era_choice"].to_bool(
false))) {
261 std::vector<std::string> allowed =
utils::split(data1[
"allow_" + elem2.
type]);
265 std::vector<std::string> disallowed =
utils::split(data1[
"disallow_" + elem2.
type]);
271 std::vector<std::string> allowed =
utils::split(data2[
"allow_" + elem1.
type]);
275 std::vector<std::string> disallowed =
utils::split(data2[
"disallow_" + elem1.
type]);
288 for(
const std::string&
s : req1) {
289 elem m(
s,
"modification");
296 for(
const std::string&
s : req2) {
297 elem m(
s,
"modification");
304 for(
const std::string& id1 : req1) {
305 elem m1(id1,
"modification");
307 for(
const std::string& id2 : req2) {
308 elem m2(id2,
"modification");
322 if(elem2.
type !=
"modification") {
328 if(
data.has_attribute(
"force_modification")) {
329 std::vector<std::string> required =
utils::split(
data[
"force_modification"]);
372 std::vector<std::string> mods_copy =
mods_;
375 if(std::find(mods_copy.begin(), mods_copy.end(),
id) == mods_copy.end()) {
376 mods_copy.push_back(
id);
380 if(pos != mods_copy.end()) {
381 mods_copy.erase(pos);
402 if(
i[
"id"] ==
era_) {
440 std::vector<std::string> items;
441 for(
const std::string& mod : mods) {
445 return gui2::dialogs::depcheck_confirm_change::execute(
true, items, requester);
450 std::vector<std::string> items;
451 for(
const std::string& mod : mods) {
455 return gui2::dialogs::depcheck_confirm_change::execute(
false, items, requester);
460 std::vector<std::string> items;
461 for(
const std::string& era : eras) {
468 return eras[dialog.
result()];
476 std::vector<std::string> items;
477 for(
const std::string&
scenario : scenarios) {
483 return scenarios[dialog.
result()];
496 std::string type_str;
503 type_str =
"scenario";
506 type_str =
"modification";
516 std::string
msg =
_(
"Scenario can’t be activated. Some dependencies are missing: ");
545 std::vector<std::string> newmods = req;
546 for(
const std::string&
i :
mods_) {
548 newmods.push_back(
i);
560 std::vector<std::string> compatible;
563 compatible.push_back(
i[
"id"]);
567 if(!compatible.empty()) {
585 std::string
msg =
_(
"Era can’t be activated. Some dependencies are missing: ");
613 std::vector<std::string> newmods = req;
614 for(
const std::string&
i :
mods_) {
616 newmods.push_back(
i);
628 std::vector<std::string> compatible;
631 compatible.push_back(
i[
"id"]);
635 if(!compatible.empty()) {
652 std::vector<std::string> filtered;
653 for(
const std::string&
i : modifications) {
655 elem ei(
i,
"modification");
657 for(
const std::string& j : filtered) {
662 filtered.push_back(
i);
666 if(filtered.size() != modifications.size()) {
668 " Some of them will be disabled."));
675 std::vector<std::string> compatible;
677 elem era(
c[
"id"],
"era");
680 for(
const std::string&
s :
mods_) {
685 compatible.push_back(era.
id);
690 if(!compatible.empty()) {
715 elem scen(
c[
"id"],
"scenario");
717 for(
const std::string&
s :
mods_) {
722 compatible.push_back(scen.
id);
727 if(!compatible.empty()) {
A config object defines a single node in a WML file, with access to child nodes.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
config & add_child_at(config_key_type key, const config &val, std::size_t index)
config & find_mandatory_child(config_key_type key, const std::string &name, const std::string &value)
bool has_attribute(config_key_type key) const
child_itors child_range(config_key_type key)
config & add_child(config_key_type key)
A class grating read only view to a vector of config objects, viewed as one config with all children ...
config_array_view child_range(config_key_type key) const
int result() const
Returns the selected item.
bool show(const unsigned auto_close_time=0)
Shows the window.
bool change_scenario(const std::string &id)
Attempts to change the selected scenario.
void try_era_by_index(int index, bool force=false)
Tries to set the selected era.
bool change_modifications(const std::vector< std::string > &modifications)
Attempts to change the selected modifications.
void revert()
restores the lastly saved values of era_, scenarios_ and mods_
void try_modifications(const std::vector< std::string > &ids, bool force=false)
Tries to set the enabled modifications.
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.
bool exists(const elem &e) const
Decides whether a certain component is installed or not.
void insert_element(component_type type, const config &data, int index=0)
Adds a new element to the manager's database.
std::string change_era_dialog(const std::vector< std::string > &eras)
Display a dialog requesting the user to select a new era.
void try_era(const std::string &id, bool force=false)
Tries to set the selected era.
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.
bool does_conflict(const elem &elem1, const elem &elem2, bool directonly=false) const
Decides if two components are conflicting or not.
config depinfo_
holds all required info about the components and their dependencies
std::vector< std::string > get_required(const elem &e) const
Get the list of modifications required by a certain component.
std::string prev_era_
used by save_state() and revert() to backup/restore era_
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.
std::string find_name_for(const elem &e) const
Look up the name of a given component.
bool does_require(const elem &elem1, const elem &elem2) const
Decides whether e1 requires e2.
std::vector< std::string > mods_
the ids of the currently selected modifications
int get_era_index() const
Returns the selected era.
std::string scenario_
the id of the currently selected scenario
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...
std::string change_scenario_dialog(const std::vector< std::string > &scenarios)
Display a dialog requesting the user to select a new scenario.
bool is_modification_active(int index) const
Tells whether a certain mod is activated.
std::string era_
the id of the currently selected era
void try_scenario(const std::string &id, bool force=false)
Tries to set the selected scenario.
void try_scenario_by_index(int index, bool force=false)
Tries to set the selected scenario.
manager(const game_config_view &gamecfg, bool mp)
void failure_dialog(const std::string &msg)
Shows an error message.
bool change_era(const std::string &id)
Attempts to change the selected era.
void save_state()
saves the current values of era_, scenarios_ and mods_
std::string prev_scenario_
used by save_state() and revert() to backup/restore scenario_
int get_scenario_index() const
Returns the selected scenario.
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...
void try_modification_by_id(const std::string &id, bool activate, bool force=false)
Tries to enable/disable a specific modification.
std::vector< std::string > prev_mods_
used by save_state() and revert() to backup/restore mods_
static lg::log_domain log_mp_create_depcheck("mp/create/depcheck")
unsigned in
If equal to search_counter, the node is off the list.
static std::string _(const char *str)
std::string id
Text to match against addon_info.tags()
Standard logging facilities (interface).
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
Main entry points of multiplayer mode.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< std::string > split(const config_attribute_value &val)
std::string::const_iterator iterator
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
represents a component (era, modification or scenario)
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
static map_location::direction s