2024-03-07 00:39:28 +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.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Storyboards.Commands
|
|
|
|
|
{
|
|
|
|
|
public class StoryboardLoopingGroup : StoryboardCommandGroup
|
|
|
|
|
{
|
2024-03-08 06:58:58 +08:00
|
|
|
|
private readonly double loopStartTime;
|
2024-03-07 00:39:28 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The total number of times this loop is played back. Always greater than zero.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly int TotalIterations;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new command loop.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="startTime">The start time of the loop.</param>
|
|
|
|
|
/// <param name="repeatCount">The number of times the loop should repeat. Should be greater than zero. Zero means a single playback.</param>
|
|
|
|
|
public StoryboardLoopingGroup(double startTime, int repeatCount)
|
|
|
|
|
{
|
2024-05-02 05:31:48 +08:00
|
|
|
|
ArgumentOutOfRangeException.ThrowIfNegative(repeatCount);
|
2024-03-07 00:39:28 +08:00
|
|
|
|
|
2024-03-08 06:58:58 +08:00
|
|
|
|
loopStartTime = startTime;
|
2024-03-07 00:39:28 +08:00
|
|
|
|
TotalIterations = repeatCount + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AddCommand<T>(ICollection<StoryboardCommand<T>> list, StoryboardCommand<T> command)
|
2024-03-08 06:58:58 +08:00
|
|
|
|
=> base.AddCommand(list, new StoryboardLoopingCommand<T>(command, this));
|
2024-03-07 00:39:28 +08:00
|
|
|
|
|
2024-03-08 06:58:58 +08:00
|
|
|
|
public override string ToString() => $"{loopStartTime} x{TotalIterations}";
|
2024-03-07 00:39:28 +08:00
|
|
|
|
|
|
|
|
|
private class StoryboardLoopingCommand<T> : StoryboardCommand<T>
|
|
|
|
|
{
|
|
|
|
|
private readonly StoryboardCommand<T> command;
|
2024-03-08 06:58:58 +08:00
|
|
|
|
private readonly StoryboardLoopingGroup loopingGroup;
|
2024-03-07 00:39:28 +08:00
|
|
|
|
|
2024-03-08 06:58:58 +08:00
|
|
|
|
public StoryboardLoopingCommand(StoryboardCommand<T> command, StoryboardLoopingGroup loopingGroup)
|
2024-03-07 00:39:28 +08:00
|
|
|
|
// In an ideal world, we would multiply the command duration by TotalIterations in command end time.
|
|
|
|
|
// Unfortunately this would clash with how stable handled end times, and results in some storyboards playing outro
|
|
|
|
|
// sequences for minutes or hours.
|
2024-03-09 02:33:46 +08:00
|
|
|
|
: base(command.Easing, loopingGroup.loopStartTime + command.StartTime, loopingGroup.loopStartTime + command.EndTime, command.StartValue, command.EndValue)
|
2024-03-07 00:39:28 +08:00
|
|
|
|
{
|
|
|
|
|
this.command = command;
|
2024-03-08 06:58:58 +08:00
|
|
|
|
this.loopingGroup = loopingGroup;
|
2024-03-07 00:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 06:58:58 +08:00
|
|
|
|
public override string PropertyName => command.PropertyName;
|
|
|
|
|
|
2024-03-08 08:06:49 +08:00
|
|
|
|
public override void ApplyInitialValue<TDrawable>(TDrawable d) => command.ApplyInitialValue(d);
|
2024-03-07 00:39:28 +08:00
|
|
|
|
|
2024-03-08 08:06:49 +08:00
|
|
|
|
public override TransformSequence<TDrawable> ApplyTransforms<TDrawable>(TDrawable d)
|
2024-03-07 00:39:28 +08:00
|
|
|
|
{
|
2024-03-08 06:58:58 +08:00
|
|
|
|
if (loopingGroup.TotalIterations == 0)
|
|
|
|
|
return command.ApplyTransforms(d);
|
2024-03-07 00:39:28 +08:00
|
|
|
|
|
2024-03-08 06:58:58 +08:00
|
|
|
|
double loopingGroupDuration = loopingGroup.Duration;
|
|
|
|
|
return command.ApplyTransforms(d).Loop(loopingGroupDuration - Duration, loopingGroup.TotalIterations);
|
2024-03-07 00:39:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|