mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Fixed loading of object names
This commit is contained in:
parent
b13637cdd5
commit
f71cbc5d9b
@ -13,10 +13,6 @@
|
||||
"lastReservedIndex" : {
|
||||
"type":"number"
|
||||
},
|
||||
"subObjects" : {
|
||||
"type" : "array",
|
||||
"additionalItems" : true
|
||||
},
|
||||
"handler": {
|
||||
"type":"string"
|
||||
},
|
||||
|
@ -182,6 +182,7 @@ TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::strin
|
||||
}
|
||||
|
||||
auto createdObject = handlerConstructors.at(obj->handlerName)();
|
||||
createdObject->modName = scope;
|
||||
createdObject->setType(obj->id, index);
|
||||
createdObject->setTypeName(obj->getIdentifier(), identifier);
|
||||
createdObject->init(entry);
|
||||
@ -212,18 +213,14 @@ ObjectClass * CObjectClassesHandler::loadFromJson(const std::string & scope, con
|
||||
obj->id = index;
|
||||
|
||||
obj->objects.resize(json["lastReservedIndex"].Float() + 1);
|
||||
auto originalData = json["subObjects"].Vector();
|
||||
|
||||
for (auto subData : json["types"].Struct())
|
||||
{
|
||||
if (!subData.second["index"].isNull())
|
||||
{
|
||||
if (subData.second["index"].meta != "core")
|
||||
logMod->warn("Object %s:%s from mod %s - attempt to load object with preset index!", name, subData.first, scope);
|
||||
size_t subIndex = subData.second["index"].Integer();
|
||||
if (subIndex < originalData.size())
|
||||
{
|
||||
JsonUtils::merge(originalData[subIndex], subData.second);
|
||||
std::swap(originalData[subIndex], subData.second);
|
||||
}
|
||||
loadSubObject(scope, subData.first, subData.second, obj, subIndex);
|
||||
}
|
||||
else
|
||||
@ -333,10 +330,24 @@ void CObjectClassesHandler::beforeValidate(JsonNode & object)
|
||||
{
|
||||
for (auto & entry : object["types"].Struct())
|
||||
{
|
||||
if (object.Struct().count("subObjects"))
|
||||
{
|
||||
auto const & vector = object["subObjects"].Vector();
|
||||
|
||||
if (!entry.second.Struct().count("index"))
|
||||
continue;
|
||||
|
||||
size_t index = entry.second["index"].Integer();
|
||||
|
||||
if (index < vector.size())
|
||||
JsonUtils::inherit(entry.second, vector[index]);
|
||||
}
|
||||
|
||||
JsonUtils::inherit(entry.second, object["base"]);
|
||||
for (auto & templ : entry.second["templates"].Struct())
|
||||
JsonUtils::inherit(templ.second, entry.second["base"]);
|
||||
}
|
||||
object.Struct().erase("subObjects");
|
||||
}
|
||||
|
||||
void CObjectClassesHandler::afterLoadFinalization()
|
||||
|
@ -139,10 +139,9 @@ class CGObjectInstance;
|
||||
/// Class responsible for creation of objects of specific type & subtype
|
||||
class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable
|
||||
{
|
||||
RandomMapInfo rmgInfo;
|
||||
friend class CObjectClassesHandler;
|
||||
|
||||
/// Text ID for human-readable name of this object, used for objects like banks and dwellings, if set
|
||||
boost::optional<std::string> nameTextID;
|
||||
RandomMapInfo rmgInfo;
|
||||
|
||||
JsonNode base; /// describes base template
|
||||
|
||||
@ -226,7 +225,6 @@ public:
|
||||
h & subtype;
|
||||
h & templates;
|
||||
h & rmgInfo;
|
||||
h & nameTextID;
|
||||
h & modName;
|
||||
h & typeName;
|
||||
h & subTypeName;
|
||||
|
Loading…
x
Reference in New Issue
Block a user