1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-01 10:13:30 +00:00

Conditions - Refactor layer properties WIP

This commit is contained in:
Robert 2020-04-29 19:44:42 +02:00
parent d9bba8cb54
commit 660324c980
33 changed files with 363 additions and 492 deletions

View File

@ -5,11 +5,11 @@ namespace Artemis.Core.Events
{ {
public class LayerPropertyEventArgs : EventArgs public class LayerPropertyEventArgs : EventArgs
{ {
public LayerPropertyEventArgs(LayerProperty layerProperty) public LayerPropertyEventArgs(BaseLayerProperty layerProperty)
{ {
LayerProperty = layerProperty; LayerProperty = layerProperty;
} }
public LayerProperty LayerProperty { get; } public BaseLayerProperty LayerProperty { get; }
} }
} }

View File

@ -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; }
}
}

View File

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class FloatKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(float)};
protected override object GetInterpolatedValue()
{
var currentKeyframe = (Keyframe<float>) CurrentKeyframe;
var nextKeyframe = (Keyframe<float>) NextKeyframe;
var diff = nextKeyframe.Value - currentKeyframe.Value;
return currentKeyframe.Value + diff * KeyframeProgressEased;
}
}
}

View File

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class IntKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(int)};
protected override object GetInterpolatedValue()
{
var currentKeyframe = (Keyframe<int>) CurrentKeyframe;
var nextKeyframe = (Keyframe<int>) NextKeyframe;
var diff = nextKeyframe.Value - currentKeyframe.Value;
return (int) Math.Round(currentKeyframe.Value + diff * KeyframeProgressEased, MidpointRounding.AwayFromZero);
}
}
}

View File

@ -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
{
/// <summary>
/// Indicates whether <see cref="Initialize" /> has been called.
/// </summary>
public bool Initialized { get; private set; }
/// <summary>
/// The layer property this keyframe engine applies to.
/// </summary>
public LayerProperty LayerProperty { get; private set; }
/// <summary>
/// The total progress
/// </summary>
public TimeSpan Progress { get; private set; }
/// <summary>
/// The progress from the current keyframe to the next.
/// <para>Range 0.0 to 1.0.</para>
/// </summary>
public float KeyframeProgress { get; private set; }
/// <summary>
/// The progress from the current keyframe to the next with the current keyframes easing function applied.
/// <para>Range 0.0 to 1.0 but can be higher than 1.0 depending on easing function.</para>
/// </summary>
public float KeyframeProgressEased { get; set; }
/// <summary>
/// The current keyframe
/// </summary>
public BaseKeyframe CurrentKeyframe { get; private set; }
/// <summary>
/// The next keyframe
/// </summary>
public BaseKeyframe NextKeyframe { get; private set; }
/// <summary>
/// The types this keyframe engine supports.
/// </summary>
public abstract List<Type> CompatibleTypes { get; }
/// <summary>
/// Associates the keyframe engine with the provided layer property.
/// </summary>
/// <param name="layerProperty"></param>
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;
}
/// <summary>
/// Updates the engine's progress
/// </summary>
/// <param name="deltaTime"></param>
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
}
/// <summary>
/// Overrides the engine's progress to the provided value
/// </summary>
/// <param name="progress"></param>
public void OverrideProgress(TimeSpan progress)
{
Progress = TimeSpan.Zero;
Update(progress.TotalSeconds);
}
/// <summary>
/// Gets the current value, if the progress is in between two keyframes the value will be interpolated
/// </summary>
/// <returns></returns>
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();
}
}

View File

@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class SKColorKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKColor)};
protected override object GetInterpolatedValue()
{
var currentKeyframe = (Keyframe<SKColor>) CurrentKeyframe;
var nextKeyframe = (Keyframe<SKColor>) 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));
}
}
}

View File

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class SKPointKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKPoint)};
protected override object GetInterpolatedValue()
{
var currentKeyframe = (Keyframe<SKPoint>) CurrentKeyframe;
var nextKeyframe = (Keyframe<SKPoint>) 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);
}
}
}

View File

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class SKSizeKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKSize)};
protected override object GetInterpolatedValue()
{
var currentKeyframe = (Keyframe<SKSize>) CurrentKeyframe;
var nextKeyframe = (Keyframe<SKSize>) 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);
}
}
}

View File

