123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /*
- * 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 <PythonBuilderNotificationHandler.h>
- #include <AzCore/Serialization/SerializeContext.h>
- #include <AzCore/Serialization/EditContext.h>
- #include <AzCore/Serialization/EditContextConstants.inl>
- #include <AzToolsFramework/API/EditorPythonConsoleBus.h>
- #include <AssetBuilderSDK/AssetBuilderSDK.h>
- #include <EditorPythonBindings/EditorPythonBindingsSymbols.h>
- #include <Source/PythonAssetBuilderSystemComponent.h>
- namespace PythonAssetBuilder
- {
- void PythonBuilderNotificationHandler::Reflect(AZ::ReflectContext * context)
- {
- if (auto&& behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
- {
- behaviorContext->EBus<PythonBuilderNotificationBus>("PythonBuilderNotificationBus")
- ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
- ->Attribute(AZ::Script::Attributes::Module, "asset.builder")
- ->Handler<PythonBuilderNotificationHandler>()
- ->Event("OnCreateJobsRequest", &PythonBuilderNotificationBus::Events::OnCreateJobsRequest)
- ->Event("OnProcessJobRequest", &PythonBuilderNotificationBus::Events::OnProcessJobRequest)
- ->Event("OnShutdown", &PythonBuilderNotificationBus::Events::OnShutdown)
- ->Event("OnCancel", &PythonBuilderNotificationBus::Events::OnCancel)
- ;
- }
- }
- AssetBuilderSDK::CreateJobsResponse PythonBuilderNotificationHandler::OnCreateJobsRequest(const AssetBuilderSDK::CreateJobsRequest& request)
- {
- AssetBuilderSDK::CreateJobsResponse response;
- try
- {
- auto editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
- if (editorPythonEventsInterface)
- {
- editorPythonEventsInterface->ExecuteWithLock([&response, &request, this]()
- {
- this->CallResult(response, FN_OnCreateJobsRequest, request);
- });
- }
- else
- {
- response.m_result = AssetBuilderSDK::CreateJobsResultCode::Failed;
- }
- }
- catch ([[maybe_unused]] const std::exception& e)
- {
- AZ_Error(PythonBuilder, false, "OnCreateJobsRequest exception %s", e.what());
- response.m_result = AssetBuilderSDK::CreateJobsResultCode::Failed;
- }
- return response;
- }
- AssetBuilderSDK::ProcessJobResponse PythonBuilderNotificationHandler::OnProcessJobRequest(const AssetBuilderSDK::ProcessJobRequest& request)
- {
- AssetBuilderSDK::ProcessJobResponse response;
- try
- {
- auto editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
- if (editorPythonEventsInterface)
- {
- editorPythonEventsInterface->ExecuteWithLock([&response, &request, this]()
- {
- this->CallResult(response, FN_OnProcessJobRequest, request);
- });
- }
- else
- {
- response.m_resultCode = AssetBuilderSDK::ProcessJobResult_Failed;
- }
- }
- catch ([[maybe_unused]] const std::exception& e)
- {
- AZ_Error(PythonBuilder, false, "OnProcessJobRequest exception %s", e.what());
- response.m_resultCode = AssetBuilderSDK::ProcessJobResult_Failed;
- }
- return response;
- }
- void PythonBuilderNotificationHandler::OnShutdown()
- {
- try
- {
- auto editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
- if (editorPythonEventsInterface)
- {
- editorPythonEventsInterface->ExecuteWithLock([this]()
- {
- this->Call(FN_OnShutdown);
- });
- }
- }
- catch ([[maybe_unused]] const std::exception& e)
- {
- AZ_Warning(PythonBuilder, false, "OnShutdown exception %s", e.what());
- }
- }
- void PythonBuilderNotificationHandler::OnCancel()
- {
- try
- {
- auto editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
- if (editorPythonEventsInterface)
- {
- editorPythonEventsInterface->ExecuteWithLock([this]()
- {
- this->Call(FN_OnCancel);
- });
- }
- }
- catch ([[maybe_unused]] const std::exception& e)
- {
- AZ_Error(PythonBuilder, false, "OnCancel exception %s", e.what());
- }
- }
- }
|