mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Profile editor - Finished most of the refactor except databindings
This commit is contained in:
1 parent
7fff1a593f
commit
fea454ad12
56 files changed
+866
-459
No files matched your search
+13
-1
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -36,12 +37,23 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void ApplyValue(float value)
|
||||
{
|
||||
if (SetExpression == null)
|
||||
return;
|
||||
|
||||
if (DataBinding.LayerProperty.PropertyDescription.MaxInputValue is float max)
|
||||
value = Math.Min(value, max);
|
||||
if (DataBinding.LayerProperty.PropertyDescription.MinInputValue is float min)
|
||||
value = Math.Max(value, min);
|
||||
|
||||
SetExpression?.Invoke(value);
|
||||
var test = new SKSize(5,5);
|
||||
test.Width = 10;
|
||||
|
||||
SetExpression(DataBinding.LayerProperty.CurrentValue, value);
|
||||
}
|
||||
|
||||
private void Mehtest(ref SKSize test)
|
||||
{
|
||||
test.Width = 20;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void ApplyValue(object value)
|
||||
{
|
||||
SetExpression?.Invoke(value);
|
||||
SetExpression?.Invoke(DataBinding.LayerProperty.CurrentValue, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void ApplyValue(int value)
|
||||
{
|
||||
SetExpression?.Invoke(value);
|
||||
SetExpression?.Invoke(DataBinding.LayerProperty.CurrentValue, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||
|
||||
@@ -14,9 +13,9 @@ namespace Artemis.Core
|
||||
private readonly List<DataBindingModifier<TLayerProperty, TProperty>> _modifiers = new List<DataBindingModifier<TLayerProperty, TProperty>>();
|
||||
|
||||
private TProperty _currentValue;
|
||||
private bool _disposed;
|
||||
private TimeSpan _easingProgress;
|
||||
private TProperty _previousValue;
|
||||
private bool _disposed;
|
||||
|
||||
internal DataBinding(DataBindingRegistration<TLayerProperty, TProperty> dataBindingRegistration)
|
||||
{
|
||||
@@ -53,11 +52,6 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public DataBindingConverter<TLayerProperty, TProperty> Converter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property on the <see cref="LayerProperty" /> this data binding targets
|
||||
/// </summary>
|
||||
public PropertyInfo TargetProperty { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently used instance of the data model that contains the source of the data binding
|
||||
/// </summary>
|
||||
@@ -118,8 +112,21 @@ namespace Artemis.Core
|
||||
if (Converter == null)
|
||||
return;
|
||||
|
||||
var value = GetValue(Converter.GetValue());
|
||||
Converter.ApplyValue(GetValue(value));
|
||||
var converterValue = Converter.GetValue();
|
||||
var value = GetValue(converterValue);
|
||||
Converter.ApplyValue(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
dataBindingModifier.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -218,7 +225,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public Type GetTargetType()
|
||||
{
|
||||
return TargetProperty.PropertyType;
|
||||
return Registration.PropertyExpression.ReturnType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -257,7 +264,6 @@ namespace Artemis.Core
|
||||
|
||||
Converter = dataBindingRegistration?.Converter;
|
||||
Registration = dataBindingRegistration;
|
||||
TargetProperty = dataBindingRegistration?.Property;
|
||||
|
||||
if (GetTargetType().IsValueType)
|
||||
{
|
||||
@@ -305,7 +311,7 @@ namespace Artemis.Core
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DataBinding");
|
||||
// General
|
||||
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetProperty);
|
||||
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetExpression);
|
||||
ApplyRegistration(registration);
|
||||
|
||||
Mode = (DataBindingMode) Entity.DataBindingMode;
|
||||
@@ -329,7 +335,7 @@ namespace Artemis.Core
|
||||
LayerProperty.Entity.DataBindingEntities.Add(Entity);
|
||||
|
||||
// General
|
||||
Entity.TargetProperty = TargetProperty?.Name;
|
||||
Entity.TargetExpression = Registration.PropertyExpression.ToString();
|
||||
Entity.DataBindingMode = (int) Mode;
|
||||
Entity.EasingTime = EasingTime;
|
||||
Entity.EasingFunction = (int) EasingFunction;
|
||||
@@ -340,7 +346,7 @@ namespace Artemis.Core
|
||||
Entity.SourceDataModelGuid = SourceDataModel.PluginInfo.Guid;
|
||||
Entity.SourcePropertyPath = SourcePropertyPath;
|
||||
}
|
||||
|
||||
|
||||
// Modifiers
|
||||
Entity.Modifiers.Clear();
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
@@ -381,18 +387,6 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
dataBindingModifier.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -18,7 +19,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// A dynamically compiled setter pointing to the data bound property
|
||||
/// </summary>
|
||||
public Action<TProperty> SetExpression { get; private set; }
|
||||
public Action<TLayerProperty, TProperty> SetExpression { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data binding this converter is applied to
|
||||
@@ -81,19 +82,34 @@ namespace Artemis.Core
|
||||
OnInitialized();
|
||||
}
|
||||
|
||||
private Action<TProperty> CreateValueSetter()
|
||||
private Action<TLayerProperty, TProperty> CreateValueSetter()
|
||||
{
|
||||
if (DataBinding.TargetProperty?.DeclaringType == null)
|
||||
return null;
|
||||
MethodInfo setterMethod = null;
|
||||
|
||||
if (DataBinding.Registration.Member != null)
|
||||
{
|
||||
if (DataBinding.Registration.Member is PropertyInfo propertyInfo)
|
||||
setterMethod = propertyInfo.GetSetMethod();
|
||||
}
|
||||
|
||||
var setterMethod = DataBinding.TargetProperty.GetSetMethod();
|
||||
if (setterMethod == null)
|
||||
return null;
|
||||
|
||||
var parameter = Expression.Parameter(typeof(TLayerProperty), "currentValue");
|
||||
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
|
||||
|
||||
var body = DataBinding.Registration.PropertyExpression;
|
||||
var lambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
|
||||
|
||||
var memberAccess = Expression.MakeMemberAccess(parameter, DataBinding.Registration.Member);
|
||||
var assignment = Expression.Assign(memberAccess, propertyValue);
|
||||
var lambda = Expression.Lambda<Action<TLayerProperty, TProperty>>(assignment, parameter, propertyValue);
|
||||
|
||||
if (typeof(TLayerProperty).IsValueType)
|
||||
{
|
||||
// var layerProperty = Expression.Constant(DataBinding.LayerProperty);
|
||||
// var layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty, DataBinding.LayerProperty.GetType().GetMember(nameof(DataBinding.LayerProperty.CurrentValue))[0]);
|
||||
// var assingment = Expression.Assign()
|
||||
}
|
||||
|
||||
return lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace Artemis.Core
|
||||
return;
|
||||
}
|
||||
|
||||
var targetType = DataBinding.TargetProperty.PropertyType;
|
||||
var targetType = DataBinding.GetTargetType();
|
||||
if (!modifierType.SupportsType(targetType))
|
||||
{
|
||||
throw new ArtemisCoreException($"Cannot apply modifier type {modifierType.GetType().Name} to this modifier because " +
|
||||
@@ -227,7 +227,7 @@ namespace Artemis.Core
|
||||
ParameterDataModel = null;
|
||||
ParameterPropertyPath = null;
|
||||
|
||||
var targetType = DataBinding.TargetProperty.PropertyType;
|
||||
var targetType = DataBinding.GetTargetType();
|
||||
|
||||
// If not null ensure the types match and if not, convert it
|
||||
if (staticValue != null && staticValue.GetType() == targetType)
|
||||
@@ -269,7 +269,7 @@ namespace Artemis.Core
|
||||
else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null && ParameterStaticValue == null)
|
||||
{
|
||||
// Use the target type so JSON.NET has a better idea what to do
|
||||
var targetType = DataBinding.TargetProperty.PropertyType;
|
||||
var targetType = DataBinding.GetTargetType();
|
||||
object staticValue;
|
||||
|
||||
try
|
||||
|
||||
@@ -8,13 +8,16 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public class DataBindingRegistration<TLayerProperty, TProperty> : IDataBindingRegistration
|
||||
{
|
||||
internal DataBindingRegistration(LayerProperty<TLayerProperty> layerProperty,
|
||||
DataBindingConverter<TLayerProperty, TProperty> converter,
|
||||
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));
|
||||
PropertyExpression = propertyExpression ?? throw new ArgumentNullException(nameof(propertyExpression));
|
||||
|
||||
if (propertyExpression.Body is MemberExpression memberExpression)
|
||||
Member = memberExpression.Member;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -28,15 +31,16 @@ namespace Artemis.Core
|
||||
public DataBindingConverter<TLayerProperty, TProperty> Converter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the expression that that accesses the property
|
||||
/// Gets the expression that that accesses the property
|
||||
/// </summary>
|
||||
public Expression<Func<TLayerProperty, TProperty>> PropertyExpression { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the registered property
|
||||
/// Gets the member the <see cref="PropertyExpression" /> targets
|
||||
/// <para><c>null</c> if the <see cref="PropertyExpression" /> is not a member expression</para>
|
||||
/// </summary>
|
||||
public PropertyInfo Property { get; }
|
||||
|
||||
public MemberInfo Member { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data binding created using this registration
|
||||
/// </summary>
|
||||
@@ -48,7 +52,7 @@ namespace Artemis.Core
|
||||
if (DataBinding != null)
|
||||
return DataBinding;
|
||||
|
||||
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetProperty == PropertyExpression.ToString());
|
||||
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetExpression == PropertyExpression.ToString());
|
||||
if (dataBinding == null)
|
||||
return null;
|
||||
|
||||
|
||||
Reference in new issue
Block a user