96 lines
2.5 KiB
C++
96 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "MCPHandler.h"
|
|
#include "MCPFetcher.h"
|
|
#include "MCPUtils.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "Engine/SimpleConstructionScript.h"
|
|
#include "Engine/SCS_Node.h"
|
|
#include "Blueprint_ListComponents.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UMCP_Blueprint_ListComponents : public UObject, public IMCPHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="Path to a blueprint, e.g. /Game/Tangibles/TAN_Tree"))
|
|
FString Path;
|
|
|
|
virtual FString GetDescription() const override
|
|
{
|
|
return TEXT("List all components in a Blueprint's SimpleConstructionScript, "
|
|
"showing hierarchy and component classes.");
|
|
}
|
|
|
|
virtual void Handle(FStringBuilderBase& Result) override
|
|
{
|
|
MCPFetcher F(Result);
|
|
F.Walk(Path);
|
|
if (!F.Ok()) return;
|
|
|
|
UBlueprint* BP = F.Cast<UBlueprint>();
|
|
if (!BP) return;
|
|
|
|
USimpleConstructionScript* SCS = BP->SimpleConstructionScript;
|
|
if (!SCS)
|
|
{
|
|
Result.Append(TEXT("ERROR: Not an Actor Blueprint (no SimpleConstructionScript)\n"));
|
|
return;
|
|
}
|
|
|
|
const TArray<USCS_Node*>& RootNodes = SCS->GetRootNodes();
|
|
const TArray<USCS_Node*>& AllNodes = SCS->GetAllNodes();
|
|
|
|
if (AllNodes.Num() == 0)
|
|
{
|
|
Result.Append(TEXT("No components.\n"));
|
|
return;
|
|
}
|
|
|
|
Result.Append(TEXT("WARNING: This only lists components added in this blueprint's SCS. "
|
|
"It does not include inherited components from C++ parent classes "
|
|
"(available via the CDO's OwnedComponents) or from parent blueprint SCS nodes.\n"));
|
|
|
|
// Emit components as a tree, starting from root nodes
|
|
for (USCS_Node* Root : RootNodes)
|
|
{
|
|
if (!Root) continue;
|
|
EmitNode(Root, 0, Root == RootNodes[0], Result);
|
|
}
|
|
}
|
|
|
|
private:
|
|
void EmitNode(USCS_Node* Node, int32 Depth, bool bIsSceneRoot, FStringBuilderBase& Result)
|
|
{
|
|
// Indent to show hierarchy
|
|
for (int32 i = 0; i < Depth; i++)
|
|
Result.Append(TEXT(" "));
|
|
|
|
FString ClassName = Node->ComponentClass
|
|
? MCPUtils::FormatName(Node->ComponentClass)
|
|
: TEXT("None");
|
|
|
|
Result.Appendf(TEXT("%s %s"),
|
|
*ClassName,
|
|
*MCPUtils::FormatName(Node->ComponentTemplate));
|
|
|
|
if (bIsSceneRoot && Depth == 0)
|
|
Result.Append(TEXT(" [SceneRoot]"));
|
|
|
|
Result.Append(TEXT("\n"));
|
|
|
|
for (USCS_Node* Child : Node->GetChildNodes())
|
|
{
|
|
if (!Child) continue;
|
|
EmitNode(Child, Depth + 1, false, Result);
|
|
}
|
|
}
|
|
};
|