mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Fix conflicts with templates loaded from mods
This commit is contained in:
parent
bf2c9237b2
commit
8d9489c368
@ -117,14 +117,6 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData()
|
||||
|
||||
std::pair key(tmpl->id, tmpl->subid);
|
||||
legacyTemplates.insert(std::make_pair(key, tmpl));
|
||||
|
||||
if (!tmpl->isVisitable())
|
||||
{
|
||||
if (tmpl->id != Obj::RIVER_DELTA)
|
||||
{
|
||||
VLC->biomeHandler->addTemplate("core", tmpl->stringID, tmpl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
objects.resize(256);
|
||||
@ -222,14 +214,18 @@ TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::strin
|
||||
|
||||
for (auto & templ : createdObject->getTemplates())
|
||||
{
|
||||
// Register templates for new objects
|
||||
// Register templates for new objects from mods
|
||||
VLC->biomeHandler->addTemplate(scope, templ->stringID, templ);
|
||||
}
|
||||
|
||||
auto range = legacyTemplates.equal_range(std::make_pair(obj->id, index));
|
||||
for (auto & templ : boost::make_iterator_range(range.first, range.second))
|
||||
{
|
||||
// Register legacy templates as "core"
|
||||
VLC->biomeHandler->addTemplate("core", templ.second->stringID, templ.second);
|
||||
// FIXME: Why does it clear stringID?
|
||||
createdObject->addTemplate(templ.second);
|
||||
|
||||
}
|
||||
legacyTemplates.erase(range.first, range.second);
|
||||
|
||||
|
@ -182,7 +182,6 @@ std::vector<ObstacleSet::EObstacleType> ObstacleSetFilter::getAllowedTypes() con
|
||||
|
||||
std::vector<JsonNode> ObstacleSetHandler::loadLegacyData()
|
||||
{
|
||||
// TODO: Where to load objects.json?
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -212,7 +211,6 @@ void ObstacleSetHandler::loadObject(std::string scope, std::string name, const J
|
||||
{
|
||||
logMod->error("Failed to load obstacle set: %s", name);
|
||||
}
|
||||
// TODO:
|
||||
VLC->identifiersHandler->registerObject(scope, "biome", name, biomes.at(index)->id);
|
||||
}
|
||||
|
||||
@ -235,17 +233,12 @@ std::shared_ptr<ObstacleSet> ObstacleSetHandler::loadFromJson(const std::string
|
||||
auto templates = json["templates"].Vector();
|
||||
for (const auto & node : templates)
|
||||
{
|
||||
// TODO: We need to store all the templates by their name
|
||||
// TODO: We need to store all the templates by their id
|
||||
logGlobal->info("Registering obstacle template: %s in scope %s", node.String(), scope);
|
||||
|
||||
logGlobal->info("Registering obstacle template: %s", node.String());
|
||||
/*
|
||||
FIXME:
|
||||
Warning: identifier AVXplns0 is not in camelCase!
|
||||
registered biome.templateSet1 as core:1701602145
|
||||
*/
|
||||
|
||||
VLC->identifiers()->requestIdentifier(scope, "obstacleTemplate", node.String(), [this, os](si32 id)
|
||||
auto identifier = boost::algorithm::to_lower_copy(node.String());
|
||||
|
||||
// FIXME: Identifier 'avlswn02' exists in mod 'hota.mapdecorations' but identifier was explicitly requested from mod 'hota.mapdecorations'!
|
||||
VLC->identifiers()->requestIdentifier(scope, "obstacleTemplate", identifier, [this, os](si32 id)
|
||||
{
|
||||
logGlobal->info("Resolved obstacle id: %d", id);
|
||||
os->addObstacle(obstacleTemplates[id]);
|
||||
@ -259,17 +252,24 @@ void ObstacleSetHandler::addTemplate(const std::string & scope, const std::strin
|
||||
{
|
||||
auto id = obstacleTemplates.size();
|
||||
|
||||
auto strippedName = name;
|
||||
auto strippedName = boost::algorithm::to_lower_copy(name);
|
||||
auto pos = strippedName.find(".def");
|
||||
if(pos != std::string::npos)
|
||||
strippedName.erase(pos, 4);
|
||||
|
||||
// TODO: Consider converting to lowercase?
|
||||
// Save by name
|
||||
VLC->identifiersHandler->registerObject(scope, "obstacleTemplate", strippedName, id);
|
||||
if (VLC->identifiersHandler->getIdentifier(scope, "obstacleTemplate", strippedName, true))
|
||||
{
|
||||
logMod->warn("Duplicate obstacle template: %s", strippedName);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save by name
|
||||
VLC->identifiersHandler->registerObject(scope, "obstacleTemplate", strippedName, id);
|
||||
|
||||
// Index by id
|
||||
obstacleTemplates[id] = tmpl;
|
||||
// Index by id
|
||||
obstacleTemplates[id] = tmpl;
|
||||
}
|
||||
}
|
||||
|
||||
void ObstacleSetHandler::addObstacleSet(std::shared_ptr<ObstacleSet> os)
|
||||
|
Loading…
Reference in New Issue
Block a user