// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using osu.Framework.Graphics; using osu.Framework.Lists; using osuTK; using osuTK.Graphics; namespace osu.Game.Storyboards.Commands { public class StoryboardCommandGroup { public SortedList> X; public SortedList> Y; public SortedList> Scale; public SortedList> VectorScale; public SortedList> Rotation; public SortedList> Colour; public SortedList> Alpha; public SortedList> BlendingParameters; public SortedList> FlipH; public SortedList> FlipV; private readonly IReadOnlyList[] lists; /// /// Returns the earliest start time of the commands added to this group. /// [JsonIgnore] public double StartTime { get; private set; } = double.MaxValue; /// /// Returns the latest end time of the commands added to this group. /// [JsonIgnore] public double EndTime { get; private set; } = double.MinValue; [JsonIgnore] public double Duration => EndTime - StartTime; [JsonIgnore] public bool HasCommands { get; private set; } public StoryboardCommandGroup() { lists = new IReadOnlyList[] { X = new SortedList>(), Y = new SortedList>(), Scale = new SortedList>(), VectorScale = new SortedList>(), Rotation = new SortedList>(), Colour = new SortedList>(), Alpha = new SortedList>(), BlendingParameters = new SortedList>(), FlipH = new SortedList>(), FlipV = new SortedList>() }; } /// /// Returns all commands contained by this group unsorted. /// public virtual IEnumerable GetAllCommands() => lists.SelectMany(l => l); public void AddX(double startTime, double endTime, float startValue, float endValue, Easing easing) => AddCommand(X, new StoryboardXCommand(startTime, endTime, startValue, endValue, easing)); public void AddY(double startTime, double endTime, float startValue, float endValue, Easing easing) => AddCommand(Y, new StoryboardYCommand(startTime, endTime, startValue, endValue, easing)); public void AddScale(double startTime, double endTime, float startValue, float endValue, Easing easing) => AddCommand(Scale, new StoryboardScaleCommand(startTime, endTime, startValue, endValue, easing)); public void AddVectorScale(double startTime, double endTime, Vector2 startValue, Vector2 endValue, Easing easing) => AddCommand(VectorScale, new StoryboardVectorScaleCommand(startTime, endTime, startValue, endValue, easing)); public void AddRotation(double startTime, double endTime, float startValue, float endValue, Easing easing) => AddCommand(Rotation, new StoryboardRotationCommand(startTime, endTime, startValue, endValue, easing)); public void AddColour(double startTime, double endTime, Color4 startValue, Color4 endValue, Easing easing) => AddCommand(Colour, new StoryboardColourCommand(startTime, endTime, startValue, endValue, easing)); public void AddAlpha(double startTime, double endTime, float startValue, float endValue, Easing easing) => AddCommand(Alpha, new StoryboardAlphaCommand(startTime, endTime, startValue, endValue, easing)); public void AddBlendingParameters(double startTime, double endTime, BlendingParameters startValue, BlendingParameters endValue, Easing easing) => AddCommand(BlendingParameters, new StoryboardBlendingParametersCommand(startTime, endTime, startValue, endValue, easing)); public void AddFlipH(double startTime, double endTime, bool startValue, bool endValue, Easing easing) => AddCommand(FlipH, new StoryboardFlipHCommand(startTime, endTime, startValue, endValue, easing)); public void AddFlipV(double startTime, double endTime, bool startValue, bool endValue, Easing easing) => AddCommand(FlipV, new StoryboardFlipVCommand(startTime, endTime, startValue, endValue, easing)); /// /// Adds the given storyboard to the target . /// Can be overriden to apply custom effects to the given command before adding it to the list (e.g. looping or time offsets). /// /// The value type of the target property affected by this storyboard command. protected virtual void AddCommand(ICollection> list, StoryboardCommand command) { list.Add(command); HasCommands = true; if (command.StartTime < StartTime) StartTime = command.StartTime; if (command.EndTime > EndTime) EndTime = command.EndTime; } } }