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