1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Simplify NKAI settings loading code

This commit is contained in:
Ivan Savenko 2024-04-19 18:40:47 +03:00
parent 20f323d83c
commit e8e4446886

View File

@ -18,7 +18,7 @@
#include "../../../lib/modding/CModHandler.h" #include "../../../lib/modding/CModHandler.h"
#include "../../../lib/VCMI_Lib.h" #include "../../../lib/VCMI_Lib.h"
#include "../../../lib/filesystem/Filesystem.h" #include "../../../lib/filesystem/Filesystem.h"
#include "../../../lib/json/JsonNode.h" #include "../../../lib/json/JsonUtils.h"
namespace NKAI namespace NKAI
{ {
@ -31,27 +31,8 @@ namespace NKAI
allowObjectGraph(false), allowObjectGraph(false),
useTroopsFromGarrisons(false) useTroopsFromGarrisons(false)
{ {
ResourcePath resource("config/ai/nkai/nkai-settings", EResType::JSON); JsonNode node = JsonUtils::assembleFromFiles("config/ai/nkai/nkai-settings");
loadFromMod("core", resource);
for(const auto & modName : VLC->modh->getActiveMods())
{
if(CResourceHandler::get(modName)->existsResource(resource))
loadFromMod(modName, resource);
}
}
void Settings::loadFromMod(const std::string & modName, const ResourcePath & resource)
{
if(!CResourceHandler::get(modName)->existsResource(resource))
{
logGlobal->error("Failed to load font %s from mod %s", resource.getName(), modName);
return;
}
JsonNode node(JsonPath::fromResource(resource), modName);
if(node.Struct()["maxRoamingHeroes"].isNumber()) if(node.Struct()["maxRoamingHeroes"].isNumber())
{ {
maxRoamingHeroes = node.Struct()["maxRoamingHeroes"].Integer(); maxRoamingHeroes = node.Struct()["maxRoamingHeroes"].Integer();