Prop Get2/Set2
This commit is contained in:
42
Plugins/UEWingman/Source/UEWingman/Handlers/Property_Get2.h
Normal file
42
Plugins/UEWingman/Source/UEWingman/Handlers/Property_Get2.h
Normal file
@@ -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<UObject>();
|
||||||
|
if (!Obj) return;
|
||||||
|
|
||||||
|
WingPropHandle Props;
|
||||||
|
WingPropHandle::Handles Handles = Props.GetDetails(Obj, false);
|
||||||
|
TSharedPtr<IPropertyHandle>* P = WingUtils::FindOneWithExternalID(Property, Handles, TEXT("Property"));
|
||||||
|
if (!P) return;
|
||||||
|
|
||||||
|
UWingServer::Print(WingPropHandle::GetText(**P));
|
||||||
|
}
|
||||||
|
};
|
||||||
61
Plugins/UEWingman/Source/UEWingman/Handlers/Property_Set2.h
Normal file
61
Plugins/UEWingman/Source/UEWingman/Handlers/Property_Set2.h
Normal file
@@ -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<UObject>();
|
||||||
|
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<IPropertyHandle>* 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<IPropertyHandle>* 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());
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "WingActorComponent.h"
|
#include "WingActorComponent.h"
|
||||||
#include "WingUtils.h"
|
#include "WingUtils.h"
|
||||||
#include "WingTypes.h"
|
#include "WingTypes.h"
|
||||||
|
#include "Dom/JsonValue.h"
|
||||||
#include "PropertyEditorModule.h"
|
#include "PropertyEditorModule.h"
|
||||||
#include "IDetailTreeNode.h"
|
#include "IDetailTreeNode.h"
|
||||||
#include "Engine/Blueprint.h"
|
#include "Engine/Blueprint.h"
|
||||||
@@ -339,6 +340,43 @@ bool WingPropHandle::SetText(IPropertyHandle& Handle, const FString& Text)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SetJson
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool WingPropHandle::SetJson(IPropertyHandle& Handle, const TSharedPtr<FJsonValue>& 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
|
// Print
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public:
|
|||||||
// (human-readable format via UWingTypes).
|
// (human-readable format via UWingTypes).
|
||||||
static FString GetText(IPropertyHandle& Handle);
|
static FString GetText(IPropertyHandle& Handle);
|
||||||
static bool SetText(IPropertyHandle& Handle, const FString& Text);
|
static bool SetText(IPropertyHandle& Handle, const FString& Text);
|
||||||
|
static bool SetJson(IPropertyHandle& Handle, const TSharedPtr<FJsonValue>& JsonValue);
|
||||||
|
|
||||||
// Print a single property in a standardized format:
|
// Print a single property in a standardized format:
|
||||||
// editable|readonly Type Name = Value
|
// editable|readonly Type Name = Value
|
||||||
|
|||||||
Reference in New Issue
Block a user