1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 03:42:57 +08:00

Refactor abstract check to reduce duplication

This commit is contained in:
Bartłomiej Dach 2024-03-26 11:13:03 +01:00
parent e7cf1ab4df
commit 1866b4b6b1
No known key found for this signature in database
5 changed files with 57 additions and 48 deletions

View File

@ -15,24 +15,25 @@ namespace osu.Game.Rulesets.Catch.Edit.Checks
public override IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var diff = context.Beatmap.Difficulty;
Issue? issue;
if (HasMoreThanOneDecimalPlace(diff.ApproachRate))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Approach rate", diff.ApproachRate);
if (HasMoreThanOneDecimalPlace("Approach rate", diff.ApproachRate, out issue))
yield return issue;
if (OutOfRange(diff.ApproachRate))
yield return new IssueTemplateOutOfRange(this).Create("Approach rate", diff.ApproachRate);
if (OutOfRange("Approach rate", diff.ApproachRate, out issue))
yield return issue;
if (HasMoreThanOneDecimalPlace(diff.CircleSize))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Circle size", diff.CircleSize);
if (HasMoreThanOneDecimalPlace("Circle size", diff.CircleSize, out issue))
yield return issue;
if (OutOfRange(diff.CircleSize))
yield return new IssueTemplateOutOfRange(this).Create("Circle size", diff.CircleSize);
if (OutOfRange("Circle size", diff.CircleSize, out issue))
yield return issue;
if (HasMoreThanOneDecimalPlace(diff.DrainRate))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Drain rate", diff.DrainRate);
if (HasMoreThanOneDecimalPlace("Drain rate", diff.DrainRate, out issue))
yield return issue;
if (OutOfRange(diff.DrainRate))
yield return new IssueTemplateOutOfRange(this).Create("Drain rate", diff.DrainRate);
if (OutOfRange("Drain rate", diff.DrainRate, out issue))
yield return issue;
}
}
}

View File

@ -15,18 +15,19 @@ namespace osu.Game.Rulesets.Mania.Edit.Checks
public override IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var diff = context.Beatmap.Difficulty;
Issue? issue;
if (HasMoreThanOneDecimalPlace(diff.OverallDifficulty))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Overall difficulty", diff.OverallDifficulty);
if (HasMoreThanOneDecimalPlace("Overall difficulty", diff.OverallDifficulty, out issue))
yield return issue;
if (OutOfRange(diff.OverallDifficulty))
yield return new IssueTemplateOutOfRange(this).Create("Overall difficulty", diff.OverallDifficulty);
if (OutOfRange("Overall difficulty", diff.OverallDifficulty, out issue))
yield return issue;
if (HasMoreThanOneDecimalPlace(diff.DrainRate))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Drain rate", diff.DrainRate);
if (HasMoreThanOneDecimalPlace("Drain rate", diff.DrainRate, out issue))
yield return issue;
if (OutOfRange(diff.DrainRate))
yield return new IssueTemplateOutOfRange(this).Create("Drain rate", diff.DrainRate);
if (OutOfRange("Drain rate", diff.DrainRate, out issue))
yield return issue;
}
}
}

View File

@ -15,30 +15,31 @@ namespace osu.Game.Rulesets.Osu.Edit.Checks
public override IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var diff = context.Beatmap.Difficulty;
Issue? issue;
if (HasMoreThanOneDecimalPlace(diff.ApproachRate))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Approach rate", diff.ApproachRate);
if (HasMoreThanOneDecimalPlace("Approach rate", diff.ApproachRate, out issue))
yield return issue;
if (OutOfRange(diff.ApproachRate))
yield return new IssueTemplateOutOfRange(this).Create("Approach rate", diff.ApproachRate);
if (OutOfRange("Approach rate", diff.ApproachRate, out issue))
yield return issue;
if (HasMoreThanOneDecimalPlace(diff.OverallDifficulty))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Overall difficulty", diff.OverallDifficulty);
if (HasMoreThanOneDecimalPlace("Overall difficulty", diff.OverallDifficulty, out issue))
yield return issue;
if (OutOfRange(diff.OverallDifficulty))
yield return new IssueTemplateOutOfRange(this).Create("Overall difficulty", diff.OverallDifficulty);
if (OutOfRange("Overall difficulty", diff.OverallDifficulty, out issue))
yield return issue;
if (HasMoreThanOneDecimalPlace(diff.CircleSize))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Circle size", diff.CircleSize);
if (HasMoreThanOneDecimalPlace("Circle size", diff.CircleSize, out issue))
yield return issue;
if (OutOfRange(diff.CircleSize))
yield return new IssueTemplateOutOfRange(this).Create("Circle size", diff.CircleSize);
if (OutOfRange("Circle size", diff.CircleSize, out issue))
yield return issue;
if (HasMoreThanOneDecimalPlace(diff.DrainRate))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Drain rate", diff.DrainRate);
if (HasMoreThanOneDecimalPlace("Drain rate", diff.DrainRate, out issue))
yield return issue;
if (OutOfRange(diff.DrainRate))
yield return new IssueTemplateOutOfRange(this).Create("Drain rate", diff.DrainRate);
if (OutOfRange("Drain rate", diff.DrainRate, out issue))
yield return issue;
}
}
}

View File

@ -15,18 +15,19 @@ namespace osu.Game.Rulesets.Taiko.Edit.Checks
public override IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var diff = context.Beatmap.Difficulty;
Issue? issue;
if (HasMoreThanOneDecimalPlace(diff.OverallDifficulty))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Overall difficulty", diff.OverallDifficulty);
if (HasMoreThanOneDecimalPlace("Overall difficulty", diff.OverallDifficulty, out issue))
yield return issue;
if (OutOfRange(diff.OverallDifficulty))
yield return new IssueTemplateOutOfRange(this).Create("Overall difficulty", diff.OverallDifficulty);
if (OutOfRange("Overall difficulty", diff.OverallDifficulty, out issue))
yield return issue;
if (HasMoreThanOneDecimalPlace(diff.DrainRate))
yield return new IssueTemplateMoreThanOneDecimal(this).Create("Drain rate", diff.DrainRate);
if (HasMoreThanOneDecimalPlace("Drain rate", diff.DrainRate, out issue))
yield return issue;
if (OutOfRange(diff.DrainRate))
yield return new IssueTemplateOutOfRange(this).Create("Drain rate", diff.DrainRate);
if (OutOfRange("Drain rate", diff.DrainRate, out issue))
yield return issue;
}
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
@ -21,14 +22,18 @@ namespace osu.Game.Rulesets.Edit.Checks
/// <summary>
/// If the setting is out of the boundaries set by the editor (0 - 10)
/// </summary>
protected bool OutOfRange(float setting)
protected bool OutOfRange(string setting, float value, [NotNullWhen(true)] out Issue? issue)
{
return setting < 0f || setting > 10f;
bool hasIssue = value < 0f || value > 10f;
issue = hasIssue ? new IssueTemplateOutOfRange(this).Create(setting, value) : null;
return hasIssue;
}
protected bool HasMoreThanOneDecimalPlace(float setting)
protected bool HasMoreThanOneDecimalPlace(string setting, float value, [NotNullWhen(true)] out Issue? issue)
{
return float.Round(setting, 1) != setting;
bool hasIssue = float.Round(value, 1) != value;
issue = hasIssue ? new IssueTemplateMoreThanOneDecimal(this).Create(setting, value) : null;
return hasIssue;
}
public class IssueTemplateMoreThanOneDecimal : IssueTemplate