mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
Mod compatibility check is now in a separate class and not part of
ModHandler
This commit is contained in:
@ -491,88 +491,6 @@ void CModHandler::afterLoad(bool onlyEssential)
|
||||
std::fstream file(CResourceHandler::get()->getResourceName(ResourcePath("config/modSettings.json"))->c_str(), std::ofstream::out | std::ofstream::trunc);
|
||||
file << modSettings.toJson();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CModHandler::trySetActiveMods(const std::vector<std::pair<TModID, CModInfo::VerificationInfo>> & modList)
|
||||
{
|
||||
auto searchVerificationInfo = [&modList](const TModID & m) -> const CModInfo::VerificationInfo*
|
||||
{
|
||||
for(auto & i : modList)
|
||||
if(i.first == m)
|
||||
return &i.second;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
std::vector<TModID> missingMods, excessiveMods;
|
||||
ModIncompatibility::ModListWithVersion missingModsResult;
|
||||
ModIncompatibility::ModList excessiveModsResult;
|
||||
|
||||
for(const auto & m : activeMods)
|
||||
{
|
||||
if(searchVerificationInfo(m))
|
||||
continue;
|
||||
|
||||
//TODO: support actual disabling of these mods
|
||||
if(getModInfo(m).checkModGameplayAffecting())
|
||||
excessiveMods.push_back(m);
|
||||
}
|
||||
|
||||
for(const auto & infoPair : modList)
|
||||
{
|
||||
auto & remoteModId = infoPair.first;
|
||||
auto & remoteModInfo = infoPair.second;
|
||||
|
||||
bool modAffectsGameplay = remoteModInfo.impactsGameplay;
|
||||
//parent mod affects gameplay if child affects too
|
||||
for(const auto & subInfoPair : modList)
|
||||
modAffectsGameplay |= (subInfoPair.second.impactsGameplay && subInfoPair.second.parent == remoteModId);
|
||||
|
||||
if(!allMods.count(remoteModId))
|
||||
{
|
||||
if(modAffectsGameplay)
|
||||
missingMods.push_back(remoteModId); //mod is not installed
|
||||
continue;
|
||||
}
|
||||
|
||||
auto & localModInfo = getModInfo(remoteModId).getVerificationInfo();
|
||||
modAffectsGameplay |= getModInfo(remoteModId).checkModGameplayAffecting();
|
||||
bool modVersionCompatible = localModInfo.version.isNull()
|
||||
|| remoteModInfo.version.isNull()
|
||||
|| localModInfo.version.compatible(remoteModInfo.version);
|
||||
bool modLocalyEnabled = vstd::contains(activeMods, remoteModId);
|
||||
|
||||
if(modVersionCompatible && modAffectsGameplay && modLocalyEnabled)
|
||||
continue;
|
||||
|
||||
if(modAffectsGameplay)
|
||||
missingMods.push_back(remoteModId); //incompatible mod impacts gameplay
|
||||
}
|
||||
|
||||
//filter mods
|
||||
for(auto & m : missingMods)
|
||||
{
|
||||
if(auto * vInfo = searchVerificationInfo(m))
|
||||
{
|
||||
assert(vInfo->parent != m);
|
||||
if(!vInfo->parent.empty() && vstd::contains(missingMods, vInfo->parent))
|
||||
continue;
|
||||
missingModsResult.push_back({vInfo->name, vInfo->version.toString()});
|
||||
}
|
||||
}
|
||||
for(auto & m : excessiveMods)
|
||||
{
|
||||
auto & vInfo = getModInfo(m).getVerificationInfo();
|
||||
assert(vInfo.parent != m);
|
||||
if(!vInfo.parent.empty() && vstd::contains(excessiveMods, vInfo.parent))
|
||||
continue;
|
||||
excessiveModsResult.push_back(vInfo.name);
|
||||
}
|
||||
|
||||
if(!missingModsResult.empty() || !excessiveModsResult.empty())
|
||||
throw ModIncompatibility(missingModsResult, excessiveModsResult);
|
||||
|
||||
//TODO: support actual enabling of required mods
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
Reference in New Issue
Block a user