@ -32,8 +32,8 @@ namespace Artemis.Core.Models.Profile
Profile = profile; Profile = profile;
Parent = parent; Parent = parent;
Name = name; Name = name;
General = new LayerGeneralProperties(); General = new LayerGeneralProperties {IsCorePropertyGroup = true};
Transform = new LayerTransformProperties(); Transform = new LayerTransformProperties {IsCorePropertyGroup = true};
_leds = new List<ArtemisLed>(); _leds = new List<ArtemisLed>();
} }
@ -47,8 +47,8 @@ namespace Artemis.Core.Models.Profile
Parent = parent; Parent = parent;
Name = layerEntity.Name; Name = layerEntity.Name;
Order = layerEntity.Order; Order = layerEntity.Order;
General = new LayerGeneralProperties(); General = new LayerGeneralProperties {IsCorePropertyGroup = true};
Transform = new LayerTransformProperties(); Transform = new LayerTransformProperties {IsCorePropertyGroup = true};
_leds = new List<ArtemisLed>(); _leds = new List<ArtemisLed>();
} }
@ -104,7 +104,7 @@ namespace Artemis.Core.Models.Profile
/// <summary> /// <summary>
/// The brush that will fill the <see cref="LayerShape" />. /// The brush that will fill the <see cref="LayerShape" />.
/// </summary> /// </summary>
public ILayerBrush LayerBrush { get; internal set; } public BaseLayerBrush LayerBrush { get; internal set; }
public override string ToString() public override string ToString()
{ {
@ -121,8 +121,9 @@ namespace Artemis.Core.Models.Profile
LayerEntity.Order = Order; LayerEntity.Order = Order;
LayerEntity.Name = Name; LayerEntity.Name = Name;
LayerEntity.ProfileId = Profile.EntityId; LayerEntity.ProfileId = Profile.EntityId;
foreach (var layerProperty in Properties) General.ApplyToEntity();
layerProperty.ApplyToEntity(); Transform.ApplyToEntity();
LayerBrush.ApplyToEntity();
// LEDs // LEDs
LayerEntity.Leds.Clear(); LayerEntity.Leds.Clear();
@ -146,7 +147,7 @@ namespace Artemis.Core.Models.Profile
private void ApplyShapeType() private void ApplyShapeType()
{ {
switch (Properties.ShapeType.CurrentValue) switch (General.ShapeType.CurrentValue)
{ {
case LayerShapeType.Ellipse: case LayerShapeType.Ellipse:
LayerShape = new Ellipse(this); LayerShape = new Ellipse(this);
@ -179,20 +180,11 @@ namespace Artemis.Core.Models.Profile
/// <inheritdoc /> /// <inheritdoc />
public override void Update(double deltaTime) public override void Update(double deltaTime)
{ {
foreach (var property in Properties) General.Update(deltaTime);
property.KeyframeEngine?.Update(deltaTime); Transform.Update(deltaTime);
// For now, reset all keyframe engines after the last keyframe was hit LayerBrush?.UpdateProperties(deltaTime);
// This is a placeholder method of repeating the animation until repeat modes are implemented // TODO: Find the last keyframe and if required, reset the properties
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?.Update(deltaTime); LayerBrush?.Update(deltaTime);
} }
@ -208,10 +200,10 @@ namespace Artemis.Core.Models.Profile
using (var paint = new SKPaint()) using (var paint = new SKPaint())
{ {
paint.BlendMode = Properties.BlendMode.CurrentValue; paint.BlendMode = General.BlendMode.CurrentValue;
paint.Color = new SKColor(0, 0, 0, (byte) (Properties.Opacity.CurrentValue * 2.55f)); paint.Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f));
switch (Properties.FillType.CurrentValue) switch (General.FillType.CurrentValue)
{ {
case LayerFillType.Stretch: case LayerFillType.Stretch:
StretchRender(canvas, canvasInfo, paint); StretchRender(canvas, canvasInfo, paint);
@ -230,11 +222,11 @@ namespace Artemis.Core.Models.Profile
private void StretchRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint) private void StretchRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint)
{ {
// Apply transformations // Apply transformations
var sizeProperty = Properties.Scale.CurrentValue; var sizeProperty = Transform.Scale.CurrentValue;
var rotationProperty = Properties.Rotation.CurrentValue; var rotationProperty = Transform.Rotation.CurrentValue;
var anchorPosition = GetLayerAnchorPosition(); 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 // 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; 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) private void ClipRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint)
{ {
// Apply transformations // Apply transformations
var sizeProperty = Properties.Scale.CurrentValue; var sizeProperty = Transform.Scale.CurrentValue;
var rotationProperty = Properties.Rotation.CurrentValue; var rotationProperty = Transform.Rotation.CurrentValue;
var anchorPosition = GetLayerAnchorPosition(); 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 // 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; var x = anchorPosition.X - Bounds.MidX - anchorProperty.X * Bounds.Width;
@ -308,7 +300,7 @@ namespace Artemis.Core.Models.Profile
internal SKPoint GetLayerAnchorPosition() internal SKPoint GetLayerAnchorPosition()
{ {
var positionProperty = Properties.Position.CurrentValue; var positionProperty = Transform.Position.CurrentValue;
// Start at the center of the shape // Start at the center of the shape
var position = new SKPoint(Bounds.MidX, Bounds.MidY); var position = new SKPoint(Bounds.MidX, Bounds.MidY);

View File

@ -0,0 +1,25 @@
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Models.Profile.LayerProperties
{
public abstract class BaseLayerProperty
{
/// <summary>
/// Used to declare that this property doesn't belong to a plugin and should use the core plugin GUID
/// </summary>
internal bool IsCoreProperty { get; set; }
/// <summary>
/// Applies the provided property entity to the layer property by deserializing the JSON base value and keyframe values
/// </summary>
/// <param name="entity"></param>
/// <param name="layerPropertyGroup"></param>
internal abstract void ApplyToLayerProperty(PropertyEntity entity, LayerPropertyGroup layerPropertyGroup);
/// <summary>
/// Saves the property to the underlying property entity that was configured when calling
/// <see cref="ApplyToLayerProperty" />
/// </summary>
internal abstract void ApplyToEntity();
}
}

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using Artemis.Core.Exceptions;
using Artemis.Core.Utilities; using Artemis.Core.Utilities;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -10,18 +12,19 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// <summary> /// <summary>
/// Represents a property on a layer. Properties are saved in storage and can optionally be modified from the UI. /// Represents a property on a layer. Properties are saved in storage and can optionally be modified from the UI.
/// <para> /// <para>
/// 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. /// these for you.
/// </para> /// </para>
/// </summary> /// </summary>
/// <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 GenericLayerProperty<T> : LayerProperty public abstract class LayerProperty<T> : BaseLayerProperty
{ {
private T _currentValue;
private List<LayerPropertyKeyframe<T>> _keyframes;
private T _baseValue; private T _baseValue;
private T _currentValue;
private bool _isInitialized;
private List<LayerPropertyKeyframe<T>> _keyframes;
protected GenericLayerProperty() protected LayerProperty()
{ {
_keyframes = new List<LayerPropertyKeyframe<T>>(); _keyframes = new List<LayerPropertyKeyframe<T>>();
} }
@ -92,47 +95,8 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// </summary> /// </summary>
public LayerPropertyKeyframe<T> NextKeyframe { get; protected set; } public LayerPropertyKeyframe<T> NextKeyframe { get; protected set; }
/// <summary> internal PropertyEntity PropertyEntity { get; set; }
/// Updates the property, moving the timeline forwards by the provided <paramref name="deltaTime" /> internal LayerPropertyGroup LayerPropertyGroup { get; set; }
/// </summary>
/// <param name="deltaTime">The amount of time to move the timeline forwards</param>
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();
}
/// <summary>
/// Overrides the timeline progress to match the provided <paramref name="progress" />
/// </summary>
/// <param name="progress">The new progress to set the layer property timeline to.</param>
public void OverrideProgress(TimeSpan progress)
{
TimelineProgress = TimeSpan.Zero;
Update(progress.TotalSeconds);
}
/// <summary> /// <summary>
/// Adds a keyframe to the layer property /// Adds a keyframe to the layer property
@ -166,24 +130,106 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// <param name="keyframeProgressEased">The current keyframe progress, eased with the current easing function</param> /// <param name="keyframeProgressEased">The current keyframe progress, eased with the current easing function</param>
protected abstract void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased); protected abstract void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased);
/// <summary>
/// Updates the property, moving the timeline forwards by the provided <paramref name="deltaTime" />
/// </summary>
/// <param name="deltaTime">The amount of time to move the timeline forwards</param>
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();
}
/// <summary>
/// Overrides the timeline progress to match the provided <paramref name="overrideTime" />
/// </summary>
/// <param name="overrideTime">The new progress to set the layer property timeline to.</param>
internal void OverrideProgress(TimeSpan overrideTime)
{
TimelineProgress = TimeSpan.Zero;
Update(overrideTime.TotalSeconds);
}
/// <summary>
/// Sorts the keyframes in ascending order by position
/// </summary>
internal void SortKeyframes() internal void SortKeyframes()
{ {
_keyframes = _keyframes.OrderBy(k => k.Position).ToList(); _keyframes = _keyframes.OrderBy(k => k.Position).ToList();
} }
internal override void LoadFromEntity(PropertyEntity entity) internal override void ApplyToLayerProperty(PropertyEntity entity, LayerPropertyGroup layerPropertyGroup)
{ {
BaseValue = JsonConvert.DeserializeObject<T>(entity.Value); // Doubt this will happen but let's make sure
CurrentValue = BaseValue; if (_isInitialized)
throw new ArtemisCoreException("Layer property already initialized, wut");
_keyframes.Clear(); PropertyEntity = entity;
foreach (var keyframeEntity in entity.KeyframeEntities) LayerPropertyGroup = layerPropertyGroup;
LayerPropertyGroup.PropertyGroupUpdating += (sender, args) => Update(args.DeltaTime);
LayerPropertyGroup.PropertyGroupOverriding += (sender, args) => OverrideProgress(args.OverrideTime);
try
{ {
var value = JsonConvert.DeserializeObject<T>(keyframeEntity.Value); IsLoadedFromStorage = true;
var keyframe = new LayerPropertyKeyframe<T>(value, keyframeEntity.Position, (Easings.Functions) keyframeEntity.EasingFunction); BaseValue = JsonConvert.DeserializeObject<T>(entity.Value);
_keyframes.Add(keyframe); CurrentValue = BaseValue;
_keyframes.Clear();
_keyframes.AddRange(entity.KeyframeEntities.Select(k => new LayerPropertyKeyframe<T>(
JsonConvert.DeserializeObject<T>(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 #region Events
@ -215,9 +261,4 @@ namespace Artemis.Core.Models.Profile.LayerProperties
#endregion #endregion
} }
public abstract class LayerProperty
{
internal abstract void LoadFromEntity(PropertyEntity entity);
}
} }

View File

@ -14,7 +14,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
EasingFunction = easingFunction; EasingFunction = easingFunction;
} }
public GenericLayerProperty<T> LayerProperty { get; internal set; } public LayerProperty<T> LayerProperty { get; internal set; }
public T Value { get; set; } public T Value { get; set; }
public TimeSpan Position public TimeSpan Position

View File

@ -4,7 +4,7 @@ using Artemis.Core.Models.Profile.Colors;
namespace Artemis.Core.Models.Profile.LayerProperties.Types namespace Artemis.Core.Models.Profile.LayerProperties.Types
{ {
/// <inheritdoc/> /// <inheritdoc/>
public class ColorGradientLayerProperty : GenericLayerProperty<ColorGradient> public class ColorGradientLayerProperty : LayerProperty<ColorGradient>
{ {
internal ColorGradientLayerProperty() internal ColorGradientLayerProperty()
{ {

View File

@ -3,7 +3,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types namespace Artemis.Core.Models.Profile.LayerProperties.Types
{ {
/// <inheritdoc/> /// <inheritdoc/>
public class EnumLayerProperty<T> : GenericLayerProperty<T> where T : System.Enum public class EnumLayerProperty<T> : LayerProperty<T> where T : System.Enum
{ {
public EnumLayerProperty() public EnumLayerProperty()
{ {

View File

@ -1,7 +1,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types namespace Artemis.Core.Models.Profile.LayerProperties.Types
{ {
/// <inheritdoc/> /// <inheritdoc/>
public class FloatLayerProperty : GenericLayerProperty<float> public class FloatLayerProperty : LayerProperty<float>
{ {
internal FloatLayerProperty() internal FloatLayerProperty()
{ {

View File

@ -3,7 +3,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types namespace Artemis.Core.Models.Profile.LayerProperties.Types
{ {
/// <inheritdoc/> /// <inheritdoc/>
public class IntLayerProperty : GenericLayerProperty<int> public class IntLayerProperty : LayerProperty<int>
{ {
internal IntLayerProperty() internal IntLayerProperty()
{ {

View File

@ -5,7 +5,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties.Types
/// <summary> /// <summary>
/// A special layer property used to configure the selected layer brush /// A special layer property used to configure the selected layer brush
/// </summary> /// </summary>
public class LayerBrushReferenceLayerProperty : GenericLayerProperty<LayerBrushReference> public class LayerBrushReferenceLayerProperty : LayerProperty<LayerBrushReference>
{ {
internal LayerBrushReferenceLayerProperty() internal LayerBrushReferenceLayerProperty()
{ {

View File

@ -4,7 +4,7 @@ using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerProperties.Types namespace Artemis.Core.Models.Profile.LayerProperties.Types
{ {
/// <inheritdoc/> /// <inheritdoc/>
public class SKColorLayerProperty : GenericLayerProperty<SKColor> public class SKColorLayerProperty : LayerProperty<SKColor>
{ {
internal SKColorLayerProperty() internal SKColorLayerProperty()
{ {

View File

@ -3,7 +3,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types namespace Artemis.Core.Models.Profile.LayerProperties.Types
{ {
/// <inheritdoc/> /// <inheritdoc/>
public class SKPointLayerProperty : GenericLayerProperty<SKPoint> public class SKPointLayerProperty : LayerProperty<SKPoint>
{ {
internal SKPointLayerProperty() internal SKPointLayerProperty()
{ {

View File

@ -3,7 +3,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types namespace Artemis.Core.Models.Profile.LayerProperties.Types
{ {
/// <inheritdoc/> /// <inheritdoc/>
public class SKSizeLayerProperty : GenericLayerProperty<SKSize> public class SKSizeLayerProperty : LayerProperty<SKSize>
{ {
internal SKSizeLayerProperty() internal SKSizeLayerProperty()
{ {

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using Artemis.Core.Events;
using Artemis.Core.Models.Profile.LayerProperties; using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes; using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Plugins.Exceptions; using Artemis.Core.Plugins.Exceptions;
@ -11,6 +12,11 @@ namespace Artemis.Core.Models.Profile
{ {
public bool PropertiesInitialized { get; private set; } public bool PropertiesInitialized { get; private set; }
/// <summary>
/// Used to declare that this property group doesn't belong to a plugin and should use the core plugin GUID
/// </summary>
internal bool IsCorePropertyGroup { get; set; }
/// <summary> /// <summary>
/// Called when all layer properties in this property group have been initialized /// Called when all layer properties in this property group have been initialized
/// </summary> /// </summary>
@ -26,10 +32,10 @@ namespace Artemis.Core.Models.Profile
var propertyDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyDescriptionAttribute)); var propertyDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyDescriptionAttribute));
if (propertyDescription != null) 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"); 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); InitializeProperty(layer, path, instance);
propertyInfo.SetValue(this, instance); propertyInfo.SetValue(this, instance);
} }
@ -52,11 +58,61 @@ namespace Artemis.Core.Models.Profile
PropertiesInitialized = true; PropertiesInitialized = true;
} }
private void InitializeProperty(Layer layer, string path, LayerProperty instance) internal void ApplyToEntity()
{ {
var entity = layer.LayerEntity.PropertyEntities.FirstOrDefault(p => p.Id == path); // Get all properties with a PropertyDescriptionAttribute
if (entity != null) foreach (var propertyInfo in GetType().GetProperties())
instance.LoadFromEntity(entity); {
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<PropertyGroupUpdatingEventArgs> PropertyGroupUpdating;
internal event EventHandler<PropertyGroupUpdatingEventArgs> PropertyGroupOverriding;
internal virtual void OnPropertyGroupUpdating(PropertyGroupUpdatingEventArgs e)
{
PropertyGroupUpdating?.Invoke(this, e);
}
protected virtual void OnPropertyGroupOverriding(PropertyGroupUpdatingEventArgs e)
{
PropertyGroupOverriding?.Invoke(this, e);
}
#endregion
} }
} }

View File

@ -1,7 +1,5 @@
using System; using System.IO;
using System.IO;
using Artemis.Core.Exceptions; using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.KeyframeEngines;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Repositories.Interfaces; using Artemis.Storage.Repositories.Interfaces;
@ -60,7 +58,6 @@ namespace Artemis.Core.Ninject
File.Delete($"{Constants.DataFolder}\\database.db"); File.Delete($"{Constants.DataFolder}\\database.db");
return new LiteRepository(Constants.ConnectionString); return new LiteRepository(Constants.ConnectionString);
} }
}).InSingletonScope(); }).InSingletonScope();
// Bind all repositories as singletons // Bind all repositories as singletons
@ -73,15 +70,6 @@ namespace Artemis.Core.Ninject
.Configure(c => c.InSingletonScope()); .Configure(c => c.InSingletonScope());
}); });
// Bind all keyframe engines
Kernel.Bind(x =>
{
x.FromAssemblyContaining<KeyframeEngine>()
.SelectAllClasses()
.InheritedFrom<KeyframeEngine>()
.BindAllBaseClasses();
});
Kernel.Bind<PluginSettings>().ToProvider<PluginSettingsProvider>(); Kernel.Bind<PluginSettings>().ToProvider<PluginSettingsProvider>();
Kernel.Bind<ILogger>().ToProvider<LoggerProvider>(); Kernel.Bind<ILogger>().ToProvider<LoggerProvider>();
} }

View File

@ -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
{
/// <summary>
/// A basic layer brush that does not implement any layer property, to use properties with persistent storage,
/// implement <see cref="LayerBrush{T}" /> instead
/// </summary>
public abstract class BaseLayerBrush : IDisposable
{
/// <summary>
/// Gets the layer this brush is applied to
/// </summary>
public Layer Layer { get; internal set; }
/// <summary>
/// Gets the descriptor of this brush
/// </summary>
public LayerBrushDescriptor Descriptor { get; internal set; }
/// <summary>
/// Gets the plugin info that defined this brush
/// </summary>
public PluginInfo PluginInfo => Descriptor.LayerBrushProvider.PluginInfo;
/// <summary>
/// Called when the brush is being removed from the layer
/// </summary>
public virtual void Dispose()
{
}
/// <summary>
/// Called before rendering every frame, write your update logic here
/// </summary>
/// <param name="deltaTime"></param>
public virtual void Update(double deltaTime)
{
}
/// <summary>
/// The main method of rendering anything to the layer. The provided <see cref="SKCanvas" /> is specific to the layer
/// and matches it's width and height.
/// <para>Called during rendering or layer preview, in the order configured on the layer</para>
/// </summary>
/// <param name="canvas">The layer canvas</param>
/// <param name="canvasInfo"></param>
/// <param name="path">The path to be filled, represents the shape</param>
/// <param name="paint">The paint to be used to fill the shape</param>
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)
{
}
}
}

View File

@ -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
{
/// <summary>
/// Gets the layer this brush is applied to
/// </summary>
Layer Layer { get; }
/// <summary>
/// Gets the descriptor of this brush
/// </summary>
LayerBrushDescriptor Descriptor { get; }
/// <summary>
/// Called before rendering every frame, write your update logic here
/// </summary>
/// <param name="deltaTime"></param>
void Update(double deltaTime);
/// <summary>
/// The main method of rendering anything to the layer. The provided <see cref="SKCanvas" /> is specific to the layer
/// and matches it's width and height.
/// <para>Called during rendering or layer preview, in the order configured on the layer</para>
/// </summary>
/// <param name="canvas">The layer canvas</param>
/// <param name="canvasInfo"></param>
/// <param name="path">The path to be filled, represents the shape</param>
/// <param name="paint">The paint to be used to fill the shape</param>
void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);
public void InitializeProperties(ILayerService layerService, string path);
}
}

View File

@ -1,11 +1,10 @@
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Exceptions; using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush namespace Artemis.Core.Plugins.LayerBrush
{ {
public abstract class LayerBrush<T> : ILayerBrush where T : LayerPropertyGroup public abstract class LayerBrush<T> : BaseLayerBrush where T : LayerPropertyGroup
{ {
private T _properties; private T _properties;
@ -15,27 +14,6 @@ namespace Artemis.Core.Plugins.LayerBrush
Descriptor = descriptor; Descriptor = descriptor;
} }
/// <inheritdoc />
public Layer Layer { get; }
/// <inheritdoc />
public LayerBrushDescriptor Descriptor { get; }
/// <inheritdoc />
public virtual void Dispose()
{
}
/// <inheritdoc />
public virtual void Update(double deltaTime)
{
}
/// <inheritdoc />
public virtual void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
{
}
#region Properties #region Properties
/// <summary> /// <summary>
@ -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(); OnPropertiesInitialized();
PropertiesInitialized = true; PropertiesInitialized = true;
} }
internal override void ApplyToEntity()
{
Properties.ApplyToEntity();
}
internal override void UpdateProperties(double deltaTime)
{
Properties.Update(deltaTime);
}
#endregion #endregion
} }
} }

View File

@ -20,7 +20,7 @@ namespace Artemis.Core.Plugins.LayerBrush
public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors => _layerBrushDescriptors.AsReadOnly(); public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors => _layerBrushDescriptors.AsReadOnly();
protected void AddLayerBrushDescriptor<T>(string displayName, string description, string icon) where T : ILayerBrush protected void AddLayerBrushDescriptor<T>(string displayName, string description, string icon) where T : BaseLayerBrush
{ {
_layerBrushDescriptors.Add(new LayerBrushDescriptor(displayName, description, icon, typeof(T), this)); _layerBrushDescriptors.Add(new LayerBrushDescriptor(displayName, description, icon, typeof(T), this));
} }

View File

@ -1,6 +1,4 @@
using Artemis.Core.Models.Profile; 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.LayerBrush;
namespace Artemis.Core.Services.Interfaces namespace Artemis.Core.Services.Interfaces
@ -8,14 +6,27 @@ namespace Artemis.Core.Services.Interfaces
public interface ILayerService : IArtemisService public interface ILayerService : IArtemisService
{ {
/// <summary> /// <summary>
/// Instantiates and adds the <see cref="LayerBrush" /> described by the provided <see cref="LayerBrushDescriptor" /> /// Creates a new layer
/// </summary>
/// <param name="profile"></param>
/// <param name="parent"></param>
/// <param name="name"></param>
/// <returns></returns>
Layer CreateLayer(Profile profile, ProfileElement parent, string name);
/// <summary>
/// Instantiates and adds the <see cref="BaseLayerBrush" /> described by the provided
/// <see cref="LayerBrushDescriptor" />
/// to the <see cref="Layer" />. /// to the <see cref="Layer" />.
/// </summary> /// </summary>
/// <param name="layer">The layer to instantiate the brush for</param> /// <param name="layer">The layer to instantiate the brush for</param>
/// <returns></returns> /// <returns></returns>
ILayerBrush InstantiateLayerBrush(Layer layer); BaseLayerBrush InstantiateLayerBrush(Layer layer);
void LoadPropertyBaseValue(Layer layer, string path, object layerProperty); /// <summary>
void LoadPropertyKeyframes(Layer layer, string path, object layerProperty); /// Removes the layer brush from the provided layer and disposes it
/// </summary>
/// <param name="layer"></param>
void RemoveLayerBrush(Layer layer);
} }
} }

View File

@ -1,12 +1,7 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using Artemis.Core.Models.Profile; 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.LayerBrush;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Newtonsoft.Json;
using Ninject; using Ninject;
using Ninject.Parameters; using Ninject.Parameters;
using Serilog; using Serilog;
@ -31,8 +26,8 @@ namespace Artemis.Core.Services
var layer = new Layer(profile, parent, name); var layer = new Layer(profile, parent, name);
// Layers have two hardcoded property groups, instantiate them // Layers have two hardcoded property groups, instantiate them
layer.General.InitializeProperties(this, layer, null, null); layer.General.InitializeProperties(this, layer, null);
layer.Transform.InitializeProperties(this, layer, null, null); layer.Transform.InitializeProperties(this, layer, null);
// With the properties loaded, the layer brush can be instantiated // With the properties loaded, the layer brush can be instantiated
InstantiateLayerBrush(layer); InstantiateLayerBrush(layer);
@ -40,7 +35,7 @@ namespace Artemis.Core.Services
return layer; return layer;
} }
public ILayerBrush InstantiateLayerBrush(Layer layer) public BaseLayerBrush InstantiateLayerBrush(Layer layer)
{ {
RemoveLayerBrush(layer); RemoveLayerBrush(layer);
@ -62,7 +57,7 @@ namespace Artemis.Core.Services
new ConstructorArgument("layer", layer), new ConstructorArgument("layer", layer),
new ConstructorArgument("descriptor", descriptor) new ConstructorArgument("descriptor", descriptor)
}; };
var layerBrush = (ILayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments); var layerBrush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments);
layerBrush.InitializeProperties(this, null); layerBrush.InitializeProperties(this, null);
layer.LayerBrush = layerBrush; layer.LayerBrush = layerBrush;
@ -76,11 +71,9 @@ namespace Artemis.Core.Services
var brush = layer.LayerBrush; var brush = layer.LayerBrush;
layer.LayerBrush = null; 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(); brush.Dispose();
layer.LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid);
} }
} }
} }

View File

@ -94,7 +94,6 @@ namespace Artemis.Core.Services.Storage
if (profile != null) if (profile != null)
{ {
InstantiateProfileLayerBrushes(profile); InstantiateProfileLayerBrushes(profile);
InstantiateProfileKeyframeEngines(profile);
} }
} }
@ -166,13 +165,6 @@ namespace Artemis.Core.Services.Storage
_layerService.InstantiateLayerBrush(layer); _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) private void ActiveProfilesPopulateLeds(ArtemisSurface surface)
{ {
var profileModules = _pluginService.GetPluginsOfType<ProfileModule>(); var profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
@ -187,13 +179,6 @@ namespace Artemis.Core.Services.Storage
InstantiateProfileLayerBrushes(profileModule.ActiveProfile); InstantiateProfileLayerBrushes(profileModule.ActiveProfile);
} }
private void ActiveProfilesInstantiateKeyframeEngines()
{
var profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
InstantiateProfileKeyframeEngines(profileModule.ActiveProfile);
}
#region Event handlers #region Event handlers
private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e) private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e)
@ -212,7 +197,6 @@ namespace Artemis.Core.Services.Storage
if (e.PluginInfo.Instance is LayerBrushProvider) if (e.PluginInfo.Instance is LayerBrushProvider)
{ {
ActiveProfilesInstantiateProfileLayerBrushes(); ActiveProfilesInstantiateProfileLayerBrushes();
ActiveProfilesInstantiateKeyframeEngines();
} }
else if (e.PluginInfo.Instance is ProfileModule profileModule) else if (e.PluginInfo.Instance is ProfileModule profileModule)
{ {

View File

@ -10,8 +10,9 @@ namespace Artemis.Storage.Entities.Profile
KeyframeEntities = new List<KeyframeEntity>(); KeyframeEntities = new List<KeyframeEntity>();
} }
public string Id { get; set; } public Guid PluginGuid { get; set; }
public string ValueType { get; set; } public string Path { get; set; }
public string Value { get; set; } public string Value { get; set; }
public bool IsUsingKeyframes { get; set; } public bool IsUsingKeyframes { get; set; }

View File

@ -50,7 +50,7 @@ namespace Artemis.UI.Ninject.Factories
public interface ILayerPropertyVmFactory : IVmFactory public interface ILayerPropertyVmFactory : IVmFactory
{ {
LayerPropertyViewModel Create(LayerProperty layerProperty, LayerPropertyViewModel parent); LayerPropertyViewModel Create(BaseLayerProperty layerProperty, LayerPropertyViewModel parent);
} }
public interface IPropertyTreeVmFactory : IVmFactory public interface IPropertyTreeVmFactory : IVmFactory

View File

@ -169,7 +169,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
PopulateProperties(e.LayerProperty.Layer); PopulateProperties(e.LayerProperty.Layer);
} }
private LayerPropertyViewModel CreatePropertyViewModel(LayerProperty layerProperty) private LayerPropertyViewModel CreatePropertyViewModel(BaseLayerProperty layerProperty)
{ {
LayerPropertyViewModel parent = null; LayerPropertyViewModel parent = null;
// If the property has a parent, find it's VM // If the property has a parent, find it's VM

View File

@ -16,7 +16,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
private bool _keyframesEnabled; private bool _keyframesEnabled;
private bool _isExpanded; 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; _kernel = kernel;
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
@ -30,7 +30,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
Parent?.Children.Add(this); Parent?.Children.Add(this);
} }
public LayerProperty LayerProperty { get; } public BaseLayerProperty LayerProperty { get; }
public LayerPropertyViewModel Parent { get; } public LayerPropertyViewModel Parent { get; }
public List<LayerPropertyViewModel> Children { get; } public List<LayerPropertyViewModel> Children { get; }