1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #3304 from IvanSavenko/handle_unknown_objects

Handle unknown objects
This commit is contained in:
Ivan Savenko 2023-12-11 18:23:28 +02:00 committed by GitHub
commit a3786f3357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 7 deletions

View File

@ -935,5 +935,16 @@
"grassHills" : { "index" :208, "handler": "static", "types" : { "object" : { "index" : 0} } },
"roughHills" : { "index" :209, "handler": "static", "types" : { "object" : { "index" : 0} } },
"subterraneanRocks" : { "index" :210, "handler": "static", "types" : { "object" : { "index" : 0} } },
"swampFoliage" : { "index" :211, "handler": "static", "types" : { "object" : { "index" : 0} } }
"swampFoliage" : { "index" :211, "handler": "static", "types" : { "object" : { "index" : 0} } },
/// special object to handle invalid / unknown objects on some user-made maps
"nothing" : {
"index" : 0,
"handler": "generic",
"types" : {
"nothing" : {
"index" : 0
}
}
}
}

View File

@ -312,6 +312,9 @@ TObjectTypeHandler CObjectClassesHandler::getHandlerFor(MapObjectID type, MapObj
{
try
{
if (objects.at(type.getNum()) == nullptr)
return objects.front()->objects.front();
auto result = objects.at(type.getNum())->objects.at(subtype.getNum());
if (result != nullptr)
@ -467,8 +470,11 @@ std::string CObjectClassesHandler::getObjectName(MapObjectID type, MapObjectSubI
const auto handler = getHandlerFor(type, subtype);
if (handler && handler->hasNameTextID())
return handler->getNameTranslated();
else
if (objects[type.getNum()])
return objects[type.getNum()]->getNameTranslated();
return objects.front()->getNameTranslated();
}
SObjectSounds CObjectClassesHandler::getObjectSounds(MapObjectID type, MapObjectSubID subtype) const
@ -480,19 +486,27 @@ SObjectSounds CObjectClassesHandler::getObjectSounds(MapObjectID type, MapObject
if(type == Obj::PRISON || type == Obj::HERO || type == Obj::SPELL_SCROLL)
subtype = 0;
assert(objects[type.getNum()]);
if(objects[type.getNum()])
return getHandlerFor(type, subtype)->getSounds();
else
return objects.front()->objects.front()->getSounds();
}
std::string CObjectClassesHandler::getObjectHandlerName(MapObjectID type) const
{
if (objects.at(type.getNum()))
return objects.at(type.getNum())->handlerName;
else
return objects.front()->handlerName;
}
std::string CObjectClassesHandler::getJsonKey(MapObjectID type) const
{
if (objects.at(type.getNum()) != nullptr)
return objects.at(type.getNum())->getJsonKey();
logGlobal->warn("Unknown object of type %d!", type);
return objects.front()->getJsonKey();
}
VCMI_LIB_NAMESPACE_END