Skip to content

Commit

Permalink
Profiles - Added IPluginFeatureDependent interface and implement thro…
Browse files Browse the repository at this point in the history
…ugout profiles
  • Loading branch information
RobertBeekman committed Mar 2, 2024
1 parent 28640f9 commit 2a1c9d4
Show file tree
Hide file tree
Showing 25 changed files with 188 additions and 18 deletions.
15 changes: 15 additions & 0 deletions src/Artemis.Core/Models/IPluginFeatureDependent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace Artemis.Core;

/// <summary>
/// Represents a class that depends on plugin features
/// </summary>
public interface IPluginFeatureDependent
{
/// <summary>
/// Gets the plugin features this class depends on, may contain the same plugin feature twice if depending on it in multiple ways.
/// </summary>
/// <returns>A <see cref="List{T}"/> of <see cref="PluginFeature"/> this class depends on.</returns>
public List<PluginFeature> GetFeatureDependencies();
}
11 changes: 11 additions & 0 deletions src/Artemis.Core/Models/Profile/Conditions/AlwaysOnCondition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;

Expand Down Expand Up @@ -82,4 +83,14 @@ public void OverrideTimeline(TimeSpan position)
}

#endregion

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
return [];
}

#endregion
}
10 changes: 10 additions & 0 deletions src/Artemis.Core/Models/Profile/Conditions/EventCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,14 @@ public void LoadNodeScript()
}

#endregion

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
return [..EventPath?.GetFeatureDependencies() ?? [], ..Script.GetFeatureDependencies()];
}

#endregion
}
2 changes: 1 addition & 1 deletion src/Artemis.Core/Models/Profile/Conditions/ICondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Artemis.Core;
/// <summary>
/// Represents a condition applied to a <see cref="ProfileElement" />
/// </summary>
public interface ICondition : IDisposable, IStorageModel
public interface ICondition : IDisposable, IStorageModel, IPluginFeatureDependent
{
/// <summary>
/// Gets the entity used to store this condition
Expand Down
11 changes: 11 additions & 0 deletions src/Artemis.Core/Models/Profile/Conditions/PlayOnceCondition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;

Expand Down Expand Up @@ -82,4 +83,14 @@ public void OverrideTimeline(TimeSpan position)
}

#endregion

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
return [];
}

#endregion
}
11 changes: 11 additions & 0 deletions src/Artemis.Core/Models/Profile/Conditions/StaticCondition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;
Expand Down Expand Up @@ -159,6 +160,16 @@ public void LoadNodeScript()
}

#endregion

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
return Script.GetFeatureDependencies();
}

#endregion
}

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Artemis.Core/Models/Profile/DataBindings/DataBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,14 @@ public void Save()
}

#endregion

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
return Script.GetFeatureDependencies();
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Artemis.Core;
/// Represents a data binding that binds a certain <see cref="LayerProperty{T}" /> to a value inside a
/// <see cref="DataModel" />
/// </summary>
public interface IDataBinding : IStorageModel, IDisposable
public interface IDataBinding : IStorageModel, IDisposable, IPluginFeatureDependent
{
/// <summary>
/// Gets the layer property the data binding is applied to
Expand Down
10 changes: 9 additions & 1 deletion src/Artemis.Core/Models/Profile/DataModel/DataModelPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Artemis.Core;
/// <summary>
/// Represents a path that points to a property in data model
/// </summary>
public class DataModelPath : IStorageModel, IDisposable
public class DataModelPath : IStorageModel, IDisposable, IPluginFeatureDependent
{
private readonly LinkedList<DataModelPathSegment> _segments;
private Expression<Func<object, object>>? _accessorLambda;
Expand Down Expand Up @@ -188,6 +188,14 @@ public override string ToString()
return string.IsNullOrWhiteSpace(Path) ? "this" : Path;
}

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
if (Target == null)
return [];
return [Target.Module];
}

/// <summary>
/// Occurs whenever the path becomes invalid
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Artemis.Core/Models/Profile/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ public override string ToString()
return $"[Folder] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
}

/// <inheritdoc />
public override List<PluginFeature> GetFeatureDependencies()
{
return [
..LayerEffects.SelectMany(e => e.GetFeatureDependencies()),
..Children.SelectMany(c => c.GetFeatureDependencies()),
..DisplayCondition.GetFeatureDependencies()
];
}

#region Rendering

/// <inheritdoc />
Expand Down
14 changes: 13 additions & 1 deletion src/Artemis.Core/Models/Profile/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ public override string ToString()
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
}

/// <inheritdoc />
public override List<PluginFeature> GetFeatureDependencies()
{
return [
..LayerEffects.SelectMany(e => e.GetFeatureDependencies()),
..LayerBrush?.GetFeatureDependencies() ?? [],
..General.GetFeatureDependencies(),
..Transform.GetFeatureDependencies(),
..DisplayCondition.GetFeatureDependencies()
];
}

/// <summary>
/// Occurs when a property affecting the rendering properties of this layer has been updated
/// </summary>
Expand Down Expand Up @@ -768,7 +780,7 @@ public void RemoveLed(ArtemisLed led)

if (!_leds.Remove(led))
return;

CalculateRenderProperties();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Artemis.Core;
/// initialize these for you.
/// </para>
/// </summary>
public interface ILayerProperty : IStorageModel, IDisposable
public interface ILayerProperty : IStorageModel, IDisposable, IPluginFeatureDependent
{
/// <summary>
/// Gets the description attribute applied to this property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public override string ToString()
return $"{Path} - {CurrentValue} ({PropertyType})";
}

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
return DataBinding.GetFeatureDependencies();
}

