Files
integration/Plugins/BlueprintMCP/Source/BlueprintMCP/Handlers/Class_ShowProperties.h

79 lines
2.6 KiB
C
Raw Normal View History

2026-03-08 22:17:14 -04:00
#pragma once
#include "CoreMinimal.h"
#include "MCPHandler.h"
#include "MCPUtils.h"
2026-03-12 00:44:17 -04:00
#include "Class_ShowProperties.generated.h"
2026-03-08 22:17:14 -04:00
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
2026-03-12 00:44:17 -04:00
UCLASS()
class UMCP_Class_ShowProperties : public UObject, public IMCPHandler
2026-03-08 22:17:14 -04:00
{
GENERATED_BODY()
public:
UPROPERTY(meta=(Description="Class name to list properties for"))
FString ClassName;
UPROPERTY(meta=(Optional, Description="Substring filter for property names"))
2026-03-10 20:15:59 -04:00
FString Query;
2026-03-08 22:17:14 -04:00
virtual FString GetDescription() const override
{
return TEXT("List properties on a UClass, including type, owning class, and property flags.");
}
2026-03-12 17:48:11 -04:00
virtual void Handle(FStringBuilderBase& Result) override
2026-03-08 22:17:14 -04:00
{
2026-03-10 07:17:42 -04:00
UClass* FoundClass = MCPUtils::FindClassByName(ClassName);
2026-03-08 22:17:14 -04:00
if (!FoundClass)
{
2026-03-10 07:17:42 -04:00
Result.Appendf(TEXT("ERROR: Class '%s' not found\n"), *ClassName);
return;
2026-03-08 22:17:14 -04:00
}
2026-03-10 07:17:42 -04:00
Result.Appendf(TEXT("Properties of %s:\n"), *MCPUtils::FormatName(FoundClass));
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
int32 Count = 0;
2026-03-08 22:17:14 -04:00
for (TFieldIterator<FProperty> PropIt(FoundClass); PropIt; ++PropIt)
{
FProperty* Prop = *PropIt;
if (!Prop) continue;
FString PropName = Prop->GetName();
2026-03-10 20:15:59 -04:00
if (!Query.IsEmpty() && !PropName.Contains(Query, ESearchCase::IgnoreCase))
2026-03-08 22:17:14 -04:00
continue;
2026-03-10 07:17:42 -04:00
// Build compact flags string
TStringBuilder<256> Flags;
if (Prop->HasAnyPropertyFlags(CPF_BlueprintVisible)) Flags.Append(TEXT(" BlueprintVisible"));
if (Prop->HasAnyPropertyFlags(CPF_BlueprintReadOnly)) Flags.Append(TEXT(" BlueprintReadOnly"));
if (Prop->HasAnyPropertyFlags(CPF_Edit)) Flags.Append(TEXT(" EditAnywhere"));
if (Prop->HasAnyPropertyFlags(CPF_EditConst)) Flags.Append(TEXT(" VisibleOnly"));
if (Prop->HasAnyPropertyFlags(CPF_Config)) Flags.Append(TEXT(" Config"));
if (Prop->HasAnyPropertyFlags(CPF_SaveGame)) Flags.Append(TEXT(" SaveGame"));
if (Prop->HasAnyPropertyFlags(CPF_Transient)) Flags.Append(TEXT(" Transient"));
if (Prop->HasAnyPropertyFlags(CPF_RepNotify)) Flags.Append(TEXT(" RepNotify"));
2026-03-08 22:17:14 -04:00
UClass* OwnerClass = Prop->GetOwnerClass();
2026-03-10 07:17:42 -04:00
Result.Appendf(TEXT(" %s %s"), *MCPUtils::FormatPropertyType(Prop), *PropName);
if (OwnerClass && OwnerClass != FoundClass)
Result.Appendf(TEXT(" [%s]"), *MCPUtils::FormatName(OwnerClass));
if (Flags.Len() > 0)
Result.Appendf(TEXT(" (%s)"), Flags.ToString() + 1); // skip leading space
Result.Append(TEXT("\n"));
Count++;
2026-03-08 22:17:14 -04:00
}
2026-03-10 07:17:42 -04:00
if (Count == 0)
{
Result.Append(TEXT("No properties found.\n"));
}
2026-03-08 22:17:14 -04:00
}
};