2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-06-19 15:01:33 +08:00
|
|
|
|
using System;
|
2019-08-07 21:59:35 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
2017-05-22 09:12:33 +08:00
|
|
|
|
namespace osu.Game.Beatmaps.Timing
|
2017-05-17 17:42:48 +08:00
|
|
|
|
{
|
2024-06-19 15:01:33 +08:00
|
|
|
|
public readonly struct BreakPeriod : IEquatable<BreakPeriod>
|
2017-05-17 17:42:48 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The minimum duration required for a break to have any effect.
|
|
|
|
|
/// </summary>
|
2017-09-16 00:39:55 +08:00
|
|
|
|
public const double MIN_BREAK_DURATION = 650;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-22 09:12:33 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The break start time.
|
|
|
|
|
/// </summary>
|
2024-06-19 15:01:33 +08:00
|
|
|
|
public double StartTime { get; init; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-17 17:42:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The break end time.
|
|
|
|
|
/// </summary>
|
2024-06-19 15:01:33 +08:00
|
|
|
|
public double EndTime { get; init; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-17 17:42:48 +08:00
|
|
|
|
/// <summary>
|
2017-05-22 09:12:33 +08:00
|
|
|
|
/// The break duration.
|
2017-05-17 17:42:48 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public double Duration => EndTime - StartTime;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-17 17:42:48 +08:00
|
|
|
|
/// <summary>
|
2020-10-12 14:28:16 +08:00
|
|
|
|
/// Whether the break has any effect.
|
2017-05-17 17:42:48 +08:00
|
|
|
|
/// </summary>
|
2017-09-16 00:39:55 +08:00
|
|
|
|
public bool HasEffect => Duration >= MIN_BREAK_DURATION;
|
2019-05-12 15:25:25 +08:00
|
|
|
|
|
2020-04-06 02:29:03 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a new break period.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="startTime">The start time of the break period.</param>
|
|
|
|
|
/// <param name="endTime">The end time of the break period.</param>
|
|
|
|
|
public BreakPeriod(double startTime, double endTime)
|
|
|
|
|
{
|
|
|
|
|
StartTime = startTime;
|
|
|
|
|
EndTime = endTime;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-12 15:25:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether this break contains a specified time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="time">The time to check in milliseconds.</param>
|
|
|
|
|
/// <returns>Whether the time falls within this <see cref="BreakPeriod"/>.</returns>
|
2019-08-07 21:59:35 +08:00
|
|
|
|
public bool Contains(double time) => time >= StartTime && time <= EndTime - BreakOverlay.BREAK_FADE_DURATION;
|
2024-06-19 15:01:33 +08:00
|
|
|
|
|
|
|
|
|
public bool Equals(BreakPeriod other) => StartTime.Equals(other.StartTime) && EndTime.Equals(other.EndTime);
|
|
|
|
|
public override bool Equals(object? obj) => obj is BreakPeriod other && Equals(other);
|
|
|
|
|
public override int GetHashCode() => HashCode.Combine(StartTime, EndTime);
|
2017-05-17 17:42:48 +08:00
|
|
|
|
}
|
2018-01-05 19:21:19 +08:00
|
|
|
|
}
|