1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00

Show error message on load if mod has broken creature instead of

crashing on creature window screen
This commit is contained in:
Ivan Savenko
2024-06-01 11:49:51 +00:00
parent f39aaf2495
commit b50d350747
2 changed files with 15 additions and 3 deletions

View File

@@ -646,10 +646,15 @@ CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const Json
registerObject(scope, type_name, extraName.String(), cre->getIndex());
}
if (!cre->special &&
!CResourceHandler::get()->existsResource(cre->animDefName) &&
!CResourceHandler::get()->existsResource(cre->animDefName.addPrefix("SPRITES/")))
throw ModLoadingException(scope, "creature " + cre->getJsonKey() + " has no combat animation but is not marked as special!" );
JsonNode advMapFile = node["graphics"]["map"];
JsonNode advMapMask = node["graphics"]["mapMask"];
VLC->identifiers()->requestIdentifier(scope, "object", "monster", [cre, scope, advMapFile, advMapMask](si32 index)
VLC->identifiers()->requestIdentifier(scope, "object", "monster", [cre, scope, advMapFile, advMapMask](si32 monsterIndex)
{
JsonNode conf;
conf.setModScope(scope);
@@ -672,7 +677,7 @@ CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const Json
if (VLC->objtypeh->getHandlerFor(Obj::MONSTER, cre->getId().num)->getTemplates().empty())
{
if (!cre->special)
throw DataLoadingException("Mod " + scope + " is corrupted! Please disable or reinstall this mod. Reason: creature " + cre->getJsonKey() + " has no adventure map animation but is not marked as special!" );
throw ModLoadingException(scope, "creature " + cre->getJsonKey() + " has no adventure map animation but is not marked as special!" );
VLC->objtypeh->removeSubObject(Obj::MONSTER, cre->getId().num);
}
@@ -737,7 +742,6 @@ void CCreatureHandler::loadCrExpMod()
}
}
void CCreatureHandler::loadCrExpBon(CBonusSystemNode & globalEffects)
{
if (VLC->settings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE)) //reading default stack experience bonuses

View File

@@ -14,3 +14,11 @@ class DLL_LINKAGE DataLoadingException: public std::runtime_error
public:
using std::runtime_error::runtime_error;
};
class DLL_LINKAGE ModLoadingException: public DataLoadingException
{
public:
ModLoadingException(const std::string & modName, const std::string & reason)
: DataLoadingException("Mod " + modName + " is corrupted! Please disable or reinstall this mod. Reason: " + reason)
{}
};