From fe4a4d564667ee804f9fc52bb0157eebded00c3e Mon Sep 17 00:00:00 2001 From: jyelon Date: Fri, 3 Apr 2026 11:41:21 -0400 Subject: [PATCH] Prop Get2/Set2 --- .../Source/UEWingman/Handlers/Property_Get2.h | 42 +++++++++++++ .../Source/UEWingman/Handlers/Property_Set2.h | 61 +++++++++++++++++++ .../UEWingman/Private/WingPropHandle.cpp | 38 ++++++++++++ .../Source/UEWingman/Public/WingPropHandle.h | 1 + 4 files changed, 142 insertions(+) create mode 100644 Plugins/UEWingman/Source/UEWingman/Handlers/Property_Get2.h create mode 100644 Plugins/UEWingman/Source/UEWingman/Handlers/Property_Set2.h diff --git a/Plugins/UEWingman/Source/UEWingman/Handlers/Property_Get2.h b/Plugins/UEWingman/Source/UEWingman/Handlers/Property_Get2.h new file mode 100644 index 00000000..d6562757 --- /dev/null +++ b/Plugins/UEWingman/Source/UEWingman/Handlers/Property_Get2.h @@ -0,0 +1,42 @@ +#pragma once + +#include "CoreMinimal.h" +#include "WingServer.h" +#include "WingHandler.h" +#include "WingFetcher.h" +#include "WingPropHandle.h" +#include "WingUtils.h" +#include "Property_Get2.generated.h" + +UCLASS() +class UWing_Property_Get2 : public UWingHandler +{ + GENERATED_BODY() + +public: + UPROPERTY(meta=(Description="Target object")) + FString Object; + + UPROPERTY(meta=(Description="Property name")) + FString Property; + + virtual void Register() override + { + UWingServer::AddHandler(this, + TEXT("Get the value of a single property.")); + } + + virtual void Handle() override + { + WingFetcher F; + UObject* Obj = F.Walk(Object).Cast(); + if (!Obj) return; + + WingPropHandle Props; + WingPropHandle::Handles Handles = Props.GetDetails(Obj, false); + TSharedPtr* P = WingUtils::FindOneWithExternalID(Property, Handles, TEXT("Property")); + if (!P) return; + + UWingServer::Print(WingPropHandle::GetText(**P)); + } +}; diff --git a/Plugins/UEWingman/Source/UEWingman/Handlers/Property_Set2.h b/Plugins/UEWingman/Source/UEWingman/Handlers/Property_Set2.h new file mode 100644 index 00000000..307ffad2 --- /dev/null +++ b/Plugins/UEWingman/Source/UEWingman/Handlers/Property_Set2.h @@ -0,0 +1,61 @@ +#pragma once + +#include "CoreMinimal.h" +#include "WingServer.h" +#include "WingHandler.h" +#include "WingFetcher.h" +#include "WingPropHandle.h" +#include "WingUtils.h" +#include "Property_Set2.generated.h" + +UCLASS() +class UWing_Property_Set2 : public UWingHandler +{ + GENERATED_BODY() + +public: + UPROPERTY(meta=(Description="Target object")) + FString Object; + + UPROPERTY(meta=(Description="Object mapping property names to new values in Unreal text format")) + FWingJsonObject Properties; + + virtual void Register() override + { + UWingServer::AddHandler(this, + TEXT("Set one or more editable properties. Values use Unreal text format.")); + } + + virtual void Handle() override + { + WingFetcher F; + UObject* Obj = F.Walk(Object).Cast(); + if (!Obj) return; + + if (!Properties.Json || Properties.Json->Values.Num() == 0) + { + UWingServer::Print(TEXT("Error: No properties specified\n")); + return; + } + + WingPropHandle Props; + WingPropHandle::Handles Handles = Props.GetDetails(Obj, true); + + // Validation pass — resolve all properties before modifying anything. + for (const auto& Pair : Properties.Json->Values) + { + TSharedPtr* P = WingUtils::FindOneWithExternalID(Pair.Key, Handles, TEXT("Property")); + if (!P) return; + } + + // Assignment pass — store the values. + int SuccessCount = 0; + for (const auto& Pair : Properties.Json->Values) + { + TSharedPtr* P = WingUtils::FindOneWithExternalID(Pair.Key, Handles, TEXT("Property")); + if (P && WingPropHandle::SetJson(**P, Pair.Value)) SuccessCount++; + } + + UWingServer::Printf(TEXT("Set %d/%d properties.\n"), SuccessCount, Properties.Json->Values.Num()); + } +}; diff --git a/Plugins/UEWingman/Source/UEWingman/Private/WingPropHandle.cpp b/Plugins/UEWingman/Source/UEWingman/Private/WingPropHandle.cpp index 72b2b8c5..cd1bf352 100644 --- a/Plugins/UEWingman/Source/UEWingman/Private/WingPropHandle.cpp +++ b/Plugins/UEWingman/Source/UEWingman/Private/WingPropHandle.cpp @@ -3,6 +3,7 @@ #include "WingActorComponent.h" #include "WingUtils.h" #include "WingTypes.h" +#include "Dom/JsonValue.h" #include "PropertyEditorModule.h" #include "IDetailTreeNode.h" #include "Engine/Blueprint.h" @@ -339,6 +340,43 @@ bool WingPropHandle::SetText(IPropertyHandle& Handle, const FString& Text) return true; } +///////////////////////////////////////////////////////////////////////////// +// +// SetJson +// +///////////////////////////////////////////////////////////////////////////// + +bool WingPropHandle::SetJson(IPropertyHandle& Handle, const TSharedPtr& JsonValue) +{ + FPropertyAccess::Result Result; + + switch (JsonValue->Type) + { + case EJson::String: + return SetText(Handle, JsonValue->AsString()); + + case EJson::Boolean: + Result = Handle.SetValue(JsonValue->AsBool()); + break; + + case EJson::Number: + Result = Handle.SetValue(JsonValue->AsNumber()); + break; + + default: + Result = FPropertyAccess::Fail; + break; + } + + if (Result != FPropertyAccess::Success) + { + UWingServer::Printf(TEXT("ERROR: Failed to set property '%s'\n"), + *WingUtils::FormatName(Handle.GetProperty())); + return false; + } + return true; +} + ///////////////////////////////////////////////////////////////////////////// // // Print diff --git a/Plugins/UEWingman/Source/UEWingman/Public/WingPropHandle.h b/Plugins/UEWingman/Source/UEWingman/Public/WingPropHandle.h index 6453bfb2..fdae7ef6 100644 --- a/Plugins/UEWingman/Source/UEWingman/Public/WingPropHandle.h +++ b/Plugins/UEWingman/Source/UEWingman/Public/WingPropHandle.h @@ -53,6 +53,7 @@ public: // (human-readable format via UWingTypes). static FString GetText(IPropertyHandle& Handle); static bool SetText(IPropertyHandle& Handle, const FString& Text); + static bool SetJson(IPropertyHandle& Handle, const TSharedPtr& JsonValue); // Print a single property in a standardized format: // editable|readonly Type Name = Value