mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Minor fixes, no more missing objects & templates
This commit is contained in:
parent
7e057b6df8
commit
e9b41cd3c6
@ -660,6 +660,9 @@ void CArtHandler::afterLoadFinalization()
|
||||
// Necessary for objects added via mods that don't have any templates in H3
|
||||
VLC->objtypeh->getHandlerFor(Obj::ARTIFACT, art->id)->addTemplate(templ);
|
||||
}
|
||||
// object does not have any templates - this is not usable object (e.g. pseudo-art like lock)
|
||||
if (VLC->objtypeh->getHandlerFor(Obj::ARTIFACT, art->id)->getTemplates().empty())
|
||||
VLC->objtypeh->eraseObject(Obj::ARTIFACT, art->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1123,6 +1123,10 @@ void CCreatureHandler::afterLoadFinalization()
|
||||
templ["animation"].String() = crea->advMapDef;
|
||||
VLC->objtypeh->getHandlerFor(Obj::MONSTER, crea->idNumber)->addTemplate(templ);
|
||||
}
|
||||
|
||||
// object does not have any templates - this is not usable object (e.g. pseudo-creature like Arrow Tower)
|
||||
if (VLC->objtypeh->getHandlerFor(Obj::MONSTER, crea->idNumber.num)->getTemplates().empty())
|
||||
VLC->objtypeh->eraseObject(Obj::MONSTER, crea->idNumber.num);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -391,7 +391,7 @@ CObjectClassesHandler::CObjectClassesHandler()
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
void readTextFile(Container objects, std::string path)
|
||||
void readTextFile(Container & objects, std::string path)
|
||||
{
|
||||
CLegacyConfigParser parser(path);
|
||||
size_t totalNumber = parser.readNumber(); // first line contains number of objects to read and nothing else
|
||||
@ -449,10 +449,14 @@ void CObjectClassesHandler::loadObjectEntry(const JsonNode & entry, ObjectContai
|
||||
|
||||
if (handler->getTemplates().empty())
|
||||
{
|
||||
auto range = legacyTemplates.equal_range(std::make_pair(obj->id, si32(entry["index"].Float())));
|
||||
auto range = legacyTemplates.equal_range(std::make_pair(obj->id, id));
|
||||
for (auto & templ : boost::make_iterator_range(range.first, range.second))
|
||||
{
|
||||
handler->addTemplate(templ.second);
|
||||
}
|
||||
legacyTemplates.erase(range.first, range.second);
|
||||
}
|
||||
|
||||
obj->objects[id] = handler;
|
||||
}
|
||||
|
||||
@ -500,6 +504,13 @@ void CObjectClassesHandler::createObject(std::string name, JsonNode config, si32
|
||||
loadObjectEntry(config, objects[ID]);
|
||||
}
|
||||
|
||||
void CObjectClassesHandler::eraseObject(si32 ID, si32 subID)
|
||||
{
|
||||
assert(objects.count(ID));
|
||||
assert(objects.at(ID)->objects.count(subID));
|
||||
objects.at(ID)->objects.erase(subID);
|
||||
}
|
||||
|
||||
std::vector<bool> CObjectClassesHandler::getDefaultAllowed() const
|
||||
{
|
||||
return std::vector<bool>(); //TODO?
|
||||
@ -532,6 +543,14 @@ void CObjectClassesHandler::beforeValidate(JsonNode & object)
|
||||
void CObjectClassesHandler::afterLoadFinalization()
|
||||
{
|
||||
legacyTemplates.clear(); // whatever left there is no longer needed
|
||||
for (auto entry : objects)
|
||||
{
|
||||
for (auto obj : entry.second->objects)
|
||||
{
|
||||
if (obj.second->getTemplates().empty())
|
||||
logGlobal->warnStream() << "No templates found for " << entry.first << ":" << obj.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string CObjectClassesHandler::getObjectName(si32 type) const
|
||||
|
@ -214,6 +214,7 @@ public:
|
||||
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
|
||||
|
||||
void createObject(std::string name, JsonNode config, si32 ID, boost::optional<si32> subID = boost::optional<si32>());
|
||||
void eraseObject(si32 ID, si32 subID);
|
||||
|
||||
void beforeValidate(JsonNode & object) override;
|
||||
void afterLoadFinalization() override;
|
||||
|
Loading…
Reference in New Issue
Block a user