2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-06-06 16:52:35 +00:00

feat: accept aliases for asset type names

This commit is contained in:
Jan Laupetin
2026-05-02 17:42:55 +02:00
parent 0cbe0c2891
commit 08c128addd
20 changed files with 175 additions and 251 deletions
+69
View File
@@ -5,6 +5,7 @@
#include "IW5/GameIW5.h"
#include "T5/GameT5.h"
#include "T6/GameT6.h"
#include "Utils/StringUtils.h"
#include <cassert>
@@ -24,3 +25,71 @@ IGame* IGame::GetGameById(GameId gameId)
return result;
}
AbstractGame::AbstractGame(const char* const* assetTypeNames,
const asset_type_t assetTypeCount,
const char* const* subAssetTypeNames,
const asset_type_t subAssetTypeCount)
: m_asset_type_names(assetTypeNames),
m_asset_type_count(assetTypeCount),
m_sub_asset_type_names(subAssetTypeNames),
m_sub_asset_type_count(subAssetTypeCount)
{
for (asset_type_t assetType = 0; assetType < assetTypeCount; ++assetType)
{
assert(assetTypeNames[assetType] != nullptr);
AddAssetTypeNameAlias(assetType, assetTypeNames[assetType]);
}
}
const std::vector<GameLanguagePrefix>& AbstractGame::GetLanguagePrefixes() const
{
static std::vector<GameLanguagePrefix> prefixes;
return prefixes;
}
asset_type_t AbstractGame::GetAssetTypeCount() const
{
return m_asset_type_count;
}
std::optional<const char*> AbstractGame::GetAssetTypeName(const asset_type_t assetType) const
{
if (assetType < m_asset_type_count)
return m_asset_type_names[assetType];
return std::nullopt;
}
std::optional<asset_type_t> AbstractGame::FindAssetTypeByName(const std::string& potentialAssetTypeName) const
{
std::string lowerCaseName = potentialAssetTypeName;
utils::MakeStringLowerCase(lowerCaseName);
const auto existingAssetType = m_asset_type_name_lookup.find(lowerCaseName);
if (existingAssetType != m_asset_type_name_lookup.end())
return existingAssetType->second;
return std::nullopt;
}
asset_type_t AbstractGame::GetSubAssetTypeCount() const
{
return m_sub_asset_type_count;
}
std::optional<const char*> AbstractGame::GetSubAssetTypeName(const asset_type_t subAssetType) const
{
if (subAssetType < m_sub_asset_type_count)
return m_sub_asset_type_names[subAssetType];
return std::nullopt;
}
void AbstractGame::AddAssetTypeNameAlias(const asset_type_t assetType, const std::string& assetTypeName)
{
std::string lowerCaseName = assetTypeName;
utils::MakeStringLowerCase(lowerCaseName);
m_asset_type_name_lookup.emplace(lowerCaseName, assetType);
}