fix [modification]type=key
Previous it couldhappens that create_engines and depcheck::manager s lis of mods could get out of sync which caused wrong modification to be active. Also we add a type= key to [era]s chiech defaults to mp so that only the default era is avaiable in sp by default (for technical reasons there must be at least one era avaiable in sp.
This commit is contained in:
parent
daa045026f
commit
87313970e1
4 changed files with 46 additions and 23 deletions
|
@ -53,6 +53,7 @@
|
|||
id=era_default
|
||||
name= _ "Default"
|
||||
description=_ "The standard era for Wesnoth multiplayer. Consists of six factions and is generally balanced."
|
||||
type=hybrid
|
||||
|
||||
{ERA_DEFAULT}
|
||||
[/era]
|
||||
|
|
|
@ -421,7 +421,7 @@ create_engine::create_engine(game_display& disp, saved_game& state) :
|
|||
state_.mp_settings().show_connect = connect;
|
||||
game_config_manager::get()->load_game_config_for_create(type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
|
||||
//Initilialize dependency_manager_ after refreshing game config.
|
||||
dependency_manager_.reset(new depcheck::manager(game_config_manager::get()->game_config(), disp.video()));
|
||||
dependency_manager_.reset(new depcheck::manager(game_config_manager::get()->game_config(), type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER, disp.video()));
|
||||
//TODO the editor dir is already configurable, is the preferences value
|
||||
filesystem::get_files_in_dir(filesystem::get_user_data_dir() + "/editor/maps", &user_map_names_,
|
||||
NULL, filesystem::FILE_NAME_ONLY);
|
||||
|
@ -1117,14 +1117,13 @@ void create_engine::init_extras(const MP_EXTRA extra_type)
|
|||
{
|
||||
std::vector<extras_metadata_ptr>& extras = get_extras_by_type(extra_type);
|
||||
const std::string extra_name = (extra_type == ERA) ? "era" : "modification";
|
||||
|
||||
BOOST_FOREACH(const config &extra,
|
||||
game_config_manager::get()->game_config().child_range(extra_name)) {
|
||||
|
||||
const std::string& type = extra["type"];
|
||||
ng::depcheck::component_availabilty default_availabilty = (extra_type == ERA) ? ng::depcheck::component_availabilty::MP : ng::depcheck::component_availabilty::HYBRID;
|
||||
BOOST_FOREACH(const config &extra, game_config_manager::get()->game_config().child_range(extra_name))
|
||||
{
|
||||
ng::depcheck::component_availabilty type = extra["type"].to_enum(default_availabilty);
|
||||
bool mp = state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
|
||||
if((type != "mp" || mp) && (type != "sp" || !mp) )
|
||||
if((type != ng::depcheck::component_availabilty::MP || mp) && (type != ng::depcheck::component_availabilty::SP || !mp) )
|
||||
{
|
||||
extras_metadata_ptr new_extras_metadata(new extras_metadata());
|
||||
new_extras_metadata->id = extra["id"].str();
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace ng
|
|||
namespace depcheck
|
||||
{
|
||||
|
||||
manager::manager(const config& gamecfg, CVideo& video)
|
||||
manager::manager(const config& gamecfg, bool mp, CVideo& video)
|
||||
: video_(video)
|
||||
, depinfo_()
|
||||
, era_()
|
||||
|
@ -70,26 +70,32 @@ manager::manager(const config& gamecfg, CVideo& video)
|
|||
{
|
||||
DBG_MP << "Initializing the dependency manager" << std::endl;
|
||||
BOOST_FOREACH (const config& cfg, gamecfg.child_range("modification")) {
|
||||
config info;
|
||||
info["id"] = cfg["id"];
|
||||
info["name"] = cfg["name"];
|
||||
component_availabilty type = cfg["type"].to_enum<component_availabilty>(component_availabilty::HYBRID);
|
||||
if((type != component_availabilty::MP || mp) && (type != component_availabilty::SP || !mp) ) {
|
||||
config info;
|
||||
info["id"] = cfg["id"];
|
||||
info["name"] = cfg["name"];
|
||||
|
||||
copy_keys(info, cfg, "scenario");
|
||||
copy_keys(info, cfg, "era");
|
||||
copy_keys(info, cfg, "modification");
|
||||
copy_keys(info, cfg, "scenario");
|
||||
copy_keys(info, cfg, "era");
|
||||
copy_keys(info, cfg, "modification");
|
||||
|
||||
depinfo_.add_child("modification", info);
|
||||
depinfo_.add_child("modification", info);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FOREACH (const config& cfg, gamecfg.child_range("era")) {
|
||||
config info;
|
||||
info["id"] = cfg["id"];
|
||||
info["name"] = cfg["name"];
|
||||
component_availabilty type = cfg["type"].to_enum<component_availabilty>(component_availabilty::MP);
|
||||
if((type != component_availabilty::MP || mp) && (type != component_availabilty::SP || !mp) ) {
|
||||
config info;
|
||||
info["id"] = cfg["id"];
|
||||
info["name"] = cfg["name"];
|
||||
|
||||
copy_keys(info, cfg, "scenario");
|
||||
copy_keys(info, cfg, "modification", true);
|
||||
copy_keys(info, cfg, "scenario");
|
||||
copy_keys(info, cfg, "modification", true);
|
||||
|
||||
depinfo_.add_child("era", info);
|
||||
depinfo_.add_child("era", info);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FOREACH (const config& cfg, gamecfg.child_range("multiplayer")) {
|
||||
|
@ -386,7 +392,6 @@ void manager::try_scenario_by_index(int index, bool force)
|
|||
int manager::get_era_index() const
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
BOOST_FOREACH (const config& i, depinfo_.child_range("era"))
|
||||
{
|
||||
if (i["id"] == era_) {
|
||||
|
@ -740,6 +745,15 @@ bool manager::change_modifications
|
|||
return true;
|
||||
}
|
||||
|
||||
component_availabilty manager::default_availabilty(component_type t)
|
||||
{
|
||||
if(t == ERA)
|
||||
return component_availabilty::MP;
|
||||
if(t == SCENARIO)
|
||||
return component_availabilty::MP;
|
||||
if(t == MODIFICATION)
|
||||
return component_availabilty::HYBRID;
|
||||
}
|
||||
|
||||
|
||||
} //namespace depcheck
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <vector>
|
||||
#include "config.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "make_enum.hpp"
|
||||
|
||||
class CVideo;
|
||||
|
||||
|
@ -35,6 +36,11 @@ enum component_type
|
|||
MODIFICATION
|
||||
};
|
||||
|
||||
MAKE_ENUM(component_availabilty,
|
||||
(SP, "sp")
|
||||
(MP, "mp")
|
||||
(HYBRID, "hybrid")
|
||||
)
|
||||
/**
|
||||
* Note to all triers:
|
||||
* It's not guaranteed that the specified component will be selected
|
||||
|
@ -49,7 +55,7 @@ enum component_type
|
|||
class manager
|
||||
{
|
||||
public:
|
||||
manager(const config& gamecfg, CVideo& video);
|
||||
manager(const config& gamecfg, bool mp, CVideo& video);
|
||||
|
||||
/**
|
||||
* Tries to set the selected era
|
||||
|
@ -360,6 +366,9 @@ private:
|
|||
*/
|
||||
std::string find_name_for(const elem& e) const;
|
||||
|
||||
|
||||
static component_availabilty default_availabilty(component_type t);
|
||||
|
||||
};
|
||||
|
||||
} //namespace depcheck
|
||||
|
|
Loading…
Add table
Reference in a new issue