mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Conditions - WIP commit
This commit is contained in:
parent
349e0a2c41
commit
302ba10caa
@ -56,7 +56,4 @@
|
|||||||
<HintPath>..\..\..\RGB.NET\bin\netstandard2.0\RGB.NET.Groups.dll</HintPath>
|
<HintPath>..\..\..\RGB.NET\bin\netstandard2.0\RGB.NET.Groups.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Attributes\" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Artemis.Core.Utilities;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Models.Profile.LayerProperties.Abstract
|
||||||
|
{
|
||||||
|
public abstract class LayerProperty<T>
|
||||||
|
{
|
||||||
|
private List<LayerPropertyKeyFrame<T>> _keyframes;
|
||||||
|
|
||||||
|
protected LayerProperty()
|
||||||
|
{
|
||||||
|
_keyframes = new List<LayerPropertyKeyFrame<T>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T BaseValue { get; set; }
|
||||||
|
public T CurrentValue { get; set; }
|
||||||
|
public IReadOnlyList<LayerPropertyKeyFrame<T>> Keyframes => _keyframes.AsReadOnly();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The total progress on the timeline
|
||||||
|
/// </summary>
|
||||||
|
public TimeSpan TimelineProgress { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current keyframe in the timeline
|
||||||
|
/// </summary>
|
||||||
|
public LayerPropertyKeyFrame<T> CurrentKeyframe { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The next keyframe in the timeline
|
||||||
|
/// </summary>
|
||||||
|
public LayerPropertyKeyFrame<T> NextKeyframe { get; protected set; }
|
||||||
|
|
||||||
|
public void Update(double deltaTime)
|
||||||
|
{
|
||||||
|
float keyframeProgress;
|
||||||
|
float keyframeProgressEased;
|
||||||
|
|
||||||
|
TimelineProgress = TimelineProgress.Add(TimeSpan.FromSeconds(deltaTime));
|
||||||
|
// The current keyframe is the last keyframe before the current time
|
||||||
|
CurrentKeyframe = _keyframes.LastOrDefault(k => k.Position <= TimelineProgress);
|
||||||
|
// The next keyframe is the first keyframe that's after the current time
|
||||||
|
NextKeyframe = _keyframes.FirstOrDefault(k => k.Position > TimelineProgress);
|
||||||
|
|
||||||
|
if (CurrentKeyframe == null)
|
||||||
|
{
|
||||||
|
keyframeProgress = 0;
|
||||||
|
keyframeProgressEased = 0;
|
||||||
|
}
|
||||||
|
else if (NextKeyframe == null)
|
||||||
|
{
|
||||||
|
keyframeProgress = 1;
|
||||||
|
keyframeProgressEased = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var timeDiff = NextKeyframe.Position - CurrentKeyframe.Position;
|
||||||
|
keyframeProgress = (float) ((TimelineProgress - CurrentKeyframe.Position).TotalMilliseconds / timeDiff.TotalMilliseconds);
|
||||||
|
keyframeProgressEased = (float) Easings.Interpolate(keyframeProgress, CurrentKeyframe.EasingFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateCurrentValue(keyframeProgress, keyframeProgressEased);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased);
|
||||||
|
|
||||||
|
public void OverrideProgress(TimeSpan progress)
|
||||||
|
{
|
||||||
|
TimelineProgress = TimeSpan.Zero;
|
||||||
|
Update(progress.TotalSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void SortKeyframes()
|
||||||
|
{
|
||||||
|
_keyframes = _keyframes.OrderBy(k => k.Position).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Models.Profile.LayerProperties.Attributes
|
||||||
|
{
|
||||||
|
public class PropertyDescriptionAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Core.Exceptions;
|
using Artemis.Core.Exceptions;
|
||||||
using Artemis.Core.Models.Profile.KeyframeEngines;
|
using Artemis.Core.Models.Profile.KeyframeEngines;
|
||||||
|
using Artemis.Core.Models.Profile.LayerProperties.Abstract;
|
||||||
using Artemis.Core.Plugins.Models;
|
using Artemis.Core.Plugins.Models;
|
||||||
using Artemis.Core.Utilities;
|
using Artemis.Core.Utilities;
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
@ -28,7 +29,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
|||||||
CanUseKeyframes = true;
|
CanUseKeyframes = true;
|
||||||
InputStepSize = 1;
|
InputStepSize = 1;
|
||||||
|
|
||||||
// This can only be null if accessed internally
|
// This can only be null if accessed internally, all public ways of creating enforce a plugin info
|
||||||
if (PluginInfo == null)
|
if (PluginInfo == null)
|
||||||
PluginInfo = Constants.CorePluginInfo;
|
PluginInfo = Constants.CorePluginInfo;
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
using Artemis.Core.Models.Profile.LayerProperties.Abstract;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||||
|
{
|
||||||
|
public class FloatLayerProperty : LayerProperty<float>
|
||||||
|
{
|
||||||
|
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
|
||||||
|
{
|
||||||
|
var diff = NextKeyframe.Value - CurrentKeyframe.Value;
|
||||||
|
CurrentValue = CurrentKeyframe.Value + diff * keyframeProgressEased;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using Artemis.Core.Models.Profile.LayerProperties.Abstract;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||||
|
{
|
||||||
|
public class IntLayerProperty : LayerProperty<int>
|
||||||
|
{
|
||||||
|
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
|
||||||
|
{
|
||||||
|
var diff = NextKeyframe.Value - CurrentKeyframe.Value;
|
||||||
|
CurrentValue = (int) Math.Round(CurrentKeyframe.Value + diff * keyframeProgressEased, MidpointRounding.AwayFromZero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using Artemis.Core.Utilities;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||||
|
{
|
||||||
|
public class LayerPropertyKeyFrame<T>
|
||||||
|
{
|
||||||
|
private TimeSpan _position;
|
||||||
|
|
||||||
|
public LayerPropertyKeyFrame(LayerProperty<T> layerProperty, T value, TimeSpan position, Easings.Functions easingFunction)
|
||||||
|
{
|
||||||
|
_position = position;
|
||||||
|
Value = value;
|
||||||
|
LayerProperty = layerProperty;
|
||||||
|
EasingFunction = easingFunction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LayerProperty<T> LayerProperty { get; set; }
|
||||||
|
public T Value { get; set; }
|
||||||
|
|
||||||
|
public TimeSpan Position
|
||||||
|
{
|
||||||
|
get => _position;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_position = value;
|
||||||
|
LayerProperty.SortKeyframes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Easings.Functions EasingFunction { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using Artemis.Core.Models.Profile.LayerProperties.Abstract;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||||
|
{
|
||||||
|
public class SKColorLayerProperty : LayerProperty<SKColor>
|
||||||
|
{
|
||||||
|
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
|
||||||
|
{
|
||||||
|
var redDiff = NextKeyframe.Value.Red - CurrentKeyframe.Value.Red;
|
||||||
|
var greenDiff = NextKeyframe.Value.Green - CurrentKeyframe.Value.Green;
|
||||||
|
var blueDiff = NextKeyframe.Value.Blue - CurrentKeyframe.Value.Blue;
|
||||||
|
var alphaDiff = NextKeyframe.Value.Alpha - CurrentKeyframe.Value.Alpha;
|
||||||
|
|
||||||
|
CurrentValue = new SKColor(
|
||||||
|
ClampToByte(CurrentKeyframe.Value.Red + redDiff * keyframeProgressEased),
|
||||||
|
ClampToByte(CurrentKeyframe.Value.Green + greenDiff * keyframeProgressEased),
|
||||||
|
ClampToByte(CurrentKeyframe.Value.Blue + blueDiff * keyframeProgressEased),
|
||||||
|
ClampToByte(CurrentKeyframe.Value.Alpha + alphaDiff * keyframeProgressEased)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte ClampToByte(float value)
|
||||||
|
{
|
||||||
|
return (byte) Math.Max(0, Math.Min(255, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
using Artemis.Core.Models.Profile.LayerProperties.Abstract;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||||
|
{
|
||||||
|
public class SKPointLayerProperty : LayerProperty<SKPoint>
|
||||||
|
{
|
||||||
|
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
|
||||||
|
{
|
||||||
|
var xDiff = NextKeyframe.Value.X - CurrentKeyframe.Value.X;
|
||||||
|
var yDiff = NextKeyframe.Value.Y - CurrentKeyframe.Value.Y;
|
||||||
|
CurrentValue = new SKPoint(CurrentKeyframe.Value.X + xDiff * keyframeProgressEased, CurrentKeyframe.Value.Y + yDiff * keyframeProgressEased);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
using Artemis.Core.Models.Profile.LayerProperties.Abstract;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||||
|
{
|
||||||
|
public class SKSizeLayerProperty : LayerProperty<SKSize>
|
||||||
|
{
|
||||||
|
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
|
||||||
|
{
|
||||||
|
var widthDiff = NextKeyframe.Value.Width - CurrentKeyframe.Value.Width;
|
||||||
|
var heightDiff = NextKeyframe.Value.Height - CurrentKeyframe.Value.Height;
|
||||||
|
CurrentValue = new SKSize(CurrentKeyframe.Value.Width + widthDiff * keyframeProgressEased, CurrentKeyframe.Value.Height + heightDiff * keyframeProgressEased);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user