NodeUtils.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/EntityId.h>
  10. #include <Editor/Translation/TranslationHelper.h>
  11. #include <ScriptCanvas/Bus/NodeIdPair.h>
  12. #include <ScriptCanvas/Core/ScriptCanvasBus.h>
  13. namespace ScriptCanvasEditor
  14. {
  15. namespace Nodes
  16. {
  17. namespace Internal
  18. {
  19. template<class... ComponentTypes>
  20. struct PopulateHelper;
  21. template<class ComponentType, class... ComponentTypes>
  22. struct PopulateHelper<ComponentType, ComponentTypes...>
  23. {
  24. public:
  25. static void PopulateComponentDescriptors(AZStd::vector< AZ::Uuid >& componentDescriptors)
  26. {
  27. componentDescriptors.emplace_back(azrtti_typeid<ComponentType>());
  28. PopulateHelper<ComponentTypes...>::PopulateComponentDescriptors(componentDescriptors);
  29. }
  30. };
  31. template<>
  32. struct PopulateHelper<>
  33. {
  34. public:
  35. static void PopulateComponentDescriptors([[maybe_unused]] AZStd::vector< AZ::Uuid >& componentDescriptors)
  36. {
  37. }
  38. };
  39. }
  40. enum class NodeType
  41. {
  42. WrapperNode,
  43. GeneralNode
  44. };
  45. struct NodeReplacementConfiguration
  46. {
  47. NodeReplacementConfiguration()
  48. : m_nodeType(NodeType::GeneralNode)
  49. {
  50. }
  51. template<class... ComponentTypes>
  52. void PopulateComponentDescriptors()
  53. {
  54. m_customComponents.reserve(sizeof...(ComponentTypes));
  55. Internal::PopulateHelper<ComponentTypes...>::PopulateComponentDescriptors(m_customComponents);
  56. }
  57. NodeType m_nodeType;
  58. AZStd::string m_nodeSubStyle;
  59. AZStd::string m_titlePalette;
  60. AZStd::vector< AZ::Uuid > m_customComponents;
  61. AZ::EntityId m_scriptCanvasId;
  62. };
  63. struct StyleConfiguration
  64. {
  65. AZStd::string m_nodeSubStyle;
  66. AZStd::string m_titlePalette;
  67. };
  68. // Copies the slot name to the underlying ScriptCanvas Data Slot which matches the slot Id
  69. void UpdateSlotDatumLabels(AZ::EntityId graphCanvasNodeId);
  70. void UpdateSlotDatumLabel(const AZ::EntityId& graphCanvasNodeId, ScriptCanvas::SlotId scSlotId, const AZStd::string& name);
  71. template <typename NodeType>
  72. NodeType* GetNode(AZ::EntityId scriptCanvasGraphId, NodeIdPair nodeIdPair)
  73. {
  74. ScriptCanvas::Node* node = nullptr;
  75. AZ::Entity* sourceEntity = nullptr;
  76. AZ::ComponentApplicationBus::BroadcastResult(sourceEntity, &AZ::ComponentApplicationRequests::FindEntity, nodeIdPair.m_scriptCanvasId);
  77. if (sourceEntity)
  78. {
  79. node = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Node>(sourceEntity);
  80. if (node == nullptr)
  81. {
  82. ScriptCanvas::SystemRequestBus::BroadcastResult(node, &ScriptCanvas::SystemRequests::CreateNodeOnEntity, sourceEntity->GetId(), scriptCanvasGraphId, azrtti_typeid<NodeType>());
  83. }
  84. }
  85. return azrtti_cast<NodeType*>(node);
  86. }
  87. }
  88. }