Data bindings - WIP commit

Layer/effect config dialogs - Don't require specific ctor parameter names
This commit is contained in:
Robert committed 2020-09-03 20:16:01 +02:00
1 parent c98fc51623
commit 21beffc0a9
15 files changed
+408 -130

No files matched your search

@@ -15,18 +15,23 @@ namespace Artemis.Core
public class DataBinding
{
private readonly List<DataBindingModifier> _modifiers = new List<DataBindingModifier>();
private bool _isInitialized;
public DataBinding(BaseLayerProperty layerProperty, PropertyInfo targetProperty)
internal DataBinding(BaseLayerProperty layerProperty, PropertyInfo targetProperty)
{
LayerProperty = layerProperty;
TargetProperty = targetProperty;
Entity = new DataBindingEntity();
ApplyToEntity();
}
public DataBinding(BaseLayerProperty layerProperty, PropertyInfo targetProperty, DataBindingEntity entity)
internal DataBinding(BaseLayerProperty layerProperty, DataBindingEntity entity)
{
LayerProperty = layerProperty;
TargetProperty = targetProperty;
Entity = entity;
ApplyToDataBinding();
}
/// <summary>
@@ -37,7 +42,7 @@ namespace Artemis.Core
/// <summary>
/// Gets the inner property this data binding targets
/// </summary>
public PropertyInfo TargetProperty { get; }
public PropertyInfo TargetProperty { get; private set; }
/// <summary>
/// Gets the currently used instance of the data model that contains the source of the data binding
@@ -49,13 +54,25 @@ namespace Artemis.Core
/// </summary>
public string SourcePropertyPath { get; private set; }
public DataBindingMode Mode { get; set; }
/// <summary>
/// Gets or sets the easing time of the data binding
/// </summary>
public TimeSpan EasingTime { get; set; }
/// <summary>
/// Gets ors ets the easing function of the data binding
/// </summary>
public Easings.Functions EasingFunction { get; set; }
/// <summary>
/// Gets a list of modifiers applied to this data binding
/// </summary>
public IReadOnlyList<DataBindingModifier> Modifiers => _modifiers.AsReadOnly();
/// <summary>
/// Gets the compiled function that gets the current value of the data binding target
/// Gets the compiled function that gets the current value of the data binding target
/// </summary>
public Func<DataModel, object> CompiledTargetAccessor { get; private set; }
@@ -131,15 +148,60 @@ namespace Artemis.Core
return dataBindingValue;
}
internal void Initialize(IDataModelService dataModelService, IDataBindingService dataBindingService)
internal void ApplyToEntity()
{
// Source
// General
Entity.TargetProperty = TargetProperty?.Name;
Entity.DataBindingMode = (int) Mode;
Entity.EasingTime = EasingTime;
Entity.EasingFunction = (int) EasingFunction;
// Data model
Entity.SourceDataModelGuid = SourceDataModel?.PluginInfo?.Guid;
Entity.SourcePropertyPath = SourcePropertyPath;
// Modifiers
Entity.Modifiers.Clear();
foreach (var dataBindingModifier in Modifiers)
{
dataBindingModifier.ApplyToEntity();
Entity.Modifiers.Add(dataBindingModifier.Entity);
}
}
internal void ApplyToDataBinding()
{
// General
TargetProperty = LayerProperty.GetDataBindingProperties()?.FirstOrDefault(p => p.Name == Entity.TargetProperty);
Mode = (DataBindingMode) Entity.DataBindingMode;
EasingTime = Entity.EasingTime;
EasingFunction = (Easings.Functions) Entity.EasingFunction;
foreach (var dataBindingModifier in Modifiers)
// Data model is done during Initialize
// Modifiers
foreach (var dataBindingModifierEntity in Entity.Modifiers)
_modifiers.Add(new DataBindingModifier(this, dataBindingModifierEntity));
}
internal void Initialize(IDataModelService dataModelService, IDataBindingService dataBindingService)
{
if (_isInitialized)
throw new ArtemisCoreException("Data binding is already initialized");
// Source
if (Entity.SourceDataModelGuid != null)
{
var dataModel = dataModelService.GetPluginDataModelByGuid(Entity.SourceDataModelGuid.Value);
if (dataModel != null && dataModel.ContainsPath(Entity.SourcePropertyPath))
UpdateSource(dataModel, Entity.SourcePropertyPath);
}
// Modifiers
foreach (var dataBindingModifier in Modifiers)
dataBindingModifier.Initialize(dataModelService, dataBindingService);
_isInitialized = true;
}
private void CreateExpression()
@@ -158,4 +220,10 @@ namespace Artemis.Core
CompiledTargetAccessor = lambda.Compile();
}
}
public enum DataBindingMode
{
Override,
Add
}
}
@@ -4,6 +4,7 @@ using System.Linq.Expressions;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile.DataBindings;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
namespace Artemis.Core
@@ -14,26 +15,26 @@ namespace Artemis.Core
public class DataBindingModifier
{
private DataBinding _dataBinding;
private bool _isInitialized;
/// <summary>
/// Creates a new instance of the <see cref="DataBindingModifier" /> class
/// Creates a new instance of the <see cref="DataBindingModifier"/> class
/// </summary>
public DataBindingModifier(DataBinding dataBinding, ProfileRightSideType parameterType)
/// <param name="parameterType">The type of the parameter, can either be dynamic (based on a data model value) or static</param>
public DataBindingModifier(ProfileRightSideType parameterType)
{
DataBinding = dataBinding;
ParameterType = parameterType;
Entity = new DataBindingModifierEntity();
ApplyToEntity();
}
/// <summary>
/// Creates a new instance of the <see cref="DataBindingModifier" /> class
/// </summary>
public DataBindingModifier(DataBinding dataBinding, DataBindingModifierEntity entity)
internal DataBindingModifier(DataBinding dataBinding, DataBindingModifierEntity entity)
{
DataBinding = dataBinding;
ParameterType = (ProfileRightSideType) entity.ParameterType;
Order = entity.Order;
Entity = entity;
ApplyToDataBindingModifier();
}
/// <summary>
@@ -192,6 +193,9 @@ namespace Artemis.Core
internal void Initialize(IDataModelService dataModelService, IDataBindingService dataBindingService)
{
if (_isInitialized)
throw new ArtemisCoreException("Data binding modifier is already initialized");
// Modifier type
if (Entity.ModifierTypePluginGuid != null)
{
@@ -207,6 +211,7 @@ namespace Artemis.Core
if (dataModel != null && dataModel.ContainsPath(Entity.ParameterPropertyPath))
UpdateParameter(dataModel, Entity.ParameterPropertyPath);
}
// Static parameter
else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null)
{
// Use the target type so JSON.NET has a better idea what to do
@@ -227,7 +232,7 @@ namespace Artemis.Core
UpdateParameter(staticValue);
}
// Static parameter
_isInitialized = true;
}
@@ -291,5 +296,32 @@ namespace Artemis.Core
Expression.Property
);
}
internal void ApplyToEntity()
{
// Modifier
Entity.ModifierType = ModifierType?.GetType().Name;
Entity.ModifierTypePluginGuid = ModifierType?.PluginInfo.Guid;
// General
Entity.Order = Order;
Entity.ParameterType = (int) ParameterType;
// Parameter
Entity.ParameterDataModelGuid = ParameterDataModel?.PluginInfo.Guid;
Entity.ParameterPropertyPath = ParameterPropertyPath;
Entity.ParameterStaticValue = JsonConvert.SerializeObject(ParameterStaticValue);
}
internal void ApplyToDataBindingModifier()
{
// Modifier type is done during Initialize
// General
Order = Entity.Order;
ParameterType = (ProfileRightSideType) Entity.ParameterType;
// Parameter is done during initialize
}
}
}
+2
View File
@@ -112,6 +112,7 @@ namespace Artemis.Core
internal set => SetAndNotify(ref _layerBrush, value);
}
/// <inheritdoc />
public override string ToString()
{
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
@@ -138,6 +139,7 @@ namespace Artemis.Core
return keyframes;
}
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (!disposing)
@@ -10,7 +10,7 @@ namespace Artemis.Core
/// </summary>
public abstract class BaseLayerProperty
{
private readonly List<DataBinding> _dataBindings = new List<DataBinding>();
protected readonly List<DataBinding> _dataBindings = new List<DataBinding>();
private bool _isHidden;
private bool _keyframesEnabled;
@@ -31,15 +31,15 @@ namespace Artemis.Core
/// <summary>
/// Gets whether keyframes are supported on this type of property
/// </summary>
public bool KeyframesSupported { get; protected internal set; } = true;
public bool KeyframesSupported { get; protected internal set; } = true;
/// <summary>
/// Gets whether data bindings are supported on this type of property
/// </summary>
public bool DataBindingsSupported { get; protected internal set; } = true;
/// <summary>
/// Gets a read-only collection of the currently applied data bindings
/// Gets a read-only collection of the currently applied data bindings
/// </summary>
public IReadOnlyCollection<DataBinding> DataBindings => _dataBindings.AsReadOnly();
@@ -141,6 +141,30 @@ namespace Artemis.Core
ApplyDataBinding(dataBinding);
}
/// <summary>
/// Adds a new data binding targeting the given property to the <see cref="DataBindings" /> collection
/// </summary>
/// <param name="targetProperty">The property the new data binding should target</param>
/// <returns>The newly created data binding</returns>
public DataBinding AddDataBinding(PropertyInfo targetProperty)
{
var dataBinding = new DataBinding(this, targetProperty);
_dataBindings.Add(dataBinding);
return dataBinding;
}
/// <summary>
/// Removes the provided data binding from the <see cref="DataBindings" /> collection
/// </summary>
/// <param name="dataBinding">The data binding to remove</param>
public void RemoveDataBinding(DataBinding dataBinding)
{
_dataBindings.Remove(dataBinding);
}
#endregion
#region Events
@@ -255,6 +255,13 @@ namespace Artemis.Core
(Easings.Functions) k.EasingFunction,
this
)));
_dataBindings.Clear();
foreach (var entityDataBindingEntity in entity.DataBindingEntities)
{
var dataBinding = new DataBinding(this, entityDataBindingEntity);
_dataBindings.Add(dataBinding);
}
}
catch (JsonException e)
{