ScriptCanvasBuilderDataSystemBus.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 <Builder/ScriptCanvasBuilder.h>
  11. #include <ScriptCanvas/Asset/RuntimeAsset.h>
  12. namespace ScriptCanvasBuilder
  13. {
  14. /**
  15. * Indicator status for DataSystemSourceNotifications and Requests
  16. */
  17. enum class BuilderSourceStatus
  18. {
  19. Failed,
  20. Good,
  21. Removed,
  22. Unloadable,
  23. };
  24. /**
  25. * Status and property data for DataSystemSourceNotifications and Requests
  26. */
  27. struct BuilderSourceResult
  28. {
  29. BuilderSourceStatus status = BuilderSourceStatus::Failed;
  30. const BuildVariableOverrides* data = nullptr;
  31. };
  32. /**
  33. * Provides notifications of changes, failures, and removals of ScriptCanvas source files in the project folders only.
  34. * This alleviates clients which are only interested in ScriptCanvas source file status from having to listen to the AssetSystemBus
  35. * themselves, and checking for or re-parsing for ScriptCanvas builder data.
  36. */
  37. class DataSystemSourceNotifications
  38. : public AZ::EBusTraits
  39. {
  40. public:
  41. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  42. using BusIdType = AZ::Uuid;
  43. /// sent when a source file has been modified or newly added
  44. virtual void SourceFileChanged(const BuilderSourceResult& result, AZStd::string_view relativePath, AZStd::string_view scanFolder) = 0;
  45. /// sent when a source file failed to load or process
  46. virtual void SourceFileFailed(AZStd::string_view relativePath, AZStd::string_view scanFolder) = 0;
  47. /// sent when file was removed from the tracked system
  48. virtual void SourceFileRemoved(AZStd::string_view relativePath, AZStd::string_view scanFolder) = 0;
  49. };
  50. using DataSystemSourceNotificationsBus = AZ::EBus<DataSystemSourceNotifications>;
  51. /**
  52. * Builder requests allow clients to query the source Builder status and data on demand.
  53. */
  54. class DataSystemSourceRequests
  55. : public AZ::EBusTraits
  56. {
  57. public:
  58. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  59. /// Makes an on-demand request for the compiled builder data of the source
  60. virtual BuilderSourceResult CompileBuilderData(SourceHandle sourceHandle) = 0;
  61. };
  62. using DataSystemSourceRequestsBus = AZ::EBus<DataSystemSourceRequests>;
  63. /**
  64. * Notifications distilled from asset processor notifications relating to ScriptCanvas assets.
  65. */
  66. class DataSystemAssetNotifications
  67. : public AZ::EBusTraits
  68. {
  69. public:
  70. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  71. using BusIdType = AZ::Uuid;
  72. /// the asset, possibly due to change, is immediately available for execution
  73. virtual void OnReady(ScriptCanvas::RuntimeAssetPtr asset) = 0;
  74. /// the asset, possibly due to change or removal, is no longer available for execution at all
  75. virtual void OnAssetNotReady() = 0;
  76. };
  77. using DataSystemAssetNotificationsBus = AZ::EBus<DataSystemAssetNotifications>;
  78. /**
  79. * Indicator status DataSystemAssetRequests
  80. */
  81. enum class BuilderAssetStatus
  82. {
  83. Ready,
  84. Pending,
  85. Error
  86. };
  87. /**
  88. * Status and asset data for DataSystemAssetRequests
  89. */
  90. struct BuilderAssetResult
  91. {
  92. BuilderAssetStatus status = BuilderAssetStatus::Error;
  93. ScriptCanvas::RuntimeAssetPtr data;
  94. };
  95. /**
  96. * Requests for asset status and data
  97. */
  98. class DataSystemAssetRequests
  99. : public AZ::EBusTraits
  100. {
  101. public:
  102. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  103. /// Returns status and the Asset (if there is one) for the supplied SourceHandle. If
  104. /// the status is 'Ready', the asset can be executed immediately.
  105. /// If it is 'Pending', the system is waiting on results of processing since the source
  106. /// has recently changed.
  107. virtual BuilderAssetResult LoadAsset(SourceHandle sourceHandle) = 0;
  108. };
  109. using DataSystemAssetRequestsBus = AZ::EBus<DataSystemAssetRequests>;
  110. }