mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-27 12:31:50 +00:00
fix: do not override properties of foreign zones
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
#include "GlobalAssetPoolsLoader.h"
|
#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_registration(registration),
|
||||||
m_zone(zone),
|
m_zone(zone),
|
||||||
m_foreign_zone(foreignZone),
|
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] == ',')
|
if (assetName && assetName[0] == ',')
|
||||||
{
|
{
|
||||||
@@ -24,7 +27,7 @@ std::optional<XAssetInfoGeneric*> GlobalAssetPoolsAssetStealer::Visit_Dependency
|
|||||||
if (assetDependency)
|
if (assetDependency)
|
||||||
{
|
{
|
||||||
m_registration.AddDependency(assetDependency);
|
m_registration.AddDependency(assetDependency);
|
||||||
return assetDependency;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,25 +35,27 @@ std::optional<XAssetInfoGeneric*> GlobalAssetPoolsAssetStealer::Visit_Dependency
|
|||||||
if (newDependency)
|
if (newDependency)
|
||||||
{
|
{
|
||||||
m_registration.AddDependency(newDependency);
|
m_registration.AddDependency(newDependency);
|
||||||
return newDependency;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_failure = true;
|
m_failure = true;
|
||||||
return std::nullopt;
|
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
|
// 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));
|
m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReferenceGeneric(assetType, assetName));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GlobalAssetPoolsAssetStealer::Failed() const
|
bool GlobalAssetPoolsRegistrationPreparation::Failed() const
|
||||||
{
|
{
|
||||||
return m_failure;
|
return m_failure;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
#include "Marking/BaseAssetMarker.h"
|
#include "Marking/BaseAssetMarker.h"
|
||||||
#include "Pool/GlobalAssetPool.h"
|
#include "Pool/GlobalAssetPool.h"
|
||||||
|
|
||||||
class GlobalAssetPoolsAssetStealer : public AssetVisitor
|
class GlobalAssetPoolsRegistrationPreparation : public AssetVisitor
|
||||||
{
|
{
|
||||||
public:
|
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<XAssetInfoGeneric*> Visit_Dependency(asset_type_t assetType, const char* assetName) override;
|
||||||
std::optional<scr_string_t> Visit_ScriptString(scr_string_t scriptString) override;
|
std::optional<scr_string_t> Visit_ScriptString(scr_string_t scriptString) override;
|
||||||
@@ -44,11 +44,13 @@ public:
|
|||||||
|
|
||||||
AssetRegistration<AssetType> registration(assetName, existingAsset->Asset());
|
AssetRegistration<AssetType> registration(assetName, existingAsset->Asset());
|
||||||
|
|
||||||
GlobalAssetPoolsAssetStealer stealer(registration, m_zone, *existingAsset->m_zone, context);
|
GlobalAssetPoolsRegistrationPreparation registrationPreparation(registration, m_zone, *existingAsset->m_zone, context);
|
||||||
AssetMarker<AssetType> marker(stealer);
|
AssetMarker<AssetType> marker(registrationPreparation);
|
||||||
marker.Mark(existingAsset->Asset());
|
marker.Mark(existingAsset->Asset());
|
||||||
|
|
||||||
auto* newAsset = context.AddAsset(std::move(registration));
|
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);
|
return AssetCreationResult::Success(newAsset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,7 +261,8 @@ namespace
|
|||||||
"{0}::{0}({1}* asset, const Zone& zone, IZoneOutputStream& stream)", WriterClassName(m_env.m_asset), m_env.m_asset->m_definition->GetFullName())
|
"{0}::{0}({1}* asset, const Zone& zone, IZoneOutputStream& stream)", WriterClassName(m_env.m_asset), m_env.m_asset->m_definition->GetFullName())
|
||||||
|
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}::EnumEntry, AssetName<{0}>(*asset)), zone, stream)", m_env.m_asset->m_asset_name)
|
LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}::EnumEntry, NonReferenceAssetName(AssetName<{0}>(*asset))), zone, stream)",
|
||||||
|
m_env.m_asset->m_asset_name)
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
|
|
||||||
LINE("{")
|
LINE("{")
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ AssetWriter::AssetWriter(XAssetInfoGeneric* asset, const Zone& zone, IZoneOutput
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* AssetWriter::NonReferenceAssetName(const char* assetName)
|
||||||
|
{
|
||||||
|
if (assetName && assetName[0] == ',')
|
||||||
|
return &assetName[1];
|
||||||
|
|
||||||
|
return assetName;
|
||||||
|
}
|
||||||
|
|
||||||
scr_string_t AssetWriter::UseScriptString(const scr_string_t scrString) const
|
scr_string_t AssetWriter::UseScriptString(const scr_string_t scrString) const
|
||||||
{
|
{
|
||||||
assert(scrString < m_asset->m_zone->m_script_strings.Count());
|
assert(scrString < m_asset->m_zone->m_script_strings.Count());
|
||||||
@@ -17,9 +25,7 @@ scr_string_t AssetWriter::UseScriptString(const scr_string_t scrString) const
|
|||||||
if (m_asset->m_zone == &m_zone)
|
if (m_asset->m_zone == &m_zone)
|
||||||
return scrString;
|
return scrString;
|
||||||
|
|
||||||
// This swap should have already been performed in GlobalAssetPoolsLoader
|
// The asset comes from a different zone, we need to translate it
|
||||||
assert(false);
|
|
||||||
|
|
||||||
const auto strValue = m_asset->m_zone->m_script_strings.CValue(scrString);
|
const auto strValue = m_asset->m_zone->m_script_strings.CValue(scrString);
|
||||||
return m_zone.m_script_strings.GetScriptString(strValue);
|
return m_zone.m_script_strings.GetScriptString(strValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ class AssetWriter : public ContentWriterBase
|
|||||||
protected:
|
protected:
|
||||||
AssetWriter(XAssetInfoGeneric* asset, const Zone& zone, IZoneOutputStream& stream);
|
AssetWriter(XAssetInfoGeneric* asset, const Zone& zone, IZoneOutputStream& stream);
|
||||||
|
|
||||||
_NODISCARD scr_string_t UseScriptString(scr_string_t scrString) const;
|
[[nodiscard]] static const char* NonReferenceAssetName(const char* assetName);
|
||||||
|
[[nodiscard]] scr_string_t UseScriptString(scr_string_t scrString) const;
|
||||||
void WriteScriptStringArray(bool atStreamStart, size_t count);
|
void WriteScriptStringArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
XAssetInfoGeneric* m_asset;
|
XAssetInfoGeneric* m_asset;
|
||||||
|
|||||||
Reference in New Issue
Block a user