From f71cbc5d9ba24e7dd40c57a28e5eb0d851019107 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 10 Jan 2023 16:24:42 +0200 Subject: [PATCH] Fixed loading of object names --- config/schemas/object.json | 4 ---- lib/mapObjects/CObjectClassesHandler.cpp | 23 +++++++++++++++++------ lib/mapObjects/CObjectClassesHandler.h | 6 ++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/config/schemas/object.json b/config/schemas/object.json index b171928d3..f9c5c2e18 100644 --- a/config/schemas/object.json +++ b/config/schemas/object.json @@ -13,10 +13,6 @@ "lastReservedIndex" : { "type":"number" }, - "subObjects" : { - "type" : "array", - "additionalItems" : true - }, "handler": { "type":"string" }, diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index 643319e88..3061eafec 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjects/CObjectClassesHandler.cpp @@ -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() diff --git a/lib/mapObjects/CObjectClassesHandler.h b/lib/mapObjects/CObjectClassesHandler.h index 38d03f77c..f36b1c0fc 100644 --- a/lib/mapObjects/CObjectClassesHandler.h +++ b/lib/mapObjects/CObjectClassesHandler.h @@ -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 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;