/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include #include #include #include #include #include // Undo this AZ_PUSH_DISABLE_WARNING(4251 4800 4244, "-Wunknown-warning-option") #include #include #include AZ_POP_DISABLE_WARNING #include namespace ScriptCanvasEditor { EditorAssetSystemComponent::~EditorAssetSystemComponent() { } void EditorAssetSystemComponent::Reflect(AZ::ReflectContext* context) { if (auto serializeContext = azrtti_cast(context)) { serializeContext->Class() ->Version(0) ; } } void EditorAssetSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC("ScriptCanvasEditorAssetService", 0x4a1c043d)); } void EditorAssetSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ_CRC("AssetDatabaseService", 0x3abf5601)); required.push_back(AZ_CRC("AssetCatalogService", 0xc68ffc57)); required.push_back(AZ_CRC("ScriptCanvasService", 0x41fd58f3)); } void EditorAssetSystemComponent::Init() { } void EditorAssetSystemComponent::Activate() { m_editorAssetRegistry.Register(); AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusConnect(); EditorAssetConversionBus::Handler::BusConnect(); } void EditorAssetSystemComponent::Deactivate() { EditorAssetConversionBus::Handler::BusDisconnect(); AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusDisconnect(); m_editorAssetRegistry.Unregister(); } ScriptCanvas::AssetRegistry& EditorAssetSystemComponent::GetAssetRegistry() { return m_editorAssetRegistry; } static bool HandlesSource(const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* entry) { AZStd::string_view targetExtension = entry->GetExtension(); AZStd::string_view scriptCanvasFileFilter = SourceDescription::GetFileFilter(); if (AZStd::wildcard_match(scriptCanvasFileFilter.data(), targetExtension.data())) { return true; } return false; } AZ::Outcome, AZStd::string> EditorAssetSystemComponent::CreateRuntimeAsset(const SourceHandle& editAsset) { return ScriptCanvasBuilder::CreateRuntimeAsset(editAsset); } AZ::Outcome EditorAssetSystemComponent::CreateLuaAsset(const SourceHandle& editAsset, AZStd::string_view graphPathForRawLuaFile) { return ScriptCanvasBuilder::CreateLuaAsset(editAsset, graphPathForRawLuaFile); } void EditorAssetSystemComponent::AddSourceFileOpeners ( [[maybe_unused]] const char* fullSourceFileName , const AZ::Uuid& sourceUuid , AzToolsFramework::AssetBrowser::SourceFileOpenerList& openers) { using namespace AzToolsFramework; using namespace AzToolsFramework::AssetBrowser; // get the full details of the source file based on its UUID. if (const SourceAssetBrowserEntry* source = SourceAssetBrowserEntry::GetSourceByUuid(sourceUuid)) { if (!HandlesSource(source)) { return; } } else { // has no UUID / Not a source file. return; } // You can push back any number of "Openers" - choose a unique identifier, and icon, // and then a lambda which will be activated if the user chooses to open it with your opener: openers.push_back({ "ScriptCanvas_Editor_Asset_Edit", "Script Canvas Editor..." , QIcon(ScriptCanvasEditor::SourceDescription::GetIconPath()), [](const char*, const AZ::Uuid& scSourceUuid) { AzToolsFramework::OpenViewPane(LyViewPane::ScriptCanvas); if (auto sourceHandle = CompleteDescription(SourceHandle(nullptr, scSourceUuid, {}))) { AZ::Outcome openOutcome = AZ::Failure(AZStd::string()); GeneralRequestBus::BroadcastResult(openOutcome, &GeneralRequests::OpenScriptCanvasAsset , *sourceHandle, Tracker::ScriptCanvasFileState::UNMODIFIED, -1); if (!openOutcome) { AZ_Warning("ScriptCanvas", openOutcome, "%s", openOutcome.GetError().data()); } } else { AZ_Warning("ScriptCanvas", false , "Unabled to find full path for Source UUid %s", scSourceUuid.ToString().c_str()); } }}); } }