1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 10:32:54 +08:00
osu-lazer/osu.Game/Storyboards/CommandTimelineGroup.cs

69 lines
2.9 KiB
C#
Raw Normal View History

2017-09-08 05:55:05 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
2017-09-09 21:34:26 +08:00
using osu.Framework.Graphics;
2017-09-08 05:55:05 +08:00
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Storyboards
{
2017-09-09 00:00:17 +08:00
public delegate CommandTimeline<T> CommandTimelineSelector<T>(CommandTimelineGroup commandTimelineGroup);
2017-09-08 05:55:05 +08:00
public class CommandTimelineGroup
{
public CommandTimeline<float> X = new CommandTimeline<float>();
public CommandTimeline<float> Y = new CommandTimeline<float>();
public CommandTimeline<Vector2> Scale = new CommandTimeline<Vector2>();
public CommandTimeline<float> Rotation = new CommandTimeline<float>();
public CommandTimeline<Color4> Colour = new CommandTimeline<Color4>();
public CommandTimeline<float> Alpha = new CommandTimeline<float>();
2017-09-09 21:34:26 +08:00
public CommandTimeline<BlendingMode> BlendingMode = new CommandTimeline<BlendingMode>();
2017-09-08 05:55:05 +08:00
public CommandTimeline<bool> FlipH = new CommandTimeline<bool>();
public CommandTimeline<bool> FlipV = new CommandTimeline<bool>();
2017-09-08 19:04:53 +08:00
public IEnumerable<ICommandTimeline> Timelines
2017-09-08 05:55:05 +08:00
{
get
{
yield return X;
yield return Y;
yield return Scale;
yield return Rotation;
yield return Colour;
yield return Alpha;
2017-09-09 21:34:26 +08:00
yield return BlendingMode;
2017-09-08 05:55:05 +08:00
yield return FlipH;
yield return FlipV;
}
}
2017-09-09 00:03:04 +08:00
public double CommandsStartTime => Timelines.Where(t => t.HasCommands).Min(t => t.StartTime);
public double CommandsEndTime => Timelines.Where(t => t.HasCommands).Max(t => t.EndTime);
public double CommandsDuration => CommandsEndTime - CommandsStartTime;
public virtual double StartTime => CommandsStartTime;
public virtual double EndTime => CommandsEndTime;
public double Duration => EndTime - StartTime;
2017-09-09 00:03:04 +08:00
2017-09-08 05:55:05 +08:00
public bool HasCommands => Timelines.Any(t => t.HasCommands);
2017-09-09 00:00:17 +08:00
public virtual IEnumerable<CommandTimeline<T>.TypedCommand> GetCommands<T>(CommandTimelineSelector<T> timelineSelector, double offset = 0)
2017-09-08 05:55:05 +08:00
{
2017-09-09 00:00:17 +08:00
if (offset != 0)
return timelineSelector(this).Commands.Select(command =>
new CommandTimeline<T>.TypedCommand
{
Easing = command.Easing,
StartTime = offset + command.StartTime,
EndTime = offset + command.EndTime,
StartValue = command.StartValue,
EndValue = command.EndValue,
});
2017-09-08 05:55:05 +08:00
2017-09-09 00:00:17 +08:00
return timelineSelector(this).Commands;
}
2017-09-08 05:55:05 +08:00
}
}