Meta - Code cleanup

This commit is contained in:
SpoinkyNL committed 2020-06-13 22:27:51 +02:00
1 parent 18593853d8
commit fd991112a9
105 files changed
+3097 -2624

No files matched your search

+2 -2
View File
@@ -164,7 +164,7 @@ namespace Artemis.Core.Models.Profile
LayerEntity.LayerEffects.Clear();
foreach (var layerEffect in LayerEffects)
{
var layerEffectEntity = new LayerEffectEntity()
var layerEffectEntity = new LayerEffectEntity
{
PluginGuid = layerEffect.PluginInfo.Guid,
EffectType = layerEffect.GetType().Name,
@@ -505,7 +505,7 @@ namespace Artemis.Core.Models.Profile
{
if (LayerBrush == null)
return;
var brush = LayerBrush;
DeactivateLayerBrush();
LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid && p.Path.StartsWith("LayerBrush."));
@@ -17,7 +17,7 @@ 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;
@@ -10,15 +10,15 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// </summary>
public abstract class BaseLayerProperty
{
private bool _keyframesEnabled;
private bool _isHidden;
private bool _keyframesEnabled;
internal BaseLayerProperty()
{
}
/// <summary>
/// The layer this property applies to
/// The layer this property applies to
/// </summary>
public Layer Layer { get; internal set; }
@@ -84,7 +84,9 @@ namespace Artemis.Core.Models.Profile.LayerProperties
internal PropertyEntity PropertyEntity { get; set; }
internal LayerPropertyGroup LayerPropertyGroup { get; set; }
public abstract void ApplyDefaultValue();
/// <summary>
/// Applies the provided property entity to the layer property by deserializing the JSON base value and keyframe values
@@ -113,12 +115,12 @@ namespace Artemis.Core.Models.Profile.LayerProperties
public event EventHandler BaseValueChanged;
/// <summary>
/// Occurs when the <see cref="IsHidden"/> value of the layer property was updated
/// Occurs when the <see cref="IsHidden" /> value of the layer property was updated
/// </summary>
public event EventHandler VisibilityChanged;
/// <summary>
/// Occurs when keyframes are enabled/disabled
/// Occurs when keyframes are enabled/disabled
/// </summary>
public event EventHandler KeyframesToggled;
@@ -163,9 +165,5 @@ namespace Artemis.Core.Models.Profile.LayerProperties
}
#endregion
public abstract void ApplyDefaultValue();
}
}
@@ -56,7 +56,8 @@ namespace Artemis.Core.Models.Profile.LayerProperties
}
/// <summary>
/// Gets or sets the default value of this layer property. If set, this value is automatically applied if the property has no
/// 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; }
@@ -166,6 +167,12 @@ namespace Artemis.Core.Models.Profile.LayerProperties
RemoveKeyframe(layerPropertyKeyframe);
}
public override void ApplyDefaultValue()
{
BaseValue = DefaultValue;
CurrentValue = DefaultValue;
}
/// <summary>
/// Called every update (if keyframes are both supported and enabled) to determine the new <see cref="CurrentValue" />
/// based on the provided progress
@@ -284,11 +291,5 @@ namespace Artemis.Core.Models.Profile.LayerProperties
EasingFunction = (int) k.EasingFunction
}));
}
public override void ApplyDefaultValue()
{
BaseValue = DefaultValue;
CurrentValue = DefaultValue;
}
}
}
@@ -12,6 +12,11 @@ namespace Artemis.Core.Models.Profile.LayerProperties.Types
KeyframesSupported = false;
}
public static implicit operator ColorGradient(ColorGradientLayerProperty p)
{
return p.CurrentValue;
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
throw new ArtemisCoreException("Color Gradients do not support keyframes.");
@@ -24,7 +29,5 @@ namespace Artemis.Core.Models.Profile.LayerProperties.Types
// Don't allow color gradients to be null
BaseValue ??= DefaultValue ?? new ColorGradient();
}
public static implicit operator ColorGradient(ColorGradientLayerProperty p) => p.CurrentValue;
}
}
@@ -11,12 +11,19 @@ namespace Artemis.Core.Models.Profile.LayerProperties.Types
KeyframesSupported = false;
}
public static implicit operator T(EnumLayerProperty<T> p)
{
return p.CurrentValue;
}
public static implicit operator int(EnumLayerProperty<T> p)
{
return Convert.ToInt32(p.CurrentValue);
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
throw new ArtemisCoreException("Enum properties do not support keyframes.");
}
public static implicit operator T(EnumLayerProperty<T> p) => p.CurrentValue;
public static implicit operator int(EnumLayerProperty<T> p) => Convert.ToInt32(p.CurrentValue);
}
}
@@ -1,19 +1,26 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
/// <inheritdoc/>
/// <inheritdoc />
public class FloatLayerProperty : LayerProperty<float>
{
internal FloatLayerProperty()
{
}
public static implicit operator float(FloatLayerProperty p)
{
return p.CurrentValue;
}
public static implicit operator double(FloatLayerProperty p)
{
return p.CurrentValue;
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
var diff = NextKeyframe.Value - CurrentKeyframe.Value;
CurrentValue = CurrentKeyframe.Value + diff * keyframeProgressEased;
}
public static implicit operator float(FloatLayerProperty p) => p.CurrentValue;
public static implicit operator double(FloatLayerProperty p) => p.CurrentValue;
}
}
@@ -2,21 +2,32 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
/// <inheritdoc/>
/// <inheritdoc />
public class IntLayerProperty : LayerProperty<int>
{
internal IntLayerProperty()
{
}
public static implicit operator int(IntLayerProperty p)
{
return p.CurrentValue;
}
public static implicit operator float(IntLayerProperty p)
{
return p.CurrentValue;
}
public static implicit operator double(IntLayerProperty p)
{
return p.CurrentValue;
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
var diff = NextKeyframe.Value - CurrentKeyframe.Value;
CurrentValue = (int) Math.Round(CurrentKeyframe.Value + diff * keyframeProgressEased, MidpointRounding.AwayFromZero);
}
public static implicit operator int(IntLayerProperty p) => p.CurrentValue;
public static implicit operator float(IntLayerProperty p) => p.CurrentValue;
public static implicit operator double(IntLayerProperty p) => p.CurrentValue;
}
}
@@ -3,7 +3,7 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
/// <summary>
/// A special layer property used to configure the selected layer brush
/// A special layer property used to configure the selected layer brush
/// </summary>
public class LayerBrushReferenceLayerProperty : LayerProperty<LayerBrushReference>
{
@@ -12,11 +12,14 @@ namespace Artemis.Core.Models.Profile.LayerProperties.Types
KeyframesSupported = false;
}
public static implicit operator LayerBrushReference(LayerBrushReferenceLayerProperty p)
{
return p.CurrentValue;
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
throw new ArtemisCoreException("Layer brush references do not support keyframes.");
}
public static implicit operator LayerBrushReference(LayerBrushReferenceLayerProperty p) => p.CurrentValue;
}
}
@@ -3,13 +3,18 @@ using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
/// <inheritdoc/>
/// <inheritdoc />
public class SKColorLayerProperty : LayerProperty<SKColor>
{
internal SKColorLayerProperty()
{
}
public static implicit operator SKColor(SKColorLayerProperty p)
{
return p.CurrentValue;
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
var redDiff = NextKeyframe.Value.Red - CurrentKeyframe.Value.Red;
@@ -29,7 +34,5 @@ namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
return (byte) Math.Max(0, Math.Min(255, value));
}
public static implicit operator SKColor(SKColorLayerProperty p) => p.CurrentValue;
}
}
@@ -2,20 +2,23 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
/// <inheritdoc/>
/// <inheritdoc />
public class SKPointLayerProperty : LayerProperty<SKPoint>
{
internal SKPointLayerProperty()
{
}
public static implicit operator SKPoint(SKPointLayerProperty p)
{
return p.CurrentValue;
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
var xDiff = NextKeyframe.Value.X - CurrentKeyframe.Value.X;
var yDiff = NextKeyframe.Value.Y - CurrentKeyframe.Value.Y;
CurrentValue = new SKPoint(CurrentKeyframe.Value.X + xDiff * keyframeProgressEased, CurrentKeyframe.Value.Y + yDiff * keyframeProgressEased);
}
public static implicit operator SKPoint(SKPointLayerProperty p) => p.CurrentValue;
}
}
@@ -2,20 +2,23 @@
namespace Artemis.Core.Models.Profile.LayerProperties.Types
{
/// <inheritdoc/>
/// <inheritdoc />
public class SKSizeLayerProperty : LayerProperty<SKSize>
{
internal SKSizeLayerProperty()
{
}
public static implicit operator SKSize(SKSizeLayerProperty p)
{
return p.CurrentValue;
}
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
{
var widthDiff = NextKeyframe.Value.Width - CurrentKeyframe.Value.Width;
var heightDiff = NextKeyframe.Value.Height - CurrentKeyframe.Value.Height;
CurrentValue = new SKSize(CurrentKeyframe.Value.Width + widthDiff * keyframeProgressEased, CurrentKeyframe.Value.Height + heightDiff * keyframeProgressEased);
}
public static implicit operator SKSize(SKSizeLayerProperty p) => p.CurrentValue;
}
}
@@ -107,6 +107,21 @@ namespace Artemis.Core.Models.Profile
return _allLayerProperties;
}
public void UpdateOrder(int oldOrder)
{
// Expanded state is tied to the path so save it before changing the path
var expanded = Layer.IsPropertyGroupExpanded(this);
Layer.SetPropertyGroupExpanded(this, false);
Path = Path.Replace($"LayerEffect.{oldOrder}.", $"LayerEffect.{LayerEffect.Order}.");
// Restore the expanded state with the new path
Layer.SetPropertyGroupExpanded(this, expanded);
// Update children
foreach (var layerPropertyGroup in LayerPropertyGroups)
layerPropertyGroup.UpdateOrder(oldOrder);
}
/// <summary>
/// Called before properties are fully initialized to allow you to populate
/// <see cref="LayerProperty{T}.DefaultValue" /> on the properties you want
@@ -280,20 +295,5 @@ namespace Artemis.Core.Models.Profile
}
#endregion
public void UpdateOrder(int oldOrder)
{
// Expanded state is tied to the path so save it before changing the path
var expanded = Layer.IsPropertyGroupExpanded(this);
Layer.SetPropertyGroupExpanded(this, false);
Path = Path.Replace($"LayerEffect.{oldOrder}.", $"LayerEffect.{LayerEffect.Order}.");
// Restore the expanded state with the new path
Layer.SetPropertyGroupExpanded(this, expanded);
// Update children
foreach (var layerPropertyGroup in LayerPropertyGroups)
layerPropertyGroup.UpdateOrder(oldOrder);
}
}
}
@@ -127,14 +127,14 @@ namespace Artemis.Core.Models.Profile
}
}
/// <summary>
/// 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}";
}
/// <summary>
/// Applies the profile element's properties to the underlying storage entity
/// </summary>
internal abstract void ApplyToEntity();
}
}