Meta - Code cleanup

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

No files matched your search

@@ -14,7 +14,7 @@ namespace Artemis.Core.Events
OverrideTime = overrideTime;
}
public double DeltaTime { get; }
public TimeSpan OverrideTime { get; }
public double DeltaTime { get; }
public TimeSpan OverrideTime { get; }
}
}
+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();
}
}
+1 -1
View File
@@ -63,7 +63,7 @@ namespace Artemis.Core.Ninject
}).InSingletonScope();
Kernel.Bind<StorageMigrationService>().ToSelf().InSingletonScope();
// Bind all migrations as singletons
Kernel.Bind(x =>
{
+5 -5
View File
@@ -23,6 +23,11 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary>
public bool HasConfigurationViewModel { get; protected set; }
public void Dispose()
{
DisablePlugin();
}
/// <summary>
/// Called when the plugin is activated
/// </summary>
@@ -59,11 +64,6 @@ namespace Artemis.Core.Plugins.Abstract
}
}
public void Dispose()
{
DisablePlugin();
}
#region Events
public event EventHandler PluginEnabled;
File diff suppressed because it is too large. Load diff
+2 -3
View File
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
@@ -7,4 +6,4 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9b811f9b-86b9-4771-87af-72bae7078a36")]
[assembly: Guid("9b811f9b-86b9-4771-87af-72bae7078a36")]
+21 -23
View File
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.JsonConverters;
@@ -10,7 +9,6 @@ using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces;
using Artemis.Storage;
using Artemis.Storage.Migrations.Interfaces;
using Newtonsoft.Json;
using RGB.NET.Core;
using Serilog;
@@ -29,11 +27,11 @@ namespace Artemis.Core.Services
private readonly IProfileService _profileService;
private readonly IRgbService _rgbService;
private readonly ISurfaceService _surfaceService;
private readonly PluginSetting<LogEventLevel> _loggingLevel;
private List<Module> _modules;
private PluginSetting<LogEventLevel> _loggingLevel;
// ReSharper disable once UnusedParameter.Local - Storage migration service is injected early to ensure it runs before anything else
internal CoreService(ILogger logger, StorageMigrationService _, ISettingsService settingsService, IPluginService pluginService,
internal CoreService(ILogger logger, StorageMigrationService _, ISettingsService settingsService, IPluginService pluginService,
IRgbService rgbService, ISurfaceService surfaceService, IProfileService profileService)
{
_logger = logger;
@@ -51,7 +49,7 @@ namespace Artemis.Core.Services
_pluginService.PluginEnabled += (sender, args) => _modules = _pluginService.GetPluginsOfType<Module>();
_pluginService.PluginDisabled += (sender, args) => _modules = _pluginService.GetPluginsOfType<Module>();
ConfigureJsonConvert();
}
@@ -66,24 +64,6 @@ namespace Artemis.Core.Services
public bool IsInitialized { get; set; }
protected virtual void OnFrameRendering(FrameRenderingEventArgs e)
{
FrameRendering?.Invoke(this, e);
}
protected virtual void OnFrameRendered(FrameRenderedEventArgs e)
{
FrameRendered?.Invoke(this, e);
}
private void ConfigureJsonConvert()
{
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Converters = new List<JsonConverter> {new SKColorConverter()}
};
}
public void Initialize()
{
if (IsInitialized)
@@ -107,6 +87,24 @@ namespace Artemis.Core.Services
OnInitialized();
}
protected virtual void OnFrameRendering(FrameRenderingEventArgs e)
{
FrameRendering?.Invoke(this, e);
}
protected virtual void OnFrameRendered(FrameRenderedEventArgs e)
{
FrameRendered?.Invoke(this, e);
}
private void ConfigureJsonConvert()
{
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Converters = new List<JsonConverter> {new SKColorConverter()}
};
}
private void ApplyLoggingLevel()
{
_logger.Information("Setting logging level to {loggingLevel}", _loggingLevel.Value);
@@ -3,7 +3,6 @@ using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.LayerEffect;
using Artemis.Core.Plugins.LayerEffect.Abstract;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Services.Interfaces
{
@@ -35,7 +35,7 @@ namespace Artemis.Core.Services.Interfaces
/// </summary>
/// <param name="deviceProvider"></param>
void AddDeviceProvider(IRGBDeviceProvider deviceProvider);
void Dispose();
/// <summary>
+2 -8
View File
@@ -1,18 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Documents;
using System.Linq;
using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.LayerEffect;
using Artemis.Core.Plugins.LayerEffect.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile;
using Ninject;
using Ninject.Injection;
using Ninject.Parameters;
using Serilog;
namespace Artemis.Core.Services
@@ -63,7 +57,7 @@ namespace Artemis.Core.Services
if (descriptor == null)
return null;
var brush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType);
brush.Layer = layer;
brush.Descriptor = descriptor;
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Extensions;
@@ -4,7 +4,6 @@ using Artemis.Core.Events;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces;
using Artemis.Storage.Entities.Profile;
@@ -214,9 +213,7 @@ namespace Artemis.Core.Services.Storage
private void OnPluginLoaded(object sender, PluginEventArgs e)
{
if (e.PluginInfo.Instance is LayerBrushProvider)
{
ActiveProfilesInstantiateProfileLayerBrushes();
}
else if (e.PluginInfo.Instance is ProfileModule profileModule)
{
var activeProfile = GetActiveProfile(profileModule);
@@ -95,7 +95,6 @@ namespace Artemis.Core.Services.Storage
// Update the RGB service's graphics decorator to work with the new surface entity
_rgbService.UpdateSurfaceLedGroup();
OnActiveSurfaceConfigurationChanged(new SurfaceConfigurationEventArgs(ActiveSurface));
}
public void UpdateSurfaceConfiguration(ArtemisSurface surface, bool includeDevices)