mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Conditions - Refactor layer properties WIP
This commit is contained in:
1 parent
d9bba8cb54
commit
660324c980
33 files changed
+363
-492
No files matched your search
@@ -1,6 +1,4 @@
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.KeyframeEngines;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
@@ -8,14 +6,27 @@ namespace Artemis.Core.Services.Interfaces
|
||||
public interface ILayerService : IArtemisService
|
||||
{
|
||||
/// <summary>
|
||||
/// Instantiates and adds the <see cref="LayerBrush" /> described by the provided <see cref="LayerBrushDescriptor" />
|
||||
/// Creates a new layer
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <param name="parent"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
Layer CreateLayer(Profile profile, ProfileElement parent, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates and adds the <see cref="BaseLayerBrush" /> described by the provided
|
||||
/// <see cref="LayerBrushDescriptor" />
|
||||
/// to the <see cref="Layer" />.
|
||||
/// </summary>
|
||||
/// <param name="layer">The layer to instantiate the brush for</param>
|
||||
/// <returns></returns>
|
||||
ILayerBrush InstantiateLayerBrush(Layer layer);
|
||||
BaseLayerBrush InstantiateLayerBrush(Layer layer);
|
||||
|
||||
void LoadPropertyBaseValue(Layer layer, string path, object layerProperty);
|
||||
void LoadPropertyKeyframes(Layer layer, string path, object layerProperty);
|
||||
/// <summary>
|
||||
/// Removes the layer brush from the provided layer and disposes it
|
||||
/// </summary>
|
||||
/// <param name="layer"></param>
|
||||
void RemoveLayerBrush(Layer layer);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.KeyframeEngines;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Newtonsoft.Json;
|
||||
using Ninject;
|
||||
using Ninject.Parameters;
|
||||
using Serilog;
|
||||
@@ -31,8 +26,8 @@ namespace Artemis.Core.Services
|
||||
var layer = new Layer(profile, parent, name);
|
||||
|
||||
// Layers have two hardcoded property groups, instantiate them
|
||||
layer.General.InitializeProperties(this, layer, null, null);
|
||||
layer.Transform.InitializeProperties(this, layer, null, null);
|
||||
layer.General.InitializeProperties(this, layer, null);
|
||||
layer.Transform.InitializeProperties(this, layer, null);
|
||||
|
||||
// With the properties loaded, the layer brush can be instantiated
|
||||
InstantiateLayerBrush(layer);
|
||||
@@ -40,7 +35,7 @@ namespace Artemis.Core.Services
|
||||
return layer;
|
||||
}
|
||||
|
||||
public ILayerBrush InstantiateLayerBrush(Layer layer)
|
||||
public BaseLayerBrush InstantiateLayerBrush(Layer layer)
|
||||
{
|
||||
RemoveLayerBrush(layer);
|
||||
|
||||
@@ -62,7 +57,7 @@ namespace Artemis.Core.Services
|
||||
new ConstructorArgument("layer", layer),
|
||||
new ConstructorArgument("descriptor", descriptor)
|
||||
};
|
||||
var layerBrush = (ILayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments);
|
||||
var layerBrush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments);
|
||||
layerBrush.InitializeProperties(this, null);
|
||||
layer.LayerBrush = layerBrush;
|
||||
|
||||
@@ -76,11 +71,9 @@ namespace Artemis.Core.Services
|
||||
|
||||
var brush = layer.LayerBrush;
|
||||
layer.LayerBrush = null;
|
||||
|
||||
var propertiesToRemove = layer.Properties.Where(l => l.PluginInfo == brush.Descriptor.LayerBrushProvider.PluginInfo).ToList();
|
||||
foreach (var layerProperty in propertiesToRemove)
|
||||
layer.Properties.RemoveLayerProperty(layerProperty);
|
||||
brush.Dispose();
|
||||
|
||||
layer.LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,6 @@ namespace Artemis.Core.Services.Storage
|
||||
if (profile != null)
|
||||
{
|
||||
InstantiateProfileLayerBrushes(profile);
|
||||
InstantiateProfileKeyframeEngines(profile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,14 +164,7 @@ namespace Artemis.Core.Services.Storage
|
||||
foreach (var layer in profile.GetAllLayers().Where(l => l.LayerBrush == null))
|
||||
_layerService.InstantiateLayerBrush(layer);
|
||||
}
|
||||
|
||||
private void InstantiateProfileKeyframeEngines(Profile profile)
|
||||
{
|
||||
// Only instantiate engines for properties without an existing engine instance
|
||||
foreach (var layerProperty in profile.GetAllLayers().SelectMany(l => l.Properties).Where(p => p.KeyframeEngine == null))
|
||||
_layerService.InstantiateKeyframeEngine(layerProperty);
|
||||
}
|
||||
|
||||
|
||||
private void ActiveProfilesPopulateLeds(ArtemisSurface surface)
|
||||
{
|
||||
var profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
|
||||
@@ -186,14 +178,7 @@ namespace Artemis.Core.Services.Storage
|
||||
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
||||
InstantiateProfileLayerBrushes(profileModule.ActiveProfile);
|
||||
}
|
||||
|
||||
private void ActiveProfilesInstantiateKeyframeEngines()
|
||||
{
|
||||
var profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
|
||||
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
||||
InstantiateProfileKeyframeEngines(profileModule.ActiveProfile);
|
||||
}
|
||||
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e)
|
||||
@@ -212,7 +197,6 @@ namespace Artemis.Core.Services.Storage
|
||||
if (e.PluginInfo.Instance is LayerBrushProvider)
|
||||
{
|
||||
ActiveProfilesInstantiateProfileLayerBrushes();
|
||||
ActiveProfilesInstantiateKeyframeEngines();
|
||||
}
|
||||
else if (e.PluginInfo.Instance is ProfileModule profileModule)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user