Nuget - Updated packages

Brush properties - Added default values
Brush properties - Removed option to always auto-expand groups
Layer properties - Remember expanded/collapsed groups
Storage - Added migration system
Storage - Added migration that removes profiles made in the old layer properties format
Layer timeline - Added back zoom functionality
This commit is contained in:
SpoinkyNL committed 2020-05-29 00:09:04 +02:00
1 parent 8456817a2b
commit e6080eb897
58 files changed
+329 -188

No files matched your search

@@ -55,7 +55,7 @@ namespace Artemis.Core.Models.Profile.Colors
if (right == null || left == right)
return left.Color;
position = (float) Math.Round((position - left.Position) / (right.Position - left.Position), 2);
var a = (byte) ((right.Color.Alpha - left.Color.Alpha) * position + left.Color.Alpha);
var r = (byte) ((right.Color.Red - left.Color.Red) * position + left.Color.Red);
@@ -65,15 +65,19 @@ namespace Artemis.Core.Models.Profile.Colors
}
/// <summary>
/// [PH] Looping through HSV, adds 8 rainbow colors
/// Gets a new ColorGradient with colors looping through the HSV-spectrum
/// </summary>
public void MakeFabulous()
/// <returns></returns>
public static ColorGradient GetUnicornBarf()
{
var gradient = new ColorGradient();
for (var i = 0; i < 9; i++)
{
var color = i != 8 ? SKColor.FromHsv(i * 32, 100, 100) : SKColor.FromHsv(0, 100, 100);
Stops.Add(new ColorGradientStop(color, 0.125f * i));
gradient.Stops.Add(new ColorGradientStop(color, 0.125f * i));
}
return gradient;
}
#region PropertyChanged
+23 -3
View File
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Media.Animation;
using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
@@ -22,6 +21,7 @@ namespace Artemis.Core.Models.Profile
/// </summary>
public sealed class Layer : ProfileElement
{
private readonly List<string> _expandedPropertyGroups;
private LayerShape _layerShape;
private List<ArtemisLed> _leds;
private SKPath _path;
@@ -38,6 +38,8 @@ namespace Artemis.Core.Models.Profile
Transform = new LayerTransformProperties {IsCorePropertyGroup = true};
_leds = new List<ArtemisLed>();
_expandedPropertyGroups = new List<string>();
General.PropertyGroupInitialized += GeneralOnPropertyGroupInitialized;
}
@@ -54,6 +56,9 @@ namespace Artemis.Core.Models.Profile
Transform = new LayerTransformProperties {IsCorePropertyGroup = true};
_leds = new List<ArtemisLed>();
_expandedPropertyGroups = new List<string>();
_expandedPropertyGroups.AddRange(layerEntity.ExpandedPropertyGroups);
General.PropertyGroupInitialized += GeneralOnPropertyGroupInitialized;
}
@@ -99,10 +104,10 @@ namespace Artemis.Core.Models.Profile
}
}
[PropertyGroupDescription(Name = "General", Description = "A collection of general properties", ExpandByDefault = true)]
[PropertyGroupDescription(Name = "General", Description = "A collection of general properties")]
public LayerGeneralProperties General { get; set; }
[PropertyGroupDescription(Name = "Transform", Description = "A collection of transformation properties", ExpandByDefault = true)]
[PropertyGroupDescription(Name = "Transform", Description = "A collection of transformation properties")]
public LayerTransformProperties Transform { get; set; }
/// <summary>
@@ -115,6 +120,19 @@ namespace Artemis.Core.Models.Profile
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
}
public bool IsPropertyGroupExpanded(LayerPropertyGroup layerPropertyGroup)
{
return _expandedPropertyGroups.Contains(layerPropertyGroup.Path);
}
public void SetPropertyGroupExpanded(LayerPropertyGroup layerPropertyGroup, bool expanded)
{
if (!expanded && IsPropertyGroupExpanded(layerPropertyGroup))
_expandedPropertyGroups.Remove(layerPropertyGroup.Path);
else if (expanded && !IsPropertyGroupExpanded(layerPropertyGroup))
_expandedPropertyGroups.Add(layerPropertyGroup.Path);
}
#region Storage
internal override void ApplyToEntity()
@@ -125,6 +143,8 @@ namespace Artemis.Core.Models.Profile
LayerEntity.Order = Order;
LayerEntity.Name = Name;
LayerEntity.ProfileId = Profile.EntityId;
LayerEntity.ExpandedPropertyGroups.Clear();
LayerEntity.ExpandedPropertyGroups.AddRange(_expandedPropertyGroups);
General.ApplyToEntity();
Transform.ApplyToEntity();
@@ -1,5 +1,4 @@
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Models.Profile.LayerProperties.Types;
using SkiaSharp;
@@ -19,17 +18,15 @@ namespace Artemis.Core.Models.Profile
[PropertyDescription(Name = "Brush type", Description = "The type of brush to use for this layer")]
public LayerBrushReferenceLayerProperty BrushReference { get; set; }
protected override void PopulateDefaults()
{
ShapeType.DefaultValue = LayerShapeType.Rectangle;
FillType.DefaultValue = LayerFillType.Stretch;
BlendMode.DefaultValue = SKBlendMode.SrcOver;
}
protected override void OnPropertiesInitialized()
{
// Populate defaults
if (!ShapeType.IsLoadedFromStorage)
ShapeType.BaseValue = LayerShapeType.Rectangle;
if (!FillType.IsLoadedFromStorage)
FillType.BaseValue = LayerFillType.Stretch;
if (!BlendMode.IsLoadedFromStorage)
BlendMode.BaseValue = SKBlendMode.SrcOver;
// TODO: SpoinkyNL 28-4-2020: Select preferred default brush type with a fallback to the first available
}
}
}
@@ -141,5 +141,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
}
#endregion
public abstract void ApplyDefaultValue();
}
}
@@ -55,6 +55,12 @@ namespace Artemis.Core.Models.Profile.LayerProperties
internal set => _currentValue = value;
}
/// <summary>
/// Gets or sets the default value of this layer property. If set, this value is automatically applied if the property has no
/// value in storage
/// </summary>
public T DefaultValue { get; set; }
/// <summary>
/// Gets a read-only list of all the keyframes on this layer property
/// </summary>
@@ -275,5 +281,10 @@ namespace Artemis.Core.Models.Profile.LayerProperties
EasingFunction = (int) k.EasingFunction
}));
}
public override void ApplyDefaultValue()
{
CurrentValue = DefaultValue;
}
}
}
@@ -1,5 +1,6 @@
using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.Colors;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
@@ -11,6 +12,18 @@ namespace Artemis.Core.Models.Profile.LayerProperties.Types
KeyframesSupported = false;
}
internal override void ApplyToLayerProperty(PropertyEntity entity, LayerPropertyGroup layerPropertyGroup, bool fromStorage)
{
base.ApplyToLayerProperty(entity, layerPropertyGroup, fromStorage);
// Don't allow color gradients to be null
if (BaseValue == null)
{
BaseValue = DefaultValue ?? new ColorGradient();
}
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
throw new ArtemisCoreException("Color Gradients do not support keyframes.");
@@ -13,11 +13,11 @@ using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Models.Profile
{
public class LayerPropertyGroup
public abstract class LayerPropertyGroup
{
private ReadOnlyCollection<BaseLayerProperty> _allLayerProperties;
private readonly List<BaseLayerProperty> _layerProperties;
private readonly List<LayerPropertyGroup> _layerPropertyGroups;
private ReadOnlyCollection<BaseLayerProperty> _allLayerProperties;
protected LayerPropertyGroup()
{
@@ -26,17 +26,22 @@ namespace Artemis.Core.Models.Profile
}
/// <summary>
/// The layer this property group applies to
/// The layer this property group applies to
/// </summary>
public Layer Layer { get; internal set; }
/// <summary>
/// The path of this property group
/// </summary>
public string Path { get; internal set; }
/// <summary>
/// The parent group of this layer property group, set after construction
/// </summary>
public LayerPropertyGroup Parent { get; internal set; }
/// <summary>
/// Gets whether this property group's properties are all initialized
/// Gets whether this property group's properties are all initialized
/// </summary>
public bool PropertiesInitialized { get; private set; }
@@ -61,10 +66,39 @@ namespace Artemis.Core.Models.Profile
public ReadOnlyCollection<LayerPropertyGroup> LayerPropertyGroups => _layerPropertyGroups.AsReadOnly();
/// <summary>
/// Called when all layer properties in this property group have been initialized
/// Recursively gets all layer properties on this group and any subgroups
/// </summary>
protected virtual void OnPropertiesInitialized()
/// <returns></returns>
public IReadOnlyCollection<BaseLayerProperty> GetAllLayerProperties()
{
if (!PropertiesInitialized)
return new List<BaseLayerProperty>();
if (_allLayerProperties != null)
return _allLayerProperties;
var result = new List<BaseLayerProperty>(LayerProperties);
foreach (var layerPropertyGroup in LayerPropertyGroups)
result.AddRange(layerPropertyGroup.GetAllLayerProperties());
_allLayerProperties = result.AsReadOnly();
return _allLayerProperties;
}
/// <summary>
/// Called before properties are fully initialized to allow you to populate
/// <see cref="LayerProperty{T}.DefaultValue" /> on the properties you want
/// </summary>
protected abstract void PopulateDefaults();
/// <summary>
/// Called when all layer properties in this property group have been initialized, you may access all properties on the
/// group here
/// </summary>
protected abstract void OnPropertiesInitialized();
protected virtual void OnPropertyGroupInitialized()
{
PropertyGroupInitialized?.Invoke(this, EventArgs.Empty);
}
internal void InitializeProperties(ILayerService layerService, Layer layer, [NotNull] string path)
@@ -76,6 +110,7 @@ namespace Artemis.Core.Models.Profile
throw new ArtemisCoreException("Layer property group already initialized, wut");
Layer = layer;
Path = path.TrimEnd('.');
// Get all properties with a PropertyDescriptionAttribute
foreach (var propertyInfo in GetType().GetProperties())
@@ -110,9 +145,12 @@ namespace Artemis.Core.Models.Profile
}
}
PopulateDefaults();
foreach (var layerProperty in _layerProperties.Where(p => !p.IsLoadedFromStorage))
layerProperty.ApplyDefaultValue();
OnPropertiesInitialized();
PropertiesInitialized = true;
OnPropertyGroupInitialized();
}
@@ -152,25 +190,6 @@ namespace Artemis.Core.Models.Profile
OnPropertyGroupOverriding(new PropertyGroupUpdatingEventArgs(overrideTime));
}
/// <summary>
/// Recursively gets all layer properties on this group and any subgroups
/// </summary>
/// <returns></returns>
public IReadOnlyCollection<BaseLayerProperty> GetAllLayerProperties()
{
if (!PropertiesInitialized)
return new List<BaseLayerProperty>();
if (_allLayerProperties != null)
return _allLayerProperties;
var result = new List<BaseLayerProperty>(LayerProperties);
foreach (var layerPropertyGroup in LayerPropertyGroups)
result.AddRange(layerPropertyGroup.GetAllLayerProperties());
_allLayerProperties = result.AsReadOnly();
return _allLayerProperties;
}
private void InitializeProperty(Layer layer, string path, BaseLayerProperty instance)
{
var pluginGuid = IsCorePropertyGroup || instance.IsCoreProperty ? Constants.CorePluginInfo.Guid : layer.LayerBrush.PluginInfo.Guid;
@@ -203,10 +222,5 @@ namespace Artemis.Core.Models.Profile
}
#endregion
protected virtual void OnPropertyGroupInitialized()
{
PropertyGroupInitialized?.Invoke(this, EventArgs.Empty);
}
}
}
@@ -1,5 +1,4 @@
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Models.Profile.LayerProperties.Types;
using SkiaSharp;
@@ -22,13 +21,14 @@ namespace Artemis.Core.Models.Profile
[PropertyDescription(Description = "The opacity of the shape", InputAffix = "%", MinInputValue = 0f, MaxInputValue = 100f)]
public FloatLayerProperty Opacity { get; set; }
protected override void PopulateDefaults()
{
Scale.DefaultValue = new SKSize(100, 100);
Opacity.DefaultValue = 100;
}
protected override void OnPropertiesInitialized()
{
// Populate defaults
if (!Scale.IsLoadedFromStorage)
Scale.BaseValue = new SKSize(100, 100);
if (!Opacity.IsLoadedFromStorage)
Opacity.BaseValue = 100;
}
}
}
@@ -131,5 +131,10 @@ namespace Artemis.Core.Models.Profile
/// Applies the profile element's properties to the underlying storage entity
/// </summary>
internal abstract void ApplyToEntity();
public override string ToString()
{
return $"{nameof(EntityId)}: {EntityId}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
}
}
}