1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Profiles - Improved handling of enabling/disabling plugins

This commit is contained in:
Robert 2020-06-30 21:39:29 +02:00
parent 2c2b0ca3e1
commit 956707b23d
6 changed files with 50 additions and 17 deletions

View File

@ -472,7 +472,7 @@ namespace Artemis.Core.Models.Profile
DeactivateLayerEffect(baseLayerEffect); DeactivateLayerEffect(baseLayerEffect);
} }
private void DeactivateLayerBrush() internal void DeactivateLayerBrush()
{ {
if (LayerBrush == null) if (LayerBrush == null)
return; return;

View File

@ -46,6 +46,10 @@ namespace Artemis.Core.Services
_surfaceService = surfaceService; _surfaceService = surfaceService;
_profileService = profileService; _profileService = profileService;
_loggingLevel = settingsService.GetSetting("Core.LoggingLevel", LogEventLevel.Debug); _loggingLevel = settingsService.GetSetting("Core.LoggingLevel", LogEventLevel.Debug);
_frameStopWatch = new Stopwatch();
UpdatePluginCache();
ConfigureJsonConvert();
_rgbService.Surface.Updating += SurfaceOnUpdating; _rgbService.Surface.Updating += SurfaceOnUpdating;
_rgbService.Surface.Updated += SurfaceOnUpdated; _rgbService.Surface.Updated += SurfaceOnUpdated;
@ -53,11 +57,6 @@ namespace Artemis.Core.Services
_pluginService.PluginEnabled += (sender, args) => UpdatePluginCache(); _pluginService.PluginEnabled += (sender, args) => UpdatePluginCache();
_pluginService.PluginDisabled += (sender, args) => UpdatePluginCache(); _pluginService.PluginDisabled += (sender, args) => UpdatePluginCache();
UpdatePluginCache();
_frameStopWatch = new Stopwatch();
ConfigureJsonConvert();
} }
public TimeSpan FrameTime { get; private set; } public TimeSpan FrameTime { get; private set; }

View File

@ -23,6 +23,12 @@ namespace Artemis.Core.Services.Interfaces
/// <param name="layer">The layer to remove the active brush from</param> /// <param name="layer">The layer to remove the active brush from</param>
void RemoveLayerBrush(Layer layer); void RemoveLayerBrush(Layer layer);
/// <summary>
/// Deactivates the currently active layer brush from the <see cref="Layer" /> but keeps all settings
/// </summary>
/// <param name="layer">The layer to deactivate the active brush on</param>
void DeactivateLayerBrush(Layer layer);
/// <summary> /// <summary>
/// Instantiates and adds the <see cref="BaseLayerBrush" /> described by the provided /// Instantiates and adds the <see cref="BaseLayerBrush" /> described by the provided
/// <see cref="LayerBrushDescriptor" /> /// <see cref="LayerBrushDescriptor" />

View File

