mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-02 17:27:47 +00:00
refactor: streamline T6 asset loading
This commit is contained in:
@@ -16,15 +16,15 @@ namespace
|
||||
class GdtLoaderPhysPreset final : public AssetCreator<AssetPhysPreset>
|
||||
{
|
||||
public:
|
||||
GdtLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
|
||||
GdtLoaderPhysPreset(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
: m_gdt(gdt),
|
||||
m_info_string_loader(memory, searchPath, zone)
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON, assetName);
|
||||
const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_PHYS_PRESET, assetName);
|
||||
if (gdtEntry == nullptr)
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
@@ -40,14 +40,14 @@ namespace
|
||||
|
||||
private:
|
||||
IGdtQueryable& m_gdt;
|
||||
InfoStringLoaderPhysPreset m_info_string_loader;
|
||||
T6::phys_preset::InfoStringLoader m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace T6
|
||||
namespace T6::phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateGdtPhysPresetLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateGdtLoader(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone)
|
||||
{
|
||||
return std::make_unique<GdtLoaderPhysPreset>(memory, searchPath, gdt, zone);
|
||||
return std::make_unique<GdtLoaderPhysPreset>(memory, gdt, zone);
|
||||
}
|
||||
} // namespace T6
|
||||
} // namespace T6::phys_preset
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace T6
|
||||
namespace T6::phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateGdtPhysPresetLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
|
||||
} // namespace T6
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateGdtLoader(MemoryManager& memory, IGdtQueryable& gdt, Zone& zone);
|
||||
} // namespace T6::phys_preset
|
||||
|
||||
@@ -60,31 +60,39 @@ namespace
|
||||
}
|
||||
} // namespace
|
||||
|
||||
InfoStringLoaderPhysPreset::InfoStringLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath),
|
||||
m_zone(zone)
|
||||
namespace T6::phys_preset
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult InfoStringLoaderPhysPreset::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
|
||||
{
|
||||
auto* physPreset = m_memory.Alloc<PhysPreset>();
|
||||
physPreset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
|
||||
|
||||
PhysPresetInfo physPresetInfo;
|
||||
memset(&physPresetInfo, 0, sizeof(physPresetInfo));
|
||||
InfoStringToPhysPresetConverter converter(
|
||||
infoString, physPresetInfo, m_zone.m_script_strings, m_memory, context, registration, phys_preset_fields, std::extent_v<decltype(phys_preset_fields)>);
|
||||
if (!converter.Convert())
|
||||
InfoStringLoader::InfoStringLoader(MemoryManager& memory, Zone& zone)
|
||||
: m_memory(memory),
|
||||
m_zone(zone)
|
||||
{
|
||||
std::cerr << std::format("Failed to parse phys preset: \"{}\"\n", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
CopyFromPhysPresetInfo(physPresetInfo, *physPreset);
|
||||
AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
|
||||
{
|
||||
auto* physPreset = m_memory.Alloc<PhysPreset>();
|
||||
physPreset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
|
||||
}
|
||||
AssetRegistration<AssetPhysPreset> registration(assetName, physPreset);
|
||||
|
||||
PhysPresetInfo physPresetInfo;
|
||||
memset(&physPresetInfo, 0, sizeof(physPresetInfo));
|
||||
InfoStringToPhysPresetConverter converter(infoString,
|
||||
physPresetInfo,
|
||||
m_zone.m_script_strings,
|
||||
m_memory,
|
||||
context,
|
||||
registration,
|
||||
phys_preset_fields,
|
||||
std::extent_v<decltype(phys_preset_fields)>);
|
||||
if (!converter.Convert())
|
||||
{
|
||||
std::cerr << std::format("Failed to parse phys preset: \"{}\"\n", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
CopyFromPhysPresetInfo(physPresetInfo, *physPreset);
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
|
||||
}
|
||||
} // namespace T6::phys_preset
|
||||
|
||||
@@ -4,18 +4,17 @@
|
||||
#include "Asset/AssetCreationResult.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
namespace T6::phys_preset
|
||||
{
|
||||
class InfoStringLoaderPhysPreset
|
||||
class InfoStringLoader
|
||||
{
|
||||
public:
|
||||
InfoStringLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
InfoStringLoader(MemoryManager& memory, Zone& zone);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
Zone& m_zone;
|
||||
};
|
||||
} // namespace T6
|
||||
} // namespace T6::phys_preset
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace T6;
|
||||
using namespace ::phys_preset;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -19,13 +20,13 @@ namespace
|
||||
public:
|
||||
RawLoaderPhysPreset(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
: m_search_path(searchPath),
|
||||
m_info_string_loader(memory, searchPath, zone)
|
||||
m_info_string_loader(memory, zone)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto fileName = phys_preset::GetFileNameForAssetName(assetName);
|
||||
const auto fileName = GetFileNameForAssetName(assetName);
|
||||
const auto file = m_search_path.Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
@@ -42,14 +43,14 @@ namespace
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
InfoStringLoaderPhysPreset m_info_string_loader;
|
||||
T6::phys_preset::InfoStringLoader m_info_string_loader;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace T6
|
||||
namespace T6::phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateRawPhysPresetLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||
{
|
||||
return std::make_unique<RawLoaderPhysPreset>(memory, searchPath, zone);
|
||||
}
|
||||
} // namespace T6
|
||||
} // namespace T6::phys_preset
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace T6
|
||||
namespace T6::phys_preset
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateRawPhysPresetLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
} // namespace T6
|
||||
std::unique_ptr<AssetCreator<AssetPhysPreset>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||
} // namespace T6::phys_preset
|
||||
|
||||
Reference in New Issue
Block a user