More refactoring.

This commit is contained in:
2026-03-14 01:31:06 -04:00
parent 8eeac9bd07
commit e33bfefec7
8 changed files with 166 additions and 134 deletions

View File

@@ -15,6 +15,30 @@
#include "Engine/LevelScriptBlueprint.h"
#include "Subsystems/AssetEditorSubsystem.h"
MCPFetcher::WalkFunc MCPFetcher::GetWalker(const FString& Step)
{
if (Step.Equals(TEXT("graph"), ESearchCase::IgnoreCase)) return &MCPFetcher::Graph;
if (Step.Equals(TEXT("node"), ESearchCase::IgnoreCase)) return &MCPFetcher::Node;
if (Step.Equals(TEXT("pin"), ESearchCase::IgnoreCase)) return &MCPFetcher::Pin;
if (Step.Equals(TEXT("component"), ESearchCase::IgnoreCase)) return &MCPFetcher::Component;
if (Step.Equals(TEXT("levelblueprint"), ESearchCase::IgnoreCase)) return &MCPFetcher::LevelBlueprint;
return nullptr;
}
void MCPFetcher::PrintDocs()
{
UMCPServer::Print(TEXT("Some commands take a Path parameter. A Path starts with an asset\n"));
UMCPServer::Print(TEXT("package path (e.g. /Game/Widgets/WB_Hotkeys), followed by zero or\n"));
UMCPServer::Print(TEXT("more comma-separated steps that navigate into the asset:\n\n"));
UMCPServer::Print(TEXT(" graph — Find a named UEdGraph (blank name for material graphs)\n"));
UMCPServer::Print(TEXT(" node — Find a named UEdGraphNode within a graph or blueprint\n"));
UMCPServer::Print(TEXT(" pin — Find a named UEdGraphPin on a node\n"));
UMCPServer::Print(TEXT(" component — Find a named component in a Blueprint's SCS\n"));
UMCPServer::Print(TEXT(" levelblueprint — Get the level blueprint from a UWorld\n"));
UMCPServer::Print(TEXT("\nExample: /Game/Widgets/WB_Hotkeys,graph:EventGraph,node:Self_Reference_03,pin:Result\n"));
}
void MCPFetcher::SetObj(UObject* InObj) { UMCPServer::AddTouchedObject(InObj); Obj = InObj; ResultPin = nullptr; }
void MCPFetcher::SetPin(UEdGraphPin* InPin) { ResultPin = InPin; Obj = nullptr; }
@@ -36,17 +60,7 @@ MCPFetcher& MCPFetcher::TypeMismatch(const TCHAR* Walker, const TCHAR* Expected)
return *this;
}
const TArray<MCPFetcher::FWalker>& MCPFetcher::GetWalkerTable()
{
static TArray<FWalker> Table = {
{ TEXT("graph"), TEXT("Find a named UEdGraph (blank name for material graphs)"), &MCPFetcher::Graph },
{ TEXT("node"), TEXT("Find a named UEdGraphNode within a graph or blueprint"), &MCPFetcher::Node },
{ TEXT("pin"), TEXT("Find a named UEdGraphPin on a node"), &MCPFetcher::Pin },
{ TEXT("component"), TEXT("Find a named component in a Blueprint's SCS"), &MCPFetcher::Component },
{ TEXT("levelblueprint"), TEXT("Get the level blueprint from a UWorld"), &MCPFetcher::LevelBlueprint },
};
return Table;
}
MCPFetcher& MCPFetcher::Walk(const FString& Path)
{
@@ -73,13 +87,13 @@ MCPFetcher& MCPFetcher::Walk(const FString& Path)
if (!Segments[i].Split(TEXT(":"), &Key, &Value))
Key = Segments[i];
const FWalker* W = GetWalker(Key);
if (!W)
WalkFunc Func = GetWalker(Key);
if (!Func)
{
UMCPServer::Printf(TEXT("ERROR: Unknown path step '%s'\n"), *Key);
return SetError();
}
(this->*W->Func)(Value);
(this->*Func)(Value);
if (bError) return *this;
}
@@ -135,16 +149,6 @@ bool MCPFetcher::CheckAssetIsA(UClass* StaticClass)
return true;
}
const MCPFetcher::FWalker* MCPFetcher::GetWalker(const FString& Key)
{
for (const FWalker& W : GetWalkerTable())
{
if (Key.Equals(W.Key, ESearchCase::IgnoreCase))
return &W;
}
return nullptr;
}
MCPFetcher& MCPFetcher::Graph(const FString& Value)
{
if (bError) return *this;
@@ -330,30 +334,6 @@ MCPFetcher& MCPFetcher::LevelBlueprint(const FString& Value)
return *this;
}
MCPFetcher& MCPFetcher::Template()
{
if (bError) return *this;
if (!Obj)
{
UMCPServer::Print(TEXT("ERROR: Template: object is null\n"));
return SetError();
}
if (UBlueprint* BP = ::Cast<UBlueprint>(Obj))
{
if (!BP->GeneratedClass)
{
UMCPServer::Printf(TEXT("ERROR: Blueprint '%s' has no GeneratedClass\n"), *Obj->GetName());
return SetError();
}
SetObj(BP->GeneratedClass->GetDefaultObject());
return *this;
}
// Everything else is its own template — no navigation needed.
return *this;
}
MCPFetcher& MCPFetcher::ToBlueprint()
{
if (bError) return *this;