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>(); UEdGraphNode* Node = F.Node(Entry.Node).Cast<UEdGraphNode>();
if (!Node) return; 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; if (!P) return;
UMCPServer::AddTouchedObject(Node); UMCPServer::AddTouchedObject(Node);

View File

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

View File

@@ -36,7 +36,8 @@ public:
UObject* Obj = F.Walk(Object).Cast<UObject>(); UObject* Obj = F.Walk(Object).Cast<UObject>();
if (!Obj) return; 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; if (!P) return;
UMCPServer::Print(P.GetText()); UMCPServer::Print(P.GetText());

View File

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

View File

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

View File

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