mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 16:13:34 +08:00
Add verify checks to unused audio at the end
This commit is contained in:
parent
96ad0d4b54
commit
63816adbc0
90
osu.Game.Tests/Editing/Checks/CheckUnusedAudioAtEndTest.cs
Normal file
90
osu.Game.Tests/Editing/Checks/CheckUnusedAudioAtEndTest.cs
Normal file
@ -0,0 +1,90 @@
|
||||
// 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.
|
||||
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Edit.Checks;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using static osu.Game.Tests.Visual.OsuTestScene.ClockBackedTestWorkingBeatmap;
|
||||
|
||||
namespace osu.Game.Tests.Editing.Checks
|
||||
{
|
||||
public class CheckUnusedAudioTest
|
||||
{
|
||||
private CheckUnusedAudioAtEnd check = null!;
|
||||
|
||||
private IBeatmap beatmapNotFullyMapped = null!;
|
||||
|
||||
private IBeatmap beatmapFullyMapped = null!;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
check = new CheckUnusedAudioAtEnd();
|
||||
beatmapNotFullyMapped = new Beatmap<HitObject>
|
||||
{
|
||||
HitObjects =
|
||||
{
|
||||
new HitCircle { StartTime = 0 },
|
||||
new HitCircle { StartTime = 1_298 },
|
||||
},
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
Metadata = new BeatmapMetadata { AudioFile = "abc123.jpg" }
|
||||
}
|
||||
};
|
||||
beatmapFullyMapped = new Beatmap<HitObject>
|
||||
{
|
||||
HitObjects =
|
||||
{
|
||||
new HitCircle { StartTime = 0 },
|
||||
new HitCircle { StartTime = 9000 },
|
||||
},
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
Metadata = new BeatmapMetadata { AudioFile = "abc123.jpg" }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAudioNotFullyUsed()
|
||||
{
|
||||
var context = getContext(beatmapNotFullyMapped);
|
||||
var issues = check.Run(context).ToList();
|
||||
|
||||
Assert.That(issues, Has.Count.EqualTo(1));
|
||||
Assert.That(issues.Single().Template is CheckUnusedAudioAtEnd.IssueTemplateUnusedAudioAtEnd);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAudioFullyUsed()
|
||||
{
|
||||
var context = getContext(beatmapFullyMapped);
|
||||
var issues = check.Run(context).ToList();
|
||||
|
||||
Assert.That(issues, Has.Count.EqualTo(0));
|
||||
}
|
||||
|
||||
private BeatmapVerifierContext getContext(IBeatmap beatmap)
|
||||
{
|
||||
return new BeatmapVerifierContext(beatmap, getMockWorkingBeatmap(beatmap).Object);
|
||||
}
|
||||
|
||||
private Mock<IWorkingBeatmap> getMockWorkingBeatmap(IBeatmap beatmap)
|
||||
{
|
||||
var mockTrack = new TrackVirtualStore(new FramedClock()).GetVirtual(10000, "virtual");
|
||||
|
||||
var mockWorkingBeatmap = new Mock<IWorkingBeatmap>();
|
||||
mockWorkingBeatmap.SetupGet(w => w.Beatmap).Returns(beatmap);
|
||||
mockWorkingBeatmap.SetupGet(w => w.Track).Returns(mockTrack);
|
||||
|
||||
return mockWorkingBeatmap;
|
||||
}
|
||||
}
|
||||
}
|
19
osu.Game/Localisation/CheckUnusedAudioAtEndStrings.cs
Normal file
19
osu.Game/Localisation/CheckUnusedAudioAtEndStrings.cs
Normal file
@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Localisation;
|
||||
|
||||
namespace osu.Game.Localisation
|
||||
{
|
||||
public static class CheckUnusedAudioAtEndStrings
|
||||
{
|
||||
private const string prefix = @"osu.Game.Resources.Localisation.CheckUnusedAudioAtEnd";
|
||||
|
||||
/// <summary>
|
||||
/// "{0}% of the audio is not mapped."
|
||||
/// </summary>
|
||||
public static LocalisableString OfTheAudioIsNot(double percentageLeft) => new TranslatableString(getKey(@"of_the_audio_is_not"), @"{0}% of the audio is not mapped.", percentageLeft);
|
||||
|
||||
private static string getKey(string key) => $@"{prefix}:{key}";
|
||||
}
|
||||
}
|
@ -36,12 +36,14 @@ namespace osu.Game.Rulesets.Edit
|
||||
new CheckConcurrentObjects(),
|
||||
new CheckZeroLengthObjects(),
|
||||
new CheckDrainLength(),
|
||||
new CheckUnusedAudioAtEnd(),
|
||||
|
||||
// Timing
|
||||
new CheckPreviewTime(),
|
||||
|
||||
// Events
|
||||
new CheckBreaks()
|
||||
|
||||
};
|
||||
|
||||
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
||||
|
50
osu.Game/Rulesets/Edit/Checks/CheckUnusedAudioAtEnd.cs
Normal file
50
osu.Game/Rulesets/Edit/Checks/CheckUnusedAudioAtEnd.cs
Normal file
@ -0,0 +1,50 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit.Checks
|
||||
{
|
||||
public class CheckUnusedAudioAtEnd : ICheck
|
||||
{
|
||||
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Compose, "More than 20% unused audio at the end");
|
||||
|
||||
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
||||
{
|
||||
new IssueTemplateUnusedAudioAtEnd(this),
|
||||
};
|
||||
|
||||
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
||||
{
|
||||
double mappedLength = context.Beatmap.HitObjects.Last().GetEndTime();
|
||||
double trackLength = context.WorkingBeatmap.Track.Length;
|
||||
|
||||
double mappedPercentage = calculatePercentage(mappedLength, trackLength);
|
||||
|
||||
if (mappedPercentage < 80)
|
||||
{
|
||||
yield return new IssueTemplateUnusedAudioAtEnd(this).Create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private double calculatePercentage(double mappedLenght, double trackLenght)
|
||||
{
|
||||
return Math.Round(mappedLenght / trackLenght * 100);
|
||||
}
|
||||
|
||||
public class IssueTemplateUnusedAudioAtEnd : IssueTemplate
|
||||
{
|
||||
public IssueTemplateUnusedAudioAtEnd(ICheck check)
|
||||
: base(check, IssueType.Problem, "There is more than 20% unused audio at the end.")
|
||||
{
|
||||
}
|
||||
|
||||
public Issue Create() => new Issue(this);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user