mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 00:25:44 +00:00
Add metadata from zone definition as keyvaluepairs to zone for T6
This commit is contained in:
parent
5e08469635
commit
5cd5ae5533
@ -3,6 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "ObjLoading.h"
|
#include "ObjLoading.h"
|
||||||
|
#include "Game/T6/CommonT6.h"
|
||||||
#include "Game/T6/T6.h"
|
#include "Game/T6/T6.h"
|
||||||
#include "Game/T6/GameT6.h"
|
#include "Game/T6/GameT6.h"
|
||||||
#include "Game/T6/GameAssetPoolT6.h"
|
#include "Game/T6/GameAssetPoolT6.h"
|
||||||
@ -57,6 +58,60 @@ void ZoneCreator::CreateZoneAssetPools(Zone* zone) const
|
|||||||
zone->m_pools->InitPoolDynamic(assetType);
|
zone->m_pools->InitPoolDynamic(assetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ZoneCreator::HandleMetadata(Zone* zone, ZoneCreationContext& context) const
|
||||||
|
{
|
||||||
|
std::vector<KeyValuePair> kvpList;
|
||||||
|
|
||||||
|
for (const auto& [metaKey, metaValue] : context.m_definition->m_metadata)
|
||||||
|
{
|
||||||
|
if (metaKey.rfind("level.", 0) == 0)
|
||||||
|
{
|
||||||
|
const std::string strValue = metaKey.substr(std::char_traits<char>::length("level."));
|
||||||
|
if(strValue.empty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int keyHash;
|
||||||
|
if(strValue[0] == '@')
|
||||||
|
{
|
||||||
|
char* endPtr;
|
||||||
|
keyHash = strtol(&strValue[1], &endPtr, 16);
|
||||||
|
|
||||||
|
if(endPtr != &strValue[strValue.size()])
|
||||||
|
{
|
||||||
|
std::cout << "Could not parse metadata key \"" << metaKey << "\" as hash" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keyHash = CommonT6::Com_HashKey(strValue.c_str(), 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KeyValuePair kvp
|
||||||
|
{
|
||||||
|
keyHash,
|
||||||
|
CommonT6::Com_HashKey(zone->m_name.c_str(), 64),
|
||||||
|
zone->GetMemory()->Dup(metaValue.c_str())
|
||||||
|
};
|
||||||
|
kvpList.push_back(kvp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!kvpList.empty())
|
||||||
|
{
|
||||||
|
auto* kvps = zone->GetMemory()->Create<KeyValuePairs>();
|
||||||
|
kvps->name = zone->GetMemory()->Dup(zone->m_name.c_str());
|
||||||
|
kvps->numVariables = kvpList.size();
|
||||||
|
kvps->keyValuePairs = static_cast<KeyValuePair*>(zone->GetMemory()->Alloc(sizeof(KeyValuePair) * kvpList.size()));
|
||||||
|
|
||||||
|
for(auto i = 0u; i < kvpList.size(); i++)
|
||||||
|
kvps->keyValuePairs[i] = kvpList[i];
|
||||||
|
|
||||||
|
zone->m_pools->AddAsset(ASSET_TYPE_KEYVALUEPAIRS, zone->m_name, kvps, std::vector<XAssetInfoGeneric*>(), std::vector<scr_string_t>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ZoneCreator::SupportsGame(const std::string& gameName) const
|
bool ZoneCreator::SupportsGame(const std::string& gameName) const
|
||||||
{
|
{
|
||||||
return gameName == g_GameT6.GetShortName();
|
return gameName == g_GameT6.GetShortName();
|
||||||
@ -69,7 +124,7 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext&
|
|||||||
|
|
||||||
for (const auto& assetEntry : context.m_definition->m_assets)
|
for (const auto& assetEntry : context.m_definition->m_assets)
|
||||||
{
|
{
|
||||||
if(!assetEntry.m_is_reference)
|
if (!assetEntry.m_is_reference)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
context.m_ignored_assets.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name);
|
context.m_ignored_assets.emplace_back(assetEntry.m_asset_type, assetEntry.m_asset_name);
|
||||||
@ -79,6 +134,8 @@ std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext&
|
|||||||
if (!CreateIgnoredAssetMap(context, assetLoadingContext->m_ignored_asset_map))
|
if (!CreateIgnoredAssetMap(context, assetLoadingContext->m_ignored_asset_map))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
HandleMetadata(zone.get(), context);
|
||||||
|
|
||||||
for (const auto& assetEntry : context.m_definition->m_assets)
|
for (const auto& assetEntry : context.m_definition->m_assets)
|
||||||
{
|
{
|
||||||
const auto foundAssetTypeEntry = m_asset_types_by_name.find(assetEntry.m_asset_type);
|
const auto foundAssetTypeEntry = m_asset_types_by_name.find(assetEntry.m_asset_type);
|
||||||
|
@ -15,6 +15,7 @@ namespace T6
|
|||||||
static std::vector<Gdt*> CreateGdtList(ZoneCreationContext& context);
|
static std::vector<Gdt*> CreateGdtList(ZoneCreationContext& context);
|
||||||
bool CreateIgnoredAssetMap(ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const;
|
bool CreateIgnoredAssetMap(ZoneCreationContext& context, std::unordered_map<std::string, asset_type_t>& ignoredAssetMap) const;
|
||||||
void CreateZoneAssetPools(Zone* zone) const;
|
void CreateZoneAssetPools(Zone* zone) const;
|
||||||
|
void HandleMetadata(Zone* zone, ZoneCreationContext& context) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ZoneCreator();
|
ZoneCreator();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user