ScriptCanvasBuilder.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/Asset/AssetCommon.h>
  10. #include <ScriptCanvas/Asset/RuntimeAsset.h>
  11. #include <ScriptCanvas/Core/Core.h>
  12. #include <ScriptCanvas/Grammar/PrimitivesDeclarations.h>
  13. #include <ScriptCanvas/Variable/VariableCore.h>
  14. namespace ScriptCanvas
  15. {
  16. class SourceTree;
  17. }
  18. namespace ScriptCanvasBuilder
  19. {
  20. using SourceHandle = ScriptCanvas::SourceHandle;
  21. class BuildVariableOverrides
  22. {
  23. public:
  24. AZ_TYPE_INFO(BuildVariableOverrides, "{8336D44C-8EDC-4C28-AEB4-3420D5FD5AE2}");
  25. AZ_CLASS_ALLOCATOR(BuildVariableOverrides, AZ::SystemAllocator);
  26. static void Reflect(AZ::ReflectContext* reflectContext);
  27. void Clear();
  28. // use this to preserve old values that may have been overridden on the instance, and are still valid in the parsed graph
  29. void CopyPreviousOverriddenValues(const BuildVariableOverrides& source);
  30. bool IsEmpty() const;
  31. // use this to initialize the new data, and make sure they have a editor graph variable for proper editor display
  32. void PopulateFromParsedResults(ScriptCanvas::Grammar::AbstractCodeModelConstPtr abstractCodeModel, const ScriptCanvas::VariableData& variables);
  33. void SetHandlesToDescription();
  34. // #functions2 provide an identifier for the node/variable in the source that caused the dependency. the root will not have one.
  35. SourceHandle m_source;
  36. // all of the variables here are overrides
  37. AZStd::vector<ScriptCanvas::GraphVariable> m_variables;
  38. // the values here may or may not be overrides
  39. AZStd::vector<AZStd::pair<ScriptCanvas::VariableId, AZ::EntityId>> m_entityIds;
  40. // these two variable lists are all that gets exposed to the edit context
  41. AZStd::vector<ScriptCanvas::GraphVariable> m_overrides;
  42. AZStd::vector<ScriptCanvas::GraphVariable> m_overridesUnused;
  43. AZStd::vector<BuildVariableOverrides> m_dependencies;
  44. // #scriptcanvas_component_extension
  45. bool m_isComponentScript = false;
  46. };
  47. // copy the variables overridden during editor / prefab build time back to runtime data
  48. ScriptCanvas::RuntimeDataOverrides ConvertToRuntime(const BuildVariableOverrides& overrides);
  49. /// Replace the provided overrides asset hierarchy with the provided loaded one.
  50. /// Returns false if there is a size mismatch in dependencies or if any of the asset has not yet loaded
  51. bool ReplaceAsset(ScriptCanvas::RuntimeDataOverrides& overrides, ScriptCanvas::RuntimeAssetPtr asset);
  52. AZ::Outcome<BuildVariableOverrides, AZStd::string> ParseEditorAssetTree(const ScriptCanvas::SourceTree& editorAssetTree);
  53. }
  54. namespace AZStd
  55. {
  56. AZStd::string to_string(const ScriptCanvasBuilder::BuildVariableOverrides& overrides);
  57. }