Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,61 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Serialization/EditContext.h>
#include <Editor/Nodes/EditorLibrary.h>
#include <Editor/Nodes/ScriptCanvasAssetNode.h>
namespace ScriptCanvasEditor
{
namespace Library
{
void Editor::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
serializeContext->Class<Editor, LibraryDefinition>()
->Version(1)
;
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<Editor>("Editor", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/All.png")
;
}
}
}
void Editor::InitNodeRegistry(ScriptCanvas::NodeRegistry& nodeRegistry)
{
ScriptCanvas::Library::AddNodeToRegistry<Editor, ScriptCanvasAssetNode>(nodeRegistry);
}
AZStd::vector<AZ::ComponentDescriptor*> Editor::GetComponentDescriptors()
{
return AZStd::vector<AZ::ComponentDescriptor*>({
ScriptCanvasAssetNode::CreateDescriptor(),
});
}
}
AZStd::vector<AZ::ComponentDescriptor*> GetLibraryDescriptors()
{
return Library::Editor::GetComponentDescriptors();
}
} // namespace ScriptCanvasEditor
@@ -0,0 +1,37 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <ScriptCanvas/Libraries/Libraries.h>
namespace AZ
{
class ReflectContext;
class ComponentDescriptor;
} // namespace AZ
namespace ScriptCanvasEditor
{
namespace Library
{
struct Editor : public ScriptCanvas::Library::LibraryDefinition
{
AZ_RTTI(Editor, "{59697735-4B64-4DC5-8380-02B2999FFCFE}", ScriptCanvas::Library::LibraryDefinition);
static void Reflect(AZ::ReflectContext*);
static void InitNodeRegistry(ScriptCanvas::NodeRegistry& nodeRegistry);
static AZStd::vector<AZ::ComponentDescriptor*> GetComponentDescriptors();
};
} // namespace Library
AZStd::vector<AZ::ComponentDescriptor*> GetLibraryDescriptors();
} // namespace ScriptCanvasEditor
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,167 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/Component/EntityId.h>
#include <GraphCanvas/Components/Slots/SlotBus.h>
#include <ScriptCanvas/Core/Node.h>
#include <ScriptCanvas/Bus/NodeIdPair.h>
#include <ScriptCanvas/Variable/VariableCore.h>
#include <ScriptCanvas/GraphCanvas/NodeDescriptorBus.h>
#include <ScriptCanvas/Libraries/Core/FunctionNode.h>
#include <ScriptEvents/ScriptEventsAsset.h>
#include <Editor/Translation/TranslationHelper.h>
namespace ScriptCanvas
{
class Slot;
}
namespace ScriptCanvasEditor
{
namespace Nodes
{
namespace Internal
{
template<class... ComponentTypes>
struct PopulateHelper;
template<class ComponentType, class... ComponentTypes>
struct PopulateHelper<ComponentType, ComponentTypes...>
{
public:
static void PopulateComponentDescriptors(AZStd::vector< AZ::Uuid >& componentDescriptors)
{
componentDescriptors.emplace_back(azrtti_typeid<ComponentType>());
PopulateHelper<ComponentTypes...>::PopulateComponentDescriptors(componentDescriptors);
}
};
template<>
struct PopulateHelper<>
{
public:
static void PopulateComponentDescriptors([[maybe_unused]] AZStd::vector< AZ::Uuid >& componentDescriptors)
{
}
};
}
enum class NodeType
{
WrapperNode,
GeneralNode
};
struct NodeConfiguration
{
NodeConfiguration()
: m_nodeType(NodeType::GeneralNode)
{
}
template<class... ComponentTypes>
void PopulateComponentDescriptors()
{
m_customComponents.reserve(sizeof...(ComponentTypes));
Internal::PopulateHelper<ComponentTypes...>::PopulateComponentDescriptors(m_customComponents);
}
NodeType m_nodeType;
AZStd::string m_nodeSubStyle;
AZStd::string m_titlePalette;
AZStd::vector< AZ::Uuid > m_customComponents;
// Translation Information for the Node
AZStd::string m_translationContext;
AZStd::string m_translationKeyName;
AZStd::string m_translationKeyContext;
TranslationContextGroup m_translationGroup;
AZStd::string m_titleFallback;
AZStd::string m_subtitleFallback;
AZStd::string m_tooltipFallback;
AZ::EntityId m_scriptCanvasId;
};
struct StyleConfiguration
{
AZStd::string m_nodeSubStyle;
AZStd::string m_titlePalette;
};
AZStd::string GetContextName(const AZ::SerializeContext::ClassData& classData);
AZStd::string GetCategoryName(const AZ::SerializeContext::ClassData& classData);
AZ::EntityId DisplayEbusEventNode(const AZ::EntityId& graphCanvasGraphId, const AZStd::string& busName, const AZStd::string& eventName, const ScriptCanvas::EBusEventId& eventId);
// Generic method of displaying a node.
AZ::EntityId DisplayScriptCanvasNode(const AZ::EntityId& graphCanvasGraphId, const ScriptCanvas::Node* node);
// Specific create methods which will also handle displaying the node.
NodeIdPair CreateNode(const AZ::Uuid& classData, const ScriptCanvas::ScriptCanvasId& scriptCanvasId, const StyleConfiguration& styleConfiguration);
NodeIdPair CreateEntityNode(const AZ::EntityId& sourceId, const ScriptCanvas::ScriptCanvasId& scriptCanvasId);
NodeIdPair CreateObjectMethodNode(const AZStd::string& className, const AZStd::string& methodName, const ScriptCanvas::ScriptCanvasId& scriptCanvasId);
NodeIdPair CreateEbusWrapperNode(const AZStd::string& busName, const ScriptCanvas::ScriptCanvasId& scriptCanvasId);
// Script Events
AZ::EntityId DisplayScriptEventNode(const AZ::EntityId& graphCanvasGraphId, const AZ::Data::AssetId assetId, const ScriptEvents::Method& methodDefinition);
NodeIdPair CreateScriptEventReceiverNode(const ScriptCanvas::ScriptCanvasId& scriptCanvasId, const AZ::Data::AssetId& assetId);
NodeIdPair CreateScriptEventSenderNode(const ScriptCanvas::ScriptCanvasId& scriptCanvasId, const AZ::Data::AssetId& assetId, const ScriptCanvas::EBusEventId& eventId);
NodeIdPair CreateGetVariableNode(const ScriptCanvas::VariableId& variableId, const AZ::EntityId& scriptCanvasGraphId);
NodeIdPair CreateSetVariableNode(const ScriptCanvas::VariableId& variableId, const AZ::EntityId& scriptCanvasGraphId);
NodeIdPair CreateFunctionNode(const ScriptCanvas::ScriptCanvasId& scriptCanvasGraphId, const AZ::Data::AssetId& assetId);
AZ::EntityId DisplayFunctionNode(const AZ::EntityId& graphCanvasGraphId, const ScriptCanvas::Nodes::Core::FunctionNode* functionNode);
AZ::EntityId DisplayFunctionNode(const AZ::EntityId& graphCanvasGraphId, ScriptCanvas::Nodes::Core::FunctionNode* functionNode);
AZ::EntityId DisplayNodeling(const AZ::EntityId& graphCanvasGraphId, const ScriptCanvas::Nodes::Core::Internal::Nodeling* nodeling);
NodeIdPair CreateExecutionNodeling(const ScriptCanvas::ScriptCanvasId& scriptCanvasId, AZStd::string rootName = "New Nodeling");
// SlotGroup will control how elements are grouped.
// Invalid will cause the slots to put themselves into whatever category they belong to by default.
AZ::EntityId DisplayScriptCanvasSlot(const AZ::EntityId& graphCanvasNodeId, const ScriptCanvas::Slot& slot, GraphCanvas::SlotGroup group = GraphCanvas::SlotGroups::Invalid);
AZ::EntityId DisplayVisualExtensionSlot(const AZ::EntityId& graphCanvasNodeId, const ScriptCanvas::VisualExtensionSlotConfiguration& extenderConfiguration);
void CopySlotTranslationKeyedNamesToDatums(AZ::EntityId graphCanvasNodeId);
template <typename NodeType>
NodeType* GetNode(AZ::EntityId scriptCanvasGraphId, NodeIdPair nodeIdPair)
{
ScriptCanvas::Node* node = nullptr;
AZ::Entity* sourceEntity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(sourceEntity, &AZ::ComponentApplicationRequests::FindEntity, nodeIdPair.m_scriptCanvasId);
if (sourceEntity)
{
node = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Node>(sourceEntity);
if (node == nullptr)
{
ScriptCanvas::SystemRequestBus::BroadcastResult(node, &ScriptCanvas::SystemRequests::CreateNodeOnEntity, sourceEntity->GetId(), scriptCanvasGraphId, azrtti_typeid<NodeType>());
}
}
return azrtti_cast<NodeType*>(node);
}
}
}
@@ -0,0 +1,210 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <Editor/Nodes/ScriptCanvasAssetNode.h>
#include <ScriptCanvas/Core/Graph.h>
#include <Editor/Assets/ScriptCanvasAssetTrackerBus.h>
namespace ScriptCanvasEditor
{
/**
* \note when we reflecting we can check if the class is inheriting from IEventHandler
* and use the this->events.
*/
class ScriptCanvasAssetNodeEventHandler
: public AZ::SerializeContext::IEventHandler
{
void OnReadBegin(void* classPtr)
{
auto* scriptCanvasAssetNode = reinterpret_cast<ScriptCanvasAssetNode*>(classPtr);
scriptCanvasAssetNode->ComputeDataPatch();
}
};
void ScriptCanvasAssetNode::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (!serializeContext)
{
return;
}
serializeContext->Class<ScriptCanvasAssetNode, ScriptCanvas::Node>()
->Version(0)
->EventHandler<ScriptCanvasAssetNodeEventHandler>()
->Field("m_assetInstance", &ScriptCanvasAssetNode::m_scriptCanvasAssetInstance)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<ScriptCanvasAssetNode>("ScriptCanvas Asset", "Script Canvas Asset Node which contains a reference to another ScriptCanvas graph")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/ScriptCanvas/Placeholder.png")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::List)
;
}
}
ScriptCanvasAssetNode::ScriptCanvasAssetNode(const AZ::Data::Asset<ScriptCanvasAsset>& scriptCanvasAsset, bool storeAssetDataInternally)
{
SetAssetDataStoredInternally(storeAssetDataInternally);
SetAsset(scriptCanvasAsset);
}
ScriptCanvasAssetNode::~ScriptCanvasAssetNode()
{
}
void ScriptCanvasAssetNode::OnInputSignal(const ScriptCanvas::SlotId&)
{
}
void ScriptCanvasAssetNode::OnInit()
{
if (GetAsset().GetId().IsValid())
{
AZ::Data::AssetBus::Handler::BusConnect(GetAsset().GetId());
AZ::Entity* scriptCanvasEntity = GetScriptCanvasEntity();
if (scriptCanvasEntity)
{
if (scriptCanvasEntity->GetState() == AZ::Entity::State::Constructed)
{
scriptCanvasEntity->Init();
}
if (scriptCanvasEntity->GetState() == AZ::Entity::State::Init)
{
scriptCanvasEntity->Activate();
}
}
}
}
bool ScriptCanvasAssetNode::GetAssetDataStoredInternally() const
{
return m_scriptCanvasAssetInstance.GetReference().GetAssetDataStoredInternally();
}
void ScriptCanvasAssetNode::SetAssetDataStoredInternally(bool storeInObjectStream)
{
m_scriptCanvasAssetInstance.GetReference().SetAssetDataStoredInternally(storeInObjectStream);
}
ScriptCanvas::ScriptCanvasData& ScriptCanvasAssetNode::GetScriptCanvasData()
{
return m_scriptCanvasAssetInstance.GetScriptCanvasData();
}
const ScriptCanvas::ScriptCanvasData& ScriptCanvasAssetNode::GetScriptCanvasData() const
{
return m_scriptCanvasAssetInstance.GetScriptCanvasData();
}
AZ::Entity* ScriptCanvasAssetNode::GetScriptCanvasEntity() const
{
return GetScriptCanvasData().GetScriptCanvasEntity();
}
AZ::Data::Asset<ScriptCanvasAsset>& ScriptCanvasAssetNode::GetAsset()
{
return m_scriptCanvasAssetInstance.GetReference().GetAsset();
}
const AZ::Data::Asset<ScriptCanvasAsset>& ScriptCanvasAssetNode::GetAsset() const
{
return m_scriptCanvasAssetInstance.GetReference().GetAsset();
}
void ScriptCanvasAssetNode::SetAsset(const AZ::Data::Asset<ScriptCanvasAsset>& scriptCanvasAsset)
{
m_scriptCanvasAssetInstance.GetReference().SetAsset(scriptCanvasAsset);
if (scriptCanvasAsset.GetId().IsValid())
{
auto onAssetReady = [](ScriptCanvasMemoryAsset&) {};
AssetTrackerRequestBus::Broadcast(&AssetTrackerRequests::Load, scriptCanvasAsset.GetId(), azrtti_typeid<ScriptCanvasAsset>(), onAssetReady);
AZ::Data::AssetBus::Handler::BusConnect(scriptCanvasAsset.GetId());
ApplyDataPatch();
}
}
void ScriptCanvasAssetNode::OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset)
{
SetAsset(asset);
if (!GetAsset().IsReady())
{
AZ_Error("Script Canvas", false, "Reloaded graph with id %s is not valid", asset.GetId().ToString<AZStd::string>().data());
return;
}
// Update data patches against the old version of the asset.
ApplyDataPatch();
}
void ScriptCanvasAssetNode::OnAssetUnloaded(const AZ::Data::AssetId assetId, const AZ::Data::AssetType)
{
AZ::Data::AssetBus::Handler::BusDisconnect(assetId);
}
void ScriptCanvasAssetNode::ComputeDataPatch()
{
m_scriptCanvasAssetInstance.ComputeDataPatch();
}
void ScriptCanvasAssetNode::ApplyDataPatch()
{
m_scriptCanvasAssetInstance.ApplyDataPatch();
}
bool ScriptCanvasAssetNode::Visit(const VisitCB& preVisitCB, const VisitCB & postVisitCB)
{
AZStd::unordered_set<AZ::Data::AssetId> visitedGraphs;
return Visit(preVisitCB, postVisitCB, visitedGraphs);
}
bool ScriptCanvasAssetNode::Visit(const VisitCB& preVisitCB, const VisitCB & postVisitCB, AZStd::unordered_set<AZ::Data::AssetId>& visitedGraphs)
{
const AZ::Data::AssetId& visitedAssetId = GetAsset().GetId();
if (visitedGraphs.count(visitedAssetId) > 0)
{
AZ_Error("Script Canvas", false, "The Script Canvas Asset %s has already been visited, processing will stop", visitedAssetId.ToString<AZStd::string>().data());
return false;
}
if (!preVisitCB || preVisitCB(*this))
{
auto graph = GetScriptCanvasEntity() ? AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Graph>(GetScriptCanvasEntity()) : nullptr;
if (graph)
{
for (AZ::Entity* nodeEntity : graph->GetNodeEntities())
{
if (auto childAssetNode = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvasAssetNode>(nodeEntity))
{
// Visit ScriptCanvasAssetNodes that are in the asset referenced by @assetNode
if (!childAssetNode->Visit(preVisitCB, postVisitCB, visitedGraphs))
{
break;
}
}
}
}
}
// Visit siblings ScriptCanvasAssetNodes
bool visitSiblings = !postVisitCB || postVisitCB(*this);
visitedGraphs.insert(visitedAssetId);
return visitSiblings;
}
}
@@ -0,0 +1,97 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/Component/Component.h>
#include <ScriptCanvas/Core/Node.h>
#include <ScriptCanvas/Bus/GraphBus.h>
#include <ScriptCanvas/Assets/ScriptCanvasAsset.h>
#include <Editor/Assets/ScriptCanvasAssetInstance.h>
namespace ScriptCanvasEditor
{
//! A group of entities in a scene
class ScriptCanvasAssetNode
: public ScriptCanvas::Node
, protected AZ::Data::AssetBus::Handler
{
public:
AZ_COMPONENT(ScriptCanvasAssetNode, "{65A34956-B6ED-4EB2-966C-5BC844F7B05E}", ScriptCanvas::Node);
static void Reflect(AZ::ReflectContext* context);
ScriptCanvasAssetNode() = default;
ScriptCanvasAssetNode(const AZ::Data::Asset<ScriptCanvasAsset>& scriptCanvasAsset, bool storeAssetDataInternally);
~ScriptCanvasAssetNode() override;
// AZ::Component
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("ScriptCanvas_AssetService", 0x17a357ae));
}
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("ScriptCanvas_AssetService", 0x17a357ae));
}
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
{
(void)dependent;
}
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
(void)required;
}
////
void OnInit() override;
// Retrieves the asset associated with this node
AZ::Data::Asset<ScriptCanvasAsset>& GetAsset();
const AZ::Data::Asset<ScriptCanvasAsset>& GetAsset() const;
// Sets the asset associated with this node
void SetAsset(const AZ::Data::Asset<ScriptCanvasAsset>& scriptCanvasAsset);
bool GetAssetDataStoredInternally() const;
void SetAssetDataStoredInternally(bool storeInObjectStream);
ScriptCanvas::ScriptCanvasData& GetScriptCanvasData();
const ScriptCanvas::ScriptCanvasData& GetScriptCanvasData() const;
AZ::Entity* GetScriptCanvasEntity() const;
using VisitCB = AZStd::function<bool(ScriptCanvasAssetNode& scriptCanvasAssetNode)>;
bool Visit(const VisitCB& preVisitCB, const VisitCB & postVisitCB);
bool Visit(const VisitCB& preVisitCB, const VisitCB & postVisitCB, AZStd::unordered_set<AZ::Data::AssetId>& visitedGraphs);
////
protected:
void OnInputSignal(const ScriptCanvas::SlotId&) override;
// AssetBus::Handler
void OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset) override;
void OnAssetUnloaded(const AZ::Data::AssetId assetId, const AZ::Data::AssetType) override;
////
friend class ScriptCanvasAssetNodeEventHandler;
void ComputeDataPatch();
void ApplyDataPatch();
private:
ScriptCanvasAssetNode(const ScriptCanvasAssetNode&) = delete;
//! References to the Script Canvas asset used by this component
ScriptCanvasAssetInstance m_scriptCanvasAssetInstance;
};
}