Started work on the keyframe engine to tie everything together!

This commit is contained in:
Robert committed 2020-01-08 14:35:29 +01:00
1 parent 7a3b5dec3e
commit acdb90897e
28 files changed
+339 -107

No files matched your search

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.KeyframeEngines;
namespace Artemis.Core.Models.Profile.LayerProperties
{
@@ -67,12 +68,16 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// </summary>
public Type Type { get; set; }
protected List<BaseKeyframe> BaseKeyframes { get; set; }
/// <summary>
/// A list of keyframes defining different values of the property in time, this list contains the untyped <see cref="BaseKeyframe"/>.
/// A list of keyframes defining different values of the property in time, this list contains the untyped
/// <see cref="BaseKeyframe" />.
/// </summary>
public IReadOnlyCollection<BaseKeyframe> UntypedKeyframes => BaseKeyframes.AsReadOnly();
public KeyframeEngine KeyframeEngine { get; set; }
protected List<BaseKeyframe> BaseKeyframes { get; set; }
protected object BaseValue
{
get => _baseValue;
@@ -80,11 +85,14 @@ namespace Artemis.Core.Models.Profile.LayerProperties
{
if (value != null && value.GetType() != Type)
throw new ArtemisCoreException($"Cannot set value of type {value.GetType()} on property {this}, expected type is {Type}.");
_baseValue = value;
if (!Equals(_baseValue, value))
{
_baseValue = value;
OnValueChanged();
}
}
}
public void ApplyToEntity()
{
// Big o' TODO
@@ -94,5 +102,16 @@ namespace Artemis.Core.Models.Profile.LayerProperties
{
return $"{nameof(Id)}: {Id}, {nameof(Name)}: {Name}, {nameof(Description)}: {Description}";
}
#region Events
public event EventHandler<EventArgs> ValueChanged;
protected virtual void OnValueChanged()
{
ValueChanged?.Invoke(this, EventArgs.Empty);
}
#endregion
}
}
@@ -9,14 +9,18 @@ namespace Artemis.Core.Models.Profile.LayerProperties
{
}
/// <summary>
/// The value of the property without any keyframes applied
/// </summary>
public T Value
{
get => (T) BaseValue;
get => BaseValue != null ? (T) BaseValue : default;
set => BaseValue = value;
}
/// <summary>
/// A list of keyframes defining different values of the property in time, this list contains the strongly typed <see cref="Keyframe{T}"/>
/// A list of keyframes defining different values of the property in time, this list contains the strongly typed
/// <see cref="Keyframe{T}" />
/// </summary>
public ReadOnlyCollection<Keyframe<T>> Keyframes => BaseKeyframes.Cast<Keyframe<T>>().ToList().AsReadOnly();
@@ -45,5 +49,17 @@ namespace Artemis.Core.Models.Profile.LayerProperties
{
BaseKeyframes.Clear();
}
/// <summary>
/// Gets the current value using the keyframes
/// </summary>
/// <returns></returns>
public T GetCurrentValue()
{
if (KeyframeEngine == null)
return Value;
return (T) KeyframeEngine.GetCurrentValue();
}
}
}