using System;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.LayerBrushes;
///
/// A class that describes a layer brush
///
public class LayerBrushDescriptor
{
internal LayerBrushDescriptor(string displayName, string description, string icon, Type layerBrushType, LayerBrushProvider provider)
{
DisplayName = displayName;
Description = description;
Icon = icon;
LayerBrushType = layerBrushType;
Provider = provider;
}
///
/// 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 brush
///
public Type LayerBrushType { get; }
///
/// The plugin that provided this
///
public LayerBrushProvider Provider { get; }
///
/// Determines whether the provided references to a brush provided by this descriptor
///
public bool MatchesLayerBrushReference(LayerBrushReference? reference)
{
if (reference == null)
return false;
return Provider.Id == reference.LayerBrushProviderId && LayerBrushType.Name == reference.BrushType;
}
///
/// Creates an instance of the described brush and applies it to the layer
///
public BaseLayerBrush CreateInstance(Layer layer, LayerBrushEntity? entity)
{
if (layer == null)
throw new ArgumentNullException(nameof(layer));
BaseLayerBrush brush = (BaseLayerBrush) Provider.Plugin.Resolve(LayerBrushType);
brush.Layer = layer;
brush.Descriptor = this;
brush.LayerBrushEntity = entity ?? new LayerBrushEntity {ProviderId = Provider.Id, BrushType = LayerBrushType.FullName ?? throw new InvalidOperationException()};
brush.Initialize();
return brush;
}
}