mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Fix conflicts with templates loaded from mods
This commit is contained in:
@ -117,14 +117,6 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData()
|
|||||||
|
|
||||||
std::pair key(tmpl->id, tmpl->subid);
|
std::pair key(tmpl->id, tmpl->subid);
|
||||||
legacyTemplates.insert(std::make_pair(key, tmpl));
|
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);
|
objects.resize(256);
|
||||||
@ -222,14 +214,18 @@ TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::strin
|
|||||||
|
|
||||||
for (auto & templ : createdObject->getTemplates())
|
for (auto & templ : createdObject->getTemplates())
|
||||||
{
|
{
|
||||||
// Register templates for new objects
|
// Register templates for new objects from mods
|
||||||
VLC->biomeHandler->addTemplate(scope, templ->stringID, templ);
|
VLC->biomeHandler->addTemplate(scope, templ->stringID, templ);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto range = legacyTemplates.equal_range(std::make_pair(obj->id, index));
|
auto range = legacyTemplates.equal_range(std::make_pair(obj->id, index));
|
||||||
for (auto & templ : boost::make_iterator_range(range.first, range.second))
|
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);
|
createdObject->addTemplate(templ.second);
|
||||||
|
|
||||||
}
|
}
|
||||||
legacyTemplates.erase(range.first, range.second);
|
legacyTemplates.erase(range.first, range.second);
|
||||||
|
|
||||||
|
@ -182,7 +182,6 @@ std::vector<ObstacleSet::EObstacleType> ObstacleSetFilter::getAllowedTypes() con
|
|||||||
|
|
||||||
std::vector<JsonNode> ObstacleSetHandler::loadLegacyData()
|
std::vector<JsonNode> ObstacleSetHandler::loadLegacyData()
|
||||||
{
|
{
|
||||||
// TODO: Where to load objects.json?
|
|
||||||
return {};
|
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);
|
logMod->error("Failed to load obstacle set: %s", name);
|
||||||
}
|
}
|
||||||
// TODO:
|
|
||||||
VLC->identifiersHandler->registerObject(scope, "biome", name, biomes.at(index)->id);
|
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();
|
auto templates = json["templates"].Vector();
|
||||||
for (const auto & node : templates)
|
for (const auto & node : templates)
|
||||||
{
|
{
|
||||||
// TODO: We need to store all the templates by their name
|
logGlobal->info("Registering obstacle template: %s in scope %s", node.String(), scope);
|
||||||
// TODO: We need to store all the templates by their id
|
|
||||||
|
|
||||||
logGlobal->info("Registering obstacle template: %s", node.String());
|
auto identifier = boost::algorithm::to_lower_copy(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)
|
// 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);
|
logGlobal->info("Resolved obstacle id: %d", id);
|
||||||
os->addObstacle(obstacleTemplates[id]);
|
os->addObstacle(obstacleTemplates[id]);
|
||||||
@ -259,18 +252,25 @@ void ObstacleSetHandler::addTemplate(const std::string & scope, const std::strin
|
|||||||
{
|
{
|
||||||
auto id = obstacleTemplates.size();
|
auto id = obstacleTemplates.size();
|
||||||
|
|
||||||
auto strippedName = name;
|
auto strippedName = boost::algorithm::to_lower_copy(name);
|
||||||
auto pos = strippedName.find(".def");
|
auto pos = strippedName.find(".def");
|
||||||
if(pos != std::string::npos)
|
if(pos != std::string::npos)
|
||||||
strippedName.erase(pos, 4);
|
strippedName.erase(pos, 4);
|
||||||
|
|
||||||
// TODO: Consider converting to lowercase?
|
if (VLC->identifiersHandler->getIdentifier(scope, "obstacleTemplate", strippedName, true))
|
||||||
|
{
|
||||||
|
logMod->warn("Duplicate obstacle template: %s", strippedName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Save by name
|
// Save by name
|
||||||
VLC->identifiersHandler->registerObject(scope, "obstacleTemplate", strippedName, id);
|
VLC->identifiersHandler->registerObject(scope, "obstacleTemplate", strippedName, id);
|
||||||
|
|
||||||
// Index by id
|
// Index by id
|
||||||
obstacleTemplates[id] = tmpl;
|
obstacleTemplates[id] = tmpl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ObstacleSetHandler::addObstacleSet(std::shared_ptr<ObstacleSet> os)
|
void ObstacleSetHandler::addObstacleSet(std::shared_ptr<ObstacleSet> os)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user