Profile editor - Many runtime fixes, UI is back to usable!

This commit is contained in:
SpoinkyNL committed 2020-09-12 23:11:08 +02:00
1 parent db9d9fb4e6
commit 7fff1a593f
38 files changed
+309 -352

No files matched your search

@@ -41,13 +41,13 @@ namespace Artemis.Core
if (DataBinding.LayerProperty.PropertyDescription.MinInputValue is float min)
value = Math.Max(value, min);
ValueSetter?.Invoke(value);
SetExpression?.Invoke(value);
}
/// <inheritdoc />
public override float GetValue()
{
return ValueGetter?.Invoke() ?? 0f;
return GetExpression(DataBinding.LayerProperty.CurrentValue);
}
}
}
@@ -26,13 +26,13 @@ namespace Artemis.Core
/// <inheritdoc />
public override void ApplyValue(object value)
{
ValueSetter?.Invoke(value);
SetExpression?.Invoke(value);
}
/// <inheritdoc />
public override object GetValue()
{
return ValueGetter?.Invoke();
return GetExpression(DataBinding.LayerProperty.CurrentValue);
}
}
}
@@ -3,12 +3,12 @@
namespace Artemis.Core
{
/// <inheritdoc />
public class IntDataBindingConverter : FloatDataBindingConverter<int>
public class IntDataBindingConverter : IntDataBindingConverter<int>
{
}
/// <inheritdoc />
public class IntDataBindingConverter<T> : DataBindingConverter<T, int> where T : ILayerProperty
public class IntDataBindingConverter<T> : DataBindingConverter<T, int>
{
/// <summary>
/// Creates a new instance of the <see cref="IntDataBindingConverter{T}" /> class
@@ -41,13 +41,13 @@ namespace Artemis.Core
/// <inheritdoc />
public override void ApplyValue(int value)
{
ValueSetter?.Invoke(value);
SetExpression?.Invoke(value);
}
/// <inheritdoc />
public override int GetValue()
{
return ValueGetter?.Invoke() ?? 0;
return GetExpression(DataBinding.LayerProperty.CurrentValue);
}
}
}
@@ -13,12 +13,12 @@ namespace Artemis.Core
/// <summary>
/// A dynamically compiled getter pointing to the data bound property
/// </summary>
public Func<TProperty> ValueGetter { get; private set; }
public Func<TLayerProperty, TProperty> GetExpression { get; private set; }
/// <summary>
/// A dynamically compiled setter pointing to the data bound property
/// </summary>
public Action<TProperty> ValueSetter { get; private set; }
public Action<TProperty> SetExpression { get; private set; }
/// <summary>
/// Gets the data binding this converter is applied to
@@ -75,32 +75,12 @@ namespace Artemis.Core
internal void Initialize(DataBinding<TLayerProperty, TProperty> dataBinding)
{
DataBinding = dataBinding;
ValueGetter = CreateValueGetter();
ValueSetter = CreateValueSetter();
GetExpression = dataBinding.Registration.PropertyExpression.Compile();
SetExpression = CreateValueSetter();
OnInitialized();
}
private Func<TProperty> CreateValueGetter()
{
if (DataBinding.TargetProperty?.DeclaringType == null)
return null;
var getterMethod = DataBinding.TargetProperty.GetGetMethod();
if (getterMethod == null)
return null;
var constant = Expression.Constant(DataBinding.LayerProperty);
// The path is null if the registration is applied to the root (LayerProperty.CurrentValue)
var property = DataBinding.Registration.Path == null
? Expression.Property(constant, DataBinding.TargetProperty)
: (MemberExpression) DataBinding.Registration.Path.Split('.').Aggregate<string, Expression>(constant, Expression.Property);
var lambda = Expression.Lambda<Func<TProperty>>(property);
return lambda.Compile();
}
private Action<TProperty> CreateValueSetter()
{
if (DataBinding.TargetProperty?.DeclaringType == null)
@@ -110,10 +90,9 @@ namespace Artemis.Core
if (setterMethod == null)
return null;
var constant = Expression.Constant(DataBinding.LayerProperty);
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
var body = Expression.Call(constant, setterMethod, propertyValue);
var body = DataBinding.Registration.PropertyExpression;
var lambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
return lambda.Compile();
}
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Artemis.Core
@@ -7,16 +8,13 @@ namespace Artemis.Core
/// <inheritdoc />
public class DataBindingRegistration<TLayerProperty, TProperty> : IDataBindingRegistration
{
internal DataBindingRegistration(
LayerProperty<TLayerProperty> layerProperty,
DataBindingConverter<TLayerProperty, TProperty> converter,
PropertyInfo property,
string path)
internal DataBindingRegistration(LayerProperty<TLayerProperty> layerProperty,
DataBindingConverter<TLayerProperty, TProperty> converter,
Expression<Func<TLayerProperty, TProperty>> propertyExpression)
{
LayerProperty = layerProperty ?? throw new ArgumentNullException(nameof(layerProperty));
Converter = converter ?? throw new ArgumentNullException(nameof(converter));
Property = property ?? throw new ArgumentNullException(nameof(property));
Path = path ?? throw new ArgumentNullException(nameof(path));
PropertyExpression = propertyExpression ?? throw new ArgumentNullException(nameof(propertyExpression));
}
/// <summary>
@@ -24,22 +22,21 @@ namespace Artemis.Core
/// </summary>
public LayerProperty<TLayerProperty> LayerProperty { get; }
/// <summary>
/// Gets the converter that's used by the data binding
/// </summary>
public DataBindingConverter<TLayerProperty, TProperty> Converter { get; }
/// <summary>
/// Gets the expression that that accesses the property
/// </summary>
public Expression<Func<TLayerProperty, TProperty>> PropertyExpression { get; }
/// <summary>
/// Gets the registered property
/// </summary>
public PropertyInfo Property { get; }
/// <summary>
/// Gets the path of the registered property on the layer property
/// </summary>
public string Path { get; }
/// <summary>
/// Gets the data binding created using this registration
/// </summary>
@@ -51,7 +48,7 @@ namespace Artemis.Core
if (DataBinding != null)
return DataBinding;
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetProperty == Path);
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetProperty == PropertyExpression.ToString());
if (dataBinding == null)
return null;