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:
parent
c4fdca45d9
commit
24efb9b413
@ -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")
|
if(targetType == "NO_TARGET")
|
||||||
spell->targetType = CSpell::NO_TARGET;
|
spell->targetType = CSpell::NO_TARGET;
|
||||||
@ -711,18 +711,16 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
|
|||||||
spell->targetType = CSpell::CREATURE;
|
spell->targetType = CSpell::CREATURE;
|
||||||
else if(targetType == "OBSTACLE")
|
else if(targetType == "OBSTACLE")
|
||||||
spell->targetType = CSpell::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();
|
spell->mainEffectAnim = json["anim"].Float();
|
||||||
|
|
||||||
for(const auto & counteredSpell: json["counters"].Struct())
|
for(const auto & counteredSpell: json["counters"].Struct())
|
||||||
if (counteredSpell.second.Bool())
|
if (counteredSpell.second.Bool())
|
||||||
{
|
{
|
||||||
JsonNode tmp(JsonNode::DATA_STRING);
|
VLC->modh->identifiers.requestIdentifier(json.meta, "spell", counteredSpell.first, [=](si32 id)
|
||||||
tmp.meta = json.meta;
|
{
|
||||||
tmp.String() = counteredSpell.first;
|
|
||||||
|
|
||||||
VLC->modh->identifiers.requestIdentifier(tmp,[=](si32 id){
|
|
||||||
spell->counteredSpells.push_back(SpellID(id));
|
spell->counteredSpells.push_back(SpellID(id));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -761,12 +759,12 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
|
|||||||
else if(!implicitPositiveness)
|
else if(!implicitPositiveness)
|
||||||
{
|
{
|
||||||
spell->positiveness = CSpell::NEUTRAL; //duplicates constructor but, just in case
|
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();
|
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);
|
auto it = bonusNameMap.find(name);
|
||||||
if(it == bonusNameMap.end())
|
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())
|
for(auto bonusData: json[name].Struct())
|
||||||
{
|
{
|
||||||
@ -796,24 +794,19 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode& json)
|
|||||||
readBonusStruct("limit", spell->limiters);
|
readBonusStruct("limit", spell->limiters);
|
||||||
readBonusStruct("absoluteLimit", spell->absoluteLimiters);
|
readBonusStruct("absoluteLimit", spell->absoluteLimiters);
|
||||||
|
|
||||||
|
|
||||||
const JsonNode & graphicsNode = json["graphics"];
|
const JsonNode & graphicsNode = json["graphics"];
|
||||||
|
|
||||||
spell->iconImmune = graphicsNode["iconImmune"].String();
|
spell->iconImmune = graphicsNode["iconImmune"].String();
|
||||||
spell->iconBook = graphicsNode["iconBook"].String();
|
spell->iconBook = graphicsNode["iconBook"].String();
|
||||||
spell->iconEffect = graphicsNode["iconEffect"].String();
|
spell->iconEffect = graphicsNode["iconEffect"].String();
|
||||||
spell->iconScenarioBonus = graphicsNode["iconScenarioBonus"].String();
|
spell->iconScenarioBonus = graphicsNode["iconScenarioBonus"].String();
|
||||||
spell->iconScroll = graphicsNode["iconScroll"].String();
|
spell->iconScroll = graphicsNode["iconScroll"].String();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const JsonNode & soundsNode = json["sounds"];
|
const JsonNode & soundsNode = json["sounds"];
|
||||||
|
|
||||||
spell->castSound = soundsNode["cast"].String();
|
spell->castSound = soundsNode["cast"].String();
|
||||||
|
|
||||||
|
|
||||||
//load level attributes
|
//load level attributes
|
||||||
|
|
||||||
const int levelsCount = GameConstants::SPELL_SCHOOL_LEVELS;
|
const int levelsCount = GameConstants::SPELL_SCHOOL_LEVELS;
|
||||||
|
|
||||||
for(int levelIndex = 0; levelIndex < levelsCount; levelIndex++)
|
for(int levelIndex = 0; levelIndex < levelsCount; levelIndex++)
|
||||||
@ -877,7 +870,6 @@ void CSpellHandler::beforeValidate(JsonNode & object)
|
|||||||
inheritNode("basic");
|
inheritNode("basic");
|
||||||
inheritNode("advanced");
|
inheritNode("advanced");
|
||||||
inheritNode("expert");
|
inheritNode("expert");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user