2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-06 16:57:25 +00:00

refactor: streamline IW4 asset loading

This commit is contained in:
Jan Laupetin
2025-08-05 01:13:58 +02:00
parent 81a67151b5
commit 6806337f46
49 changed files with 398 additions and 397 deletions

View File

@@ -10,26 +10,43 @@
using namespace IW4;
GdtLoaderPhysPreset::GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
: m_memory(memory),
m_gdt(gdt),
m_zone(zone)
namespace
{
}
AssetCreationResult GdtLoaderPhysPreset::CreateAsset(const std::string& assetName, AssetCreationContext& context)
{
auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_PHYS_PRESET, assetName);
if (gdtEntry == nullptr)
return AssetCreationResult::NoAction();
InfoString infoString;
if (!infoString.FromGdtProperties(*gdtEntry))
class GdtLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
{
std::cerr << std::format("Failed to read phys preset gdt entry: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
public:
GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
: m_gdt(gdt),
m_info_string_loader(memory, zone)
{
}
InfoStringLoaderPhysPreset infoStringLoader(m_memory, m_zone);
return infoStringLoader.CreateAsset(assetName, infoString, context);
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_PHYS_PRESET, assetName);
if (gdtEntry == nullptr)
return AssetCreationResult::NoAction();
InfoString infoString;
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cerr << std::format("Failed to read phys preset gdt entry: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
return m_info_string_loader.CreateAsset(assetName, infoString, context);
}
private:
IGdtQueryable& m_gdt;
IW4::phys_preset::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace IW4::phys_preset
{
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateGdtLoader(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
{
return std::make_unique<GdtLoaderPhysPreset>(memory, gdt, zone);
}
} // namespace IW4::phys_preset