1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 21:47:25 +08:00
osu-lazer/osu.Game/Rulesets/Edit/Checks/CheckBackground.cs
Naxess 7c4f6d2b62 Rework template usage
Includes moving the origin check back to templates, constructing nested template classes in each check, and making parameterized template usage.
2021-04-12 15:47:26 +02:00

75 lines
2.3 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.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckBackground : ICheck
{
private readonly IssueTemplateNoneSet templateNoneSet;
private readonly IssueTemplateDoesNotExist templateDoesNotExist;
private readonly IssueTemplate[] templates;
private class IssueTemplateNoneSet : IssueTemplate
{
public IssueTemplateNoneSet(ICheck checkOrigin)
: base(checkOrigin, IssueType.Problem, "No background has been set")
{
}
public Issue Create() => new Issue(this);
}
private class IssueTemplateDoesNotExist : IssueTemplate
{
public IssueTemplateDoesNotExist(ICheck checkOrigin)
: base(checkOrigin, IssueType.Problem, "The background file \"{0}\" does not exist.")
{
}
public Issue Create(string filename) => new Issue(this, filename);
}
public CheckBackground()
{
templates = new IssueTemplate[]
{
templateNoneSet = new IssueTemplateNoneSet(this),
templateDoesNotExist = new IssueTemplateDoesNotExist(this)
};
}
public CheckMetadata Metadata { get; } = new CheckMetadata
(
category: CheckCategory.Resources,
description: "Missing background."
);
public IEnumerable<IssueTemplate> PossibleTemplates => templates;
public IEnumerable<Issue> Run(IBeatmap beatmap)
{
if (beatmap.Metadata.BackgroundFile == null)
{
yield return templateNoneSet.Create();
yield break;
}
// If the background is set, also make sure it still exists.
var set = beatmap.BeatmapInfo.BeatmapSet;
var file = set.Files.FirstOrDefault(f => f.Filename == beatmap.Metadata.BackgroundFile);
if (file != null)
yield break;
yield return templateDoesNotExist.Create(beatmap.Metadata.BackgroundFile);
}
}
}