mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Darthified code
This commit is contained in:
1 parent
5b80c1e4fe
commit
ae64db8a13
198 files changed
+1339
-1305
No files matched your search
@@ -93,8 +93,8 @@ namespace Artemis.Core
|
||||
if (Converter == null)
|
||||
return;
|
||||
|
||||
var converterValue = Converter.GetValue();
|
||||
var value = GetValue(converterValue);
|
||||
TProperty converterValue = Converter.GetValue();
|
||||
TProperty value = GetValue(converterValue);
|
||||
Converter.ApplyValue(value);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Artemis.Core
|
||||
if (Converter == null || DataBindingMode == null)
|
||||
return baseValue;
|
||||
|
||||
var value = DataBindingMode.GetValue(baseValue);
|
||||
TProperty value = DataBindingMode.GetValue(baseValue);
|
||||
|
||||
// If no easing is to be applied simple return whatever the current value is
|
||||
if (EasingTime == TimeSpan.Zero || !Converter.SupportsInterpolate)
|
||||
@@ -175,7 +175,7 @@ namespace Artemis.Core
|
||||
if (_easingProgress == EasingTime || !Converter.SupportsInterpolate)
|
||||
return _currentValue;
|
||||
|
||||
var easingAmount = _easingProgress.TotalSeconds / EasingTime.TotalSeconds;
|
||||
double easingAmount = _easingProgress.TotalSeconds / EasingTime.TotalSeconds;
|
||||
return Converter.Interpolate(_previousValue, _currentValue, Easings.Interpolate(easingAmount, EasingFunction));
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace Artemis.Core
|
||||
throw new ObjectDisposedException("DataBinding");
|
||||
|
||||
// General
|
||||
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetExpression);
|
||||
DataBindingRegistration<TLayerProperty, TProperty> registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetExpression);
|
||||
if (registration != null)
|
||||
ApplyRegistration(registration);
|
||||
|
||||
|
||||
@@ -130,43 +130,43 @@ namespace Artemis.Core
|
||||
|
||||
private void CreateSetReferenceTypeExpression()
|
||||
{
|
||||
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
|
||||
var parameter = Expression.Parameter(typeof(TLayerProperty), "currentValue");
|
||||
var memberAccess = Expression.MakeMemberAccess(parameter, DataBinding.Registration.Member);
|
||||
var assignment = Expression.Assign(memberAccess, propertyValue);
|
||||
var referenceTypeLambda = Expression.Lambda<Action<TLayerProperty, TProperty>>(assignment, parameter, propertyValue);
|
||||
ParameterExpression propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
|
||||
ParameterExpression parameter = Expression.Parameter(typeof(TLayerProperty), "currentValue");
|
||||
MemberExpression memberAccess = Expression.MakeMemberAccess(parameter, DataBinding.Registration.Member);
|
||||
BinaryExpression assignment = Expression.Assign(memberAccess, propertyValue);
|
||||
Expression<Action<TLayerProperty, TProperty>> referenceTypeLambda = Expression.Lambda<Action<TLayerProperty, TProperty>>(assignment, parameter, propertyValue);
|
||||
|
||||
ReferenceTypeSetExpression = referenceTypeLambda.Compile();
|
||||
}
|
||||
|
||||
private void CreateSetValueTypeExpression()
|
||||
{
|
||||
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
|
||||
var variableCurrent = Expression.Variable(typeof(TLayerProperty), "current");
|
||||
var layerProperty = Expression.Constant(DataBinding.LayerProperty);
|
||||
var layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty,
|
||||
ParameterExpression propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
|
||||
ParameterExpression variableCurrent = Expression.Variable(typeof(TLayerProperty), "current");
|
||||
ConstantExpression layerProperty = Expression.Constant(DataBinding.LayerProperty);
|
||||
MemberExpression layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty,
|
||||
DataBinding.LayerProperty.GetType().GetMember(nameof(DataBinding.LayerProperty.CurrentValue))[0]);
|
||||
|
||||
var body = Expression.Block(
|
||||
BlockExpression body = Expression.Block(
|
||||
new[] {variableCurrent},
|
||||
Expression.Assign(variableCurrent, layerPropertyMemberAccess),
|
||||
Expression.Assign(Expression.MakeMemberAccess(variableCurrent, DataBinding.Registration.Member), propertyValue),
|
||||
Expression.Assign(layerPropertyMemberAccess, variableCurrent)
|
||||
);
|
||||
|
||||
var valueTypeLambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
|
||||
Expression<Action<TProperty>> valueTypeLambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
|
||||
ValueTypeSetExpression = valueTypeLambda.Compile();
|
||||
}
|
||||
|
||||
private void CreateSetCurrentValueExpression()
|
||||
{
|
||||
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
|
||||
var layerProperty = Expression.Constant(DataBinding.LayerProperty);
|
||||
var layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty,
|
||||
ParameterExpression propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
|
||||
ConstantExpression layerProperty = Expression.Constant(DataBinding.LayerProperty);
|
||||
MemberExpression layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty,
|
||||
DataBinding.LayerProperty.GetType().GetMember(nameof(DataBinding.LayerProperty.CurrentValue))[0]);
|
||||
|
||||
var body = Expression.Assign(layerPropertyMemberAccess, propertyValue);
|
||||
var lambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
|
||||
BinaryExpression body = Expression.Assign(layerPropertyMemberAccess, propertyValue);
|
||||
Expression<Action<TProperty>> lambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
|
||||
ValueTypeSetExpression = lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -58,7 +59,7 @@ namespace Artemis.Core
|
||||
if (DataBinding != null)
|
||||
return DataBinding;
|
||||
|
||||
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetExpression == PropertyExpression.ToString());
|
||||
DataBindingEntity dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetExpression == PropertyExpression.ToString());
|
||||
if (dataBinding == null)
|
||||
return null;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Artemis.Core
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ConditionalDataBinding");
|
||||
|
||||
var condition = Conditions.FirstOrDefault(c => c.Evaluate());
|
||||
DataBindingCondition<TLayerProperty, TProperty> condition = Conditions.FirstOrDefault(c => c.Evaluate());
|
||||
if (condition != null)
|
||||
Console.WriteLine();
|
||||
return condition == null ? baseValue : condition.Value;
|
||||
@@ -49,7 +49,7 @@ namespace Artemis.Core
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
foreach (var dataBindingCondition in Conditions)
|
||||
foreach (DataBindingCondition<TLayerProperty, TProperty> dataBindingCondition in Conditions)
|
||||
dataBindingCondition.Dispose();
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Artemis.Core
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ConditionalDataBinding");
|
||||
|
||||
var condition = new DataBindingCondition<TLayerProperty, TProperty>(this);
|
||||
DataBindingCondition<TLayerProperty, TProperty> condition = new DataBindingCondition<TLayerProperty, TProperty>(this);
|
||||
_conditions.Add(condition);
|
||||
|
||||
ApplyOrder();
|
||||
@@ -102,9 +102,9 @@ namespace Artemis.Core
|
||||
throw new ObjectDisposedException("ConditionalDataBinding");
|
||||
|
||||
_conditions.Sort((a, b) => a.Order.CompareTo(b.Order));
|
||||
for (var index = 0; index < _conditions.Count; index++)
|
||||
for (int index = 0; index < _conditions.Count; index++)
|
||||
{
|
||||
var condition = _conditions[index];
|
||||
DataBindingCondition<TLayerProperty, TProperty> condition = _conditions[index];
|
||||
condition.Order = index + 1;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public void Load()
|
||||
{
|
||||
foreach (var dataBindingConditionEntity in Entity.Values)
|
||||
foreach (DataBindingConditionEntity dataBindingConditionEntity in Entity.Values)
|
||||
_conditions.Add(new DataBindingCondition<TLayerProperty, TProperty>(this, dataBindingConditionEntity));
|
||||
|
||||
ApplyOrder();
|
||||
@@ -126,7 +126,7 @@ namespace Artemis.Core
|
||||
public void Save()
|
||||
{
|
||||
Entity.Values.Clear();
|
||||
foreach (var dataBindingCondition in Conditions)
|
||||
foreach (DataBindingCondition<TLayerProperty, TProperty> dataBindingCondition in Conditions)
|
||||
dataBindingCondition.Save();
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace Artemis.Core
|
||||
|
||||
if (ParameterType == ProfileRightSideType.Dynamic && CompiledParameterAccessor != null)
|
||||
{
|
||||
var value = CompiledParameterAccessor(ParameterDataModel);
|
||||
object value = CompiledParameterAccessor(ParameterDataModel);
|
||||
return ModifierType.Apply(currentValue, value);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace Artemis.Core
|
||||
return;
|
||||
}
|
||||
|
||||
var targetType = DirectDataBinding.DataBinding.GetTargetType();
|
||||
Type targetType = DirectDataBinding.DataBinding.GetTargetType();
|
||||
if (!modifierType.SupportsType(targetType))
|
||||
{
|
||||
throw new ArtemisCoreException($"Cannot apply modifier type {modifierType.GetType().Name} to this modifier because " +
|
||||
@@ -226,7 +226,7 @@ namespace Artemis.Core
|
||||
ParameterDataModel = null;
|
||||
ParameterPropertyPath = null;
|
||||
|
||||
var parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
|
||||
Type parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
|
||||
|
||||
// If not null ensure the types match and if not, convert it
|
||||
if (staticValue != null && staticValue.GetType() == parameterType)
|
||||
@@ -252,7 +252,7 @@ namespace Artemis.Core
|
||||
// Modifier type
|
||||
if (Entity.ModifierTypePluginGuid != null && ModifierType == null)
|
||||
{
|
||||
var modifierType = DataBindingModifierTypeStore.Get(Entity.ModifierTypePluginGuid.Value, Entity.ModifierType)?.DataBindingModifierType;
|
||||
DataBindingModifierType modifierType = DataBindingModifierTypeStore.Get(Entity.ModifierTypePluginGuid.Value, Entity.ModifierType)?.DataBindingModifierType;
|
||||
if (modifierType != null)
|
||||
UpdateModifierType(modifierType);
|
||||
}
|
||||
@@ -260,7 +260,7 @@ namespace Artemis.Core
|
||||
// Dynamic parameter
|
||||
if (ParameterType == ProfileRightSideType.Dynamic && Entity.ParameterDataModelGuid != null && ParameterDataModel == null)
|
||||
{
|
||||
var dataModel = DataModelStore.Get(Entity.ParameterDataModelGuid.Value)?.DataModel;
|
||||
DataModel dataModel = DataModelStore.Get(Entity.ParameterDataModelGuid.Value)?.DataModel;
|
||||
if (dataModel != null && dataModel.ContainsPath(Entity.ParameterPropertyPath))
|
||||
UpdateParameter(dataModel, Entity.ParameterPropertyPath);
|
||||
}
|
||||
@@ -268,7 +268,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 parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
|
||||
Type parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
|
||||
object staticValue;
|
||||
|
||||
try
|
||||
@@ -299,10 +299,10 @@ namespace Artemis.Core
|
||||
return;
|
||||
|
||||
// If the right side value is null, the constant type cannot be inferred and must be provided based on the data binding target
|
||||
var parameterAccessor = ExpressionUtilities.CreateDataModelAccessor(
|
||||
ParameterDataModel, ParameterPropertyPath, "parameter", out var rightSideParameter
|
||||
Expression parameterAccessor = ExpressionUtilities.CreateDataModelAccessor(
|
||||
ParameterDataModel, ParameterPropertyPath, "parameter", out ParameterExpression rightSideParameter
|
||||
);
|
||||
var lambda = Expression.Lambda<Func<DataModel, object>>(Expression.Convert(parameterAccessor, typeof(object)), rightSideParameter);
|
||||
Expression<Func<DataModel, object>> lambda = Expression.Lambda<Func<DataModel, object>>(Expression.Convert(parameterAccessor, typeof(object)), rightSideParameter);
|
||||
CompiledParameterAccessor = lambda.Compile();
|
||||
}
|
||||
}
|
||||
@@ -314,7 +314,7 @@ namespace Artemis.Core
|
||||
if (ModifierType != null)
|
||||
return;
|
||||
|
||||
var modifierType = e.TypeRegistration.DataBindingModifierType;
|
||||
DataBindingModifierType modifierType = e.TypeRegistration.DataBindingModifierType;
|
||||
if (modifierType.PluginInfo.Guid == Entity.ModifierTypePluginGuid && modifierType.GetType().Name == Entity.ModifierType)
|
||||
UpdateModifierType(modifierType);
|
||||
}
|
||||
@@ -327,7 +327,7 @@ namespace Artemis.Core
|
||||
|
||||
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
|
||||
{
|
||||
var dataModel = e.Registration.DataModel;
|
||||
DataModel dataModel = e.Registration.DataModel;
|
||||
if (dataModel.PluginInfo.Guid == Entity.ParameterDataModelGuid && dataModel.ContainsPath(Entity.ParameterPropertyPath))
|
||||
UpdateParameter(dataModel, Entity.ParameterPropertyPath);
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ namespace Artemis.Core
|
||||
if (CompiledTargetAccessor == null)
|
||||
return baseValue;
|
||||
|
||||
var dataBindingValue = CompiledTargetAccessor(SourceDataModel);
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
object dataBindingValue = CompiledTargetAccessor(SourceDataModel);
|
||||
foreach (DataBindingModifier<TLayerProperty, TProperty> dataBindingModifier in Modifiers)
|
||||
dataBindingValue = dataBindingModifier.Apply(dataBindingValue);
|
||||
|
||||
return DataBinding.Converter.ConvertFromObject(dataBindingValue);
|
||||
@@ -75,7 +75,7 @@ namespace Artemis.Core
|
||||
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
foreach (DataBindingModifier<TLayerProperty, TProperty> dataBindingModifier in Modifiers)
|
||||
dataBindingModifier.Dispose();
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Artemis.Core
|
||||
// Data model is done during Initialize
|
||||
|
||||
// Modifiers
|
||||
foreach (var dataBindingModifierEntity in Entity.Modifiers)
|
||||
foreach (DataBindingModifierEntity dataBindingModifierEntity in Entity.Modifiers)
|
||||
_modifiers.Add(new DataBindingModifier<TLayerProperty, TProperty>(this, dataBindingModifierEntity));
|
||||
|
||||
ApplyOrder();
|
||||
@@ -107,7 +107,7 @@ namespace Artemis.Core
|
||||
|
||||
// Modifiers
|
||||
Entity.Modifiers.Clear();
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
foreach (DataBindingModifier<TLayerProperty, TProperty> dataBindingModifier in Modifiers)
|
||||
dataBindingModifier.Save();
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Artemis.Core
|
||||
// Source
|
||||
if (Entity.SourceDataModelGuid != null && SourceDataModel == null)
|
||||
{
|
||||
var dataModel = DataModelStore.Get(Entity.SourceDataModelGuid.Value)?.DataModel;
|
||||
DataModel dataModel = DataModelStore.Get(Entity.SourceDataModelGuid.Value)?.DataModel;
|
||||
if (dataModel != null && dataModel.ContainsPath(Entity.SourcePropertyPath))
|
||||
UpdateSource(dataModel, Entity.SourcePropertyPath);
|
||||
}
|
||||
@@ -131,19 +131,19 @@ namespace Artemis.Core
|
||||
|
||||
private void CreateExpression()
|
||||
{
|
||||
var listType = SourceDataModel.GetListTypeInPath(SourcePropertyPath);
|
||||
Type listType = SourceDataModel.GetListTypeInPath(SourcePropertyPath);
|
||||
if (listType != null)
|
||||
throw new ArtemisCoreException($"Cannot create a regular accessor at path {SourcePropertyPath} because the path contains a list");
|
||||
|
||||
var parameter = Expression.Parameter(typeof(DataModel), "targetDataModel");
|
||||
var accessor = SourcePropertyPath.Split('.').Aggregate<string, Expression>(
|
||||
ParameterExpression parameter = Expression.Parameter(typeof(DataModel), "targetDataModel");
|
||||
Expression accessor = SourcePropertyPath.Split('.').Aggregate<string, Expression>(
|
||||
Expression.Convert(parameter, SourceDataModel.GetType()), // Cast to the appropriate type
|
||||
Expression.Property
|
||||
);
|
||||
|
||||
var returnValue = Expression.Convert(accessor, typeof(object));
|
||||
UnaryExpression returnValue = Expression.Convert(accessor, typeof(object));
|
||||
|
||||
var lambda = Expression.Lambda<Func<DataModel, object>>(returnValue, parameter);
|
||||
Expression<Func<DataModel, object>> lambda = Expression.Lambda<Func<DataModel, object>>(returnValue, parameter);
|
||||
CompiledTargetAccessor = lambda.Compile();
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ namespace Artemis.Core
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DirectDataBinding");
|
||||
|
||||
var modifier = new DataBindingModifier<TLayerProperty, TProperty>(this, type);
|
||||
DataBindingModifier<TLayerProperty, TProperty> modifier = new DataBindingModifier<TLayerProperty, TProperty>(this, type);
|
||||
_modifiers.Add(modifier);
|
||||
|
||||
ApplyOrder();
|
||||
@@ -230,9 +230,9 @@ namespace Artemis.Core
|
||||
public void ApplyOrder()
|
||||
{
|
||||
_modifiers.Sort((a, b) => a.Order.CompareTo(b.Order));
|
||||
for (var index = 0; index < _modifiers.Count; index++)
|
||||
for (int index = 0; index < _modifiers.Count; index++)
|
||||
{
|
||||
var modifier = _modifiers[index];
|
||||
DataBindingModifier<TLayerProperty, TProperty> modifier = _modifiers[index];
|
||||
modifier.Order = index + 1;
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@ namespace Artemis.Core
|
||||
|
||||
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
|
||||
{
|
||||
var dataModel = e.Registration.DataModel;
|
||||
DataModel dataModel = e.Registration.DataModel;
|
||||
if (dataModel.PluginInfo.Guid == Entity.SourceDataModelGuid && dataModel.ContainsPath(Entity.SourcePropertyPath))
|
||||
UpdateSource(dataModel, Entity.SourcePropertyPath);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user