mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-26 09:50:38 +00:00
* feat: T4 add string table loader * chore: rename stringtable loaders to match style between games * fix: make sure all games correctly interpret failed stringtable loading --------- Co-authored-by: Jan Laupetin <[email protected]>
48 lines
1.4 KiB
C++
48 lines
1.4 KiB
C++
#include "LoaderStringTableIW5.h"
|
|
|
|
#include "Csv/CsvStream.h"
|
|
#include "Game/IW5/CommonIW5.h"
|
|
#include "Game/IW5/IW5.h"
|
|
#include "StringTable/StringTableLoader.h"
|
|
|
|
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);
|
|
if (!stringTable)
|
|
return AssetCreationResult::Failure();
|
|
|
|
return AssetCreationResult::Success(context.AddAsset<AssetStringTable>(assetName, stringTable));
|
|
}
|
|
|
|
private:
|
|
MemoryManager& m_memory;
|
|
ISearchPath& m_search_path;
|
|
};
|
|
} // namespace
|
|
|
|
namespace string_table
|
|
{
|
|
std::unique_ptr<AssetCreator<AssetStringTable>> CreateLoaderIW5(MemoryManager& memory, ISearchPath& searchPath)
|
|
{
|
|
return std::make_unique<StringTableLoader>(memory, searchPath);
|
|
}
|
|
} // namespace string_table
|