1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 15:27:26 +08:00
osu-lazer/osu.Game/Storyboards/CommandLoop.cs

48 lines
1.8 KiB
C#
Raw Normal View History

// 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
2021-09-29 06:59:08 +08:00
using System;
2018-04-13 17:19:50 +08:00
using System.Collections.Generic;
namespace osu.Game.Storyboards
{
public class CommandLoop : CommandTimelineGroup
{
public double LoopStartTime;
/// <summary>
/// The total number of times this loop is played back. Always greater than zero.
/// </summary>
public readonly int TotalIterations;
2018-04-13 17:19:50 +08:00
public override double StartTime => LoopStartTime + CommandsStartTime;
public override double EndTime => StartTime + CommandsDuration * TotalIterations;
2018-04-13 17:19:50 +08:00
/// <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 CommandLoop(double startTime, int repeatCount)
2018-04-13 17:19:50 +08:00
{
if (repeatCount < 0) throw new ArgumentException("Repeat count must be zero or above.", nameof(repeatCount));
2018-04-13 17:19:50 +08:00
LoopStartTime = startTime;
TotalIterations = repeatCount + 1;
2018-04-13 17:19:50 +08:00
}
public override IEnumerable<CommandTimeline<T>.TypedCommand> GetCommands<T>(CommandTimelineSelector<T> timelineSelector, double offset = 0)
{
for (int loop = 0; loop < TotalIterations; loop++)
2018-04-13 17:19:50 +08:00
{
double loopOffset = LoopStartTime + loop * CommandsDuration;
2018-04-13 17:19:50 +08:00
foreach (var command in base.GetCommands(timelineSelector, offset + loopOffset))
yield return command;
}
}
public override string ToString()
=> $"{LoopStartTime} x{TotalIterations}";
2018-04-13 17:19:50 +08:00
}
}