mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Data model - Improved encapsulation
Conditions - Renamed from DisplayConditions to DataModelConditions to better match their nature Core - More documentation
This commit is contained in:
1 parent
6b93b1c878
commit
a646ff95ed
39 files changed
+581
-355
No files matched your search
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Artemis.Core.DataModelExpansions
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an attribute that marks a data model property to be ignored by the UI
|
||||
/// </summary>
|
||||
public class DataModelIgnoreAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Artemis.Core.DataModelExpansions
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an attribute that describes a data model property
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class DataModelPropertyAttribute : Attribute
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Artemis.Core.DataModelExpansions
|
||||
[DataModelIgnore]
|
||||
public bool IsExpansion { get; internal set; }
|
||||
|
||||
public bool ContainsPath(string path)
|
||||
internal bool ContainsPath(string path)
|
||||
{
|
||||
var parts = path.Split('.');
|
||||
var current = GetType();
|
||||
@@ -43,7 +43,7 @@ namespace Artemis.Core.DataModelExpansions
|
||||
return true;
|
||||
}
|
||||
|
||||
public Type GetTypeAtPath(string path)
|
||||
internal Type GetTypeAtPath(string path)
|
||||
{
|
||||
if (!ContainsPath(path))
|
||||
return null;
|
||||
@@ -62,7 +62,7 @@ namespace Artemis.Core.DataModelExpansions
|
||||
return result;
|
||||
}
|
||||
|
||||
public Type GetListTypeInPath(string path)
|
||||
internal Type GetListTypeInPath(string path)
|
||||
{
|
||||
if (!ContainsPath(path))
|
||||
return null;
|
||||
@@ -90,7 +90,7 @@ namespace Artemis.Core.DataModelExpansions
|
||||
return null;
|
||||
}
|
||||
|
||||
public Type GetListTypeAtPath(string path)
|
||||
internal Type GetListTypeAtPath(string path)
|
||||
{
|
||||
if (!ContainsPath(path))
|
||||
return null;
|
||||
@@ -98,29 +98,7 @@ namespace Artemis.Core.DataModelExpansions
|
||||
var child = GetTypeAtPath(path);
|
||||
return child.GenericTypeArguments.Length > 0 ? child.GenericTypeArguments[0] : null;
|
||||
}
|
||||
|
||||
public string GetListInnerPath(string path)
|
||||
{
|
||||
if (GetListTypeInPath(path) == null)
|
||||
throw new ArtemisCoreException($"Cannot determine inner list path at {path} because it does not contain a list");
|
||||
|
||||
var parts = path.Split('.');
|
||||
var current = GetType();
|
||||
|
||||
for (var index = 0; index < parts.Length; index++)
|
||||
{
|
||||
var part = parts[index];
|
||||
var property = current.GetProperty(part);
|
||||
|
||||
if (typeof(IList).IsAssignableFrom(property.PropertyType))
|
||||
return string.Join('.', parts.Skip(index + 1).ToList());
|
||||
|
||||
current = property.PropertyType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a read-only list of all properties in this datamodel that are to be ignored
|
||||
/// </summary>
|
||||
|
||||
@@ -10,14 +10,22 @@ namespace Artemis.Core.DataModelExpansions
|
||||
/// </summary>
|
||||
public abstract class BaseDataModelExpansion : Plugin
|
||||
{
|
||||
protected readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
|
||||
/// <summary>
|
||||
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
|
||||
/// </summary>
|
||||
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all properties ignored at runtime using IgnoreProperty(x => x.y)
|
||||
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly();
|
||||
|
||||
internal DataModel InternalDataModel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame when the data model should update
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Time in seconds since the last update</param>
|
||||
public abstract void Update(double deltaTime);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,13 +2,23 @@
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a view model for a brush configuration window
|
||||
/// </summary>
|
||||
public abstract class BrushConfigurationViewModel : Screen
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="BrushConfigurationViewModel" /> class
|
||||
/// </summary>
|
||||
/// <param name="layerBrush"></param>
|
||||
protected BrushConfigurationViewModel(BaseLayerBrush layerBrush)
|
||||
{
|
||||
LayerBrush = layerBrush;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the layer brush this view model is associated with
|
||||
/// </summary>
|
||||
public BaseLayerBrush LayerBrush { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
using Artemis.Core.Services;
|
||||
using SkiaSharp;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a brush that renders on a layer
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of brush properties</typeparam>
|
||||
public abstract class LayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="LayerBrush{T}" /> class
|
||||
/// </summary>
|
||||
protected LayerBrush()
|
||||
{
|
||||
BrushType = LayerBrushType.Regular;
|
||||
|
||||
@@ -44,6 +44,16 @@ namespace Artemis.Core.LayerBrushes
|
||||
/// </summary>
|
||||
public LayerBrushProvider LayerBrushProvider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the provided <paramref name="reference" /> references to a brush provided by this descriptor
|
||||
/// </summary>
|
||||
public bool MatchesLayerBrushReference(LayerBrushReference reference)
|
||||
{
|
||||
if (reference == null)
|
||||
return false;
|
||||
return LayerBrushProvider.PluginInfo.Guid == reference.BrushPluginGuid && LayerBrushType.Name == reference.BrushType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the described brush and applies it to the layer
|
||||
/// </summary>
|
||||
@@ -61,12 +71,5 @@ namespace Artemis.Core.LayerBrushes
|
||||
layer.LayerBrush = brush;
|
||||
layer.OnLayerBrushUpdated();
|
||||
}
|
||||
|
||||
public bool MatchesLayerBrushReference(LayerBrushReference reference)
|
||||
{
|
||||
if (reference == null)
|
||||
return false;
|
||||
return LayerBrushProvider.PluginInfo.Guid == reference.BrushPluginGuid && LayerBrushType.Name == reference.BrushType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,21 @@
|
||||
using Artemis.Core.Services;
|
||||
using SkiaSharp;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a brush that renders on a per-layer basis
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of brush properties</typeparam>
|
||||
public abstract class PerLedLayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="PerLedLayerBrush{T}" /> class
|
||||
/// </summary>
|
||||
protected PerLedLayerBrush()
|
||||
{
|
||||
BrushType = LayerBrushType.Regular;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The main method of rendering for this type of brush. Called once per frame for each LED in the layer
|
||||
/// <para>
|
||||
|
||||
@@ -2,13 +2,23 @@
|
||||
|
||||
namespace Artemis.Core.LayerEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a view model for an effect configuration window
|
||||
/// </summary>
|
||||
public abstract class EffectConfigurationViewModel : Screen
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="EffectConfigurationViewModel" /> class
|
||||
/// </summary>
|
||||
/// <param name="layerEffect"></param>
|
||||
protected EffectConfigurationViewModel(BaseLayerEffect layerEffect)
|
||||
{
|
||||
LayerEffect = layerEffect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the layer effect this view model is associated with
|
||||
/// </summary>
|
||||
public BaseLayerEffect LayerEffect { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using Artemis.Core.Services;
|
||||
|
||||
namespace Artemis.Core.LayerEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an effect that applies preprocessing and/or postprocessing to a layer
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public abstract class LayerEffect<T> : BaseLayerEffect where T : LayerPropertyGroup
|
||||
{
|
||||
private T _properties;
|
||||
|
||||
+1
@@ -16,6 +16,7 @@
|
||||
return ActivationMet;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string GetUserFriendlyDescription()
|
||||
{
|
||||
return "No description available";
|
||||
|
||||
+1
@@ -43,6 +43,7 @@ namespace Artemis.Core.Modules
|
||||
: processes.Any();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string GetUserFriendlyDescription()
|
||||
{
|
||||
var description = $"Requirement met when \"{ProcessName}.exe\" is running";
|
||||
|
||||
@@ -144,13 +144,13 @@ namespace Artemis.Core.Modules
|
||||
public bool IsUpdateAllowed => IsActivated && (UpdateDuringActivationOverride || !IsActivatedOverride);
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame when the module must update
|
||||
/// Called each frame when the module should update
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Time in seconds since the last update</param>
|
||||
public abstract void Update(double deltaTime);
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame when the module must render
|
||||
/// Called each frame when the module should render
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Time since the last render</param>
|
||||
/// <param name="surface">The RGB Surface to render to</param>
|
||||
|
||||
@@ -91,18 +91,27 @@ namespace Artemis.Core.Modules
|
||||
/// </summary>
|
||||
public abstract class ProfileModule : Module
|
||||
{
|
||||
protected readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
|
||||
/// <summary>
|
||||
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
|
||||
/// </summary>
|
||||
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ProfileModule" /> class
|
||||
/// </summary>
|
||||
protected ProfileModule()
|
||||
{
|
||||
OpacityOverride = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all properties ignored at runtime using IgnoreProperty(x => x.y)
|
||||
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently active profile
|
||||
/// </summary>
|
||||
public Profile ActiveProfile { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -225,8 +234,14 @@ namespace Artemis.Core.Modules
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="ActiveProfile" /> has changed
|
||||
/// </summary>
|
||||
public event EventHandler ActiveProfileChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="ActiveProfileChanged" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnActiveProfileChanged()
|
||||
{
|
||||
ActiveProfileChanged?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
@@ -2,13 +2,23 @@
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a view model for a plugin configuration window
|
||||
/// </summary>
|
||||
public abstract class PluginConfigurationViewModel : Screen
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="PluginConfigurationViewModel" /> class
|
||||
/// </summary>
|
||||
/// <param name="plugin"></param>
|
||||
protected PluginConfigurationViewModel(Plugin plugin)
|
||||
{
|
||||
Plugin = plugin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin this configuration view model is associated with
|
||||
/// </summary>
|
||||
public Plugin Plugin { get; }
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@ using Stylet;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents basic info about a plugin and contains a reference to the instance of said plugin
|
||||
/// </summary>
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class PluginInfo : PropertyChangedBase
|
||||
{
|
||||
@@ -17,7 +20,6 @@ namespace Artemis.Core
|
||||
private Guid _guid;
|
||||
private string _icon;
|
||||
private Plugin _instance;
|
||||
private bool _lastEnableSuccessful;
|
||||
private Exception _loadException;
|
||||
private string _main;
|
||||
private string _name;
|
||||
@@ -140,6 +142,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
internal PluginEntity PluginEntity { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Name} v{Version} - {Guid}";
|
||||
|
||||
@@ -93,12 +93,12 @@ namespace Artemis.Core
|
||||
Action(interval.TotalSeconds);
|
||||
}
|
||||
|
||||
private void InstanceOnPluginEnabled(object? sender, EventArgs e)
|
||||
private void InstanceOnPluginEnabled(object sender, EventArgs e)
|
||||
{
|
||||
Start();
|
||||
}
|
||||
|
||||
private void InstanceOnPluginDisabled(object? sender, EventArgs e)
|
||||
private void InstanceOnPluginDisabled(object sender, EventArgs e)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ using Stylet;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a setting tied to a plugin of type <typeparamref name="T" />
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The value type of the setting</typeparam>
|
||||
public class PluginSetting<T> : PropertyChangedBase
|
||||
{
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
@@ -78,14 +82,21 @@ namespace Artemis.Core
|
||||
_pluginRepository.SaveSetting(_pluginSettingEntity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the value of the setting has been changed
|
||||
/// </summary>
|
||||
public event EventHandler<EventArgs> SettingChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{nameof(Name)}: {Name}, {nameof(Value)}: {Value}, {nameof(HasChanged)}: {HasChanged}";
|
||||
}
|
||||
|
||||
protected virtual void OnSettingChanged()
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="SettingChanged" /> event
|
||||
/// </summary>
|
||||
protected internal virtual void OnSettingChanged()
|
||||
{
|
||||
SettingChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user