// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. 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 PossibleTemplates => new IssueTemplate[] { new IssueTemplateIncorrectMarker(this), }; private IEnumerable 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)(? 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(romanisedTitle) && !check.ExactRegex.IsMatch(romanisedTitle)) { yield return new IssueTemplateIncorrectMarker(this).Create(hasRomanisedTitle ? "Romanised title" : "Title", check.CorrectMarkerFormat); } if (hasRomanisedTitle && check.AnyRegex.IsMatch(unicodeTitle) && !check.ExactRegex.IsMatch(unicodeTitle)) { yield return new IssueTemplateIncorrectMarker(this).Create("Title", check.CorrectMarkerFormat); } } } private class MarkerCheck { public string CorrectMarkerFormat; public Regex ExactRegex; public Regex AnyRegex; public MarkerCheck(string exact, string anyRegex) { CorrectMarkerFormat = exact; ExactRegex = new Regex(Regex.Escape(exact)); AnyRegex = new Regex(anyRegex); } } public class IssueTemplateIncorrectMarker : IssueTemplate { public IssueTemplateIncorrectMarker(ICheck check) : base(check, IssueType.Problem, "{0} field has a incorrect format of marker {1}") { } public Issue Create(string titleField, string correctMarkerFormat) => new Issue(this, titleField, correctMarkerFormat); } } }