mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
chore: inject ZoneAssetCreationStateCollection to states
This commit is contained in:
parent
ef862ff246
commit
2313da1c12
@ -64,6 +64,7 @@ std::unique_ptr<XAssetInfoGeneric> GenericAssetRegistration::CreateXAssetInfo()
|
||||
|
||||
AssetCreationContext::AssetCreationContext(Zone& zone, const AssetCreatorCollection* creators, const IgnoredAssetLookup* ignoredAssetLookup)
|
||||
: ZoneAssetCreationStateContainer(zone),
|
||||
m_zone(zone),
|
||||
m_creators(creators),
|
||||
m_ignored_asset_lookup(ignoredAssetLookup)
|
||||
{
|
||||
|
@ -68,6 +68,7 @@ public:
|
||||
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;
|
||||
};
|
||||
|
@ -6,6 +6,21 @@
|
||||
#include <typeindex>
|
||||
#include <unordered_map>
|
||||
|
||||
class ZoneAssetCreationStateContainer;
|
||||
|
||||
class ZoneAssetCreationInjection
|
||||
{
|
||||
public:
|
||||
ZoneAssetCreationInjection(ZoneAssetCreationStateContainer& zoneStates, Zone& zone)
|
||||
: m_zone_states(zoneStates),
|
||||
m_zone(zone)
|
||||
{
|
||||
}
|
||||
|
||||
ZoneAssetCreationStateContainer& m_zone_states;
|
||||
Zone& m_zone;
|
||||
};
|
||||
|
||||
class IZoneAssetCreationState
|
||||
{
|
||||
protected:
|
||||
@ -18,7 +33,7 @@ public:
|
||||
IZoneAssetCreationState& operator=(const IZoneAssetCreationState& other) = default;
|
||||
IZoneAssetCreationState& operator=(IZoneAssetCreationState&& other) noexcept = default;
|
||||
|
||||
virtual void SetZone(Zone* zone)
|
||||
virtual void Inject(ZoneAssetCreationInjection& inject)
|
||||
{
|
||||
// Do nothing by default
|
||||
}
|
||||
@ -28,7 +43,7 @@ class ZoneAssetCreationStateContainer
|
||||
{
|
||||
public:
|
||||
ZoneAssetCreationStateContainer(Zone& zone)
|
||||
: m_zone(zone)
|
||||
: m_injection(*this, zone)
|
||||
{
|
||||
}
|
||||
|
||||
@ -42,16 +57,14 @@ public:
|
||||
return *dynamic_cast<T*>(foundEntry->second.get());
|
||||
|
||||
auto newState = std::make_unique<T>();
|
||||
newState->SetZone(&m_zone);
|
||||
newState->Inject(m_injection);
|
||||
auto* newStatePtr = newState.get();
|
||||
m_zone_asset_creation_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetCreationState>>(typeid(T), std::move(newState)));
|
||||
|
||||
return *newStatePtr;
|
||||
}
|
||||
|
||||
protected:
|
||||
Zone& m_zone;
|
||||
|
||||
private:
|
||||
ZoneAssetCreationInjection m_injection;
|
||||
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetCreationState>> m_zone_asset_creation_states;
|
||||
};
|
||||
|
@ -10,11 +10,11 @@ MenuConversionZoneState::MenuConversionZoneState()
|
||||
{
|
||||
}
|
||||
|
||||
void MenuConversionZoneState::SetZone(Zone* zone)
|
||||
void MenuConversionZoneState::Inject(ZoneAssetCreationInjection& inject)
|
||||
{
|
||||
auto* memory = zone->GetMemory();
|
||||
auto* memory = inject.m_zone.GetMemory();
|
||||
|
||||
m_zone = zone;
|
||||
m_zone = &inject.m_zone;
|
||||
m_supporting_data = memory->Create<ExpressionSupportingData>();
|
||||
memset(m_supporting_data, 0, sizeof(ExpressionSupportingData));
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace IW4
|
||||
ExpressionSupportingData* m_supporting_data;
|
||||
|
||||
MenuConversionZoneState();
|
||||
void SetZone(Zone* zone) override;
|
||||
void Inject(ZoneAssetCreationInjection& inject) override;
|
||||
|
||||
Statement_s* FindFunction(const std::string& functionName);
|
||||
|
||||
|
@ -10,11 +10,11 @@ MenuConversionZoneState::MenuConversionZoneState()
|
||||
{
|
||||
}
|
||||
|
||||
void MenuConversionZoneState::SetZone(Zone* zone)
|
||||
void MenuConversionZoneState::Inject(ZoneAssetCreationInjection& inject)
|
||||
{
|
||||
auto* memory = zone->GetMemory();
|
||||
auto* memory = inject.m_zone.GetMemory();
|
||||
|
||||
m_zone = zone;
|
||||
m_zone = &inject.m_zone;
|
||||
m_supporting_data = memory->Create<ExpressionSupportingData>();
|
||||
memset(m_supporting_data, 0, sizeof(ExpressionSupportingData));
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace IW5
|
||||
ExpressionSupportingData* m_supporting_data;
|
||||
|
||||
MenuConversionZoneState();
|
||||
void SetZone(Zone* zone) override;
|
||||
void Inject(ZoneAssetCreationInjection& inject) override;
|
||||
|
||||
Statement_s* FindFunction(const std::string& functionName);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user