1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-22 23:00:52 +08:00
Files
osu-lazer/osu.Game/Rulesets/Edit/Checks/CheckInconsistentSettings.cs
T
2025-08-06 14:57:42 +01:00

83 lines
3.6 KiB
C#

// 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 osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckInconsistentSettings : ICheck
{
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Settings, "Inconsistent settings", CheckScope.BeatmapSet);
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateInconsistentSetting(this, IssueType.Warning),
new IssueTemplateInconsistentSetting(this, IssueType.Negligible)
};
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var difficulties = context.BeatmapsetDifficulties;
if (difficulties.Count <= 1)
yield break;
var referenceBeatmap = context.Beatmap;
bool hasStoryboard = ResourcesCheckUtils.HasAnyStoryboardElementPresent(context.WorkingBeatmap);
// Define fields to check
var fieldsToCheck = new (IssueType issueType, string fieldName, Func<IBeatmap, object> fieldSelector)[]
{
(IssueType.Warning, "Audio lead-in", b => b.AudioLeadIn),
(IssueType.Warning, "Countdown", b => b.Countdown),
(IssueType.Warning, "Countdown offset", b => b.CountdownOffset),
(IssueType.Warning, "Epilepsy warning", b => b.EpilepsyWarning),
(IssueType.Warning, "Letterbox during breaks", b => b.LetterboxInBreaks),
(IssueType.Warning, "Samples match playback rate", b => b.SamplesMatchPlaybackRate),
(IssueType.Warning, "Widescreen support", b => hasStoryboard && b.WidescreenStoryboard),
(IssueType.Negligible, "Tick Rate", b => b.Difficulty.SliderTickRate),
};
// Iterate over each setting
foreach ((IssueType issueType, string fieldName, Func<IBeatmap, object> fieldSelector) in fieldsToCheck)
{
object referenceValue = fieldSelector(referenceBeatmap);
foreach (var beatmap in difficulties)
{
if (beatmap == referenceBeatmap)
continue;
object currentValue = fieldSelector(beatmap);
if (!EqualityComparer<object>.Default.Equals(referenceValue, currentValue))
{
yield return new IssueTemplateInconsistentSetting(this, issueType).Create(
fieldName,
referenceBeatmap.BeatmapInfo.DifficultyName,
beatmap.BeatmapInfo.DifficultyName,
referenceValue.ToString() ?? string.Empty,
currentValue.ToString() ?? string.Empty
);
}
}
}
}
public class IssueTemplateInconsistentSetting : IssueTemplate
{
public IssueTemplateInconsistentSetting(ICheck check, IssueType issueType)
: base(check, issueType, "Inconsistent \"{0}\" setting between \"{1}\" and \"{2}\"; \"{3}\" and \"{4}\" respectively.")
{
}
public Issue Create(string fieldName, string referenceDifficulty, string currentDifficulty, string referenceValue, string currentValue)
=> new Issue(this, fieldName, referenceDifficulty, currentDifficulty, referenceValue, currentValue);
}
}
}