[LYN-3412] Updated LandscapeCanvas component to properly serialize with prefabs. (#1224)
* [LYN-3412] Updated LandscapeCanvas component to properly serialize with prefabs. * [LYN-3412] Updated PR with feedback. * [LYN-3412] Reverted unintentional changes. * [LYN-3412] Removed one more comment. * [LYN-3412] Additional PR feedback fixed.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
// AZ
|
||||
#include <AzCore/RTTI/RTTI.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/std/containers/map.h>
|
||||
|
||||
// Graph Model
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
// AZ
|
||||
#include <AzCore/std/containers/unordered_map.h>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <AzCore/std/any.h>
|
||||
#include <AzCore/std/smart_ptr/enable_shared_from_this.h>
|
||||
|
||||
// Graph Model
|
||||
#include <GraphModel/Integration/GraphCanvasMetadata.h>
|
||||
#include <GraphModel/Model/Common.h>
|
||||
#include <GraphModel/Model/GraphElement.h>
|
||||
|
||||
@@ -136,9 +136,9 @@ namespace GraphModel
|
||||
//! Set/gets a bundle of generic metadata that is provided by the node graph UI
|
||||
//! system. This may include node positions, comment blocks, node groupings, and
|
||||
//! bookmarks, for example.
|
||||
void SetUiMetadata(const AZStd::any& uiMetadata);
|
||||
const AZStd::any& GetUiMetadata() const;
|
||||
AZStd::any& GetUiMetadata();
|
||||
void SetUiMetadata(const GraphModelIntegration::GraphCanvasMetadata& uiMetadata);
|
||||
const GraphModelIntegration::GraphCanvasMetadata& GetUiMetadata() const;
|
||||
GraphModelIntegration::GraphCanvasMetadata& GetUiMetadata();
|
||||
|
||||
AZStd::shared_ptr<Slot> FindSlot(const Endpoint& endpoint);
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace GraphModel
|
||||
ConnectionList m_connections;
|
||||
|
||||
//! Used to store and serialize metadata from the graph UI, like node positions, comments, group boxes, etc.
|
||||
AZStd::any m_uiMetadata;
|
||||
GraphModelIntegration::GraphCanvasMetadata m_uiMetadata;
|
||||
|
||||
//! Used to store all of our node <-> wrapper node mappings
|
||||
NodeWrappingMap m_nodeWrappings;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#pragma once
|
||||
|
||||
// AZ
|
||||
#include <AzCore/Serialization/Json/BaseJsonSerializer.h>
|
||||
#include <AzCore/std/any.h>
|
||||
#include <AzCore/std/hash.h>
|
||||
#include <AzCore/std/containers/list.h>
|
||||
@@ -165,6 +166,32 @@ namespace GraphModel
|
||||
ExtendableSlotConfiguration m_extendableSlotConfiguration;
|
||||
};
|
||||
|
||||
//! Custom JSON serializer for Slot because we use an AZStd::any for m_value
|
||||
class JsonSlotSerializer
|
||||
: public AZ::BaseJsonSerializer
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(JsonSlotSerializer, "{8AC96D70-7BCD-4D68-8813-269938982D51}", AZ::BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR(JsonSlotSerializer, AZ::SystemAllocator, 0);
|
||||
|
||||
AZ::JsonSerializationResult::Result Load(
|
||||
void* outputValue, const AZ::Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
AZ::JsonDeserializerContext& context) override;
|
||||
|
||||
AZ::JsonSerializationResult::Result Store(
|
||||
rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue, const AZ::Uuid& valueTypeId,
|
||||
AZ::JsonSerializerContext& context) override;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
bool LoadAny(
|
||||
AZStd::any& propertyValue, const rapidjson::Value& inputPropertyValue, AZ::JsonDeserializerContext& context,
|
||||
AZ::JsonSerializationResult::ResultCode& result);
|
||||
template<typename T>
|
||||
bool StoreAny(
|
||||
const AZStd::any& propertyValue, rapidjson::Value& outputPropertyValue, AZ::JsonSerializerContext& context,
|
||||
AZ::JsonSerializationResult::ResultCode& result);
|
||||
};
|
||||
|
||||
//!!! Start in Graph.h for high level GraphModel documentation !!!
|
||||
|
||||
@@ -180,6 +207,7 @@ namespace GraphModel
|
||||
class Slot : public GraphElement, public AZStd::enable_shared_from_this<Slot>
|
||||
{
|
||||
friend class Graph; // So the Graph can update the Slot's cache of Connection pointers
|
||||
friend class JsonSlotSerializer; // So we can set the m_value and m_subId directly from the serializer
|
||||
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR(Slot, AZ::SystemAllocator, 0);
|
||||
|
||||
Reference in New Issue
Block a user