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:
@ -9,8 +9,9 @@
|
|||||||
{ "skill" : "leadership", "level": "basic" },
|
{ "skill" : "leadership", "level": "basic" },
|
||||||
{ "skill" : "archery", "level": "basic" }
|
{ "skill" : "archery", "level": "basic" }
|
||||||
],
|
],
|
||||||
"specialty" : [
|
"specialty" : {
|
||||||
{
|
"bonuses" : {
|
||||||
|
"archery" : {
|
||||||
"type" : "SECONDARY_SKILL_PREMY",
|
"type" : "SECONDARY_SKILL_PREMY",
|
||||||
"subtype" : "skill.archery",
|
"subtype" : "skill.archery",
|
||||||
"valueType" : "PERCENT_TO_BASE",
|
"valueType" : "PERCENT_TO_BASE",
|
||||||
@ -19,7 +20,8 @@
|
|||||||
"parameters" : [100]
|
"parameters" : [100]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"valeska":
|
"valeska":
|
||||||
{
|
{
|
||||||
@ -31,26 +33,18 @@
|
|||||||
{ "skill" : "leadership", "level": "basic" },
|
{ "skill" : "leadership", "level": "basic" },
|
||||||
{ "skill" : "archery", "level": "basic" }
|
{ "skill" : "archery", "level": "basic" }
|
||||||
],
|
],
|
||||||
"specialty" : [
|
"specialty" : {
|
||||||
{
|
"base" : {
|
||||||
"limiter" : {
|
|
||||||
"parameters" : [
|
|
||||||
"archer",
|
|
||||||
true
|
|
||||||
],
|
|
||||||
"type" : "CREATURE_TYPE_LIMITER"
|
|
||||||
},
|
|
||||||
"type" : "STACKS_SPEED",
|
|
||||||
"val" : 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"limiter" : {
|
"limiter" : {
|
||||||
"parameters" : [
|
"parameters" : [
|
||||||
"archer",
|
"archer",
|
||||||
true
|
true
|
||||||
],
|
],
|
||||||
"type" : "CREATURE_TYPE_LIMITER"
|
"type" : "CREATURE_TYPE_LIMITER"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
"bonuses" : {
|
||||||
|
"attack" : {
|
||||||
"subtype" : "primSkill.attack",
|
"subtype" : "primSkill.attack",
|
||||||
"type" : "PRIMARY_SKILL",
|
"type" : "PRIMARY_SKILL",
|
||||||
"updater" : {
|
"updater" : {
|
||||||
@ -61,14 +55,7 @@
|
|||||||
"type" : "GROWS_WITH_LEVEL"
|
"type" : "GROWS_WITH_LEVEL"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
"defence" : {
|
||||||
"limiter" : {
|
|
||||||
"parameters" : [
|
|
||||||
"archer",
|
|
||||||
true
|
|
||||||
],
|
|
||||||
"type" : "CREATURE_TYPE_LIMITER"
|
|
||||||
},
|
|
||||||
"subtype" : "primSkill.defence",
|
"subtype" : "primSkill.defence",
|
||||||
"type" : "PRIMARY_SKILL",
|
"type" : "PRIMARY_SKILL",
|
||||||
"updater" : {
|
"updater" : {
|
||||||
@ -78,8 +65,13 @@
|
|||||||
],
|
],
|
||||||
"type" : "GROWS_WITH_LEVEL"
|
"type" : "GROWS_WITH_LEVEL"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"speed" : {
|
||||||
|
"type" : "STACKS_SPEED",
|
||||||
|
"val" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"edric":
|
"edric":
|
||||||
{
|
{
|
||||||
|
@ -115,11 +115,11 @@
|
|||||||
"additionalItems" : true
|
"additionalItems" : true
|
||||||
},
|
},
|
||||||
"specialty": {
|
"specialty": {
|
||||||
"type":"array",
|
|
||||||
"description": "Description of hero specialty using bonus system",
|
|
||||||
"items": {
|
|
||||||
"oneOf" : [
|
"oneOf" : [
|
||||||
{
|
{
|
||||||
|
"type":"array",
|
||||||
|
"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",
|
"type" : "object",
|
||||||
"description" : "List of bonuses",
|
"description": "Description of hero specialty using bonus system",
|
||||||
"items" : { "$ref" : "vcmi:bonus" }
|
"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",
|
||||||
|
@ -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
|
|
||||||
{
|
|
||||||
hero->specialty.push_back(prepSpec(JsonUtils::parseBonus(specialty)));
|
|
||||||
}
|
}
|
||||||
|
else if(specialtyNode.getType() == JsonNode::DATA_STRUCT)
|
||||||
|
{
|
||||||
|
//proper new format
|
||||||
|
for(auto keyValue : specialtyNode["bonuses"].Struct())
|
||||||
|
hero->specialty.push_back(prepSpec(JsonUtils::parseBonus(keyValue.second)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Reference in New Issue
Block a user