mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-05-02 08:29:36 +00:00
chore: make keyvaluepairscompiler use a zonestate
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#include "KeyValuePairsCreator.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
CommonKeyValuePair::CommonKeyValuePair(std::string keyStr, std::string value)
|
||||
: m_key_str(std::move(keyStr)),
|
||||
m_value(std::move(value))
|
||||
{
|
||||
}
|
||||
|
||||
CommonKeyValuePair::CommonKeyValuePair(const unsigned keyHash, std::string value)
|
||||
: m_key_hash(keyHash),
|
||||
m_value(std::move(value))
|
||||
{
|
||||
}
|
||||
|
||||
void KeyValuePairsCreator::AddKeyValuePair(CommonKeyValuePair keyValuePair)
|
||||
{
|
||||
m_key_value_pairs.emplace_back(std::move(keyValuePair));
|
||||
}
|
||||
|
||||
void KeyValuePairsCreator::Finalize(const ZoneDefinition& zoneDefinition)
|
||||
{
|
||||
for (const auto& metaData : zoneDefinition.m_properties.m_properties)
|
||||
{
|
||||
if (metaData.first.rfind("level.", 0) == 0)
|
||||
{
|
||||
std::string strValue = metaData.first.substr(std::char_traits<char>::length("level."));
|
||||
if (strValue.empty())
|
||||
continue;
|
||||
|
||||
if (strValue[0] == '@')
|
||||
{
|
||||
char* endPtr;
|
||||
const unsigned keyHash = strtoul(&strValue[1], &endPtr, 16);
|
||||
|
||||
if (endPtr != &strValue[strValue.size()])
|
||||
{
|
||||
std::cerr << std::format("Could not parse metadata key \"{}\" as hash\n", metaData.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
m_key_value_pairs.emplace_back(keyHash, metaData.second);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_key_value_pairs.emplace_back(std::move(strValue), metaData.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<CommonKeyValuePair> KeyValuePairsCreator::GetFinalKeyValuePairs()
|
||||
{
|
||||
return std::move(m_key_value_pairs);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IZoneAssetCreationState.h"
|
||||
#include "Zone/Definition/ZoneDefinition.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class CommonKeyValuePair
|
||||
{
|
||||
public:
|
||||
CommonKeyValuePair(std::string keyStr, std::string value);
|
||||
CommonKeyValuePair(unsigned keyHash, std::string value);
|
||||
|
||||
std::optional<std::string> m_key_str;
|
||||
std::optional<unsigned> m_key_hash;
|
||||
std::string m_value;
|
||||
};
|
||||
|
||||
class KeyValuePairsCreator : public IZoneAssetCreationState
|
||||
{
|
||||
public:
|
||||
void AddKeyValuePair(CommonKeyValuePair keyValuePair);
|
||||
void Finalize(const ZoneDefinition& zoneDefinition);
|
||||
std::vector<CommonKeyValuePair> GetFinalKeyValuePairs();
|
||||
|
||||
private:
|
||||
std::vector<CommonKeyValuePair> m_key_value_pairs;
|
||||
};
|
||||
Reference in New Issue
Block a user