1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Basic version of object templates mapping

This commit is contained in:
Ivan Savenko
2023-05-24 22:02:27 +03:00
parent b3ca6c8cee
commit 952708e865
4 changed files with 86 additions and 15 deletions

View File

@@ -15,6 +15,8 @@
#include "../VCMI_Lib.h"
#include "../CModHandler.h"
#include "../CTownHandler.h"
#include "../mapObjects/CObjectClassesHandler.h"
#include "../filesystem/Filesystem.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -50,6 +52,42 @@ void MapIdentifiersH3M::loadMapping(const JsonNode & mapping)
}
}
for (auto entryTemplate : mapping["templates"].Struct())
{
std::string h3mName = entryTemplate.second.String();
std::string vcmiName = entryTemplate.first;
if (!CResourceHandler::get()->existsResource(ResourceID( "SPRITES/" + vcmiName, EResType::ANIMATION)))
logMod->warn("Template animation file %s was not found!", vcmiName);
mappingObjectTemplate[h3mName] = vcmiName;
}
for (auto entryOuter : mapping["objects"].Struct())
{
if (entryOuter.second.isStruct())
{
for (auto entryInner : entryOuter.second.Struct())
{
auto handler = VLC->objtypeh->getHandlerFor( VLC->modh->scopeGame(), entryOuter.first, entryInner.first);
auto entryValues = entryInner.second.Vector();
ObjectTypeIdentifier h3mID{Obj(entryValues[0].Integer()), int32_t(entryValues[1].Integer())};
ObjectTypeIdentifier vcmiID{Obj(handler->getIndex()), handler->getSubIndex()};
mappingObjectIndex[h3mID] = vcmiID;
}
}
else
{
auto handler = VLC->objtypeh->getHandlerFor( VLC->modh->scopeGame(), entryOuter.first, entryOuter.first);
auto entryValues = entryOuter.second.Vector();
ObjectTypeIdentifier h3mID{Obj(entryValues[0].Integer()), int32_t(entryValues[1].Integer())};
ObjectTypeIdentifier vcmiID{Obj(handler->getIndex()), handler->getSubIndex()};
mappingObjectIndex[h3mID] = vcmiID;
}
}
mappingBuilding = loadMapping<BuildingID>(mapping["buildingsCommon"], "building.core:random");
mappingFaction = loadMapping<FactionID>(mapping["factions"], "faction");
mappingCreature = loadMapping<CreatureID>(mapping["creatures"], "creature");
@@ -60,6 +98,23 @@ void MapIdentifiersH3M::loadMapping(const JsonNode & mapping)
mappingSecondarySkill = loadMapping<SecondarySkill>(mapping["skills"], "skill");
}
void MapIdentifiersH3M::remapTemplate(ObjectTemplate & objectTemplate)
{
std::string name = boost::to_lower_copy(objectTemplate.animationFile);
if (mappingObjectTemplate.count(name))
objectTemplate.animationFile = mappingObjectTemplate.at(name);
ObjectTypeIdentifier objectType{ objectTemplate.id, objectTemplate.subid};
if (mappingObjectIndex.count(objectType))
{
auto mappedType = mappingObjectIndex.at(objectType);
objectTemplate.id = mappedType.ID;
objectTemplate.subid = mappedType.subID;
}
}
BuildingID MapIdentifiersH3M::remapBuilding(std::optional<FactionID> owner, BuildingID input) const
{
if (owner.has_value() && mappingFactionBuilding.count(*owner))