Enum handling is now centralized

This commit is contained in:
2026-03-19 11:19:31 -04:00
parent 23c096b614
commit a9258f3a86
4 changed files with 26 additions and 47 deletions

View File

@@ -267,22 +267,27 @@ FString WingUtils::WrapText(const FString& Text, int32 ColLimit, const FString&
// Enum helpers
// ============================================================
FString WingUtils::EnumToString(UEnum* Enum, int64 Value, const FString& Prefix)
FString WingUtils::EnumToString(UEnum* Enum, int64 Value)
{
FString Full = Enum->GetNameStringByValue(Value);
if (!Prefix.IsEmpty() && Full.StartsWith(Prefix))
return Full.Mid(Prefix.Len());
return Full;
return Enum->GetNameStringByValue(Value);
}
bool WingUtils::StringToEnum(UEnum* Enum, const FString& Str, int64& OutValue, const FString& Prefix)
bool WingUtils::StringToEnum(UEnum* Enum, const FString& Str, int64& OutValue)
{
OutValue = Enum->GetValueByNameString(Prefix + Str);
if (OutValue == INDEX_NONE)
int32 Index = Enum->GetIndexByNameString(Str);
if (Index == INDEX_NONE)
{
UWingServer::Printf(TEXT("ERROR: Invalid value '%s' for %s\n"), *Str, *Enum->GetName());
FString Prefix = Enum->GenerateEnumPrefix();
if (!Prefix.IsEmpty())
Index = Enum->GetIndexByNameString(Prefix + TEXT("_") + Str);
}
if (Index == INDEX_NONE)
{
UWingServer::Printf(TEXT("ERROR: '%s' is not a valid value for %s\n"), *Str, *Enum->GetName());
OutValue = 0;
return false;
}
OutValue = Enum->GetValueByIndex(Index);
return true;
}