mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Cleanup
* simplify JSON values getting * ensure initialization of Bonus fields
This commit is contained in:
parent
9e7fe4d011
commit
f686edc1b8
@ -23,17 +23,13 @@
|
|||||||
|
|
||||||
static inline void jsonSetString(const JsonNode& source, const std::string& name, std::string& dest)
|
static inline void jsonSetString(const JsonNode& source, const std::string& name, std::string& dest)
|
||||||
{
|
{
|
||||||
const JsonNode& val = source[name];
|
dest = source[name].String();//null->empty string
|
||||||
if(!val.isNull())
|
|
||||||
{
|
|
||||||
dest = val.String();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void jsonSetBool(const JsonNode& source, const std::string& name, bool& dest)
|
static inline void jsonSetBool(const JsonNode& source, const std::string& name, bool& dest)
|
||||||
{
|
{
|
||||||
const JsonNode& val = source[name];
|
const JsonNode& val = source[name];
|
||||||
if(!val.isNull())
|
if(!val.isNull()) //do not rely on default value
|
||||||
{
|
{
|
||||||
dest = val.Bool();
|
dest = val.Bool();
|
||||||
}
|
}
|
||||||
|
@ -532,9 +532,7 @@ void CSpellHandler::load()
|
|||||||
const JsonNode & graphicsNode = spell.second["graphics"];
|
const JsonNode & graphicsNode = spell.second["graphics"];
|
||||||
if (!graphicsNode.isNull())
|
if (!graphicsNode.isNull())
|
||||||
{
|
{
|
||||||
const JsonNode& iconImmune = graphicsNode["iconImmune"];
|
s->iconImmune = graphicsNode["iconImmune"].String();
|
||||||
if (!iconImmune.isNull())
|
|
||||||
s->iconImmune = iconImmune.String();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1148,11 +1148,16 @@ Bonus::Bonus(ui16 Dur, BonusType Type, BonusSource Src, si32 Val, ui32 ID, si32
|
|||||||
|
|
||||||
Bonus::Bonus()
|
Bonus::Bonus()
|
||||||
{
|
{
|
||||||
|
duration = PERMANENT;
|
||||||
|
turnsRemain = 0;
|
||||||
|
type = NONE;
|
||||||
subtype = -1;
|
subtype = -1;
|
||||||
additionalInfo = -1;
|
additionalInfo = -1;
|
||||||
turnsRemain = 0;
|
|
||||||
valType = ADDITIVE_VALUE;
|
valType = ADDITIVE_VALUE;
|
||||||
effectRange = NO_LIMIT;
|
effectRange = NO_LIMIT;
|
||||||
|
val = 0;
|
||||||
|
source = OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bonus::~Bonus()
|
Bonus::~Bonus()
|
||||||
|
@ -965,9 +965,7 @@ Bonus * JsonUtils::parseBonus (const JsonNode &ability)
|
|||||||
|
|
||||||
resolveIdentifier (b->subtype, ability, "subtype");
|
resolveIdentifier (b->subtype, ability, "subtype");
|
||||||
|
|
||||||
value = &ability["val"];
|
b->val = ability["val"].Float();
|
||||||
if (!value->isNull())
|
|
||||||
b->val = value->Float();
|
|
||||||
|
|
||||||
value = &ability["valueType"];
|
value = &ability["valueType"];
|
||||||
if (!value->isNull())
|
if (!value->isNull())
|
||||||
@ -975,17 +973,11 @@ Bonus * JsonUtils::parseBonus (const JsonNode &ability)
|
|||||||
|
|
||||||
resolveIdentifier (b->additionalInfo, ability, "addInfo");
|
resolveIdentifier (b->additionalInfo, ability, "addInfo");
|
||||||
|
|
||||||
value = &ability["turns"];
|
b->turnsRemain = ability["turns"].Float();
|
||||||
if (!value->isNull())
|
|
||||||
b->turnsRemain = value->Float();
|
|
||||||
|
|
||||||
value = &ability["sourceID"];
|
b->sid = ability["sourceID"].Float();
|
||||||
if (!value->isNull())
|
|
||||||
b->sid = value->Float();
|
|
||||||
|
|
||||||
value = &ability["description"];
|
b->description = ability["description"].String();
|
||||||
if (!value->isNull())
|
|
||||||
b->description = value->String();
|
|
||||||
|
|
||||||
value = &ability["effectRange"];
|
value = &ability["effectRange"];
|
||||||
if (!value->isNull())
|
if (!value->isNull())
|
||||||
|
Loading…
Reference in New Issue
Block a user