mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Databindings - Added conditional databindings
Conditions - Added easy method for null-handling in operators
This commit is contained in:
1 parent
b19cc6ca54
commit
b73ea53622
26 files changed
+491
-134
No files matched your search
@@ -53,5 +53,34 @@ namespace Artemis.Core
|
||||
/// <param name="rightSide">The parameter on the right side of the expression</param>
|
||||
/// <returns></returns>
|
||||
public abstract BinaryExpression CreateExpression(Expression leftSide, Expression rightSide);
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the provided expression in null-checks for the left and right side
|
||||
/// <para>
|
||||
/// The resulting expression body looks like:
|
||||
/// <code>(a == null && b == null) || ((a != null && b != null) && <expression>)</code>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="leftSide">The left side to check for nulls</param>
|
||||
/// <param name="rightSide">The right side to check for nulls</param>
|
||||
/// <param name="expression">The expression to wrap</param>
|
||||
/// <returns>The wrapped expression</returns>
|
||||
protected BinaryExpression AddNullChecks(Expression leftSide, Expression rightSide, BinaryExpression expression)
|
||||
{
|
||||
var nullConst = Expression.Constant(null);
|
||||
return Expression.OrElse(
|
||||
Expression.AndAlso(
|
||||
Expression.Equal(leftSide, nullConst),
|
||||
Expression.Equal(rightSide, nullConst)
|
||||
),
|
||||
Expression.AndAlso(
|
||||
Expression.AndAlso(
|
||||
Expression.NotEqual(leftSide, nullConst),
|
||||
Expression.NotEqual(rightSide, nullConst)
|
||||
),
|
||||
expression
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,9 +152,10 @@ namespace Artemis.Core
|
||||
|
||||
private void ApplyRegistration(DataBindingRegistration<TLayerProperty, TProperty> dataBindingRegistration)
|
||||
{
|
||||
if (dataBindingRegistration != null)
|
||||
dataBindingRegistration.DataBinding = this;
|
||||
if (dataBindingRegistration == null)
|
||||
throw new ArgumentNullException(nameof(dataBindingRegistration));
|
||||
|
||||
dataBindingRegistration.DataBinding = this;
|
||||
Converter = dataBindingRegistration?.Converter;
|
||||
Registration = dataBindingRegistration;
|
||||
|
||||
@@ -226,9 +227,11 @@ namespace Artemis.Core
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DataBinding");
|
||||
|
||||
// General
|
||||
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetExpression);
|
||||
ApplyRegistration(registration);
|
||||
if (registration != null)
|
||||
ApplyRegistration(registration);
|
||||
|
||||
EasingTime = Entity.EasingTime;
|
||||
EasingFunction = (Easings.Functions) Entity.EasingFunction;
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Artemis.Core
|
||||
{
|
||||
DataBinding = dataBinding;
|
||||
Entity = entity;
|
||||
Load();
|
||||
}
|
||||
|
||||
internal ConditionalDataBindingEntity Entity { get; }
|
||||
@@ -90,8 +91,14 @@ namespace Artemis.Core
|
||||
OnConditionsUpdated();
|
||||
}
|
||||
|
||||
internal void ApplyOrder()
|
||||
/// <summary>
|
||||
/// Applies the current order of conditions to the <see cref="Conditions" /> collection
|
||||
/// </summary>
|
||||
public void ApplyOrder()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ConditionalDataBinding");
|
||||
|
||||
_conditions.Sort((a, b) => a.Order.CompareTo(b.Order));
|
||||
for (var index = 0; index < _conditions.Count; index++)
|
||||
{
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace Artemis.Core
|
||||
/// Creates a new instance of the <see cref="DataBindingCondition{TLayerProperty,TProperty}" /> class
|
||||
/// </summary>
|
||||
/// <param name="conditionalDataBinding">The conditional data binding this condition is applied too</param>
|
||||
public DataBindingCondition(ConditionalDataBinding<TLayerProperty, TProperty> conditionalDataBinding)
|
||||
internal DataBindingCondition(ConditionalDataBinding<TLayerProperty, TProperty> conditionalDataBinding)
|
||||
{
|
||||
ConditionalDataBinding = conditionalDataBinding ?? throw new ArgumentNullException(nameof(conditionalDataBinding));
|
||||
Order = conditionalDataBinding.Conditions.Count + 1;
|
||||
Condition = new DataModelConditionGroup(null);
|
||||
Entity = new DataBindingConditionEntity();
|
||||
Save();
|
||||
}
|
||||
@@ -34,9 +35,9 @@ namespace Artemis.Core
|
||||
public ConditionalDataBinding<TLayerProperty, TProperty> ConditionalDataBinding { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the position at which the modifier appears on the data binding
|
||||
/// Gets or sets the position at which the modifier appears on the data binding
|
||||
/// </summary>
|
||||
public int Order { get; internal set; }
|
||||
public int Order { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value to be applied when the condition is met
|
||||
@@ -82,7 +83,7 @@ namespace Artemis.Core
|
||||
? new DataModelConditionGroup(null, Entity.Condition)
|
||||
: new DataModelConditionGroup(null);
|
||||
|
||||
Value = JsonConvert.DeserializeObject<TProperty>(Entity.Value);
|
||||
Value = Entity.Value == null ? default : JsonConvert.DeserializeObject<TProperty>(Entity.Value);
|
||||
Order = Entity.Order;
|
||||
}
|
||||
|
||||
@@ -93,15 +94,5 @@ namespace Artemis.Core
|
||||
|
||||
Condition.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the order and resorts the Conditions list in the <see cref="ConditionalDataBinding" />
|
||||
/// </summary>
|
||||
/// <param name="order"></param>
|
||||
public void UpdateOrder(int order)
|
||||
{
|
||||
Order = order;
|
||||
ConditionalDataBinding.ApplyOrder();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,9 +46,9 @@ namespace Artemis.Core
|
||||
public ProfileRightSideType ParameterType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the position at which the modifier appears on the data binding
|
||||
/// Gets or sets the position at which the modifier appears on the data binding
|
||||
/// </summary>
|
||||
public int Order { get; internal set; }
|
||||
public int Order { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently used instance of the parameter data model
|
||||
|
||||
@@ -224,7 +224,10 @@ namespace Artemis.Core
|
||||
OnModifiersUpdated();
|
||||
}
|
||||
|
||||
internal void ApplyOrder()
|
||||
/// <summary>
|
||||
/// Applies the current order of conditions to the <see cref="Modifiers" /> collection
|
||||
/// </summary>
|
||||
public void ApplyOrder()
|
||||
{
|
||||
_modifiers.Sort((a, b) => a.Order.CompareTo(b.Order));
|
||||
for (var index = 0; index < _modifiers.Count; index++)
|
||||
|
||||
Reference in new issue
Block a user