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

added updater to Bonus json format

This commit is contained in:
Henning Koehler 2017-09-11 12:36:02 +12:00
parent f8a8f6ac72
commit 2703b035a6
5 changed files with 61 additions and 3 deletions

View File

@ -9,9 +9,16 @@
{ "skill" : "leadership", "level": "basic" }, { "skill" : "leadership", "level": "basic" },
{ "skill" : "archery", "level": "basic" } { "skill" : "archery", "level": "basic" }
], ],
"specialties": "specialty" : [
[ {
{ "type":2, "val": 5, "subtype": 1, "info": 0 } "type" : "SECONDARY_SKILL_PREMY",
"subtype" : "skill.archery",
"valueType" : "PERCENT_TO_BASE",
"updater" : {
"type" : "GROWS_WITH_LEVEL",
"parameters" : [100]
}
}
] ]
}, },
"valeska": "valeska":

View File

@ -70,6 +70,23 @@
} }
] ]
}, },
"updater" : {
"description" : "updater",
"type" : "object",
"required" : ["type", "parameters"],
"additionalProperties" : false,
"properties" : {
"type" : {
"type" : "string",
"description" : "type"
},
"parameters": {
"type" : "array",
"description" : "parameters",
"additionalItems" : true
}
}
},
"sourceID": { "sourceID": {
"type":"number", "type":"number",
"description": "sourceID" "description": "sourceID"

View File

@ -1327,6 +1327,9 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus)
printField(effectRange); printField(effectRange);
#undef printField #undef printField
if(bonus.updater)
out << "\tUpdater: " << bonus.updater->toString() << "\n";
return out; return out;
} }
@ -1571,6 +1574,11 @@ IUpdater::~IUpdater()
{ {
} }
std::string IUpdater::toString() const
{
return typeid(*this).name();
}
ScalingUpdater::ScalingUpdater() : valPer20(0), stepSize(1) ScalingUpdater::ScalingUpdater() : valPer20(0), stepSize(1)
{ {
} }
@ -1596,6 +1604,13 @@ bool ScalingUpdater::update(Bonus & b, const CBonusSystemNode & context) const
return false; return false;
} }
std::string ScalingUpdater::toString() const
{
char buf[100];
sprintf(buf, "ScalingUpdater(valPer20=%d, stepSize=%d)", valPer20, stepSize);
return std::string(buf);
}
std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater) std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater)
{ {
updater = Updater; updater = Updater;

View File

@ -1024,6 +1024,7 @@ public:
virtual ~IUpdater(); virtual ~IUpdater();
virtual bool update(Bonus & b, const CBonusSystemNode & context) const = 0; virtual bool update(Bonus & b, const CBonusSystemNode & context) const = 0;
virtual std::string toString() const;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
@ -1046,4 +1047,5 @@ struct DLL_LINKAGE ScalingUpdater : public IUpdater
} }
bool update(Bonus & b, const CBonusSystemNode & context) const override; bool update(Bonus & b, const CBonusSystemNode & context) const override;
virtual std::string toString() const override;
}; };

View File

@ -603,6 +603,23 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
if (!value->isNull()) if (!value->isNull())
b->propagator = parseByMap(bonusPropagatorMap, value, "propagator type "); b->propagator = parseByMap(bonusPropagatorMap, value, "propagator type ");
value = &ability["updater"];
if (!value->isNull())
{
const JsonNode & updaterJson = *value;
if(updaterJson["type"].String() == "GROWS_WITH_LEVEL")
{
std::shared_ptr<ScalingUpdater> updater = std::make_shared<ScalingUpdater>();
const JsonVector param = updaterJson["parameters"].Vector();
updater->valPer20 = param[0].Float();
if(param.size() > 1)
updater->stepSize = param[1].Float();
b->addUpdater(updater);
}
else
logMod->warn("Unknown updater type \"%s\"", updaterJson["type"].String());
}
return true; return true;
} }