Respect gdt parents when converting to infostring

This commit is contained in:
Jan 2021-03-28 12:21:47 +02:00
parent 579c0747d0
commit a42f75c85e
10 changed files with 37 additions and 18 deletions

View File

@ -2,6 +2,7 @@
#include <sstream>
#include <cstring>
#include <stack>
const std::string InfoString::EMPTY_VALUE;
@ -196,20 +197,38 @@ bool InfoString::FromStream(const std::string& prefix, std::istream& stream)
return true;
}
bool InfoString::FromGdtProperties(const std::string& prefix, const GdtEntry& gdtEntry)
bool InfoString::FromGdtProperties(const GdtEntry& gdtEntry)
{
const auto foundPrefixEntry = gdtEntry.m_properties.find(GDT_PREFIX_FIELD);
if (foundPrefixEntry == gdtEntry.m_properties.end() || foundPrefixEntry->second != prefix)
return false;
std::stack<const GdtEntry*> entryStack;
for(const auto& [key, value] : gdtEntry.m_properties)
{
if(key == GDT_PREFIX_FIELD)
continue;
const auto* currentEntry = &gdtEntry;
while (currentEntry)
{
entryStack.push(&gdtEntry);
currentEntry = gdtEntry.m_parent;
}
}
while(!entryStack.empty())
{
const auto* currentEntry = entryStack.top();
entryStack.pop();
for (const auto& [key, value] : currentEntry->m_properties)
{
auto existingEntry = m_values.find(key);
if(existingEntry == m_values.end())
{
m_keys_by_insertion.push_back(key);
m_values.emplace(std::make_pair(key, value));
}
else
{
existingEntry->second = value;
}
}
}
return true;
}

View File

@ -28,5 +28,5 @@ public:
bool FromStream(std::istream& stream);
bool FromStream(const std::string& prefix, std::istream& stream);
bool FromGdtProperties(const std::string& prefix, const GdtEntry& gdtEntry);
bool FromGdtProperties(const GdtEntry& gdtEntry);
};

View File

@ -113,7 +113,7 @@ bool AssetLoaderPhysConstraints::LoadFromGdt(const std::string& assetName, IGdtQ
return false;
InfoString infoString;
if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, *gdtEntry))
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read phys constraints gdt entry: \"" << assetName << "\"" << std::endl;
return true;

View File

@ -96,7 +96,7 @@ bool AssetLoaderPhysPreset::LoadFromGdt(const std::string& assetName, IGdtQuerya
return false;
InfoString infoString;
if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *gdtEntry))
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read phys preset gdt entry: \"" << assetName << "\"" << std::endl;
return true;

View File

@ -80,7 +80,7 @@ bool AssetLoaderTracer::LoadFromGdt(const std::string& assetName, IGdtQueryable*
return false;
InfoString infoString;
if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_TRACER, *gdtEntry))
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read tracer gdt entry: \"" << assetName << "\"" << std::endl;
return true;

View File

@ -136,7 +136,7 @@ bool AssetLoaderVehicle::LoadFromGdt(const std::string& assetName, IGdtQueryable
return false;
InfoString infoString;
if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_VEHICLE, *gdtEntry))
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read vehicle gdt entry: \"" << assetName << "\"" << std::endl;
return true;

View File

@ -552,7 +552,7 @@ bool AssetLoaderWeapon::LoadFromGdt(const std::string& assetName, IGdtQueryable*
return false;
InfoString infoString;
if(!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON, *gdtEntry))
if(!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read weapon gdt entry: \"" << assetName << "\"" << std::endl;
return true;

View File

@ -132,7 +132,7 @@ bool AssetLoaderWeaponAttachment::LoadFromGdt(const std::string& assetName, IGdt
return false;
InfoString infoString;
if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT, *gdtEntry))
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read attachment gdt entry: \"" << assetName << "\"" << std::endl;
return true;

View File

@ -236,7 +236,7 @@ bool AssetLoaderWeaponAttachmentUnique::LoadFromGdt(const std::string& assetName
return false;
InfoString infoString;
if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE, *gdtEntry))
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read attachment unique gdt entry: \"" << assetName << "\"" << std::endl;
return true;

View File

@ -93,7 +93,7 @@ bool AssetLoaderZBarrier::LoadFromGdt(const std::string& assetName, IGdtQueryabl
return false;
InfoString infoString;
if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, *gdtEntry))
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read zbarrier gdt entry: \"" << assetName << "\"" << std::endl;
return true;