Browse Source

Merge pull request #6048 from MichalZr6/develop

Fix template.json schema and insert@/modify@ in JsonUtils::merge function
Ivan Savenko 2 months ago
parent
commit
467a5a9713

+ 1 - 2
config/schemas/template.json

@@ -186,10 +186,9 @@
 	},
 	
 	"additionalProperties" : false,
+	"required" : ["zones", "connections", "minSize", "maxSize", "players"],
 	"properties" :
 	{
-		"required" : ["zones", "connections", "minSize", "maxSize", "players"],
-		
 		"players" : {
 			"description" : "Number of players that will be present on map (human or AI)",
 			"type": "string"

+ 1 - 1
lib/entities/faction/CTownHandler.cpp

@@ -331,7 +331,7 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
 	//MODS COMPATIBILITY FOR pre-1.6
 	if(ret->produce.empty() && ret->bid == BuildingID::RESOURCE_SILO)
 	{
-		logGlobal->warn("Resource silo in town '%s' does not produces any resources!", ret->town->faction->getJsonKey());
+		logGlobal->warn("Resource silo in town '%s' does not produce any resources!", ret->town->faction->getJsonKey());
 		switch (ret->town->primaryRes.toEnum())
 		{
 			case EGameResID::GOLD:

+ 3 - 3
lib/json/JsonUtils.cpp

@@ -34,7 +34,7 @@ static std::optional<int> getIndexSafe(const JsonNode & node, const std::string
 	}
 	catch(const std::out_of_range & )
 	{
-		logMod->warn("Failed to replace index when replacing individual items in array. Value '%s' does not exists in targeted array of %d items", keyName, node.Vector().size());
+		logMod->warn("Failed to replace index when replacing individual items in array. Value '%s' does not exist in targeted array of %d items", keyName, node.Vector().size());
 		return std::nullopt;
 	}
 };
@@ -253,14 +253,14 @@ void JsonUtils::merge(JsonNode & dest, JsonNode & source, bool ignoreOverride, b
 						else if (boost::algorithm::starts_with(node.first, "insert@"))
 						{
 							constexpr int numberPosition = std::char_traits<char>::length("insert@");
-							auto index = getIndexSafe(node.second, node.first.substr(numberPosition));
+							auto index = getIndexSafe(dest, node.first.substr(numberPosition));
 							if (index)
 								dest.Vector().insert(dest.Vector().begin() + index.value(), std::move(node.second));
 						}
 						else if (boost::algorithm::starts_with(node.first, "modify@"))
 						{
 							constexpr int numberPosition = std::char_traits<char>::length("modify@");
-							auto index = getIndexSafe(node.second,	node.first.substr(numberPosition));
+							auto index = getIndexSafe(dest,	node.first.substr(numberPosition));
 							if (index)
 								merge(dest.Vector().at(index.value()), node.second, ignoreOverride);
 						}

+ 1 - 1
lib/modding/ContentTypeHandler.cpp

@@ -154,7 +154,7 @@ bool ContentTypeHandler::loadMod(const std::string & modName, bool validate)
 		{
 			// normal new object
 			logMod->trace("no index in loadMod(%s)", name);
-			performValidate(data,name);
+			performValidate(data, name);
 			handler->loadObject(modName, name, data);
 		}
 	}