Configuration.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <AzFramework/Asset/AssetCatalogBus.h>
  10. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  11. #include <Builder/ScriptCanvasBuilder.h>
  12. #include <Builder/ScriptCanvasBuilderDataSystemBus.h>
  13. #include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
  14. #include <ScriptCanvas/Components/EditorScriptCanvasComponentSerializer.h>
  15. #include <ScriptCanvas/Components/EditorDeprecationData.h>
  16. namespace ScriptCanvas
  17. {
  18. class SourceHandle;
  19. }
  20. namespace ScriptCanvasEditor
  21. {
  22. using SourceHandle = ScriptCanvas::SourceHandle;
  23. /// <summary>
  24. /// Configuration provides user-facing facilities for selecting a ScriptCanvas source file, monitoring its status, and exposing its
  25. /// properties for configuration if possible.
  26. /// </summary>
  27. class Configuration final
  28. : public AzFramework::AssetCatalogEventBus::Handler
  29. , public ScriptCanvasBuilder::DataSystemSourceNotificationsBus::Handler
  30. {
  31. friend class AZ::EditorScriptCanvasComponentSerializer;
  32. friend class Deprecated::EditorScriptCanvasComponentVersionConverter;
  33. public:
  34. AZ_TYPE_INFO(Configuration, "{0F4D78A9-EF29-4D6A-AC5B-8F4E19B1A6EE}");
  35. static void Reflect(AZ::ReflectContext* context);
  36. Configuration();
  37. explicit Configuration(const SourceHandle& sourceHandle);
  38. ~Configuration();
  39. const ScriptCanvasBuilder::BuildVariableOverrides* CompileLatest();
  40. /// Will signal when the properties have been modified by the user, or when the source file has been changed.
  41. AZ::EventHandler<const Configuration&> ConnectToPropertiesChanged(AZStd::function<void(const Configuration&)>&& function) const;
  42. /// Will signal when the selected source file has been successfully compiled.
  43. AZ::EventHandler<const Configuration&> ConnectToSourceCompiled(AZStd::function<void(const Configuration&)>&& function) const;
  44. /// Will signal when the selected source file has failed to compile for any reason.
  45. AZ::EventHandler<const Configuration&> ConnectToSourceFailed(AZStd::function<void(const Configuration&)>&& function) const;
  46. /// Returns the user editable properties of the selected source. The properties could be empty.
  47. const ScriptCanvasBuilder::BuildVariableOverrides& GetOverrides() const;
  48. const SourceHandle& GetSource() const;
  49. bool HasSource() const;
  50. /// Provides a manual call to Refresh() with currently selected source file.
  51. void Refresh();
  52. /// Sets the selected file to the input sourceHandle, compiles latest, and sends all signals.
  53. void Refresh(const SourceHandle& sourceHandle);
  54. private:
  55. enum class BuildStatusValidation
  56. {
  57. Good,
  58. Bad,
  59. IncompatibleScript,
  60. };
  61. mutable AZ::Event<const Configuration&> m_eventPropertiesChanged;
  62. mutable AZ::Event<const Configuration&> m_eventSourceCompiled;
  63. mutable AZ::Event<const Configuration&> m_eventSourceFailed;
  64. SourceHandle m_sourceHandle;
  65. AZStd::string m_sourceName;
  66. ScriptCanvasBuilder::BuildVariableOverrides m_propertyOverrides;
  67. void ClearVariables();
  68. BuildStatusValidation CompileLatestInternal();
  69. void MergeWithLatestCompilation(const ScriptCanvasBuilder::BuildVariableOverrides& buildData);
  70. // on RPE source selection changed
  71. AZ::u32 OnEditorChangeSource();
  72. AZ::u32 OnEditorChangeProperties();
  73. void OpenEditor(const AZ::Data::AssetId&, const AZ::Data::AssetType&);
  74. // if result is good, merge results and update display
  75. void SourceFileChanged
  76. ( const ScriptCanvasBuilder::BuilderSourceResult& result
  77. , AZStd::string_view relativePath
  78. , AZStd::string_view scanFolder) override;
  79. // update the display icon for failure, save the values in the graph
  80. void SourceFileFailed(AZStd::string_view relativePath, AZStd::string_view scanFolder) override;
  81. // update the display icon for removal, save the values in the graph
  82. void SourceFileRemoved(AZStd::string_view relativePath, AZStd::string_view scanFolder) override;
  83. BuildStatusValidation ValidateBuildResult(const ScriptCanvasBuilder::BuilderSourceResult& result) const;
  84. // #scriptcanvas_component_extension ...
  85. public:
  86. bool AcceptsComponentScript() const;
  87. /// Some Scripts refer the 'self Entity Id', part of the Entity / Component extension of current ScriptCanvas scripting system.
  88. /// This allows programmers to enable or disable using such a script with this Configuration.
  89. void SetAcceptsComponentScript(bool value);
  90. AZ::EventHandler<const Configuration&> ConnectToIncompatilbleScript(AZStd::function<void(const Configuration&)>&& function) const;
  91. private:
  92. mutable AZ::Event<const Configuration&> m_eventIncompatibleScript;
  93. bool m_acceptsComponentScript = true;
  94. // ... #scriptcanvas_component_extension
  95. };
  96. }