Migrating back to WingProperty. Sigh.
This commit is contained in:
@@ -62,15 +62,25 @@ void FWingProperty::PrintExpectsReceived(const TCHAR *Type)
|
||||
*WingUtils::FormatName(Prop), Type, *Prop->GetCPPType());
|
||||
}
|
||||
|
||||
|
||||
bool FWingProperty::CheckImportTextResult(const FString &Value)
|
||||
{
|
||||
uint8 *VP = Prop->ContainerPtrToValuePtr<uint8>(Container);
|
||||
if (FObjectPropertyBase *OProp = CastField<FObjectPropertyBase>(Prop))
|
||||
{
|
||||
UObject *Obj = OProp->GetObjectPropertyValue(VP);
|
||||
if (Obj == nullptr && Value.TrimStartAndEnd().Compare(TEXT("None"), ESearchCase::IgnoreCase) != 0)
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: Failed to parse '%s' for property '%s'\n"),
|
||||
*Value, *WingUtils::FormatName(Prop));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FWingProperty::SetText(FString Value)
|
||||
{
|
||||
// Mostly, this is implemented by Unreal's ImportText_Incontainer.
|
||||
// We override it for a few very specific types.
|
||||
|
||||
// Notify that we're modifying the containing object.
|
||||
if (Prop->GetOwnerClass())
|
||||
UWingServer::AddTouchedObject(static_cast<UObject*>(Container));
|
||||
|
||||
// Pin types get parsed by UWingTypes.
|
||||
if (IsPinTypeProperty(Prop))
|
||||
{
|
||||
@@ -111,20 +121,101 @@ bool FWingProperty::SetText(FString Value)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FWingProperty::CheckImportTextResult(const FString &Value)
|
||||
bool FWingProperty::SetDouble(double D)
|
||||
{
|
||||
uint8 *VP = Prop->ContainerPtrToValuePtr<uint8>(Container);
|
||||
if (FObjectPropertyBase *OProp = CastField<FObjectPropertyBase>(Prop))
|
||||
FNumericProperty *NProp = CastField<FNumericProperty>(Prop);
|
||||
if (!NProp)
|
||||
{
|
||||
UObject *Obj = OProp->GetObjectPropertyValue(VP);
|
||||
if (Obj == nullptr && Value.TrimStartAndEnd().Compare(TEXT("None"), ESearchCase::IgnoreCase) != 0)
|
||||
PrintExpectsReceived(TEXT("double"));
|
||||
return false;
|
||||
}
|
||||
if (NProp->IsFloatingPoint())
|
||||
{
|
||||
uint8 buffer[16];
|
||||
NProp->SetFloatingPointPropertyValue(buffer, D);
|
||||
if (!FMath::IsFinite(NProp->GetFloatingPointPropertyValue(buffer)))
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: Failed to parse '%s' for property '%s'\n"),
|
||||
*Value, *WingUtils::FormatName(Prop));
|
||||
UWingServer::Printf(TEXT("ERROR: Property '%s' of type %s cannot hold %lf\n"),
|
||||
*WingUtils::FormatName(Prop), *Prop->GetCPPType(), D);
|
||||
return false;
|
||||
}
|
||||
Prop->SetValue_InContainer(Container, buffer);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
else
|
||||
{
|
||||
uint8 buffer[16];
|
||||
if (FMath::Floor(D) != D)
|
||||
{
|
||||
PrintExpectsReceived(TEXT("double"));
|
||||
return false;
|
||||
}
|
||||
if (FMath::Abs(D) > (double)((1LL)<<53))
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: To store very large numbers in '%s', do not pass them as double. Use string or int.\n"),
|
||||
*WingUtils::FormatName(Prop));
|
||||
return false;
|
||||
}
|
||||
int64 I = (int64)D;
|
||||
NProp->SetIntPropertyValue(buffer, I);
|
||||
if (NProp->GetSignedIntPropertyValue(buffer) != I)
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: Property '%s' of type %s cannot hold %lld\n"),
|
||||
*WingUtils::FormatName(Prop), *Prop->GetCPPType(), I);
|
||||
return false;
|
||||
}
|
||||
NProp->SetValue_InContainer(Container, buffer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool FWingProperty::SetInt64(int64 I)
|
||||
{
|
||||
FNumericProperty *NProp = CastField<FNumericProperty>(Prop);
|
||||
if (!NProp)
|
||||
{
|
||||
PrintExpectsReceived(TEXT("int"));
|
||||
return false;
|
||||
}
|
||||
if (NProp->IsFloatingPoint())
|
||||
{
|
||||
uint8 buffer[16];
|
||||
double D = I;
|
||||
NProp->SetFloatingPointPropertyValue(buffer, D);
|
||||
int64 RT = (int64)NProp->GetFloatingPointPropertyValue(buffer);
|
||||
if (RT != I)
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: Property '%s' of type %s cannot hold %lld\n"),
|
||||
*WingUtils::FormatName(Prop), *Prop->GetCPPType(), I);
|
||||
return false;
|
||||
}
|
||||
Prop->SetValue_InContainer(Container, buffer);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8 buffer[16];
|
||||
NProp->SetIntPropertyValue(buffer, I);
|
||||
if (NProp->GetSignedIntPropertyValue(buffer) != I)
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: Property '%s' of type %s cannot hold %lld\n"),
|
||||
*WingUtils::FormatName(Prop), *Prop->GetCPPType(), I);
|
||||
return false;
|
||||
}
|
||||
NProp->SetValue_InContainer(Container, buffer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool FWingProperty::SetBool(bool B)
|
||||
{
|
||||
if (FBoolProperty* BoolProp = CastField<FBoolProperty>(Prop))
|
||||
{
|
||||
Prop->SetValue_InContainer(Container, &B);
|
||||
return true;
|
||||
}
|
||||
PrintExpectsReceived(TEXT("boolean"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,65 +228,12 @@ bool FWingProperty::SetJson(const TSharedPtr<FJsonValue> &JsonValue)
|
||||
|
||||
if (JsonValue->Type == EJson::Number)
|
||||
{
|
||||
// If the property is float or double, just store the value.
|
||||
double D = JsonValue->AsNumber();
|
||||
if (FFloatProperty* FloatProp = CastField<FFloatProperty>(Prop))
|
||||
{
|
||||
float Value = (float)D;
|
||||
Prop->SetValue_InContainer(Container, &Value);
|
||||
return true;
|
||||
}
|
||||
else if (FDoubleProperty* DoubleProp = CastField<FDoubleProperty>(Prop))
|
||||
{
|
||||
double Value = (double)D;
|
||||
Prop->SetValue_InContainer(Container, &Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
// At this point, we've ruled out it being a float or double property.
|
||||
// All that's left is integers. Verify that the number can be converted
|
||||
// losslessly to an int64, and then do so.
|
||||
if (FMath::Floor(D) != D)
|
||||
{
|
||||
PrintExpectsReceived(TEXT("float"));
|
||||
return false;
|
||||
}
|
||||
if (FMath::Abs(D) > (double)((1LL)<<53))
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: To store very large numbers in '%s', please pass a json string\n"),
|
||||
*WingUtils::FormatName(Prop));
|
||||
return false;
|
||||
}
|
||||
int64 I = (int64)D;
|
||||
|
||||
// Now store the integer. Make sure it fits first.
|
||||
if (FNumericProperty *NumericProperty = CastField<FNumericProperty>(Prop))
|
||||
{
|
||||
uint8 buffer[16];
|
||||
NumericProperty->SetIntPropertyValue(buffer, I);
|
||||
if (NumericProperty->GetSignedIntPropertyValue(buffer) != I)
|
||||
{
|
||||
UWingServer::Printf(TEXT("ERROR: Property '%s' of type %s is too small to hold %lld\n"),
|
||||
*WingUtils::FormatName(Prop), *Prop->GetCPPType(), I);
|
||||
return false;
|
||||
}
|
||||
NumericProperty->SetValue_InContainer(Container, buffer);
|
||||
return true;
|
||||
}
|
||||
PrintExpectsReceived(TEXT("integer"));
|
||||
return false;
|
||||
return SetDouble(JsonValue->AsNumber());
|
||||
}
|
||||
|
||||
if (JsonValue->Type == EJson::Boolean)
|
||||
{
|
||||
if (FBoolProperty* BoolProp = CastField<FBoolProperty>(Prop))
|
||||
{
|
||||
bool Value = JsonValue->AsBool();
|
||||
Prop->SetValue_InContainer(Container, &Value);
|
||||
return true;
|
||||
}
|
||||
PrintExpectsReceived(TEXT("boolean"));
|
||||
return false;
|
||||
return SetBool(JsonValue->AsBool());
|
||||
}
|
||||
|
||||
if (JsonValue->Type == EJson::Object)
|
||||
|
||||
Reference in New Issue
Block a user