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

68 lines
2.0 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 "WingUtils.h"
2026-03-08 22:17:14 -04:00
#include "Engine/UserDefinedEnum.h"
#include "Kismet2/EnumEditorUtils.h"
#include "Factories/EnumFactory.h"
2026-03-18 10:17:58 -04:00
#include "WingPackageMaker.h"
2026-03-12 00:44:17 -04:00
#include "Enum_Create.generated.h"
2026-03-08 22:17:14 -04:00
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
2026-03-15 19:32:09 -04:00
UCLASS()
2026-03-18 10:17:58 -04:00
class UWing_Enum_Create : public UObject, public IWingHandler
2026-03-08 22:17:14 -04:00
{
GENERATED_BODY()
public:
UPROPERTY(meta=(Description="Full package path for the new enum (e.g. '/Game/DataTypes/E_MyEnum')"))
FString AssetPath;
UPROPERTY(meta=(Description="Array of enum value names"))
2026-03-18 10:17:58 -04:00
FWingJsonArray Values;
2026-03-08 22:17:14 -04:00
virtual FString GetDescription() const override
{
return TEXT("Create a new UserDefinedEnum asset with the specified values.");
}
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
TArray<FString> EnumValues;
for (const TSharedPtr<FJsonValue>& Val : Values.Array)
{
FString Str = Val->AsString();
if (!Str.IsEmpty()) EnumValues.Add(Str);
}
if (EnumValues.Num() == 0)
{
2026-03-18 10:17:58 -04:00
UWingServer::Print(TEXT("ERROR: Values must be a non-empty array of strings\n"));
2026-03-13 14:26:04 -04:00
return;
2026-03-10 07:17:42 -04:00
}
// Create the enum using AssetTools.
2026-03-12 18:31:55 -04:00
UUserDefinedEnum* NewEnum = Maker.CreateAsset<UUserDefinedEnum, UEnumFactory>();
if (!NewEnum) return;
2026-03-10 07:17:42 -04:00
// Add enum values — UUserDefinedEnum starts with a MAX value.
// We need to add entries before MAX.
for (int32 i = 0; i < EnumValues.Num(); ++i)
{
FEnumEditorUtils::AddNewEnumeratorForUserDefinedEnum(NewEnum);
int32 NewIndex = NewEnum->NumEnums() - 2;
FEnumEditorUtils::SetEnumeratorDisplayName(NewEnum, NewIndex, FText::FromString(EnumValues[i]));
}
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Created %s with %d values\n"), *NewEnum->GetPathName(), EnumValues.Num());
2026-03-08 22:17:14 -04:00
}
};