mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Display conditions - Implemented IDisposable
Display conditions - Listen to registration add/remove WIP Data bindings - Implemented IDisposable Data bindings - Listen to registration add/remove
This commit is contained in:
parent
11de30318e
commit
1de6fefc2a
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.Storage.Entities.Profile.Abstract;
|
using Artemis.Storage.Entities.Profile.Abstract;
|
||||||
|
|
||||||
@ -7,7 +8,7 @@ namespace Artemis.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An abstract class for display condition parts
|
/// An abstract class for display condition parts
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class DisplayConditionPart
|
public abstract class DisplayConditionPart : IDisposable
|
||||||
{
|
{
|
||||||
private readonly List<DisplayConditionPart> _children = new List<DisplayConditionPart>();
|
private readonly List<DisplayConditionPart> _children = new List<DisplayConditionPart>();
|
||||||
|
|
||||||
@ -62,5 +63,23 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal abstract void ApplyToEntity();
|
internal abstract void ApplyToEntity();
|
||||||
internal abstract DisplayConditionPartEntity GetEntity();
|
internal abstract DisplayConditionPartEntity GetEntity();
|
||||||
|
|
||||||
|
#region IDisposable
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -11,6 +11,8 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DisplayConditionGroup : DisplayConditionPart
|
public class DisplayConditionGroup : DisplayConditionPart
|
||||||
{
|
{
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="DisplayConditionGroup" /> class
|
/// Creates a new instance of the <see cref="DisplayConditionGroup" /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -55,6 +57,9 @@ namespace Artemis.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool Evaluate()
|
public override bool Evaluate()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DisplayConditionGroup");
|
||||||
|
|
||||||
// Empty groups are always true
|
// Empty groups are always true
|
||||||
if (Children.Count == 0)
|
if (Children.Count == 0)
|
||||||
return true;
|
return true;
|
||||||
@ -80,6 +85,9 @@ namespace Artemis.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool EvaluateObject(object target)
|
public override bool EvaluateObject(object target)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DisplayConditionGroup");
|
||||||
|
|
||||||
// Empty groups are always true
|
// Empty groups are always true
|
||||||
if (Children.Count == 0)
|
if (Children.Count == 0)
|
||||||
return true;
|
return true;
|
||||||
@ -111,6 +119,19 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
return Entity;
|
return Entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region IDisposable
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
_disposed = true;
|
||||||
|
foreach (var child in Children)
|
||||||
|
child.Dispose();
|
||||||
|
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum BooleanOperator
|
public enum BooleanOperator
|
||||||
|
|||||||
@ -10,6 +10,8 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
public class DisplayConditionList : DisplayConditionPart
|
public class DisplayConditionList : DisplayConditionPart
|
||||||
{
|
{
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
public DisplayConditionList(DisplayConditionPart parent)
|
public DisplayConditionList(DisplayConditionPart parent)
|
||||||
{
|
{
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
@ -37,6 +39,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
public override bool Evaluate()
|
public override bool Evaluate()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DisplayConditionList");
|
||||||
|
|
||||||
if (CompiledListAccessor == null)
|
if (CompiledListAccessor == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -45,6 +50,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
public override bool EvaluateObject(object target)
|
public override bool EvaluateObject(object target)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DisplayConditionList");
|
||||||
|
|
||||||
if (!Children.Any())
|
if (!Children.Any())
|
||||||
return false;
|
return false;
|
||||||
if (!(target is IList list))
|
if (!(target is IList list))
|
||||||
@ -63,6 +71,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
public void UpdateList(DataModel dataModel, string path)
|
public void UpdateList(DataModel dataModel, string path)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DisplayConditionList");
|
||||||
|
|
||||||
if (dataModel != null && path == null)
|
if (dataModel != null && path == null)
|
||||||
throw new ArtemisCoreException("If a data model is provided, a path is also required");
|
throw new ArtemisCoreException("If a data model is provided, a path is also required");
|
||||||
if (dataModel == null && path != null)
|
if (dataModel == null && path != null)
|
||||||
@ -93,6 +104,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
public void CreateExpression()
|
public void CreateExpression()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DisplayConditionList");
|
||||||
|
|
||||||
var parameter = Expression.Parameter(typeof(object), "listDataModel");
|
var parameter = Expression.Parameter(typeof(object), "listDataModel");
|
||||||
var accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>(
|
var accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>(
|
||||||
Expression.Convert(parameter, ListDataModel.GetType()),
|
Expression.Convert(parameter, ListDataModel.GetType()),
|
||||||
@ -101,12 +115,15 @@ namespace Artemis.Core
|
|||||||
var lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter);
|
var lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter);
|
||||||
CompiledListAccessor = lambda.Compile();
|
CompiledListAccessor = lambda.Compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void ApplyToEntity()
|
internal override void ApplyToEntity()
|
||||||
{
|
{
|
||||||
// Target list
|
// Target list
|
||||||
Entity.ListDataModelGuid = ListDataModel?.PluginInfo?.Guid;
|
if (ListDataModel != null)
|
||||||
Entity.ListPropertyPath = ListPropertyPath;
|
{
|
||||||
|
Entity.ListDataModelGuid = ListDataModel.PluginInfo.Guid;
|
||||||
|
Entity.ListPropertyPath = ListPropertyPath;
|
||||||
|
}
|
||||||
|
|
||||||
// Operator
|
// Operator
|
||||||
Entity.ListOperator = (int) ListOperator;
|
Entity.ListOperator = (int) ListOperator;
|
||||||
@ -125,6 +142,8 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal void Initialize()
|
internal void Initialize()
|
||||||
{
|
{
|
||||||
|
DataModelStore.DataModelAdded += DataModelStoreOnDataModelAdded;
|
||||||
|
DataModelStore.DataModelRemoved += DataModelStoreOnDataModelRemoved;
|
||||||
if (Entity.ListDataModelGuid == null)
|
if (Entity.ListDataModelGuid == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -147,6 +166,49 @@ namespace Artemis.Core
|
|||||||
AddChild(new DisplayConditionGroup(this));
|
AddChild(new DisplayConditionGroup(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region Event handlers
|
||||||
|
|
||||||
|
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
|
||||||
|
{
|
||||||
|
var dataModel = e.Registration.DataModel;
|
||||||
|
if (dataModel.PluginInfo.Guid == Entity.ListDataModelGuid && dataModel.ContainsPath(Entity.ListPropertyPath))
|
||||||
|
{
|
||||||
|
ListDataModel = dataModel;
|
||||||
|
ListPropertyPath = Entity.ListPropertyPath;
|
||||||
|
CreateExpression();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataModelStoreOnDataModelRemoved(object sender, DataModelStoreEvent e)
|
||||||
|
{
|
||||||
|
if (ListDataModel != e.Registration.DataModel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ListDataModel = null;
|
||||||
|
CompiledListAccessor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IDisposable
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
_disposed = true;
|
||||||
|
|
||||||
|
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||||
|
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||||
|
|
||||||
|
foreach (var child in Children)
|
||||||
|
child.Dispose();
|
||||||
|
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ListOperator
|
public enum ListOperator
|
||||||
|
|||||||
@ -248,6 +248,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal void Initialize()
|
internal void Initialize()
|
||||||
{
|
{
|
||||||
|
DataModelStore.DataModelAdded += DataModelStoreOnDataModelAdded;
|
||||||
|
DataModelStore.DataModelRemoved += DataModelStoreOnDataModelRemoved;
|
||||||
|
|
||||||
// Left side
|
// Left side
|
||||||
if (Entity.LeftDataModelGuid != null)
|
if (Entity.LeftDataModelGuid != null)
|
||||||
{
|
{
|
||||||
@ -424,5 +427,42 @@ namespace Artemis.Core
|
|||||||
Expression.Property
|
Expression.Property
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Event handlers
|
||||||
|
|
||||||
|
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
|
||||||
|
{
|
||||||
|
var dataModel = e.Registration.DataModel;
|
||||||
|
if (dataModel.PluginInfo.Guid == Entity.LeftDataModelGuid && dataModel.ContainsPath(Entity.LeftPropertyPath))
|
||||||
|
UpdateLeftSide(dataModel, Entity.LeftPropertyPath);
|
||||||
|
if (dataModel.PluginInfo.Guid == Entity.RightDataModelGuid && dataModel.ContainsPath(Entity.RightPropertyPath))
|
||||||
|
UpdateRightSide(dataModel, Entity.RightPropertyPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataModelStoreOnDataModelRemoved(object sender, DataModelStoreEvent e)
|
||||||
|
{
|
||||||
|
if (LeftDataModel == e.Registration.DataModel)
|
||||||
|
{
|
||||||
|
CompiledDynamicPredicate = null;
|
||||||
|
LeftDataModel = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RightDataModel == e.Registration.DataModel)
|
||||||
|
{
|
||||||
|
CompiledDynamicPredicate = null;
|
||||||
|
RightDataModel = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||||
|
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||||
|
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,7 +4,6 @@ using System.Linq;
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Artemis.Core.DataModelExpansions;
|
using Artemis.Core.DataModelExpansions;
|
||||||
using Artemis.Core.Services;
|
|
||||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
@ -17,6 +16,7 @@ namespace Artemis.Core
|
|||||||
private TProperty _currentValue;
|
private TProperty _currentValue;
|
||||||
private TimeSpan _easingProgress;
|
private TimeSpan _easingProgress;
|
||||||
private TProperty _previousValue;
|
private TProperty _previousValue;
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
internal DataBinding(DataBindingRegistration<TLayerProperty, TProperty> dataBindingRegistration)
|
internal DataBinding(DataBindingRegistration<TLayerProperty, TProperty> dataBindingRegistration)
|
||||||
{
|
{
|
||||||
@ -25,6 +25,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
ApplyRegistration(dataBindingRegistration);
|
ApplyRegistration(dataBindingRegistration);
|
||||||
Save();
|
Save();
|
||||||
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal DataBinding(LayerProperty<TLayerProperty> layerProperty, DataBindingEntity entity)
|
internal DataBinding(LayerProperty<TLayerProperty> layerProperty, DataBindingEntity entity)
|
||||||
@ -32,6 +33,8 @@ namespace Artemis.Core
|
|||||||
LayerProperty = layerProperty;
|
LayerProperty = layerProperty;
|
||||||
Entity = entity;
|
Entity = entity;
|
||||||
|
|
||||||
|
// Load will add children so be initialized before that
|
||||||
|
Initialize();
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +98,9 @@ namespace Artemis.Core
|
|||||||
/// <param name="deltaTime">The time in seconds that passed since the last update</param>
|
/// <param name="deltaTime">The time in seconds that passed since the last update</param>
|
||||||
public void Update(double deltaTime)
|
public void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBinding");
|
||||||
|
|
||||||
// Data bindings cannot go back in time like brushes
|
// Data bindings cannot go back in time like brushes
|
||||||
deltaTime = Math.Max(0, deltaTime);
|
deltaTime = Math.Max(0, deltaTime);
|
||||||
|
|
||||||
@ -103,11 +109,27 @@ namespace Artemis.Core
|
|||||||
_easingProgress = EasingTime;
|
_easingProgress = EasingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Apply()
|
||||||
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBinding");
|
||||||
|
|
||||||
|
if (Converter == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var value = GetValue(Converter.GetValue());
|
||||||
|
Converter.ApplyValue(GetValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a modifier to the data binding's <see cref="Modifiers" /> collection
|
/// Adds a modifier to the data binding's <see cref="Modifiers" /> collection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddModifier(DataBindingModifier<TLayerProperty, TProperty> modifier)
|
public void AddModifier(DataBindingModifier<TLayerProperty, TProperty> modifier)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBinding");
|
||||||
|
|
||||||
if (!_modifiers.Contains(modifier))
|
if (!_modifiers.Contains(modifier))
|
||||||
{
|
{
|
||||||
modifier.DataBinding = this;
|
modifier.DataBinding = this;
|
||||||
@ -122,6 +144,9 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveModifier(DataBindingModifier<TLayerProperty, TProperty> modifier)
|
public void RemoveModifier(DataBindingModifier<TLayerProperty, TProperty> modifier)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBinding");
|
||||||
|
|
||||||
if (_modifiers.Contains(modifier))
|
if (_modifiers.Contains(modifier))
|
||||||
{
|
{
|
||||||
modifier.DataBinding = null;
|
modifier.DataBinding = null;
|
||||||
@ -138,6 +163,9 @@ namespace Artemis.Core
|
|||||||
/// <param name="path">The path pointing to the source inside the data model</param>
|
/// <param name="path">The path pointing to the source inside the data model</param>
|
||||||
public void UpdateSource(DataModel dataModel, string path)
|
public void UpdateSource(DataModel dataModel, string path)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBinding");
|
||||||
|
|
||||||
if (dataModel != null && path == null)
|
if (dataModel != null && path == null)
|
||||||
throw new ArtemisCoreException("If a data model is provided, a path is also required");
|
throw new ArtemisCoreException("If a data model is provided, a path is also required");
|
||||||
if (dataModel == null && path != null)
|
if (dataModel == null && path != null)
|
||||||
@ -161,6 +189,9 @@ namespace Artemis.Core
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public TProperty GetValue(TProperty baseValue)
|
public TProperty GetValue(TProperty baseValue)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBinding");
|
||||||
|
|
||||||
if (CompiledTargetAccessor == null || Converter == null)
|
if (CompiledTargetAccessor == null || Converter == null)
|
||||||
return baseValue;
|
return baseValue;
|
||||||
|
|
||||||
@ -198,30 +229,18 @@ namespace Artemis.Core
|
|||||||
return SourceDataModel?.GetTypeAtPath(SourcePropertyPath);
|
return SourceDataModel?.GetTypeAtPath(SourcePropertyPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
private void Initialize()
|
||||||
public void Apply()
|
|
||||||
{
|
{
|
||||||
if (Converter == null)
|
DataModelStore.DataModelAdded += DataModelStoreOnDataModelAdded;
|
||||||
return;
|
DataModelStore.DataModelRemoved += DataModelStoreOnDataModelRemoved;
|
||||||
|
|
||||||
var value = GetValue(Converter.GetValue());
|
|
||||||
Converter.ApplyValue(GetValue(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void Initialize(IDataModelService dataModelService, IDataBindingService dataBindingService)
|
|
||||||
{
|
|
||||||
// Source
|
// Source
|
||||||
if (Entity.SourceDataModelGuid != null && SourceDataModel == null)
|
if (Entity.SourceDataModelGuid != null && SourceDataModel == null)
|
||||||
{
|
{
|
||||||
var dataModel = dataModelService.GetPluginDataModelByGuid(Entity.SourceDataModelGuid.Value);
|
var dataModel = DataModelStore.Get(Entity.SourceDataModelGuid.Value)?.DataModel;
|
||||||
if (dataModel != null && dataModel.ContainsPath(Entity.SourcePropertyPath))
|
if (dataModel != null && dataModel.ContainsPath(Entity.SourcePropertyPath))
|
||||||
UpdateSource(dataModel, Entity.SourcePropertyPath);
|
UpdateSource(dataModel, Entity.SourcePropertyPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifiers
|
|
||||||
foreach (var dataBindingModifier in Modifiers)
|
|
||||||
dataBindingModifier.Initialize(dataModelService, dataBindingService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetEasing(TProperty value)
|
private void ResetEasing(TProperty value)
|
||||||
@ -283,6 +302,8 @@ namespace Artemis.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Load()
|
public void Load()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBinding");
|
||||||
// General
|
// General
|
||||||
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetProperty);
|
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetProperty);
|
||||||
ApplyRegistration(registration);
|
ApplyRegistration(registration);
|
||||||
@ -301,6 +322,9 @@ namespace Artemis.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBinding");
|
||||||
|
|
||||||
if (!LayerProperty.Entity.DataBindingEntities.Contains(Entity))
|
if (!LayerProperty.Entity.DataBindingEntities.Contains(Entity))
|
||||||
LayerProperty.Entity.DataBindingEntities.Add(Entity);
|
LayerProperty.Entity.DataBindingEntities.Add(Entity);
|
||||||
|
|
||||||
@ -311,9 +335,12 @@ namespace Artemis.Core
|
|||||||
Entity.EasingFunction = (int) EasingFunction;
|
Entity.EasingFunction = (int) EasingFunction;
|
||||||
|
|
||||||
// Data model
|
// Data model
|
||||||
Entity.SourceDataModelGuid = SourceDataModel?.PluginInfo?.Guid;
|
if (SourceDataModel != null)
|
||||||
Entity.SourcePropertyPath = SourcePropertyPath;
|
{
|
||||||
|
Entity.SourceDataModelGuid = SourceDataModel.PluginInfo.Guid;
|
||||||
|
Entity.SourcePropertyPath = SourcePropertyPath;
|
||||||
|
}
|
||||||
|
|
||||||
// Modifiers
|
// Modifiers
|
||||||
Entity.Modifiers.Clear();
|
Entity.Modifiers.Clear();
|
||||||
foreach (var dataBindingModifier in Modifiers)
|
foreach (var dataBindingModifier in Modifiers)
|
||||||
@ -322,6 +349,25 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Event handlers
|
||||||
|
|
||||||
|
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
|
||||||
|
{
|
||||||
|
var dataModel = e.Registration.DataModel;
|
||||||
|
if (dataModel.PluginInfo.Guid == Entity.SourceDataModelGuid && dataModel.ContainsPath(Entity.SourcePropertyPath))
|
||||||
|
UpdateSource(dataModel, Entity.SourcePropertyPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataModelStoreOnDataModelRemoved(object sender, DataModelStoreEvent e)
|
||||||
|
{
|
||||||
|
if (SourceDataModel != e.Registration.DataModel)
|
||||||
|
return;
|
||||||
|
SourceDataModel = null;
|
||||||
|
CompiledTargetAccessor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -335,6 +381,18 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_disposed = true;
|
||||||
|
|
||||||
|
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||||
|
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||||
|
|
||||||
|
foreach (var dataBindingModifier in Modifiers)
|
||||||
|
dataBindingModifier.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using Artemis.Core.DataModelExpansions;
|
using Artemis.Core.DataModelExpansions;
|
||||||
using Artemis.Core.Services;
|
|
||||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@ -12,6 +11,7 @@ namespace Artemis.Core
|
|||||||
public class DataBindingModifier<TLayerProperty, TProperty> : IDataBindingModifier
|
public class DataBindingModifier<TLayerProperty, TProperty> : IDataBindingModifier
|
||||||
{
|
{
|
||||||
private DataBinding<TLayerProperty, TProperty> _dataBinding;
|
private DataBinding<TLayerProperty, TProperty> _dataBinding;
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="DataBindingModifier{TLayerProperty,TProperty}" /> class
|
/// Creates a new instance of the <see cref="DataBindingModifier{TLayerProperty,TProperty}" /> class
|
||||||
@ -22,6 +22,7 @@ namespace Artemis.Core
|
|||||||
ParameterType = parameterType;
|
ParameterType = parameterType;
|
||||||
Entity = new DataBindingModifierEntity();
|
Entity = new DataBindingModifierEntity();
|
||||||
Save();
|
Save();
|
||||||
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal DataBindingModifier(DataBinding<TLayerProperty, TProperty> dataBinding, DataBindingModifierEntity entity)
|
internal DataBindingModifier(DataBinding<TLayerProperty, TProperty> dataBinding, DataBindingModifierEntity entity)
|
||||||
@ -29,6 +30,7 @@ namespace Artemis.Core
|
|||||||
DataBinding = dataBinding;
|
DataBinding = dataBinding;
|
||||||
Entity = entity;
|
Entity = entity;
|
||||||
Load();
|
Load();
|
||||||
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -82,6 +84,52 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal DataBindingModifierEntity Entity { get; set; }
|
internal DataBindingModifierEntity Entity { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBindingModifier");
|
||||||
|
|
||||||
|
if (!DataBinding.Entity.Modifiers.Contains(Entity))
|
||||||
|
DataBinding.Entity.Modifiers.Add(Entity);
|
||||||
|
|
||||||
|
// Modifier
|
||||||
|
if (ModifierType != null)
|
||||||
|
{
|
||||||
|
Entity.ModifierType = ModifierType.GetType().Name;
|
||||||
|
Entity.ModifierTypePluginGuid = ModifierType.PluginInfo.Guid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// General
|
||||||
|
Entity.Order = Order;
|
||||||
|
Entity.ParameterType = (int) ParameterType;
|
||||||
|
|
||||||
|
// Parameter
|
||||||
|
if (ParameterDataModel != null)
|
||||||
|
{
|
||||||
|
Entity.ParameterDataModelGuid = ParameterDataModel.PluginInfo.Guid;
|
||||||
|
Entity.ParameterPropertyPath = ParameterPropertyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity.ParameterStaticValue = JsonConvert.SerializeObject(ParameterStaticValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Load()
|
||||||
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBindingModifier");
|
||||||
|
|
||||||
|
// Modifier type is done during Initialize
|
||||||
|
|
||||||
|
// General
|
||||||
|
Order = Entity.Order;
|
||||||
|
ParameterType = (ProfileRightSideType) Entity.ParameterType;
|
||||||
|
|
||||||
|
// Parameter is done during initialize
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Applies the modifier to the provided value
|
/// Applies the modifier to the provided value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -89,6 +137,9 @@ namespace Artemis.Core
|
|||||||
/// <returns>The modified value</returns>
|
/// <returns>The modified value</returns>
|
||||||
public object Apply(object currentValue)
|
public object Apply(object currentValue)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBindingModifier");
|
||||||
|
|
||||||
if (ModifierType == null)
|
if (ModifierType == null)
|
||||||
return currentValue;
|
return currentValue;
|
||||||
|
|
||||||
@ -113,6 +164,9 @@ namespace Artemis.Core
|
|||||||
/// <param name="modifierType"></param>
|
/// <param name="modifierType"></param>
|
||||||
public void UpdateModifierType(DataBindingModifierType modifierType)
|
public void UpdateModifierType(DataBindingModifierType modifierType)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBindingModifier");
|
||||||
|
|
||||||
// Calling CreateExpression will clear compiled expressions
|
// Calling CreateExpression will clear compiled expressions
|
||||||
if (modifierType == null)
|
if (modifierType == null)
|
||||||
{
|
{
|
||||||
@ -139,6 +193,9 @@ namespace Artemis.Core
|
|||||||
/// <param name="path">The path pointing to the parameter inside the data model</param>
|
/// <param name="path">The path pointing to the parameter inside the data model</param>
|
||||||
public void UpdateParameter(DataModel dataModel, string path)
|
public void UpdateParameter(DataModel dataModel, string path)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBindingModifier");
|
||||||
|
|
||||||
if (dataModel != null && path == null)
|
if (dataModel != null && path == null)
|
||||||
throw new ArtemisCoreException("If a data model is provided, a path is also required");
|
throw new ArtemisCoreException("If a data model is provided, a path is also required");
|
||||||
if (dataModel == null && path != null)
|
if (dataModel == null && path != null)
|
||||||
@ -163,6 +220,9 @@ namespace Artemis.Core
|
|||||||
/// <param name="staticValue">The static value to use as a parameter</param>
|
/// <param name="staticValue">The static value to use as a parameter</param>
|
||||||
public void UpdateParameter(object staticValue)
|
public void UpdateParameter(object staticValue)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("DataBindingModifier");
|
||||||
|
|
||||||
ParameterType = ProfileRightSideType.Static;
|
ParameterType = ProfileRightSideType.Static;
|
||||||
ParameterDataModel = null;
|
ParameterDataModel = null;
|
||||||
ParameterPropertyPath = null;
|
ParameterPropertyPath = null;
|
||||||
@ -183,12 +243,17 @@ namespace Artemis.Core
|
|||||||
CreateExpression();
|
CreateExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Initialize(IDataModelService dataModelService, IDataBindingService dataBindingService)
|
private void Initialize()
|
||||||
{
|
{
|
||||||
|
DataBindingModifierTypeStore.DataBindingModifierAdded += DataBindingModifierTypeStoreOnDataBindingModifierAdded;
|
||||||
|
DataBindingModifierTypeStore.DataBindingModifierRemoved += DataBindingModifierTypeStoreOnDataBindingModifierRemoved;
|
||||||
|
DataModelStore.DataModelAdded += DataModelStoreOnDataModelAdded;
|
||||||
|
DataModelStore.DataModelRemoved += DataModelStoreOnDataModelRemoved;
|
||||||
|
|
||||||
// Modifier type
|
// Modifier type
|
||||||
if (Entity.ModifierTypePluginGuid != null && ModifierType == null)
|
if (Entity.ModifierTypePluginGuid != null && ModifierType == null)
|
||||||
{
|
{
|
||||||
var modifierType = dataBindingService.GetModifierType(Entity.ModifierTypePluginGuid.Value, Entity.ModifierType);
|
var modifierType = DataBindingModifierTypeStore.Get(Entity.ModifierTypePluginGuid.Value, Entity.ModifierType)?.DataBindingModifierType;
|
||||||
if (modifierType != null)
|
if (modifierType != null)
|
||||||
UpdateModifierType(modifierType);
|
UpdateModifierType(modifierType);
|
||||||
}
|
}
|
||||||
@ -196,7 +261,7 @@ namespace Artemis.Core
|
|||||||
// Dynamic parameter
|
// Dynamic parameter
|
||||||
if (ParameterType == ProfileRightSideType.Dynamic && Entity.ParameterDataModelGuid != null && ParameterDataModel == null)
|
if (ParameterType == ProfileRightSideType.Dynamic && Entity.ParameterDataModelGuid != null && ParameterDataModel == null)
|
||||||
{
|
{
|
||||||
var dataModel = dataModelService.GetPluginDataModelByGuid(Entity.ParameterDataModelGuid.Value);
|
var dataModel = DataModelStore.Get(Entity.ParameterDataModelGuid.Value)?.DataModel;
|
||||||
if (dataModel != null && dataModel.ContainsPath(Entity.ParameterPropertyPath))
|
if (dataModel != null && dataModel.ContainsPath(Entity.ParameterPropertyPath))
|
||||||
UpdateParameter(dataModel, Entity.ParameterPropertyPath);
|
UpdateParameter(dataModel, Entity.ParameterPropertyPath);
|
||||||
}
|
}
|
||||||
@ -214,7 +279,7 @@ namespace Artemis.Core
|
|||||||
// If deserialization fails, use the type's default
|
// If deserialization fails, use the type's default
|
||||||
catch (JsonSerializationException e)
|
catch (JsonSerializationException e)
|
||||||
{
|
{
|
||||||
dataBindingService.LogModifierDeserializationFailure(GetType().Name, e);
|
DeserializationLogger.LogModifierDeserializationFailure(GetType().Name, e);
|
||||||
staticValue = Activator.CreateInstance(targetType);
|
staticValue = Activator.CreateInstance(targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,39 +287,6 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void Save()
|
|
||||||
{
|
|
||||||
if (!DataBinding.Entity.Modifiers.Contains(Entity))
|
|
||||||
DataBinding.Entity.Modifiers.Add(Entity);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void Load()
|
|
||||||
{
|
|
||||||
// Modifier type is done during Initialize
|
|
||||||
|
|
||||||
// General
|
|
||||||
Order = Entity.Order;
|
|
||||||
ParameterType = (ProfileRightSideType) Entity.ParameterType;
|
|
||||||
|
|
||||||
// Parameter is done during initialize
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void CreateExpression()
|
private void CreateExpression()
|
||||||
{
|
{
|
||||||
CompiledParameterAccessor = null;
|
CompiledParameterAccessor = null;
|
||||||
@ -286,5 +318,51 @@ namespace Artemis.Core
|
|||||||
Expression.Property
|
Expression.Property
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Event handlers
|
||||||
|
|
||||||
|
private void DataBindingModifierTypeStoreOnDataBindingModifierAdded(object sender, DataBindingModifierTypeStoreEvent e)
|
||||||
|
{
|
||||||
|
if (ModifierType != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var modifierType = e.TypeRegistration.DataBindingModifierType;
|
||||||
|
if (modifierType.PluginInfo.Guid == Entity.ModifierTypePluginGuid && modifierType.GetType().Name == Entity.ModifierType)
|
||||||
|
UpdateModifierType(modifierType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataBindingModifierTypeStoreOnDataBindingModifierRemoved(object sender, DataBindingModifierTypeStoreEvent e)
|
||||||
|
{
|
||||||
|
if (e.TypeRegistration.DataBindingModifierType == ModifierType)
|
||||||
|
UpdateModifierType(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
|
||||||
|
{
|
||||||
|
var dataModel = e.Registration.DataModel;
|
||||||
|
if (dataModel.PluginInfo.Guid == Entity.ParameterDataModelGuid && dataModel.ContainsPath(Entity.ParameterPropertyPath))
|
||||||
|
UpdateParameter(dataModel, Entity.ParameterPropertyPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataModelStoreOnDataModelRemoved(object sender, DataModelStoreEvent e)
|
||||||
|
{
|
||||||
|
if (e.Registration.DataModel != ParameterDataModel)
|
||||||
|
return;
|
||||||
|
ParameterDataModel = null;
|
||||||
|
CompiledParameterAccessor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_disposed = true;
|
||||||
|
|
||||||
|
DataBindingModifierTypeStore.DataBindingModifierAdded -= DataBindingModifierTypeStoreOnDataBindingModifierAdded;
|
||||||
|
DataBindingModifierTypeStore.DataBindingModifierRemoved -= DataBindingModifierTypeStoreOnDataBindingModifierRemoved;
|
||||||
|
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||||
|
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,20 +1,14 @@
|
|||||||
using Artemis.Core.DataModelExpansions;
|
using System;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.DataModelExpansions;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a data binding that binds a certain <see cref="LayerProperty{T}" /> to a value inside a <see cref="DataModel" />
|
/// Represents a data binding that binds a certain <see cref="LayerProperty{T}" /> to a value inside a
|
||||||
|
/// <see cref="DataModel" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDataBinding : IStorageModel, IUpdateModel
|
public interface IDataBinding : IStorageModel, IUpdateModel, IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// (Re)initializes the data binding
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dataModelService"></param>
|
|
||||||
/// <param name="dataBindingService"></param>
|
|
||||||
void Initialize(IDataModelService dataModelService, IDataBindingService dataBindingService);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Applies the data binding to the layer property
|
/// Applies the data binding to the layer property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
namespace Artemis.Core
|
using System;
|
||||||
|
|
||||||
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Modifies a data model value in a way defined by the modifier type
|
/// Modifies a data model value in a way defined by the modifier type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDataBindingModifier : IStorageModel
|
public interface IDataBindingModifier : IStorageModel, IDisposable
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Core.Services;
|
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -10,9 +9,6 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class DataBindingModifierType
|
public abstract class DataBindingModifierType
|
||||||
{
|
{
|
||||||
private IDataBindingService _dataBindingService;
|
|
||||||
private bool _registered;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the plugin info this data binding modifier belongs to
|
/// Gets the plugin info this data binding modifier belongs to
|
||||||
/// <para>Note: Not set until after registering</para>
|
/// <para>Note: Not set until after registering</para>
|
||||||
@ -63,35 +59,5 @@ namespace Artemis.Core
|
|||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>The modified value, must be a value of a type contained in <see cref="CompatibleTypes" /></returns>
|
/// <returns>The modified value, must be a value of a type contained in <see cref="CompatibleTypes" /></returns>
|
||||||
public abstract object Apply(object currentValue, object parameterValue);
|
public abstract object Apply(object currentValue, object parameterValue);
|
||||||
|
|
||||||
internal void Register(PluginInfo pluginInfo, IDataBindingService dataBindingService)
|
|
||||||
{
|
|
||||||
if (_registered)
|
|
||||||
return;
|
|
||||||
|
|
||||||
PluginInfo = pluginInfo;
|
|
||||||
_dataBindingService = dataBindingService;
|
|
||||||
|
|
||||||
if (PluginInfo != Constants.CorePluginInfo)
|
|
||||||
PluginInfo.Instance.PluginDisabled += InstanceOnPluginDisabled;
|
|
||||||
|
|
||||||
_registered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void Unsubscribe()
|
|
||||||
{
|
|
||||||
if (!_registered)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (PluginInfo != Constants.CorePluginInfo)
|
|
||||||
PluginInfo.Instance.PluginDisabled -= InstanceOnPluginDisabled;
|
|
||||||
_registered = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InstanceOnPluginDisabled(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
// The service will call Unsubscribe
|
|
||||||
_dataBindingService.RemoveModifierType(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using Artemis.Storage.Entities.Profile;
|
using System;
|
||||||
|
using Artemis.Storage.Entities.Profile;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -9,7 +10,7 @@ namespace Artemis.Core
|
|||||||
/// initialize these for you.
|
/// initialize these for you.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ILayerProperty : IStorageModel, IUpdateModel
|
public interface ILayerProperty : IStorageModel, IUpdateModel, IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the layer property
|
/// Initializes the layer property
|
||||||
|
|||||||
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Artemis.Core.Services;
|
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@ -19,6 +18,8 @@ namespace Artemis.Core
|
|||||||
/// <typeparam name="T">The type of property encapsulated in this layer property</typeparam>
|
/// <typeparam name="T">The type of property encapsulated in this layer property</typeparam>
|
||||||
public abstract class LayerProperty<T> : ILayerProperty
|
public abstract class LayerProperty<T> : ILayerProperty
|
||||||
{
|
{
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="LayerProperty{T}" /> class
|
/// Creates a new instance of the <see cref="LayerProperty{T}" /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -37,6 +38,9 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Update(double deltaTime)
|
public void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
CurrentValue = BaseValue;
|
CurrentValue = BaseValue;
|
||||||
|
|
||||||
UpdateKeyframes();
|
UpdateKeyframes();
|
||||||
@ -136,6 +140,9 @@ namespace Artemis.Core
|
|||||||
/// </param>
|
/// </param>
|
||||||
public void SetCurrentValue(T value, TimeSpan? time)
|
public void SetCurrentValue(T value, TimeSpan? time)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
if (time == null || !KeyframesEnabled || !KeyframesSupported)
|
if (time == null || !KeyframesEnabled || !KeyframesSupported)
|
||||||
BaseValue = value;
|
BaseValue = value;
|
||||||
else
|
else
|
||||||
@ -159,6 +166,9 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void ApplyDefaultValue()
|
public void ApplyDefaultValue()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
BaseValue = DefaultValue;
|
BaseValue = DefaultValue;
|
||||||
CurrentValue = DefaultValue;
|
CurrentValue = DefaultValue;
|
||||||
}
|
}
|
||||||
@ -212,6 +222,9 @@ namespace Artemis.Core
|
|||||||
/// <param name="keyframe">The keyframe to add</param>
|
/// <param name="keyframe">The keyframe to add</param>
|
||||||
public void AddKeyframe(LayerPropertyKeyframe<T> keyframe)
|
public void AddKeyframe(LayerPropertyKeyframe<T> keyframe)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
if (_keyframes.Contains(keyframe))
|
if (_keyframes.Contains(keyframe))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -229,6 +242,9 @@ namespace Artemis.Core
|
|||||||
/// <param name="keyframe">The keyframe to remove</param>
|
/// <param name="keyframe">The keyframe to remove</param>
|
||||||
public LayerPropertyKeyframe<T> CopyKeyframe(LayerPropertyKeyframe<T> keyframe)
|
public LayerPropertyKeyframe<T> CopyKeyframe(LayerPropertyKeyframe<T> keyframe)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
var newKeyframe = new LayerPropertyKeyframe<T>(
|
var newKeyframe = new LayerPropertyKeyframe<T>(
|
||||||
keyframe.Value,
|
keyframe.Value,
|
||||||
keyframe.Position,
|
keyframe.Position,
|
||||||
@ -246,6 +262,9 @@ namespace Artemis.Core
|
|||||||
/// <param name="keyframe">The keyframe to remove</param>
|
/// <param name="keyframe">The keyframe to remove</param>
|
||||||
public void RemoveKeyframe(LayerPropertyKeyframe<T> keyframe)
|
public void RemoveKeyframe(LayerPropertyKeyframe<T> keyframe)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
if (!_keyframes.Contains(keyframe))
|
if (!_keyframes.Contains(keyframe))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -260,6 +279,9 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void ClearKeyframes()
|
public void ClearKeyframes()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
var keyframes = new List<LayerPropertyKeyframe<T>>(_keyframes);
|
var keyframes = new List<LayerPropertyKeyframe<T>>(_keyframes);
|
||||||
foreach (var layerPropertyKeyframe in keyframes)
|
foreach (var layerPropertyKeyframe in keyframes)
|
||||||
RemoveKeyframe(layerPropertyKeyframe);
|
RemoveKeyframe(layerPropertyKeyframe);
|
||||||
@ -313,6 +335,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
public DataBindingRegistration<T, TProperty> GetDataBindingRegistration<TProperty>(string propertyName)
|
public DataBindingRegistration<T, TProperty> GetDataBindingRegistration<TProperty>(string propertyName)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
var match = _dataBindingRegistrations.FirstOrDefault(r => r is DataBindingRegistration<T, TProperty> registration &&
|
var match = _dataBindingRegistrations.FirstOrDefault(r => r is DataBindingRegistration<T, TProperty> registration &&
|
||||||
registration.Property.Name == propertyName);
|
registration.Property.Name == propertyName);
|
||||||
return (DataBindingRegistration<T, TProperty>) match;
|
return (DataBindingRegistration<T, TProperty>) match;
|
||||||
@ -320,6 +345,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
public void RegisterDataBindingProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda, DataBindingConverter<T, TProperty> converter)
|
public void RegisterDataBindingProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda, DataBindingConverter<T, TProperty> converter)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
// If the lambda references to itself, use the property info of public new T CurrentValue
|
// If the lambda references to itself, use the property info of public new T CurrentValue
|
||||||
PropertyInfo propertyInfo;
|
PropertyInfo propertyInfo;
|
||||||
string path = null;
|
string path = null;
|
||||||
@ -353,6 +381,9 @@ namespace Artemis.Core
|
|||||||
/// <returns>The newly created data binding</returns>
|
/// <returns>The newly created data binding</returns>
|
||||||
public DataBinding<T, TProperty> EnableDataBinding<TProperty>(DataBindingRegistration<T, TProperty> dataBindingRegistration)
|
public DataBinding<T, TProperty> EnableDataBinding<TProperty>(DataBindingRegistration<T, TProperty> dataBindingRegistration)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
if (dataBindingRegistration.LayerProperty != this)
|
if (dataBindingRegistration.LayerProperty != this)
|
||||||
throw new ArtemisCoreException("Cannot enable a data binding using a data binding registration of a different layer property");
|
throw new ArtemisCoreException("Cannot enable a data binding using a data binding registration of a different layer property");
|
||||||
|
|
||||||
@ -368,6 +399,9 @@ namespace Artemis.Core
|
|||||||
/// <param name="dataBinding">The data binding to remove</param>
|
/// <param name="dataBinding">The data binding to remove</param>
|
||||||
public void DisableDataBinding<TProperty>(DataBinding<T, TProperty> dataBinding)
|
public void DisableDataBinding<TProperty>(DataBinding<T, TProperty> dataBinding)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
_dataBindings.Remove(dataBinding);
|
_dataBindings.Remove(dataBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,12 +414,6 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void InitializeDataBindings(IDataModelService dataModelService, IDataBindingService dataBindingService)
|
|
||||||
{
|
|
||||||
foreach (var dataBinding in _dataBindings)
|
|
||||||
dataBinding.Initialize(dataModelService, dataBindingService);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Storage
|
#region Storage
|
||||||
@ -402,6 +430,9 @@ namespace Artemis.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Initialize(RenderProfileElement profileElement, LayerPropertyGroup group, PropertyEntity entity, bool fromStorage, PropertyDescriptionAttribute description)
|
public void Initialize(RenderProfileElement profileElement, LayerPropertyGroup group, PropertyEntity entity, bool fromStorage, PropertyDescriptionAttribute description)
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
_isInitialized = true;
|
_isInitialized = true;
|
||||||
|
|
||||||
ProfileElement = profileElement ?? throw new ArgumentNullException(nameof(profileElement));
|
ProfileElement = profileElement ?? throw new ArgumentNullException(nameof(profileElement));
|
||||||
@ -409,13 +440,16 @@ namespace Artemis.Core
|
|||||||
Entity = entity ?? throw new ArgumentNullException(nameof(entity));
|
Entity = entity ?? throw new ArgumentNullException(nameof(entity));
|
||||||
PropertyDescription = description ?? throw new ArgumentNullException(nameof(description));
|
PropertyDescription = description ?? throw new ArgumentNullException(nameof(description));
|
||||||
IsLoadedFromStorage = fromStorage;
|
IsLoadedFromStorage = fromStorage;
|
||||||
|
|
||||||
LayerPropertyGroup.PropertyGroupUpdating += (sender, args) => Update(args.DeltaTime);
|
LayerPropertyGroup.PropertyGroupUpdating += (sender, args) => Update(args.DeltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Load()
|
public void Load()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
if (!_isInitialized)
|
if (!_isInitialized)
|
||||||
throw new ArtemisCoreException("Layer property is not yet initialized");
|
throw new ArtemisCoreException("Layer property is not yet initialized");
|
||||||
|
|
||||||
@ -467,6 +501,9 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerProperty");
|
||||||
|
|
||||||
if (!_isInitialized)
|
if (!_isInitialized)
|
||||||
throw new ArtemisCoreException("Layer property is not yet initialized");
|
throw new ArtemisCoreException("Layer property is not yet initialized");
|
||||||
|
|
||||||
@ -550,5 +587,14 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_disposed = true;
|
||||||
|
|
||||||
|
foreach (var dataBinding in _dataBindings)
|
||||||
|
dataBinding.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,7 +6,6 @@ using System.Reflection;
|
|||||||
using Artemis.Core.LayerBrushes;
|
using Artemis.Core.LayerBrushes;
|
||||||
using Artemis.Core.LayerEffects;
|
using Artemis.Core.LayerEffects;
|
||||||
using Artemis.Core.Properties;
|
using Artemis.Core.Properties;
|
||||||
using Artemis.Core.Services;
|
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
@ -15,6 +14,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
private readonly List<ILayerProperty> _layerProperties;
|
private readonly List<ILayerProperty> _layerProperties;
|
||||||
private readonly List<LayerPropertyGroup> _layerPropertyGroups;
|
private readonly List<LayerPropertyGroup> _layerPropertyGroups;
|
||||||
|
private bool _disposed;
|
||||||
private bool _isHidden;
|
private bool _isHidden;
|
||||||
|
|
||||||
protected LayerPropertyGroup()
|
protected LayerPropertyGroup()
|
||||||
@ -23,6 +23,9 @@ namespace Artemis.Core
|
|||||||
_layerPropertyGroups = new List<LayerPropertyGroup>();
|
_layerPropertyGroups = new List<LayerPropertyGroup>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the description of this group
|
||||||
|
/// </summary>
|
||||||
public PropertyGroupDescriptionAttribute GroupDescription { get; internal set; }
|
public PropertyGroupDescriptionAttribute GroupDescription { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -83,19 +86,30 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ReadOnlyCollection<LayerPropertyGroup> LayerPropertyGroups => _layerPropertyGroups.AsReadOnly();
|
public ReadOnlyCollection<LayerPropertyGroup> LayerPropertyGroups => _layerPropertyGroups.AsReadOnly();
|
||||||
|
|
||||||
|
#region IDisposable
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
_disposed = true;
|
||||||
DisableProperties();
|
DisableProperties();
|
||||||
|
|
||||||
|
foreach (var layerProperty in _layerProperties)
|
||||||
|
layerProperty.Dispose();
|
||||||
foreach (var layerPropertyGroup in _layerPropertyGroups)
|
foreach (var layerPropertyGroup in _layerPropertyGroups)
|
||||||
layerPropertyGroup.Dispose();
|
layerPropertyGroup.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recursively gets all layer properties on this group and any subgroups
|
/// Recursively gets all layer properties on this group and any subgroups
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyCollection<ILayerProperty> GetAllLayerProperties()
|
public IReadOnlyCollection<ILayerProperty> GetAllLayerProperties()
|
||||||
{
|
{
|
||||||
|
if (_disposed)
|
||||||
|
throw new ObjectDisposedException("LayerPropertyGroup");
|
||||||
|
|
||||||
if (!PropertiesInitialized)
|
if (!PropertiesInitialized)
|
||||||
return new List<ILayerProperty>();
|
return new List<ILayerProperty>();
|
||||||
|
|
||||||
@ -240,7 +254,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Events
|
#region Events
|
||||||
|
|
||||||
internal event EventHandler<LayerPropertyGroupUpdatingEventArgs> PropertyGroupUpdating;
|
internal event EventHandler<LayerPropertyGroupUpdatingEventArgs> PropertyGroupUpdating;
|
||||||
|
|||||||
@ -34,7 +34,7 @@ namespace Artemis.Core
|
|||||||
UndoStack = new Stack<string>();
|
UndoStack = new Stack<string>();
|
||||||
RedoStack = new Stack<string>();
|
RedoStack = new Stack<string>();
|
||||||
|
|
||||||
ApplyToProfile();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileModule Module { get; }
|
public ProfileModule Module { get; }
|
||||||
@ -86,7 +86,7 @@ namespace Artemis.Core
|
|||||||
return (Folder) Children.Single();
|
return (Folder) Children.Single();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ApplyToProfile()
|
internal override void Load()
|
||||||
{
|
{
|
||||||
if (_disposed)
|
if (_disposed)
|
||||||
throw new ObjectDisposedException("Profile");
|
throw new ObjectDisposedException("Profile");
|
||||||
|
|||||||
@ -12,6 +12,12 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
public abstract class RenderProfileElement : ProfileElement
|
public abstract class RenderProfileElement : ProfileElement
|
||||||
{
|
{
|
||||||
|
protected RenderProfileElement()
|
||||||
|
{
|
||||||
|
LayerEffectStore.LayerEffectAdded += LayerEffectStoreOnLayerEffectAdded;
|
||||||
|
LayerEffectStore.LayerEffectRemoved += LayerEffectStoreOnLayerEffectRemoved;
|
||||||
|
}
|
||||||
|
|
||||||
internal void ApplyRenderElementDefaults()
|
internal void ApplyRenderElementDefaults()
|
||||||
{
|
{
|
||||||
MainSegmentLength = TimeSpan.FromSeconds(5);
|
MainSegmentLength = TimeSpan.FromSeconds(5);
|
||||||
@ -270,6 +276,7 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal void ActivateLayerEffect(BaseLayerEffect layerEffect)
|
internal void ActivateLayerEffect(BaseLayerEffect layerEffect)
|
||||||
{
|
{
|
||||||
_layerEffects.Add(layerEffect);
|
_layerEffects.Add(layerEffect);
|
||||||
@ -285,6 +292,16 @@ namespace Artemis.Core
|
|||||||
OnLayerEffectsUpdated();
|
OnLayerEffectsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LayerEffectStoreOnLayerEffectRemoved(object? sender, LayerEffectStoreEvent e)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LayerEffectStoreOnLayerEffectAdded(object? sender, LayerEffectStoreEvent e)
|
||||||
|
{
|
||||||
|
ActivateEffects();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Conditions
|
#region Conditions
|
||||||
|
|||||||
@ -17,21 +17,17 @@ namespace Artemis.Core.Services
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IPluginService _pluginService;
|
private readonly IPluginService _pluginService;
|
||||||
private readonly IProfileRepository _profileRepository;
|
private readonly IProfileRepository _profileRepository;
|
||||||
private readonly IRenderElementService _renderElementService;
|
|
||||||
private readonly ISurfaceService _surfaceService;
|
private readonly ISurfaceService _surfaceService;
|
||||||
|
|
||||||
internal ProfileService(ILogger logger, IPluginService pluginService, ISurfaceService surfaceService, IRenderElementService renderElementService, IProfileRepository profileRepository)
|
internal ProfileService(ILogger logger, IPluginService pluginService, ISurfaceService surfaceService, IProfileRepository profileRepository)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_pluginService = pluginService;
|
_pluginService = pluginService;
|
||||||
_surfaceService = surfaceService;
|
_surfaceService = surfaceService;
|
||||||
_renderElementService = renderElementService;
|
|
||||||
_profileRepository = profileRepository;
|
_profileRepository = profileRepository;
|
||||||
|
|
||||||
_surfaceService.ActiveSurfaceConfigurationSelected += OnActiveSurfaceConfigurationSelected;
|
_surfaceService.ActiveSurfaceConfigurationSelected += OnActiveSurfaceConfigurationSelected;
|
||||||
_surfaceService.SurfaceConfigurationUpdated += OnSurfaceConfigurationUpdated;
|
_surfaceService.SurfaceConfigurationUpdated += OnSurfaceConfigurationUpdated;
|
||||||
_pluginService.PluginEnabled += OnPluginToggled;
|
|
||||||
_pluginService.PluginDisabled += OnPluginToggled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonSerializerSettings MementoSettings { get; set; } = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
|
public JsonSerializerSettings MementoSettings { get; set; } = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
|
||||||
@ -186,7 +182,7 @@ namespace Artemis.Core.Services
|
|||||||
profile.RedoStack.Push(memento);
|
profile.RedoStack.Push(memento);
|
||||||
profile.ProfileEntity = JsonConvert.DeserializeObject<ProfileEntity>(top, MementoSettings);
|
profile.ProfileEntity = JsonConvert.DeserializeObject<ProfileEntity>(top, MementoSettings);
|
||||||
|
|
||||||
profile.ApplyToProfile();
|
profile.Load();
|
||||||
InstantiateProfile(profile);
|
InstantiateProfile(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +206,7 @@ namespace Artemis.Core.Services
|
|||||||
profile.UndoStack.Push(memento);
|
profile.UndoStack.Push(memento);
|
||||||
profile.ProfileEntity = JsonConvert.DeserializeObject<ProfileEntity>(top, MementoSettings);
|
profile.ProfileEntity = JsonConvert.DeserializeObject<ProfileEntity>(top, MementoSettings);
|
||||||
|
|
||||||
profile.ApplyToProfile();
|
profile.Load();
|
||||||
InstantiateProfile(profile);
|
InstantiateProfile(profile);
|
||||||
|
|
||||||
_logger.Debug("Redo profile update - Success");
|
_logger.Debug("Redo profile update - Success");
|
||||||
@ -221,9 +217,6 @@ namespace Artemis.Core.Services
|
|||||||
public void InstantiateProfile(Profile profile)
|
public void InstantiateProfile(Profile profile)
|
||||||
{
|
{
|
||||||
profile.PopulateLeds(_surfaceService.ActiveSurface);
|
profile.PopulateLeds(_surfaceService.ActiveSurface);
|
||||||
InitializeLayerProperties(profile);
|
|
||||||
InstantiateLayers(profile);
|
|
||||||
InstantiateFolders(profile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ExportProfile(ProfileDescriptor profileDescriptor)
|
public string ExportProfile(ProfileDescriptor profileDescriptor)
|
||||||
@ -268,67 +261,7 @@ namespace Artemis.Core.Services
|
|||||||
_profileRepository.Save(profileEntity);
|
_profileRepository.Save(profileEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the properties on the layers of the given profile
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="profile"></param>
|
|
||||||
private void InitializeLayerProperties(Profile profile)
|
|
||||||
{
|
|
||||||
foreach (var layer in profile.GetAllLayers())
|
|
||||||
{
|
|
||||||
if (!layer.General.PropertiesInitialized)
|
|
||||||
layer.General.Initialize(layer, "General.", Constants.CorePluginInfo);
|
|
||||||
if (!layer.Transform.PropertiesInitialized)
|
|
||||||
layer.Transform.Initialize(layer, "Transform.", Constants.CorePluginInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Instantiates all plugin-related classes on the folders of the given profile
|
|
||||||
/// </summary>
|
|
||||||
private void InstantiateFolders(Profile profile)
|
|
||||||
{
|
|
||||||
foreach (var folder in profile.GetAllFolders())
|
|
||||||
{
|
|
||||||
// Instantiate effects
|
|
||||||
_renderElementService.InstantiateLayerEffects(folder);
|
|
||||||
// Remove effects of plugins that are disabled
|
|
||||||
var disabledEffects = new List<BaseLayerEffect>(folder.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled));
|
|
||||||
foreach (var layerLayerEffect in disabledEffects)
|
|
||||||
_renderElementService.RemoveLayerEffect(layerLayerEffect);
|
|
||||||
|
|
||||||
_renderElementService.InstantiateDisplayConditions(folder);
|
|
||||||
_renderElementService.InstantiateDataBindings(folder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Instantiates all plugin-related classes on the layers of the given profile
|
|
||||||
/// </summary>
|
|
||||||
private void InstantiateLayers(Profile profile)
|
|
||||||
{
|
|
||||||
foreach (var layer in profile.GetAllLayers())
|
|
||||||
{
|
|
||||||
// Instantiate brush
|
|
||||||
if (layer.LayerBrush == null)
|
|
||||||
_renderElementService.InstantiateLayerBrush(layer);
|
|
||||||
// Remove brush if plugin is disabled
|
|
||||||
else if (!layer.LayerBrush.PluginInfo.Enabled)
|
|
||||||
_renderElementService.DeactivateLayerBrush(layer);
|
|
||||||
|
|
||||||
// Instantiate effects
|
|
||||||
_renderElementService.InstantiateLayerEffects(layer);
|
|
||||||
// Remove effects of plugins that are disabled
|
|
||||||
var disabledEffects = new List<BaseLayerEffect>(layer.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled));
|
|
||||||
foreach (var layerLayerEffect in disabledEffects)
|
|
||||||
_renderElementService.RemoveLayerEffect(layerLayerEffect);
|
|
||||||
|
|
||||||
_renderElementService.InstantiateDisplayConditions(layer);
|
|
||||||
_renderElementService.InstantiateDataBindings(layer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Populates all missing LEDs on all currently active profiles
|
/// Populates all missing LEDs on all currently active profiles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -339,21 +272,7 @@ namespace Artemis.Core.Services
|
|||||||
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
||||||
profileModule.ActiveProfile.PopulateLeds(surface);
|
profileModule.ActiveProfile.PopulateLeds(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Instantiates all missing plugin-related classes on the profile trees of all currently active profiles
|
|
||||||
/// </summary>
|
|
||||||
private void ActiveProfilesInstantiatePlugins()
|
|
||||||
{
|
|
||||||
var profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
|
|
||||||
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
|
||||||
{
|
|
||||||
InstantiateLayers(profileModule.ActiveProfile);
|
|
||||||
InstantiateFolders(profileModule.ActiveProfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Event handlers
|
#region Event handlers
|
||||||
|
|
||||||
private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e)
|
private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e)
|
||||||
@ -366,15 +285,7 @@ namespace Artemis.Core.Services
|
|||||||
if (e.Surface.IsActive)
|
if (e.Surface.IsActive)
|
||||||
ActiveProfilesPopulateLeds(e.Surface);
|
ActiveProfilesPopulateLeds(e.Surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPluginToggled(object sender, PluginEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.PluginInfo.Instance is LayerBrushProvider)
|
|
||||||
ActiveProfilesInstantiatePlugins();
|
|
||||||
if (e.PluginInfo.Instance is LayerEffectProvider)
|
|
||||||
ActiveProfilesInstantiatePlugins();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,21 +37,26 @@ namespace Artemis.Plugins.LayerBrushes.Color.PropertyGroups
|
|||||||
|
|
||||||
protected override void EnableProperties()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
GradientType.BaseValueChanged += OnBaseValueChanged;
|
GradientType.BaseValueChanged += GradientTypeOnBaseValueChanged;
|
||||||
if (ProfileElement is Layer layer)
|
if (ProfileElement is Layer layer)
|
||||||
layer.General.ResizeMode.BaseValueChanged += OnBaseValueChanged;
|
layer.General.ResizeMode.BaseValueChanged += ResizeModeOnBaseValueChanged;
|
||||||
|
|
||||||
UpdateVisibility();
|
UpdateVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DisableProperties()
|
protected override void DisableProperties()
|
||||||
{
|
{
|
||||||
GradientType.BaseValueChanged -= OnBaseValueChanged;
|
GradientType.BaseValueChanged -= GradientTypeOnBaseValueChanged;
|
||||||
if (ProfileElement is Layer layer)
|
if (ProfileElement is Layer layer)
|
||||||
layer.General.ResizeMode.BaseValueChanged -= OnBaseValueChanged;
|
layer.General.ResizeMode.BaseValueChanged -= ResizeModeOnBaseValueChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBaseValueChanged(object sender, LayerPropertyEventArgs e)
|
private void GradientTypeOnBaseValueChanged(object sender, LayerPropertyEventArgs<ColorType> e)
|
||||||
|
{
|
||||||
|
UpdateVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResizeModeOnBaseValueChanged(object sender, LayerPropertyEventArgs<LayerResizeMode> e)
|
||||||
{
|
{
|
||||||
UpdateVisibility();
|
UpdateVisibility();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace Artemis.Plugins.LayerBrushes.Color.PropertyGroups
|
|||||||
protected override void EnableProperties()
|
protected override void EnableProperties()
|
||||||
{
|
{
|
||||||
if (ProfileElement is Layer layer)
|
if (ProfileElement is Layer layer)
|
||||||
layer.General.ResizeMode.BaseValueChanged += OnBaseValueChanged;
|
layer.General.ResizeMode.BaseValueChanged += ResizeModeOnBaseValueChanged;
|
||||||
|
|
||||||
UpdateVisibility();
|
UpdateVisibility();
|
||||||
}
|
}
|
||||||
@ -26,10 +26,10 @@ namespace Artemis.Plugins.LayerBrushes.Color.PropertyGroups
|
|||||||
protected override void DisableProperties()
|
protected override void DisableProperties()
|
||||||
{
|
{
|
||||||
if (ProfileElement is Layer layer)
|
if (ProfileElement is Layer layer)
|
||||||
layer.General.ResizeMode.BaseValueChanged -= OnBaseValueChanged;
|
layer.General.ResizeMode.BaseValueChanged -= ResizeModeOnBaseValueChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBaseValueChanged(object sender, LayerPropertyEventArgs e)
|
private void ResizeModeOnBaseValueChanged(object sender, LayerPropertyEventArgs<LayerResizeMode> e)
|
||||||
{
|
{
|
||||||
UpdateVisibility();
|
UpdateVisibility();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user