Broad rearrangement of handlers
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "MCPHandler.h"
|
||||
#include "MCPFetcher.h"
|
||||
#include "MCPUtils.h"
|
||||
#include "EdGraph/EdGraphNode.h"
|
||||
#include "K2Node_Event.h"
|
||||
#include "K2Node_CustomEvent.h"
|
||||
#include "K2Node_FunctionEntry.h"
|
||||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
#include "GraphNode_Delete.generated.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
UCLASS()
|
||||
class UMCP_GraphNode_Delete : public UObject, public IMCPHandler
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(meta=(Description="Path to the node, e.g. /Game/Foo,graph:EventGraph,node:MyNode"))
|
||||
FString Node;
|
||||
|
||||
virtual FString GetDescription() const override
|
||||
{
|
||||
return TEXT("Delete a node from a Blueprint graph. "
|
||||
"Cannot delete entry nodes (FunctionEntry, Event, CustomEvent).");
|
||||
}
|
||||
|
||||
virtual void Handle(const FJsonObject* Json, FStringBuilderBase& Result) override
|
||||
{
|
||||
MCPFetcher F(Result);
|
||||
UEdGraphNode* FoundNode = F.Walk(Node).Cast<UEdGraphNode>();
|
||||
if (!FoundNode) return;
|
||||
|
||||
UEdGraph* Graph = FoundNode->GetGraph();
|
||||
UBlueprint* BP = FBlueprintEditorUtils::FindBlueprintForNodeChecked(FoundNode);
|
||||
|
||||
// Protect root/entry nodes — deleting these leaves the graph in an invalid
|
||||
// state with no root node, causing compiler errors that can't be fixed
|
||||
// without recreating the entire function/event.
|
||||
MCPErrorCallback Error(Result);
|
||||
FString NodeTitle = MCPUtils::FormatName(FoundNode);
|
||||
FString GraphName = MCPUtils::FormatName(Graph);
|
||||
|
||||
if (Cast<UK2Node_FunctionEntry>(FoundNode))
|
||||
{
|
||||
return Error.SetError(FString::Printf(
|
||||
TEXT("Cannot delete FunctionEntry node '%s' in graph '%s'. ")
|
||||
TEXT("This is the root node of the function — removing it would leave an empty, uncompilable graph. ")
|
||||
TEXT("To remove the entire function, delete it from the Blueprint editor."),
|
||||
*NodeTitle, *GraphName));
|
||||
}
|
||||
if (Cast<UK2Node_Event>(FoundNode))
|
||||
{
|
||||
return Error.SetError(FString::Printf(
|
||||
TEXT("Cannot delete event entry node '%s' in graph '%s'. ")
|
||||
TEXT("This is the root node of the event handler — removing it would leave an empty, uncompilable graph."),
|
||||
*NodeTitle, *GraphName));
|
||||
}
|
||||
if (Cast<UK2Node_CustomEvent>(FoundNode))
|
||||
{
|
||||
return Error.SetError(FString::Printf(
|
||||
TEXT("Cannot delete CustomEvent entry node '%s' in graph '%s'. ")
|
||||
TEXT("This is the root node of the custom event — removing it would leave an empty, uncompilable graph."),
|
||||
*NodeTitle, *GraphName));
|
||||
}
|
||||
|
||||
FoundNode->BreakAllNodeLinks();
|
||||
Graph->RemoveNode(FoundNode);
|
||||
|
||||
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(BP);
|
||||
|
||||
Result.Appendf(TEXT("Deleted node '%s' from graph '%s'.\n"), *NodeTitle, *GraphName);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user