Databindings - Added conditional databindings

Conditions - Added easy method for null-handling in operators
This commit is contained in:
Robert committed 2020-09-23 19:26:44 +02:00
1 parent b19cc6ca54
commit b73ea53622
26 files changed
+491 -134

No files matched your search

@@ -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++)