mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +02:00
Bonuse::toJsonNode uses string constants for type/subtype
This commit is contained in:
parent
c79b776f3c
commit
05838b3827
12
Global.h
12
Global.h
@ -369,6 +369,18 @@ namespace vstd
|
|||||||
return std::find(c.begin(),c.end(),i);
|
return std::find(c.begin(),c.end(),i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//returns first key that maps to given value if present, returns success via found if provided
|
||||||
|
template <typename Key, typename T>
|
||||||
|
Key findKey(const std::map<Key, T> & map, const T & value, bool * found = nullptr)
|
||||||
|
{
|
||||||
|
for(auto iter = map.cbegin(); iter != map.cend(); iter++)
|
||||||
|
{
|
||||||
|
if(iter->second == value)
|
||||||
|
return iter->first;
|
||||||
|
}
|
||||||
|
return Key();
|
||||||
|
}
|
||||||
|
|
||||||
//removes element i from container c, returns false if c does not contain i
|
//removes element i from container c, returns false if c does not contain i
|
||||||
template <typename Container, typename Item>
|
template <typename Container, typename Item>
|
||||||
typename Container::size_type operator-=(Container &c, const Item &i)
|
typename Container::size_type operator-=(Container &c, const Item &i)
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "CSkillHandler.h"
|
#include "CSkillHandler.h"
|
||||||
#include "CStack.h"
|
#include "CStack.h"
|
||||||
#include "CArtHandler.h"
|
#include "CArtHandler.h"
|
||||||
|
#include "StringConstants.h"
|
||||||
|
|
||||||
#define FOREACH_PARENT(pname) TNodes lparents; getParents(lparents); for(CBonusSystemNode *pname : lparents)
|
#define FOREACH_PARENT(pname) TNodes lparents; getParents(lparents); for(CBonusSystemNode *pname : lparents)
|
||||||
#define FOREACH_CPARENT(pname) TCNodes lparents; getParents(lparents); for(const CBonusSystemNode *pname : lparents)
|
#define FOREACH_CPARENT(pname) TCNodes lparents; getParents(lparents); for(const CBonusSystemNode *pname : lparents)
|
||||||
@ -1163,17 +1164,37 @@ std::string Bonus::Description() const
|
|||||||
return str.str();
|
return str.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonNode subtypeToJson(Bonus::BonusType type, int subtype)
|
||||||
|
{
|
||||||
|
JsonNode node;
|
||||||
|
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case Bonus::PRIMARY_SKILL:
|
||||||
|
node.String() = PrimarySkill::names[subtype];
|
||||||
|
break;
|
||||||
|
case Bonus::SECONDARY_SKILL_PREMY:
|
||||||
|
node.String() = NSecondarySkill::names[subtype];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
node.Integer() = subtype;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
JsonNode Bonus::toJsonNode() const
|
JsonNode Bonus::toJsonNode() const
|
||||||
{
|
{
|
||||||
JsonNode root(JsonNode::DATA_STRUCT);
|
JsonNode root(JsonNode::DATA_STRUCT);
|
||||||
|
|
||||||
root["type"].Float() = type;
|
root["type"].String() = vstd::findKey(bonusNameMap, type);
|
||||||
if(subtype != -1)
|
if(subtype != -1)
|
||||||
root["subtype"].Float() = subtype;
|
root["subtype"] = subtypeToJson(type, subtype);
|
||||||
if(val != 0)
|
if(val != 0)
|
||||||
root["val"].Float() = val;
|
root["val"].Integer() = val;
|
||||||
if(valType != ADDITIVE_VALUE)
|
if(valType != ADDITIVE_VALUE)
|
||||||
root["valType"].Float() = valType;
|
root["valType"].String() = vstd::findKey(bonusValueMap, valType);
|
||||||
if(limiter)
|
if(limiter)
|
||||||
root["limiter"] = limiter->toJsonNode();
|
root["limiter"] = limiter->toJsonNode();
|
||||||
if(updater)
|
if(updater)
|
||||||
|
@ -611,9 +611,9 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
|
|||||||
{
|
{
|
||||||
std::shared_ptr<ScalingUpdater> updater = std::make_shared<ScalingUpdater>();
|
std::shared_ptr<ScalingUpdater> updater = std::make_shared<ScalingUpdater>();
|
||||||
const JsonVector param = updaterJson["parameters"].Vector();
|
const JsonVector param = updaterJson["parameters"].Vector();
|
||||||
updater->valPer20 = param[0].Float();
|
updater->valPer20 = param[0].Integer();
|
||||||
if(param.size() > 1)
|
if(param.size() > 1)
|
||||||
updater->stepSize = param[1].Float();
|
updater->stepSize = param[1].Integer();
|
||||||
b->addUpdater(updater);
|
b->addUpdater(updater);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user