mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
UI VM factories - Shortened names for readibility
Layer properties - Ensure only LayerBrushes can add properties and make sure that method instantiates a keyframe engine Layer properties UI - Respond to properties being added/removed
This commit is contained in:
1 parent
4f66d09755
commit
51a21b7a8a
29 files changed
+417
-303
No files matched your search
@@ -428,7 +428,7 @@ namespace Artemis.Core.Models.Profile
|
||||
/// <typeparam name="T">The type of value of the layer property</typeparam>
|
||||
/// <param name="layerProperty">The property to apply to the layer</param>
|
||||
/// <returns>True if an existing value was found and applied, otherwise false.</returns>
|
||||
public bool RegisterLayerProperty<T>(LayerProperty<T> layerProperty)
|
||||
internal bool RegisterLayerProperty<T>(LayerProperty<T> layerProperty)
|
||||
{
|
||||
return RegisterLayerProperty((BaseLayerProperty) layerProperty);
|
||||
}
|
||||
@@ -439,7 +439,7 @@ namespace Artemis.Core.Models.Profile
|
||||
/// </summary>
|
||||
/// <param name="layerProperty">The property to apply to the layer</param>
|
||||
/// <returns>True if an existing value was found and applied, otherwise false.</returns>
|
||||
public bool RegisterLayerProperty(BaseLayerProperty layerProperty)
|
||||
internal bool RegisterLayerProperty(BaseLayerProperty layerProperty)
|
||||
{
|
||||
if (_properties.ContainsKey((layerProperty.PluginInfo.Guid, layerProperty.Id)))
|
||||
throw new ArtemisCoreException($"Duplicate property ID detected. Layer already contains a property with ID {layerProperty.Id}.");
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
// This can only be null if accessed internally
|
||||
if (PluginInfo == null)
|
||||
PluginInfo = Constants.CorePluginInfo;
|
||||
|
||||
|
||||
Children = new List<BaseLayerProperty>();
|
||||
BaseKeyframes = new List<BaseKeyframe>();
|
||||
|
||||
@@ -108,9 +108,9 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
public IReadOnlyCollection<BaseKeyframe> UntypedKeyframes => BaseKeyframes.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the keyframe engine instance of this property
|
||||
/// Gets the keyframe engine instance of this property
|
||||
/// </summary>
|
||||
public KeyframeEngine KeyframeEngine { get; set; }
|
||||
public KeyframeEngine KeyframeEngine { get; internal set; }
|
||||
|
||||
protected List<BaseKeyframe> BaseKeyframes { get; set; }
|
||||
|
||||
@@ -129,50 +129,6 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
}
|
||||
}
|
||||
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
var propertyEntity = Layer.LayerEntity.PropertyEntities.FirstOrDefault(p => p.Id == Id);
|
||||
if (propertyEntity == null)
|
||||
{
|
||||
propertyEntity = new PropertyEntity {Id = Id};
|
||||
Layer.LayerEntity.PropertyEntities.Add(propertyEntity);
|
||||
}
|
||||
|
||||
propertyEntity.ValueType = Type.Name;
|
||||
propertyEntity.Value = JsonConvert.SerializeObject(BaseValue);
|
||||
propertyEntity.IsUsingKeyframes = IsUsingKeyframes;
|
||||
|
||||
propertyEntity.KeyframeEntities.Clear();
|
||||
foreach (var baseKeyframe in BaseKeyframes)
|
||||
{
|
||||
propertyEntity.KeyframeEntities.Add(new KeyframeEntity
|
||||
{
|
||||
Position = baseKeyframe.Position,
|
||||
Value = JsonConvert.SerializeObject(baseKeyframe.BaseValue),
|
||||
EasingFunction = (int) baseKeyframe.EasingFunction
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal void ApplyToProperty(PropertyEntity propertyEntity)
|
||||
{
|
||||
BaseValue = DeserializePropertyValue(propertyEntity.Value);
|
||||
IsUsingKeyframes = propertyEntity.IsUsingKeyframes;
|
||||
|
||||
BaseKeyframes.Clear();
|
||||
foreach (var keyframeEntity in propertyEntity.KeyframeEntities.OrderBy(e => e.Position))
|
||||
{
|
||||
// Create a strongly typed keyframe or else it cannot be cast later on
|
||||
var keyframeType = typeof(Keyframe<>);
|
||||
var keyframe = (BaseKeyframe) Activator.CreateInstance(keyframeType.MakeGenericType(Type), Layer, this);
|
||||
keyframe.Position = keyframeEntity.Position;
|
||||
keyframe.BaseValue = DeserializePropertyValue(keyframeEntity.Value);
|
||||
keyframe.EasingFunction = (Easings.Functions) keyframeEntity.EasingFunction;
|
||||
|
||||
BaseKeyframes.Add(keyframe);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new keyframe for this base property without knowing the type
|
||||
/// </summary>
|
||||
@@ -261,9 +217,29 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
SortKeyframes();
|
||||
}
|
||||
|
||||
internal void SortKeyframes()
|
||||
/// <summary>
|
||||
/// Returns the flattened index of this property on the layer
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetFlattenedIndex()
|
||||
{
|
||||
BaseKeyframes = BaseKeyframes.OrderBy(k => k.Position).ToList();
|
||||
if (Parent == null)
|
||||
return Layer.Properties.IndexOf(this);
|
||||
|
||||
// Create a flattened list of all properties in their order as defined by the parent/child hierarchy
|
||||
var properties = new List<BaseLayerProperty>();
|
||||
// Iterate root properties (those with children)
|
||||
foreach (var baseLayerProperty in Layer.Properties)
|
||||
{
|
||||
// First add self, then add all children
|
||||
if (baseLayerProperty.Children.Any())
|
||||
{
|
||||
properties.Add(baseLayerProperty);
|
||||
properties.AddRange(baseLayerProperty.GetAllChildren());
|
||||
}
|
||||
}
|
||||
|
||||
return properties.IndexOf(this);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@@ -271,6 +247,65 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
return $"{nameof(Id)}: {Id}, {nameof(Name)}: {Name}, {nameof(Description)}: {Description}";
|
||||
}
|
||||
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
var propertyEntity = Layer.LayerEntity.PropertyEntities.FirstOrDefault(p => p.Id == Id);
|
||||
if (propertyEntity == null)
|
||||
{
|
||||
propertyEntity = new PropertyEntity {Id = Id};
|
||||
Layer.LayerEntity.PropertyEntities.Add(propertyEntity);
|
||||
}
|
||||
|
||||
propertyEntity.ValueType = Type.Name;
|
||||
propertyEntity.Value = JsonConvert.SerializeObject(BaseValue);
|
||||
propertyEntity.IsUsingKeyframes = IsUsingKeyframes;
|
||||
|
||||
propertyEntity.KeyframeEntities.Clear();
|
||||
foreach (var baseKeyframe in BaseKeyframes)
|
||||
{
|
||||
propertyEntity.KeyframeEntities.Add(new KeyframeEntity
|
||||
{
|
||||
Position = baseKeyframe.Position,
|
||||
Value = JsonConvert.SerializeObject(baseKeyframe.BaseValue),
|
||||
EasingFunction = (int) baseKeyframe.EasingFunction
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal void ApplyToProperty(PropertyEntity propertyEntity)
|
||||
{
|
||||
BaseValue = DeserializePropertyValue(propertyEntity.Value);
|
||||
IsUsingKeyframes = propertyEntity.IsUsingKeyframes;
|
||||
|
||||
BaseKeyframes.Clear();
|
||||
foreach (var keyframeEntity in propertyEntity.KeyframeEntities.OrderBy(e => e.Position))
|
||||
{
|
||||
// Create a strongly typed keyframe or else it cannot be cast later on
|
||||
var keyframeType = typeof(Keyframe<>);
|
||||
var keyframe = (BaseKeyframe) Activator.CreateInstance(keyframeType.MakeGenericType(Type), Layer, this);
|
||||
keyframe.Position = keyframeEntity.Position;
|
||||
keyframe.BaseValue = DeserializePropertyValue(keyframeEntity.Value);
|
||||
keyframe.EasingFunction = (Easings.Functions) keyframeEntity.EasingFunction;
|
||||
|
||||
BaseKeyframes.Add(keyframe);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SortKeyframes()
|
||||
{
|
||||
BaseKeyframes = BaseKeyframes.OrderBy(k => k.Position).ToList();
|
||||
}
|
||||
|
||||
internal IEnumerable<BaseLayerProperty> GetAllChildren()
|
||||
{
|
||||
var children = new List<BaseLayerProperty>();
|
||||
children.AddRange(Children);
|
||||
foreach (var layerPropertyViewModel in Children)
|
||||
children.AddRange(layerPropertyViewModel.GetAllChildren());
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
private object DeserializePropertyValue(string value)
|
||||
{
|
||||
if (value == "null")
|
||||
|
||||
@@ -1,71 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a property on the layer. This property is visible in the profile editor and can be key-framed (unless
|
||||
/// opted out)
|
||||
/// opted out).
|
||||
/// <para>To create and register a new LayerProperty use <see cref="LayerBrush.RegisterLayerProperty" /></para>
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class LayerProperty<T> : BaseLayerProperty
|
||||
{
|
||||
internal LayerProperty(Layer layer, BaseLayerProperty parent, string id, string name, string description) : base(layer, null, parent, id, name, description, typeof(T))
|
||||
internal LayerProperty(Layer layer, BaseLayerProperty parent, string id, string name, string description)
|
||||
: base(layer, null, parent, id, name, description, typeof(T))
|
||||
{
|
||||
}
|
||||
|
||||
internal LayerProperty(Layer layer, string id, string name, string description) : base(layer, null, null, id, name, description, typeof(T))
|
||||
internal LayerProperty(Layer layer, string id, string name, string description)
|
||||
: base(layer, null, null, id, name, description, typeof(T))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a property on the layer. This property is visible in the profile editor and can be key-framed (unless
|
||||
/// opted out)
|
||||
/// <para>
|
||||
/// Note: The value and keyframes of the property are stored using the ID, after adding the property to the layer
|
||||
/// these are restored.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="layer">The layer the property is applied to</param>
|
||||
/// <param name="pluginInfo">The plugin to create this property for</param>
|
||||
/// <param name="parent">The parent of this property, use this to create a tree-hierarchy in the editor</param>
|
||||
/// <param name="id">A and ID identifying your property, must be unique within your plugin</param>
|
||||
/// <param name="name">A name for your property, this is visible in the editor</param>
|
||||
/// <param name="description">A description for your property, this is visible in the editor</param>
|
||||
public LayerProperty(Layer layer, PluginInfo pluginInfo, BaseLayerProperty parent, string id, string name, string description) : base(layer, pluginInfo, parent, id, name, description,
|
||||
typeof(T))
|
||||
internal LayerProperty(Layer layer, PluginInfo pluginInfo, BaseLayerProperty parent, string id, string name, string description)
|
||||
: base(layer, pluginInfo, parent, id, name, description, typeof(T))
|
||||
{
|
||||
if (layer == null)
|
||||
throw new ArgumentNullException(nameof(layer));
|
||||
if (pluginInfo == null)
|
||||
throw new ArgumentNullException(nameof(pluginInfo));
|
||||
if (id == null)
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a property on the layer. This property is visible in the profile editor and can be key-framed (unless
|
||||
/// opted out)
|
||||
/// <para>
|
||||
/// Note: The value and keyframes of the property are stored using the ID, after adding the property to the layer
|
||||
/// these are restored.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="layer">The layer the property is applied to</param>
|
||||
/// <param name="pluginInfo">The plugin to create this property for</param>
|
||||
/// <param name="id">A and ID identifying your property, must be unique within your plugin</param>
|
||||
/// <param name="name">A name for your property, this is visible in the editor</param>
|
||||
/// <param name="description">A description for your property, this is visible in the editor</param>
|
||||
public LayerProperty(Layer layer, PluginInfo pluginInfo, string id, string name, string description) : base(layer, pluginInfo, null, id, name, description, typeof(T))
|
||||
{
|
||||
if (layer == null)
|
||||
throw new ArgumentNullException(nameof(layer));
|
||||
if (pluginInfo == null)
|
||||
throw new ArgumentNullException(nameof(pluginInfo));
|
||||
if (id == null)
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user