mirror of
https://github.com/ppy/osu.git
synced 2024-11-14 15:17:27 +08:00
Refactor abstract check to reduce duplication
This commit is contained in:
parent
e7cf1ab4df
commit
1866b4b6b1
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user