mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Profile editor - Finished most of the refactor except databindings
This commit is contained in:
1 parent
5b321b25c9
commit
d49b574bda
56 files changed
+866
-459
No files matched your search
@@ -23,6 +23,7 @@
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayerproperties_005Ctypes/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayershapes/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Csurface/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=placeholders/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=plugins/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=plugins_005Cdatamodelexpansions_005Cattributes/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=plugins_005Cdatamodelexpansions_005Cinternal/@EntryIndexedValue">True</s:Boolean>
|
||||
|
||||
@@ -32,7 +32,13 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// The plugin info used by core components of Artemis
|
||||
/// </summary>
|
||||
public static readonly PluginInfo CorePluginInfo = new PluginInfo {Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core"};
|
||||
public static readonly PluginInfo CorePluginInfo = new PluginInfo
|
||||
{
|
||||
Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core", Enabled = true
|
||||
};
|
||||
|
||||
internal static readonly CorePlugin CorePlugin = new CorePlugin {PluginInfo = CorePluginInfo};
|
||||
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new EffectPlaceholderPlugin {PluginInfo = CorePluginInfo};
|
||||
|
||||
/// <summary>
|
||||
/// A read-only collection containing all primitive numeric types
|
||||
|
||||
+13
-1
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -36,12 +37,23 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void ApplyValue(float value)
|
||||
{
|
||||
if (SetExpression == null)
|
||||
return;
|
||||
|
||||
if (DataBinding.LayerProperty.PropertyDescription.MaxInputValue is float max)
|
||||
value = Math.Min(value, max);
|
||||
if (DataBinding.LayerProperty.PropertyDescription.MinInputValue is float min)
|
||||
value = Math.Max(value, min);
|
||||
|
||||
SetExpression?.Invoke(value);
|
||||
var test = new SKSize(5,5);
|
||||
test.Width = 10;
|
||||
|
||||
SetExpression(DataBinding.LayerProperty.CurrentValue, value);
|
||||
}
|
||||
|
||||
private void Mehtest(ref SKSize test)
|
||||
{
|
||||
test.Width = 20;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void ApplyValue(object value)
|
||||
{
|
||||
SetExpression?.Invoke(value);
|
||||
SetExpression?.Invoke(DataBinding.LayerProperty.CurrentValue, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void ApplyValue(int value)
|
||||
{
|
||||
SetExpression?.Invoke(value);
|
||||
SetExpression?.Invoke(DataBinding.LayerProperty.CurrentValue, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||
|
||||
@@ -14,9 +13,9 @@ namespace Artemis.Core
|
||||
private readonly List<DataBindingModifier<TLayerProperty, TProperty>> _modifiers = new List<DataBindingModifier<TLayerProperty, TProperty>>();
|
||||
|
||||
private TProperty _currentValue;
|
||||
private bool _disposed;
|
||||
private TimeSpan _easingProgress;
|
||||
private TProperty _previousValue;
|
||||
private bool _disposed;
|
||||
|
||||
internal DataBinding(DataBindingRegistration<TLayerProperty, TProperty> dataBindingRegistration)
|
||||
{
|
||||
@@ -53,11 +52,6 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public DataBindingConverter<TLayerProperty, TProperty> Converter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property on the <see cref="LayerProperty" /> this data binding targets
|
||||
/// </summary>
|
||||
public PropertyInfo TargetProperty { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently used instance of the data model that contains the source of the data binding
|
||||
/// </summary>
|
||||
@@ -118,8 +112,21 @@ namespace Artemis.Core
|
||||
if (Converter == null)
|
||||
return;
|
||||
|
||||
var value = GetValue(Converter.GetValue());
|
||||
Converter.ApplyValue(GetValue(value));
|
||||
var converterValue = Converter.GetValue();
|
||||
var value = GetValue(converterValue);
|
||||
Converter.ApplyValue(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
dataBindingModifier.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -218,7 +225,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public Type GetTargetType()
|
||||
{
|
||||
return TargetProperty.PropertyType;
|
||||
return Registration.PropertyExpression.ReturnType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -257,7 +264,6 @@ namespace Artemis.Core
|
||||
|
||||
Converter = dataBindingRegistration?.Converter;
|
||||
Registration = dataBindingRegistration;
|
||||
TargetProperty = dataBindingRegistration?.Property;
|
||||
|
||||
if (GetTargetType().IsValueType)
|
||||
{
|
||||
@@ -305,7 +311,7 @@ namespace Artemis.Core
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DataBinding");
|
||||
// General
|
||||
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetProperty);
|
||||
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetExpression);
|
||||
ApplyRegistration(registration);
|
||||
|
||||
Mode = (DataBindingMode) Entity.DataBindingMode;
|
||||
@@ -329,7 +335,7 @@ namespace Artemis.Core
|
||||
LayerProperty.Entity.DataBindingEntities.Add(Entity);
|
||||
|
||||
// General
|
||||
Entity.TargetProperty = TargetProperty?.Name;
|
||||
Entity.TargetExpression = Registration.PropertyExpression.ToString();
|
||||
Entity.DataBindingMode = (int) Mode;
|
||||
Entity.EasingTime = EasingTime;
|
||||
Entity.EasingFunction = (int) EasingFunction;
|
||||
@@ -340,7 +346,7 @@ namespace Artemis.Core
|
||||
Entity.SourceDataModelGuid = SourceDataModel.PluginInfo.Guid;
|
||||
Entity.SourcePropertyPath = SourcePropertyPath;
|
||||
}
|
||||
|
||||
|
||||
// Modifiers
|
||||
Entity.Modifiers.Clear();
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
@@ -381,18 +387,6 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
dataBindingModifier.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -18,7 +19,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// A dynamically compiled setter pointing to the data bound property
|
||||
/// </summary>
|
||||
public Action<TProperty> SetExpression { get; private set; }
|
||||
public Action<TLayerProperty, TProperty> SetExpression { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data binding this converter is applied to
|
||||
@@ -81,19 +82,34 @@ namespace Artemis.Core
|
||||
OnInitialized();
|
||||
}
|
||||
|
||||
private Action<TProperty> CreateValueSetter()
|
||||
private Action<TLayerProperty, TProperty> CreateValueSetter()
|
||||
{
|
||||
if (DataBinding.TargetProperty?.DeclaringType == null)
|
||||
return null;
|
||||
MethodInfo setterMethod = null;
|
||||
|
||||
if (DataBinding.Registration.Member != null)
|
||||
{
|
||||
if (DataBinding.Registration.Member is PropertyInfo propertyInfo)
|
||||
setterMethod = propertyInfo.GetSetMethod();
|
||||
}
|
||||
|
||||
var setterMethod = DataBinding.TargetProperty.GetSetMethod();
|
||||
if (setterMethod == null)
|
||||
return null;
|
||||
|
||||
var parameter = Expression.Parameter(typeof(TLayerProperty), "currentValue");
|
||||
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
|
||||
|
||||
var body = DataBinding.Registration.PropertyExpression;
|
||||
var lambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
|
||||
|
||||
var memberAccess = Expression.MakeMemberAccess(parameter, DataBinding.Registration.Member);
|
||||
var assignment = Expression.Assign(memberAccess, propertyValue);
|
||||
var lambda = Expression.Lambda<Action<TLayerProperty, TProperty>>(assignment, parameter, propertyValue);
|
||||
|
||||
if (typeof(TLayerProperty).IsValueType)
|
||||
{
|
||||
// var layerProperty = Expression.Constant(DataBinding.LayerProperty);
|
||||
// var layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty, DataBinding.LayerProperty.GetType().GetMember(nameof(DataBinding.LayerProperty.CurrentValue))[0]);
|
||||
// var assingment = Expression.Assign()
|
||||
}
|
||||
|
||||
return lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace Artemis.Core
|
||||
return;
|
||||
}
|
||||
|
||||
var targetType = DataBinding.TargetProperty.PropertyType;
|
||||
var targetType = DataBinding.GetTargetType();
|
||||
if (!modifierType.SupportsType(targetType))
|
||||
{
|
||||
throw new ArtemisCoreException($"Cannot apply modifier type {modifierType.GetType().Name} to this modifier because " +
|
||||
@@ -227,7 +227,7 @@ namespace Artemis.Core
|
||||
ParameterDataModel = null;
|
||||
ParameterPropertyPath = null;
|
||||
|
||||
var targetType = DataBinding.TargetProperty.PropertyType;
|
||||
var targetType = DataBinding.GetTargetType();
|
||||
|
||||
// If not null ensure the types match and if not, convert it
|
||||
if (staticValue != null && staticValue.GetType() == targetType)
|
||||
@@ -269,7 +269,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 targetType = DataBinding.TargetProperty.PropertyType;
|
||||
var targetType = DataBinding.GetTargetType();
|
||||
object staticValue;
|
||||
|
||||
try
|
||||
|
||||
@@ -8,13 +8,16 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public class DataBindingRegistration<TLayerProperty, TProperty> : IDataBindingRegistration
|
||||
{
|
||||
internal DataBindingRegistration(LayerProperty<TLayerProperty> layerProperty,
|
||||
DataBindingConverter<TLayerProperty, TProperty> converter,
|
||||
internal DataBindingRegistration(LayerProperty<TLayerProperty> layerProperty,
|
||||
DataBindingConverter<TLayerProperty, TProperty> converter,
|
||||
Expression<Func<TLayerProperty, TProperty>> propertyExpression)
|
||||
{
|
||||
LayerProperty = layerProperty ?? throw new ArgumentNullException(nameof(layerProperty));
|
||||
Converter = converter ?? throw new ArgumentNullException(nameof(converter));
|
||||
PropertyExpression = propertyExpression ?? throw new ArgumentNullException(nameof(propertyExpression));
|
||||
|
||||
if (propertyExpression.Body is MemberExpression memberExpression)
|
||||
Member = memberExpression.Member;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -28,15 +31,16 @@ namespace Artemis.Core
|
||||
public DataBindingConverter<TLayerProperty, TProperty> Converter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the expression that that accesses the property
|
||||
/// Gets the expression that that accesses the property
|
||||
/// </summary>
|
||||
public Expression<Func<TLayerProperty, TProperty>> PropertyExpression { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the registered property
|
||||
/// Gets the member the <see cref="PropertyExpression" /> targets
|
||||
/// <para><c>null</c> if the <see cref="PropertyExpression" /> is not a member expression</para>
|
||||
/// </summary>
|
||||
public PropertyInfo Property { get; }
|
||||
|
||||
public MemberInfo Member { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data binding created using this registration
|
||||
/// </summary>
|
||||
@@ -48,7 +52,7 @@ namespace Artemis.Core
|
||||
if (DataBinding != null)
|
||||
return DataBinding;
|
||||
|
||||
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetProperty == PropertyExpression.ToString());
|
||||
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetExpression == PropertyExpression.ToString());
|
||||
if (dataBinding == null)
|
||||
return null;
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace Artemis.Core
|
||||
|
||||
canvas.Restore();
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void AddChild(ProfileElement child, int? order = null)
|
||||
{
|
||||
@@ -242,17 +242,13 @@ namespace Artemis.Core
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
_disposed = true;
|
||||
|
||||
foreach (var baseLayerEffect in LayerEffects)
|
||||
baseLayerEffect.Dispose();
|
||||
foreach (var profileElement in Children)
|
||||
profileElement.Dispose();
|
||||
|
||||
_folderBitmap?.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
internal override void Load()
|
||||
@@ -290,10 +286,6 @@ namespace Artemis.Core
|
||||
FolderEntity.ExpandedPropertyGroups.Clear();
|
||||
FolderEntity.ExpandedPropertyGroups.AddRange(_expandedPropertyGroups);
|
||||
|
||||
// Conditions
|
||||
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
|
||||
DisplayConditionGroup?.Save();
|
||||
|
||||
SaveRenderElement();
|
||||
}
|
||||
|
||||
|
||||
@@ -124,20 +124,16 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
_disposed = true;
|
||||
|
||||
// Brush first in case it depends on any of the other disposables during it's own disposal
|
||||
_layerBrush?.Dispose();
|
||||
|
||||
foreach (var baseLayerEffect in LayerEffects)
|
||||
baseLayerEffect.Dispose();
|
||||
|
||||
_general?.Dispose();
|
||||
_layerBitmap?.Dispose();
|
||||
_transform?.Dispose();
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -210,10 +206,6 @@ namespace Artemis.Core
|
||||
LayerEntity.Leds.Add(ledEntity);
|
||||
}
|
||||
|
||||
// Conditions
|
||||
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
|
||||
DisplayConditionGroup?.Save();
|
||||
|
||||
SaveRenderElement();
|
||||
}
|
||||
|
||||
@@ -691,14 +683,8 @@ namespace Artemis.Core
|
||||
|
||||
// Ensure the brush reference matches the brush
|
||||
var current = General.BrushReference.CurrentValue;
|
||||
if (current.BrushPluginGuid != descriptor.LayerBrushProvider.PluginInfo.Guid || current.BrushType != descriptor.LayerBrushType.Name)
|
||||
{
|
||||
General.BrushReference.CurrentValue = new LayerBrushReference
|
||||
{
|
||||
BrushPluginGuid = descriptor.LayerBrushProvider.PluginInfo.Guid,
|
||||
BrushType = descriptor.LayerBrushType.Name
|
||||
};
|
||||
}
|
||||
if (!descriptor.MatchesLayerBrushReference(current))
|
||||
General.BrushReference.CurrentValue = new LayerBrushReference(descriptor);
|
||||
|
||||
ActivateLayerBrush();
|
||||
}
|
||||
@@ -746,7 +732,7 @@ namespace Artemis.Core
|
||||
|
||||
private void LayerBrushStoreOnLayerBrushRemoved(object sender, LayerBrushStoreEvent e)
|
||||
{
|
||||
if (LayerBrush.Descriptor == e.Registration.LayerBrushDescriptor)
|
||||
if (LayerBrush?.Descriptor == e.Registration.LayerBrushDescriptor)
|
||||
DeactivateLayerBrush();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,5 +17,15 @@ namespace Artemis.Core
|
||||
/// The full type name of the brush descriptor
|
||||
/// </summary>
|
||||
public string BrushType { get; set; }
|
||||
|
||||
public LayerBrushReference()
|
||||
{
|
||||
}
|
||||
|
||||
public LayerBrushReference(LayerBrushDescriptor descriptor)
|
||||
{
|
||||
BrushPluginGuid = descriptor.LayerBrushProvider.PluginInfo.Guid;
|
||||
BrushType = descriptor.LayerBrushType.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,5 @@ namespace Artemis.Core
|
||||
/// Returns a list off all data binding registrations
|
||||
/// </summary>
|
||||
List<IDataBindingRegistration> GetAllDataBindingRegistrations();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the property is hidden in the UI
|
||||
/// </summary>
|
||||
bool IsHidden { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,9 @@ namespace Artemis.Core
|
||||
|
||||
private bool _isHidden;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Gets or sets whether the property is hidden in the UI
|
||||
/// </summary>
|
||||
public bool IsHidden
|
||||
{
|
||||
get => _isHidden;
|
||||
@@ -318,13 +320,13 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public bool DataBindingsSupported { get; protected internal set; } = true;
|
||||
|
||||
public DataBindingRegistration<T, TProperty> GetDataBindingRegistration<TProperty>(string propertyName)
|
||||
public DataBindingRegistration<T, TProperty> GetDataBindingRegistration<TProperty>(string expression)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("LayerProperty");
|
||||
|
||||
var match = _dataBindingRegistrations.FirstOrDefault(r => r is DataBindingRegistration<T, TProperty> registration &&
|
||||
registration.Property.Name == propertyName);
|
||||
registration.PropertyExpression.ToString() == expression);
|
||||
return (DataBindingRegistration<T, TProperty>) match;
|
||||
}
|
||||
|
||||
|
||||
@@ -237,6 +237,10 @@ namespace Artemis.Core
|
||||
if (instance == null)
|
||||
throw new ArtemisPluginException($"Failed to create instance of layer property group at {path + propertyInfo.Name}");
|
||||
|
||||
// Ensure the description has a name, if not this is a good point to set it based on the property info
|
||||
if (string.IsNullOrWhiteSpace(propertyGroupDescription.Name))
|
||||
propertyGroupDescription.Name = propertyInfo.Name.Humanize();
|
||||
|
||||
instance.Parent = this;
|
||||
instance.GroupDescription = propertyGroupDescription;
|
||||
instance.LayerBrush = LayerBrush;
|
||||
|
||||
@@ -32,6 +32,10 @@ namespace Artemis.Core
|
||||
DisplayContinuously = RenderElementEntity.DisplayContinuously;
|
||||
AlwaysFinishTimeline = RenderElementEntity.AlwaysFinishTimeline;
|
||||
|
||||
DisplayConditionGroup = RenderElementEntity.RootDisplayCondition != null
|
||||
? new DisplayConditionGroup(null, RenderElementEntity.RootDisplayCondition)
|
||||
: new DisplayConditionGroup(null);
|
||||
|
||||
ActivateEffects();
|
||||
}
|
||||
|
||||
@@ -49,7 +53,7 @@ namespace Artemis.Core
|
||||
var layerEffectEntity = new LayerEffectEntity
|
||||
{
|
||||
Id = layerEffect.EntityId,
|
||||
PluginGuid = layerEffect.PluginInfo.Guid,
|
||||
PluginGuid = layerEffect.Descriptor.PlaceholderFor ?? layerEffect.PluginInfo.Guid,
|
||||
EffectType = layerEffect.GetEffectTypeName(),
|
||||
Name = layerEffect.Name,
|
||||
Enabled = layerEffect.Enabled,
|
||||
@@ -59,6 +63,10 @@ namespace Artemis.Core
|
||||
RenderElementEntity.LayerEffects.Add(layerEffectEntity);
|
||||
layerEffect.BaseProperties.ApplyToEntity();
|
||||
}
|
||||
|
||||
// Conditions
|
||||
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
|
||||
DisplayConditionGroup?.Save();
|
||||
}
|
||||
|
||||
#region Properties
|
||||
@@ -204,7 +212,7 @@ namespace Artemis.Core
|
||||
|
||||
return (TimelinePosition - oldPosition).TotalSeconds;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the progress of the element
|
||||
/// </summary>
|
||||
@@ -238,6 +246,8 @@ namespace Artemis.Core
|
||||
Order = LayerEffects.Count + 1
|
||||
};
|
||||
descriptor.CreateInstance(this, entity);
|
||||
|
||||
OrderEffects();
|
||||
OnLayerEffectsUpdated();
|
||||
}
|
||||
|
||||
@@ -254,6 +264,12 @@ namespace Artemis.Core
|
||||
effect.Dispose();
|
||||
|
||||
// Update the order on the remaining effects
|
||||
OrderEffects();
|
||||
OnLayerEffectsUpdated();
|
||||
}
|
||||
|
||||
private void OrderEffects()
|
||||
{
|
||||
var index = 0;
|
||||
foreach (var baseLayerEffect in LayerEffects.OrderBy(e => e.Order))
|
||||
{
|
||||
@@ -261,7 +277,7 @@ namespace Artemis.Core
|
||||
index++;
|
||||
}
|
||||
|
||||
OnLayerEffectsUpdated();
|
||||
_layerEffects.Sort((a, b) => a.Order.CompareTo(b.Order));
|
||||
}
|
||||
|
||||
internal void ActivateEffects()
|
||||
@@ -270,7 +286,7 @@ namespace Artemis.Core
|
||||
{
|
||||
// If there is a non-placeholder existing effect, skip this entity
|
||||
var existing = _layerEffects.FirstOrDefault(e => e.EntityId == layerEffectEntity.Id);
|
||||
if (existing != null && !existing.Descriptor.IsPlaceHolder)
|
||||
if (existing != null && existing.Descriptor.PlaceholderFor == null)
|
||||
continue;
|
||||
|
||||
var descriptor = LayerEffectStore.Get(layerEffectEntity.PluginGuid, layerEffectEntity.EffectType)?.LayerEffectDescriptor;
|
||||
@@ -282,37 +298,42 @@ namespace Artemis.Core
|
||||
_layerEffects.Remove(existing);
|
||||
existing.Dispose();
|
||||
}
|
||||
|
||||
// Create an instance with the descriptor
|
||||
descriptor.CreateInstance(this, layerEffectEntity);
|
||||
}
|
||||
else if (existing == null)
|
||||
{
|
||||
// If no descriptor was found and there was no existing placeholder, create a placeholder
|
||||
descriptor = PlaceholderLayerEffectDescriptor.Create();
|
||||
descriptor = PlaceholderLayerEffectDescriptor.Create(layerEffectEntity.PluginGuid);
|
||||
descriptor.CreateInstance(this, layerEffectEntity);
|
||||
}
|
||||
}
|
||||
|
||||
OrderEffects();
|
||||
}
|
||||
|
||||
|
||||
internal void ActivateLayerEffect(BaseLayerEffect layerEffect)
|
||||
{
|
||||
_layerEffects.Add(layerEffect);
|
||||
|
||||
// Update the order on the effects
|
||||
var index = 0;
|
||||
foreach (var baseLayerEffect in LayerEffects.OrderBy(e => e.Order))
|
||||
{
|
||||
baseLayerEffect.Order = Order = index + 1;
|
||||
index++;
|
||||
}
|
||||
|
||||
OnLayerEffectsUpdated();
|
||||
}
|
||||
|
||||
private void LayerEffectStoreOnLayerEffectRemoved(object? sender, LayerEffectStoreEvent e)
|
||||
private void LayerEffectStoreOnLayerEffectRemoved(object sender, LayerEffectStoreEvent e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// If effects provided by the plugin are on the element, replace them with placeholders
|
||||
var pluginEffects = _layerEffects.Where(ef => ef.Descriptor.LayerEffectProvider != null &&
|
||||
ef.PluginInfo.Guid == e.Registration.Plugin.PluginInfo.Guid).ToList();
|
||||
foreach (var pluginEffect in pluginEffects)
|
||||
{
|
||||
var entity = RenderElementEntity.LayerEffects.First(en => en.Id == pluginEffect.EntityId);
|
||||
_layerEffects.Remove(pluginEffect);
|
||||
pluginEffect.Dispose();
|
||||
|
||||
var descriptor = PlaceholderLayerEffectDescriptor.Create(pluginEffect.PluginInfo.Guid);
|
||||
descriptor.CreateInstance(this, entity);
|
||||
}
|
||||
}
|
||||
|
||||
private void LayerEffectStoreOnLayerEffectAdded(object sender, LayerEffectStoreEvent e)
|
||||
@@ -359,6 +380,21 @@ namespace Artemis.Core
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
LayerEffectStore.LayerEffectAdded -= LayerEffectStoreOnLayerEffectAdded;
|
||||
LayerEffectStore.LayerEffectRemoved -= LayerEffectStoreOnLayerEffectRemoved;
|
||||
|
||||
foreach (var baseLayerEffect in LayerEffects)
|
||||
baseLayerEffect.Dispose();
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler LayerEffectsUpdated;
|
||||
|
||||
@@ -61,5 +61,12 @@ namespace Artemis.Core.LayerBrushes
|
||||
layer.LayerBrush = brush;
|
||||
layer.OnLayerBrushUpdated();
|
||||
}
|
||||
|
||||
public bool MatchesLayerBrushReference(LayerBrushReference reference)
|
||||
{
|
||||
if (reference == null)
|
||||
return false;
|
||||
return LayerBrushProvider.PluginInfo.Guid == reference.BrushPluginGuid && LayerBrushType.Name == reference.BrushType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ namespace Artemis.Core.LayerEffects
|
||||
/// <summary>
|
||||
/// Gets the plugin info that defined this effect
|
||||
/// </summary>
|
||||
public PluginInfo PluginInfo => Descriptor.LayerEffectProvider.PluginInfo;
|
||||
public PluginInfo PluginInfo => Descriptor.LayerEffectProvider?.PluginInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the layer property group without knowing it's type
|
||||
@@ -108,7 +108,7 @@ namespace Artemis.Core.LayerEffects
|
||||
public void Dispose()
|
||||
{
|
||||
DisableLayerEffect();
|
||||
BaseProperties.Dispose();
|
||||
BaseProperties?.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.LayerEffects.Placeholder;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Ninject;
|
||||
@@ -47,9 +48,9 @@ namespace Artemis.Core.LayerEffects
|
||||
public LayerEffectProvider LayerEffectProvider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating if this descriptor is a placeholder for a missing plugin
|
||||
/// Gets the GUID this descriptor is acting as a placeholder for. If null, this descriptor is not a placeholder
|
||||
/// </summary>
|
||||
public bool IsPlaceHolder { get; internal set; }
|
||||
public Guid? PlaceholderFor { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the described effect and applies it to the render element
|
||||
@@ -60,7 +61,7 @@ namespace Artemis.Core.LayerEffects
|
||||
if (renderElement.LayerEffects.Any(e => e.EntityId == entity.Id))
|
||||
return;
|
||||
|
||||
if (IsPlaceHolder)
|
||||
if (PlaceholderFor != null)
|
||||
{
|
||||
CreatePlaceHolderInstance(renderElement, entity);
|
||||
return;
|
||||
@@ -82,7 +83,8 @@ namespace Artemis.Core.LayerEffects
|
||||
|
||||
private void CreatePlaceHolderInstance(RenderProfileElement renderElement, LayerEffectEntity entity)
|
||||
{
|
||||
var effect = new PlaceholderLayerEffect(entity) {ProfileElement = renderElement, Descriptor = this};
|
||||
var effect = new PlaceholderLayerEffect(entity, PlaceholderFor.Value) {ProfileElement = renderElement, Descriptor = this};
|
||||
effect.Initialize();
|
||||
renderElement.ActivateLayerEffect(effect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.LayerEffects
|
||||
namespace Artemis.Core.LayerEffects.Placeholder
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a layer effect that could not be loaded due to a missing plugin
|
||||
/// </summary>
|
||||
public class PlaceholderLayerEffect : BaseLayerEffect
|
||||
internal class PlaceholderLayerEffect : LayerEffect<PlaceholderProperties>
|
||||
{
|
||||
internal PlaceholderLayerEffect(LayerEffectEntity originalEntity)
|
||||
internal PlaceholderLayerEffect(LayerEffectEntity originalEntity, Guid placeholderFor)
|
||||
{
|
||||
OriginalEntity = originalEntity;
|
||||
|
||||
PlaceholderFor = placeholderFor;
|
||||
|
||||
EntityId = OriginalEntity.Id;
|
||||
Order = OriginalEntity.Order;
|
||||
Name = OriginalEntity.Name;
|
||||
@@ -20,6 +22,7 @@ namespace Artemis.Core.LayerEffects
|
||||
}
|
||||
|
||||
internal LayerEffectEntity OriginalEntity { get; }
|
||||
public Guid PlaceholderFor { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void EnableLayerEffect()
|
||||
@@ -50,8 +53,22 @@ namespace Artemis.Core.LayerEffects
|
||||
{
|
||||
return OriginalEntity.EffectType;
|
||||
}
|
||||
}
|
||||
|
||||
internal override void Initialize()
|
||||
/// <summary>
|
||||
/// This is in place so that the UI has something to show
|
||||
/// </summary>
|
||||
internal class PlaceholderProperties : LayerPropertyGroup
|
||||
{
|
||||
protected override void PopulateDefaults()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void EnableProperties()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DisableProperties()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
+9
-3
@@ -1,10 +1,16 @@
|
||||
namespace Artemis.Core.LayerEffects.Placeholder
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.LayerEffects.Placeholder
|
||||
{
|
||||
internal static class PlaceholderLayerEffectDescriptor
|
||||
{
|
||||
public static LayerEffectDescriptor Create()
|
||||
public static LayerEffectDescriptor Create(Guid missingPluginGuid)
|
||||
{
|
||||
var descriptor = new LayerEffectDescriptor("Missing effect", "This effect could not be loaded", "FileQuestion", null, null) {IsPlaceHolder = true};
|
||||
var descriptor = new LayerEffectDescriptor("Missing effect", "This effect could not be loaded", "FileQuestion", null, Constants.EffectPlaceholderPlugin)
|
||||
{
|
||||
PlaceholderFor = missingPluginGuid
|
||||
};
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Gets whether the plugin is enabled
|
||||
/// </summary>
|
||||
public bool Enabled { get; private set; }
|
||||
public bool Enabled { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a configuration dialog for this plugin that is accessible in the UI under Settings > Plugins
|
||||
|
||||
@@ -22,5 +22,10 @@ namespace Artemis.Core.Services
|
||||
/// Returns a list of all registered layer brush descriptors
|
||||
/// </summary>
|
||||
List<LayerBrushDescriptor> GetLayerBrushes();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the descriptor of the default layer brush
|
||||
/// </summary>
|
||||
LayerBrushDescriptor GetDefaultLayerBrush();
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,13 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
internal class LayerBrushService : ILayerBrushService
|
||||
{
|
||||
private readonly ISettingsService _settingsService;
|
||||
|
||||
public LayerBrushService(ISettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
}
|
||||
|
||||
public LayerBrushRegistration RegisterLayerBrush(LayerBrushDescriptor descriptor)
|
||||
{
|
||||
if (descriptor == null)
|
||||
@@ -26,5 +33,16 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
return LayerBrushStore.GetAll().Select(r => r.LayerBrushDescriptor).ToList();
|
||||
}
|
||||
|
||||
public LayerBrushDescriptor GetDefaultLayerBrush()
|
||||
{
|
||||
var defaultReference = _settingsService.GetSetting("ProfileEditor.DefaultLayerBrushDescriptor", new LayerBrushReference
|
||||
{
|
||||
BrushPluginGuid = Guid.Parse("92a9d6ba-6f7a-4937-94d5-c1d715b4141a"),
|
||||
BrushType = "ColorBrush"
|
||||
});
|
||||
|
||||
return LayerBrushStore.Get(defaultReference.Value.BrushPluginGuid, defaultReference.Value.BrushType)?.LayerBrushDescriptor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.LayerBrushes;
|
||||
using Artemis.Core.LayerEffects;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
@@ -19,7 +17,12 @@ namespace Artemis.Core.Services
|
||||
private readonly IProfileRepository _profileRepository;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
|
||||
internal ProfileService(ILogger logger, IPluginService pluginService, ISurfaceService surfaceService, IProfileRepository profileRepository)
|
||||
internal ProfileService(ILogger logger,
|
||||
IPluginService pluginService,
|
||||
ISurfaceService surfaceService,
|
||||
IConditionOperatorService conditionOperatorService,
|
||||
IDataBindingService dataBindingService,
|
||||
IProfileRepository profileRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
_pluginService = pluginService;
|
||||
@@ -261,7 +264,7 @@ namespace Artemis.Core.Services
|
||||
_profileRepository.Save(profileEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Populates all missing LEDs on all currently active profiles
|
||||
/// </summary>
|
||||
@@ -272,7 +275,7 @@ namespace Artemis.Core.Services
|
||||
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
||||
profileModule.ActiveProfile.PopulateLeds(surface);
|
||||
}
|
||||
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e)
|
||||
@@ -285,7 +288,7 @@ namespace Artemis.Core.Services
|
||||
if (e.Surface.IsActive)
|
||||
ActiveProfilesPopulateLeds(e.Surface);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Artemis.Core.LayerEffects;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty plugin used by <see cref="Constants.CorePluginInfo"/>
|
||||
/// </summary>
|
||||
internal class CorePlugin : Plugin
|
||||
{
|
||||
public CorePlugin()
|
||||
{
|
||||
Constants.CorePluginInfo.Instance = this;
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
public override void EnablePlugin()
|
||||
{
|
||||
}
|
||||
|
||||
public override void DisablePlugin()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal class EffectPlaceholderPlugin : LayerEffectProvider
|
||||
{
|
||||
public EffectPlaceholderPlugin()
|
||||
{
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
public override void EnablePlugin()
|
||||
{
|
||||
}
|
||||
|
||||
public override void DisablePlugin()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user