73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "MCPHandler.h"
|
|
#include "MCPFetcher.h"
|
|
#include "MCPUtils.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "Kismet2/BlueprintEditorUtils.h"
|
|
#include "Blueprint_RemoveVariable.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UMCP_Blueprint_RemoveVariable : public UObject, public IMCPHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="Blueprint name or package path"))
|
|
FString Blueprint;
|
|
|
|
UPROPERTY(meta=(Description="Name of the variable to remove"))
|
|
FString VariableName;
|
|
|
|
virtual FString GetDescription() const override
|
|
{
|
|
return TEXT("Remove a member variable from a Blueprint.");
|
|
}
|
|
|
|
virtual void Handle(FStringBuilderBase& Result) override
|
|
{
|
|
MCPFetcher F;
|
|
UBlueprint* BP = F.Walk(Blueprint).Cast<UBlueprint>();
|
|
if (!BP) return;
|
|
|
|
// Find the variable using Identifies for consistent name matching
|
|
const FBPVariableDescription* Found = nullptr;
|
|
for (const FBPVariableDescription& Var : BP->NewVariables)
|
|
{
|
|
if (MCPUtils::FormatName(Var) == VariableName ||
|
|
Var.VarName.ToString().Equals(VariableName, ESearchCase::IgnoreCase))
|
|
{
|
|
Found = &Var;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!Found)
|
|
{
|
|
Result.Appendf(TEXT("ERROR: Variable '%s' not found in %s.\nAvailable variables:\n"),
|
|
*VariableName, *MCPUtils::FormatName(BP));
|
|
for (const FBPVariableDescription& Var : BP->NewVariables)
|
|
{
|
|
Result.Appendf(TEXT(" %s\n"), *MCPUtils::FormatName(Var));
|
|
}
|
|
return;
|
|
}
|
|
|
|
FName VarFName = Found->VarName;
|
|
|
|
// RemoveMemberVariable also cleans up Get/Set nodes
|
|
FBlueprintEditorUtils::RemoveMemberVariable(BP, VarFName);
|
|
|
|
bool bSaved = MCPUtils::SaveBlueprintPackage(BP);
|
|
Result.Appendf(TEXT("Removed variable %s from %s.%s\n"),
|
|
*VarFName.ToString(), *MCPUtils::FormatName(BP),
|
|
bSaved ? TEXT("") : TEXT(" WARNING: save failed."));
|
|
}
|
|
};
|