2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-12-08 12:17:48 +00:00

refactor: streamline T6 asset loading

This commit is contained in:
Jan Laupetin
2025-08-04 23:48:30 +02:00
parent 472e59991f
commit a5024d40b0
59 changed files with 380 additions and 383 deletions

View File

@@ -40,14 +40,14 @@ namespace
private:
IGdtQueryable& m_gdt;
InfoStringLoaderZBarrier m_info_string_loader;
T6::z_barrier::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::z_barrier
{
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateGdtZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
{
return std::make_unique<GdtLoaderZBarrier>(memory, searchPath, gdt, zone);
}
} // namespace T6
} // namespace T6::z_barrier

View File

@@ -8,7 +8,7 @@
#include <memory>
namespace T6
namespace T6::z_barrier
{
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateGdtZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6::z_barrier

View File

@@ -55,29 +55,32 @@ namespace
}
} // namespace
InfoStringLoaderZBarrier::InfoStringLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
namespace T6::z_barrier
{
}
AssetCreationResult InfoStringLoaderZBarrier::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* zbarrier = m_memory.Alloc<ZBarrierDef>();
zbarrier->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetZBarrier> registration(assetName, zbarrier);
InfoStringToZBarrierConverter converter(
infoString, *zbarrier, m_zone.m_script_strings, m_memory, context, registration, zbarrier_fields, std::extent_v<decltype(zbarrier_fields)>);
if (!converter.Convert())
InfoStringLoader::InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
{
std::cerr << std::format("Failed to parse zbarrier: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculateZBarrierFields(*zbarrier);
AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* zbarrier = m_memory.Alloc<ZBarrierDef>();
zbarrier->name = m_memory.Dup(assetName.c_str());
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
AssetRegistration<AssetZBarrier> registration(assetName, zbarrier);
InfoStringToZBarrierConverter converter(
infoString, *zbarrier, m_zone.m_script_strings, m_memory, context, registration, zbarrier_fields, std::extent_v<decltype(zbarrier_fields)>);
if (!converter.Convert())
{
std::cerr << std::format("Failed to parse zbarrier: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculateZBarrierFields(*zbarrier);
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
} // namespace T6::z_barrier

View File

@@ -4,12 +4,12 @@
#include "Asset/AssetCreationResult.h"
#include "InfoString/InfoString.h"
namespace T6
namespace T6::z_barrier
{
class InfoStringLoaderZBarrier
class InfoStringLoader
{
public:
InfoStringLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
@@ -18,4 +18,4 @@ namespace T6
ISearchPath& m_search_path;
Zone& m_zone;
};
} // namespace T6
} // namespace T6::z_barrier

View File

@@ -43,14 +43,14 @@ namespace
private:
ISearchPath& m_search_path;
InfoStringLoaderZBarrier m_info_string_loader;
T6::z_barrier::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::z_barrier
{
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateRawZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<RawLoaderZBarrier>(memory, searchPath, zone);
}
} // namespace T6
} // namespace T6::z_barrier

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace T6
namespace T6::z_barrier
{
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateRawZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6::z_barrier