mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 15:28:11 -05:00
chore: use generic loaders for iw4,iw5,t5,t6 instead of duplicating implementations
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "StringTable/StringTableLoader.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@ -30,49 +31,8 @@ bool AssetLoaderStringTable::LoadFromRaw(
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
auto* stringTable = memory->Create<StringTable>();
|
||||
stringTable->name = memory->Dup(assetName.c_str());
|
||||
|
||||
std::vector<std::vector<std::string>> csvLines;
|
||||
std::vector<std::string> currentLine;
|
||||
auto maxCols = 0u;
|
||||
const CsvInputStream csv(*file.m_stream);
|
||||
|
||||
while (csv.NextRow(currentLine))
|
||||
{
|
||||
if (currentLine.size() > maxCols)
|
||||
maxCols = currentLine.size();
|
||||
csvLines.emplace_back(std::move(currentLine));
|
||||
currentLine = std::vector<std::string>();
|
||||
}
|
||||
|
||||
stringTable->columnCount = static_cast<int>(maxCols);
|
||||
stringTable->rowCount = static_cast<int>(csvLines.size());
|
||||
const auto cellCount = static_cast<unsigned>(stringTable->rowCount) * static_cast<unsigned>(stringTable->columnCount);
|
||||
|
||||
if (cellCount)
|
||||
{
|
||||
stringTable->values = static_cast<StringTableCell*>(memory->Alloc(sizeof(StringTableCell) * cellCount));
|
||||
|
||||
for (auto row = 0u; row < csvLines.size(); row++)
|
||||
{
|
||||
const auto& rowValues = csvLines[row];
|
||||
for (auto col = 0u; col < maxCols; col++)
|
||||
{
|
||||
auto& cell = stringTable->values[row * maxCols + col];
|
||||
if (col >= rowValues.size() || rowValues[col].empty())
|
||||
cell.string = "";
|
||||
else
|
||||
cell.string = memory->Dup(rowValues[col].c_str());
|
||||
|
||||
cell.hash = Common::StringTable_HashString(cell.string);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stringTable->values = nullptr;
|
||||
}
|
||||
string_table::StringTableLoaderV2<StringTable, Common::StringTable_HashString> loader;
|
||||
auto* stringTable = loader.LoadFromStream(assetName, *memory, *file.m_stream);
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_STRINGTABLE, assetName, stringTable);
|
||||
|
||||
|
Reference in New Issue
Block a user