mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-13 08:18:21 -05:00
Add asset loader for localize files
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
#include "AssetLoaderLocalizeEntry.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#include "Localize/LocalizeCommon.h"
|
||||
#include "Parsing/LocalizeFile/LocalizeFileReader.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
XAssetInfoGeneric* AssetLoaderLocalizeEntry::LoadFromGlobalAssetPools(const std::string& assetName) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* AssetLoaderLocalizeEntry::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AssetLoaderLocalizeEntry::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderLocalizeEntry::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
std::string fileName;
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << LocalizeCommon::GetNameOfLanguage(zone->m_language) << "/localizedstrings/" << assetName << ".str";
|
||||
fileName = str.str();
|
||||
}
|
||||
|
||||
const auto file = searchPath->Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
LocalizeFileReader reader(*file.m_stream, assetName, zone->m_language);
|
||||
const auto localizeEntries = reader.ReadLocalizeFile();
|
||||
|
||||
for(const auto& entry : localizeEntries)
|
||||
{
|
||||
auto* localizeEntry = memory->Create<LocalizeEntry>();
|
||||
localizeEntry->name = memory->Dup(entry.m_key.c_str());
|
||||
localizeEntry->value = memory->Dup(entry.m_value.c_str());
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, entry.m_key, localizeEntry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user