using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Models.Profile.LayerProperties
{
///
/// For internal use only, to implement your own layer property type, extend instead.
///
public abstract class BaseLayerProperty
{
private bool _isHidden;
private bool _keyframesEnabled;
internal BaseLayerProperty()
{
}
///
/// Gets the profile element (such as layer or folder) this effect is applied to
///
public RenderProfileElement ProfileElement { get; internal set; }
///
/// The parent group of this layer property, set after construction
///
public LayerPropertyGroup Parent { get; internal set; }
///
/// Gets whether keyframes are supported on this property
///
public bool KeyframesSupported { get; protected set; } = true;
///
/// Gets or sets whether keyframes are enabled on this property, has no effect if is
/// False
///
public bool KeyframesEnabled
{
get => _keyframesEnabled;
set
{
if (_keyframesEnabled == value) return;
_keyframesEnabled = value;
OnKeyframesToggled();
}
}
///
/// Gets or sets whether the property is hidden in the UI
///
public bool IsHidden
{
get => _isHidden;
set
{
_isHidden = value;
OnVisibilityChanged();
}
}
///
/// Indicates whether the BaseValue was loaded from storage, useful to check whether a default value must be applied
///
public bool IsLoadedFromStorage { get; internal set; }
///
/// Gets the total progress on the timeline
///
public TimeSpan TimelineProgress { get; internal set; }
///
/// Used to declare that this property doesn't belong to a plugin and should use the core plugin GUID
///
public bool IsCoreProperty { get; internal set; }
public PropertyDescriptionAttribute PropertyDescription { get; internal set; }
///
/// Gets a list of all the keyframes in their non-generic base form, without their values being available
///
public abstract IReadOnlyList BaseKeyframes { get; }
internal PropertyEntity PropertyEntity { get; set; }
internal LayerPropertyGroup LayerPropertyGroup { get; set; }
public abstract void ApplyDefaultValue();
///
/// Applies the provided property entity to the layer property by deserializing the JSON base value and keyframe values
///
///
///
///
internal abstract void ApplyToLayerProperty(PropertyEntity entity, LayerPropertyGroup layerPropertyGroup, bool fromStorage);
///
/// Saves the property to the underlying property entity that was configured when calling
///
///
internal abstract void ApplyToEntity();
#region Events
///
/// Occurs once every frame when the layer property is updated
///
public event EventHandler Updated;
///
/// Occurs when the base value of the layer property was updated
///
public event EventHandler BaseValueChanged;
///
/// Occurs when the value of the layer property was updated
///
public event EventHandler VisibilityChanged;
///
/// Occurs when keyframes are enabled/disabled
///
public event EventHandler KeyframesToggled;
///
/// Occurs when a new keyframe was added to the layer property
///
public event EventHandler KeyframeAdded;
///
/// Occurs when a keyframe was removed from the layer property
///
public event EventHandler KeyframeRemoved;
protected virtual void OnUpdated()
{
Updated?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnBaseValueChanged()
{
BaseValueChanged?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnVisibilityChanged()
{
VisibilityChanged?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnKeyframesToggled()
{
KeyframesToggled?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnKeyframeAdded()
{
KeyframeAdded?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnKeyframeRemoved()
{
KeyframeRemoved?.Invoke(this, EventArgs.Empty);
}
#endregion
}
}