More work on blueprint MCP
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "WingServer.h"
|
||||
#include "WingHandler.h"
|
||||
#include "WingUtils.h"
|
||||
#include "AssetRegistry/AssetRegistryModule.h"
|
||||
#include "AssetRegistry/IAssetRegistry.h"
|
||||
#include "Asset_ContentBrowse.generated.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
UCLASS()
|
||||
class UWing_Asset_ContentBrowse : public UObject, public IWingHandler
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(meta=(Description="Content browser path to list, e.g. /Game or /Game/Maps"))
|
||||
FString Path;
|
||||
|
||||
virtual FString GetDescription() const override
|
||||
{
|
||||
return TEXT("List the subfolders and assets inside a content browser folder.");
|
||||
}
|
||||
|
||||
static FString GetExtraInfoString(const FAssetData& Data)
|
||||
{
|
||||
FString ParentClassName;
|
||||
if (Data.GetTagValue(FName(TEXT("ParentClass")), ParentClassName))
|
||||
{
|
||||
int32 DotIndex;
|
||||
if (ParentClassName.FindLastChar('.', DotIndex))
|
||||
ParentClassName = ParentClassName.Mid(DotIndex + 1);
|
||||
ParentClassName.RemoveFromEnd(TEXT("'"));
|
||||
return FString::Printf(TEXT("(parent: %s)"), *ParentClassName);
|
||||
}
|
||||
return FString();
|
||||
}
|
||||
|
||||
static FString GetAssetTypeString(const FAssetData& Data)
|
||||
{
|
||||
FString AssetType = WingUtils::FormatName(Data.GetClass());
|
||||
FString BlueprintTypeTag;
|
||||
if (Data.GetTagValue(FName(TEXT("BlueprintType")), BlueprintTypeTag))
|
||||
{
|
||||
BlueprintTypeTag.RemoveFromStart(TEXT("BPTYPE_"));
|
||||
if (BlueprintTypeTag == TEXT("Normal"))
|
||||
AssetType = TEXT("Blueprint");
|
||||
else if (BlueprintTypeTag == TEXT("Const"))
|
||||
AssetType = TEXT("ConstBlueprint");
|
||||
else
|
||||
AssetType = BlueprintTypeTag;
|
||||
}
|
||||
return AssetType;
|
||||
}
|
||||
|
||||
virtual void Handle() override
|
||||
{
|
||||
// Normalize: strip trailing slash
|
||||
while (Path.EndsWith(TEXT("/")))
|
||||
{
|
||||
Path.LeftChopInline(1);
|
||||
}
|
||||
|
||||
IAssetRegistry& AR = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry").Get();
|
||||
|
||||
TArray<FString> Results;
|
||||
AR.EnumerateSubPaths(Path, [&Results](FString SubPath)
|
||||
{
|
||||
Results.Add(FString::Printf(TEXT("[Folder] %s\n"), *SubPath));
|
||||
return true;
|
||||
}, false);
|
||||
|
||||
// Collect assets in this folder (non-recursive)
|
||||
FARFilter Filter;
|
||||
Filter.PackagePaths.Add(FName(*Path));
|
||||
Filter.bRecursivePaths = false;
|
||||
TArray<FAssetData> Assets;
|
||||
AR.GetAssets(Filter, Assets);
|
||||
|
||||
for (const FAssetData &Asset : Assets)
|
||||
{
|
||||
if (Asset.IsRedirector()) continue;
|
||||
FString TypeString = GetAssetTypeString(Asset);
|
||||
FString ExtraInfo = GetExtraInfoString(Asset);
|
||||
Results.Add(FString::Printf(TEXT("%-30s %s %s\n"),
|
||||
*TypeString, *Asset.PackageName.ToString(), *ExtraInfo));
|
||||
}
|
||||
|
||||
Results.Sort();
|
||||
for (const FString &Result : Results) UWingServer::Print(Result);
|
||||
|
||||
if (Results.IsEmpty())
|
||||
{
|
||||
UWingServer::Printf(TEXT("No contents found at '%s'.\n"), *Path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
}
|
||||
|
||||
// Find the newly created variable description
|
||||
FBlueprintVar Editor(BP, Name);
|
||||
FWingBlueprintVar Editor(BP, Name);
|
||||
if (Editor.NotFound()) return;
|
||||
|
||||
// Apply config if provided
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
UBlueprint* BP = F.Walk(Blueprint).Cast<UBlueprint>();
|
||||
if (!BP) return;
|
||||
|
||||
FBlueprintVar Editor(BP, Variable);
|
||||
FWingBlueprintVar Editor(BP, Variable);
|
||||
if (Editor.NotFound()) return;
|
||||
|
||||
FBlueprintEditorUtils::RemoveMemberVariable(BP, Editor.Desc->VarName);
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
UBlueprint* BP = F.Walk(Blueprint).Cast<UBlueprint>();
|
||||
if (!BP) return;
|
||||
|
||||
FBlueprintVar Editor(BP, Variable);
|
||||
FWingBlueprintVar Editor(BP, Variable);
|
||||
if (Editor.NotFound()) return;
|
||||
|
||||
UWingServer::Printf(TEXT("Variable %s in %s:\n"), *Variable, *WingUtils::FormatName(BP));
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
UBlueprint* BP = F.Walk(Blueprint).Cast<UBlueprint>();
|
||||
if (!BP) return;
|
||||
|
||||
FBlueprintVar Editor(BP, Variable);
|
||||
FWingBlueprintVar Editor(BP, Variable);
|
||||
if (Editor.NotFound()) return;
|
||||
|
||||
if (!Properties.Json || Properties.Json->Values.Num() == 0)
|
||||
|
||||
Reference in New Issue
Block a user