static void SetPropertyValue( UObject *Target, const FString &PropertyName, const FString &PropertyValue )
	{

		if ( Target == NULL )
			return;

		void *ContainerPtr = Target;
		int32 ArrayIndex;
		UProperty *Prop = nLiveEditorListenServer::GetPropertyByName( Target, Target->GetClass(), PropertyName, &ContainerPtr, ArrayIndex );
		if ( !Prop || !Prop->IsA( UNumericProperty::StaticClass() ) )
		{
			return;
		}

		check( ContainerPtr != NULL );

		if ( Prop->IsA( UByteProperty::StaticClass() ) )
		{
			UByteProperty *NumericProp = CastChecked<UByteProperty>(Prop);
			uint8 Value = FCString::Atoi( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
		else if ( Prop->IsA( UInt8Property::StaticClass() ) )
		{
			UInt8Property *NumericProp = CastChecked<UInt8Property>(Prop);
			int32 Value = FCString::Atoi( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
		else if ( Prop->IsA( UInt16Property::StaticClass() ) )
		{
			UInt16Property *NumericProp = CastChecked<UInt16Property>(Prop);
			int16 Value = FCString::Atoi( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
		else if ( Prop->IsA( UIntProperty::StaticClass() ) )
		{
			UIntProperty *NumericProp = CastChecked<UIntProperty>(Prop);
			int32 Value = FCString::Atoi( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
		else if ( Prop->IsA( UInt64Property::StaticClass() ) )
		{
			UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop);
			int64 Value = FCString::Atoi64( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
		else if ( Prop->IsA( UUInt16Property::StaticClass() ) )
		{
			UUInt16Property *NumericProp = CastChecked<UUInt16Property>(Prop);
			uint16 Value = FCString::Atoi( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
		else if ( Prop->IsA( UUInt32Property::StaticClass() ) )
		{
			UUInt32Property *NumericProp = CastChecked<UUInt32Property>(Prop);
			uint32 Value = FCString::Atoi( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
		else if ( Prop->IsA( UInt64Property::StaticClass() ) )
		{
			UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop);
			uint64 Value = FCString::Atoi64( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
		else if ( Prop->IsA( UFloatProperty::StaticClass() ) )
		{
			UFloatProperty *NumericProp = CastChecked<UFloatProperty>(Prop);
			float Value = FCString::Atof( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
		else if ( Prop->IsA( UDoubleProperty::StaticClass() ) )
		{
			UDoubleProperty *NumericProp = CastChecked<UDoubleProperty>(Prop);
			double Value = FCString::Atod( *PropertyValue );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex);
		}
	}
	static void ModifyPropertyValue( UObject *Target, const FString &PropertyName, TEnumAsByte<ELiveEditControllerType::Type> ControlType, float Delta, int32 MidiValue, bool bShouldClamp, float ClampMin, float ClampMax )
	{
		if ( Target == NULL )
			return;

		void *ContainerPtr = Target;
		int32 ArrayIndex = 0;
		UProperty *Prop = GetPropertyByName( Target, Target->GetClass(), PropertyName, &ContainerPtr, ArrayIndex );
		if ( Prop == NULL || !Prop->IsA( UNumericProperty::StaticClass() ) )
			return;

		check( ContainerPtr != NULL );

		if ( bShouldClamp && ControlType == ELiveEditControllerType::ControlChangeFixed )
		{
			//if we are clamped and it's a fixed range controller, make sure that the Delta can cover the full span of the clamped range
			//this overrides DeltaMult on the LiveEditObject Action in the case where DeltaMult is too small to cover the clamped range
			//with the meager fidelity of Midi (127 ticks per controller)
			float EvenDelta = (ClampMax - ClampMin)/127.0f;
			if ( EvenDelta > FMath::Abs(Delta) )
			{
				float sign = (Delta > 0.0f)? 1.0f : -1.0f;
				Delta = EvenDelta * sign;
			}
		}

		if ( Prop->IsA( UByteProperty::StaticClass() ) )
		{
			UByteProperty *NumericProp = CastChecked<UByteProperty>(Prop);
			uint8 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			uint8 NewValue = CalculateNewValue<uint8>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
		else if ( Prop->IsA( UInt8Property::StaticClass() ) )
		{
			UInt8Property *NumericProp = CastChecked<UInt8Property>(Prop);
			uint8 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			uint8 NewValue = CalculateNewValue<uint8>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
		else if ( Prop->IsA( UInt16Property::StaticClass() ) )
		{
			UInt16Property *NumericProp = CastChecked<UInt16Property>(Prop);
			int16 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			int16 NewValue = CalculateNewValue<int16>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
		else if ( Prop->IsA( UIntProperty::StaticClass() ) )
		{
			UIntProperty *NumericProp = CastChecked<UIntProperty>(Prop);
			int32 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			int32 NewValue = CalculateNewValue<int32>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
		else if ( Prop->IsA( UInt64Property::StaticClass() ) )
		{
			UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop);
			int64 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			int64 NewValue = CalculateNewValue<int64>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
		else if ( Prop->IsA( UUInt16Property::StaticClass() ) )
		{
			UUInt16Property *NumericProp = CastChecked<UUInt16Property>(Prop);
			uint16 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			uint16 NewValue = CalculateNewValue<uint16>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
		else if ( Prop->IsA( UUInt32Property::StaticClass() ) )
		{
			UUInt32Property *NumericProp = CastChecked<UUInt32Property>(Prop);
			uint32 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			uint32 NewValue = CalculateNewValue<uint32>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
		else if ( Prop->IsA( UInt64Property::StaticClass() ) )
		{
			UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop);
			uint64 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			uint64 NewValue = CalculateNewValue<uint64>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
		else if ( Prop->IsA( UFloatProperty::StaticClass() ) )
		{
			UFloatProperty *NumericProp = CastChecked<UFloatProperty>(Prop);
			float CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			float NewValue = CalculateNewValue<float>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
		else if ( Prop->IsA( UDoubleProperty::StaticClass() ) )
		{
			UDoubleProperty *NumericProp = CastChecked<UDoubleProperty>(Prop);
			double CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex);
			double NewValue = CalculateNewValue<double>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax );
			NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex);
		}
	}
	static void CopyPropertyFromArchetype( UObject *Target, UObject *Archetype, FName PropertyName )
	{
		if ( Target == NULL || Archetype == NULL || !Target->IsA( Archetype->GetClass() ) )
			return;

		void *ArchetypeContainerPtr = Archetype;
		int32 ArchetypeArrayIndex;
		UProperty *Prop = GetPropertyByName( Archetype, Archetype->GetClass(), PropertyName.ToString(), &ArchetypeContainerPtr, ArchetypeArrayIndex );
		if ( !Prop || !Prop->IsA( UNumericProperty::StaticClass() ) )
			return;
		check(ArchetypeContainerPtr != NULL);

		void *TargetContainerPtr = Target; //(void*)((uint8*)ArchetypeContainerPtr - (uint8*)Archetype + (uint8*)Target);
		int32 TargetArrayIndex;
		UProperty *TargetProp = GetPropertyByName( Target, Target->GetClass(), PropertyName.ToString(), &TargetContainerPtr, TargetArrayIndex );
		check( TargetProp != NULL && TargetProp->IsA( UNumericProperty::StaticClass() ) );
		check( TargetArrayIndex == ArchetypeArrayIndex );

		if ( Prop->IsA( UByteProperty::StaticClass() ) )
		{
			UByteProperty *NumericProp = CastChecked<UByteProperty>(Prop);
			uint8 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
		else if ( Prop->IsA( UInt8Property::StaticClass() ) )
		{
			UInt8Property *NumericProp = CastChecked<UInt8Property>(Prop);
			int32 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
		else if ( Prop->IsA( UInt16Property::StaticClass() ) )
		{
			UInt16Property *NumericProp = CastChecked<UInt16Property>(Prop);
			int16 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
		else if ( Prop->IsA( UIntProperty::StaticClass() ) )
		{
			UIntProperty *NumericProp = CastChecked<UIntProperty>(Prop);
			int32 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
		else if ( Prop->IsA( UInt64Property::StaticClass() ) )
		{
			UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop);
			int64 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
		else if ( Prop->IsA( UUInt16Property::StaticClass() ) )
		{
			UUInt16Property *NumericProp = CastChecked<UUInt16Property>(Prop);
			uint16 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
		else if ( Prop->IsA( UUInt32Property::StaticClass() ) )
		{
			UUInt32Property *NumericProp = CastChecked<UUInt32Property>(Prop);
			uint32 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
		else if ( Prop->IsA( UInt64Property::StaticClass() ) )
		{
			UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop);
			uint64 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
		else if ( Prop->IsA( UFloatProperty::StaticClass() ) )
		{
			UFloatProperty *NumericProp = CastChecked<UFloatProperty>(Prop);
			float ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
		else if ( Prop->IsA( UDoubleProperty::StaticClass() ) )
		{
			UDoubleProperty *NumericProp = CastChecked<UDoubleProperty>(Prop);
			double ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex);
			NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex);
		}
	}
Beispiel #4
0
void USQLiteDatabase::AssignResultsToObjectProperties(const SQLiteResultValue& ResultValue, UObject* ObjectToPopulate)
{
	auto propertyMap = CollectProperties(ObjectToPopulate);
	for (SQLiteResultField field : ResultValue.Fields)
	{
		if (propertyMap.Contains(field.Name))
		{
			UProperty* targetProperty = propertyMap[field.Name];

			if (field.Type == SQLiteResultValueTypes::Integer)
			{
				UInt64Property* int64prop = NULL;
				UIntProperty* int32prop = NULL;
				UInt16Property* int16prop = NULL;
				UInt8Property* int8prop = NULL;
				UBoolProperty* boolProp = NULL;

				if ((int64prop = Cast<UInt64Property>(targetProperty)) != NULL)
				{
					int64prop->SetPropertyValue_InContainer(ObjectToPopulate, field.IntValue);
					LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue));
				}
				else if ((int32prop = Cast<UIntProperty>(targetProperty)) != NULL)
				{
					int32prop->SetPropertyValue_InContainer(ObjectToPopulate, (int32)field.IntValue);
					LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue));
				}
				else if ((int16prop = Cast<UInt16Property>(targetProperty)) != NULL)
				{
					int16prop->SetPropertyValue_InContainer(ObjectToPopulate, (int16)field.IntValue);
					LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue));
				}
				else if ((int8prop = Cast<UInt8Property>(targetProperty)) != NULL)
				{
					int8prop->SetPropertyValue_InContainer(ObjectToPopulate, (int8)field.IntValue);
					LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue));
				}
				else if ((boolProp = Cast<UBoolProperty>(targetProperty)) != NULL)
				{
					boolProp->SetPropertyValue_InContainer(ObjectToPopulate, field.IntValue > 0);
					LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue));
				}
			}

			else if (field.Type == SQLiteResultValueTypes::Float)
			{
				UDoubleProperty* doubleProp = NULL;
				UFloatProperty* floatProp = NULL;
				if ((doubleProp = Cast<UDoubleProperty>(targetProperty)) != NULL)
				{
					doubleProp->SetPropertyValue_InContainer(ObjectToPopulate, field.DoubleValue);
					LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%f'"), *field.Name, field.DoubleValue));
				}
				else if ((floatProp = Cast<UFloatProperty>(targetProperty)) != NULL)
				{
					floatProp->SetPropertyValue_InContainer(ObjectToPopulate, (float)field.DoubleValue);
					LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%f'"), *field.Name, field.DoubleValue));
				}
			}

			else if (field.Type == SQLiteResultValueTypes::Text)
			{
				UStrProperty* strProp = NULL;
				if ((strProp = Cast<UStrProperty>(targetProperty)) != NULL)
				{
					strProp->SetPropertyValue_InContainer(ObjectToPopulate, field.StringValue);
					LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%s'"), *field.Name, *field.StringValue.Mid(0, 64)));
				}
			}

		}
	}
}