Skip to content

Commit

Permalink
Profiles - Added IPluginFeatureDependent interface and implement thro…
Browse files Browse the repository at this point in the history
…ughout profiles (#842)

* Profiles - Added IPluginFeatureDependent interface and implement througout profiles
* Workshop - Include dependencies in profile upload request
  • Loading branch information
RobertBeekman authored Mar 3, 2024
1 parent 28640f9 commit e5a5f10
Show file tree
Hide file tree
Showing 27 changed files with 209 additions and 24 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 IEnumerable<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 IEnumerable<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 IEnumerable<PluginFeature> GetFeatureDependencies()
{
return Script.GetFeatureDependencies().Concat(EventPath?.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 IEnumerable<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 IEnumerable<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 IEnumerable<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 IEnumerable<PluginFeature> GetFeatureDependencies()
{
if (Target == null)
return [];
return [Target.Module];
}

/// <summary>
/// Occurs whenever the path becomes invalid
/// </summary>
Expand Down
8 changes: 8 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,14 @@ public override string ToString()
return $"[Folder] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
}

/// <inheritdoc />
public override IEnumerable<PluginFeature> GetFeatureDependencies()
{
return LayerEffects.SelectMany(e => e.GetFeatureDependencies())
.Concat(Children.SelectMany(c => c.GetFeatureDependencies()))
.Concat(DisplayCondition.GetFeatureDependencies());
}

#region Rendering

/// <inheritdoc />
Expand Down
12 changes: 11 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,16 @@ public override string ToString()
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
}

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

/// <summary>
/// Occurs when a property affecting the rendering properties of this layer has been updated
/// </summary>
Expand Down Expand Up @@ -768,7 +778,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 IEnumerable<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 IEnumerable<PluginFeature> GetFeatureDependencies()
{
return LayerProperties.SelectMany(p => p.GetFeatureDependencies()).Concat(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 IEnumerable<PluginFeature> GetFeatureDependencies()
{
return GetRootFolder().GetFeatureDependencies().Concat(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 IEnumerable<PluginFeature> GetFeatureDependencies();

/// <summary>
/// Occurs when a child was added to the <see cref="Children" /> list
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace Artemis.Core;
/// <summary>
/// Represents the configuration of a profile, contained in a <see cref="ProfileCategory" />
/// </summary>
public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable
public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable, IPluginFeatureDependent
{
/// <summary>
/// Represents an empty profile.
/// </summary>
public static readonly ProfileConfiguration Empty = new(ProfileCategory.Empty, "Empty", "Empty");

private ActivationBehaviour _activationBehaviour;
private bool _activationConditionMet;
private ProfileCategory _category;
Expand Down Expand Up @@ -146,7 +146,7 @@ public bool ActivationConditionMet
get => _activationConditionMet;
private set => SetAndNotify(ref _activationConditionMet, value);
}

/// <summary>
/// Gets the profile of this profile configuration
/// </summary>
Expand All @@ -159,8 +159,8 @@ public Profile? Profile
/// <summary>
/// Gets or sets a boolean indicating whether this profile should fade in and out when enabling or disabling
/// </summary>
public bool FadeInAndOut
{
public bool FadeInAndOut
{
get => _fadeInAndOut;
set => SetAndNotify(ref _fadeInAndOut, value);
}
Expand Down Expand Up @@ -188,7 +188,7 @@ public Module? Module
/// alongside any activation requirements of the <see cref="Module" />, if set
/// </summary>
public NodeScript<bool> ActivationCondition { get; }

/// <summary>
/// Gets the entity used by this profile config
/// </summary>
Expand Down Expand Up @@ -247,6 +247,19 @@ public override string ToString()
return $"[ProfileConfiguration] {nameof(Name)}: {Name}";
}

/// <inheritdoc />
public IEnumerable<PluginFeature> GetFeatureDependencies()
{
if (_disposed)
throw new ObjectDisposedException("ProfileConfiguration");
if (Profile == null)
throw new InvalidOperationException("Cannot determine feature dependencies when the profile is not loaded.");

return ActivationCondition.GetFeatureDependencies()
.Concat(Profile.GetFeatureDependencies())
.Concat(Module != null ? [Module] : []);
}

internal void LoadModules(List<Module> enabledModules)
{
if (_disposed)
Expand Down
16 changes: 15 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,20 @@ public void Dispose()
Dispose(true);
GC.SuppressFinalize(this);
}

#region Implementation of IPluginFeatureDependent

/// <inheritdoc />
public IEnumerable<PluginFeature> GetFeatureDependencies()
{
IEnumerable<PluginFeature> result = [Descriptor.Provider];
if (BaseProperties != null)
result = result.Concat(BaseProperties.GetFeatureDependencies());

return result;
}

#endregion
}

/// <summary>
Expand Down
Loading

0 comments on commit e5a5f10

Please sign in to comment.