@ -28,7 +28,7 @@ namespace AzToolsFramework
{
namespace Internal
{
AZ : : JsonSerializationResult : : ResultCode JsonIssueReporter ( AZStd : : string & scratchBuffer ,
static AZ : : JsonSerializationResult : : ResultCode JsonIssueReporter ( AZStd : : string & scratchBuffer ,
AZStd : : string_view message , AZ : : JsonSerializationResult : : ResultCode result , AZStd : : string_view path )
{
namespace JSR = AZ : : JsonSerializationResult ;
@ -48,6 +48,66 @@ namespace AzToolsFramework
return result ;
}
static bool StoreInstanceInPrefabDom (
const Instance & instance ,
PrefabDom & prefabDom ,
AZStd : : vector < AZ : : Data : : Asset < AZ : : Data : : AssetData > > * referencedAssets ,
StoreFlags flags )
{
InstanceEntityIdMapper entityIdMapper ;
entityIdMapper . SetStoringInstance ( instance ) ;
// Need to store the id mapper as both its type and its base type
// Metadata is found by type id and we need access to both types at different levels (Instance, EntityId)
AZ : : JsonSerializerSettings settings ;
settings . m_metadata . Add ( static_cast < AZ : : JsonEntityIdSerializer : : JsonEntityIdMapper * > ( & entityIdMapper ) ) ;
settings . m_metadata . Add ( & entityIdMapper ) ;
if ( referencedAssets )
{
settings . m_metadata . Add ( AZ : : Data : : SerializedAssetTracker { } ) ;
}
if ( ( flags & StoreFlags : : StripDefaultValues ) ! = StoreFlags : : StripDefaultValues )
{
settings . m_keepDefaults = true ;
}
if ( ( flags & StoreFlags : : StoreLinkIds ) ! = StoreFlags : : None )
{
settings . m_metadata . Create < LinkIdMetadata > ( ) ;
}
AZStd : : string scratchBuffer ;
auto issueReportingCallback = [ & scratchBuffer ] (
AZStd : : string_view message , AZ : : JsonSerializationResult : : ResultCode result ,
AZStd : : string_view path ) - > AZ : : JsonSerializationResult : : ResultCode
{
return Internal : : JsonIssueReporter ( scratchBuffer , message , result , path ) ;
} ;
settings . m_reporting = AZStd : : move ( issueReportingCallback ) ;
AZ : : JsonSerializationResult : : ResultCode result =
AZ : : JsonSerialization : : Store ( prefabDom , prefabDom . GetAllocator ( ) , instance , settings ) ;
if ( result . GetProcessing ( ) = = AZ : : JsonSerializationResult : : Processing : : Halted )
{
AZ_Error (
" Prefab " , false ,
" Failed to serialize prefab instance with source path %s. "
" Unable to proceed. " ,
instance . GetTemplateSourcePath ( ) . c_str ( ) ) ;
return false ;
}
if ( referencedAssets )
{
* referencedAssets = AZStd : : move ( settings . m_metadata . Find < AZ : : Data : : SerializedAssetTracker > ( ) - > GetTrackedAssets ( ) ) ;
}
return true ;
}
}
PrefabDomValueReference FindPrefabDomValue ( PrefabDomValue & parentValue , const char * valueName )
@ -74,49 +134,7 @@ namespace AzToolsFramework
bool StoreInstanceInPrefabDom ( const Instance & instance , PrefabDom & prefabDom , StoreFlags flags )
{
InstanceEntityIdMapper entityIdMapper ;
entityIdMapper . SetStoringInstance ( instance ) ;
// Need to store the id mapper as both its type and its base type
// Meta data is found by type id and we need access to both types at different levels (Instance, EntityId)
AZ : : JsonSerializerSettings settings ;
settings . m_metadata . Add ( static_cast < AZ : : JsonEntityIdSerializer : : JsonEntityIdMapper * > ( & entityIdMapper ) ) ;
settings . m_metadata . Add ( & entityIdMapper ) ;
if ( ( flags & StoreFlags : : StripDefaultValues ) ! = StoreFlags : : StripDefaultValues )
{
settings . m_keepDefaults = true ;
}
if ( ( flags & StoreFlags : : StoreLinkIds ) ! = StoreFlags : : None )
{
settings . m_metadata . Create < LinkIdMetadata > ( ) ;
}
AZStd : : string scratchBuffer ;
auto issueReportingCallback = [ & scratchBuffer ]
( AZStd : : string_view message , AZ : : JsonSerializationResult : : ResultCode result ,
AZStd : : string_view path ) - > AZ : : JsonSerializationResult : : ResultCode
{
return Internal : : JsonIssueReporter ( scratchBuffer , message , result , path ) ;
} ;
settings . m_reporting = AZStd : : move ( issueReportingCallback ) ;
AZ : : JsonSerializationResult : : ResultCode result =
AZ : : JsonSerialization : : Store ( prefabDom , prefabDom . GetAllocator ( ) , instance , settings ) ;
if ( result . GetProcessing ( ) = = AZ : : JsonSerializationResult : : Processing : : Halted )
{
AZ_Error ( " Prefab " , false ,
" Failed to serialize prefab instance with source path %s. "
" Unable to proceed. " ,
instance . GetTemplateSourcePath ( ) . c_str ( ) ) ;
return false ;
}
return true ;
return Internal : : StoreInstanceInPrefabDom ( instance , prefabDom , nullptr , flags ) ;
}
bool StoreInstanceInPrefabDom (
@ -125,52 +143,7 @@ namespace AzToolsFramework
AZStd : : vector < AZ : : Data : : Asset < AZ : : Data : : AssetData > > & referencedAssets ,
StoreFlags flags )
{
InstanceEntityIdMapper entityIdMapper ;
entityIdMapper . SetStoringInstance ( instance ) ;
// Need to store the id mapper as both its type and its base type
// Meta data is found by type id and we need access to both types at different levels (Instance, EntityId)
AZ : : JsonSerializerSettings settings ;
settings . m_metadata . Add ( static_cast < AZ : : JsonEntityIdSerializer : : JsonEntityIdMapper * > ( & entityIdMapper ) ) ;
settings . m_metadata . Add ( & entityIdMapper ) ;
settings . m_metadata . Add ( AZ : : Data : : SerializedAssetTracker { } ) ;
if ( ( flags & StoreFlags : : StripDefaultValues ) ! = StoreFlags : : StripDefaultValues )
{
settings . m_keepDefaults = true ;
}
if ( ( flags & StoreFlags : : StoreLinkIds ) ! = StoreFlags : : None )
{
settings . m_metadata . Create < LinkIdMetadata > ( ) ;
}
AZStd : : string scratchBuffer ;
auto issueReportingCallback = [ & scratchBuffer ] (
AZStd : : string_view message , AZ : : JsonSerializationResult : : ResultCode result ,
AZStd : : string_view path ) - > AZ : : JsonSerializationResult : : ResultCode
{
return Internal : : JsonIssueReporter ( scratchBuffer , message , result , path ) ;
} ;
settings . m_reporting = AZStd : : move ( issueReportingCallback ) ;
AZ : : JsonSerializationResult : : ResultCode result =
AZ : : JsonSerialization : : Store ( prefabDom , prefabDom . GetAllocator ( ) , instance , settings ) ;
if ( result . GetProcessing ( ) = = AZ : : JsonSerializationResult : : Processing : : Halted )
{
AZ_Error (
" Prefab " , false ,
" Failed to serialize prefab instance with source path %s. "
" Unable to proceed. " ,
instance . GetTemplateSourcePath ( ) . c_str ( ) ) ;
return false ;
}
referencedAssets = AZStd : : move ( settings . m_metadata . Find < AZ : : Data : : SerializedAssetTracker > ( ) - > GetTrackedAssets ( ) ) ;
return true ;
return Internal : : StoreInstanceInPrefabDom ( instance , prefabDom , & referencedAssets , flags ) ;
}
bool StoreEntityInPrefabDomFormat ( const AZ : : Entity & entity , Instance & owningInstance , PrefabDom & prefabDom , StoreFlags flags )