Files
integration/Plugins/UEWingman/Deprecated/Struct_Create.h

96 lines
2.7 KiB
C
Raw Normal View History

2026-03-08 22:17:14 -04:00
#pragma once
#include "CoreMinimal.h"
2026-03-18 10:17:58 -04:00
#include "WingServer.h"
#include "WingHandler.h"
#include "WingTypes.h"
#include "WingJson.h"
#include "WingUtils.h"
2026-03-08 22:17:14 -04:00
#include "StructUtils/UserDefinedStruct.h"
#include "Kismet2/BlueprintEditorUtils.h"
#include "UserDefinedStructure/UserDefinedStructEditorData.h"
#include "Factories/StructureFactory.h"
2026-03-18 10:17:58 -04:00
#include "WingPackageMaker.h"
2026-03-12 00:44:17 -04:00
#include "Struct_Create.generated.h"
2026-03-08 22:17:14 -04:00
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
USTRUCT()
struct FStructPropertyEntry
{
GENERATED_BODY()
UPROPERTY()
FString Name;
UPROPERTY()
FString Type;
};
2026-03-15 19:32:09 -04:00
UCLASS()
2026-03-18 10:17:58 -04:00
class UWing_Struct_Create : public UObject, public IWingHandler
2026-03-08 22:17:14 -04:00
{
GENERATED_BODY()
public:
2026-03-12 18:31:55 -04:00
UPROPERTY(meta=(Description="Full asset path for the new struct (e.g. '/Game/DataTypes/S_MyStruct')"))
FString AssetPath;
2026-03-08 22:17:14 -04:00
UPROPERTY(meta=(Optional, Description="Array of initial properties, each with 'name' and 'type' fields"))
2026-03-18 10:17:58 -04:00
FWingJsonArray Properties;
2026-03-08 22:17:14 -04:00
virtual FString GetDescription() const override
{
2026-03-10 07:17:42 -04:00
return TEXT("Create a new UserDefinedStruct asset with optional initial properties.");
2026-03-08 22:17:14 -04:00
}
virtual void Handle() override
2026-03-08 22:17:14 -04:00
{
2026-03-18 10:17:58 -04:00
WingPackageMaker Maker(AssetPath);
2026-03-12 18:31:55 -04:00
if (!Maker.Ok()) return;
2026-03-10 07:17:42 -04:00
// Create the struct using the AssetTools factory.
2026-03-12 18:31:55 -04:00
UUserDefinedStruct* NewStruct = Maker.CreateAsset<UUserDefinedStruct, UStructureFactory>();
if (!NewStruct) return;
2026-03-10 07:17:42 -04:00
// Add properties if specified.
int32 PropsAdded = 0;
for (const TSharedPtr<FJsonValue>& PropVal : Properties.Array)
{
FStructPropertyEntry Entry;
2026-03-18 10:17:58 -04:00
if (!WingJson::PopulateFromJson(FStructPropertyEntry::StaticStruct(), &Entry, PropVal)) return;
2026-03-10 07:17:42 -04:00
if (Entry.Name.IsEmpty() || Entry.Type.IsEmpty()) continue;
FEdGraphPinType PinType;
2026-03-18 10:17:58 -04:00
if (!UWingTypes::TextToType(Entry.Type, PinType))
2026-03-10 07:17:42 -04:00
continue;
// Snapshot existing GUIDs so we can find the newly added one.
TSet<FGuid> ExistingGuids;
for (const FStructVariableDescription& Var : FStructureEditorUtils::GetVarDesc(NewStruct))
ExistingGuids.Add(Var.VarGuid);
if (!FStructureEditorUtils::AddVariable(NewStruct, PinType))
continue;
// Find the new variable by diffing GUID sets.
for (const FStructVariableDescription& Var : FStructureEditorUtils::GetVarDesc(NewStruct))
{
if (!ExistingGuids.Contains(Var.VarGuid))
{
FStructureEditorUtils::RenameVariable(NewStruct, Var.VarGuid, Entry.Name);
break;
}
}
PropsAdded++;
}
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Created %s\n"), *NewStruct->GetPathName());
2026-03-10 07:17:42 -04:00
if (PropsAdded > 0)
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Properties added: %d\n"), PropsAdded);
2026-03-08 22:17:14 -04:00
}
};