1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 03:02:54 +08:00
osu-lazer/osu.Game/Rulesets/Edit/Checks/CheckTitleMarkers.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
3.1 KiB
C#
Raw Normal View History

2024-07-03 04:20:00 +08:00
// 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.
2024-07-03 22:13:30 +08:00
using System;
2024-07-03 04:20:00 +08:00
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),
};
2024-07-03 21:49:17 +08:00
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)"),
];
2024-07-03 04:20:00 +08:00
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
string romanisedTitle = context.Beatmap.Metadata.Title;
string unicodeTitle = context.Beatmap.Metadata.TitleUnicode;
foreach (var check in markerChecks)
2024-07-03 04:20:00 +08:00
{
bool hasRomanisedTitle = unicodeTitle != romanisedTitle;
2024-07-03 22:13:30 +08:00
if (check.AnyRegex.IsMatch(unicodeTitle) && !unicodeTitle.Contains(check.CorrectMarkerFormat, StringComparison.Ordinal))
2024-07-03 04:20:00 +08:00
yield return new IssueTemplateIncorrectMarker(this).Create("Title", check.CorrectMarkerFormat);
2024-07-03 22:13:30 +08:00
if (hasRomanisedTitle && check.AnyRegex.IsMatch(romanisedTitle) && !romanisedTitle.Contains(check.CorrectMarkerFormat, StringComparison.Ordinal))
yield return new IssueTemplateIncorrectMarker(this).Create("Romanised title", check.CorrectMarkerFormat);
2024-07-03 04:20:00 +08:00
}
}
private class MarkerCheck
2024-07-03 04:20:00 +08:00
{
2024-07-03 21:49:17 +08:00
public readonly string CorrectMarkerFormat;
public readonly Regex AnyRegex;
2024-07-03 04:20:00 +08:00
public MarkerCheck(string exact, string anyRegex)
{
CorrectMarkerFormat = exact;
2024-07-03 21:49:21 +08:00
AnyRegex = new Regex(anyRegex, RegexOptions.Compiled);
2024-07-03 04:20:00 +08:00
}
}
public class IssueTemplateIncorrectMarker : IssueTemplate
{
public IssueTemplateIncorrectMarker(ICheck check)
2024-07-03 22:13:47 +08:00
: base(check, IssueType.Problem, "{0} field has an incorrect format of marker {1}")
2024-07-03 04:20:00 +08:00
{
}
public Issue Create(string titleField, string correctMarkerFormat) => new Issue(this, titleField, correctMarkerFormat);
}
}
2024-07-03 21:49:17 +08:00
}