Browse Source

SpellHandler: add more error checking + cleanup.

AlexVinS 11 years ago
parent
commit
24efb9b413
1 changed files with 12 additions and 20 deletions
  1. 12 20
      lib/CSpellHandler.cpp

+ 12 - 20
lib/CSpellHandler.cpp

@@ -703,7 +703,7 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 		});
 	}
 
-	auto targetType = json["targetType"].String();
+	const std::string targetType = json["targetType"].String();
 
 	if(targetType == "NO_TARGET")
 		spell->targetType = CSpell::NO_TARGET;
@@ -711,18 +711,16 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 		spell->targetType = CSpell::CREATURE;
 	else if(targetType == "OBSTACLE")
 		spell->targetType = CSpell::OBSTACLE;
-
+	else 
+		logGlobal->warnStream() << "Spell " << spell->name << ". Target type " << (targetType.empty() ? "empty" : "unknown ("+targetType+")") << ". Assumed NO_TARGET.";
 
 	spell->mainEffectAnim = json["anim"].Float();
 
 	for(const auto & counteredSpell: json["counters"].Struct())
 		if (counteredSpell.second.Bool())
 		{
-			JsonNode tmp(JsonNode::DATA_STRING);
-			tmp.meta = json.meta;
-			tmp.String() = counteredSpell.first;
-
-			VLC->modh->identifiers.requestIdentifier(tmp,[=](si32 id){
+			VLC->modh->identifiers.requestIdentifier(json.meta, "spell", counteredSpell.first, [=](si32 id)
+			{
 				spell->counteredSpells.push_back(SpellID(id));
 			});
 		}
@@ -761,12 +759,12 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 	else if(!implicitPositiveness)
 	{
 		spell->positiveness = CSpell::NEUTRAL; //duplicates constructor but, just in case
-		logGlobal->errorStream() << "No positiveness specified, assumed NEUTRAL";
+		logGlobal->warnStream() << "Spell " << spell->name << ": no positiveness specified, assumed NEUTRAL";
 	}
 
 	spell->isSpecial = flags["special"].Bool();
 
-	auto findBonus = [&](std::string name, std::vector<Bonus::BonusType> &vec)
+	auto findBonus = [&](const std::string & name, std::vector<Bonus::BonusType> &vec)
 	{
 		auto it = bonusNameMap.find(name);
 		if(it == bonusNameMap.end())
@@ -779,7 +777,7 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 		}
 	};
 
-	auto readBonusStruct = [&](std::string name, std::vector<Bonus::BonusType> &vec)
+	auto readBonusStruct = [&](const std::string & name, std::vector<Bonus::BonusType> &vec)
 	{
 		for(auto bonusData: json[name].Struct())
 		{
@@ -796,24 +794,19 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
 	readBonusStruct("limit", spell->limiters);	
 	readBonusStruct("absoluteLimit", spell->absoluteLimiters);
 
-
 	const JsonNode & graphicsNode = json["graphics"];
 
-	spell->iconImmune = graphicsNode["iconImmune"].String();
-	spell->iconBook = graphicsNode["iconBook"].String();
-	spell->iconEffect = graphicsNode["iconEffect"].String();
+	spell->iconImmune =        graphicsNode["iconImmune"].String();
+	spell->iconBook =          graphicsNode["iconBook"].String();
+	spell->iconEffect =        graphicsNode["iconEffect"].String();
 	spell->iconScenarioBonus = graphicsNode["iconScenarioBonus"].String();
-	spell->iconScroll = graphicsNode["iconScroll"].String();
-
-
+	spell->iconScroll =        graphicsNode["iconScroll"].String();
 
 	const JsonNode & soundsNode = json["sounds"];
 
 	spell->castSound = soundsNode["cast"].String();
 
-
 	//load level attributes
-
 	const int levelsCount = GameConstants::SPELL_SCHOOL_LEVELS;
 
 	for(int levelIndex = 0; levelIndex < levelsCount; levelIndex++)
@@ -877,7 +870,6 @@ void CSpellHandler::beforeValidate(JsonNode & object)
 	inheritNode("basic");
 	inheritNode("advanced");
 	inheritNode("expert");
-
 }