mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Implemented basic keyframes
This commit is contained in:
1 parent
e8570a6dd9
commit
0958c3af9f
41 files changed
+951
-123
No files matched your search
@@ -1,4 +1,6 @@
|
||||
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
|
||||
@@ -14,5 +16,19 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// <param name="settings">JSON settings to be deserialized and injected into the layer brush</param>
|
||||
/// <returns></returns>
|
||||
LayerBrush InstantiateLayerBrush(Layer layer, LayerBrushDescriptor brushDescriptor, string settings = null);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates and adds a compatible <see cref="KeyframeEngine" /> to the provided <see cref="LayerProperty{T}" />
|
||||
/// </summary>
|
||||
/// <param name="layerProperty">The layer property to apply the keyframe engine to.</param>
|
||||
/// <returns>The resulting keyframe engine, if a compatible engine was found.</returns>
|
||||
KeyframeEngine InstantiateKeyframeEngine<T>(LayerProperty<T> layerProperty);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates and adds a compatible <see cref="KeyframeEngine" /> to the provided <see cref="BaseLayerProperty" />.
|
||||
/// </summary>
|
||||
/// <param name="layerProperty">The layer property to apply the keyframe engine to.</param>
|
||||
/// <returns>The resulting keyframe engine, if a compatible engine was found.</returns>
|
||||
KeyframeEngine InstantiateKeyframeEngine(BaseLayerProperty layerProperty);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.KeyframeEngines;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Plugins.Exceptions;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
@@ -74,6 +77,24 @@ namespace Artemis.Core.Services
|
||||
return layerElement;
|
||||
}
|
||||
|
||||
public KeyframeEngine InstantiateKeyframeEngine<T>(LayerProperty<T> layerProperty)
|
||||
{
|
||||
return InstantiateKeyframeEngine((BaseLayerProperty) layerProperty);
|
||||
}
|
||||
|
||||
public KeyframeEngine InstantiateKeyframeEngine(BaseLayerProperty layerProperty)
|
||||
{
|
||||
// This creates an instance of each keyframe engine, which is pretty cheap since all the expensive stuff is done during
|
||||
// Initialize() call but it's not ideal
|
||||
var keyframeEngines = _kernel.Get<List<KeyframeEngine>>();
|
||||
var keyframeEngine = keyframeEngines.FirstOrDefault(k => k.CompatibleTypes.Contains(layerProperty.Type));
|
||||
if (keyframeEngine == null)
|
||||
return null;
|
||||
|
||||
keyframeEngine.Initialize(layerProperty);
|
||||
return keyframeEngine;
|
||||
}
|
||||
|
||||
public void RemoveLayerBrush(Layer layer, LayerBrush layerElement)
|
||||
{
|
||||
var brush = layer.LayerBrush;
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace Artemis.Core.Services.Storage
|
||||
|
||||
if (_surfaceService.ActiveSurface != null)
|
||||
profile.PopulateLeds(_surfaceService.ActiveSurface);
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
@@ -78,7 +79,10 @@ namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
|
||||
if (profile != null)
|
||||
{
|
||||
InstantiateProfileLayerBrushes(profile);
|
||||
InstantiateProfileKeyframeEngines(profile);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteProfile(Profile profile)
|
||||
@@ -118,6 +122,15 @@ namespace Artemis.Core.Services.Storage
|
||||
}
|
||||
}
|
||||
|
||||
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>();
|
||||
@@ -132,6 +145,13 @@ namespace Artemis.Core.Services.Storage
|
||||
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 OnActiveSurfaceConfigurationChanged(object sender, SurfaceConfigurationEventArgs e)
|
||||
@@ -148,7 +168,10 @@ namespace Artemis.Core.Services.Storage
|
||||
private void OnPluginLoaded(object sender, PluginEventArgs e)
|
||||
{
|
||||
if (e.PluginInfo.Instance is LayerBrushProvider)
|
||||
{
|
||||
ActiveProfilesInstantiateProfileLayerBrushes();
|
||||
ActiveProfilesInstantiateKeyframeEngines();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in new issue
Block a user