mirror of
https://github.com/osukey/osukey.git
synced 2025-08-02 14:17:06 +09:00
Storyboards implementation.
This commit is contained in:
61
osu.Game/Storyboards/CommandTimeline.cs
Normal file
61
osu.Game/Storyboards/CommandTimeline.cs
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Caching;
|
||||
using osu.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Storyboards
|
||||
{
|
||||
public class CommandTimeline<T> : CommandTimeline
|
||||
{
|
||||
private readonly List<Command> commands = new List<Command>();
|
||||
public IEnumerable<Command> Commands => commands.OrderBy(c => c.StartTime);
|
||||
public bool HasCommands => commands.Count > 0;
|
||||
|
||||
private Cached<double> startTimeBacking;
|
||||
public double StartTime => startTimeBacking.IsValid ? startTimeBacking : (startTimeBacking.Value = HasCommands ? commands.Min(c => c.StartTime) : double.MinValue);
|
||||
|
||||
private Cached<double> endTimeBacking;
|
||||
public double EndTime => endTimeBacking.IsValid ? endTimeBacking : (endTimeBacking.Value = HasCommands ? commands.Max(c => c.EndTime) : double.MaxValue);
|
||||
|
||||
public T StartValue => HasCommands ? commands.OrderBy(c => c.StartTime).First().StartValue : default(T);
|
||||
public T EndValue => HasCommands ? commands.OrderByDescending(c => c.EndTime).First().EndValue : default(T);
|
||||
|
||||
public void Add(Easing easing, double startTime, double endTime, T startValue, T endValue)
|
||||
{
|
||||
if (endTime < startTime)
|
||||
return;
|
||||
|
||||
commands.Add(new Command { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue, });
|
||||
|
||||
startTimeBacking.Invalidate();
|
||||
endTimeBacking.Invalidate();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
=> $"{commands.Count} command(s)";
|
||||
|
||||
public class Command
|
||||
{
|
||||
public Easing Easing;
|
||||
public double StartTime;
|
||||
public double EndTime;
|
||||
public T StartValue;
|
||||
public T EndValue;
|
||||
|
||||
public double Duration => EndTime - StartTime;
|
||||
|
||||
public override string ToString()
|
||||
=> $"{StartTime} -> {EndTime}, {StartValue} -> {EndValue} {Easing}";
|
||||
}
|
||||
}
|
||||
|
||||
public interface CommandTimeline
|
||||
{
|
||||
double StartTime { get; }
|
||||
double EndTime { get; }
|
||||
bool HasCommands { get; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user