/// <summary>
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
/// </summary>
Expand Down
12 changes: 11 additions & 1 deletion src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Artemis.Core;
/// initialize these for you.
/// </para>
/// </summary>
public abstract class LayerPropertyGroup : IDisposable
public abstract class LayerPropertyGroup : IDisposable, IPluginFeatureDependent
{
private readonly List<ILayerProperty> _layerProperties;
private readonly List<LayerPropertyGroup> _layerPropertyGroups;
Expand Down Expand Up @@ -343,4 +343,14 @@ public void Dispose()
Dispose(true);
GC.SuppressFinalize(this);
}

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
return [..LayerProperties.SelectMany(p => p.GetFeatureDependencies()), ..LayerPropertyGroups.SelectMany(g => g.GetFeatureDependencies())];
}

#endregion
}
6 changes: 6 additions & 0 deletions src/Artemis.Core/Models/Profile/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ public override string ToString()
return $"[Profile] {nameof(Name)}: {Name}";
}

/// <inheritdoc />
public override List<PluginFeature> GetFeatureDependencies()
{
return [..GetRootFolder().GetFeatureDependencies(), ..Scripts.Select(c => c.ScriptingProvider)];
}

/// <summary>
/// Populates all the LEDs on the elements in this profile
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion src/Artemis.Core/Models/Profile/ProfileElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Artemis.Core;
/// <summary>
/// Represents an element of a <see cref="Profile" />
/// </summary>
public abstract class ProfileElement : BreakableModel, IDisposable
public abstract class ProfileElement : BreakableModel, IDisposable, IPluginFeatureDependent
{
internal readonly List<ProfileElement> ChildrenList;
private Guid _entityId;
Expand Down Expand Up @@ -122,6 +122,9 @@ public override string ToString()
return $"{nameof(EntityId)}: {EntityId}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
}

/// <inheritdoc />
public abstract List<PluginFeature> GetFeatureDependencies();

/// <summary>
/// Occurs when a child was added to the <see cref="Children" /> list
/// </summary>
Expand Down
14 changes: 13 additions & 1 deletion src/Artemis.Core/Plugins/LayerBrushes/Internal/BaseLayerBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Artemis.Core.LayerBrushes;
/// <summary>
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="PerLedLayerBrush{T}" /> or instead
/// </summary>
public abstract class BaseLayerBrush : BreakableModel, IDisposable
public abstract class BaseLayerBrush : BreakableModel, IDisposable, IPluginFeatureDependent
{
private LayerBrushType _brushType;
private ILayerBrushConfigurationDialog? _configurationDialog;
Expand Down Expand Up @@ -199,6 +199,18 @@ public void Dispose()
Dispose(true);
GC.SuppressFinalize(this);
}

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
if (BaseProperties == null)
return [Descriptor.Provider];
return [Descriptor.Provider, ..BaseProperties.GetFeatureDependencies()];
}

#endregion
}

/// <summary>
Expand Down
17 changes: 15 additions & 2 deletions src/Artemis.Core/Plugins/LayerEffects/Internal/BaseLayerEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Artemis.Storage.Entities.Profile;
using SkiaSharp;

Expand All @@ -7,7 +8,7 @@ namespace Artemis.Core.LayerEffects;
/// <summary>
/// For internal use only, please use <see cref="LayerEffect{T}" /> instead
/// </summary>
public abstract class BaseLayerEffect : BreakableModel, IDisposable, IStorageModel
public abstract class BaseLayerEffect : BreakableModel, IDisposable, IStorageModel, IPluginFeatureDependent
{
private ILayerEffectConfigurationDialog? _configurationDialog;
private LayerEffectDescriptor _descriptor;
Expand Down Expand Up @@ -164,7 +165,7 @@ protected virtual void Dispose(bool disposing)
// Not only is this needed to initialize properties on the layer effects, it also prevents implementing anything
// but LayerEffect<T> outside the core
internal abstract void Initialize();

internal void InternalUpdate(Timeline timeline)
{
BaseProperties?.Update(timeline);
Expand Down Expand Up @@ -235,4 +236,16 @@ public void Save()
BaseProperties?.ApplyToEntity();
LayerEffectEntity.PropertyGroup = BaseProperties?.PropertyGroupEntity;
}

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
if (BaseProperties == null)
return [Descriptor.Provider];
return [Descriptor.Provider, ..BaseProperties.GetFeatureDependencies()];
}

#endregion
}
2 changes: 1 addition & 1 deletion src/Artemis.Core/VisualScripting/Interfaces/INode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Artemis.Core;
/// <summary>
/// Represents a kind of node inside a <see cref="INodeScript" />
/// </summary>
public interface INode : INotifyPropertyChanged, IBreakableModel
public interface INode : INotifyPropertyChanged, IBreakableModel, IPluginFeatureDependent
{
/// <summary>
/// Gets or sets the ID of the node.
Expand Down
2 changes: 1 addition & 1 deletion src/Artemis.Core/VisualScripting/Interfaces/INodeScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Artemis.Core;
/// <summary>
/// Represents a node script
/// </summary>
public interface INodeScript : INotifyPropertyChanged, IDisposable, IStorageModel
public interface INodeScript : INotifyPropertyChanged, IDisposable, IStorageModel, IPluginFeatureDependent
{
/// <summary>
/// Gets the name of the node script.
Expand Down
10 changes: 10 additions & 0 deletions src/Artemis.Core/VisualScripting/NodeScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ private void SavePins(INode node, int collectionId, IEnumerable<IPin> pins)
}

#endregion

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public List<PluginFeature> GetFeatureDependencies()
{
return Nodes.SelectMany(n => n.GetFeatureDependencies()).ToList();
}

#endregion
}

/// <summary>
Expand Down
Loading

0 comments on commit 2a1c9d4

Please sign in to comment.