Added all the missing serializer support, fixed up serialization notification
Signed-off-by: chcurran <82187351+carlitosan@users.noreply.github.com>monroegm-disable-blank-issue-2
parent
c701522adc
commit
d7d2e84fee
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/Memory/Memory.h>
|
||||
#include <AzCore/Serialization/AZStdAnyDataContainer.inl>
|
||||
#include <AzCore/Serialization/Json/BaseJsonSerializer.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <ExpressionEvaluation/ExpressionEngine/ExpressionTypes.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class ElementInformationSerializer
|
||||
: public BaseJsonSerializer
|
||||
{
|
||||
|
||||
public:
|
||||
AZ_RTTI(ElementInformationSerializer, "{B33E6AA9-C700-4E3D-857C-55F362AFE57A}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
|
||||
private:
|
||||
using ElementInformation = ExpressionEvaluation::ElementInformation;
|
||||
|
||||
JsonSerializationResult::Result Load
|
||||
( void* outputValue
|
||||
, const Uuid& outputValueTypeId
|
||||
, const rapidjson::Value& inputValue
|
||||
, JsonDeserializerContext& context) override
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(outputValueTypeId == azrtti_typeid<ElementInformation>(), "ElementInformationSerializer Load against "
|
||||
"output typeID that was not ElementInformation");
|
||||
AZ_Assert(outputValue, "ElementInformationSerializer Load against null output");
|
||||
|
||||
JsonSerializationResult::ResultCode result(JSR::Tasks::ReadField);
|
||||
auto outputDatum = reinterpret_cast<ElementInformation*>(outputValue);
|
||||
result.Combine(ContinueLoadingFromJsonObjectField
|
||||
( &outputDatum->m_id
|
||||
, azrtti_typeid<decltype(outputDatum->m_id)>()
|
||||
, inputValue
|
||||
, "Id"
|
||||
, context));
|
||||
|
||||
// any storage begin
|
||||
auto isEmptyAny = inputValue.FindMember("isEmptyAny");
|
||||
if (isEmptyAny == inputValue.MemberEnd())
|
||||
{
|
||||
return context.Report
|
||||
(JSR::Tasks::ReadField
|
||||
, JSR::Outcomes::Missing
|
||||
, "ElementInformationSerializer::Load failed to load the 'isEmptyAny'' member");
|
||||
}
|
||||
|
||||
if (!isEmptyAny->value.GetBool())
|
||||
{
|
||||
AZ::Uuid typeId = AZ::Uuid::CreateNull();
|
||||
auto typeIdMember = inputValue.FindMember(JsonSerialization::TypeIdFieldIdentifier);
|
||||
if (typeIdMember == inputValue.MemberEnd())
|
||||
{
|
||||
return context.Report
|
||||
(JSR::Tasks::ReadField
|
||||
, JSR::Outcomes::Missing
|
||||
, AZStd::string::format("ElementInformationSerializer::Load failed to load the %s member"
|
||||
, JsonSerialization::TypeIdFieldIdentifier));
|
||||
}
|
||||
|
||||
result.Combine(LoadTypeId(typeId, typeIdMember->value, context));
|
||||
if (typeId.IsNull())
|
||||
{
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Catastrophic
|
||||
, "ElementInformationSerializer::Load failed to load the AZ TypeId of the value");
|
||||
}
|
||||
|
||||
AZStd::any storage = context.GetSerializeContext()->CreateAny(typeId);
|
||||
if (storage.empty() || storage.type() != typeId)
|
||||
{
|
||||
return context.Report(result, "ElementInformationSerializer::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));
|
||||
outputDatum->m_extraStore = storage;
|
||||
}
|
||||
// any storage end
|
||||
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "ElementInformationSerializer Load finished loading ElementInformation"
|
||||
: "ElementInformationSerializer Load failed to load ElementInformation");
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result Store
|
||||
( rapidjson::Value& outputValue
|
||||
, const void* inputValue
|
||||
, const void* defaultValue
|
||||
, const Uuid& valueTypeId, JsonSerializerContext& context) override
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(valueTypeId == azrtti_typeid<ElementInformation>(), "ElementInformation Store against value typeID that "
|
||||
"was not ElementInformation");
|
||||
AZ_Assert(inputValue, "ElementInformation Store against null inputValue pointer ");
|
||||
|
||||
auto inputScriptDataPtr = reinterpret_cast<const ElementInformation*>(inputValue);
|
||||
auto defaultScriptDataPtr = reinterpret_cast<const ElementInformation*>(defaultValue);
|
||||
|
||||
if (defaultScriptDataPtr)
|
||||
{
|
||||
if (inputScriptDataPtr->m_id == defaultScriptDataPtr->m_id
|
||||
&& AZ::Helpers::CompareAnyValue(inputScriptDataPtr->m_extraStore, defaultScriptDataPtr->m_extraStore))
|
||||
{
|
||||
return context.Report
|
||||
( JSR::Tasks::WriteValue, JSR::Outcomes::DefaultsUsed, "ElementInformation Store used defaults for "
|
||||
"ElementInformation");
|
||||
}
|
||||
}
|
||||
|
||||
JSR::ResultCode result(JSR::Tasks::WriteValue);
|
||||
outputValue.SetObject();
|
||||
|
||||
result.Combine(ContinueStoringToJsonObjectField
|
||||
( outputValue
|
||||
, "Id"
|
||||
, &inputScriptDataPtr->m_id
|
||||
, defaultScriptDataPtr ? &defaultScriptDataPtr->m_id : nullptr
|
||||
, azrtti_typeid<decltype(inputScriptDataPtr->m_id)>()
|
||||
, context));
|
||||
|
||||
|
||||
outputValue.AddMember("isEmptyAny", rapidjson::Value(inputScriptDataPtr->m_extraStore.empty()), context.GetJsonAllocator());
|
||||
|
||||
if (!inputScriptDataPtr->m_extraStore.empty())
|
||||
{
|
||||
rapidjson::Value typeValue;
|
||||
result.Combine(StoreTypeId(typeValue, inputScriptDataPtr->m_extraStore.type(), context));
|
||||
outputValue.AddMember
|
||||
(rapidjson::StringRef(JsonSerialization::TypeIdFieldIdentifier)
|
||||
, AZStd::move(typeValue)
|
||||
, context.GetJsonAllocator());
|
||||
|
||||
result.Combine(ContinueStoringToJsonObjectField
|
||||
( outputValue
|
||||
, "Value"
|
||||
, AZStd::any_cast<void>(const_cast<AZStd::any*>(&inputScriptDataPtr->m_extraStore))
|
||||
, defaultScriptDataPtr ? AZStd::any_cast<void>(const_cast<AZStd::any*>(&defaultScriptDataPtr->m_extraStore)) : nullptr
|
||||
, inputScriptDataPtr->m_extraStore.type()
|
||||
, context));
|
||||
|
||||
}
|
||||
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "ElementInformation Store finished saving ElementInformation"
|
||||
: "ElementInformation Store failed to save ElementInformation");
|
||||
}
|
||||
};
|
||||
|
||||
AZ_CLASS_ALLOCATOR_IMPL(ElementInformationSerializer, SystemAllocator, 0);
|
||||
}
|
||||
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/Memory/Memory.h>
|
||||
#include <AzCore/Serialization/AZStdAnyDataContainer.inl>
|
||||
#include <AzCore/Serialization/Json/BaseJsonSerializer.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <ExpressionEvaluation/ExpressionEngine/ExpressionTree.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class ExpressionTreeVariableDescriptorSerializer
|
||||
: public BaseJsonSerializer
|
||||
{
|
||||
|
||||
public:
|
||||
AZ_RTTI(ExpressionTreeVariableDescriptorSerializer, "{5EFF37D6-BD54-45C6-9FC6-B1E0D3A8204C}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
|
||||
private:
|
||||
using VariableDescriptor = ExpressionEvaluation::ExpressionTree::VariableDescriptor;
|
||||
|
||||
JsonSerializationResult::Result Load
|
||||
( void* outputValue
|
||||
, const Uuid& outputValueTypeId
|
||||
, const rapidjson::Value& inputValue
|
||||
, JsonDeserializerContext& context) override
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(outputValueTypeId == azrtti_typeid<VariableDescriptor>(), "ExpressionTreeVariableDescriptorSerializer Load against "
|
||||
"output typeID that was not VariableDescriptor");
|
||||
AZ_Assert(outputValue, "ExpressionTreeVariableDescriptorSerializer Load against null output");
|
||||
|
||||
JsonSerializationResult::ResultCode result(JSR::Tasks::ReadField);
|
||||
auto outputDatum = reinterpret_cast<VariableDescriptor*>(outputValue);
|
||||
|
||||
result.Combine(ContinueLoadingFromJsonObjectField
|
||||
( &outputDatum->m_supportedTypes
|
||||
, azrtti_typeid<decltype(outputDatum->m_supportedTypes)>()
|
||||
, inputValue
|
||||
, "SupportedTypes"
|
||||
, context));
|
||||
|
||||
// any storage begin
|
||||
AZ::Uuid typeId = AZ::Uuid::CreateNull();
|
||||
auto typeIdMember = inputValue.FindMember(JsonSerialization::TypeIdFieldIdentifier);
|
||||
if (typeIdMember == inputValue.MemberEnd())
|
||||
{
|
||||
return context.Report
|
||||
( JSR::Tasks::ReadField
|
||||
, JSR::Outcomes::Missing
|
||||
, AZStd::string::format("ExpressionTreeVariableDescriptorSerializer::Load failed to load the %s member"
|
||||
, JsonSerialization::TypeIdFieldIdentifier));
|
||||
}
|
||||
|
||||
result.Combine(LoadTypeId(typeId, typeIdMember->value, context));
|
||||
if (typeId.IsNull())
|
||||
{
|
||||
return context.Report(JSR::Tasks::ReadField, JSR::Outcomes::Catastrophic
|
||||
, "ExpressionTreeVariableDescriptorSerializer::Load failed to load the AZ TypeId of the value");
|
||||
}
|
||||
|
||||
AZStd::any storage = context.GetSerializeContext()->CreateAny(typeId);
|
||||
if (storage.empty() || storage.type() != typeId)
|
||||
{
|
||||
return context.Report(result, "ExpressionTreeVariableDescriptorSerializer::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));
|
||||
outputDatum->m_value = storage;
|
||||
// any storage end
|
||||
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "ExpressionTreeVariableDescriptorSerializer Load finished loading VariableDescriptor"
|
||||
: "ExpressionTreeVariableDescriptorSerializer Load failed to load VariableDescriptor");
|
||||
}
|
||||
|
||||
JsonSerializationResult::Result Store
|
||||
( rapidjson::Value& outputValue
|
||||
, const void* inputValue
|
||||
, const void* defaultValue
|
||||
, const Uuid& valueTypeId, JsonSerializerContext& context) override
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(valueTypeId == azrtti_typeid<VariableDescriptor>(), "VariableDescriptor Store against value typeID that "
|
||||
"was not VariableDescriptor");
|
||||
AZ_Assert(inputValue, "VariableDescriptor Store against null inputValue pointer ");
|
||||
|
||||
auto inputScriptDataPtr = reinterpret_cast<const VariableDescriptor*>(inputValue);
|
||||
auto defaultScriptDataPtr = reinterpret_cast<const VariableDescriptor*>(defaultValue);
|
||||
|
||||
if (defaultScriptDataPtr)
|
||||
{
|
||||
if (inputScriptDataPtr->m_supportedTypes == defaultScriptDataPtr->m_supportedTypes
|
||||
&& AZ::Helpers::CompareAnyValue(inputScriptDataPtr->m_value, defaultScriptDataPtr->m_value))
|
||||
{
|
||||
return context.Report
|
||||
( JSR::Tasks::WriteValue, JSR::Outcomes::DefaultsUsed, "VariableDescriptor Store used defaults for "
|
||||
"VariableDescriptor");
|
||||
}
|
||||
}
|
||||
|
||||
JSR::ResultCode result(JSR::Tasks::WriteValue);
|
||||
outputValue.SetObject();
|
||||
|
||||
result.Combine(ContinueStoringToJsonObjectField
|
||||
( outputValue
|
||||
, "SupportedTypes"
|
||||
, &inputScriptDataPtr->m_supportedTypes
|
||||
, defaultScriptDataPtr ? &defaultScriptDataPtr->m_supportedTypes : nullptr
|
||||
, azrtti_typeid<decltype(inputScriptDataPtr->m_supportedTypes)>()
|
||||
, context));
|
||||
|
||||
rapidjson::Value typeValue;
|
||||
result.Combine(StoreTypeId(typeValue, inputScriptDataPtr->m_value.type(), context));
|
||||
outputValue.AddMember
|
||||
( rapidjson::StringRef(JsonSerialization::TypeIdFieldIdentifier)
|
||||
, AZStd::move(typeValue)
|
||||
, context.GetJsonAllocator());
|
||||
|
||||
result.Combine(ContinueStoringToJsonObjectField
|
||||
( outputValue
|
||||
, "Value"
|
||||
, AZStd::any_cast<void>(const_cast<AZStd::any*>(&inputScriptDataPtr->m_value))
|
||||
, defaultScriptDataPtr ? AZStd::any_cast<void>(const_cast<AZStd::any*>(&defaultScriptDataPtr->m_value)) : nullptr
|
||||
, inputScriptDataPtr->m_value.type()
|
||||
, context));
|
||||
|
||||
return context.Report(result, result.GetProcessing() != JSR::Processing::Halted
|
||||
? "VariableDescriptor Store finished saving VariableDescriptor"
|
||||
: "VariableDescriptor Store failed to save VariableDescriptor");
|
||||
}
|
||||
};
|
||||
|
||||
AZ_CLASS_ALLOCATOR_IMPL(ExpressionTreeVariableDescriptorSerializer, SystemAllocator, 0);
|
||||
}
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue