1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

SpellHandler: add more error checking + cleanup.

This commit is contained in:
AlexVinS 2014-11-12 03:27:45 +03:00
parent c4fdca45d9
commit 24efb9b413

View File

@ -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");
}