From 8b03acd27bdbdd6a997dbd70a00a7b4568e6b8bc Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 6 Mar 2024 00:05:56 +0300 Subject: [PATCH] Implement StoryboardElementWithDuration --- .../Formats/LegacyStoryboardDecoder.cs | 2 +- osu.Game/Storyboards/CommandLoop.cs | 1 + osu.Game/Storyboards/CommandTimeline.cs | 4 +- osu.Game/Storyboards/CommandTimelineGroup.cs | 9 +- .../Drawables/DrawableStoryboardAnimation.cs | 2 +- .../Drawables/DrawableStoryboardSprite.cs | 2 +- ...pable.cs => IDrawableStoryboardElement.cs} | 6 +- .../Storyboards/Drawables/IVectorScalable.cs | 13 - osu.Game/Storyboards/StoryboardAnimation.cs | 5 +- .../StoryboardElementWithDuration.cs | 261 +++++++++++++++ osu.Game/Storyboards/StoryboardSprite.cs | 297 +----------------- 11 files changed, 284 insertions(+), 318 deletions(-) rename osu.Game/Storyboards/Drawables/{IFlippable.cs => IDrawableStoryboardElement.cs} (54%) delete mode 100644 osu.Game/Storyboards/Drawables/IVectorScalable.cs create mode 100644 osu.Game/Storyboards/StoryboardElementWithDuration.cs diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index a9a4d9cc49..ba328b2dbd 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -17,7 +17,7 @@ namespace osu.Game.Beatmaps.Formats { public class LegacyStoryboardDecoder : LegacyDecoder { - private StoryboardSprite? storyboardSprite; + private StoryboardElementWithDuration? storyboardSprite; private CommandTimelineGroup? timelineGroup; private Storyboard storyboard = null!; diff --git a/osu.Game/Storyboards/CommandLoop.cs b/osu.Game/Storyboards/CommandLoop.cs index a912daea44..6dd782cb7f 100644 --- a/osu.Game/Storyboards/CommandLoop.cs +++ b/osu.Game/Storyboards/CommandLoop.cs @@ -50,6 +50,7 @@ namespace osu.Game.Storyboards StartValue = command.StartValue, EndValue = command.EndValue, PropertyName = command.PropertyName, + IsParameterCommand = command.IsParameterCommand, LoopCount = TotalIterations, Delay = fullLoopDuration - command.EndTime + command.StartTime }; diff --git a/osu.Game/Storyboards/CommandTimeline.cs b/osu.Game/Storyboards/CommandTimeline.cs index ce25bfe25b..4ad31d88c2 100644 --- a/osu.Game/Storyboards/CommandTimeline.cs +++ b/osu.Game/Storyboards/CommandTimeline.cs @@ -25,6 +25,7 @@ namespace osu.Game.Storyboards public T EndValue { get; private set; } public string PropertyName { get; } + public bool IsParameterTimeline { get; set; } public CommandTimeline(string propertyName) { @@ -38,7 +39,7 @@ namespace osu.Game.Storyboards endTime = startTime; } - commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue, PropertyName = PropertyName }); + commands.Add(new TypedCommand { Easing = easing, StartTime = startTime, EndTime = endTime, StartValue = startValue, EndValue = endValue, PropertyName = PropertyName, IsParameterCommand = IsParameterTimeline }); if (startTime < StartTime) { @@ -65,6 +66,7 @@ namespace osu.Game.Storyboards public string PropertyName { get; set; } public int LoopCount { get; set; } public double Delay { get; set; } + public bool IsParameterCommand { get; set; } public T StartValue; public T EndValue; diff --git a/osu.Game/Storyboards/CommandTimelineGroup.cs b/osu.Game/Storyboards/CommandTimelineGroup.cs index cb795e0ffe..0362925619 100644 --- a/osu.Game/Storyboards/CommandTimelineGroup.cs +++ b/osu.Game/Storyboards/CommandTimelineGroup.cs @@ -22,9 +22,9 @@ namespace osu.Game.Storyboards public CommandTimeline Rotation = new CommandTimeline("Rotation"); public CommandTimeline Colour = new CommandTimeline("Colour"); public CommandTimeline Alpha = new CommandTimeline("Alpha"); - public CommandTimeline BlendingParameters = new CommandTimeline("Blending"); - public CommandTimeline FlipH = new CommandTimeline("FlipH"); - public CommandTimeline FlipV = new CommandTimeline("FlipV"); + public CommandTimeline BlendingParameters = new CommandTimeline("Blending") { IsParameterTimeline = true }; + public CommandTimeline FlipH = new CommandTimeline("FlipH") { IsParameterTimeline = true }; + public CommandTimeline FlipV = new CommandTimeline("FlipV") { IsParameterTimeline = true }; private readonly ICommandTimeline[] timelines; @@ -109,7 +109,8 @@ namespace osu.Game.Storyboards EndTime = offset + command.EndTime, StartValue = command.StartValue, EndValue = command.EndValue, - PropertyName = command.PropertyName + PropertyName = command.PropertyName, + IsParameterCommand = command.IsParameterCommand }); } diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs index fae9ec7f2e..8e1a8ce949 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardAnimation.cs @@ -16,7 +16,7 @@ using osuTK; namespace osu.Game.Storyboards.Drawables { - public partial class DrawableStoryboardAnimation : TextureAnimation, IFlippable, IVectorScalable + public partial class DrawableStoryboardAnimation : TextureAnimation, IDrawableStoryboardElement { public StoryboardAnimation Animation { get; } diff --git a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs index ec875219b6..6772178e85 100644 --- a/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs +++ b/osu.Game/Storyboards/Drawables/DrawableStoryboardSprite.cs @@ -13,7 +13,7 @@ using osuTK; namespace osu.Game.Storyboards.Drawables { - public partial class DrawableStoryboardSprite : Sprite, IFlippable, IVectorScalable + public partial class DrawableStoryboardSprite : Sprite, IDrawableStoryboardElement { public StoryboardSprite Sprite { get; } diff --git a/osu.Game/Storyboards/Drawables/IFlippable.cs b/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs similarity index 54% rename from osu.Game/Storyboards/Drawables/IFlippable.cs rename to osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs index 2a931875ea..6652b5509c 100644 --- a/osu.Game/Storyboards/Drawables/IFlippable.cs +++ b/osu.Game/Storyboards/Drawables/IDrawableStoryboardElement.cs @@ -1,13 +1,15 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Graphics.Transforms; +using osuTK; namespace osu.Game.Storyboards.Drawables { - internal interface IFlippable : ITransformable + public interface IDrawableStoryboardElement : ITransformable { bool FlipH { get; set; } bool FlipV { get; set; } + Vector2 VectorScale { get; set; } } } diff --git a/osu.Game/Storyboards/Drawables/IVectorScalable.cs b/osu.Game/Storyboards/Drawables/IVectorScalable.cs deleted file mode 100644 index ab0452df80..0000000000 --- a/osu.Game/Storyboards/Drawables/IVectorScalable.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Graphics.Transforms; -using osuTK; - -namespace osu.Game.Storyboards.Drawables -{ - internal interface IVectorScalable : ITransformable - { - Vector2 VectorScale { get; set; } - } -} diff --git a/osu.Game/Storyboards/StoryboardAnimation.cs b/osu.Game/Storyboards/StoryboardAnimation.cs index 1a4b6bb923..173acf7ff1 100644 --- a/osu.Game/Storyboards/StoryboardAnimation.cs +++ b/osu.Game/Storyboards/StoryboardAnimation.cs @@ -7,7 +7,7 @@ using osu.Game.Storyboards.Drawables; namespace osu.Game.Storyboards { - public class StoryboardAnimation : StoryboardSprite + public class StoryboardAnimation : StoryboardElementWithDuration { public int FrameCount; public double FrameDelay; @@ -21,8 +21,7 @@ namespace osu.Game.Storyboards LoopType = loopType; } - public override Drawable CreateDrawable() - => new DrawableStoryboardAnimation(this); + public override DrawableStoryboardAnimation CreateStoryboardDrawable() => new DrawableStoryboardAnimation(this); } public enum AnimationLoopType diff --git a/osu.Game/Storyboards/StoryboardElementWithDuration.cs b/osu.Game/Storyboards/StoryboardElementWithDuration.cs new file mode 100644 index 0000000000..0c89b40c36 --- /dev/null +++ b/osu.Game/Storyboards/StoryboardElementWithDuration.cs @@ -0,0 +1,261 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Graphics; +using osu.Game.Storyboards.Drawables; +using osuTK; + +namespace osu.Game.Storyboards +{ + public abstract class StoryboardElementWithDuration : IStoryboardElementWithDuration + { + protected readonly List Loops = new List(); + private readonly List triggers = new List(); + + public string Path { get; } + public bool IsDrawable => HasCommands; + + public Anchor Origin; + public Vector2 InitialPosition; + + public readonly CommandTimelineGroup TimelineGroup = new CommandTimelineGroup(); + + public double StartTime + { + get + { + // To get the initial start time, we need to check whether the first alpha command to exist (across all loops) has a StartValue of zero. + // A StartValue of zero governs, above all else, the first valid display time of a sprite. + // + // You can imagine that the first command of each type decides that type's start value, so if the initial alpha is zero, + // anything before that point can be ignored (the sprite is not visible after all). + var alphaCommands = new List<(double startTime, bool isZeroStartValue)>(); + + var command = TimelineGroup.Alpha.Commands.FirstOrDefault(); + if (command != null) alphaCommands.Add((command.StartTime, command.StartValue == 0)); + + foreach (var loop in Loops) + { + command = loop.Alpha.Commands.FirstOrDefault(); + if (command != null) alphaCommands.Add((command.StartTime + loop.LoopStartTime, command.StartValue == 0)); + } + + if (alphaCommands.Count > 0) + { + var firstAlpha = alphaCommands.MinBy(t => t.startTime); + + if (firstAlpha.isZeroStartValue) + return firstAlpha.startTime; + } + + return EarliestTransformTime; + } + } + + public double EarliestTransformTime + { + get + { + // If we got to this point, either no alpha commands were present, or the earliest had a non-zero start value. + // The sprite's StartTime will be determined by the earliest command, regardless of type. + double earliestStartTime = TimelineGroup.StartTime; + foreach (var l in Loops) + earliestStartTime = Math.Min(earliestStartTime, l.StartTime); + return earliestStartTime; + } + } + + public double EndTime + { + get + { + double latestEndTime = TimelineGroup.EndTime; + + foreach (var l in Loops) + latestEndTime = Math.Max(latestEndTime, l.EndTime); + + return latestEndTime; + } + } + + public double EndTimeForDisplay + { + get + { + double latestEndTime = TimelineGroup.EndTime; + + foreach (var l in Loops) + latestEndTime = Math.Max(latestEndTime, l.StartTime + l.CommandsDuration * l.TotalIterations); + + return latestEndTime; + } + } + + public bool HasCommands => TimelineGroup.HasCommands || Loops.Any(l => l.HasCommands); + + protected StoryboardElementWithDuration(string path, Anchor origin, Vector2 initialPosition) + { + Path = path; + Origin = origin; + InitialPosition = initialPosition; + } + + public abstract Drawable CreateDrawable(); + + public CommandLoop AddLoop(double startTime, int repeatCount) + { + var loop = new CommandLoop(startTime, repeatCount); + Loops.Add(loop); + return loop; + } + + public CommandTrigger AddTrigger(string triggerName, double startTime, double endTime, int groupNumber) + { + var trigger = new CommandTrigger(triggerName, startTime, endTime, groupNumber); + triggers.Add(trigger); + return trigger; + } + + protected IEnumerable.TypedCommand> GetCommands(CommandTimelineSelector timelineSelector, IEnumerable>? triggeredGroups) + { + var commands = TimelineGroup.GetCommands(timelineSelector); + foreach (var loop in Loops) + commands = commands.Concat(loop.GetCommands(timelineSelector)); + + if (triggeredGroups != null) + { + foreach (var pair in triggeredGroups) + commands = commands.Concat(pair.Item1.GetCommands(timelineSelector, pair.Item2)); + } + + return commands; + } + + public override string ToString() + => $"{Path}, {Origin}, {InitialPosition}"; + } + + public abstract class StoryboardElementWithDuration : StoryboardElementWithDuration + where U : Drawable, IDrawableStoryboardElement + { + private delegate void DrawablePropertyInitializer(U drawable, T value); + + protected StoryboardElementWithDuration(string path, Anchor origin, Vector2 initialPosition) + : base(path, origin, initialPosition) + { + } + + public override Drawable CreateDrawable() => CreateStoryboardDrawable(); + + public abstract U CreateStoryboardDrawable(); + + public void ApplyTransforms(U drawable, IEnumerable>? triggeredGroups = null) + { + // For performance reasons, we need to apply the commands in order by start time. Not doing so will cause many functions to be interleaved, resulting in O(n^2) complexity. + // To achieve this, commands are "generated" as pairs of (command, initFunc, transformFunc) and batched into a contiguous list + // The list is then stably-sorted (to preserve command order), and applied to the drawable sequentially. + + List> generated = new List>(); + + generateCommands(generated, GetCommands(g => g.X, triggeredGroups), (d, value) => d.X = value); + generateCommands(generated, GetCommands(g => g.Y, triggeredGroups), (d, value) => d.Y = value); + generateCommands(generated, GetCommands(g => g.Scale, triggeredGroups), (d, value) => d.Scale = value); + generateCommands(generated, GetCommands(g => g.Rotation, triggeredGroups), (d, value) => d.Rotation = value); + generateCommands(generated, GetCommands(g => g.Colour, triggeredGroups), (d, value) => d.Colour = value); + generateCommands(generated, GetCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value); + generateCommands(generated, GetCommands(g => g.BlendingParameters, triggeredGroups), (d, value) => d.Blending = value, false); + generateCommands(generated, GetCommands(g => g.VectorScale, triggeredGroups), (d, value) => d.VectorScale = value); + generateCommands(generated, GetCommands(g => g.FlipH, triggeredGroups), (d, value) => d.FlipH = value, false); + generateCommands(generated, GetCommands(g => g.FlipV, triggeredGroups), (d, value) => d.FlipV = value, false); + + foreach (var command in generated.OrderBy(g => g.StartTime)) + command.ApplyTo(drawable); + } + + private void generateCommands(List> resultList, IEnumerable.TypedCommand> commands, + DrawablePropertyInitializer initializeProperty, bool alwaysInitialize = true) + { + bool initialized = false; + + foreach (var command in commands) + { + DrawablePropertyInitializer? initFunc = null; + + if (!initialized) + { + if (alwaysInitialize || command.StartTime == command.EndTime) + initFunc = initializeProperty; + initialized = true; + } + + resultList.Add(new GeneratedCommand(command, initFunc)); + } + } + + private interface IGeneratedCommand + where TDrawable : U + { + double StartTime { get; } + + void ApplyTo(TDrawable drawable); + } + + private readonly struct GeneratedCommand : IGeneratedCommand + where TDrawable : U + { + public double StartTime => command.StartTime; + + private readonly DrawablePropertyInitializer? initializeProperty; + private readonly CommandTimeline.TypedCommand command; + + public GeneratedCommand(CommandTimeline.TypedCommand command, DrawablePropertyInitializer? initializeProperty) + { + this.command = command; + this.initializeProperty = initializeProperty; + } + + public void ApplyTo(TDrawable drawable) + { + initializeProperty?.Invoke(drawable, command.StartValue); + + using (drawable.BeginAbsoluteSequence(command.StartTime)) + transform(drawable); + } + + private void transform(TDrawable drawable) + { + if (command.IsParameterCommand) + { + if (command.LoopCount == 0) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) + .TransformTo(command.PropertyName, command.EndValue); + } + else + { + drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) + .TransformTo(command.PropertyName, command.EndValue) + .Loop(command.Delay, command.LoopCount); + } + } + else + { + if (command.LoopCount == 0) + { + drawable.TransformTo(command.PropertyName, command.StartValue).Then() + .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); + } + else + { + drawable.TransformTo(command.PropertyName, command.StartValue).Then() + .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing) + .Loop(command.Delay, command.LoopCount); + } + } + } + } + } +} diff --git a/osu.Game/Storyboards/StoryboardSprite.cs b/osu.Game/Storyboards/StoryboardSprite.cs index 2c04e4c983..69994f77a4 100644 --- a/osu.Game/Storyboards/StoryboardSprite.cs +++ b/osu.Game/Storyboards/StoryboardSprite.cs @@ -1,308 +1,21 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; -using System.Collections.Generic; -using System.Linq; using osu.Framework.Graphics; using osu.Game.Storyboards.Drawables; using osuTK; namespace osu.Game.Storyboards { - public class StoryboardSprite : IStoryboardElementWithDuration + public class StoryboardSprite : StoryboardElementWithDuration { - private readonly List loops = new List(); - private readonly List triggers = new List(); - - public string Path { get; } - public bool IsDrawable => HasCommands; - - public Anchor Origin; - public Vector2 InitialPosition; - - public readonly CommandTimelineGroup TimelineGroup = new CommandTimelineGroup(); - - public double StartTime - { - get - { - // To get the initial start time, we need to check whether the first alpha command to exist (across all loops) has a StartValue of zero. - // A StartValue of zero governs, above all else, the first valid display time of a sprite. - // - // You can imagine that the first command of each type decides that type's start value, so if the initial alpha is zero, - // anything before that point can be ignored (the sprite is not visible after all). - var alphaCommands = new List<(double startTime, bool isZeroStartValue)>(); - - var command = TimelineGroup.Alpha.Commands.FirstOrDefault(); - if (command != null) alphaCommands.Add((command.StartTime, command.StartValue == 0)); - - foreach (var loop in loops) - { - command = loop.Alpha.Commands.FirstOrDefault(); - if (command != null) alphaCommands.Add((command.StartTime + loop.LoopStartTime, command.StartValue == 0)); - } - - if (alphaCommands.Count > 0) - { - var firstAlpha = alphaCommands.MinBy(t => t.startTime); - - if (firstAlpha.isZeroStartValue) - return firstAlpha.startTime; - } - - return EarliestTransformTime; - } - } - - public double EarliestTransformTime - { - get - { - // If we got to this point, either no alpha commands were present, or the earliest had a non-zero start value. - // The sprite's StartTime will be determined by the earliest command, regardless of type. - double earliestStartTime = TimelineGroup.StartTime; - foreach (var l in loops) - earliestStartTime = Math.Min(earliestStartTime, l.StartTime); - return earliestStartTime; - } - } - - public double EndTime - { - get - { - double latestEndTime = TimelineGroup.EndTime; - - foreach (var l in loops) - latestEndTime = Math.Max(latestEndTime, l.EndTime); - - return latestEndTime; - } - } - - public double EndTimeForDisplay - { - get - { - double latestEndTime = TimelineGroup.EndTime; - - foreach (var l in loops) - latestEndTime = Math.Max(latestEndTime, l.StartTime + l.CommandsDuration * l.TotalIterations); - - return latestEndTime; - } - } - - public bool HasCommands => TimelineGroup.HasCommands || loops.Any(l => l.HasCommands); - - private delegate void DrawablePropertyInitializer(Drawable drawable, T value); - public StoryboardSprite(string path, Anchor origin, Vector2 initialPosition) + : base(path, origin, initialPosition) { - Path = path; - Origin = origin; - InitialPosition = initialPosition; } - public CommandLoop AddLoop(double startTime, int repeatCount) - { - var loop = new CommandLoop(startTime, repeatCount); - loops.Add(loop); - return loop; - } - - public CommandTrigger AddTrigger(string triggerName, double startTime, double endTime, int groupNumber) - { - var trigger = new CommandTrigger(triggerName, startTime, endTime, groupNumber); - triggers.Add(trigger); - return trigger; - } - - public virtual Drawable CreateDrawable() - => new DrawableStoryboardSprite(this); - - public void ApplyTransforms(Drawable drawable, IEnumerable>? triggeredGroups = null) - { - // For performance reasons, we need to apply the commands in order by start time. Not doing so will cause many functions to be interleaved, resulting in O(n^2) complexity. - // To achieve this, commands are "generated" as pairs of (command, initFunc, transformFunc) and batched into a contiguous list - // The list is then stably-sorted (to preserve command order), and applied to the drawable sequentially. - - List generated = new List(); - - generateCommands(generated, getCommands(g => g.X, triggeredGroups), (d, value) => d.X = value); - generateCommands(generated, getCommands(g => g.Y, triggeredGroups), (d, value) => d.Y = value); - generateCommands(generated, getCommands(g => g.Scale, triggeredGroups), (d, value) => d.Scale = value); - generateCommands(generated, getCommands(g => g.Rotation, triggeredGroups), (d, value) => d.Rotation = value); - generateCommands(generated, getCommands(g => g.Colour, triggeredGroups), (d, value) => d.Colour = value); - generateCommands(generated, getCommands(g => g.Alpha, triggeredGroups), (d, value) => d.Alpha = value); - generateCommands(generated, getCommands(g => g.BlendingParameters, triggeredGroups), (d, value) => d.Blending = value, false); - - if (drawable is IVectorScalable vectorScalable) - { - generateCommands(generated, getCommands(g => g.VectorScale, triggeredGroups), (_, value) => vectorScalable.VectorScale = value); - } - - if (drawable is IFlippable flippable) - { - generateCommands(generated, getCommands(g => g.FlipH, triggeredGroups), (_, value) => flippable.FlipH = value, false); - generateCommands(generated, getCommands(g => g.FlipV, triggeredGroups), (_, value) => flippable.FlipV = value, false); - } - - foreach (var command in generated.OrderBy(g => g.StartTime)) - command.ApplyTo(drawable); - } - - private void generateCommands(List resultList, IEnumerable.TypedCommand> commands, - DrawablePropertyInitializer initializeProperty, bool alwaysInitialize = true) - { - bool initialized = false; - - foreach (var command in commands) - { - DrawablePropertyInitializer? initFunc = null; - - if (!initialized) - { - if (alwaysInitialize || command.StartTime == command.EndTime) - initFunc = initializeProperty; - initialized = true; - } - - resultList.Add(new GeneratedCommand(command, initFunc)); - } - } - - private IEnumerable.TypedCommand> getCommands(CommandTimelineSelector timelineSelector, IEnumerable>? triggeredGroups) - { - var commands = TimelineGroup.GetCommands(timelineSelector); - foreach (var loop in loops) - commands = commands.Concat(loop.GetCommands(timelineSelector)); - - if (triggeredGroups != null) - { - foreach (var pair in triggeredGroups) - commands = commands.Concat(pair.Item1.GetCommands(timelineSelector, pair.Item2)); - } - - return commands; - } - - public override string ToString() - => $"{Path}, {Origin}, {InitialPosition}"; - - private interface IGeneratedCommand - { - double StartTime { get; } - - void ApplyTo(Drawable drawable); - } - - private readonly struct GeneratedCommand : IGeneratedCommand - { - public double StartTime => command.StartTime; - - private readonly DrawablePropertyInitializer? initializeProperty; - private readonly CommandTimeline.TypedCommand command; - - public GeneratedCommand(CommandTimeline.TypedCommand command, DrawablePropertyInitializer? initializeProperty) - { - this.command = command; - this.initializeProperty = initializeProperty; - } - - public void ApplyTo(Drawable drawable) - { - initializeProperty?.Invoke(drawable, command.StartValue); - - switch (command.PropertyName) - { - case "VectorScale": - if (command.LoopCount == 0) - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - ((IVectorScalable)drawable).TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); - } - } - else - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - ((IVectorScalable)drawable).TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing) - .Loop(command.Delay, command.LoopCount); - } - } - - break; - - case "FlipH": - case "FlipV": - if (command.LoopCount == 0) - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue); - } - } - else - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - ((IFlippable)drawable).TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue) - .Loop(command.Delay, command.LoopCount); - } - } - - break; - - case "Blending": - if (command.LoopCount == 0) - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue); - } - } - else - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Delay(command.Duration) - .TransformTo(command.PropertyName, command.EndValue) - .Loop(command.Delay, command.LoopCount); - } - } - - break; - - default: - if (command.LoopCount == 0) - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing); - } - } - else - { - using (drawable.BeginAbsoluteSequence(command.StartTime)) - { - drawable.TransformTo(command.PropertyName, command.StartValue).Then() - .TransformTo(command.PropertyName, command.EndValue, command.Duration, command.Easing) - .Loop(command.Delay, command.LoopCount); - } - } - - break; - } - } - } + public override DrawableStoryboardSprite CreateStoryboardDrawable() => new DrawableStoryboardSprite(this); } } + +