mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-18 22:05:38 +00:00
move update routine for addon reqs to class mp_game_settings
This simplifies the code in saved_game.cpp which expands mp scenarios.
This commit is contained in:
parent
0ad24b48a3
commit
235acd7e0c
@ -18,11 +18,18 @@
|
||||
* Container for multiplayer game-creation parameters.
|
||||
*/
|
||||
|
||||
#include "log.hpp"
|
||||
#include "mp_game_settings.hpp"
|
||||
#include "formula_string_utils.hpp"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define ERR_NG LOG_STREAM(err, log_engine)
|
||||
#define WRN_NG LOG_STREAM(warn, log_engine)
|
||||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
#define DBG_NG LOG_STREAM(debug, log_engine)
|
||||
|
||||
mp_game_settings::mp_game_settings() :
|
||||
savegame_config(),
|
||||
name(),
|
||||
@ -163,3 +170,40 @@ void mp_game_settings::addon_version_info::write(config & cfg) const {
|
||||
cfg["min_version"] = *min_version;
|
||||
}
|
||||
}
|
||||
|
||||
void mp_game_settings::update_addon_requirements(const config & cfg) {
|
||||
if (cfg["id"].empty()) {
|
||||
WRN_NG << "Tried to add add-on metadata to a game, missing mandatory id field... skipping.\n" << cfg.debug() << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
mp_game_settings::addon_version_info new_data(cfg);
|
||||
|
||||
// Check if this add-on already has an entry as a dependency for this scenario. If so, try to reconcile their version info,
|
||||
// by taking the larger of the min versions. The version should be the same for all WML from the same add-on...
|
||||
std::map<std::string, addon_version_info>::iterator it = addons.find(cfg["id"].str());
|
||||
if (it != addons.end()) {
|
||||
addon_version_info & addon = it->second;
|
||||
|
||||
try {
|
||||
if (new_data.version) {
|
||||
if (!addon.version || (*addon.version != *new_data.version)) {
|
||||
WRN_NG << "Addon version data mismatch -- not all local WML has same version of '" << cfg["id"].str() << "' addon.\n";
|
||||
}
|
||||
}
|
||||
if (addon.version && !new_data.version) {
|
||||
WRN_NG << "Addon version data mismatch -- not all local WML has same version of '" << cfg["id"].str() << "' addon.\n";
|
||||
}
|
||||
if (new_data.min_version) {
|
||||
if (!addon.min_version || (*new_data.min_version > *addon.min_version)) {
|
||||
addon.min_version = *new_data.min_version;
|
||||
}
|
||||
}
|
||||
} catch (version_info::not_sane_exception & e) {
|
||||
WRN_NG << "Caught a version_info not_sane_exception when determining a scenario's add-on dependencies. addon_id = " << cfg["id"].str() << "\n";
|
||||
}
|
||||
} else {
|
||||
// Didn't find this addon-id in the map, so make a new entry.
|
||||
addons.insert(std::make_pair(cfg["id"].str(), new_data));
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,10 @@ struct mp_game_settings : public savegame::savegame_config
|
||||
};
|
||||
|
||||
std::map<std::string, addon_version_info> addons; // the key is the addon_id
|
||||
|
||||
// Takes a config with addon metadata (id =, version =, min_version =), formatted similarly to how mp_game_settings is written that is,
|
||||
// and adds this as a requirement, updating the min_version if there was already an entry for this addon_id.
|
||||
void update_addon_requirements(const config & addon_cfg);
|
||||
};
|
||||
|
||||
MAKE_ENUM_STREAM_OPS2(mp_game_settings, RANDOM_FACTION_MODE)
|
||||
|
@ -246,36 +246,7 @@ void saved_game::expand_mp_events()
|
||||
std::string require_attr = "require_" + mod.type;
|
||||
bool require_default = (mod.type == "era"); // By default, eras have "require_era = true", and mods have "require_modification = false"
|
||||
if (!cfg["addon_id"].empty() && cfg[require_attr].to_bool(require_default)) {
|
||||
config addon_data = config_of("id",cfg["addon_id"])("version", cfg["addon_version"])("min_version", cfg["addon_min_version"]);
|
||||
mp_game_settings::addon_version_info new_data(addon_data);
|
||||
|
||||
// Check if this add-on already has an entry as a dependency for this scenario. If so, try to reconcile their version info,
|
||||
// by taking the larger of the min versions. The version should be the same for all WML from the same add-on...
|
||||
std::map<std::string, mp_game_settings::addon_version_info>::iterator it = mp_settings_.addons.find(cfg["addon_id"].str());
|
||||
if (it != mp_settings_.addons.end()) {
|
||||
mp_game_settings::addon_version_info & addon = it->second;
|
||||
|
||||
try {
|
||||
if (new_data.version) {
|
||||
if (!addon.version || (*addon.version != *new_data.version)) {
|
||||
WRN_NG << "Addon version data mismatch -- not all local WML has same version of '" << cfg["addon_id"].str() << "' addon.\n";
|
||||
}
|
||||
}
|
||||
if (addon.version && !new_data.version) {
|
||||
WRN_NG << "Addon version data mismatch -- not all local WML has same version of '" << cfg["addon_id"].str() << "' addon.\n";
|
||||
}
|
||||
if (new_data.min_version) {
|
||||
if (!addon.min_version || (*new_data.min_version > *addon.min_version)) {
|
||||
addon.min_version = *new_data.min_version;
|
||||
}
|
||||
}
|
||||
} catch (version_info::not_sane_exception & e) {
|
||||
WRN_NG << "Caught a version_info not_sane_exception when determining a scenario's add-on dependencies. addon_id = " << cfg["addon_id"].str() << "\n";
|
||||
}
|
||||
} else {
|
||||
// Didn't find this addon-id in the map, so make a new entry.
|
||||
mp_settings_.addons.insert(std::make_pair(cfg["addon_id"].str(), new_data));
|
||||
}
|
||||
mp_settings_.update_addon_requirements(config_of("id",cfg["addon_id"])("version", cfg["addon_version"])("min_version", cfg["addon_min_version"]));
|
||||
}
|
||||
|
||||
// Copy events
|
||||
|
Loading…
x
Reference in New Issue
Block a user