Files
integration/Plugins/UEWingman/Deprecated/UMCPHandler_RemoveStructField.h

76 lines
2.1 KiB
C
Raw Normal View History

2026-03-08 22:17:14 -04:00
#pragma once
#include "CoreMinimal.h"
#include "MCPHandler.h"
2026-03-10 07:17:42 -04:00
#include "MCPFetcher.h"
2026-03-08 22:17:14 -04:00
#include "MCPUtils.h"
#include "StructUtils/UserDefinedStruct.h"
#include "UserDefinedStructure/UserDefinedStructEditorData.h"
#include "UMCPHandler_RemoveStructField.generated.h"
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
2026-03-11 22:03:32 -04:00
UCLASS(meta=(Group="Unclassified"))
2026-03-08 22:17:14 -04:00
class UMCPHandler_RemoveStructField : public UObject, public IMCPHandler
{
GENERATED_BODY()
public:
2026-03-10 07:17:42 -04:00
UPROPERTY(meta=(Description="Struct name or package path"))
FString Struct;
2026-03-08 22:17:14 -04:00
UPROPERTY(meta=(Description="Name of the field to remove"))
2026-03-10 07:17:42 -04:00
FString FieldName;
2026-03-08 22:17:14 -04:00
virtual FString GetDescription() const override
{
return TEXT("Remove a field from a UserDefinedStruct asset.");
}
2026-03-10 07:17:42 -04:00
virtual void Handle(const FJsonObject* Json, FStringBuilderBase& Result) override
2026-03-08 22:17:14 -04:00
{
2026-03-10 07:17:42 -04:00
MCPFetcher F(Result);
UUserDefinedStruct* S = F.Walk(Struct).Cast<UUserDefinedStruct>();
if (!S) return;
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
// Find the field GUID by name
FGuid TargetGuid;
bool bFound = false;
for (const FStructVariableDescription& Var : FStructureEditorUtils::GetVarDesc(S))
{
if (Var.FriendlyName.Equals(FieldName, ESearchCase::IgnoreCase) ||
Var.VarName.ToString().Equals(FieldName, ESearchCase::IgnoreCase))
{
TargetGuid = Var.VarGuid;
bFound = true;
break;
}
}
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
if (!bFound)
{
Result.Appendf(TEXT("ERROR: Field '%s' not found in %s.\nAvailable fields:\n"),
*FieldName, *MCPUtils::FormatName(S));
for (const FStructVariableDescription& Var : FStructureEditorUtils::GetVarDesc(S))
{
Result.Appendf(TEXT(" %s\n"), *Var.FriendlyName);
}
return;
}
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
if (!FStructureEditorUtils::RemoveVariable(S, TargetGuid))
{
Result.Appendf(TEXT("ERROR: Failed to remove field '%s'."), *FieldName);
return;
}
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
bool bSaved = MCPUtils::SaveGenericPackage(S);
Result.Appendf(TEXT("Removed field %s from %s.%s\n"),
*FieldName, *MCPUtils::FormatName(S),
bSaved ? TEXT("") : TEXT(" WARNING: save failed."));
2026-03-08 22:17:14 -04:00
}
};