1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:35:35 +08:00

Split out general checks into its own verifier class (and remove static usage)

This commit is contained in:
Dean Herbert 2021-04-13 19:50:22 +09:00
parent aa5fe2e9fc
commit 03ba04e8ce
3 changed files with 38 additions and 23 deletions

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Checks;
using osu.Game.Rulesets.Edit.Checks.Components;
using osu.Game.Rulesets.Osu.Edit.Checks;
@ -15,10 +14,6 @@ namespace osu.Game.Rulesets.Osu.Edit
{
private readonly List<ICheck> checks = new List<ICheck>
{
// General checks
new CheckBackground(),
// Ruleset-specific checks
new CheckOffscreenObjects()
};

View File

@ -0,0 +1,24 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit
{
/// <summary>
/// A ruleset-agnostic beatmap converter that identifies issues in common metadata or mapping standards.
/// </summary>
public class BeatmapVerifier : IBeatmapVerifier
{
private readonly List<ICheck> checks = new List<ICheck>
{
new CheckBackground(),
};
public IEnumerable<Issue> Run(IBeatmap beatmap) => checks.SelectMany(check => check.Run(beatmap));
}
}

View File

@ -7,11 +7,9 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Checks.Components;
using osuTK;
@ -20,9 +18,6 @@ namespace osu.Game.Screens.Edit.Verify
{
public class VerifyScreen : EditorScreen
{
private Ruleset ruleset;
private static IBeatmapVerifier beatmapVerifier;
[Cached]
private Bindable<Issue> selectedIssue = new Bindable<Issue>();
@ -31,16 +26,6 @@ namespace osu.Game.Screens.Edit.Verify
{
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
ruleset = parent.Get<IBindable<WorkingBeatmap>>().Value.BeatmapInfo.Ruleset?.CreateInstance();
beatmapVerifier = ruleset?.CreateBeatmapVerifier();
return dependencies;
}
[BackgroundDependencyLoader]
private void load()
{
@ -81,9 +66,15 @@ namespace osu.Game.Screens.Edit.Verify
[Resolved]
private Bindable<Issue> selectedIssue { get; set; }
private IBeatmapVerifier rulesetVerifier;
private BeatmapVerifier generalVerifier;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
generalVerifier = new BeatmapVerifier();
rulesetVerifier = Beatmap.BeatmapInfo.Ruleset?.CreateInstance()?.CreateBeatmapVerifier();
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
@ -128,9 +119,14 @@ namespace osu.Game.Screens.Edit.Verify
private void refresh()
{
table.Issues = beatmapVerifier.Run(Beatmap)
.OrderBy(issue => issue.Template.Type)
.ThenBy(issue => issue.Check.Metadata.Category);
var issues = generalVerifier.Run(Beatmap);
if (rulesetVerifier != null)
issues = issues.Concat(rulesetVerifier.Run(Beatmap));
table.Issues = issues
.OrderBy(issue => issue.Template.Type)
.ThenBy(issue => issue.Check.Metadata.Category);
}
}
}