Improvement to design of MCPProperty

This commit is contained in:
2026-03-17 11:38:25 -04:00
parent f831da0f0c
commit b58532324a
6 changed files with 19 additions and 27 deletions

View File

@@ -94,7 +94,8 @@ public:
UEdGraphNode* Node = F.Node(Entry.Node).Cast<UEdGraphNode>();
if (!Node) return;
MCPProperty P = MCPProperty::GetOneExactMatch(Node, CPF_Edit, Entry.Name);
TArray<MCPProperty> All = MCPProperty::GetAll(Node, CPF_Edit);
MCPProperty P = MCPProperty::FindOneExactMatch(All, Entry.Name);
if (!P) return;
UMCPServer::AddTouchedObject(Node);

View File

@@ -43,8 +43,8 @@ public:
MCPFetcher F;
UObject* Template = F.Walk(Object).Cast<UObject>();
if (!Template) return;
TArray<MCPProperty> Props = MCPProperty::GetAllSubstring(Template, CPF_Edit, Query);
TArray<MCPProperty> AllProps = MCPProperty::GetAll(Template, CPF_Edit);
TArray<MCPProperty> Props = MCPProperty::FindAllSubstring(AllProps, Query);
if (Local)
{
UClass* ObjClass = Template->GetClass();

View File

@@ -36,7 +36,8 @@ public:
UObject* Obj = F.Walk(Object).Cast<UObject>();
if (!Obj) return;
MCPProperty P = MCPProperty::GetOneExactMatch(Obj, CPF_Edit, Property);
TArray<MCPProperty> All = MCPProperty::GetAll(Obj, CPF_Edit);
MCPProperty P = MCPProperty::FindOneExactMatch(All, Property);
if (!P) return;
UMCPServer::Print(P.GetText());

View File

@@ -44,10 +44,11 @@ public:
}
// Validation pass — resolve all properties and values before modifying anything.
TArray<MCPProperty> All = MCPProperty::GetAll(Obj, CPF_Edit);
TArray<TPair<MCPProperty, FString>> Resolved;
for (const auto& Pair : Properties.Json->Values)
{
MCPProperty P = MCPProperty::GetOneExactMatch(Obj, CPF_Edit, Pair.Key);
MCPProperty P = MCPProperty::FindOneExactMatch(All, Pair.Key);
if (!P) return;
FString ValueStr;

View File

@@ -160,12 +160,11 @@ TArray<MCPProperty> MCPProperty::GetAll(UStruct* StructType, void* Container, EP
return Result;
}
TArray<MCPProperty> MCPProperty::GetAllSubstring(UObject* Obj, EPropertyFlags Flags, const FString& Substring)
TArray<MCPProperty> MCPProperty::FindAllSubstring(const TArray<MCPProperty>& Props, const FString& Substring)
{
TArray<MCPProperty> All = GetAll(Obj, Flags);
if (Substring.IsEmpty()) return All;
if (Substring.IsEmpty()) return Props;
TArray<MCPProperty> Result;
for (const MCPProperty& P : All)
for (const MCPProperty& P : Props)
{
if (MCPUtils::FormatName(P.Prop).Contains(Substring, ESearchCase::IgnoreCase))
Result.Add(P);
@@ -173,31 +172,22 @@ TArray<MCPProperty> MCPProperty::GetAllSubstring(UObject* Obj, EPropertyFlags Fl
return Result;
}
TArray<MCPProperty> MCPProperty::GetAllExactMatch(UObject* Obj, EPropertyFlags Flags, const FString& Name)
MCPProperty MCPProperty::FindOneExactMatch(const TArray<MCPProperty>& Props, const FString& Name)
{
TArray<MCPProperty> All = GetAll(Obj, Flags);
TArray<MCPProperty> Result;
for (const MCPProperty& P : All)
TArray<MCPProperty> Matches;
for (const MCPProperty& P : Props)
{
if (MCPUtils::Identifies(Name, P.Prop))
Result.Add(P);
Matches.Add(P);
}
return Result;
}
MCPProperty MCPProperty::GetOneExactMatch(UObject* Obj, EPropertyFlags Flags, const FString& Name)
{
TArray<MCPProperty> Matches = GetAllExactMatch(Obj, Flags, Name);
if (Matches.Num() == 0)
{
UMCPServer::Printf(TEXT("ERROR: Property '%s' not found on %s\n"),
*Name, *MCPUtils::FormatName(Obj->GetClass()));
UMCPServer::Printf(TEXT("ERROR: Property '%s' not found\n"), *Name);
return MCPProperty();
}
if (Matches.Num() > 1)
{
UMCPServer::Printf(TEXT("ERROR: Ambiguous property '%s' on %s\n"),
*Name, *MCPUtils::FormatName(Obj->GetClass()));
UMCPServer::Printf(TEXT("ERROR: Ambiguous property '%s'\n"), *Name);
return MCPProperty();
}
return Matches[0];

View File

@@ -23,9 +23,8 @@ public:
static void Remove(TArray<MCPProperty>& Props, const FString& Name);
static TArray<MCPProperty> GetAll(UObject* Obj, EPropertyFlags Flags);
static TArray<MCPProperty> GetAll(UStruct* StructType, void* Container, EPropertyFlags Flags);
static TArray<MCPProperty> GetAllSubstring(UObject* Obj, EPropertyFlags Flags, const FString& Substring);
static TArray<MCPProperty> GetAllExactMatch(UObject* Obj, EPropertyFlags Flags, const FString& Name);
static MCPProperty GetOneExactMatch(UObject* Obj, EPropertyFlags Flags, const FString& Name);
static TArray<MCPProperty> FindAllSubstring(const TArray<MCPProperty>& Props, const FString& Substring);
static MCPProperty FindOneExactMatch(const TArray<MCPProperty>& Props, const FString& Name);
private:
bool TryParseEnum(UEnum* Enum, const FString& Text, int64 &OutValue);