76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "MCPHandler.h"
|
|
#include "MCPAssetFinder.h"
|
|
#include "MCPUtils.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "Kismet2/BlueprintEditorUtils.h"
|
|
#include "Blueprint_RemoveInterface.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UMCP_Blueprint_RemoveInterface : public UObject, public IMCPHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="Blueprint name or package path"))
|
|
FString Blueprint;
|
|
|
|
UPROPERTY(meta=(Description="Interface name to remove"))
|
|
FString InterfaceName;
|
|
|
|
UPROPERTY(meta=(Optional, Description="If true, keep the function graphs as regular functions"))
|
|
bool PreserveFunctions = false;
|
|
|
|
virtual FString GetDescription() const override
|
|
{
|
|
return TEXT("Remove a Blueprint Interface implementation from a Blueprint. "
|
|
"Optionally preserve the function graphs as regular functions.");
|
|
}
|
|
|
|
virtual void Handle(const FJsonObject* Json, FStringBuilderBase& Result) override
|
|
{
|
|
MCPAssets<UBlueprint> Assets;
|
|
if (!Assets.Exact(Blueprint).Errors(Result).ENone().ETwo().Load()) return;
|
|
UBlueprint* BP = Assets.Object();
|
|
|
|
// Find the interface by name
|
|
UClass* FoundInterface = nullptr;
|
|
for (const FBPInterfaceDescription& IfaceDesc : BP->ImplementedInterfaces)
|
|
{
|
|
if (!IfaceDesc.Interface) continue;
|
|
if (MCPUtils::Identifies(InterfaceName, IfaceDesc.Interface))
|
|
{
|
|
FoundInterface = IfaceDesc.Interface;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!FoundInterface)
|
|
{
|
|
MCPErrorCallback(Result).SetError(FString::Printf(
|
|
TEXT("Interface '%s' not found. Implemented interfaces: "), *InterfaceName));
|
|
for (const FBPInterfaceDescription& IfaceDesc : BP->ImplementedInterfaces)
|
|
{
|
|
if (IfaceDesc.Interface)
|
|
Result.Appendf(TEXT(" %s\n"), *MCPUtils::FormatName(IfaceDesc.Interface));
|
|
}
|
|
return;
|
|
}
|
|
|
|
FTopLevelAssetPath InterfacePath = FoundInterface->GetClassPathName();
|
|
FBlueprintEditorUtils::RemoveInterface(BP, InterfacePath, PreserveFunctions);
|
|
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(BP);
|
|
|
|
Result.Appendf(TEXT("Removed interface %s\n"), *MCPUtils::FormatName(FoundInterface));
|
|
if (PreserveFunctions)
|
|
Result.Append(TEXT("Function graphs preserved as regular functions.\n"));
|
|
}
|
|
};
|