2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-09-08 05:55:05 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-09-09 17:00:58 +08:00
|
|
|
|
using System;
|
2017-09-08 05:55:05 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 05:55:05 +08:00
|
|
|
|
namespace osu.Game.Storyboards
|
|
|
|
|
{
|
2017-09-08 19:04:53 +08:00
|
|
|
|
public class CommandTimeline<T> : ICommandTimeline
|
2017-09-08 05:55:05 +08:00
|
|
|
|
{
|
2017-09-08 18:11:57 +08:00
|
|
|
|
private readonly List<TypedCommand> commands = new List<TypedCommand>();
|
2019-12-18 22:59:48 +08:00
|
|
|
|
|
2017-09-08 18:11:57 +08:00
|
|
|
|
public IEnumerable<TypedCommand> Commands => commands.OrderBy(c => c.StartTime);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-18 22:59:48 +08:00
|
|
|
|
public bool HasCommands => commands.Count > 0;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-18 22:59:48 +08:00
|
|
|
|
public double StartTime { get; private set; } = double.MaxValue;
|
|
|
|
|
public double EndTime { get; private set; } = double.MinValue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-18 22:59:48 +08:00
|
|
|
|
public T StartValue { get; private set; }
|
|
|
|
|
public T EndValue { get; private set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 05:55:05 +08:00
|
|
|
|
public void Add(Easing easing, double startTime, double endTime, T startValue, T endValue)
|
|
|
|
|
{
|
|
|
|
|
if (endTime < startTime)
|
2022-10-10 15:51:50 +08:00
|
|
|
|
{
|
2022-11-07 11:25:36 +08:00
|
|
|
|
endTime = startTime;
|
2022-10-10 15:51:50 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-18 22:59:48 +08:00
|
|
|
|
commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue });
|
|
|
|
|
|
|
|
|
|
if (startTime < StartTime)
|
|
|
|
|
{
|
|
|
|
|
StartValue = startValue;
|
|
|
|
|
StartTime = startTime;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-18 22:59:48 +08:00
|
|
|
|
if (endTime > EndTime)
|
|
|
|
|
{
|
|
|
|
|
EndValue = endValue;
|
|
|
|
|
EndTime = endTime;
|
|
|
|
|
}
|
2017-09-08 05:55:05 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 05:55:05 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
=> $"{commands.Count} command(s)";
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 19:04:53 +08:00
|
|
|
|
public class TypedCommand : ICommand
|
2017-09-08 05:55:05 +08:00
|
|
|
|
{
|
2017-09-08 18:11:57 +08:00
|
|
|
|
public Easing Easing { get; set; }
|
|
|
|
|
public double StartTime { get; set; }
|
|
|
|
|
public double EndTime { get; set; }
|
|
|
|
|
public double Duration => EndTime - StartTime;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 05:55:05 +08:00
|
|
|
|
public T StartValue;
|
|
|
|
|
public T EndValue;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-09 17:00:58 +08:00
|
|
|
|
public int CompareTo(ICommand other)
|
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
|
int result = StartTime.CompareTo(other.StartTime);
|
2017-09-09 17:00:58 +08:00
|
|
|
|
if (result != 0) return result;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2017-09-09 17:00:58 +08:00
|
|
|
|
return EndTime.CompareTo(other.EndTime);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 05:55:05 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
=> $"{StartTime} -> {EndTime}, {StartValue} -> {EndValue} {Easing}";
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 19:04:53 +08:00
|
|
|
|
public interface ICommandTimeline
|
2017-09-08 05:55:05 +08:00
|
|
|
|
{
|
|
|
|
|
double StartTime { get; }
|
|
|
|
|
double EndTime { get; }
|
|
|
|
|
bool HasCommands { get; }
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-09 17:00:58 +08:00
|
|
|
|
public interface ICommand : IComparable<ICommand>
|
2017-09-08 18:11:57 +08:00
|
|
|
|
{
|
|
|
|
|
Easing Easing { get; set; }
|
|
|
|
|
double StartTime { get; set; }
|
|
|
|
|
double EndTime { get; set; }
|
|
|
|
|
double Duration { get; }
|
|
|
|
|
}
|
2017-09-08 05:55:05 +08:00
|
|
|
|
}
|