浏览代码

Merge pull request #512 from godric3/jsonSchemas

Support for using relative file path in json schema references
Alexander Shishkin 7 年之前
父节点
当前提交
845f0fbf5c

+ 2 - 2
config/schemas/artifact.json

@@ -15,7 +15,7 @@
 					"level" : {
 						"type" : "number"
 					},
-					"bonus" : { "$ref" : "vcmi:bonus" }
+					"bonus" : { "$ref" : "bonus.json" }
 				}
 			}
 		}
@@ -26,7 +26,7 @@
 		"bonuses": {
 			"type":"array",
 			"description": "Bonuses provided by this artifact using bonus system",
-			"items": { "$ref" : "vcmi:bonus" }
+			"items": { "$ref" : "bonus.json" }
 		},
 		"class": {
 			"type":"string",

+ 1 - 1
config/schemas/bonus.json

@@ -25,7 +25,7 @@
 							"type" : "array",
 							"description" : "parameters",
 							"additionalItems" : true
-						},
+						}
 					}
 				},
 				{

+ 2 - 2
config/schemas/creature.json

@@ -135,7 +135,7 @@
 			"description": "Creature abilities described using Bonus system",
 			"type":"object",
 			"additionalProperties": {
-				"$ref" : "vcmi:bonus"
+				"$ref" : "bonus.json"
 			}
 		},
 		"stackExperience": {
@@ -147,7 +147,7 @@
 				"required" : [ "bonus", "values" ],
 				"description": "0",
 				"properties":{
-					"bonus": {"$ref" : "vcmi:bonus" },
+					"bonus": {"$ref" : "bonus.json" },
 					"values": {
 						"type":"array",
 						"minItems" : 10,

+ 3 - 3
config/schemas/faction.json

@@ -156,7 +156,7 @@
 				"buildings": {
 					"type" : "object",
 					"additionalProperties" : {
-						"$ref" : "vcmi:townBuilding"
+						"$ref" : "townBuilding.json"
 					}
 				},
 				"creatures": {
@@ -241,12 +241,12 @@
 					"format" : "musicFile"
 				},
 				"siege": {
-					"$ref" : "vcmi:townSiege"
+					"$ref" : "townSiege.json"
 				},
 				"structures": {
 					"type" : "object",
 					"additionalProperties" : {
-						"$ref" : "vcmi:townStructure"
+						"$ref" : "townStructure.json"
 					}
 				},
 				"townBackground": {

+ 2 - 2
config/schemas/hero.json

@@ -136,7 +136,7 @@
 							"bonuses" : {
 								"type" : "array",
 								"description" : "List of bonuses",
-								"items" : { "$ref" : "vcmi:bonus" }
+								"items" : { "$ref" : "bonus.json" }
 							}
 						}
 					}
@@ -153,7 +153,7 @@
 						"bonuses" : {
 							"type" : "object",
 							"description" : "Set of bonuses",
-							"additionalProperties" : { "$ref" : "vcmi:bonus" }
+							"additionalProperties" : { "$ref" : "bonus.json" }
 						},
 						"creature" : {
 							"type" : "string",

+ 1 - 1
config/schemas/mapHeader.json

@@ -41,7 +41,7 @@
 
 						"properties" : {
 							"type" : { "type" : "string" },
-							"messageToSend" : { "type" : "string" },
+							"messageToSend" : { "type" : "string" }
 						}
 					}
 				}

+ 5 - 5
config/schemas/object.json

@@ -8,17 +8,17 @@
 
 	"properties":{
 		"index": {
-			"type":"number",
+			"type":"number"
 		},
 		"name": {
-			"type":"string",
+			"type":"string"
 		},
 		"defaultAiValue": {
-			"type":"number",
+			"type":"number"
 		},
 
 		"handler": {
-			"type":"string",
+			"type":"string"
 		},
 
 		"sounds": {
@@ -56,7 +56,7 @@
 		"types": {
 			"type":"object",
 			"additionalProperties": {
-				"$ref" : "vcmi:objectType"
+				"$ref" : "objectType.json"
 			}
 		}
 	}

+ 4 - 4
config/schemas/objectType.json

@@ -8,13 +8,13 @@
 
 	"properties":{
 		"index": {
-			"type":"number",
+			"type":"number"
 		},
 		"name": {
-			"type":"string",
+			"type":"string"
 		},
 		"aiValue": {
-			"type":"number",
+			"type":"number"
 		},
 
 		"sounds": {
@@ -52,7 +52,7 @@
 		"templates": {
 			"type":"object",
 			"additionalProperties": {
-				"$ref" : "vcmi:objectTemplate"
+				"$ref" : "objectTemplate.json"
 			}
 		}
 	}

+ 1 - 1
config/schemas/skill.json

@@ -41,7 +41,7 @@
 				"effects" : {
 					"type" : "object",
 					"additionalProperties" : {
-						"$ref" : "vcmi:bonus"
+						"$ref" : "bonus.json"
 					}
 				}
 			}

+ 5 - 5
config/schemas/spell.json

@@ -73,10 +73,10 @@
 					"description":"Cost in mana points"
 				},
 				"power":{
-					"type": "number",
+					"type": "number"
 				},
 				"aiValue":{
-					"type": "number",
+					"type": "number"
 				},
 
 				"range":{
@@ -87,14 +87,14 @@
 					"type": "object",
 					"description": "Timed effects (updated by prolongation)",
 					"additionalProperties" : {
-						"$ref" : "vcmi:bonus"
+						"$ref" : "bonus.json"
 					}
 				},
 				"cumulativeEffects":{
 					"type": "object",
 					"description": "Timed effects (updated by unique bonus)",
 					"additionalProperties" : {
-						"$ref" : "vcmi:bonus"
+						"$ref" : "bonus.json"
 					}
 				},
 				"battleEffects":{
@@ -175,7 +175,7 @@
 
 		"power":{
 				"type": "number",
-				"description": "Base power",
+				"description": "Base power"
 		},
 
 		"defaultGainChance":{

+ 11 - 10
lib/JsonNode.cpp

@@ -904,7 +904,7 @@ const JsonNode & getSchemaByName(std::string name)
 	if (vstd::contains(loadedSchemas, name))
 		return loadedSchemas[name];
 
-	std::string filename = "config/schemas/" + name + ".json";
+	std::string filename = "config/schemas/" + name;
 
 	if (CResourceHandler::get()->existsResource(ResourceID(filename)))
 	{
@@ -921,19 +921,20 @@ const JsonNode & JsonUtils::getSchema(std::string URI)
 {
 	size_t posColon = URI.find(':');
 	size_t posHash  = URI.find('#');
+	std::string filename;
 	if(posColon == std::string::npos)
 	{
-		logMod->error("Invalid schema URI:%s", URI);
-		return nullNode;
+		filename = URI.substr(0, posHash);
 	}
-
-	std::string protocolName = URI.substr(0, posColon);
-	std::string filename =     URI.substr(posColon + 1, posHash - posColon - 1);
-
-	if(protocolName != "vcmi")
+	else
 	{
-		logMod->error("Error: unsupported URI protocol for schema: %s", URI);
-		return nullNode;
+		std::string protocolName = URI.substr(0, posColon);
+		filename = URI.substr(posColon + 1, posHash - posColon - 1) + ".json";
+		if(protocolName != "vcmi")
+		{
+			logMod->error("Error: unsupported URI protocol for schema: %s", URI);
+			return nullNode;
+		}
 	}
 
 	// check if json pointer if present (section after hash in string)