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:
parent
2c2b0ca3e1
commit
956707b23d
@ -472,7 +472,7 @@ namespace Artemis.Core.Models.Profile
|
||||
DeactivateLayerEffect(baseLayerEffect);
|
||||
}
|
||||
|
||||
private void DeactivateLayerBrush()
|
||||
internal void DeactivateLayerBrush()
|
||||
{
|
||||
if (LayerBrush == null)
|
||||
return;
|
||||
|
||||
@ -46,6 +46,10 @@ namespace Artemis.Core.Services
|
||||
_surfaceService = surfaceService;
|
||||
_profileService = profileService;
|
||||
_loggingLevel = settingsService.GetSetting("Core.LoggingLevel", LogEventLevel.Debug);
|
||||
_frameStopWatch = new Stopwatch();
|
||||
|
||||
UpdatePluginCache();
|
||||
ConfigureJsonConvert();
|
||||
|
||||
_rgbService.Surface.Updating += SurfaceOnUpdating;
|
||||
_rgbService.Surface.Updated += SurfaceOnUpdated;
|
||||
@ -53,11 +57,6 @@ namespace Artemis.Core.Services
|
||||
|
||||
_pluginService.PluginEnabled += (sender, args) => UpdatePluginCache();
|
||||
_pluginService.PluginDisabled += (sender, args) => UpdatePluginCache();
|
||||
UpdatePluginCache();
|
||||
|
||||
_frameStopWatch = new Stopwatch();
|
||||
|
||||
ConfigureJsonConvert();
|
||||
}
|
||||
|
||||
public TimeSpan FrameTime { get; private set; }
|
||||
|
||||
@ -23,6 +23,12 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// <param name="layer">The layer to remove the active brush from</param>
|
||||
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>
|
||||
/// Instantiates and adds the <see cref="BaseLayerBrush" /> described by the provided
|
||||
/// <see cref="LayerBrushDescriptor" />
|
||||
|
||||
@ -49,6 +49,12 @@ namespace Artemis.Core.Services
|
||||
layer.OnLayerBrushUpdated();
|
||||
}
|
||||
|
||||
public void DeactivateLayerBrush(Layer layer)
|
||||
{
|
||||
layer.DeactivateLayerBrush();
|
||||
layer.OnLayerBrushUpdated();
|
||||
}
|
||||
|
||||
public BaseLayerBrush InstantiateLayerBrush(Layer layer)
|
||||
{
|
||||
if (layer.LayerBrush != null)
|
||||
@ -105,15 +111,16 @@ namespace Artemis.Core.Services
|
||||
|
||||
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 descriptors = layerEffectProviders.SelectMany(l => l.LayerEffectDescriptors).ToList();
|
||||
var entities = effectElement.EffectsEntity.LayerEffects.OrderByDescending(e => e.Order).ToList();
|
||||
|
||||
|
||||
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
|
||||
var descriptor = descriptors.FirstOrDefault(d => d.LayerEffectProvider.PluginInfo.Guid == layerEffectEntity.PluginGuid &&
|
||||
d.LayerEffectType.Name == layerEffectEntity.EffectType);
|
||||
|
||||
@ -4,6 +4,7 @@ using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.LayerEffect.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
@ -34,7 +35,8 @@ namespace Artemis.Core.Services.Storage
|
||||
|
||||
_surfaceService.ActiveSurfaceConfigurationSelected += OnActiveSurfaceConfigurationSelected;
|
||||
_surfaceService.SurfaceConfigurationUpdated += OnSurfaceConfigurationUpdated;
|
||||
_pluginService.PluginLoaded += OnPluginLoaded;
|
||||
_pluginService.PluginEnabled += OnPluginToggled;
|
||||
_pluginService.PluginDisabled += OnPluginToggled;
|
||||
}
|
||||
|
||||
public void ActivateDefaultProfiles()
|
||||
@ -89,9 +91,6 @@ namespace Artemis.Core.Services.Storage
|
||||
|
||||
public void ActivateProfile(ProfileModule module, Profile profile)
|
||||
{
|
||||
if (module.ActiveProfile == profile)
|
||||
return;
|
||||
|
||||
module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
|
||||
if (profile != null)
|
||||
{
|
||||
@ -181,7 +180,12 @@ namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
foreach (var folder in profile.GetAllFolders())
|
||||
{
|
||||
// Instantiate effects
|
||||
_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())
|
||||
{
|
||||
_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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
private void OnPluginLoaded(object sender, PluginEventArgs e)
|
||||
private void OnPluginToggled(object sender, PluginEventArgs e)
|
||||
{
|
||||
if (e.PluginInfo.Instance is LayerBrushProvider)
|
||||
ActiveProfilesInstantiatePlugins();
|
||||
if (e.PluginInfo.Instance is LayerEffectProvider)
|
||||
ActiveProfilesInstantiatePlugins();
|
||||
else if (e.PluginInfo.Instance is ProfileModule profileModule)
|
||||
{
|
||||
var activeProfile = GetActiveProfile(profileModule);
|
||||
|
||||
@ -55,7 +55,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
public override bool IsExpanded
|
||||
{
|
||||
get => LayerPropertyGroup.ProfileElement.IsPropertyGroupExpanded(LayerPropertyGroup);
|
||||
set => LayerPropertyGroup.ProfileElement.SetPropertyGroupExpanded(LayerPropertyGroup, value);
|
||||
set
|
||||
{
|
||||
LayerPropertyGroup.ProfileElement.SetPropertyGroupExpanded(LayerPropertyGroup, value);
|
||||
NotifyOfPropertyChange(nameof(IsExpanded));
|
||||
}
|
||||
}
|
||||
|
||||
public ViewModelType GroupType
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user