Broad rearrangement of handlers
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "MCPHandler.h"
|
||||
#include "MCPFetcher.h"
|
||||
#include "MCPUtils.h"
|
||||
#include "StructUtils/UserDefinedStruct.h"
|
||||
#include "UserDefinedStructure/UserDefinedStructEditorData.h"
|
||||
#include "UMCPHandler_RemoveStructField.generated.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
UCLASS(meta=(Group="Unclassified"))
|
||||
class UMCPHandler_RemoveStructField : public UObject, public IMCPHandler
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(meta=(Description="Struct name or package path"))
|
||||
FString Struct;
|
||||
|
||||
UPROPERTY(meta=(Description="Name of the field to remove"))
|
||||
FString FieldName;
|
||||
|
||||
virtual FString GetDescription() const override
|
||||
{
|
||||
return TEXT("Remove a field from a UserDefinedStruct asset.");
|
||||
}
|
||||
|
||||
virtual void Handle(const FJsonObject* Json, FStringBuilderBase& Result) override
|
||||
{
|
||||
MCPFetcher F(Result);
|
||||
UUserDefinedStruct* S = F.Walk(Struct).Cast<UUserDefinedStruct>();
|
||||
if (!S) return;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!FStructureEditorUtils::RemoveVariable(S, TargetGuid))
|
||||
{
|
||||
Result.Appendf(TEXT("ERROR: Failed to remove field '%s'."), *FieldName);
|
||||
return;
|
||||
}
|
||||
|
||||
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."));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user