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

chore: extract ZoneAssetLoaderContainer to separate class

This commit is contained in:
Jan
2025-01-03 10:23:30 +01:00
parent 41d97c0954
commit fa6f9451d2
10 changed files with 57 additions and 41 deletions

View File

@@ -10,7 +10,6 @@
#include <memory>
#include <string>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
@@ -27,10 +26,10 @@ public:
std::unordered_multimap<std::string, asset_type_t> m_ignored_asset_lookup;
};
class AssetCreationContext
class AssetCreationContext : public ZoneAssetLoaderContainer
{
public:
AssetCreationContext(Zone* zone, const AssetCreatorCollection* creators, const IgnoredAssetLookup* ignoredAssetLookup);
AssetCreationContext(Zone& zone, const AssetCreatorCollection* creators, const IgnoredAssetLookup* ignoredAssetLookup);
template<typename AssetType> XAssetInfo<typename AssetType::Type>* AddAsset(AssetRegistration<AssetType> registration)
{
@@ -66,29 +65,11 @@ public:
IndirectAssetReference LoadIndirectAssetReferenceGeneric(asset_type_t assetType, const std::string& assetName);
template<typename T> T* GetZoneAssetLoaderState()
{
static_assert(std::is_base_of_v<IZoneAssetLoaderState, T>, "T must inherit IZoneAssetLoaderState");
// T must also have a public default constructor
const auto foundEntry = m_zone_asset_loader_states.find(typeid(T));
if (foundEntry != m_zone_asset_loader_states.end())
return dynamic_cast<T*>(foundEntry->second.get());
auto newState = std::make_unique<T>();
newState->SetZone(m_zone);
auto* newStatePtr = newState.get();
m_zone_asset_loader_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetLoaderState>>(typeid(T), std::move(newState)));
return newStatePtr;
}
private:
[[nodiscard]] XAssetInfoGeneric* LoadDefaultAssetDependency(asset_type_t assetType, const std::string& assetName);
Zone* m_zone;
const AssetCreatorCollection* m_creators;
const IgnoredAssetLookup* m_ignored_asset_lookup;
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetLoaderState>> m_zone_asset_loader_states;
};
#include "AssetCreatorCollection.h"