diff --git a/src/Artemis.Core/Events/LayerPropertyEventArgs.cs b/src/Artemis.Core/Events/LayerPropertyEventArgs.cs
index 9ec63f95f..9f16dc690 100644
--- a/src/Artemis.Core/Events/LayerPropertyEventArgs.cs
+++ b/src/Artemis.Core/Events/LayerPropertyEventArgs.cs
@@ -5,11 +5,11 @@ namespace Artemis.Core.Events
{
public class LayerPropertyEventArgs : EventArgs
{
- public LayerPropertyEventArgs(LayerProperty layerProperty)
+ public LayerPropertyEventArgs(BaseLayerProperty layerProperty)
{
LayerProperty = layerProperty;
}
- public LayerProperty LayerProperty { get; }
+ public BaseLayerProperty LayerProperty { get; }
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Events/PropertyGroupUpdatingEventArgs.cs b/src/Artemis.Core/Events/PropertyGroupUpdatingEventArgs.cs
new file mode 100644
index 000000000..a1f4c3b6c
--- /dev/null
+++ b/src/Artemis.Core/Events/PropertyGroupUpdatingEventArgs.cs
@@ -0,0 +1,20 @@
+using System;
+
+namespace Artemis.Core.Events
+{
+ public class PropertyGroupUpdatingEventArgs : EventArgs
+ {
+ public PropertyGroupUpdatingEventArgs(double deltaTime)
+ {
+ DeltaTime = deltaTime;
+ }
+
+ public PropertyGroupUpdatingEventArgs(TimeSpan overrideTime)
+ {
+ OverrideTime = overrideTime;
+ }
+
+ public double DeltaTime { get; }
+ public TimeSpan OverrideTime { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/KeyframeEngines/FloatKeyframeEngine.cs b/src/Artemis.Core/Models/Profile/KeyframeEngines/FloatKeyframeEngine.cs
deleted file mode 100644
index 88a922d39..000000000
--- a/src/Artemis.Core/Models/Profile/KeyframeEngines/FloatKeyframeEngine.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Artemis.Core.Models.Profile.LayerProperties;
-
-namespace Artemis.Core.Models.Profile.KeyframeEngines
-{
- ///
- public class FloatKeyframeEngine : KeyframeEngine
- {
- public sealed override List CompatibleTypes { get; } = new List {typeof(float)};
-
- protected override object GetInterpolatedValue()
- {
- var currentKeyframe = (Keyframe) CurrentKeyframe;
- var nextKeyframe = (Keyframe) NextKeyframe;
-
- var diff = nextKeyframe.Value - currentKeyframe.Value;
- return currentKeyframe.Value + diff * KeyframeProgressEased;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/KeyframeEngines/IntKeyframeEngine.cs b/src/Artemis.Core/Models/Profile/KeyframeEngines/IntKeyframeEngine.cs
deleted file mode 100644
index 9d25f8148..000000000
--- a/src/Artemis.Core/Models/Profile/KeyframeEngines/IntKeyframeEngine.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Artemis.Core.Models.Profile.LayerProperties;
-
-namespace Artemis.Core.Models.Profile.KeyframeEngines
-{
- ///
- public class IntKeyframeEngine : KeyframeEngine
- {
- public sealed override List CompatibleTypes { get; } = new List {typeof(int)};
-
- protected override object GetInterpolatedValue()
- {
- var currentKeyframe = (Keyframe) CurrentKeyframe;
- var nextKeyframe = (Keyframe) NextKeyframe;
-
- var diff = nextKeyframe.Value - currentKeyframe.Value;
- return (int) Math.Round(currentKeyframe.Value + diff * KeyframeProgressEased, MidpointRounding.AwayFromZero);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/KeyframeEngines/KeyframeEngine.cs b/src/Artemis.Core/Models/Profile/KeyframeEngines/KeyframeEngine.cs
deleted file mode 100644
index e77db585e..000000000
--- a/src/Artemis.Core/Models/Profile/KeyframeEngines/KeyframeEngine.cs
+++ /dev/null
@@ -1,135 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Artemis.Core.Exceptions;
-using Artemis.Core.Models.Profile.LayerProperties;
-using Artemis.Core.Utilities;
-
-namespace Artemis.Core.Models.Profile.KeyframeEngines
-{
- public abstract class KeyframeEngine
- {
- ///
- /// Indicates whether has been called.
- ///
- public bool Initialized { get; private set; }
-
- ///
- /// The layer property this keyframe engine applies to.
- ///
- public LayerProperty LayerProperty { get; private set; }
-
- ///
- /// The total progress
- ///
- public TimeSpan Progress { get; private set; }
-
- ///
- /// The progress from the current keyframe to the next.
- /// Range 0.0 to 1.0.
- ///
- public float KeyframeProgress { get; private set; }
-
- ///
- /// The progress from the current keyframe to the next with the current keyframes easing function applied.
- /// Range 0.0 to 1.0 but can be higher than 1.0 depending on easing function.
- ///
- public float KeyframeProgressEased { get; set; }
-
- ///
- /// The current keyframe
- ///
- public BaseKeyframe CurrentKeyframe { get; private set; }
-
- ///
- /// The next keyframe
- ///
- public BaseKeyframe NextKeyframe { get; private set; }
-
- ///
- /// The types this keyframe engine supports.
- ///
- public abstract List CompatibleTypes { get; }
-
- ///
- /// Associates the keyframe engine with the provided layer property.
- ///
- ///
- public void Initialize(LayerProperty layerProperty)
- {
- if (Initialized)
- throw new ArtemisCoreException("Cannot initialize the same keyframe engine twice");
- if (!CompatibleTypes.Contains(layerProperty.Type))
- throw new ArtemisCoreException($"This property engine does not support the provided type {layerProperty.Type.Name}");
-
- LayerProperty = layerProperty;
- LayerProperty.KeyframeEngine = this;
- Initialized = true;
- }
-
- ///
- /// Updates the engine's progress
- ///
- ///
- public void Update(double deltaTime)
- {
- if (!Initialized)
- return;
-
- var keyframes = LayerProperty.UntypedKeyframes.ToList();
- Progress = Progress.Add(TimeSpan.FromSeconds(deltaTime));
- // The current keyframe is the last keyframe before the current time
- CurrentKeyframe = keyframes.LastOrDefault(k => k.Position <= Progress);
- // The next keyframe is the first keyframe that's after the current time
- NextKeyframe = keyframes.FirstOrDefault(k => k.Position > Progress);
-
- if (CurrentKeyframe == null)
- {
- KeyframeProgress = 0;
- KeyframeProgressEased = 0;
- }
- else if (NextKeyframe == null)
- {
- KeyframeProgress = 1;
- KeyframeProgressEased = 1;
- }
- else
- {
- var timeDiff = NextKeyframe.Position - CurrentKeyframe.Position;
- KeyframeProgress = (float) ((Progress - CurrentKeyframe.Position).TotalMilliseconds / timeDiff.TotalMilliseconds);
- KeyframeProgressEased = (float) Easings.Interpolate(KeyframeProgress, CurrentKeyframe.EasingFunction);
- }
-
- // LayerProperty determines what's next: reset, stop, continue
- }
-
-
- ///
- /// Overrides the engine's progress to the provided value
- ///
- ///
- public void OverrideProgress(TimeSpan progress)
- {
- Progress = TimeSpan.Zero;
- Update(progress.TotalSeconds);
- }
-
- ///
- /// Gets the current value, if the progress is in between two keyframes the value will be interpolated
- ///
- ///
- public object GetCurrentValue()
- {
- if (CurrentKeyframe == null && LayerProperty.UntypedKeyframes.Any())
- return LayerProperty.UntypedKeyframes.First().BaseValue;
- if (CurrentKeyframe == null)
- return LayerProperty.BaseValue;
- if (NextKeyframe == null)
- return CurrentKeyframe.BaseValue;
-
- return GetInterpolatedValue();
- }
-
- protected abstract object GetInterpolatedValue();
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/KeyframeEngines/SKColorKeyframeEngine.cs b/src/Artemis.Core/Models/Profile/KeyframeEngines/SKColorKeyframeEngine.cs
deleted file mode 100644
index e0f0246b2..000000000
--- a/src/Artemis.Core/Models/Profile/KeyframeEngines/SKColorKeyframeEngine.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Artemis.Core.Models.Profile.LayerProperties;
-using SkiaSharp;
-
-namespace Artemis.Core.Models.Profile.KeyframeEngines
-{
- ///
- public class SKColorKeyframeEngine : KeyframeEngine
- {
- public sealed override List CompatibleTypes { get; } = new List {typeof(SKColor)};
-
- protected override object GetInterpolatedValue()
- {
- var currentKeyframe = (Keyframe) CurrentKeyframe;
- var nextKeyframe = (Keyframe) NextKeyframe;
-
- var redDiff = nextKeyframe.Value.Red - currentKeyframe.Value.Red;
- var greenDiff = nextKeyframe.Value.Green - currentKeyframe.Value.Green;
- var blueDiff = nextKeyframe.Value.Blue - currentKeyframe.Value.Blue;
- var alphaDiff = nextKeyframe.Value.Alpha - currentKeyframe.Value.Alpha;
-
- return new SKColor(
- ClampToByte(currentKeyframe.Value.Red + redDiff * KeyframeProgressEased),
- ClampToByte(currentKeyframe.Value.Green + greenDiff * KeyframeProgressEased),
- ClampToByte(currentKeyframe.Value.Blue + blueDiff * KeyframeProgressEased),
- ClampToByte(currentKeyframe.Value.Alpha + alphaDiff * KeyframeProgressEased)
- );
- }
-
- private byte ClampToByte(float value)
- {
- return (byte) Math.Max(0, Math.Min(255, value));
- }
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/KeyframeEngines/SKPointKeyframeEngine.cs b/src/Artemis.Core/Models/Profile/KeyframeEngines/SKPointKeyframeEngine.cs
deleted file mode 100644
index b38250ca6..000000000
--- a/src/Artemis.Core/Models/Profile/KeyframeEngines/SKPointKeyframeEngine.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Artemis.Core.Models.Profile.LayerProperties;
-using SkiaSharp;
-
-namespace Artemis.Core.Models.Profile.KeyframeEngines
-{
- ///
- public class SKPointKeyframeEngine : KeyframeEngine
- {
- public sealed override List CompatibleTypes { get; } = new List {typeof(SKPoint)};
-
- protected override object GetInterpolatedValue()
- {
- var currentKeyframe = (Keyframe) CurrentKeyframe;
- var nextKeyframe = (Keyframe) NextKeyframe;
-
- var xDiff = nextKeyframe.Value.X - currentKeyframe.Value.X;
- var yDiff = nextKeyframe.Value.Y - currentKeyframe.Value.Y;
- return new SKPoint(currentKeyframe.Value.X + xDiff * KeyframeProgressEased, currentKeyframe.Value.Y + yDiff * KeyframeProgressEased);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/KeyframeEngines/SKSizeKeyframeEngine.cs b/src/Artemis.Core/Models/Profile/KeyframeEngines/SKSizeKeyframeEngine.cs
deleted file mode 100644
index ea9e8fe45..000000000
--- a/src/Artemis.Core/Models/Profile/KeyframeEngines/SKSizeKeyframeEngine.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Artemis.Core.Models.Profile.LayerProperties;
-using SkiaSharp;
-
-namespace Artemis.Core.Models.Profile.KeyframeEngines
-{
- ///
- public class SKSizeKeyframeEngine : KeyframeEngine
- {
- public sealed override List CompatibleTypes { get; } = new List {typeof(SKSize)};
-
- protected override object GetInterpolatedValue()
- {
- var currentKeyframe = (Keyframe) CurrentKeyframe;
- var nextKeyframe = (Keyframe) NextKeyframe;
-
- var widthDiff = nextKeyframe.Value.Width - currentKeyframe.Value.Width;
- var heightDiff = nextKeyframe.Value.Height - currentKeyframe.Value.Height;
- return new SKSize(currentKeyframe.Value.Width + widthDiff * KeyframeProgressEased, currentKeyframe.Value.Height + heightDiff * KeyframeProgressEased);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs
index f4b8cf4f8..257a63244 100644
--- a/src/Artemis.Core/Models/Profile/Layer.cs
+++ b/src/Artemis.Core/Models/Profile/Layer.cs
@@ -32,8 +32,8 @@ namespace Artemis.Core.Models.Profile
Profile = profile;
Parent = parent;
Name = name;
- General = new LayerGeneralProperties();
- Transform = new LayerTransformProperties();
+ General = new LayerGeneralProperties {IsCorePropertyGroup = true};
+ Transform = new LayerTransformProperties {IsCorePropertyGroup = true};
_leds = new List();
}
@@ -47,8 +47,8 @@ namespace Artemis.Core.Models.Profile
Parent = parent;
Name = layerEntity.Name;
Order = layerEntity.Order;
- General = new LayerGeneralProperties();
- Transform = new LayerTransformProperties();
+ General = new LayerGeneralProperties {IsCorePropertyGroup = true};
+ Transform = new LayerTransformProperties {IsCorePropertyGroup = true};
_leds = new List();
}
@@ -104,7 +104,7 @@ namespace Artemis.Core.Models.Profile
///
/// The brush that will fill the .
///
- public ILayerBrush LayerBrush { get; internal set; }
+ public BaseLayerBrush LayerBrush { get; internal set; }
public override string ToString()
{
@@ -121,8 +121,9 @@ namespace Artemis.Core.Models.Profile
LayerEntity.Order = Order;
LayerEntity.Name = Name;
LayerEntity.ProfileId = Profile.EntityId;
- foreach (var layerProperty in Properties)
- layerProperty.ApplyToEntity();
+ General.ApplyToEntity();
+ Transform.ApplyToEntity();
+ LayerBrush.ApplyToEntity();
// LEDs
LayerEntity.Leds.Clear();
@@ -146,7 +147,7 @@ namespace Artemis.Core.Models.Profile
private void ApplyShapeType()
{
- switch (Properties.ShapeType.CurrentValue)
+ switch (General.ShapeType.CurrentValue)
{
case LayerShapeType.Ellipse:
LayerShape = new Ellipse(this);
@@ -179,20 +180,11 @@ namespace Artemis.Core.Models.Profile
///
public override void Update(double deltaTime)
{
- foreach (var property in Properties)
- property.KeyframeEngine?.Update(deltaTime);
+ General.Update(deltaTime);
+ Transform.Update(deltaTime);
- // For now, reset all keyframe engines after the last keyframe was hit
- // This is a placeholder method of repeating the animation until repeat modes are implemented
- var lastKeyframe = Properties.SelectMany(p => p.UntypedKeyframes).OrderByDescending(t => t.Position).FirstOrDefault();
- if (lastKeyframe != null)
- {
- if (Properties.Any(p => p.KeyframeEngine?.Progress > lastKeyframe.Position))
- {
- foreach (var baseLayerProperty in Properties)
- baseLayerProperty.KeyframeEngine?.OverrideProgress(TimeSpan.Zero);
- }
- }
+ LayerBrush?.UpdateProperties(deltaTime);
+ // TODO: Find the last keyframe and if required, reset the properties
LayerBrush?.Update(deltaTime);
}
@@ -208,10 +200,10 @@ namespace Artemis.Core.Models.Profile
using (var paint = new SKPaint())
{
- paint.BlendMode = Properties.BlendMode.CurrentValue;
- paint.Color = new SKColor(0, 0, 0, (byte) (Properties.Opacity.CurrentValue * 2.55f));
+ paint.BlendMode = General.BlendMode.CurrentValue;
+ paint.Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f));
- switch (Properties.FillType.CurrentValue)
+ switch (General.FillType.CurrentValue)
{
case LayerFillType.Stretch:
StretchRender(canvas, canvasInfo, paint);
@@ -230,11 +222,11 @@ namespace Artemis.Core.Models.Profile
private void StretchRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint)
{
// Apply transformations
- var sizeProperty = Properties.Scale.CurrentValue;
- var rotationProperty = Properties.Rotation.CurrentValue;
+ var sizeProperty = Transform.Scale.CurrentValue;
+ var rotationProperty = Transform.Rotation.CurrentValue;
var anchorPosition = GetLayerAnchorPosition();
- var anchorProperty = Properties.AnchorPoint.CurrentValue;
+ var anchorProperty = Transform.AnchorPoint.CurrentValue;
// Translation originates from the unscaled center of the shape and is tied to the anchor
var x = anchorPosition.X - Bounds.MidX - anchorProperty.X * Bounds.Width;
@@ -251,11 +243,11 @@ namespace Artemis.Core.Models.Profile
private void ClipRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint)
{
// Apply transformations
- var sizeProperty = Properties.Scale.CurrentValue;
- var rotationProperty = Properties.Rotation.CurrentValue;
+ var sizeProperty = Transform.Scale.CurrentValue;
+ var rotationProperty = Transform.Rotation.CurrentValue;
var anchorPosition = GetLayerAnchorPosition();
- var anchorProperty = Properties.AnchorPoint.CurrentValue;
+ var anchorProperty = Transform.AnchorPoint.CurrentValue;
// Translation originates from the unscaled center of the shape and is tied to the anchor
var x = anchorPosition.X - Bounds.MidX - anchorProperty.X * Bounds.Width;
@@ -308,7 +300,7 @@ namespace Artemis.Core.Models.Profile
internal SKPoint GetLayerAnchorPosition()
{
- var positionProperty = Properties.Position.CurrentValue;
+ var positionProperty = Transform.Position.CurrentValue;
// Start at the center of the shape
var position = new SKPoint(Bounds.MidX, Bounds.MidY);
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs
new file mode 100644
index 000000000..b8daceb02
--- /dev/null
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs
@@ -0,0 +1,25 @@
+using Artemis.Storage.Entities.Profile;
+
+namespace Artemis.Core.Models.Profile.LayerProperties
+{
+ public abstract class BaseLayerProperty
+ {
+ ///
+ /// Used to declare that this property doesn't belong to a plugin and should use the core plugin GUID
+ ///
+ internal bool IsCoreProperty { get; set; }
+
+ ///
+ /// Applies the provided property entity to the layer property by deserializing the JSON base value and keyframe values
+ ///
+ ///
+ ///
+ internal abstract void ApplyToLayerProperty(PropertyEntity entity, LayerPropertyGroup layerPropertyGroup);
+
+ ///
+ /// Saves the property to the underlying property entity that was configured when calling
+ ///
+ ///
+ internal abstract void ApplyToEntity();
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/GenericLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs
similarity index 72%
rename from src/Artemis.Core/Models/Profile/LayerProperties/GenericLayerProperty.cs
rename to src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs
index f07b9c909..2b89dfd8d 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/GenericLayerProperty.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
+using Artemis.Core.Exceptions;
using Artemis.Core.Utilities;
using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json;
@@ -10,18 +12,19 @@ namespace Artemis.Core.Models.Profile.LayerProperties
///
/// Represents a property on a layer. Properties are saved in storage and can optionally be modified from the UI.
///
- /// Note: You cannot initialize layer properties yourself. If properly placed, the Artemis core will initialize
+ /// Note: You cannot initialize layer properties yourself. If properly placed and annotated, the Artemis core will initialize
/// these for you.
///
///
/// The type of property encapsulated in this layer property
- public abstract class GenericLayerProperty : LayerProperty
+ public abstract class LayerProperty : BaseLayerProperty
{
- private T _currentValue;
- private List> _keyframes;
private T _baseValue;
+ private T _currentValue;
+ private bool _isInitialized;
+ private List> _keyframes;
- protected GenericLayerProperty()
+ protected LayerProperty()
{
_keyframes = new List>();
}
@@ -92,47 +95,8 @@ namespace Artemis.Core.Models.Profile.LayerProperties
///
public LayerPropertyKeyframe NextKeyframe { get; protected set; }
- ///
- /// Updates the property, moving the timeline forwards by the provided
- ///
- /// The amount of time to move the timeline forwards
- public void Update(double deltaTime)
- {
- TimelineProgress = TimelineProgress.Add(TimeSpan.FromSeconds(deltaTime));
- if (!KeyframesSupported || !KeyframesEnabled)
- return;
-
- // The current keyframe is the last keyframe before the current time
- CurrentKeyframe = _keyframes.LastOrDefault(k => k.Position <= TimelineProgress);
- // The next keyframe is the first keyframe that's after the current time
- NextKeyframe = _keyframes.FirstOrDefault(k => k.Position > TimelineProgress);
-
- // No need to update the current value if either of the keyframes are null
- if (CurrentKeyframe == null)
- CurrentValue = BaseValue;
- else if (NextKeyframe == null)
- CurrentValue = CurrentKeyframe.Value;
- // Only determine progress and current value if both keyframes are present
- else
- {
- var timeDiff = NextKeyframe.Position - CurrentKeyframe.Position;
- var keyframeProgress = (float) ((TimelineProgress - CurrentKeyframe.Position).TotalMilliseconds / timeDiff.TotalMilliseconds);
- var keyframeProgressEased = (float) Easings.Interpolate(keyframeProgress, CurrentKeyframe.EasingFunction);
- UpdateCurrentValue(keyframeProgress, keyframeProgressEased);
- }
-
- OnUpdated();
- }
-
- ///
- /// Overrides the timeline progress to match the provided
- ///
- /// The new progress to set the layer property timeline to.
- public void OverrideProgress(TimeSpan progress)
- {
- TimelineProgress = TimeSpan.Zero;
- Update(progress.TotalSeconds);
- }
+ internal PropertyEntity PropertyEntity { get; set; }
+ internal LayerPropertyGroup LayerPropertyGroup { get; set; }
///
/// Adds a keyframe to the layer property
@@ -166,24 +130,106 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// The current keyframe progress, eased with the current easing function
protected abstract void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased);
+ ///
+ /// Updates the property, moving the timeline forwards by the provided
+ ///
+ /// The amount of time to move the timeline forwards
+ internal void Update(double deltaTime)
+ {
+ TimelineProgress = TimelineProgress.Add(TimeSpan.FromSeconds(deltaTime));
+ if (!KeyframesSupported || !KeyframesEnabled)
+ return;
+
+ // The current keyframe is the last keyframe before the current time
+ CurrentKeyframe = _keyframes.LastOrDefault(k => k.Position <= TimelineProgress);
+ // The next keyframe is the first keyframe that's after the current time
+ NextKeyframe = _keyframes.FirstOrDefault(k => k.Position > TimelineProgress);
+
+ // No need to update the current value if either of the keyframes are null
+ if (CurrentKeyframe == null)
+ CurrentValue = BaseValue;
+ else if (NextKeyframe == null)
+ CurrentValue = CurrentKeyframe.Value;
+ // Only determine progress and current value if both keyframes are present
+ else
+ {
+ var timeDiff = NextKeyframe.Position - CurrentKeyframe.Position;
+ var keyframeProgress = (float) ((TimelineProgress - CurrentKeyframe.Position).TotalMilliseconds / timeDiff.TotalMilliseconds);
+ var keyframeProgressEased = (float) Easings.Interpolate(keyframeProgress, CurrentKeyframe.EasingFunction);
+ UpdateCurrentValue(keyframeProgress, keyframeProgressEased);
+ }
+
+ OnUpdated();
+ }
+
+ ///
+ /// Overrides the timeline progress to match the provided
+ ///
+ /// The new progress to set the layer property timeline to.
+ internal void OverrideProgress(TimeSpan overrideTime)
+ {
+ TimelineProgress = TimeSpan.Zero;
+ Update(overrideTime.TotalSeconds);
+ }
+
+ ///
+ /// Sorts the keyframes in ascending order by position
+ ///
internal void SortKeyframes()
{
_keyframes = _keyframes.OrderBy(k => k.Position).ToList();
}
- internal override void LoadFromEntity(PropertyEntity entity)
+ internal override void ApplyToLayerProperty(PropertyEntity entity, LayerPropertyGroup layerPropertyGroup)
{
- BaseValue = JsonConvert.DeserializeObject(entity.Value);
- CurrentValue = BaseValue;
+ // Doubt this will happen but let's make sure
+ if (_isInitialized)
+ throw new ArtemisCoreException("Layer property already initialized, wut");
- _keyframes.Clear();
- foreach (var keyframeEntity in entity.KeyframeEntities)
+ PropertyEntity = entity;
+ LayerPropertyGroup = layerPropertyGroup;
+ LayerPropertyGroup.PropertyGroupUpdating += (sender, args) => Update(args.DeltaTime);
+ LayerPropertyGroup.PropertyGroupOverriding += (sender, args) => OverrideProgress(args.OverrideTime);
+
+ try
{
- var value = JsonConvert.DeserializeObject(keyframeEntity.Value);
- var keyframe = new LayerPropertyKeyframe(value, keyframeEntity.Position, (Easings.Functions) keyframeEntity.EasingFunction);
- _keyframes.Add(keyframe);
+ IsLoadedFromStorage = true;
+ BaseValue = JsonConvert.DeserializeObject(entity.Value);
+ CurrentValue = BaseValue;
+
+ _keyframes.Clear();
+ _keyframes.AddRange(entity.KeyframeEntities.Select(k => new LayerPropertyKeyframe(
+ JsonConvert.DeserializeObject(k.Value),
+ k.Position,
+ (Easings.Functions) k.EasingFunction)
+ ));
}
- SortKeyframes();
+ catch (JsonException e)
+ {
+ // TODO: Properly log the JSON exception
+ Debug.WriteLine($"JSON exception while deserializing: {e}");
+ IsLoadedFromStorage = false;
+ }
+ finally
+ {
+ SortKeyframes();
+ _isInitialized = true;
+ }
+ }
+
+ internal override void ApplyToEntity()
+ {
+ if (_isInitialized)
+ throw new ArtemisCoreException("Layer property is not yet initialized");
+
+ PropertyEntity.Value = JsonConvert.SerializeObject(BaseValue);
+ PropertyEntity.KeyframeEntities.Clear();
+ PropertyEntity.KeyframeEntities.AddRange(Keyframes.Select(k => new KeyframeEntity
+ {
+ Value = JsonConvert.SerializeObject(k.Value),
+ Position = k.Position,
+ EasingFunction = (int) k.EasingFunction
+ }));
}
#region Events
@@ -215,9 +261,4 @@ namespace Artemis.Core.Models.Profile.LayerProperties
#endregion
}
-
- public abstract class LayerProperty
- {
- internal abstract void LoadFromEntity(PropertyEntity entity);
- }
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/LayerPropertyKeyFrame.cs b/src/Artemis.Core/Models/Profile/LayerProperties/LayerPropertyKeyFrame.cs
index ec4694d30..b89b9fbaa 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/LayerPropertyKeyFrame.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/LayerPropertyKeyFrame.cs
@@ -14,7 +14,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
EasingFunction = easingFunction;
}
- public GenericLayerProperty LayerProperty { get; internal set; }
+ public LayerProperty LayerProperty { get; internal set; }
public T Value { get; set; }
public TimeSpan Position
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/Types/ColorGradientLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/Types/ColorGradientLayerProperty.cs
index c7c5af8d1..1d32b63a7 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/Types/ColorGradientLayerProperty.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/Types/ColorGradientLayerProperty.cs
@@ -4,7 +4,7 @@ using Artemis.Core.Models.Profile.Colors;
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
///
- public class ColorGradientLayerProperty : GenericLayerProperty
+ public class ColorGradientLayerProperty : LayerProperty
{
internal ColorGradientLayerProperty()
{
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/Types/EnumLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/Types/EnumLayerProperty.cs
index f10e6253b..0dbcf3332 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/Types/EnumLayerProperty.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/Types/EnumLayerProperty.cs
@@ -3,7 +3,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
///
- public class EnumLayerProperty : GenericLayerProperty where T : System.Enum
+ public class EnumLayerProperty : LayerProperty where T : System.Enum
{
public EnumLayerProperty()
{
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/Types/FloatLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/Types/FloatLayerProperty.cs
index f7b9b9aa1..bc6e2ed01 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/Types/FloatLayerProperty.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/Types/FloatLayerProperty.cs
@@ -1,7 +1,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
///
- public class FloatLayerProperty : GenericLayerProperty
+ public class FloatLayerProperty : LayerProperty
{
internal FloatLayerProperty()
{
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/Types/IntLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/Types/IntLayerProperty.cs
index 80cf9ff4a..96eab86f2 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/Types/IntLayerProperty.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/Types/IntLayerProperty.cs
@@ -3,7 +3,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
///
- public class IntLayerProperty : GenericLayerProperty
+ public class IntLayerProperty : LayerProperty
{
internal IntLayerProperty()
{
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/Types/LayerBrushReferenceLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/Types/LayerBrushReferenceLayerProperty.cs
index 654001a56..f1d99e642 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/Types/LayerBrushReferenceLayerProperty.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/Types/LayerBrushReferenceLayerProperty.cs
@@ -5,7 +5,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties.Types
///
/// A special layer property used to configure the selected layer brush
///
- public class LayerBrushReferenceLayerProperty : GenericLayerProperty
+ public class LayerBrushReferenceLayerProperty : LayerProperty
{
internal LayerBrushReferenceLayerProperty()
{
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKColorLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKColorLayerProperty.cs
index c765d849c..b478cbd77 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKColorLayerProperty.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKColorLayerProperty.cs
@@ -4,7 +4,7 @@ using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
///
- public class SKColorLayerProperty : GenericLayerProperty
+ public class SKColorLayerProperty : LayerProperty
{
internal SKColorLayerProperty()
{
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKPointLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKPointLayerProperty.cs
index d4694d283..7595d2d62 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKPointLayerProperty.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKPointLayerProperty.cs
@@ -3,7 +3,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
///
- public class SKPointLayerProperty : GenericLayerProperty
+ public class SKPointLayerProperty : LayerProperty
{
internal SKPointLayerProperty()
{
diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKSizeLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKSizeLayerProperty.cs
index 259d4a910..f89229005 100644
--- a/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKSizeLayerProperty.cs
+++ b/src/Artemis.Core/Models/Profile/LayerProperties/Types/SKSizeLayerProperty.cs
@@ -3,7 +3,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
///
- public class SKSizeLayerProperty : GenericLayerProperty
+ public class SKSizeLayerProperty : LayerProperty
{
internal SKSizeLayerProperty()
{
diff --git a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs
index 7e61ec93b..60b83d7ca 100644
--- a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs
+++ b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
+using Artemis.Core.Events;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Plugins.Exceptions;
@@ -11,6 +12,11 @@ namespace Artemis.Core.Models.Profile
{
public bool PropertiesInitialized { get; private set; }
+ ///
+ /// Used to declare that this property group doesn't belong to a plugin and should use the core plugin GUID
+ ///
+ internal bool IsCorePropertyGroup { get; set; }
+
///
/// Called when all layer properties in this property group have been initialized
///
@@ -26,10 +32,10 @@ namespace Artemis.Core.Models.Profile
var propertyDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyDescriptionAttribute));
if (propertyDescription != null)
{
- if (!typeof(GenericLayerProperty<>).IsAssignableFrom(propertyInfo.PropertyType))
+ if (!typeof(LayerProperty<>).IsAssignableFrom(propertyInfo.PropertyType))
throw new ArtemisPluginException("Layer property with PropertyDescription attribute must be of type LayerProperty");
- var instance = (LayerProperty) Activator.CreateInstance(propertyInfo.PropertyType);
+ var instance = (BaseLayerProperty) Activator.CreateInstance(propertyInfo.PropertyType);
InitializeProperty(layer, path, instance);
propertyInfo.SetValue(this, instance);
}
@@ -52,11 +58,61 @@ namespace Artemis.Core.Models.Profile
PropertiesInitialized = true;
}
- private void InitializeProperty(Layer layer, string path, LayerProperty instance)
+ internal void ApplyToEntity()
{
- var entity = layer.LayerEntity.PropertyEntities.FirstOrDefault(p => p.Id == path);
- if (entity != null)
- instance.LoadFromEntity(entity);
+ // Get all properties with a PropertyDescriptionAttribute
+ foreach (var propertyInfo in GetType().GetProperties())
+ {
+ var propertyDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyDescriptionAttribute));
+ if (propertyDescription != null)
+ {
+ }
+ else
+ {
+ var propertyGroupDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyGroupDescriptionAttribute));
+ if (propertyGroupDescription != null)
+ {
+ }
+ }
+ }
}
+
+ internal void Update(double deltaTime)
+ {
+ // Since at this point we don't know what properties the group has without using reflection,
+ // let properties subscribe to the update event and update themselves
+ OnPropertyGroupUpdating(new PropertyGroupUpdatingEventArgs(deltaTime));
+ }
+
+ internal void Override(TimeSpan overrideTime)
+ {
+ // Same as above, but now the progress is overridden
+ OnPropertyGroupOverriding(new PropertyGroupUpdatingEventArgs(overrideTime));
+ }
+
+ private void InitializeProperty(Layer layer, string path, BaseLayerProperty instance)
+ {
+ var pluginGuid = IsCorePropertyGroup || instance.IsCoreProperty ? Constants.CorePluginInfo.Guid : layer.LayerBrush.PluginInfo.Guid;
+ var entity = layer.LayerEntity.PropertyEntities.FirstOrDefault(p => p.PluginGuid == pluginGuid && p.Path == path);
+ if (entity != null)
+ instance.ApplyToLayerProperty(entity, this);
+ }
+
+ #region Events
+
+ internal event EventHandler PropertyGroupUpdating;
+ internal event EventHandler PropertyGroupOverriding;
+
+ internal virtual void OnPropertyGroupUpdating(PropertyGroupUpdatingEventArgs e)
+ {
+ PropertyGroupUpdating?.Invoke(this, e);
+ }
+
+ protected virtual void OnPropertyGroupOverriding(PropertyGroupUpdatingEventArgs e)
+ {
+ PropertyGroupOverriding?.Invoke(this, e);
+ }
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Ninject/CoreModule.cs b/src/Artemis.Core/Ninject/CoreModule.cs
index 123f2076e..61701837b 100644
--- a/src/Artemis.Core/Ninject/CoreModule.cs
+++ b/src/Artemis.Core/Ninject/CoreModule.cs
@@ -1,7 +1,5 @@
-using System;
-using System.IO;
+using System.IO;
using Artemis.Core.Exceptions;
-using Artemis.Core.Models.Profile.KeyframeEngines;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Repositories.Interfaces;
@@ -53,14 +51,13 @@ namespace Artemis.Core.Ninject
catch (LiteException e)
{
// I don't like this way of error reporting, now I need to use reflection if I want a meaningful error code
- if (e.ErrorCode != LiteException.INVALID_DATABASE)
+ if (e.ErrorCode != LiteException.INVALID_DATABASE)
throw new ArtemisCoreException($"LiteDB threw error code {e.ErrorCode}. See inner exception for more details", e);
// If the DB is invalid it's probably LiteDB v4 (TODO: we'll have to do something better later)
File.Delete($"{Constants.DataFolder}\\database.db");
return new LiteRepository(Constants.ConnectionString);
}
-
}).InSingletonScope();
// Bind all repositories as singletons
@@ -73,15 +70,6 @@ namespace Artemis.Core.Ninject
.Configure(c => c.InSingletonScope());
});
- // Bind all keyframe engines
- Kernel.Bind(x =>
- {
- x.FromAssemblyContaining()
- .SelectAllClasses()
- .InheritedFrom()
- .BindAllBaseClasses();
- });
-
Kernel.Bind().ToProvider();
Kernel.Bind().ToProvider();
}
diff --git a/src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs
new file mode 100644
index 000000000..1d831f06f
--- /dev/null
+++ b/src/Artemis.Core/Plugins/LayerBrush/BaseLayerBrush.cs
@@ -0,0 +1,70 @@
+using System;
+using Artemis.Core.Models.Profile;
+using Artemis.Core.Plugins.Models;
+using Artemis.Core.Services.Interfaces;
+using SkiaSharp;
+
+namespace Artemis.Core.Plugins.LayerBrush
+{
+ ///
+ /// A basic layer brush that does not implement any layer property, to use properties with persistent storage,
+ /// implement instead
+ ///
+ public abstract class BaseLayerBrush : IDisposable
+ {
+ ///
+ /// Gets the layer this brush is applied to
+ ///
+ public Layer Layer { get; internal set; }
+
+ ///
+ /// Gets the descriptor of this brush
+ ///
+ public LayerBrushDescriptor Descriptor { get; internal set; }
+
+ ///
+ /// Gets the plugin info that defined this brush
+ ///
+ public PluginInfo PluginInfo => Descriptor.LayerBrushProvider.PluginInfo;
+
+ ///
+ /// Called when the brush is being removed from the layer
+ ///
+ public virtual void Dispose()
+ {
+ }
+
+ ///
+ /// Called before rendering every frame, write your update logic here
+ ///
+ ///
+ public virtual void Update(double deltaTime)
+ {
+ }
+
+ ///
+ /// The main method of rendering anything to the layer. The provided is specific to the layer
+ /// and matches it's width and height.
+ /// Called during rendering or layer preview, in the order configured on the layer
+ ///
+ /// The layer canvas
+ ///
+ /// The path to be filled, represents the shape
+ /// The paint to be used to fill the shape
+ public virtual void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
+ {
+ }
+
+ internal virtual void InitializeProperties(ILayerService layerService, string path)
+ {
+ }
+
+ internal virtual void ApplyToEntity()
+ {
+ }
+
+ internal virtual void UpdateProperties(double deltaTime)
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.Core/Plugins/LayerBrush/ILayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/ILayerBrush.cs
deleted file mode 100644
index 2b688fe91..000000000
--- a/src/Artemis.Core/Plugins/LayerBrush/ILayerBrush.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System;
-using Artemis.Core.Models.Profile;
-using Artemis.Core.Services.Interfaces;
-using SkiaSharp;
-
-namespace Artemis.Core.Plugins.LayerBrush
-{
- public interface ILayerBrush : IDisposable
- {
- ///
- /// Gets the layer this brush is applied to
- ///
- Layer Layer { get; }
-
- ///
- /// Gets the descriptor of this brush
- ///
- LayerBrushDescriptor Descriptor { get; }
-
- ///
- /// Called before rendering every frame, write your update logic here
- ///
- ///
- void Update(double deltaTime);
-
- ///
- /// The main method of rendering anything to the layer. The provided is specific to the layer
- /// and matches it's width and height.
- /// Called during rendering or layer preview, in the order configured on the layer
- ///
- /// The layer canvas
- ///
- /// The path to be filled, represents the shape
- /// The paint to be used to fill the shape
- void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);
-
- public void InitializeProperties(ILayerService layerService, string path);
- }
-}
\ No newline at end of file
diff --git a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs
index 7103ea0e1..176c2e062 100644
--- a/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs
+++ b/src/Artemis.Core/Plugins/LayerBrush/LayerBrush.cs
@@ -1,11 +1,10 @@
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Services.Interfaces;
-using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush
{
- public abstract class LayerBrush : ILayerBrush where T : LayerPropertyGroup
+ public abstract class LayerBrush : BaseLayerBrush where T : LayerPropertyGroup
{
private T _properties;
@@ -15,27 +14,6 @@ namespace Artemis.Core.Plugins.LayerBrush
Descriptor = descriptor;
}
- ///
- public Layer Layer { get; }
-
- ///
- public LayerBrushDescriptor Descriptor { get; }
-
- ///
- public virtual void Dispose()
- {
- }
-
- ///
- public virtual void Update(double deltaTime)
- {
- }
-
- ///
- public virtual void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
- {
- }
-
#region Properties
///
@@ -52,12 +30,12 @@ namespace Artemis.Core.Plugins.LayerBrush
}
internal set => _properties = value;
}
-
+
///
/// Gets whether all properties on this brush are initialized
///
public bool PropertiesInitialized { get; private set; }
-
+
///
/// Called when all layer properties in this brush have been initialized
///
@@ -65,13 +43,23 @@ namespace Artemis.Core.Plugins.LayerBrush
{
}
- public void InitializeProperties(ILayerService layerService, string path)
+ internal override void InitializeProperties(ILayerService layerService, string path)
{
- Properties.InitializeProperties(layerService, Descriptor.LayerBrushProvider.PluginInfo, path);
+ Properties.InitializeProperties(layerService, Layer, path);
OnPropertiesInitialized();
PropertiesInitialized = true;
}
+ internal override void ApplyToEntity()
+ {
+ Properties.ApplyToEntity();
+ }
+
+ internal override void UpdateProperties(double deltaTime)
+ {
+ Properties.Update(deltaTime);
+ }
+
#endregion
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Plugins/LayerBrush/LayerBrushProvider.cs b/src/Artemis.Core/Plugins/LayerBrush/LayerBrushProvider.cs
index 2631161dd..53f505f7a 100644
--- a/src/Artemis.Core/Plugins/LayerBrush/LayerBrushProvider.cs
+++ b/src/Artemis.Core/Plugins/LayerBrush/LayerBrushProvider.cs
@@ -20,7 +20,7 @@ namespace Artemis.Core.Plugins.LayerBrush
public ReadOnlyCollection LayerBrushDescriptors => _layerBrushDescriptors.AsReadOnly();
- protected void AddLayerBrushDescriptor(string displayName, string description, string icon) where T : ILayerBrush
+ protected void AddLayerBrushDescriptor(string displayName, string description, string icon) where T : BaseLayerBrush
{
_layerBrushDescriptors.Add(new LayerBrushDescriptor(displayName, description, icon, typeof(T), this));
}
diff --git a/src/Artemis.Core/Services/Interfaces/ILayerService.cs b/src/Artemis.Core/Services/Interfaces/ILayerService.cs
index 7731b655e..c59245532 100644
--- a/src/Artemis.Core/Services/Interfaces/ILayerService.cs
+++ b/src/Artemis.Core/Services/Interfaces/ILayerService.cs
@@ -1,6 +1,4 @@
using Artemis.Core.Models.Profile;
-using Artemis.Core.Models.Profile.KeyframeEngines;
-using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Plugins.LayerBrush;
namespace Artemis.Core.Services.Interfaces
@@ -8,14 +6,27 @@ namespace Artemis.Core.Services.Interfaces
public interface ILayerService : IArtemisService
{
///
- /// Instantiates and adds the described by the provided
+ /// Creates a new layer
+ ///
+ ///
+ ///
+ ///
+ ///
+ Layer CreateLayer(Profile profile, ProfileElement parent, string name);
+
+ ///
+ /// Instantiates and adds the described by the provided
+ ///
/// to the .
///
/// The layer to instantiate the brush for
///
- ILayerBrush InstantiateLayerBrush(Layer layer);
+ BaseLayerBrush InstantiateLayerBrush(Layer layer);
- void LoadPropertyBaseValue(Layer layer, string path, object layerProperty);
- void LoadPropertyKeyframes(Layer layer, string path, object layerProperty);
+ ///
+ /// Removes the layer brush from the provided layer and disposes it
+ ///
+ ///
+ void RemoveLayerBrush(Layer layer);
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Services/LayerService.cs b/src/Artemis.Core/Services/LayerService.cs
index 5b154ba52..4ef8c7981 100644
--- a/src/Artemis.Core/Services/LayerService.cs
+++ b/src/Artemis.Core/Services/LayerService.cs
@@ -1,12 +1,7 @@
-using System.Collections.Generic;
-using System.Linq;
+using System.Linq;
using Artemis.Core.Models.Profile;
-using Artemis.Core.Models.Profile.KeyframeEngines;
-using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Plugins.LayerBrush;
-using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
-using Newtonsoft.Json;
using Ninject;
using Ninject.Parameters;
using Serilog;
@@ -31,8 +26,8 @@ namespace Artemis.Core.Services
var layer = new Layer(profile, parent, name);
// Layers have two hardcoded property groups, instantiate them
- layer.General.InitializeProperties(this, layer, null, null);
- layer.Transform.InitializeProperties(this, layer, null, null);
+ layer.General.InitializeProperties(this, layer, null);
+ layer.Transform.InitializeProperties(this, layer, null);
// With the properties loaded, the layer brush can be instantiated
InstantiateLayerBrush(layer);
@@ -40,7 +35,7 @@ namespace Artemis.Core.Services
return layer;
}
- public ILayerBrush InstantiateLayerBrush(Layer layer)
+ public BaseLayerBrush InstantiateLayerBrush(Layer layer)
{
RemoveLayerBrush(layer);
@@ -62,7 +57,7 @@ namespace Artemis.Core.Services
new ConstructorArgument("layer", layer),
new ConstructorArgument("descriptor", descriptor)
};
- var layerBrush = (ILayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments);
+ var layerBrush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments);
layerBrush.InitializeProperties(this, null);
layer.LayerBrush = layerBrush;
@@ -76,11 +71,9 @@ namespace Artemis.Core.Services
var brush = layer.LayerBrush;
layer.LayerBrush = null;
-
- var propertiesToRemove = layer.Properties.Where(l => l.PluginInfo == brush.Descriptor.LayerBrushProvider.PluginInfo).ToList();
- foreach (var layerProperty in propertiesToRemove)
- layer.Properties.RemoveLayerProperty(layerProperty);
brush.Dispose();
+
+ layer.LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid);
}
}
}
\ No newline at end of file
diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs
index 8434ea02b..8729211b5 100644
--- a/src/Artemis.Core/Services/Storage/ProfileService.cs
+++ b/src/Artemis.Core/Services/Storage/ProfileService.cs
@@ -94,7 +94,6 @@ namespace Artemis.Core.Services.Storage
if (profile != null)
{
InstantiateProfileLayerBrushes(profile);
- InstantiateProfileKeyframeEngines(profile);
}
}
@@ -165,14 +164,7 @@ namespace Artemis.Core.Services.Storage
foreach (var layer in profile.GetAllLayers().Where(l => l.LayerBrush == null))
_layerService.InstantiateLayerBrush(layer);
}
-
- private void InstantiateProfileKeyframeEngines(Profile profile)
- {
- // Only instantiate engines for properties without an existing engine instance
- foreach (var layerProperty in profile.GetAllLayers().SelectMany(l => l.Properties).Where(p => p.KeyframeEngine == null))
- _layerService.InstantiateKeyframeEngine(layerProperty);
- }
-
+
private void ActiveProfilesPopulateLeds(ArtemisSurface surface)
{
var profileModules = _pluginService.GetPluginsOfType();
@@ -186,14 +178,7 @@ namespace Artemis.Core.Services.Storage
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
InstantiateProfileLayerBrushes(profileModule.ActiveProfile);
}
-
- private void ActiveProfilesInstantiateKeyframeEngines()
- {
- var profileModules = _pluginService.GetPluginsOfType();
- foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
- InstantiateProfileKeyframeEngines(profileModule.ActiveProfile);
- }
-
+
#region Event handlers
private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e)
@@ -212,7 +197,6 @@ namespace Artemis.Core.Services.Storage
if (e.PluginInfo.Instance is LayerBrushProvider)
{
ActiveProfilesInstantiateProfileLayerBrushes();
- ActiveProfilesInstantiateKeyframeEngines();
}
else if (e.PluginInfo.Instance is ProfileModule profileModule)
{
diff --git a/src/Artemis.Storage/Entities/Profile/PropertyEntity.cs b/src/Artemis.Storage/Entities/Profile/PropertyEntity.cs
index 2f450633d..4c339e22e 100644
--- a/src/Artemis.Storage/Entities/Profile/PropertyEntity.cs
+++ b/src/Artemis.Storage/Entities/Profile/PropertyEntity.cs
@@ -10,8 +10,9 @@ namespace Artemis.Storage.Entities.Profile
KeyframeEntities = new List();
}
- public string Id { get; set; }
- public string ValueType { get; set; }
+ public Guid PluginGuid { get; set; }
+ public string Path { get; set; }
+
public string Value { get; set; }
public bool IsUsingKeyframes { get; set; }
diff --git a/src/Artemis.UI/Ninject/Factories/IVMFactory.cs b/src/Artemis.UI/Ninject/Factories/IVMFactory.cs
index 7bd7aae57..34986e68d 100644
--- a/src/Artemis.UI/Ninject/Factories/IVMFactory.cs
+++ b/src/Artemis.UI/Ninject/Factories/IVMFactory.cs
@@ -50,7 +50,7 @@ namespace Artemis.UI.Ninject.Factories
public interface ILayerPropertyVmFactory : IVmFactory
{
- LayerPropertyViewModel Create(LayerProperty layerProperty, LayerPropertyViewModel parent);
+ LayerPropertyViewModel Create(BaseLayerProperty layerProperty, LayerPropertyViewModel parent);
}
public interface IPropertyTreeVmFactory : IVmFactory
diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs
index 5dde7e5fd..cc4ef6b8f 100644
--- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs
+++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs
@@ -169,7 +169,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
PopulateProperties(e.LayerProperty.Layer);
}
- private LayerPropertyViewModel CreatePropertyViewModel(LayerProperty layerProperty)
+ private LayerPropertyViewModel CreatePropertyViewModel(BaseLayerProperty layerProperty)
{
LayerPropertyViewModel parent = null;
// If the property has a parent, find it's VM
diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs
index b3c72586d..497e6f379 100644
--- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs
+++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertyViewModel.cs
@@ -16,7 +16,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
private bool _keyframesEnabled;
private bool _isExpanded;
- public LayerPropertyViewModel(LayerProperty layerProperty, LayerPropertyViewModel parent, IKernel kernel, IProfileEditorService profileEditorService)
+ public LayerPropertyViewModel(BaseLayerProperty layerProperty, LayerPropertyViewModel parent, IKernel kernel, IProfileEditorService profileEditorService)
{
_kernel = kernel;
_profileEditorService = profileEditorService;
@@ -30,7 +30,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
Parent?.Children.Add(this);
}
- public LayerProperty LayerProperty { get; }
+ public BaseLayerProperty LayerProperty { get; }
public LayerPropertyViewModel Parent { get; }
public List Children { get; }