using System;
using System.Linq;
using Artemis.Core.LayerEffects.Placeholder;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile;
using Ninject;
namespace Artemis.Core.LayerEffects
{
///
/// A class that describes a layer effect
///
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;
}
///
/// The name that is displayed in the UI
///
public string DisplayName { get; }
///
/// The description that is displayed in the UI
///
public string Description { get; }
///
/// The Material icon to display in the UI, a full reference can be found
/// here
///
public string Icon { get; }
///
/// The type of the layer effect
///
public Type LayerEffectType { get; }
///
/// The plugin that provided this
///
public LayerEffectProvider LayerEffectProvider { get; }
///
/// Gets the GUID this descriptor is acting as a placeholder for. If null, this descriptor is not a placeholder
///
public Guid? PlaceholderFor { get; internal set; }
///
/// Creates an instance of the described effect and applies it to the render element
///
internal void CreateInstance(RenderProfileElement renderElement, LayerEffectEntity entity)
{
// Skip effects already on the element
if (renderElement.LayerEffects.Any(e => e.EntityId == entity.Id))
return;
if (PlaceholderFor != null)
{
CreatePlaceHolderInstance(renderElement, entity);
return;
}
var effect = (BaseLayerEffect)CoreService.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);
}
private void CreatePlaceHolderInstance(RenderProfileElement renderElement, LayerEffectEntity entity)
{
var effect = new PlaceholderLayerEffect(entity, PlaceholderFor.Value) {ProfileElement = renderElement, Descriptor = this};
effect.Initialize();
renderElement.ActivateLayerEffect(effect);
}
}
}