1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-03 00:46:55 +02:00

updated json loading and schema to fit new specialty format

This commit is contained in:
Henning Koehler
2017-09-14 10:45:54 +12:00
parent 038cb4bf19
commit a002df399e
4 changed files with 93 additions and 70 deletions

View File

@ -9,17 +9,19 @@
{ "skill" : "leadership", "level": "basic" }, { "skill" : "leadership", "level": "basic" },
{ "skill" : "archery", "level": "basic" } { "skill" : "archery", "level": "basic" }
], ],
"specialty" : [ "specialty" : {
{ "bonuses" : {
"type" : "SECONDARY_SKILL_PREMY", "archery" : {
"subtype" : "skill.archery", "type" : "SECONDARY_SKILL_PREMY",
"valueType" : "PERCENT_TO_BASE", "subtype" : "skill.archery",
"updater" : { "valueType" : "PERCENT_TO_BASE",
"type" : "GROWS_WITH_LEVEL", "updater" : {
"parameters" : [100] "type" : "GROWS_WITH_LEVEL",
"parameters" : [100]
}
} }
} }
] }
}, },
"valeska": "valeska":
{ {
@ -31,55 +33,45 @@
{ "skill" : "leadership", "level": "basic" }, { "skill" : "leadership", "level": "basic" },
{ "skill" : "archery", "level": "basic" } { "skill" : "archery", "level": "basic" }
], ],
"specialty" : [ "specialty" : {
{ "base" : {
"limiter" : { "limiter" : {
"parameters" : [ "parameters" : [
"archer", "archer",
true true
], ],
"type" : "CREATURE_TYPE_LIMITER" "type" : "CREATURE_TYPE_LIMITER"
},
"type" : "STACKS_SPEED",
"val" : 1
},
{
"limiter" : {
"parameters" : [
"archer",
true
],
"type" : "CREATURE_TYPE_LIMITER"
},
"subtype" : "primSkill.attack",
"type" : "PRIMARY_SKILL",
"updater" : {
"parameters" : [
6,
2
],
"type" : "GROWS_WITH_LEVEL"
} }
}, },
{ "bonuses" : {
"limiter" : { "attack" : {
"parameters" : [ "subtype" : "primSkill.attack",
"archer", "type" : "PRIMARY_SKILL",
true "updater" : {
], "parameters" : [
"type" : "CREATURE_TYPE_LIMITER" 6,
2
],
"type" : "GROWS_WITH_LEVEL"
}
}, },
"subtype" : "primSkill.defence", "defence" : {
"type" : "PRIMARY_SKILL", "subtype" : "primSkill.defence",
"updater" : { "type" : "PRIMARY_SKILL",
"parameters" : [ "updater" : {
3, "parameters" : [
2 3,
], 2
"type" : "GROWS_WITH_LEVEL" ],
"type" : "GROWS_WITH_LEVEL"
}
},
"speed" : {
"type" : "STACKS_SPEED",
"val" : 1
} }
} }
] }
}, },
"edric": "edric":
{ {

View File

@ -115,11 +115,11 @@
"additionalItems" : true "additionalItems" : true
}, },
"specialty": { "specialty": {
"type":"array", "oneOf" : [
"description": "Description of hero specialty using bonus system", {
"items": { "type":"array",
"oneOf" : [ "description": "Description of hero specialty using bonus system (deprecated)",
{ "items": {
"type" : "object", "type" : "object",
"additionalProperties" : false, "additionalProperties" : false,
"required" : [ "bonuses" ], "required" : [ "bonuses" ],
@ -134,14 +134,26 @@
"items" : { "$ref" : "vcmi:bonus" } "items" : { "$ref" : "vcmi:bonus" }
} }
} }
},
{
"type" : "object",
"description" : "List of bonuses",
"items" : { "$ref" : "vcmi:bonus" }
} }
] },
} {
"type" : "object",
"description": "Description of hero specialty using bonus system",
"additionalProperties" : false,
"required" : [ "bonuses" ],
"properties" : {
"base" : {
"type" : "object",
"description" : "Will be merged with all bonuses."
},
"bonuses" : {
"type" : "object",
"description" : "Set of bonuses",
"additionalProperties" : { "$ref" : "vcmi:bonus" }
}
}
}
]
}, },
"spellbook": { "spellbook": {
"type":"array", "type":"array",

View File

@ -533,6 +533,21 @@ std::vector<std::shared_ptr<Bonus>> SpecialtyInfoToBonuses(const SSpecialtyInfo
return result; return result;
} }
void CHeroHandler::beforeValidate(JsonNode & object)
{
//handle "base" specialty info
const JsonNode & specialtyNode = object["specialty"];
if(specialtyNode.getType() == JsonNode::DATA_STRUCT)
{
const JsonNode & base = specialtyNode["base"];
if(!base.isNull())
{
for(auto keyValue : specialtyNode["bonuses"].Struct())
JsonUtils::inherit(keyValue.second, base);
}
}
}
void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node) void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
{ {
int sid = hero->ID.getNum(); int sid = hero->ID.getNum();
@ -545,11 +560,11 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
}; };
//deprecated, used only for original specialties //deprecated, used only for original specialties
const JsonNode & specialties = node["specialties"]; const JsonNode & specialtiesNode = node["specialties"];
if (!specialties.isNull()) if (!specialtiesNode.isNull())
{ {
logMod->warn("Hero %s has deprecated specialties format.", hero->identifier); logMod->warn("Hero %s has deprecated specialties format.", hero->identifier);
for(const JsonNode &specialty : node["specialties"].Vector()) for(const JsonNode &specialty : specialtiesNode.Vector())
{ {
SSpecialtyInfo spec; SSpecialtyInfo spec;
spec.type = specialty["type"].Float(); spec.type = specialty["type"].Float();
@ -560,19 +575,22 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
hero->specDeprecated.push_back(spec); hero->specDeprecated.push_back(spec);
} }
} }
//new format, using bonus system //new(er) format, using bonus system
for(const JsonNode & specialty : node["specialty"].Vector()) const JsonNode & specialtyNode = node["specialty"];
if(specialtyNode.getType() == JsonNode::DATA_VECTOR)
{ {
//deprecated new format //deprecated middle-aged format
if(!specialty["bonuses"].isNull()) for(const JsonNode & specialty : node["specialty"].Vector())
{ {
for (const JsonNode & bonus : specialty["bonuses"].Vector()) for (const JsonNode & bonus : specialty["bonuses"].Vector())
hero->specialty.push_back(prepSpec(JsonUtils::parseBonus(bonus))); hero->specialty.push_back(prepSpec(JsonUtils::parseBonus(bonus)));
} }
else //proper new format }
{ else if(specialtyNode.getType() == JsonNode::DATA_STRUCT)
hero->specialty.push_back(prepSpec(JsonUtils::parseBonus(specialty))); {
} //proper new format
for(auto keyValue : specialtyNode["bonuses"].Struct())
hero->specialty.push_back(prepSpec(JsonUtils::parseBonus(keyValue.second)));
} }
} }

View File

@ -300,6 +300,7 @@ public:
std::vector<JsonNode> loadLegacyData(size_t dataSize) override; std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
void beforeValidate(JsonNode & object);
void loadObject(std::string scope, std::string name, const JsonNode & data) override; void loadObject(std::string scope, std::string name, const JsonNode & data) override;
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override; void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
void afterLoadFinalization() override; void afterLoadFinalization() override;