mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-05-12 21:31:43 +00:00
feat: accept aliases for asset type names
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "GameLanguage.h"
|
||||
#include "IAsset.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
enum class GameId : std::uint8_t
|
||||
@@ -68,9 +70,42 @@ public:
|
||||
|
||||
[[nodiscard]] virtual asset_type_t GetAssetTypeCount() const = 0;
|
||||
[[nodiscard]] virtual std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const = 0;
|
||||
[[nodiscard]] virtual std::optional<asset_type_t> FindAssetTypeByName(const std::string& potentialAssetTypeName) const = 0;
|
||||
|
||||
[[nodiscard]] virtual asset_type_t GetSubAssetTypeCount() const = 0;
|
||||
[[nodiscard]] virtual std::optional<const char*> GetSubAssetTypeName(asset_type_t subAssetType) const = 0;
|
||||
|
||||
static IGame* GetGameById(GameId gameId);
|
||||
};
|
||||
|
||||
class AbstractGame : public IGame
|
||||
{
|
||||
public:
|
||||
AbstractGame(const char* const* assetTypeNames, asset_type_t assetTypeCount, const char* const* subAssetTypeNames, asset_type_t subAssetTypeCount);
|
||||
|
||||
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
|
||||
|
||||
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
|
||||
[[nodiscard]] std::optional<asset_type_t> FindAssetTypeByName(const std::string& potentialAssetTypeName) const override;
|
||||
|
||||
[[nodiscard]] asset_type_t GetSubAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetSubAssetTypeName(asset_type_t subAssetType) const override;
|
||||
|
||||
protected:
|
||||
template<AssetDefinition Asset_t> void AddAssetTypeNameAlias(const std::string& assetTypeName)
|
||||
{
|
||||
AddAssetTypeNameAlias(Asset_t::EnumEntry, assetTypeName);
|
||||
}
|
||||
|
||||
private:
|
||||
void AddAssetTypeNameAlias(asset_type_t assetType, const std::string& assetTypeName);
|
||||
|
||||
const char* const* m_asset_type_names;
|
||||
asset_type_t m_asset_type_count;
|
||||
|
||||
const char* const* m_sub_asset_type_names;
|
||||
asset_type_t m_sub_asset_type_count;
|
||||
|
||||
std::unordered_map<std::string, asset_type_t> m_asset_type_name_lookup;
|
||||
};
|
||||
|
||||
@@ -27,6 +27,13 @@ namespace
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
Game::Game()
|
||||
: AbstractGame(ASSET_TYPE_NAMES, std::extent_v<decltype(ASSET_TYPE_NAMES)>, SUB_ASSET_TYPE_NAMES, std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
{
|
||||
AddAssetTypeNameAlias<AssetTechniqueSet>("techset");
|
||||
AddAssetTypeNameAlias<AssetLightDef>("gfxlightdef");
|
||||
}
|
||||
|
||||
GameId Game::GetId() const
|
||||
{
|
||||
return GameId::IW3;
|
||||
@@ -43,36 +50,4 @@ namespace IW3
|
||||
static std::string shortName = "IW3";
|
||||
return shortName;
|
||||
}
|
||||
|
||||
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
|
||||
{
|
||||
static std::vector<GameLanguagePrefix> prefixes;
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetAssetTypeCount() const
|
||||
{
|
||||
return ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
|
||||
{
|
||||
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
|
||||
return ASSET_TYPE_NAMES[assetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetSubAssetTypeCount() const
|
||||
{
|
||||
return SUB_ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetSubAssetTypeName(const asset_type_t subAssetType) const
|
||||
{
|
||||
if (subAssetType < std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
return SUB_ASSET_TYPE_NAMES[subAssetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace IW3
|
||||
|
||||
@@ -4,17 +4,13 @@
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class Game final : public IGame
|
||||
class Game final : public AbstractGame
|
||||
{
|
||||
public:
|
||||
Game();
|
||||
|
||||
[[nodiscard]] GameId GetId() const override;
|
||||
[[nodiscard]] const std::string& GetFullName() const override;
|
||||
[[nodiscard]] const std::string& GetShortName() const override;
|
||||
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
|
||||
|
||||
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
|
||||
[[nodiscard]] asset_type_t GetSubAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetSubAssetTypeName(asset_type_t subAssetType) const override;
|
||||
};
|
||||
} // namespace IW3
|
||||
|
||||
@@ -29,6 +29,13 @@ namespace
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
Game::Game()
|
||||
: AbstractGame(ASSET_TYPE_NAMES, std::extent_v<decltype(ASSET_TYPE_NAMES)>, SUB_ASSET_TYPE_NAMES, std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
{
|
||||
AddAssetTypeNameAlias<AssetTechniqueSet>("techset");
|
||||
AddAssetTypeNameAlias<AssetLightDef>("gfxlightdef");
|
||||
}
|
||||
|
||||
GameId Game::GetId() const
|
||||
{
|
||||
return GameId::IW4;
|
||||
@@ -45,36 +52,4 @@ namespace IW4
|
||||
static std::string shortName = "IW4";
|
||||
return shortName;
|
||||
}
|
||||
|
||||
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
|
||||
{
|
||||
static std::vector<GameLanguagePrefix> prefixes;
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetAssetTypeCount() const
|
||||
{
|
||||
return ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
|
||||
{
|
||||
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
|
||||
return ASSET_TYPE_NAMES[assetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetSubAssetTypeCount() const
|
||||
{
|
||||
return SUB_ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetSubAssetTypeName(const asset_type_t subAssetType) const
|
||||
{
|
||||
if (subAssetType < std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
return SUB_ASSET_TYPE_NAMES[subAssetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace IW4
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IGame.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class Game final : public IGame
|
||||
class Game final : public AbstractGame
|
||||
{
|
||||
public:
|
||||
Game();
|
||||
|
||||
[[nodiscard]] GameId GetId() const override;
|
||||
[[nodiscard]] const std::string& GetFullName() const override;
|
||||
[[nodiscard]] const std::string& GetShortName() const override;
|
||||
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
|
||||
|
||||
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
|
||||
[[nodiscard]] asset_type_t GetSubAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetSubAssetTypeName(asset_type_t subAssetType) const override;
|
||||
};
|
||||
} // namespace IW4
|
||||
|
||||
@@ -66,6 +66,13 @@ namespace
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
Game::Game()
|
||||
: AbstractGame(ASSET_TYPE_NAMES, std::extent_v<decltype(ASSET_TYPE_NAMES)>, SUB_ASSET_TYPE_NAMES, std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
{
|
||||
AddAssetTypeNameAlias<AssetTechniqueSet>("techset");
|
||||
AddAssetTypeNameAlias<AssetLightDef>("gfxlightdef");
|
||||
}
|
||||
|
||||
GameId Game::GetId() const
|
||||
{
|
||||
return GameId::IW5;
|
||||
@@ -82,36 +89,4 @@ namespace IW5
|
||||
static std::string shortName = "IW5";
|
||||
return shortName;
|
||||
}
|
||||
|
||||
const std::vector<GameLanguagePrefix>& Game::GetLanguagePrefixes() const
|
||||
{
|
||||
static std::vector<GameLanguagePrefix> prefixes;
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetAssetTypeCount() const
|
||||
{
|
||||
return ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
|
||||
{
|
||||
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
|
||||
return ASSET_TYPE_NAMES[assetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetSubAssetTypeCount() const
|
||||
{
|
||||
return SUB_ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetSubAssetTypeName(const asset_type_t subAssetType) const
|
||||
{
|
||||
if (subAssetType < std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
return SUB_ASSET_TYPE_NAMES[subAssetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace IW5
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IGame.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class Game final : public IGame
|
||||
class Game final : public AbstractGame
|
||||
{
|
||||
public:
|
||||
Game();
|
||||
|
||||
[[nodiscard]] GameId GetId() const override;
|
||||
[[nodiscard]] const std::string& GetFullName() const override;
|
||||
[[nodiscard]] const std::string& GetShortName() const override;
|
||||
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
|
||||
|
||||
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
|
||||
[[nodiscard]] asset_type_t GetSubAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetSubAssetTypeName(asset_type_t subAssetType) const override;
|
||||
};
|
||||
} // namespace IW5
|
||||
|
||||
@@ -30,6 +30,13 @@ namespace
|
||||
|
||||
namespace T5
|
||||
{
|
||||
Game::Game()
|
||||
: AbstractGame(ASSET_TYPE_NAMES, std::extent_v<decltype(ASSET_TYPE_NAMES)>, SUB_ASSET_TYPE_NAMES, std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
{
|
||||
AddAssetTypeNameAlias<AssetTechniqueSet>("techset");
|
||||
AddAssetTypeNameAlias<AssetLightDef>("gfxlightdef");
|
||||
}
|
||||
|
||||
GameId Game::GetId() const
|
||||
{
|
||||
return GameId::T5;
|
||||
@@ -67,30 +74,4 @@ namespace T5
|
||||
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetAssetTypeCount() const
|
||||
{
|
||||
return ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
|
||||
{
|
||||
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
|
||||
return ASSET_TYPE_NAMES[assetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetSubAssetTypeCount() const
|
||||
{
|
||||
return SUB_ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetSubAssetTypeName(const asset_type_t subAssetType) const
|
||||
{
|
||||
if (subAssetType < std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
return SUB_ASSET_TYPE_NAMES[subAssetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace T5
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IGame.h"
|
||||
|
||||
namespace T5
|
||||
{
|
||||
class Game final : public IGame
|
||||
class Game final : public AbstractGame
|
||||
{
|
||||
public:
|
||||
Game();
|
||||
|
||||
[[nodiscard]] GameId GetId() const override;
|
||||
[[nodiscard]] const std::string& GetFullName() const override;
|
||||
[[nodiscard]] const std::string& GetShortName() const override;
|
||||
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
|
||||
|
||||
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
|
||||
[[nodiscard]] asset_type_t GetSubAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetSubAssetTypeName(asset_type_t subAssetType) const override;
|
||||
};
|
||||
} // namespace T5
|
||||
|
||||
@@ -83,6 +83,13 @@ namespace
|
||||
|
||||
namespace T6
|
||||
{
|
||||
Game::Game()
|
||||
: AbstractGame(ASSET_TYPE_NAMES, std::extent_v<decltype(ASSET_TYPE_NAMES)>, SUB_ASSET_TYPE_NAMES, std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
{
|
||||
AddAssetTypeNameAlias<AssetTechniqueSet>("techset");
|
||||
AddAssetTypeNameAlias<AssetLightDef>("gfxlightdef");
|
||||
}
|
||||
|
||||
GameId Game::GetId() const
|
||||
{
|
||||
return GameId::T6;
|
||||
@@ -123,30 +130,4 @@ namespace T6
|
||||
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetAssetTypeCount() const
|
||||
{
|
||||
return ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetAssetTypeName(const asset_type_t assetType) const
|
||||
{
|
||||
if (assetType < std::extent_v<decltype(ASSET_TYPE_NAMES)>)
|
||||
return ASSET_TYPE_NAMES[assetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
asset_type_t Game::GetSubAssetTypeCount() const
|
||||
{
|
||||
return SUB_ASSET_TYPE_COUNT;
|
||||
}
|
||||
|
||||
std::optional<const char*> Game::GetSubAssetTypeName(const asset_type_t subAssetType) const
|
||||
{
|
||||
if (subAssetType < std::extent_v<decltype(SUB_ASSET_TYPE_NAMES)>)
|
||||
return SUB_ASSET_TYPE_NAMES[subAssetType];
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace T6
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IGame.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class Game final : public IGame
|
||||
class Game final : public AbstractGame
|
||||
{
|
||||
public:
|
||||
Game();
|
||||
|
||||
[[nodiscard]] GameId GetId() const override;
|
||||
[[nodiscard]] const std::string& GetFullName() const override;
|
||||
[[nodiscard]] const std::string& GetShortName() const override;
|
||||
[[nodiscard]] const std::vector<GameLanguagePrefix>& GetLanguagePrefixes() const override;
|
||||
|
||||
[[nodiscard]] asset_type_t GetAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetAssetTypeName(asset_type_t assetType) const override;
|
||||
[[nodiscard]] asset_type_t GetSubAssetTypeCount() const override;
|
||||
[[nodiscard]] std::optional<const char*> GetSubAssetTypeName(asset_type_t subAssetType) const override;
|
||||
};
|
||||
} // namespace T6
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "UnlinkerArgs.h"
|
||||
#include "UnlinkerPaths.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
#include "Zone/AssetNameResolver.h"
|
||||
#include "Zone/Definition/ZoneDefWriter.h"
|
||||
#include "ZoneLoading.h"
|
||||
|
||||
@@ -105,11 +104,10 @@ namespace
|
||||
ObjWriting::Configuration.AssetTypesToHandleBitfield = std::vector(assetTypeCount, initialValue);
|
||||
|
||||
std::vector<bool> handledSpecifiedAssets(m_args.m_specified_asset_types.size());
|
||||
const AssetNameResolver assetNameResolver(gameId);
|
||||
auto anySpecifiedValueInvalid = false;
|
||||
for (const auto& specifiedValue : m_args.m_specified_asset_types)
|
||||
{
|
||||
const auto maybeAssetType = assetNameResolver.GetAssetTypeByName(specifiedValue);
|
||||
const auto maybeAssetType = game->FindAssetTypeByName(specifiedValue);
|
||||
if (!maybeAssetType)
|
||||
{
|
||||
con::error("Unknown asset type \"{}\"", specifiedValue);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "Csv/CsvStream.h"
|
||||
#include "Game/IGame.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
#include "Zone/AssetNameResolver.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
@@ -12,9 +11,9 @@ namespace
|
||||
class AssetListInputStream
|
||||
{
|
||||
public:
|
||||
AssetListInputStream(std::istream& stream, const GameId game)
|
||||
AssetListInputStream(std::istream& stream, const GameId gameId)
|
||||
: m_stream(stream),
|
||||
m_asset_name_resolver(game)
|
||||
m_game(*IGame::GetGameById(gameId))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,7 +32,7 @@ namespace
|
||||
continue;
|
||||
|
||||
const auto& typeName = row[0];
|
||||
const auto maybeType = m_asset_name_resolver.GetAssetTypeByName(typeName);
|
||||
const auto maybeType = m_game.FindAssetTypeByName(typeName);
|
||||
if (!maybeType)
|
||||
{
|
||||
con::error("Unknown asset type name \"{}\"", typeName);
|
||||
@@ -60,7 +59,7 @@ namespace
|
||||
|
||||
private:
|
||||
CsvInputStream m_stream;
|
||||
AssetNameResolver m_asset_name_resolver;
|
||||
IGame& m_game;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "AssetNameResolver.h"
|
||||
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
AssetNameResolver::AssetNameResolver(const GameId gameId)
|
||||
{
|
||||
const auto* game = IGame::GetGameById(gameId);
|
||||
const auto assetTypeCount = game->GetAssetTypeCount();
|
||||
|
||||
for (asset_type_t assetType = 0; assetType < assetTypeCount; assetType++)
|
||||
{
|
||||
auto maybeAssetTypeName = game->GetAssetTypeName(assetType);
|
||||
assert(maybeAssetTypeName);
|
||||
if (!maybeAssetTypeName)
|
||||
continue;
|
||||
|
||||
std::string lowerCaseName(*maybeAssetTypeName);
|
||||
utils::MakeStringLowerCase(lowerCaseName);
|
||||
m_asset_types_by_name.emplace(lowerCaseName, assetType);
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<asset_type_t> AssetNameResolver::GetAssetTypeByName(const std::string& assetTypeName) const
|
||||
{
|
||||
std::string lowerCaseName = assetTypeName;
|
||||
utils::MakeStringLowerCase(lowerCaseName);
|
||||
|
||||
const auto existingAssetType = m_asset_types_by_name.find(assetTypeName);
|
||||
if (existingAssetType != m_asset_types_by_name.end())
|
||||
return existingAssetType->second;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IGame.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class AssetNameResolver
|
||||
{
|
||||
public:
|
||||
AssetNameResolver() = default;
|
||||
explicit AssetNameResolver(GameId gameId);
|
||||
|
||||
[[nodiscard]] std::optional<asset_type_t> GetAssetTypeByName(const std::string& assetTypeName) const;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, asset_type_t> m_asset_types_by_name;
|
||||
};
|
||||
@@ -23,7 +23,12 @@ void SequenceZoneDefinitionEntry::ProcessMatch(ZoneDefinitionParserState* state,
|
||||
{
|
||||
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE_NAME);
|
||||
|
||||
const auto maybeAssetType = state->m_asset_name_resolver.GetAssetTypeByName(typeNameToken.FieldValue());
|
||||
const auto maybeAssetType = state->m_game.and_then(
|
||||
[&typeNameToken](const IGame* game)
|
||||
{
|
||||
return game->FindAssetTypeByName(typeNameToken.FieldValue());
|
||||
});
|
||||
|
||||
if (!maybeAssetType)
|
||||
throw ParsingException(typeNameToken.GetPos(), "Unknown asset type");
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ ZoneDefinitionParserState::ZoneDefinitionParserState(std::string targetName, ISe
|
||||
m_definition->m_name = std::move(targetName);
|
||||
}
|
||||
|
||||
void ZoneDefinitionParserState::SetGame(const GameId game)
|
||||
void ZoneDefinitionParserState::SetGame(const GameId gameId)
|
||||
{
|
||||
m_definition->m_game = game;
|
||||
m_asset_name_resolver = AssetNameResolver(game);
|
||||
m_definition->m_game = gameId;
|
||||
m_game = IGame::GetGameById(gameId);
|
||||
}
|
||||
|
||||
namespace
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Zone/AssetNameResolver.h"
|
||||
#include "Zone/Definition/ZoneDefinition.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -15,7 +14,7 @@ class ZoneDefinitionParserState
|
||||
public:
|
||||
ZoneDefinitionParserState(std::string targetName, ISearchPath& searchPath, IParserLineStream& underlyingStream);
|
||||
|
||||
void SetGame(GameId game);
|
||||
void SetGame(GameId gameId);
|
||||
|
||||
void StartIPak(std::string ipakName);
|
||||
void StartIwd(std::string iwdName);
|
||||
@@ -26,7 +25,7 @@ public:
|
||||
IParserLineStream& m_underlying_stream;
|
||||
std::unordered_set<std::string> m_inclusions;
|
||||
|
||||
AssetNameResolver m_asset_name_resolver;
|
||||
std::optional<IGame*> m_game;
|
||||
|
||||
std::optional<ZoneDefinitionObjContainer> m_current_ipak;
|
||||
std::optional<ZoneDefinitionObjContainer> m_current_iwd;
|
||||
|
||||
Reference in New Issue
Block a user