1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Fixed several scenarios which could lead to json with incorrectly set

mod origin info, leading to non-resolving identifiers
This commit is contained in:
Ivan Savenko
2022-11-29 22:34:32 +02:00
parent abe11aaf54
commit 36ae26bc37
4 changed files with 13 additions and 12 deletions

View File

@@ -373,8 +373,8 @@ CArtifact * CArtHandler::loadFromJson(const std::string & scope, const JsonNode
if(!art->advMapDef.empty())
{
JsonNode templ;
templ.setMeta(scope);
templ["animation"].String() = art->advMapDef;
templ.setMeta(scope);
// add new template.
// Necessary for objects added via mods that don't have any templates in H3

View File

@@ -633,6 +633,7 @@ CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const Json
{
JsonNode templ;
templ["animation"].String() = cre->advMapDef;
templ.setMeta(scope);
VLC->objtypeh->getHandlerFor(Obj::MONSTER, cre->idNumber.num)->addTemplate(templ);
}

View File

@@ -26,14 +26,6 @@
VCMI_LIB_NAMESPACE_BEGIN
// FIXME: move into inheritNode?
static void inheritNodeWithMeta(JsonNode & descendant, const JsonNode & base)
{
std::string oldMeta = descendant.meta;
JsonUtils::inherit(descendant, base);
descendant.setMeta(oldMeta);
}
CObjectClassesHandler::CObjectClassesHandler()
{
#define SET_HANDLER_CLASS(STRING, CLASSNAME) handlerConstructors[STRING] = std::make_shared<CLASSNAME>;
@@ -291,8 +283,9 @@ void CObjectClassesHandler::loadSubObject(const std::string & identifier, JsonNo
assert(objects.at(ID)->subObjects.count(subID.get()) == 0);
assert(config["index"].isNull());
config["index"].Float() = subID.get();
config["index"].setMeta(config.meta);
}
inheritNodeWithMeta(config, objects.at(ID)->base);
JsonUtils::inherit(config, objects.at(ID)->base);
loadObjectEntry(identifier, config, objects[ID], isSubObject);
}
@@ -367,10 +360,16 @@ void CObjectClassesHandler::beforeValidate(JsonNode & object)
{
for (auto & entry : object["types"].Struct())
{
inheritNodeWithMeta(entry.second, object["base"]);
JsonNode base = object["base"];
base.setMeta(entry.second.meta);
JsonUtils::inherit(entry.second, base);
for (auto & templ : entry.second["templates"].Struct())
{
inheritNodeWithMeta(templ.second, entry.second["base"]);
JsonNode subBase = entry.second["base"];
subBase.setMeta(entry.second.meta);
JsonUtils::inherit(templ.second, subBase);
}
}
}

View File

@@ -44,6 +44,7 @@ void CTownInstanceConstructor::initTypeData(const JsonNode & input)
});
filtersJson = input["filters"];
filtersJson.setMeta(input["faction"].meta);
}
void CTownInstanceConstructor::afterLoadFinalization()