2026-03-10 01:42:43 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "MCPHandler.h"
|
|
|
|
|
#include "MCPFetcher.h"
|
|
|
|
|
#include "MCPUtils.h"
|
|
|
|
|
#include "BlueprintExporter.h"
|
|
|
|
|
#include "Engine/Blueprint.h"
|
|
|
|
|
#include "EdGraph/EdGraph.h"
|
|
|
|
|
#include "UMCPHandler_DumpGraphs.generated.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
UCLASS()
|
|
|
|
|
class UMCPHandler_DumpGraphs : public UObject, public IMCPHandler
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
UPROPERTY(meta=(Description="Path to a blueprint or graph, e.g. /Game/Foo or /Game/Foo,graph:EventGraph"))
|
|
|
|
|
FString Path;
|
|
|
|
|
|
|
|
|
|
virtual FString GetDescription() const override
|
|
|
|
|
{
|
|
|
|
|
return TEXT("Dump blueprint graphs as readable text. "
|
|
|
|
|
"If given a blueprint, dumps all graphs. If given a specific graph, dumps only that one.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void Handle(const FJsonObject* Json, FStringBuilderBase& Result) override
|
|
|
|
|
{
|
|
|
|
|
MCPFetcher F(Result);
|
|
|
|
|
F.Walk(Path);
|
|
|
|
|
if (!F.Ok()) return;
|
|
|
|
|
|
|
|
|
|
if (UEdGraph* Graph = Cast<UEdGraph>(F.Obj))
|
|
|
|
|
{
|
|
|
|
|
EmitGraph(Graph, Result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (UBlueprint* BP = Cast<UBlueprint>(F.Obj))
|
|
|
|
|
{
|
|
|
|
|
TArray<UEdGraph*> Graphs = MCPUtils::AllGraphs(BP);
|
|
|
|
|
for (UEdGraph* Graph : Graphs)
|
|
|
|
|
{
|
|
|
|
|
Result.Appendf(TEXT("\n======== %s ========\n"), *MCPUtils::FormatName(Graph));
|
|
|
|
|
EmitGraph(Graph, Result);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Result.Appendf(TEXT("ERROR: Expected a blueprint or graph, got %s\n"),
|
2026-03-10 07:17:42 -04:00
|
|
|
*MCPUtils::FormatName(F.Obj->GetClass()));
|
2026-03-10 01:42:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void EmitGraph(UEdGraph* Graph, FStringBuilderBase& Result)
|
|
|
|
|
{
|
|
|
|
|
FlxBlueprintExporter Exporter(Graph);
|
|
|
|
|
Result.Append(Exporter.GetOutput());
|
|
|
|
|
FString Details = Exporter.GetDetails();
|
|
|
|
|
if (!Details.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
Result.Append(TEXT("\n"));
|
|
|
|
|
Result.Append(Details);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|