Use GetEndTime() to get storyboard endtime

This commit is contained in:
Christine Chen 2021-04-17 15:27:22 -04:00
parent 7f5b1e84a1
commit e40cb6797d
3 changed files with 17 additions and 1 deletions

View File

@ -14,4 +14,17 @@ namespace osu.Game.Storyboards
Drawable CreateDrawable(); Drawable CreateDrawable();
} }
public static class StoryboardElementExtensions
{
/// <summary>
/// Returns the end time of this object.
/// </summary>
/// <remarks>
/// This returns the <see cref="IStoryboardElementHasDuration.EndTime"/> where available, falling back to <see cref="IStoryboardElement.StartTime"/> otherwise.
/// </remarks>
/// <param name="storyboardElement">The object.</param>
/// <returns>The end time of this object.</returns>
public static double GetEndTime(this IStoryboardElement storyboardElement) => (storyboardElement as IStoryboardElementHasDuration)?.EndTime ?? storyboardElement.StartTime;
}
} }

View File

@ -3,6 +3,9 @@
namespace osu.Game.Storyboards namespace osu.Game.Storyboards
{ {
/// <summary>
/// A StoryboardElement that ends at a different time than its start time.
/// </summary>
public interface IStoryboardElementHasDuration public interface IStoryboardElementHasDuration
{ {
double EndTime { get; } double EndTime { get; }

View File

@ -44,7 +44,7 @@ namespace osu.Game.Storyboards
/// This iterates all elements and as such should be used sparingly or stored locally. /// This iterates all elements and as such should be used sparingly or stored locally.
/// Videos and samples return StartTime as their EndTIme. /// Videos and samples return StartTime as their EndTIme.
/// </remarks> /// </remarks>
public double? LatestEventTime => Layers.SelectMany(l => l.Elements.OfType<IStoryboardElementHasDuration>()).OrderByDescending(e => e.EndTime).FirstOrDefault()?.EndTime; public double? LatestEventTime => Layers.SelectMany(l => l.Elements).OrderBy(e => e.GetEndTime()).LastOrDefault()?.GetEndTime();
/// <summary> /// <summary>
/// Depth of the currently front-most storyboard layer, excluding the overlay layer. /// Depth of the currently front-most storyboard layer, excluding the overlay layer.