1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 06:05:10 +08:00

Move check origin from IssueTemplate to Issue

As a result we can also make check an interface, and need to provide the check itself when constructing an issue.
This commit is contained in:
Naxess 2021-04-12 10:08:08 +02:00
parent 42604afcdc
commit 65ebdd8f7a
8 changed files with 33 additions and 41 deletions

View File

@ -9,7 +9,7 @@ using osuTK;
namespace osu.Game.Rulesets.Osu.Edit.Checks
{
public class CheckOffscreenObjects : Check
public class CheckOffscreenObjects : ICheck
{
// These are close approximates to the edges of the screen
// in gameplay on a 4:3 aspect ratio for osu!stable.
@ -22,13 +22,13 @@ namespace osu.Game.Rulesets.Osu.Edit.Checks
// (higher = more performant, but higher false-negative chance).
private const int path_step_size = 5;
public override CheckMetadata Metadata { get; } = new CheckMetadata
public CheckMetadata Metadata { get; } = new CheckMetadata
(
category: CheckCategory.Compose,
description: "Offscreen hitobjects."
);
public override IEnumerable<IssueTemplate> PossibleTemplates => new[]
public IEnumerable<IssueTemplate> PossibleTemplates => new[]
{
templateOffscreen,
templateOffscreenSliderPath
@ -46,7 +46,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Checks
unformattedMessage: "This slider goes offscreen here on a 4:3 aspect ratio."
);
public override IEnumerable<Issue> Run(IBeatmap beatmap)
public IEnumerable<Issue> Run(IBeatmap beatmap)
{
foreach (var hitobject in beatmap.HitObjects)
{
@ -63,7 +63,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Checks
case HitCircle circle:
{
if (isOffscreen(circle.StackedPosition, circle.Radius))
yield return new Issue(circle, templateOffscreen);
yield return new Issue(this, circle, templateOffscreen);
break;
}
@ -89,7 +89,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Checks
// `SpanDuration` ensures we don't include reverses.
double time = slider.StartTime + progress * slider.SpanDuration;
yield return new Issue(slider, templateOffscreenSliderPath) { Time = time };
yield return new Issue(this, slider, templateOffscreenSliderPath) { Time = time };
yield break;
}
@ -98,7 +98,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Checks
if (!isOffscreen(slider.StackedEndPosition, slider.Radius))
yield break;
yield return new Issue(slider, templateOffscreenSliderPath) { Time = slider.EndTime };
yield return new Issue(this, slider, templateOffscreenSliderPath) { Time = slider.EndTime };
}
private bool isOffscreen(Vector2 position, double radius)

View File

@ -12,7 +12,7 @@ namespace osu.Game.Rulesets.Osu.Edit
{
public class OsuBeatmapVerifier : BeatmapVerifier
{
private readonly List<Check> checks = new List<Check>
private readonly List<ICheck> checks = new List<ICheck>
{
new CheckOffscreenObjects()
};

View File

@ -15,7 +15,7 @@ namespace osu.Game.Rulesets.Edit
/// Checks which are performed regardless of ruleset.
/// These handle things like beatmap metadata, timing, and other ruleset agnostic elements.
/// </summary>
private readonly IReadOnlyList<Check> generalChecks = new List<Check>
private readonly IReadOnlyList<ICheck> generalChecks = new List<ICheck>
{
new CheckBackground()
};

View File

@ -8,15 +8,15 @@ using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckBackground : Check
public class CheckBackground : ICheck
{
public override CheckMetadata Metadata { get; } = new CheckMetadata
public CheckMetadata Metadata { get; } = new CheckMetadata
(
category: CheckCategory.Resources,
description: "Missing background."
);
public override IEnumerable<IssueTemplate> PossibleTemplates => new[]
public IEnumerable<IssueTemplate> PossibleTemplates => new[]
{
templateNoneSet,
templateDoesNotExist
@ -34,11 +34,11 @@ namespace osu.Game.Rulesets.Edit.Checks
unformattedMessage: "The background file \"{0}\" is does not exist."
);
public override IEnumerable<Issue> Run(IBeatmap beatmap)
public IEnumerable<Issue> Run(IBeatmap beatmap)
{
if (beatmap.Metadata.BackgroundFile == null)
{
yield return new Issue(templateNoneSet);
yield return new Issue(this, templateNoneSet);
yield break;
}
@ -51,7 +51,7 @@ namespace osu.Game.Rulesets.Edit.Checks
if (file != null)
yield break;
yield return new Issue(templateDoesNotExist, beatmap.Metadata.BackgroundFile);
yield return new Issue(this, templateDoesNotExist, beatmap.Metadata.BackgroundFile);
}
}
}

View File

@ -6,28 +6,22 @@ using osu.Game.Beatmaps;
namespace osu.Game.Rulesets.Edit.Checks.Components
{
public abstract class Check
public interface ICheck
{
/// <summary>
/// The metadata for this check.
/// </summary>
public abstract CheckMetadata Metadata { get; }
public CheckMetadata Metadata { get; }
/// <summary>
/// All possible templates for issues that this check may return.
/// </summary>
public abstract IEnumerable<IssueTemplate> PossibleTemplates { get; }
public IEnumerable<IssueTemplate> PossibleTemplates { get; }
/// <summary>
/// Runs this check and returns any issues detected for the provided beatmap.
/// </summary>
/// <param name="beatmap">The beatmap to run the check on.</param>
public abstract IEnumerable<Issue> Run(IBeatmap beatmap);
protected Check()
{
foreach (var template in PossibleTemplates)
template.Origin = this;
}
public IEnumerable<Issue> Run(IBeatmap beatmap);
}
}

View File

@ -26,38 +26,41 @@ namespace osu.Game.Rulesets.Edit.Checks.Components
/// </summary>
public IssueTemplate Template;
/// <summary>
/// The check that this issue originates from.
/// </summary>
public ICheck Check;
/// <summary>
/// The arguments that give this issue its context, based on the <see cref="IssueTemplate"/>. These are then substituted into the <see cref="IssueTemplate.UnformattedMessage"/>.
/// This could for instance include timestamps, which diff is being compared to, what some volume is, etc.
/// </summary>
public object[] Arguments;
public Issue(IssueTemplate template, params object[] args)
public Issue(ICheck check, IssueTemplate template, params object[] args)
{
Check = check;
Time = null;
HitObjects = Array.Empty<HitObject>();
Template = template;
Arguments = args;
if (template.Origin == null)
throw new ArgumentException("A template had no origin. Make sure the `Templates()` method contains all templates used.");
}
public Issue(double? time, IssueTemplate template, params object[] args)
: this(template, args)
public Issue(ICheck check, double? time, IssueTemplate template, params object[] args)
: this(check, template, args)
{
Time = time;
}
public Issue(HitObject hitObject, IssueTemplate template, params object[] args)
: this(template, args)
public Issue(ICheck check, HitObject hitObject, IssueTemplate template, params object[] args)
: this(check, template, args)
{
Time = hitObject.StartTime;
HitObjects = new[] { hitObject };
}
public Issue(IEnumerable<HitObject> hitObjects, IssueTemplate template, params object[] args)
: this(template, args)
public Issue(ICheck check, IEnumerable<HitObject> hitObjects, IssueTemplate template, params object[] args)
: this(check, template, args)
{
var hitObjectList = hitObjects.ToList();

View File

@ -14,11 +14,6 @@ namespace osu.Game.Rulesets.Edit.Checks.Components
private static readonly Color4 negligible_green = new Colour4(0.33f, 0.8f, 0.5f, 1.0f);
private static readonly Color4 error_gray = new Colour4(0.5f, 0.5f, 0.5f, 1.0f);
/// <summary>
/// The check that this template originates from.
/// </summary>
public Check Origin;
/// <summary>
/// The type of the issue.
/// </summary>

View File

@ -130,7 +130,7 @@ namespace osu.Game.Screens.Edit.Verify
{
table.Issues = beatmapVerifier.Run(Beatmap)
.OrderByDescending(issue => issue.Template.Type)
.ThenByDescending(issue => issue.Template.Origin.Metadata.Category);
.ThenByDescending(issue => issue.Check.Metadata.Category);
}
}
}