1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +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
{
private CheckDrainTime check = null!;
private CheckDrainLength check = null!;
[SetUp]
public void Setup()
{
check = new CheckDrainTime();
check = new CheckDrainLength();
}
[Test]
@ -40,7 +40,7 @@ namespace osu.Game.Tests.Editing.Checks
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckDrainTime.IssueTemplateTooShort);
Assert.That(issues.Single().Template is CheckDrainLength.IssueTemplateTooShort);
}
[Test]
@ -63,7 +63,7 @@ namespace osu.Game.Tests.Editing.Checks
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckDrainTime.IssueTemplateTooShort);
Assert.That(issues.Single().Template is CheckDrainLength.IssueTemplateTooShort);
}
[Test]

View File

@ -110,6 +110,11 @@ namespace osu.Game.Beatmaps
/// </remarks>
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>
/// Find the timestamps in milliseconds of the start and end of the playable region.
/// </summary>

View File

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

View File

@ -7,10 +7,11 @@ using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckDrainTime : ICheck
public class CheckDrainLength : ICheck
{
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[]
{
@ -19,7 +20,7 @@ namespace osu.Game.Rulesets.Edit.Checks
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
double drainTime = context.Beatmap.CalculatePlayableLength() - context.Beatmap.TotalBreakTime;
double drainTime = context.Beatmap.CalculateDrainLength();
if (drainTime < min_drain_threshold)
yield return new IssueTemplateTooShort(this).Create((int)(drainTime / 1000));