ScriptCanvasTestBus.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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/EBus/EBus.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <AzCore/std/string/string_view.h>
  13. #include <ScriptCanvas/Data/Data.h>
  14. namespace AZ
  15. {
  16. class ReflectContext;
  17. }
  18. namespace ScriptCanvasTesting
  19. {
  20. void Reflect(AZ::ReflectContext* context);
  21. class GlobalBusTraits : public AZ::EBusTraits
  22. {
  23. public:
  24. AZ_TYPE_INFO(GlobalBusTraits, "{DED849D7-CF17-408B-8D87-E31FC7D3CEC4}");
  25. static void Reflect(AZ::ReflectContext* context);
  26. virtual AZStd::string AppendSweet(AZStd::string_view) = 0;
  27. virtual int Increment(int value) = 0;
  28. virtual bool Not(bool value) = 0;
  29. virtual int Sum(int numberA, int numberB) = 0;
  30. virtual void Void(AZStd::string_view) = 0;
  31. virtual AZ::Event<>* GetZeroParamEvent() = 0;
  32. virtual AZ::Event<AZStd::vector<AZStd::string>&>* GetByReferenceEvent() = 0;
  33. virtual AZ::Event<int, bool, AZStd::string>* GetByValueEvent() = 0;
  34. };
  35. using GlobalEBus = AZ::EBus<GlobalBusTraits>;
  36. class PerformanceStressBusTraits : public AZ::EBusTraits
  37. {
  38. public:
  39. AZ_TYPE_INFO(PerformanceStressBusTraits, "{68AF0B81-70F4-4822-8127-AAC442D924C7}");
  40. static void Reflect(AZ::ReflectContext* context);
  41. virtual void ForceStringCompare0() = 0;
  42. virtual void ForceStringCompare1() = 0;
  43. virtual void ForceStringCompare2() = 0;
  44. virtual void ForceStringCompare3() = 0;
  45. virtual void ForceStringCompare4() = 0;
  46. virtual void ForceStringCompare5() = 0;
  47. virtual void ForceStringCompare6() = 0;
  48. virtual void ForceStringCompare7() = 0;
  49. virtual void ForceStringCompare8() = 0;
  50. virtual void ForceStringCompare9() = 0;
  51. };
  52. using PerformanceStressEBus = AZ::EBus<PerformanceStressBusTraits>;
  53. class LocalBusTraits : public AZ::EBusTraits
  54. {
  55. public:
  56. AZ_TYPE_INFO(LocalBusTraits, "{749B6949-CBBB-44D9-A57D-9973DC88E639}");
  57. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  58. using BusIdType = double;
  59. static void Reflect(AZ::ReflectContext* context);
  60. virtual AZStd::string AppendSweet(AZStd::string_view) = 0;
  61. virtual int Increment(int value) = 0;
  62. virtual bool Not(bool value) = 0;
  63. virtual void Void(AZStd::string_view) = 0;
  64. };
  65. using LocalEBus = AZ::EBus<LocalBusTraits>;
  66. class NativeHandlingOnlyBusTraits : public AZ::EBusTraits
  67. {
  68. public:
  69. AZ_TYPE_INFO(NativeHandlingOnlyBusTraits, "{5AED48A7-3E16-41F6-B1C0-4E1FBBA84F83}");
  70. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  71. using BusIdType = AZ::EntityId;
  72. static void Reflect(AZ::ReflectContext* context);
  73. virtual AZStd::string AppendSweet(AZStd::string_view) = 0;
  74. virtual int Increment(int value) = 0;
  75. virtual AZ::EntityId TwistTypeEntityId() = 0;
  76. virtual AZ::Vector3 TwistTypeVector3() = 0;
  77. virtual AZStd::tuple<AZ::EntityId, bool> TwistTupleEntityId() = 0;
  78. virtual AZStd::tuple<AZ::Vector3, bool> TwistTupleVector3() = 0;
  79. virtual bool Not(bool value) = 0;
  80. virtual void Void(AZStd::string_view) = 0;
  81. };
  82. using NativeHandlingOnlyEBus = AZ::EBus<NativeHandlingOnlyBusTraits>;
  83. class TestTupleMethods
  84. {
  85. public:
  86. AZ_TYPE_INFO(TestTupleMethods, "{E794CE93-7AC6-476E-BF10-B107A2E4D807}");
  87. static AZStd::tuple<ScriptCanvas::Data::Vector3Type, ScriptCanvas::Data::StringType, ScriptCanvas::Data::BooleanType> Three(
  88. const ScriptCanvas::Data::Vector3Type& v, const ScriptCanvas::Data::StringType& s, const ScriptCanvas::Data::BooleanType& b)
  89. {
  90. return AZStd::make_tuple(v, s, b);
  91. }
  92. static void Reflect(AZ::ReflectContext* context)
  93. {
  94. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  95. {
  96. behaviorContext->Class<TestTupleMethods>("TestTupleMethods")
  97. ->Attribute(AZ::Script::Attributes::Category, "Tests")
  98. ->Method("Three", &TestTupleMethods::Three);
  99. behaviorContext->Method("ScriptCanvasTesting_TestTupleMethods_GlobalThree", &TestTupleMethods::Three)
  100. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  101. ->Attribute(AZ::Script::Attributes::Category, "Tests");
  102. auto GlobalThreeSameType = [](const ScriptCanvas::Data::StringType& s1, const ScriptCanvas::Data::StringType& s2,
  103. const ScriptCanvas::Data::StringType& s3)
  104. -> AZStd::tuple<ScriptCanvas::Data::StringType, ScriptCanvas::Data::StringType, ScriptCanvas::Data::StringType>
  105. {
  106. return AZStd::make_tuple(s1, s2, s3);
  107. };
  108. behaviorContext->Method("ScriptCanvasTesting_TestTupleMethods_GlobalThreeSameType", GlobalThreeSameType)
  109. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  110. ->Attribute(AZ::Script::Attributes::Category, "Tests");
  111. }
  112. }
  113. };
  114. class TestGlobalMethods
  115. {
  116. public:
  117. static void CanNotAcceptNull(AZStd::vector<AZStd::string>& strings)
  118. {
  119. AZ_TracePrintf("ScriptCanvas", "Used for testing parse errors");
  120. strings.push_back("Cannot accept null input");
  121. }
  122. static void Reflect(AZ::ReflectContext* context)
  123. {
  124. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  125. {
  126. behaviorContext->Method("ScriptCanvasTesting_TestGlobalMethods_CanNotAcceptNull", &CanNotAcceptNull)
  127. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  128. ->Attribute(AZ::Script::Attributes::Category, "Tests")
  129. ;
  130. auto IsPositive = [](int input) -> bool
  131. {
  132. return input > 0;
  133. };
  134. behaviorContext->Method("ScriptCanvasTesting_TestGlobalMethods_IsPositive", IsPositive)
  135. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  136. ->Attribute(AZ::Script::Attributes::Category, "Tests");
  137. auto DivideByPreCheck = [](int input) -> int
  138. {
  139. return 10 / input;
  140. };
  141. AZ::CheckedOperationInfo checkedInfo{ "ScriptCanvasTesting_TestGlobalMethods_IsPositive", {}, "Out", "Invalid Input" };
  142. behaviorContext->Method("ScriptCanvasTesting_TestGlobalMethods_DivideByPreCheck", DivideByPreCheck)
  143. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  144. ->Attribute(AZ::Script::Attributes::Category, "Tests")
  145. ->Attribute(AZ::ScriptCanvasAttributes::CheckedOperation, checkedInfo);
  146. auto SumPostCheck = [](int input1, int input2) -> int
  147. {
  148. return input1 + input2;
  149. };
  150. AZ::BranchOnResultInfo branchResult;
  151. branchResult.m_trueName = "Out";
  152. branchResult.m_falseName = "Not Positive";
  153. branchResult.m_nonBooleanResultCheckName = "ScriptCanvasTesting_TestGlobalMethods_IsPositive";
  154. branchResult.m_returnResultInBranches = true;
  155. behaviorContext->Method("ScriptCanvasTesting_TestGlobalMethods_SumPostCheck", SumPostCheck)
  156. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  157. ->Attribute(AZ::Script::Attributes::Category, "Tests")
  158. ->Attribute(AZ::ScriptCanvasAttributes::BranchOnResult, branchResult);
  159. }
  160. }
  161. };
  162. enum class TestEnum : AZ::u32
  163. {
  164. Alpha = 7,
  165. Bravo = 15,
  166. Charlie = 31,
  167. };
  168. }