mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 09:32:55 +08:00
Merge pull request #22281 from cdwcgt/editor-check-previewtime
Add preview time setting check
This commit is contained in:
commit
b792dc3af0
88
osu.Game.Tests/Editing/Checks/CheckPreviewTimeTest.cs
Normal file
88
osu.Game.Tests/Editing/Checks/CheckPreviewTimeTest.cs
Normal file
@ -0,0 +1,88 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Edit.Checks;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Tests.Beatmaps;
|
||||
|
||||
namespace osu.Game.Tests.Editing.Checks
|
||||
{
|
||||
public class CheckPreviewTimeTest
|
||||
{
|
||||
private CheckPreviewTime check = null!;
|
||||
|
||||
private IBeatmap beatmap = null!;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
check = new CheckPreviewTime();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPreviewTimeNotSet()
|
||||
{
|
||||
setNoPreviewTimeBeatmap();
|
||||
var content = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
|
||||
|
||||
var issues = check.Run(content).ToList();
|
||||
|
||||
Assert.That(issues, Has.Count.EqualTo(1));
|
||||
Assert.That(issues.Single().Template is CheckPreviewTime.IssueTemplateHasNoPreviewTime);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPreviewTimeconflict()
|
||||
{
|
||||
setPreviewTimeConflictBeatmap();
|
||||
|
||||
var content = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
|
||||
|
||||
var issues = check.Run(content).ToList();
|
||||
|
||||
Assert.That(issues, Has.Count.EqualTo(1));
|
||||
Assert.That(issues.Single().Template is CheckPreviewTime.IssueTemplatePreviewTimeConflict);
|
||||
Assert.That(issues.Single().Arguments.FirstOrDefault()?.ToString() == "Test1");
|
||||
}
|
||||
|
||||
private void setNoPreviewTimeBeatmap()
|
||||
{
|
||||
beatmap = new Beatmap<HitObject>
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
Metadata = new BeatmapMetadata { PreviewTime = -1 },
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setPreviewTimeConflictBeatmap()
|
||||
{
|
||||
beatmap = new Beatmap<HitObject>
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
{
|
||||
Metadata = new BeatmapMetadata { PreviewTime = 10 },
|
||||
BeatmapSet = new BeatmapSetInfo(new List<BeatmapInfo>
|
||||
{
|
||||
new BeatmapInfo
|
||||
{
|
||||
DifficultyName = "Test1",
|
||||
Metadata = new BeatmapMetadata { PreviewTime = 5 },
|
||||
},
|
||||
new BeatmapInfo
|
||||
{
|
||||
DifficultyName = "Test2",
|
||||
Metadata = new BeatmapMetadata { PreviewTime = 10 },
|
||||
},
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -36,6 +36,9 @@ namespace osu.Game.Rulesets.Edit
|
||||
new CheckUnsnappedObjects(),
|
||||
new CheckConcurrentObjects(),
|
||||
new CheckZeroLengthObjects(),
|
||||
|
||||
// Timing
|
||||
new CheckPreviewTime(),
|
||||
};
|
||||
|
||||
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
||||
|
62
osu.Game/Rulesets/Edit/Checks/CheckPreviewTime.cs
Normal file
62
osu.Game/Rulesets/Edit/Checks/CheckPreviewTime.cs
Normal file
@ -0,0 +1,62 @@
|
||||
// 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.Collections.Generic;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit.Checks
|
||||
{
|
||||
public class CheckPreviewTime : ICheck
|
||||
{
|
||||
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Timing, "Inconsistent or unset preview time");
|
||||
|
||||
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
||||
{
|
||||
new IssueTemplatePreviewTimeConflict(this),
|
||||
new IssueTemplateHasNoPreviewTime(this),
|
||||
};
|
||||
|
||||
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
||||
{
|
||||
var diffList = context.Beatmap.BeatmapInfo.BeatmapSet?.Beatmaps ?? new List<BeatmapInfo>();
|
||||
int previewTime = context.Beatmap.BeatmapInfo.Metadata.PreviewTime;
|
||||
|
||||
if (previewTime == -1)
|
||||
yield return new IssueTemplateHasNoPreviewTime(this).Create();
|
||||
|
||||
foreach (var diff in diffList)
|
||||
{
|
||||
if (diff.Equals(context.Beatmap.BeatmapInfo))
|
||||
continue;
|
||||
|
||||
if (diff.Metadata.PreviewTime != previewTime)
|
||||
yield return new IssueTemplatePreviewTimeConflict(this).Create(diff.DifficultyName, previewTime, diff.Metadata.PreviewTime);
|
||||
}
|
||||
}
|
||||
|
||||
public class IssueTemplatePreviewTimeConflict : IssueTemplate
|
||||
{
|
||||
public IssueTemplatePreviewTimeConflict(ICheck check)
|
||||
: base(check, IssueType.Problem, "Audio preview time ({1}) doesn't match the time specified in \"{0}\" ({2})")
|
||||
{
|
||||
}
|
||||
|
||||
public Issue Create(string diffName, int originalTime, int conflictTime) =>
|
||||
// preview time should show (not set) when it is not set.
|
||||
new Issue(this, diffName,
|
||||
originalTime != -1 ? $"{originalTime:N0} ms" : "not set",
|
||||
conflictTime != -1 ? $"{conflictTime:N0} ms" : "not set");
|
||||
}
|
||||
|
||||
public class IssueTemplateHasNoPreviewTime : IssueTemplate
|
||||
{
|
||||
public IssueTemplateHasNoPreviewTime(ICheck check)
|
||||
: base(check, IssueType.Problem, "A preview point for this map is not set. Consider setting one from the Timing menu.")
|
||||
{
|
||||
}
|
||||
|
||||
public Issue Create() => new Issue(this);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user