98 lines
2.4 KiB
C++
98 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "MCPHandler.h"
|
|
#include "MCPFetcher.h"
|
|
#include "MCPUtils.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "EdGraph/EdGraph.h"
|
|
#include "Kismet2/BlueprintEditorUtils.h"
|
|
#include "BlueprintGraph_Delete.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UMCP_BlueprintGraph_Delete : public UObject, public IMCPHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="Path to a blueprint, e.g. /Game/Foo/Bar"))
|
|
FString Path;
|
|
|
|
UPROPERTY(meta=(Description="Name of the graph to delete"))
|
|
FString Graph;
|
|
|
|
virtual FString GetDescription() const override
|
|
{
|
|
return TEXT("Delete a function or macro graph from a Blueprint. Cannot delete EventGraph pages.");
|
|
}
|
|
|
|
virtual void Handle(const FJsonObject* Json, FStringBuilderBase& Result) override
|
|
{
|
|
MCPFetcher F(Result);
|
|
F.Walk(Path);
|
|
if (!F.Ok()) return;
|
|
|
|
UBlueprint* BP = F.Cast<UBlueprint>();
|
|
if (!BP) return;
|
|
|
|
// Search function graphs, then macro graphs
|
|
UEdGraph* TargetGraph = nullptr;
|
|
FString GraphType;
|
|
|
|
for (UEdGraph* G : BP->FunctionGraphs)
|
|
{
|
|
if (G && MCPUtils::Identifies(Graph, G))
|
|
{
|
|
TargetGraph = G;
|
|
GraphType = TEXT("function");
|
|
break;
|
|
}
|
|
}
|
|
if (!TargetGraph)
|
|
{
|
|
for (UEdGraph* G : BP->MacroGraphs)
|
|
{
|
|
if (G && MCPUtils::Identifies(Graph, G))
|
|
{
|
|
TargetGraph = G;
|
|
GraphType = TEXT("macro");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check if it's an UbergraphPage (EventGraph) — disallow deletion
|
|
if (!TargetGraph)
|
|
{
|
|
for (UEdGraph* G : BP->UbergraphPages)
|
|
{
|
|
if (G && MCPUtils::Identifies(Graph, G))
|
|
{
|
|
Result.Appendf(TEXT("ERROR: Cannot delete UbergraphPage '%s'. EventGraph pages cannot be deleted.\n"),
|
|
*MCPUtils::FormatName(G));
|
|
return;
|
|
}
|
|
}
|
|
Result.Appendf(TEXT("ERROR: Graph '%s' not found in blueprint %s\n"),
|
|
*Graph, *MCPUtils::FormatName(BP));
|
|
return;
|
|
}
|
|
|
|
// Remove the graph
|
|
FString GraphName = MCPUtils::FormatName(TargetGraph);
|
|
F.PreEdit();
|
|
FBlueprintEditorUtils::RemoveGraph(BP, TargetGraph, EGraphRemoveFlags::Default);
|
|
F.PostEdit();
|
|
bool bSaved = MCPUtils::SaveBlueprintPackage(BP);
|
|
|
|
Result.Appendf(TEXT("Deleted %s graph %s\n"), *GraphType, *GraphName);
|
|
if (!bSaved)
|
|
Result.Append(TEXT("WARNING: Package save failed.\n"));
|
|
}
|
|
};
|