mirror of
https://github.com/ppy/osu.git
synced 2025-01-31 19:32:58 +08:00
Merge pull request #28716 from 64ArthurAraujo/verify-title-markers
Add verify checks for incorrect title markers
This commit is contained in:
commit
d95ea21361
235
osu.Game.Tests/Editing/Checks/CheckTitleMarkersTest.cs
Normal file
235
osu.Game.Tests/Editing/Checks/CheckTitleMarkersTest.cs
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
// 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 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
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class CheckTitleMarkersTest
|
||||||
|
{
|
||||||
|
private CheckTitleMarkers check = null!;
|
||||||
|
|
||||||
|
private IBeatmap beatmap = null!;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
check = new CheckTitleMarkers();
|
||||||
|
|
||||||
|
beatmap = new Beatmap<HitObject>
|
||||||
|
{
|
||||||
|
BeatmapInfo = new BeatmapInfo
|
||||||
|
{
|
||||||
|
Metadata = new BeatmapMetadata
|
||||||
|
{
|
||||||
|
Title = "Egao no Kanata",
|
||||||
|
TitleUnicode = "エガオノカナタ"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNoTitleMarkers()
|
||||||
|
{
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestTvSizeMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (TV Size)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (TV Size)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMalformedTvSizeMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (tv size)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (tv size)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(2));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestGameVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (Game Ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Game Ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMalformedGameVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (game ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (game ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(2));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestShortVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (Short Ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Short Ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMalformedShortVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (short ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (short ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(2));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCutVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (Cut Ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Cut Ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMalformedCutVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (cut ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (cut ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(2));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSpedUpVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (Sped Up Ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Sped Up Ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMalformedSpedUpVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (sped up ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (sped up ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(2));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNightcoreMixMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (Nightcore Mix)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Nightcore Mix)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMalformedNightcoreMixMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (nightcore mix)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (nightcore mix)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(2));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSpedUpCutVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (Sped Up & Cut Ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Sped Up & Cut Ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMalformedSpedUpCutVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (sped up & cut ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (sped up & cut ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(2));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNightcoreCutVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (Nightcore & Cut Ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (Nightcore & Cut Ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestMalformedNightcoreCutVerMarker()
|
||||||
|
{
|
||||||
|
beatmap.BeatmapInfo.Metadata.Title += " (nightcore & cut ver.)";
|
||||||
|
beatmap.BeatmapInfo.Metadata.TitleUnicode += " (nightcore & cut ver.)";
|
||||||
|
|
||||||
|
var issues = check.Run(getContext(beatmap)).ToList();
|
||||||
|
|
||||||
|
Assert.That(issues, Has.Count.EqualTo(2));
|
||||||
|
Assert.That(issues.Any(issue => issue.Template is CheckTitleMarkers.IssueTemplateIncorrectMarker));
|
||||||
|
}
|
||||||
|
|
||||||
|
private BeatmapVerifierContext getContext(IBeatmap beatmap)
|
||||||
|
{
|
||||||
|
return new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -46,6 +46,9 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
|
|
||||||
// Events
|
// Events
|
||||||
new CheckBreaks(),
|
new CheckBreaks(),
|
||||||
|
|
||||||
|
// Metadata
|
||||||
|
new CheckTitleMarkers(),
|
||||||
};
|
};
|
||||||
|
|
||||||
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
||||||
|
71
osu.Game/Rulesets/Edit/Checks/CheckTitleMarkers.cs
Normal file
71
osu.Game/Rulesets/Edit/Checks/CheckTitleMarkers.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// 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.Text.RegularExpressions;
|
||||||
|
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Edit.Checks
|
||||||
|
{
|
||||||
|
public class CheckTitleMarkers : ICheck
|
||||||
|
{
|
||||||
|
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Metadata, "Checks for incorrect formats of (TV Size) / (Game Ver.) / (Short Ver.) / (Cut Ver.) / (Sped Up Ver.) / etc in title.");
|
||||||
|
|
||||||
|
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
||||||
|
{
|
||||||
|
new IssueTemplateIncorrectMarker(this),
|
||||||
|
};
|
||||||
|
|
||||||
|
private readonly IEnumerable<MarkerCheck> markerChecks =
|
||||||
|
[
|
||||||
|
new MarkerCheck(@"(TV Size)", @"(?i)(tv (size|ver))"),
|
||||||
|
new MarkerCheck(@"(Game Ver.)", @"(?i)(game (size|ver))"),
|
||||||
|
new MarkerCheck(@"(Short Ver.)", @"(?i)(short (size|ver))"),
|
||||||
|
new MarkerCheck(@"(Cut Ver.)", @"(?i)(?<!& )(cut (size|ver))"),
|
||||||
|
new MarkerCheck(@"(Sped Up Ver.)", @"(?i)(?<!& )(sped|speed) ?up ver"),
|
||||||
|
new MarkerCheck(@"(Nightcore Mix)", @"(?i)(?<!& )(nightcore|night core) (ver|mix)"),
|
||||||
|
new MarkerCheck(@"(Sped Up & Cut Ver.)", @"(?i)(sped|speed) ?up (ver)? ?& cut (size|ver)"),
|
||||||
|
new MarkerCheck(@"(Nightcore & Cut Ver.)", @"(?i)(nightcore|night core) (ver|mix)? ?& cut (size|ver)"),
|
||||||
|
];
|
||||||
|
|
||||||
|
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
||||||
|
{
|
||||||
|
string romanisedTitle = context.Beatmap.Metadata.Title;
|
||||||
|
string unicodeTitle = context.Beatmap.Metadata.TitleUnicode;
|
||||||
|
|
||||||
|
foreach (var check in markerChecks)
|
||||||
|
{
|
||||||
|
bool hasRomanisedTitle = unicodeTitle != romanisedTitle;
|
||||||
|
|
||||||
|
if (check.AnyRegex.IsMatch(unicodeTitle) && !unicodeTitle.Contains(check.CorrectMarkerFormat, StringComparison.Ordinal))
|
||||||
|
yield return new IssueTemplateIncorrectMarker(this).Create("Title", check.CorrectMarkerFormat);
|
||||||
|
|
||||||
|
if (hasRomanisedTitle && check.AnyRegex.IsMatch(romanisedTitle) && !romanisedTitle.Contains(check.CorrectMarkerFormat, StringComparison.Ordinal))
|
||||||
|
yield return new IssueTemplateIncorrectMarker(this).Create("Romanised title", check.CorrectMarkerFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MarkerCheck
|
||||||
|
{
|
||||||
|
public readonly string CorrectMarkerFormat;
|
||||||
|
public readonly Regex AnyRegex;
|
||||||
|
|
||||||
|
public MarkerCheck(string exact, string anyRegex)
|
||||||
|
{
|
||||||
|
CorrectMarkerFormat = exact;
|
||||||
|
AnyRegex = new Regex(anyRegex, RegexOptions.Compiled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IssueTemplateIncorrectMarker : IssueTemplate
|
||||||
|
{
|
||||||
|
public IssueTemplateIncorrectMarker(ICheck check)
|
||||||
|
: base(check, IssueType.Problem, "{0} field has an incorrect format of marker {1}")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Issue Create(string titleField, string correctMarkerFormat) => new Issue(this, titleField, correctMarkerFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user