@ -49,6 +49,12 @@ namespace Artemis.Core.Services
layer.OnLayerBrushUpdated(); layer.OnLayerBrushUpdated();
} }
public void DeactivateLayerBrush(Layer layer)
{
layer.DeactivateLayerBrush();
layer.OnLayerBrushUpdated();
}
public BaseLayerBrush InstantiateLayerBrush(Layer layer) public BaseLayerBrush InstantiateLayerBrush(Layer layer)
{ {
if (layer.LayerBrush != null) if (layer.LayerBrush != null)
@ -105,15 +111,16 @@ namespace Artemis.Core.Services
public void InstantiateLayerEffects(EffectProfileElement effectElement) public void InstantiateLayerEffects(EffectProfileElement effectElement)
{ {
if (effectElement.LayerEffects.Any())
throw new ArtemisCoreException("Effect element (layer/folder) already has instantiated layer effects");
var layerEffectProviders = _pluginService.GetPluginsOfType<LayerEffectProvider>(); var layerEffectProviders = _pluginService.GetPluginsOfType<LayerEffectProvider>();
var descriptors = layerEffectProviders.SelectMany(l => l.LayerEffectDescriptors).ToList(); var descriptors = layerEffectProviders.SelectMany(l => l.LayerEffectDescriptors).ToList();
var entities = effectElement.EffectsEntity.LayerEffects.OrderByDescending(e => e.Order).ToList(); var entities = effectElement.EffectsEntity.LayerEffects.OrderByDescending(e => e.Order).ToList();
foreach (var layerEffectEntity in entities) foreach (var layerEffectEntity in entities)
{ {
// Skip effects already on the element
if (effectElement.LayerEffects.Any(e => e.EntityId == layerEffectEntity.Id))
continue;
// Get a matching descriptor // Get a matching descriptor
var descriptor = descriptors.FirstOrDefault(d => d.LayerEffectProvider.PluginInfo.Guid == layerEffectEntity.PluginGuid && var descriptor = descriptors.FirstOrDefault(d => d.LayerEffectProvider.PluginInfo.Guid == layerEffectEntity.PluginGuid &&
d.LayerEffectType.Name == layerEffectEntity.EffectType); d.LayerEffectType.Name == layerEffectEntity.EffectType);

View File

@ -4,6 +4,7 @@ using Artemis.Core.Events;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.LayerEffect.Abstract;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces; using Artemis.Core.Services.Storage.Interfaces;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
@ -34,7 +35,8 @@ namespace Artemis.Core.Services.Storage
_surfaceService.ActiveSurfaceConfigurationSelected += OnActiveSurfaceConfigurationSelected; _surfaceService.ActiveSurfaceConfigurationSelected += OnActiveSurfaceConfigurationSelected;
_surfaceService.SurfaceConfigurationUpdated += OnSurfaceConfigurationUpdated; _surfaceService.SurfaceConfigurationUpdated += OnSurfaceConfigurationUpdated;
_pluginService.PluginLoaded += OnPluginLoaded; _pluginService.PluginEnabled += OnPluginToggled;
_pluginService.PluginDisabled += OnPluginToggled;
} }
public void ActivateDefaultProfiles() public void ActivateDefaultProfiles()
@ -89,9 +91,6 @@ namespace Artemis.Core.Services.Storage
public void ActivateProfile(ProfileModule module, Profile profile) public void ActivateProfile(ProfileModule module, Profile profile)
{ {
if (module.ActiveProfile == profile)
return;
module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface); module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
if (profile != null) if (profile != null)
{ {
@ -181,7 +180,12 @@ namespace Artemis.Core.Services.Storage
{ {
foreach (var folder in profile.GetAllFolders()) foreach (var folder in profile.GetAllFolders())
{ {
// Instantiate effects
_layerService.InstantiateLayerEffects(folder); _layerService.InstantiateLayerEffects(folder);
// Remove effects of plugins that are disabled
var disabledEffects = new List<BaseLayerEffect>(folder.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled));
foreach (var layerLayerEffect in disabledEffects)
_layerService.RemoveLayerEffect(layerLayerEffect);
} }
} }
@ -189,8 +193,19 @@ namespace Artemis.Core.Services.Storage
{ {
foreach (var layer in profile.GetAllLayers()) foreach (var layer in profile.GetAllLayers())
{ {
_layerService.InstantiateLayerBrush(layer); // Instantiate brush
if (layer.LayerBrush == null)
_layerService.InstantiateLayerBrush(layer);
// Remove brush if plugin is disabled
else if (!layer.LayerBrush.PluginInfo.Enabled)
_layerService.DeactivateLayerBrush(layer);
// Instantiate effects
_layerService.InstantiateLayerEffects(layer); _layerService.InstantiateLayerEffects(layer);
// Remove effects of plugins that are disabled
var disabledEffects = new List<BaseLayerEffect>(layer.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled));
foreach (var layerLayerEffect in disabledEffects)
_layerService.RemoveLayerEffect(layerLayerEffect);
} }
} }
@ -224,10 +239,12 @@ namespace Artemis.Core.Services.Storage
ActiveProfilesPopulateLeds(e.Surface); ActiveProfilesPopulateLeds(e.Surface);
} }
private void OnPluginLoaded(object sender, PluginEventArgs e) private void OnPluginToggled(object sender, PluginEventArgs e)
{ {
if (e.PluginInfo.Instance is LayerBrushProvider) if (e.PluginInfo.Instance is LayerBrushProvider)
ActiveProfilesInstantiatePlugins(); ActiveProfilesInstantiatePlugins();
if (e.PluginInfo.Instance is LayerEffectProvider)
ActiveProfilesInstantiatePlugins();
else if (e.PluginInfo.Instance is ProfileModule profileModule) else if (e.PluginInfo.Instance is ProfileModule profileModule)
{ {
var activeProfile = GetActiveProfile(profileModule); var activeProfile = GetActiveProfile(profileModule);

View File

@ -55,7 +55,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
public override bool IsExpanded public override bool IsExpanded
{ {
get => LayerPropertyGroup.ProfileElement.IsPropertyGroupExpanded(LayerPropertyGroup); get => LayerPropertyGroup.ProfileElement.IsPropertyGroupExpanded(LayerPropertyGroup);
set => LayerPropertyGroup.ProfileElement.SetPropertyGroupExpanded(LayerPropertyGroup, value); set
{
LayerPropertyGroup.ProfileElement.SetPropertyGroupExpanded(LayerPropertyGroup, value);
NotifyOfPropertyChange(nameof(IsExpanded));
}
} }
public ViewModelType GroupType public ViewModelType GroupType