Enum handling is now centralized
This commit is contained in:
@@ -29,31 +29,6 @@ FString FWingProperty::GetText() const
|
||||
return Result;
|
||||
}
|
||||
|
||||
bool FWingProperty::TryParseEnum(UEnum* Enum, const FString& Text, int64 &OutValue)
|
||||
{
|
||||
int Index = Enum->GetIndexByNameString(Text);
|
||||
if (Index == INDEX_NONE)
|
||||
{
|
||||
FString Prefix = Enum->GenerateEnumPrefix();
|
||||
if (!Prefix.IsEmpty())
|
||||
{
|
||||
Index = Enum->GetIndexByNameString(Prefix + TEXT("_") + Text);
|
||||
}
|
||||
}
|
||||
if (Index == INDEX_NONE)
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: '%s' is not a valid value for %s\n"),
|
||||
*Text, *Enum->GetName());
|
||||
OutValue = 0;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
OutValue = Enum->GetValueByIndex(Index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool FWingProperty::SetText(const FString &Value)
|
||||
{
|
||||
void* ValuePtr = Prop->ContainerPtrToValuePtr<void>(Container);
|
||||
@@ -66,23 +41,23 @@ bool FWingProperty::SetText(const FString &Value)
|
||||
if (IsPinTypeProperty(Prop))
|
||||
return UWingTypes::TextToType(Value, *static_cast<FEdGraphPinType*>(ValuePtr));
|
||||
|
||||
// Byte Enum types get parsed by TryParseEnum, above.
|
||||
// Byte Enum types.
|
||||
if (FByteProperty* ByteProp = CastField<FByteProperty>(Prop))
|
||||
{
|
||||
if (UEnum* Enum = ByteProp->Enum)
|
||||
{
|
||||
int64 EnumValue;
|
||||
if (!TryParseEnum(Enum, Value, EnumValue)) return false;
|
||||
if (!WingUtils::StringToEnum(Enum, Value, EnumValue)) return false;
|
||||
ByteProp->SetPropertyValue(ValuePtr, (uint8)EnumValue);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Regular Enum types get parsed by TryParseEnum, above.
|
||||
// Regular Enum types.
|
||||
if (FEnumProperty* EnumProp = CastField<FEnumProperty>(Prop))
|
||||
{
|
||||
int64 EnumValue;
|
||||
if (!TryParseEnum(EnumProp->GetEnum(), Value, EnumValue)) return false;
|
||||
if (!WingUtils::StringToEnum(EnumProp->GetEnum(), Value, EnumValue)) return false;
|
||||
EnumProp->GetUnderlyingProperty()->SetIntPropertyValue(ValuePtr, EnumValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user