From a43affe8048b03c4776dfdefbc1ba053854f7166 Mon Sep 17 00:00:00 2001 From: jyelon Date: Wed, 8 Apr 2026 00:52:23 -0400 Subject: [PATCH] Header file reorg, documentation, and cleanup --- .../Handlers/GraphNode_SetDefaults.h | 1 - .../UEWingman/Handlers/GraphPin_Connect.h | 1 - .../UEWingman/Handlers/GraphPin_Disconnect.h | 1 - .../Source/UEWingman/Private/WingFetcher.cpp | 1 - .../Source/UEWingman/Private/WingProperty.cpp | 1 - .../UEWingman/Private/WingReferences.cpp | 6 - .../Source/UEWingman/Public/WingBasics.h | 164 +++++++++++++++--- .../Source/UEWingman/Public/WingComponent.h | 17 -- .../Source/UEWingman/Public/WingReferences.h | 66 ------- 9 files changed, 143 insertions(+), 115 deletions(-) delete mode 100644 Plugins/UEWingman/Source/UEWingman/Private/WingReferences.cpp delete mode 100644 Plugins/UEWingman/Source/UEWingman/Public/WingReferences.h diff --git a/Plugins/UEWingman/Source/UEWingman/Handlers/GraphNode_SetDefaults.h b/Plugins/UEWingman/Source/UEWingman/Handlers/GraphNode_SetDefaults.h index 137a5299..a4f61362 100644 --- a/Plugins/UEWingman/Source/UEWingman/Handlers/GraphNode_SetDefaults.h +++ b/Plugins/UEWingman/Source/UEWingman/Handlers/GraphNode_SetDefaults.h @@ -4,7 +4,6 @@ #include "WingBasics.h" #include "WingServer.h" #include "WingFetcher.h" -#include "WingReferences.h" #include "WingProperty.h" #include "WingUtils.h" #include "EdGraph/EdGraphPin.h" diff --git a/Plugins/UEWingman/Source/UEWingman/Handlers/GraphPin_Connect.h b/Plugins/UEWingman/Source/UEWingman/Handlers/GraphPin_Connect.h index fc2b3372..a763d9cc 100644 --- a/Plugins/UEWingman/Source/UEWingman/Handlers/GraphPin_Connect.h +++ b/Plugins/UEWingman/Source/UEWingman/Handlers/GraphPin_Connect.h @@ -4,7 +4,6 @@ #include "WingServer.h" #include "WingBasics.h" #include "WingFetcher.h" -#include "WingReferences.h" #include "WingProperty.h" #include "WingUtils.h" #include "Engine/Blueprint.h" diff --git a/Plugins/UEWingman/Source/UEWingman/Handlers/GraphPin_Disconnect.h b/Plugins/UEWingman/Source/UEWingman/Handlers/GraphPin_Disconnect.h index 3b1758c4..bf80481d 100644 --- a/Plugins/UEWingman/Source/UEWingman/Handlers/GraphPin_Disconnect.h +++ b/Plugins/UEWingman/Source/UEWingman/Handlers/GraphPin_Disconnect.h @@ -4,7 +4,6 @@ #include "WingServer.h" #include "WingBasics.h" #include "WingFetcher.h" -#include "WingReferences.h" #include "WingProperty.h" #include "WingUtils.h" #include "Engine/Blueprint.h" diff --git a/Plugins/UEWingman/Source/UEWingman/Private/WingFetcher.cpp b/Plugins/UEWingman/Source/UEWingman/Private/WingFetcher.cpp index 67a95930..fef762ed 100644 --- a/Plugins/UEWingman/Source/UEWingman/Private/WingFetcher.cpp +++ b/Plugins/UEWingman/Source/UEWingman/Private/WingFetcher.cpp @@ -3,7 +3,6 @@ #include "WingBasics.h" #include "WingUtils.h" #include "WingComponent.h" -#include "WingReferences.h" #include "Engine/Blueprint.h" #include "EdGraph/EdGraph.h" #include "EdGraph/EdGraphNode.h" diff --git a/Plugins/UEWingman/Source/UEWingman/Private/WingProperty.cpp b/Plugins/UEWingman/Source/UEWingman/Private/WingProperty.cpp index 871428af..5b0f6599 100644 --- a/Plugins/UEWingman/Source/UEWingman/Private/WingProperty.cpp +++ b/Plugins/UEWingman/Source/UEWingman/Private/WingProperty.cpp @@ -2,7 +2,6 @@ #include "WingComponent.h" #include "WingUtils.h" #include "WingBasics.h" -#include "WingReferences.h" #include "WingServer.h" #include "WingTypes.h" #include "Engine/Blueprint.h" diff --git a/Plugins/UEWingman/Source/UEWingman/Private/WingReferences.cpp b/Plugins/UEWingman/Source/UEWingman/Private/WingReferences.cpp deleted file mode 100644 index c4ce97df..00000000 --- a/Plugins/UEWingman/Source/UEWingman/Private/WingReferences.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "WingReferences.h" -#include "WingUtils.h" -#include "EdGraph/EdGraphNode.h" -#include "EdGraph/EdGraphPin.h" - - diff --git a/Plugins/UEWingman/Source/UEWingman/Public/WingBasics.h b/Plugins/UEWingman/Source/UEWingman/Public/WingBasics.h index d86ac33a..3286a9da 100644 --- a/Plugins/UEWingman/Source/UEWingman/Public/WingBasics.h +++ b/Plugins/UEWingman/Source/UEWingman/Public/WingBasics.h @@ -6,25 +6,22 @@ #include "Dom/JsonObject.h" #include "WingBasics.generated.h" -// Marker struct for handler parameters that accept a JSON object. -// PopulateFromJson stashes the actual JSON object into the Json field. -// -USTRUCT() -struct FWingJsonObject -{ - GENERATED_BODY() - TSharedPtr Json; -}; +class UEdGraphNode; +class UEdGraphPin; -// Marker struct for handler parameters that accept a JSON array. -// PopulateFromJson stashes the actual JSON array into the Array field. +//////////////////////////////////////////////////////////// // -USTRUCT() -struct FWingJsonArray -{ - GENERATED_BODY() - TArray> Array; -}; +// Handlers. +// +// Each command supported by the MCP is implemented by a +// 'handler'. The server receives the request, which +// contains a command. The server looks up the right +// handler class for the command, and creates a handler +// object. Using reflection, it inserts the command +// parameters into uproperty fields of the handler, then +// calls the handle method, which executes the command. +// +//////////////////////////////////////////////////////////// UENUM() enum class EWingHandlerKind @@ -59,13 +56,56 @@ public: // The configuration object. FWingHandlerConfig *Configuration; - -public: }; -// A 'WingOut' is our version of an output stream. It always -// contains a pointer to a string builder, or nullptr. +//////////////////////////////////////////////////////////// // +// Json wrappers. +// +// Normally, the json request is automatically used to +// populate the properties of the handler, so the handler +// doesn't have to deal with json. However, in a few cases, +// the handler actually does want to see some json. These +// wrappers allow a handler to request raw json data instead +// of pre-processed values. +// +//////////////////////////////////////////////////////////// + +USTRUCT() +struct FWingJsonObject +{ + GENERATED_BODY() + TSharedPtr Json; +}; + +// Marker struct for handler parameters that accept a JSON array. +// PopulateFromJson stashes the actual JSON array into the Array field. +// +USTRUCT() +struct FWingJsonArray +{ + GENERATED_BODY() + TArray> Array; +}; + +//////////////////////////////////////////////////////////// +// +// WingOut. +// +// A thin wrapper around unreal string builders. Handlers +// put their output into a WingOut (string builder), which +// eventually gets forwarded to the agent. This output +// buffer is called WingOut::Stdout. +// +// Subroutines that can generate error messages take a +// parameter 'WingOut Errors', a string builder where they +// can put the error message. Unlike a raw string builder, +// a WingOut can be nullptr, which is useful if you want to +// ignore error messages from certain subroutines. You can +// also direct error messages directly to WingOut::Stdout. +// +//////////////////////////////////////////////////////////// + class WingOut { public: @@ -87,6 +127,16 @@ private: FStringBuilderBase *Buffer; }; +//////////////////////////////////////////////////////////// +// +// FWingStructAndUStruct. +// +// A pointer to a struct, and also a pointer to a UStruct +// that describes the struct. This also can store a +// UObject and the UClass that describes the UObject. +// +//////////////////////////////////////////////////////////// + // A FWingStructAndUStruct is a pointer to a struct and its associated ustruct. // struct FWingStructAndUStruct @@ -108,3 +158,75 @@ struct FWingStructAndUStruct FWingStructAndUStruct(T *Struct) : StructPtr(Struct), UStructPtr(Struct->StaticStruct()) {} }; + +//////////////////////////////////////////////////////////// +// +// References. +// +// The MCP has a variety of operations that can manipulate +// any object, including: actors, components, graphs, graph +// nodes, graph pins, widgets, and so forth. For example, +// the agent can request a 'details panel' for any of these. +// +// However, some of those objects aren't UObjects. This +// makes it awkward to write code that deals with them +// uniformly. To homogenize them, we turn them all into +// UObjects by creating wrappers for those that aren't. +// +// Some things that you would think are UObjects, like +// components, are actually only UObjects at runtime. +// When a blueprint is still being edited, the component +// is represented by a bunch of related data structures +// inside the blueprint. At that time, there is no one +// UObject to point to as 'the component.' +// +//////////////////////////////////////////////////////////// + + +// Pin Ref: A pointer to a graph node, plus a pin name. +UCLASS() +class UWingPinReference : public UObject +{ + GENERATED_BODY() + +public: + UPROPERTY() + UEdGraphNode* Node = nullptr; + + FName PinName; +}; + +// Component Ref: A pointer to a blueprint plus a component +// name. The component can be an inherited component, as +// opposed to one that is defined in the blueprint itself. +UCLASS() +class UWingComponentReference : public UObject +{ + GENERATED_BODY() +public: + UPROPERTY() + UBlueprint* BP = nullptr; + + // The component name. + FName VariableName; +}; + +// Struct Ref: A pointer to an object, and a struct inside +// that object. The editable flag indicates whether the +// struct is marked CPF_Edit. If not, then the intent is +// that this struct is for viewing only. +UCLASS() +class UWingStructPointer : public UObject +{ + GENERATED_BODY() +public: + UPROPERTY() + UObject* Object; + + UPROPERTY() + UStruct* StructType; + + void *StructBase; + + bool Editable; +}; diff --git a/Plugins/UEWingman/Source/UEWingman/Public/WingComponent.h b/Plugins/UEWingman/Source/UEWingman/Public/WingComponent.h index 300fc892..a192119e 100644 --- a/Plugins/UEWingman/Source/UEWingman/Public/WingComponent.h +++ b/Plugins/UEWingman/Source/UEWingman/Public/WingComponent.h @@ -2,29 +2,12 @@ #include "CoreMinimal.h" #include "WingBasics.h" -#include "WingComponent.generated.h" class UBlueprint; class USCS_Node; class UActorComponent; class USimpleConstructionScript; -// a 'Component Reference' is just a pointer to a -// blueprint plus a component name. -// -UCLASS() -class UWingComponentReference : public UObject -{ - GENERATED_BODY() -public: - // The blueprint that was queried: not necessarily the - // same blueprint that defined the component. - UPROPERTY() - UBlueprint* BP = nullptr; - - // The component name. - FName VariableName; -}; struct UWingComponent { diff --git a/Plugins/UEWingman/Source/UEWingman/Public/WingReferences.h b/Plugins/UEWingman/Source/UEWingman/Public/WingReferences.h deleted file mode 100644 index 6ddb1b61..00000000 --- a/Plugins/UEWingman/Source/UEWingman/Public/WingReferences.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include "CoreMinimal.h" -#include "UObject/Object.h" -#include "WingBasics.h" -#include "WingReferences.generated.h" - -class UEdGraphNode; -class UEdGraphPin; - -//////////////////////////////////////////////////////////// -// -// The WingFetcher module allows you to start at an asset and -// walk to any object within that asset. For example, you can -// start at an actor blueprint, walk to its event graph, then -// walk to a graph node, and then walk to a graph pin. -// -// The following classes make it possible to 'walk' to a -// place that isn't a UObject, or that isn't a single UObject. -// We accomplish this by creating a UObject class that -// contains some sort of reference to the item in question. -// -//////////////////////////////////////////////////////////// - - -// WingStructPointer: Stores a pointer to a ustruct which is -// inside a UObject. This makes it possible to walk to a -// struct property. -// -// The Object field should be point at the containing object -// to ensure it doesn't get garbage collected. -// -// The editable flag indicates whether the struct property -// we walked into is marked CPF_Edit. If not, then the intent -// is that this struct is for viewing only. - -UCLASS() -class UWingStructPointer : public UObject -{ - GENERATED_BODY() -public: - UPROPERTY() - UObject* Object; - - UPROPERTY() - UStruct* StructType; - - void *StructBase; - - bool Editable; -}; - -// WingPinReference: Stores the name of a UEdGraphPin which is -// inside a UEdGraphNode. - -UCLASS() -class UWingPinReference : public UObject -{ - GENERATED_BODY() - -public: - UPROPERTY() - UEdGraphNode* Node = nullptr; - - FName PinName; -};