Broad rearrangement of handlers
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "MCPHandler.h"
|
||||
#include "MCPFetcher.h"
|
||||
#include "MCPAssetFinder.h"
|
||||
#include "MCPUtils.h"
|
||||
#include "K2Node_FunctionEntry.h"
|
||||
#include "K2Node_CustomEvent.h"
|
||||
#include "K2Node_EditablePinBase.h"
|
||||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
#include "Blueprint_RemoveFunctionParameter.generated.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
UCLASS()
|
||||
class UMCP_Blueprint_RemoveFunctionParameter : public UObject, public IMCPHandler
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(meta=(Description="Blueprint name or package path"))
|
||||
FString Blueprint;
|
||||
|
||||
UPROPERTY(meta=(Description="Name of the function or custom event"))
|
||||
FString FunctionName;
|
||||
|
||||
UPROPERTY(meta=(Description="Name of the parameter to remove"))
|
||||
FString ParamName;
|
||||
|
||||
virtual FString GetDescription() const override
|
||||
{
|
||||
return TEXT("Remove a parameter from a function or custom event in a Blueprint.");
|
||||
}
|
||||
|
||||
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 entry node (function entry or custom event)
|
||||
UK2Node_EditablePinBase* EntryNode = nullptr;
|
||||
|
||||
for (UK2Node_FunctionEntry* FuncEntry : MCPUtils::AllNodes<UK2Node_FunctionEntry>(BP))
|
||||
{
|
||||
if (MCPUtils::Identifies(FunctionName, FuncEntry->GetGraph()))
|
||||
{
|
||||
EntryNode = FuncEntry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!EntryNode)
|
||||
{
|
||||
for (UK2Node_CustomEvent* CustomEvent : MCPUtils::AllNodes<UK2Node_CustomEvent>(BP))
|
||||
{
|
||||
if (CustomEvent->CustomFunctionName.ToString().Equals(FunctionName, ESearchCase::IgnoreCase))
|
||||
{
|
||||
EntryNode = CustomEvent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!EntryNode)
|
||||
{
|
||||
Result.Appendf(TEXT("Error: Function or event '%s' not found.\nAvailable:\n"), *FunctionName);
|
||||
for (UK2Node_FunctionEntry* FE : MCPUtils::AllNodes<UK2Node_FunctionEntry>(BP))
|
||||
Result.Appendf(TEXT(" function: %s\n"), *MCPUtils::FormatName(FE->GetGraph()));
|
||||
for (UK2Node_CustomEvent* CE : MCPUtils::AllNodes<UK2Node_CustomEvent>(BP))
|
||||
Result.Appendf(TEXT(" event: %s\n"), *MCPUtils::FormatName(CE));
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the parameter to remove
|
||||
int32 RemovedIndex = INDEX_NONE;
|
||||
for (int32 i = 0; i < EntryNode->UserDefinedPins.Num(); ++i)
|
||||
{
|
||||
if (EntryNode->UserDefinedPins[i].IsValid() &&
|
||||
EntryNode->UserDefinedPins[i]->PinName.ToString().Equals(ParamName, ESearchCase::IgnoreCase))
|
||||
{
|
||||
RemovedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (RemovedIndex == INDEX_NONE)
|
||||
{
|
||||
Result.Appendf(TEXT("Error: Parameter '%s' not found on %s.\nAvailable:\n"),
|
||||
*ParamName, *MCPUtils::FormatName(EntryNode));
|
||||
for (const TSharedPtr<FUserPinInfo>& PinInfo : EntryNode->UserDefinedPins)
|
||||
if (PinInfo.IsValid())
|
||||
Result.Appendf(TEXT(" %s\n"), *PinInfo->PinName.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the pin
|
||||
EntryNode->UserDefinedPins.RemoveAt(RemovedIndex);
|
||||
|
||||
// Reconstruct the node to update output pins
|
||||
if (UEdGraph* OwningGraph = EntryNode->GetGraph())
|
||||
if (const UEdGraphSchema* Schema = OwningGraph->GetSchema())
|
||||
Schema->ReconstructNode(*EntryNode);
|
||||
|
||||
bool bSaved = MCPUtils::SaveBlueprintPackage(BP);
|
||||
|
||||
Result.Appendf(TEXT("Removed parameter '%s' from %s.\n"), *ParamName, *MCPUtils::FormatName(EntryNode));
|
||||
if (!bSaved)
|
||||
Result.Append(TEXT("Warning: save failed.\n"));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user