1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-26 05:22:54 +08:00

Add helper method to get drain length (and rename some usages)

This commit is contained in:
Dean Herbert 2023-07-25 16:58:41 +09:00
parent 04c1333b59
commit 9cfe9164fa
4 changed files with 14 additions and 8 deletions

View File

@ -16,12 +16,12 @@ namespace osu.Game.Tests.Editing.Checks
{ {
public class CheckDrainTimeTest public class CheckDrainTimeTest
{ {
private CheckDrainTime check = null!; private CheckDrainLength check = null!;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
check = new CheckDrainTime(); check = new CheckDrainLength();
} }
[Test] [Test]
@ -40,7 +40,7 @@ namespace osu.Game.Tests.Editing.Checks
var issues = check.Run(context).ToList(); var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1)); Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckDrainTime.IssueTemplateTooShort); Assert.That(issues.Single().Template is CheckDrainLength.IssueTemplateTooShort);
} }
[Test] [Test]
@ -63,7 +63,7 @@ namespace osu.Game.Tests.Editing.Checks
var issues = check.Run(context).ToList(); var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1)); Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckDrainTime.IssueTemplateTooShort); Assert.That(issues.Single().Template is CheckDrainLength.IssueTemplateTooShort);
} }
[Test] [Test]

View File

@ -110,6 +110,11 @@ namespace osu.Game.Beatmaps
/// </remarks> /// </remarks>
public static double CalculatePlayableLength(this IBeatmap beatmap) => CalculatePlayableLength(beatmap.HitObjects); public static double CalculatePlayableLength(this IBeatmap beatmap) => CalculatePlayableLength(beatmap.HitObjects);
/// <summary>
/// Find the total milliseconds between the first and last hittable objects, excluding any break time.
/// </summary>
public static double CalculateDrainLength(this IBeatmap beatmap) => CalculatePlayableLength(beatmap.HitObjects) - beatmap.TotalBreakTime;
/// <summary> /// <summary>
/// Find the timestamps in milliseconds of the start and end of the playable region. /// Find the timestamps in milliseconds of the start and end of the playable region.
/// </summary> /// </summary>

View File

@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Edit
new CheckUnsnappedObjects(), new CheckUnsnappedObjects(),
new CheckConcurrentObjects(), new CheckConcurrentObjects(),
new CheckZeroLengthObjects(), new CheckZeroLengthObjects(),
new CheckDrainTime(), new CheckDrainLength(),
// Timing // Timing
new CheckPreviewTime(), new CheckPreviewTime(),

View File

@ -7,10 +7,11 @@ using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks namespace osu.Game.Rulesets.Edit.Checks
{ {
public class CheckDrainTime : ICheck public class CheckDrainLength : ICheck
{ {
private const int min_drain_threshold = 30 * 1000; private const int min_drain_threshold = 30 * 1000;
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Compose, "Too short drain time");
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Compose, "Drain length is too short");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[] public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{ {
@ -19,7 +20,7 @@ namespace osu.Game.Rulesets.Edit.Checks
public IEnumerable<Issue> Run(BeatmapVerifierContext context) public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{ {
double drainTime = context.Beatmap.CalculatePlayableLength() - context.Beatmap.TotalBreakTime; double drainTime = context.Beatmap.CalculateDrainLength();
if (drainTime < min_drain_threshold) if (drainTime < min_drain_threshold)
yield return new IssueTemplateTooShort(this).Create((int)(drainTime / 1000)); yield return new IssueTemplateTooShort(this).Create((int)(drainTime / 1000));