1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Added (mostly) complete schema for validation of rewardable

This commit is contained in:
Ivan Savenko
2024-08-14 13:39:40 +00:00
parent 2151a7fc88
commit 72896d4ed5
5 changed files with 298 additions and 6 deletions

View File

@@ -202,7 +202,7 @@
"rewards" : [
{
"message" : "@core.genrltxt.583",
"experience" : 1000
"heroExperience" : 1000
}
]
}

View File

@@ -179,7 +179,10 @@
"description" : "stacking"
},
"description" : {
"type" : "string",
"anyOf" : [
{ "type" : "string" },
{ "type" : "number" }
],
"description" : "description"
}
}

View File

@@ -0,0 +1,288 @@
{
"type" : "object",
"$schema" : "http://json-schema.org/draft-04/schema",
"title" : "VCMI map object format",
"description" : "Description of map object class",
"required" : [ "rewards" ],
"additionalProperties" : false,
"definitions" : {
"value" : {
"anyOf" : [
{
"type" : "number"
},
{
"type" : "string" // variable name
},
{
"type" : "array",
"items" : {
"$ref" : "#/definitions/value"
}
},
{
"type" : "object",
"additionalProperties" : true,
"properties" : {
"amount" : { "$ref" : "#/definitions/value" },
"min" : { "$ref" : "#/definitions/value" },
"max" : { "$ref" : "#/definitions/value" }
}
}
]
},
"identifier" : {
"anyOf" : [
{
"type" : "string"
},
{
"type" : "object",
"additionalProperties" : true,
"properties" : {
"type" : {
"$ref" : "#/definitions/identifier"
},
"anyOf" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/identifier"
}
},
"noneOf" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/identifier"
}
}
}
}
]
},
"identifierList" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/identifier"
}
},
"identifierWithValueList" : {
"anyOf" : [
{
"type" : "array",
"items" : {
"allOf" : [
{ "$ref" : "#/definitions/identifier" },
{ "$ref" : "#/definitions/value" }
]
}
},
{
"type" : "object",
"additionalProperties" : {
"$ref" : "#/definitions/value"
}
},
],
},
"reward" : {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"appearChance" : { "type" : "object", "additionalProperties" : true }, //TODO
"limiter" : { "$ref" : "#/definitions/limiter" },
"message" : { "$ref" : "#/definitions/message" },
"description" : { "$ref" : "#/definitions/message" },
"heroExperience" : { "$ref" : "#/definitions/value" },
"heroLevel" : { "$ref" : "#/definitions/value" },
"movePercentage" : { "$ref" : "#/definitions/value" },
"movePoints" : { "$ref" : "#/definitions/value" },
"manaPercentage" : { "$ref" : "#/definitions/value" },
"manaPoints" : { "$ref" : "#/definitions/value" },
"manaOverflowFactor" : { "$ref" : "#/definitions/value" },
"removeObject" : { "type" : "boolean" },
"bonuses" : {
"type":"array",
"description": "List of bonuses that will be granted to visiting hero",
"items": { "$ref" : "bonus.json" }
},
"resources" : { "$ref" : "#/definitions/identifierWithValueList" },
"secondary" : { "$ref" : "#/definitions/identifierWithValueList" },
"creatures" : { "$ref" : "#/definitions/identifierWithValueList" },
"primary" : { "$ref" : "#/definitions/identifierWithValueList" },
"artifacts" : { "$ref" : "#/definitions/identifierList" },
"spells" : { "$ref" : "#/definitions/identifierList" },
"spellCast" : { "type" : "object", "additionalProperties" : true }, //TODO
"revealTiles" : { "type" : "object", "additionalProperties" : true }, //TODO
"changeCreatures" : { "type" : "object", "additionalProperties" : true }, //TODO
}
},
"limiter" : {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"dayOfWeek" : { "$ref" : "#/definitions/value" },
"daysPassed" : { "$ref" : "#/definitions/value" },
"heroExperience" : { "$ref" : "#/definitions/value" },
"heroLevel" : { "$ref" : "#/definitions/value" },
"manaPercentage" : { "$ref" : "#/definitions/value" },
"manaPoints" : { "$ref" : "#/definitions/value" },
"canLearnSkills" : { "type" : "boolean" },
"resources" : { "$ref" : "#/definitions/identifierWithValueList" },
"secondary" : { "$ref" : "#/definitions/identifierWithValueList" },
"creatures" : { "$ref" : "#/definitions/identifierWithValueList" },
"primary" : { "$ref" : "#/definitions/identifierWithValueList" },
"canLearnSpells" : { "$ref" : "#/definitions/identifierList" },
"heroClasses" : { "$ref" : "#/definitions/identifierList" },
"artifacts" : { "$ref" : "#/definitions/identifierList" },
"spells" : { "$ref" : "#/definitions/identifierList" },
"colors" : { "$ref" : "#/definitions/identifierList" },
"heroes" : { "$ref" : "#/definitions/identifierList" },
"anyOf" : {
"type" : "array",
"items" : { "$ref" : "#/definitions/limiter" }
},
"allOf" : {
"type" : "array",
"items" : { "$ref" : "#/definitions/limiter" }
},
"noneOf" : {
"type" : "array",
"items" : { "$ref" : "#/definitions/limiter" }
},
}
},
"message" : {
"anyOf" : [
{
"type" : "array",
"items" : {
"anyOf" : [
{ "type" : "number" },
{ "type" : "string" }
]
}
},
{
"type" : "number"
},
{
"type" : "string"
}
]
},
"variableList" : {
"type" : "object",
"additionalProperties" : {
"$ref" : "#/definitions/identifier"
}
}
},
"properties" : {
"rewards" : {
"type" : "array",
"items" : { "$ref" : "#/definitions/reward" }
},
"onVisited" : {
"type" : "array",
"items" : { "$ref" : "#/definitions/reward" }
},
"onEmpty" : {
"type" : "array",
"items" : { "$ref" : "#/definitions/reward" }
},
"variables" : {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"number" : {
"type" : "object",
"additionalProperties" : {
"$ref" : "#/definitions/value"
}
},
"artifact" : {
"$ref" : "#/definitions/variableList"
},
"spell" : {
"$ref" : "#/definitions/variableList"
},
"primarySkill" : {
"$ref" : "#/definitions/variableList"
},
"secondarySkill" : {
"$ref" : "#/definitions/variableList"
},
},
},
"onSelectMessage" : {
"$ref" : "#/definitions/message"
},
"description" : {
"$ref" : "#/definitions/message"
},
"notVisitedTooltip" : {
"$ref" : "#/definitions/message"
},
"visitedTooltip" : {
"$ref" : "#/definitions/message"
},
"onVisitedMessage" : {
"$ref" : "#/definitions/message"
},
"onEmptyMessage" : {
"$ref" : "#/definitions/message"
},
"canRefuse": {
"type" : "boolean"
},
"showScoutedPreview": {
"type" : "boolean"
},
"showInInfobox": {
"type" : "boolean"
},
"visitMode": {
"enum" : [ "unlimited", "once", "hero", "bonus", "limiter", "player" ],
"type" : "string"
},
"visitLimiter": {
"type" : "object"
},
"selectMode": {
"enum" : [ "selectFirst", "selectPlayer", "selectRandom", "selectAll" ],
"type" : "string"
},
"resetParameters" : { "type" : "object", "additionalProperties" : true }, //TODO
"compatibilityIdentifiers" : { },
"blockedVisitable" : { },
"removable" : { },
"aiValue" : { },
"index" : { },
"base" : { },
"rmg" : { },
"templates" : { },
"battleground" : { },
"sounds" : { }
}
}

View File

@@ -59,10 +59,8 @@
},
"configuration" : {
"description" : "Configuration of building. Only used if 'type' is set to 'configurable'",
//"$ref" : "#/definitions/rewardable",// TODO
"type" : "object",
"additionalProperties" : true
}
"$ref" : "rewardable.json"
},
"cost" : {
"type" : "object",
"additionalProperties" : false,

View File

@@ -10,6 +10,7 @@
#include "StdInc.h"
#include "CRewardableConstructor.h"
#include "../json/JsonUtils.h"
#include "../mapObjects/CRewardableObject.h"
#include "../texts/CGeneralTextHandler.h"
#include "../IGameCallback.h"
@@ -23,6 +24,8 @@ void CRewardableConstructor::initTypeData(const JsonNode & config)
if (!config["name"].isNull())
VLC->generaltexth->registerString( config.getModScope(), getNameTextID(), config["name"].String());
JsonUtils::validate(config, "vcmi:rewardable", getJsonKey());
}