using System;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core;
///
/// Represents a keyframe on a containing a value and a timestamp
///
public class LayerPropertyKeyframe : CorePropertyChanged, ILayerPropertyKeyframe
{
private LayerProperty _layerProperty;
private TimeSpan _position;
private T _value;
///
/// Creates a new instance of the class
///
/// The value of the keyframe
/// The position of this keyframe in the timeline
/// The easing function applied on the value of the keyframe
/// The layer property this keyframe is applied to
public LayerPropertyKeyframe(T value, TimeSpan position, Easings.Functions easingFunction, LayerProperty layerProperty)
{
_position = position;
_layerProperty = layerProperty;
_value = value;
EasingFunction = easingFunction;
}
///
/// The layer property this keyframe is applied to
///
public LayerProperty LayerProperty
{
get => _layerProperty;
internal set => SetAndNotify(ref _layerProperty, value);
}
///
/// The value of this keyframe
///
public T Value
{
get => _value;
set => SetAndNotify(ref _value, value);
}
///
public ILayerProperty UntypedLayerProperty => LayerProperty;
///
public TimeSpan Position
{
get => _position;
set
{
SetAndNotify(ref _position, value);
LayerProperty.SortKeyframes();
LayerProperty.ReapplyUpdate();
}
}
///
public Easings.Functions EasingFunction { get; set; }
///
public KeyframeEntity GetKeyframeEntity()
{
return new KeyframeEntity
{
Value = CoreJson.Serialize(Value),
Position = Position,
EasingFunction = (int) EasingFunction
};
}
///
public void Remove()
{
LayerProperty.RemoveKeyframe(this);
}
///
public ILayerPropertyKeyframe CreateCopy()
{
return new LayerPropertyKeyframe(Value, Position, EasingFunction, LayerProperty);
}
}