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:
+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