Files
integration/Plugins/UEWingman/BrokenHandlers/Details_SetMany.h

61 lines
1.7 KiB
C
Raw Normal View History

2026-04-03 11:41:21 -04:00
#pragma once
#include "CoreMinimal.h"
#include "WingServer.h"
2026-04-07 22:04:44 -04:00
#include "WingBasics.h"
2026-04-03 11:41:21 -04:00
#include "WingFetcher.h"
2026-04-03 19:54:50 -04:00
#include "WingProperty.h"
2026-04-03 11:41:21 -04:00
#include "WingUtils.h"
2026-04-03 15:03:59 -04:00
#include "Details_SetMany.generated.h"
2026-04-03 11:41:21 -04:00
UCLASS()
2026-04-03 15:03:59 -04:00
class UWing_Details_SetMany : public UWingHandler
2026-04-03 11:41:21 -04:00
{
GENERATED_BODY()
public:
2026-04-03 19:07:39 -04:00
UPROPERTY(EditAnywhere, meta=(Description="Target object"))
2026-04-03 11:41:21 -04:00
FString Object;
2026-04-03 19:07:39 -04:00
UPROPERTY(EditAnywhere, meta=(Description="Object mapping property names to new values in Unreal text format"))
2026-04-03 11:41:21 -04:00
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
{
2026-04-04 01:45:25 -04:00
WingFetcher F(WingOut::Stdout);
2026-04-03 11:41:21 -04:00
UObject* Obj = F.Walk(Object).Cast<UObject>();
if (!Obj) return;
if (!Properties.Json || Properties.Json->Values.Num() == 0)
{
2026-04-04 01:45:25 -04:00
WingOut::Stdout.Print(TEXT("Error: No properties specified\n"));
2026-04-03 11:41:21 -04:00
return;
}
TArray<FWingProperty> Props = FWingProperty::GetDetails(Obj, true);
2026-04-03 11:41:21 -04:00
// Validation pass — resolve all properties before modifying anything.
for (const auto& Pair : Properties.Json->Values)
{
2026-04-04 01:45:25 -04:00
FWingProperty* P = WingUtils::FindOneWithExternalID(Pair.Key, Props, TEXT("Property"), WingOut::Stdout);
2026-04-03 11:41:21 -04:00
if (!P) return;
}
// Assignment pass — store the values.
int SuccessCount = 0;
for (const auto& Pair : Properties.Json->Values)
{
2026-04-04 01:45:25 -04:00
FWingProperty* P = WingUtils::FindOneWithExternalID(Pair.Key, Props, TEXT("Property"), WingOut::Stdout);
if (P->SetJson(*Pair.Value, WingOut::Stdout)) SuccessCount++;
2026-04-03 11:41:21 -04:00
}
2026-04-04 01:45:25 -04:00
WingOut::Stdout.Printf(TEXT("Set %d/%d properties.\n"), SuccessCount, Properties.Json->Values.Num());
2026-04-03 11:41:21 -04:00
}
};