Files
integration/Plugins/UEWingman/Source/UEWingman/Public/WingUtils.h

178 lines
6.9 KiB
C
Raw Normal View History

2026-03-06 15:06:12 -05:00
#pragma once
#include "CoreMinimal.h"
#include "Dom/JsonObject.h"
2026-03-12 19:12:37 -04:00
#include "EdGraph/EdGraph.h"
2026-03-06 15:06:12 -05:00
#include "EdGraph/EdGraphPin.h"
2026-03-12 08:26:18 -04:00
#include "Materials/MaterialInstanceConstant.h"
#include "MaterialTypes.h"
2026-03-06 15:06:12 -05:00
class UBlueprint;
class UEdGraphNode;
class UEdGraphPin;
class UMaterial;
class UMaterialInstance;
class UMaterialFunction;
2026-03-06 15:06:12 -05:00
class UMaterialExpression;
2026-03-10 20:15:59 -04:00
struct FEdGraphSchemaAction;
2026-03-06 15:06:12 -05:00
class UAnimationStateMachineGraph;
class UAnimStateNode;
class UAnimStateTransitionNode;
class UActorComponent;
class UWorld;
class UStaticMesh;
class USkeletalMesh;
class UAnimSequence;
class UBlendSpace;
class UTexture;
class UScriptStruct;
class UEnum;
2026-03-18 18:39:13 -04:00
class USCS_Node;
struct FMemberReference;
struct FBPVariableDescription;
2026-03-06 15:06:12 -05:00
// Stateless utility functions used by MCP handlers and the MCP server.
// This is effectively a namespace — all methods are static.
2026-03-18 10:17:58 -04:00
class WingUtils
2026-03-06 15:06:12 -05:00
{
public:
////////////////////////////////////////////////////////
//
// Name Formatting
//
// The goal here is to centralize the code that outputs
// names, and have everybody use it, so that names are
// used consistently. The secondary goal is to choose
// names that are as uniquely-identifying as is practical.
// It's not always 100% possible to get perfectly unique
// names, though, so our code needs to check for ambiguity.
//
////////////////////////////////////////////////////////
2026-03-10 01:42:43 -04:00
static FString FormatName(const UWorld *World);
static FString FormatName(const UBlueprint *BP);
static FString FormatName(const UActorComponent *C);
2026-03-18 18:39:13 -04:00
static FString FormatName(const USCS_Node *Node);
2026-03-10 01:42:43 -04:00
static FString FormatName(const UEdGraph *Graph);
static FString FormatName(const UEdGraphNode* Node);
static FString FormatName(const UEdGraphPin *Pin);
static FString FormatName(const FMemberReference &Ref);
static FString FormatName(const FBPVariableDescription &Var);
2026-03-10 20:15:59 -04:00
static FString FormatName(const UStruct *Struct);
static FString FormatName(const UMaterial *Material);
static FString FormatName(const UMaterialInstance *MaterialInstance);
static FString FormatName(const UMaterialFunction *MaterialFunction);
static FString FormatName(const UMaterialExpression *Expression);
static FString FormatName(const UStaticMesh *Mesh);
static FString FormatName(const USkeletalMesh *Mesh);
static FString FormatName(const UAnimSequence *Anim);
static FString FormatName(const UBlendSpace *BlendSpace);
static FString FormatName(const UTexture *Texture);
static FString FormatName(const UScriptStruct *Struct);
static FString FormatName(const UEnum *Enum);
2026-03-10 20:15:59 -04:00
static FString FormatName(const FProperty *Prop);
////////////////////////////////////////////////////////
//
// Identifies
//
// Return true if the name identifies the object. The
// FormatName functions, above, always return names that
// identify the object. However, there may be other
// names that also identify the object. Identifying names
// aren't 100% guaranteed to be unique, but very likely.
//
////////////////////////////////////////////////////////
2026-03-11 22:03:32 -04:00
template<typename T>
static bool Identifies(const FString &Name, T&& Obj)
{
return FormatName(std::forward<T>(Obj)).Equals(Name, ESearchCase::IgnoreCase);
}
// UEdGraphNode also matches by GUID.
2026-03-10 01:42:43 -04:00
static bool Identifies(const FString &Name, const UEdGraphNode* Node);
////////////////////////////////////////////////////////
static void SanitizeNameInPlace(FString& Name);
2026-03-11 22:03:32 -04:00
static FString FormatNodeTitle(const UEdGraphNode *Node);
2026-03-08 05:00:07 -04:00
// ----- Enum helpers -----
2026-03-13 02:09:19 -04:00
static FString EnumToString(UEnum* Enum, int64 Value, const FString& Prefix = FString());
2026-03-13 14:26:04 -04:00
static bool StringToEnum(UEnum* Enum, const FString& Str, int64& OutValue, const FString& Prefix = FString());
2026-03-13 02:09:19 -04:00
2026-03-08 21:28:47 -04:00
template<typename T>
static FString EnumToString(TEnumAsByte<T> Value, const FString& Prefix = FString())
2026-03-13 02:09:19 -04:00
{ return EnumToString(StaticEnum<T>(), (int64)Value, Prefix); }
2026-03-08 21:28:47 -04:00
2026-03-08 05:00:07 -04:00
template<typename T>
static FString EnumToString(T Value, const FString& Prefix = FString())
2026-03-13 02:09:19 -04:00
{ return EnumToString(StaticEnum<T>(), (int64)Value, Prefix); }
2026-03-08 05:00:07 -04:00
template<typename T>
2026-03-13 14:26:04 -04:00
static bool StringToEnum(const FString& Str, T& OutValue, const FString& Prefix = FString())
{ int64 V; if (!StringToEnum(StaticEnum<T>(), Str, V, Prefix)) return false; OutValue = (T)V; return true; }
2026-03-12 17:20:20 -04:00
2026-03-06 15:06:12 -05:00
// ----- Blueprint helpers -----
2026-03-08 03:44:27 -04:00
static TArray<UEdGraph*> AllGraphs(UBlueprint* BP);
static TArray<UEdGraph*> AllGraphsNamed(UBlueprint* BP, const FString& Name);
static TArray<UEdGraphNode*> AllNodes(UBlueprint* BP);
template<class T> static TArray<T*> AllNodes(UBlueprint* BP)
{
TArray<T*> Result;
for (UEdGraph* Graph : AllGraphs(BP))
for (UEdGraphNode* Node : Graph->Nodes)
if (T* Typed = Cast<T>(Node))
Result.Add(Typed);
return Result;
}
template<class T> static TArray<T*> AllNodes(UEdGraph* Graph)
{
TArray<T*> Result;
for (UEdGraphNode* Node : Graph->Nodes)
if (T* Typed = Cast<T>(Node))
Result.Add(Typed);
return Result;
}
2026-03-15 05:52:11 -04:00
static bool SaveBlueprintPackage(UBlueprint* BP);
2026-03-06 15:06:12 -05:00
static UClass* FindClassByName(const FString& ClassName);
// ----- Material helpers -----
static void EnsureMaterialGraph(UMaterial* Material);
static bool SaveGenericPackage(UObject* Asset);
2026-03-10 20:15:59 -04:00
// If the material editor has a transient preview copy of this material,
// return that copy (which is what the editor is actually working on).
// Otherwise return the original.
static UMaterial* ReplaceMaterialWithTransientCopy(UMaterial* Material);
2026-03-06 15:06:12 -05:00
// ----- Anim blueprint helpers -----
static UAnimationStateMachineGraph* FindStateMachineGraph(UBlueprint* BP, const FString& GraphName);
2026-03-13 14:26:04 -04:00
static UAnimStateNode* FindStateByName(UAnimationStateMachineGraph* SMGraph, const FString& StateName);
2026-03-06 15:06:12 -05:00
static UAnimStateTransitionNode* FindTransition(UAnimationStateMachineGraph* SMGraph, const FString& FromStateName, const FString& ToStateName);
2026-03-10 20:15:59 -04:00
// ----- Graph actions (node spawning) -----
static FString ActionFullName(const TSharedPtr<FEdGraphSchemaAction>& Action);
static TArray<TSharedPtr<FEdGraphSchemaAction>> SearchGraphActions(UEdGraph* Graph, const FString& Query, int32 MaxResults = 0, bool ExactMatch = false);
// ----- Editable template -----
2026-03-11 22:03:32 -04:00
static TArray<FProperty*> SearchProperties(UObject* Obj, const FString& Query, EPropertyFlags Flags, bool bLocal);
2026-03-13 14:26:04 -04:00
static FProperty* FindPropertyByName(UObject* Obj, const FString& Name);
2026-03-10 20:15:59 -04:00
static FString GetPropertyValueText(UObject* Container, FProperty* Prop);
2026-03-13 14:26:04 -04:00
static bool SetPropertyValueText(UObject* Container, FProperty* Prop, const FString& Value);
static bool SetPropertyValueText(void* Container, FProperty* Prop, const FString& Value, UObject* Owner);
2026-03-06 15:06:12 -05:00
2026-03-13 02:09:19 -04:00
// ----- Text formatting -----
static FString WrapText(const FString& Text, int32 ColLimit, const FString& Prefix);
2026-03-09 03:44:35 -04:00
// ----- Handler discovery -----
static TArray<UClass*> CollectHandlerClasses();
2026-03-13 02:09:19 -04:00
static FString GetHandlerName(UClass* HandlerClass);
static FString GetHandlerGroup(UClass* HandlerClass);
static void FormatCommandHelp(UClass* HandlerClass);
2026-03-08 21:28:47 -04:00
2026-03-06 17:14:25 -05:00
private:
static void AppendNumericSuffix(FString &Name, int32 N);
2026-03-06 15:06:12 -05:00
};
2026-03-15 13:59:09 -04:00