mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-04 07:47:25 +00:00
chore: fix loading and writing code for IW5
This commit is contained in:
49
src/ObjLoading/Game/IW5/StringTable/LoaderStringTableIW5.cpp
Normal file
49
src/ObjLoading/Game/IW5/StringTable/LoaderStringTableIW5.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "LoaderStringTableIW5.h"
|
||||
|
||||
#include "Csv/CsvStream.h"
|
||||
#include "Game/IW5/CommonIW5.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "StringTable/StringTableLoader.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
namespace
|
||||
{
|
||||
class StringTableLoader final : public AssetCreator<AssetStringTable>
|
||||
{
|
||||
public:
|
||||
StringTableLoader(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);
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath)
|
||||
{
|
||||
return std::make_unique<StringTableLoader>(memory, searchPath);
|
||||
}
|
||||
} // namespace IW5
|
13
src/ObjLoading/Game/IW5/StringTable/LoaderStringTableIW5.h
Normal file
13
src/ObjLoading/Game/IW5/StringTable/LoaderStringTableIW5.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetStringTable>> CreateStringTableLoader(MemoryManager& memory, ISearchPath& searchPath);
|
||||
} // namespace IW5
|
Reference in New Issue
Block a user