Files
Artemis/src/Artemis.Core/Plugins/LayerEffects/LayerEffectDescriptor.cs
T
Robert ea9c6526d8 Core - Added stores for the different register-able types
Profiles - Refactored large parts of the profile structure to use these stores
2020-09-12 10:39:44 +02:00

77 lines
2.5 KiB
C#

using System;
using System.Linq;
using Artemis.Core.LayerBrushes;
using Artemis.Storage.Entities.Profile;
using Ninject;
namespace Artemis.Core.LayerEffects
{
/// <summary>
/// A class that describes a layer effect
/// </summary>
public class LayerEffectDescriptor
{
internal LayerEffectDescriptor(string displayName, string description, string icon, Type layerEffectType, LayerEffectProvider layerEffectProvider)
{
DisplayName = displayName;
Description = description;
Icon = icon;
LayerEffectType = layerEffectType;
LayerEffectProvider = layerEffectProvider;
}
/// <summary>
/// The name that is displayed in the UI
/// </summary>
public string DisplayName { get; }
/// <summary>
/// The description that is displayed in the UI
/// </summary>
public string Description { get; }
/// <summary>
/// The Material icon to display in the UI, a full reference can be found
/// <see href="https://materialdesignicons.com">here</see>
/// </summary>
public string Icon { get; }
/// <summary>
/// The type of the layer effect
/// </summary>
public Type LayerEffectType { get; }
/// <summary>
/// The plugin that provided this <see cref="LayerEffectDescriptor" />
/// </summary>
public LayerEffectProvider LayerEffectProvider { get; }
/// <summary>
/// Gets or sets the kernel used to instantiate the described layer effect
/// </summary>
internal IKernel Kernel { get; set; }
/// <summary>
/// Creates an instance of the described effect and applies it to the render element
/// </summary>
internal void CreateInstance(RenderProfileElement renderElement, LayerEffectEntity entity)
{
// Skip effects already on the element
if (renderElement.LayerEffects.Any(e => e.EntityId == entity.Id))
return;
var effect = (BaseLayerEffect) Kernel.Get(LayerEffectType);
effect.ProfileElement = renderElement;
effect.EntityId = entity.Id;
effect.Order = entity.Order;
effect.Name = entity.Name;
effect.Enabled = entity.Enabled;
effect.Descriptor = this;
effect.Initialize();
effect.Update(0);
renderElement.ActivateLayerEffect(effect);
}
}
}