2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-01-12 11:41:50 +00:00

fix: do not override properties of foreign zones

This commit is contained in:
Jan Laupetin
2025-12-25 15:29:32 +01:00
parent 2442d7160c
commit ba39e3f4d9
5 changed files with 32 additions and 17 deletions

View File

@@ -1,6 +1,9 @@
#include "GlobalAssetPoolsLoader.h"
GlobalAssetPoolsAssetStealer::GlobalAssetPoolsAssetStealer(GenericAssetRegistration& registration, Zone& zone, Zone& foreignZone, AssetCreationContext& context)
GlobalAssetPoolsRegistrationPreparation::GlobalAssetPoolsRegistrationPreparation(GenericAssetRegistration& registration,
Zone& zone,
Zone& foreignZone,
AssetCreationContext& context)
: m_registration(registration),
m_zone(zone),
m_foreign_zone(foreignZone),
@@ -9,7 +12,7 @@ GlobalAssetPoolsAssetStealer::GlobalAssetPoolsAssetStealer(GenericAssetRegistrat
{
}
std::optional<XAssetInfoGeneric*> GlobalAssetPoolsAssetStealer::Visit_Dependency(const asset_type_t assetType, const char* assetName)
std::optional<XAssetInfoGeneric*> GlobalAssetPoolsRegistrationPreparation::Visit_Dependency(const asset_type_t assetType, const char* assetName)
{
if (assetName && assetName[0] == ',')
{
@@ -24,7 +27,7 @@ std::optional<XAssetInfoGeneric*> GlobalAssetPoolsAssetStealer::Visit_Dependency
if (assetDependency)
{
m_registration.AddDependency(assetDependency);
return assetDependency;
return std::nullopt;
}
}
@@ -32,25 +35,27 @@ std::optional<XAssetInfoGeneric*> GlobalAssetPoolsAssetStealer::Visit_Dependency
if (newDependency)
{
m_registration.AddDependency(newDependency);
return newDependency;
return std::nullopt;
}
m_failure = true;
return std::nullopt;
}
std::optional<scr_string_t> GlobalAssetPoolsAssetStealer::Visit_ScriptString(scr_string_t scriptString)
std::optional<scr_string_t> GlobalAssetPoolsRegistrationPreparation::Visit_ScriptString(scr_string_t scriptString)
{
// Make sure any used script string is available in the created zone
return m_zone.m_script_strings.AddOrGetScriptString(m_foreign_zone.m_script_strings.CValue(scriptString));
m_zone.m_script_strings.AddOrGetScriptString(m_foreign_zone.m_script_strings.CValue(scriptString));
m_registration.AddScriptString(scriptString);
return std::nullopt;
}
void GlobalAssetPoolsAssetStealer::Visit_IndirectAssetRef(const asset_type_t assetType, const char* assetName)
void GlobalAssetPoolsRegistrationPreparation::Visit_IndirectAssetRef(const asset_type_t assetType, const char* assetName)
{
m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReferenceGeneric(assetType, assetName));
}
bool GlobalAssetPoolsAssetStealer::Failed() const
bool GlobalAssetPoolsRegistrationPreparation::Failed() const
{
return m_failure;
}

View File

@@ -5,10 +5,10 @@
#include "Marking/BaseAssetMarker.h"
#include "Pool/GlobalAssetPool.h"
class GlobalAssetPoolsAssetStealer : public AssetVisitor
class GlobalAssetPoolsRegistrationPreparation : public AssetVisitor
{
public:
GlobalAssetPoolsAssetStealer(GenericAssetRegistration& registration, Zone& zone, Zone& foreignZone, AssetCreationContext& context);
GlobalAssetPoolsRegistrationPreparation(GenericAssetRegistration& registration, Zone& zone, Zone& foreignZone, AssetCreationContext& context);
std::optional<XAssetInfoGeneric*> Visit_Dependency(asset_type_t assetType, const char* assetName) override;
std::optional<scr_string_t> Visit_ScriptString(scr_string_t scriptString) override;
@@ -44,11 +44,13 @@ public:
AssetRegistration<AssetType> registration(assetName, existingAsset->Asset());
GlobalAssetPoolsAssetStealer stealer(registration, m_zone, *existingAsset->m_zone, context);
AssetMarker<AssetType> marker(stealer);
GlobalAssetPoolsRegistrationPreparation registrationPreparation(registration, m_zone, *existingAsset->m_zone, context);
AssetMarker<AssetType> marker(registrationPreparation);
marker.Mark(existingAsset->Asset());
auto* newAsset = context.AddAsset(std::move(registration));
// Make sure we remember this asset came from a different zone
newAsset->m_zone = existingAsset->m_zone;
return AssetCreationResult::Success(newAsset);
}