Added all the missing serializer support, fixed up serialization notification
Signed-off-by: chcurran <82187351+carlitosan@users.noreply.github.com>
This commit is contained in:
+4
-12
@@ -44,18 +44,10 @@ namespace {{attribute_Namespace}}
|
||||
{
|
||||
{% endif %}
|
||||
{% set className = Class.attrib['Name'] %}
|
||||
{% if Class.attrib['Base'] is defined %}
|
||||
{% if Class.attrib['Base'].split(';')|length > 1 %}
|
||||
{% set baseClass = Class.attrib['Base'].split(';')[0] %}
|
||||
{% set baseClasses = ", ".join(Class.attrib['Base'].split(';')) %}
|
||||
{% else %}
|
||||
{% set baseClass = Class.attrib['Base'] %}
|
||||
{% set baseClasses = Class.attrib['Base'] %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% set baseClass = "ScriptCanvas::Node" %}
|
||||
{% set baseClasses = "ScriptCanvas::Node" %}
|
||||
{% endif %}
|
||||
{% set baseClassPair = [] %}
|
||||
{% if macros.CreateBaseClassVariables(Class, baseClassPair) %}{% endif %}
|
||||
{% set baseClass = baseClassPair[0] %}
|
||||
{% set baseClasses = baseClassPair[1] %}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+7
-12
@@ -4,6 +4,8 @@ For complete copyright and license terms please see the LICENSE at the root of t
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
#}
|
||||
{% import 'ScriptCanvas_Macros.jinja' as macros %}
|
||||
|
||||
{% macro add_attribute(attribute, tags) %}
|
||||
{% set value = tags[attribute] %}
|
||||
{% if value is defined %}
|
||||
@@ -26,18 +28,11 @@ SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
#include "{{ xml.attrib['Include'] }}"
|
||||
|
||||
{% for Class in xml.iter('Class') %}
|
||||
{% if Class.attrib['Base'] is defined %}
|
||||
{% if Class.attrib['Base'].split(';')|length > 1 %}
|
||||
{% set baseClass = Class.attrib['Base'].split(';')[0] %}
|
||||
{% set baseClasses = ", ".join(Class.attrib['Base'].split(';')) %}
|
||||
{% else %}
|
||||
{% set baseClass = Class.attrib['Base'] %}
|
||||
{% set baseClasses = Class.attrib['Base'] %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% set baseClass = "ScriptCanvas::Node" %}
|
||||
{% set baseClasses = "ScriptCanvas::Node" %}
|
||||
{% endif %}
|
||||
{% set baseClassPair = [] %}
|
||||
{% if macros.CreateBaseClassVariables(Class, baseClassPair) %}{% endif %}
|
||||
{% set baseClass = baseClassPair[0] %}
|
||||
{% set baseClasses = baseClassPair[1] %}
|
||||
|
||||
void {{ Class.attrib['QualifiedName'] }}::ConfigureSlots()
|
||||
{
|
||||
{{ baseClass }}::ConfigureSlots();
|
||||
|
||||
@@ -173,11 +173,29 @@ AZStd::tuple<{{returnTypes|join(", ")}}>
|
||||
|
||||
{# ------- #}
|
||||
|
||||
{# CreateBaseClassVariables #}
|
||||
{# Creates "baseClass" and "baseClasses" variables to use when needed "baseClasses" is a comma separated list that in includes baseClass #}
|
||||
{%- macro CreateBaseClassVariables(Class, baseClassPair) -%}
|
||||
{% set baseAttrib = Class.attrib['Base'] %}
|
||||
{% if baseAttrib is defined %}
|
||||
{% if baseAttrib.split(';')|length > 1 %}
|
||||
{% if baseClassPair.append(baseAttrib.split(';')[0]) %}{% endif %}
|
||||
{% if baseClassPair.append(", ".join(baseAttrib.split(';'))) %}{% endif %}
|
||||
{% else %}
|
||||
{% if baseClassPair.append(baseAttrib) %}{% endif %}
|
||||
{% if baseClassPair.append(baseAttrib) %}{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if baseClassPair.append("ScriptCanvas::Node") %}{% endif %}
|
||||
{% if baseClassPair.append("ScriptCanvas::Node") %}{% endif %}
|
||||
{% endif %}
|
||||
{%- endmacro -%}
|
||||
{# ------- #}
|
||||
|
||||
{# ------------------------------------------------------------------------------------- #}
|
||||
{# NODEABLES #}
|
||||
|
||||
{# TODO-LS: This macro lacks parsing the parameters provided to a Contract tag #}
|
||||
{# TODO: This macro lacks parsing the parameters provided to a Contract tag #}
|
||||
{%- macro AddContract(configurationName, item) -%}
|
||||
|
||||
{% set contracts = [] %}
|
||||
|
||||
@@ -2041,21 +2041,6 @@ namespace ScriptCanvas
|
||||
}
|
||||
}
|
||||
|
||||
void Datum::OnSerializeBegin()
|
||||
{
|
||||
if (m_type.GetType() == Data::eType::BehaviorContextObject)
|
||||
{
|
||||
if (BehaviorContextObjectPtr ptr = (*AZStd::any_cast<BehaviorContextObjectPtr>(&m_storage.value)))
|
||||
{
|
||||
ptr->OnSerializeBegin();
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Error("ScriptCanvas", false, AZStd::string::format("Datum type (%s) failed to serialized, did not store BehaviorContextObjectPtr properly", m_type.GetAZType().ToString<AZStd::string>().c_str()).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Datum::OnDeserialize()
|
||||
{
|
||||
if (m_type.GetType() == Data::eType::BehaviorContextObject)
|
||||
@@ -2080,14 +2065,9 @@ namespace ScriptCanvas
|
||||
}
|
||||
|
||||
#if defined(OBJECT_STREAM_EDITOR_ASSET_LOADING_SUPPORT_ENABLED)////
|
||||
void Datum::OnReadBegin()
|
||||
{
|
||||
OnSerializeBegin();
|
||||
}
|
||||
|
||||
void Datum::OnWriteEnd()
|
||||
{
|
||||
OnSerializeEnd();
|
||||
OnDeserialize();
|
||||
}
|
||||
#endif//defined(OBJECT_STREAM_EDITOR_ASSET_LOADING_SUPPORT_ENABLED)
|
||||
|
||||
|
||||
@@ -240,13 +240,6 @@ namespace ScriptCanvas
|
||||
class SerializeContextEventHandler : public AZ::SerializeContext::IEventHandler
|
||||
{
|
||||
public:
|
||||
/// Called after we are done writing to the instance pointed by classPtr.
|
||||
void OnReadBegin(void* classPtr) override
|
||||
{
|
||||
Datum* datum = reinterpret_cast<Datum*>(classPtr);
|
||||
datum->OnReadBegin();
|
||||
}
|
||||
|
||||
/// Called after we are done writing to the instance pointed by classPtr.
|
||||
void OnWriteEnd(void* classPtr) override
|
||||
{
|
||||
@@ -352,13 +345,9 @@ namespace ScriptCanvas
|
||||
|
||||
void OnDatumEdited();
|
||||
|
||||
void OnSerializeBegin() override;
|
||||
|
||||
void OnDeserialize() override;
|
||||
|
||||
#if defined(OBJECT_STREAM_EDITOR_ASSET_LOADING_SUPPORT_ENABLED)////
|
||||
void OnReadBegin();
|
||||
|
||||
void OnWriteEnd();
|
||||
#endif//defined(OBJECT_STREAM_EDITOR_ASSET_LOADING_SUPPORT_ENABLED)
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ namespace ScriptCanvas
|
||||
AZ_RTTI(SerializationListener, "{CA4EE281-30B3-4928-BCD8-9305CE75E463}");
|
||||
virtual ~SerializationListener() {}
|
||||
|
||||
virtual void OnSerializeBegin() {}
|
||||
virtual void OnSerializeEnd() {}
|
||||
virtual void OnSerialize() {}
|
||||
|
||||
virtual void OnDeserialize() {}
|
||||
};
|
||||
|
||||
@@ -17,14 +17,6 @@
|
||||
|
||||
namespace ScriptCanvas
|
||||
{
|
||||
void BehaviorContextObject::OnSerializeBegin()
|
||||
{
|
||||
if (!IsOwned())
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void BehaviorContextObject::Reflect(AZ::ReflectContext* reflection)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection))
|
||||
@@ -104,6 +96,12 @@ namespace ScriptCanvas
|
||||
: BehaviorContextObjectPtr(aznew BehaviorContextObject(reference, GetAnyTypeInfoReference(typeID), referenceFlags));
|
||||
}
|
||||
|
||||
void BehaviorContextObject::Deserialize(BehaviorContextObject& target, const AZ::BehaviorClass& behaviorClass, AZStd::any& source)
|
||||
{
|
||||
target.m_object = AZStd::move(AZStd::any(AZStd::any_cast<void>(&source), GetAnyTypeInfoObject(behaviorClass)));
|
||||
target.m_flags = Owned;
|
||||
}
|
||||
|
||||
void BehaviorContextObject::release()
|
||||
{
|
||||
if (--m_referenceCount == 0)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
namespace AZ
|
||||
{
|
||||
class ReflectContext;
|
||||
class BehaviorContextObjectSerializer;
|
||||
}
|
||||
|
||||
namespace ScriptCanvas
|
||||
@@ -30,6 +31,7 @@ namespace ScriptCanvas
|
||||
{
|
||||
friend struct AZStd::IntrusivePtrCountPolicy<BehaviorContextObject>;
|
||||
friend class Datum;
|
||||
friend class AZ::BehaviorContextObjectSerializer;
|
||||
|
||||
public:
|
||||
AZ_TYPE_INFO(BehaviorContextObject, "{B735214D-5182-4536-B748-61EC83C1F007}");
|
||||
@@ -81,6 +83,8 @@ namespace ScriptCanvas
|
||||
|
||||
AZ_INLINE static BehaviorContextObject* CreateDefaultHeap(const AZ::BehaviorClass& behaviorClass);
|
||||
|
||||
static void Deserialize(BehaviorContextObject& target, const AZ::BehaviorClass& behaviorClass, AZStd::any& source);
|
||||
|
||||
// use the SSO optimization on behavior class size ALIGNED with a placement new of behavior class create
|
||||
AZ_FORCE_INLINE static AnyTypeInfo GetAnyTypeInfoObject(const AZ::BehaviorClass& behaviorClass);
|
||||
|
||||
@@ -104,10 +108,10 @@ namespace ScriptCanvas
|
||||
//...so don't use the ctors, use the Create functions...
|
||||
//...the friend declarations are here for compatibility with the serialization system only
|
||||
AZ_FORCE_INLINE BehaviorContextObject() = default;
|
||||
|
||||
BehaviorContextObject& operator=(const BehaviorContextObject&) = delete;
|
||||
|
||||
BehaviorContextObject(const BehaviorContextObject&) = delete;
|
||||
BehaviorContextObject& operator=(const BehaviorContextObject&) = default;
|
||||
BehaviorContextObject(const BehaviorContextObject&) = default;
|
||||
BehaviorContextObject(BehaviorContextObject&&) = default;
|
||||
BehaviorContextObject& operator=(BehaviorContextObject&& source) = default;
|
||||
|
||||
// copy ctor
|
||||
AZ_FORCE_INLINE BehaviorContextObject(const void* source, const AnyTypeInfo& typeInfo, AZ::u32 flags);
|
||||
@@ -119,8 +123,6 @@ namespace ScriptCanvas
|
||||
|
||||
AZ_FORCE_INLINE bool IsOwned() const;
|
||||
|
||||
void OnSerializeBegin();
|
||||
|
||||
AZ_FORCE_INLINE void add_ref();
|
||||
|
||||
void release();
|
||||
|
||||
@@ -188,6 +188,7 @@ namespace ScriptCanvas
|
||||
RefreshActiveIndexes();
|
||||
|
||||
ConfigureContracts();
|
||||
SetWarnOnMissingFunction(true);
|
||||
}
|
||||
|
||||
SlotId MethodOverloaded::AddMethodInputSlot(const MethodConfiguration& config, size_t argumentIndex)
|
||||
@@ -400,10 +401,6 @@ namespace ScriptCanvas
|
||||
}
|
||||
|
||||
#if defined(OBJECT_STREAM_EDITOR_ASSET_LOADING_SUPPORT_ENABLED)////
|
||||
void MethodOverloaded::OnWriteBegin()
|
||||
{
|
||||
}
|
||||
|
||||
void MethodOverloaded::OnWriteEnd()
|
||||
{
|
||||
OnDeserialize();
|
||||
|
||||
@@ -97,8 +97,7 @@ namespace ScriptCanvas
|
||||
// SerializeContextReadWriteHandler
|
||||
void OnReadBegin() {}
|
||||
void OnReadEnd() {}
|
||||
|
||||
void OnWriteBegin();
|
||||
void OnWriteBegin() {}
|
||||
void OnWriteEnd();
|
||||
#endif//defined(OBJECT_STREAM_EDITOR_ASSET_LOADING_SUPPORT_ENABLED)
|
||||
|
||||
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/AZStdAnyDataContainer.inl>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <ScriptCanvas/Asset/RuntimeAsset.h>
|
||||
#include <ScriptCanvas/Serialization/BehaviorContextObjectSerializer.h>
|
||||
|
||||
using namespace ScriptCanvas;
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
AZ_CLASS_ALLOCATOR_IMPL(BehaviorContextObjectSerializer, SystemAllocator, 0);
|
||||
|
||||
JsonSerializationResult::Result BehaviorContextObjectSerializer::Load
|
||||
( void* outputValue
|
||||
, [[maybe_unused]] const Uuid& outputValueTypeId
|
||||
, const rapidjson::Value& inputValue
|
||||
, JsonDeserializerContext& context)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(outputValueTypeId == azrtti_typeid<BehaviorContextObject>(), "BehaviorContextObjectSerializer Load against output typeID"
|
||||
"that was not BehaviorContextObject");
|
||||
AZ_Assert(outputValue, "BehaviorContextObjectSerializer Load against null output");
|
||||
|
||||
JsonSerializationResult::ResultCode result(JSR::Tasks::ReadField);
|
||||
auto outputBehaviorContextObject = reinterpret_cast<BehaviorContextObject*>(outputValue);
|
||||
|
||||
bool isOwned = false;
|
||||
result.Combine(ContinueLoadingFromJsonObjectField
|
||||
( &isOwned
|
||||
, azrtti_typeid<bool>()
|
||||
, inputValue
|
||||
, "isOwned"
|
||||
, context));
|
||||
|
||||
if (isOwned)
|
||||
{
|
||||
AZStd::any storage;
|
||||
{ // any storage begin
|
||||
|
||||
auto typeIdMember = inputValue.FindMember(JsonSerialization::TypeIdFieldIdentifier);
|
||||
if (typeIdMember == inputValue.MemberEnd())
|
||||
{
|
||||
return context.Report
|
||||
(JSR::Tasks::ReadField
|
||||
, JSR::Outcomes::Missing
|
||||
, AZStd::string::format("BehaviorContextObjectSerializer::Load failed to load the %s member"
|
||||
, JsonSerialization::TypeIdFieldIdentifier));
|
||||
}
|
||||
|
||||
AZ::Uuid typeId;
|
||||
result.Combine(LoadTypeId(typeId, typeIdMember->value, context));
|
||||
if (typeId.IsNull())
|
||||
{
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Catastrophic
|
||||
, "BehaviorContextObjectSerializer::Load failed to load the AZ TypeId of the value");
|
||||
}
|
||||
|
||||
storage = context.GetSerializeContext()->CreateAny(typeId);
|
||||
if (storage.empty() || storage.type() != typeId)
|
||||
{
|
||||
return context.Report(result, "BehaviorContextObjectSerializer::Load failed to load a value matched the reported AZ "
|
||||
"TypeId. The C++ declaration may have been deleted or changed.");
|
||||
}
|
||||
|
||||
result.Combine(ContinueLoadingFromJsonObjectField(AZStd::any_cast<void>(&storage), typeId, inputValue, "value", context));
|
||||
} // any storage end
|
||||
|
||||
auto bcClass = AZ::BehaviorContextHelper::GetClass(storage.type());
|
||||
BehaviorContextObject::Deserialize(*outputBehaviorContextObject, *bcClass, storage);
|
||||
}
|
||||
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "BehaviorContextObjectSerializer Load finished loading BehaviorContextObject"
|
||||
: "BehaviorContextObjectSerializer Load failed to load BehaviorContextObject");
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result BehaviorContextObjectSerializer::Store
|
||||
( rapidjson::Value& outputValue
|
||||
, const void* inputValue
|
||||
, const void* defaultValue
|
||||
, [[maybe_unused]] const Uuid& valueTypeId
|
||||
, JsonSerializerContext& context)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(valueTypeId == azrtti_typeid<BehaviorContextObject>(), "BehaviorContextObjectSerializer Store against value typeID that "
|
||||
"was not BehaviorContextObject");
|
||||
AZ_Assert(inputValue, "BehaviorContextObjectSerializer Store against null inputValue pointer ");
|
||||
|
||||
auto defaultScriptDataPtr = reinterpret_cast<const BehaviorContextObject*>(defaultValue);
|
||||
auto inputScriptDataPtr = reinterpret_cast<const BehaviorContextObject*>(inputValue);
|
||||
|
||||
if (defaultScriptDataPtr)
|
||||
{
|
||||
if (AZ::Helpers::CompareAnyValue(inputScriptDataPtr->ToAny(), defaultScriptDataPtr->ToAny()))
|
||||
{
|
||||
return context.Report
|
||||
( JSR::Tasks::WriteValue, JSR::Outcomes::DefaultsUsed, "BehaviorContextObjectSerializer Store used defaults "
|
||||
"for BehaviorContextObject");
|
||||
}
|
||||
}
|
||||
|
||||
outputValue.SetObject();
|
||||
JSR::ResultCode result(JSR::Tasks::WriteValue);
|
||||
const bool isInputOwned = inputScriptDataPtr->IsOwned();
|
||||
const bool isDefaultOwned = defaultScriptDataPtr ? defaultScriptDataPtr->IsOwned() : false;
|
||||
result.Combine(ContinueStoringToJsonObjectField
|
||||
( outputValue
|
||||
, "isOwned"
|
||||
, &isInputOwned
|
||||
, &isDefaultOwned
|
||||
, azrtti_typeid<bool>()
|
||||
, context));
|
||||
|
||||
if (isInputOwned)
|
||||
{
|
||||
// any storage begin
|
||||
{
|
||||
rapidjson::Value typeValue;
|
||||
result.Combine(StoreTypeId(typeValue, inputScriptDataPtr->ToAny().type(), context));
|
||||
outputValue.AddMember
|
||||
( rapidjson::StringRef(JsonSerialization::TypeIdFieldIdentifier)
|
||||
, AZStd::move(typeValue)
|
||||
, context.GetJsonAllocator());
|
||||
}
|
||||
|
||||
result.Combine(ContinueStoringToJsonObjectField
|
||||
( outputValue
|
||||
, "value"
|
||||
, inputScriptDataPtr->Get()
|
||||
, defaultScriptDataPtr ? defaultScriptDataPtr->Get() : nullptr
|
||||
, inputScriptDataPtr->ToAny().type()
|
||||
, context));
|
||||
// datum storage end
|
||||
}
|
||||
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "BehaviorContextObjectSerializer Store finished saving BehaviorContextObject"
|
||||
: "BehaviorContextObjectSerializer Store failed to save BehaviorContextObject");
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -14,11 +14,11 @@
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class GraphDataSerializer
|
||||
class BehaviorContextObjectSerializer
|
||||
: public BaseJsonSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(GraphDataSerializer, "{2DFF5794-785F-4434-9314-52BB3EF1D00E}", BaseJsonSerializer);
|
||||
AZ_RTTI(BehaviorContextObjectSerializer, "{88469C4C-923F-4508-A45C-33DDBB91074E}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
|
||||
private:
|
||||
@@ -50,10 +50,23 @@ namespace AZ
|
||||
, "scriptCanvasType"
|
||||
, context));
|
||||
|
||||
AZStd::any storage;
|
||||
{ // datum storage begin
|
||||
AZ::Uuid typeId = AZ::Uuid::CreateNull();
|
||||
// datum storage begin
|
||||
auto isNullPointerMember = inputValue.FindMember("isNullPointer");
|
||||
if (isNullPointerMember == inputValue.MemberEnd())
|
||||
{
|
||||
return context.Report
|
||||
( JSR::Tasks::ReadField
|
||||
, JSR::Outcomes::Missing
|
||||
, "DatumSerializer::Load failed to load the 'isNullPointer'' member");
|
||||
}
|
||||
|
||||
if (isNullPointerMember->value.GetBool())
|
||||
{
|
||||
*outputDatum = Datum(scType, Datum::eOriginality::Original);
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ::Uuid typeId = AZ::Uuid::CreateNull();
|
||||
auto typeIdMember = inputValue.FindMember(JsonSerialization::TypeIdFieldIdentifier);
|
||||
if (typeIdMember == inputValue.MemberEnd())
|
||||
{
|
||||
@@ -71,7 +84,7 @@ namespace AZ
|
||||
, "DatumSerializer::Load failed to load the AZ TypeId of the value");
|
||||
}
|
||||
|
||||
storage = context.GetSerializeContext()->CreateAny(typeId);
|
||||
AZStd::any storage = context.GetSerializeContext()->CreateAny(typeId);
|
||||
if (storage.empty() || storage.type() != typeId)
|
||||
{
|
||||
return context.Report(result, "DatumSerializer::Load failed to load a value matched the reported AZ TypeId. "
|
||||
@@ -79,24 +92,25 @@ namespace AZ
|
||||
}
|
||||
|
||||
result.Combine(ContinueLoadingFromJsonObjectField(AZStd::any_cast<void>(&storage), typeId, inputValue, "value", context));
|
||||
*outputDatum = Datum(scType, Datum::eOriginality::Original, AZStd::any_cast<void>(&storage), scType.GetAZType());
|
||||
} // datum storage end
|
||||
|
||||
AZStd::string label;
|
||||
AZ_Assert(azrtti_typeid<decltype(outputDatum->m_datumLabel)>() == azrtti_typeid<decltype(label)>()
|
||||
, "m_datumLabel type changed and won't load properly");
|
||||
|
||||
result.Combine(ContinueLoadingFromJsonObjectField
|
||||
( &label
|
||||
, azrtti_typeid<decltype(outputDatum->m_datumLabel)>()
|
||||
, inputValue
|
||||
, "label"
|
||||
, context));
|
||||
outputDatum->SetLabel(label);
|
||||
|
||||
Datum copy(scType, Datum::eOriginality::Original, AZStd::any_cast<void>(&storage), scType.GetAZType());
|
||||
copy.SetLabel(label);
|
||||
*outputDatum = copy;
|
||||
outputDatum->OnDeserialize();
|
||||
|
||||
if (auto listeners = context.GetMetadata().Find<SerializationListeners>())
|
||||
{
|
||||
listeners->push_back(outputDatum);
|
||||
}
|
||||
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "DatumSerializer Load finished loading Datum"
|
||||
: "DatumSerializer Load failed to load Datum");
|
||||
@@ -126,8 +140,6 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
const_cast<Datum*>(inputScriptDataPtr)->OnSerializeBegin();
|
||||
|
||||
JSR::ResultCode result(JSR::Tasks::WriteValue);
|
||||
outputValue.SetObject();
|
||||
|
||||
@@ -146,25 +158,31 @@ namespace AZ
|
||||
, defaultScriptDataPtr ? &defaultScriptDataPtr->GetType() : nullptr
|
||||
, azrtti_typeid<decltype(inputScriptDataPtr->GetType())>()
|
||||
, context));
|
||||
|
||||
{ // datum storage begin
|
||||
{
|
||||
rapidjson::Value typeValue;
|
||||
result.Combine(StoreTypeId(typeValue, inputScriptDataPtr->GetType().GetAZType(), context));
|
||||
outputValue.AddMember
|
||||
( rapidjson::StringRef(JsonSerialization::TypeIdFieldIdentifier)
|
||||
, AZStd::move(typeValue)
|
||||
, context.GetJsonAllocator());
|
||||
}
|
||||
|
||||
// datum storage begin
|
||||
auto inputObjectSource = inputScriptDataPtr->GetAsDanger();
|
||||
outputValue.AddMember("isNullPointer", rapidjson::Value(inputObjectSource == nullptr), context.GetJsonAllocator());
|
||||
|
||||
if (inputObjectSource)
|
||||
{
|
||||
rapidjson::Value typeValue;
|
||||
result.Combine(StoreTypeId(typeValue, inputScriptDataPtr->GetType().GetAZType(), context));
|
||||
outputValue.AddMember
|
||||
( rapidjson::StringRef(JsonSerialization::TypeIdFieldIdentifier)
|
||||
, AZStd::move(typeValue)
|
||||
, context.GetJsonAllocator());
|
||||
|
||||
auto defaultObjectSource = defaultScriptDataPtr ? defaultScriptDataPtr->GetAsDanger() : nullptr;
|
||||
|
||||
result.Combine(ContinueStoringToJsonObjectField
|
||||
( outputValue
|
||||
, "value"
|
||||
, inputScriptDataPtr->GetAsDanger()
|
||||
, defaultScriptDataPtr ? defaultScriptDataPtr->GetAsDanger() : nullptr
|
||||
, inputObjectSource
|
||||
, defaultObjectSource
|
||||
, inputScriptDataPtr->GetType().GetAZType()
|
||||
, context));
|
||||
} // datum storage end
|
||||
}
|
||||
// datum storage end
|
||||
|
||||
result.Combine(ContinueStoringToJsonObjectField
|
||||
( outputValue
|
||||
@@ -174,7 +192,6 @@ namespace AZ
|
||||
, azrtti_typeid<decltype(inputScriptDataPtr->m_datumLabel)>()
|
||||
, context));
|
||||
|
||||
const_cast<Datum*>(inputScriptDataPtr)->OnSerializeEnd();
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "DatumSerializer Store finished saving Datum"
|
||||
: "DatumSerializer Store failed to save Datum");
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <ScriptCanvas/Core/SerializationListener.h>
|
||||
#include <ScriptCanvas/Core/GraphData.h>
|
||||
#include <ScriptCanvas/Serialization/GraphDataSerializer.h>
|
||||
|
||||
using namespace ScriptCanvas;
|
||||
|
||||
namespace GraphDataSerializerCpp
|
||||
{
|
||||
void CollectNodes(const GraphData::NodeContainer& container, SerializationListeners& listeners)
|
||||
{
|
||||
for (auto& nodeEntity : container)
|
||||
{
|
||||
if (nodeEntity)
|
||||
{
|
||||
if (auto listener = azrtti_cast<SerializationListener*>(AZ::EntityUtils::FindFirstDerivedComponent<Node>(nodeEntity)))
|
||||
{
|
||||
listeners.push_back(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
AZ_CLASS_ALLOCATOR_IMPL(GraphDataSerializer, SystemAllocator, 0);
|
||||
|
||||
JsonSerializationResult::Result GraphDataSerializer::Load
|
||||
( void* outputValue
|
||||
, [[maybe_unused]] const Uuid& outputValueTypeId
|
||||
, const rapidjson::Value& inputValue
|
||||
, JsonDeserializerContext& context)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(outputValueTypeId == azrtti_typeid<GraphData>()
|
||||
, "RuntimeVariableSerializer Load against output typeID that was not GraphData");
|
||||
AZ_Assert(outputValue, "RuntimeVariableSerializer Load against null output");
|
||||
context.GetMetadata().Add(SerializationListeners());
|
||||
JSR::ResultCode result(JSR::Tasks::ReadField);
|
||||
result.Combine(ContinueLoading(outputValue, outputValueTypeId, inputValue, context, ContinuationFlags::NoTypeSerializer));
|
||||
auto listeners = context.GetMetadata().Find<SerializationListeners>();
|
||||
AZ_Assert(listeners, "Failed to create SerializationListeners");
|
||||
GraphDataSerializerCpp::CollectNodes(reinterpret_cast<GraphData*>(outputValue)->m_nodes, *listeners);
|
||||
|
||||
for (auto listener : *listeners)
|
||||
{
|
||||
listener->OnDeserialize();
|
||||
}
|
||||
|
||||
reinterpret_cast<GraphData*>(outputValue)->OnDeserialized();
|
||||
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "GraphDataSerializer Load finished loading GraphData"
|
||||
: "GraphDataSerializer Load failed to load GraphData");
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result GraphDataSerializer::Store
|
||||
( rapidjson::Value& outputValue
|
||||
, const void* inputValue
|
||||
, const void* defaultValue
|
||||
, [[maybe_unused]] const Uuid& valueTypeId
|
||||
, JsonSerializerContext& context)
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(valueTypeId == azrtti_typeid<GraphData>()
|
||||
, "RuntimeVariableSerializer Store against output typeID that was not GraphData");
|
||||
AZ_Assert(inputValue, "RuntimeVariableSerializer Store against null output");
|
||||
context.GetMetadata().Add(SerializationListeners());
|
||||
auto listeners = context.GetMetadata().Find<SerializationListeners>();
|
||||
GraphDataSerializerCpp::CollectNodes(reinterpret_cast<const GraphData*>(inputValue)->m_nodes, *listeners);
|
||||
|
||||
for (auto listener : *listeners)
|
||||
{
|
||||
listener->OnSerializeBegin();
|
||||
}
|
||||
|
||||
JSR::ResultCode result(JSR::Tasks::WriteValue);
|
||||
result.Combine(ContinueStoring(outputValue, inputValue, defaultValue, valueTypeId, context, ContinuationFlags::NoTypeSerializer));
|
||||
|
||||
for (auto listener : *listeners)
|
||||
{
|
||||
listener->OnSerializeEnd();
|
||||
}
|
||||
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "GraphDataSerializer::Store finished storing GraphData"
|
||||
: "GraphDataSerializer::Store failed to store GraphData");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user