1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #512 from godric3/jsonSchemas

Support for using relative file path in json schema references
This commit is contained in:
Alexander Shishkin 2018-11-02 13:07:34 +03:00 committed by GitHub
commit 845f0fbf5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 37 additions and 36 deletions

View File

@ -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",

View File

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

View File

@ -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,

View File

@ -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": {

View File

@ -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",

View File

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

View File

@ -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"
}
}
}

View File

@ -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"
}
}
}

View File

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

View File

@ -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":{

View File

@ -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,20 +921,21 @@ 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);
}
else
{
std::string protocolName = URI.substr(0, posColon);
std::string filename = URI.substr(posColon + 1, posHash - posColon - 1);
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)
if(posHash == std::string::npos || posHash == URI.size() - 1)