2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-16 18:03:03 +00:00

chore: refactor IW4 asset loaders

This commit is contained in:
Jan
2024-12-25 21:39:05 +01:00
parent f9456101e6
commit 7ef944ebd4
139 changed files with 2370 additions and 2965 deletions

View File

@@ -0,0 +1,47 @@
#include "LoaderStringTableIW4.h"
#include "Csv/CsvStream.h"
#include "Game/IW4/CommonIW4.h"
#include "Game/IW4/IW4.h"
#include "StringTable/StringTableLoader.h"
using namespace IW4;
namespace
{
class LoaderStringTable final : public AssetCreator<AssetStringTable>
{
public:
LoaderStringTable(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(assetName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
string_table::StringTableLoaderV2<StringTable, Common::StringTable_HashString> loader;
auto* stringTable = loader.LoadFromStream(assetName, m_memory, *file.m_stream);
if (!stringTable)
return AssetCreationResult::Failure();
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace IW4
{
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<LoaderStringTable>(memory, searchPath);
}
} // namespace IW4

View File

@@ -0,0 +1,13 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/IW4/IW4.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace IW4
{
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace IW4