2021-04-10 19:03:16 +08:00
|
|
|
// 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
|
|
|
|
{
|
2021-04-12 16:08:08 +08:00
|
|
|
public class CheckBackground : ICheck
|
2021-04-10 19:03:16 +08:00
|
|
|
{
|
2021-04-12 21:47:26 +08:00
|
|
|
private readonly IssueTemplateNoneSet templateNoneSet;
|
|
|
|
private readonly IssueTemplateDoesNotExist templateDoesNotExist;
|
|
|
|
private readonly IssueTemplate[] templates;
|
2021-04-10 19:03:16 +08:00
|
|
|
|
2021-04-12 21:47:26 +08:00
|
|
|
public CheckBackground()
|
|
|
|
{
|
|
|
|
templates = new IssueTemplate[]
|
|
|
|
{
|
|
|
|
templateNoneSet = new IssueTemplateNoneSet(this),
|
|
|
|
templateDoesNotExist = new IssueTemplateDoesNotExist(this)
|
|
|
|
};
|
|
|
|
}
|
2021-04-10 19:03:16 +08:00
|
|
|
|
2021-04-12 21:47:26 +08:00
|
|
|
public CheckMetadata Metadata { get; } = new CheckMetadata
|
2021-04-10 19:03:16 +08:00
|
|
|
(
|
2021-04-12 21:47:26 +08:00
|
|
|
category: CheckCategory.Resources,
|
|
|
|
description: "Missing background."
|
2021-04-10 19:03:16 +08:00
|
|
|
);
|
|
|
|
|
2021-04-12 21:47:26 +08:00
|
|
|
public IEnumerable<IssueTemplate> PossibleTemplates => templates;
|
|
|
|
|
2021-04-12 16:08:08 +08:00
|
|
|
public IEnumerable<Issue> Run(IBeatmap beatmap)
|
2021-04-10 19:03:16 +08:00
|
|
|
{
|
|
|
|
if (beatmap.Metadata.BackgroundFile == null)
|
|
|
|
{
|
2021-04-12 21:47:26 +08:00
|
|
|
yield return templateNoneSet.Create();
|
2021-04-10 19:03:16 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2021-04-12 21:47:26 +08:00
|
|
|
yield return templateDoesNotExist.Create(beatmap.Metadata.BackgroundFile);
|
2021-04-10 19:03:16 +08:00
|
|
|
}
|
2021-04-12 22:36:10 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2021-04-10 19:03:16 +08:00
|
|
|
}
|
|
|
|
}
|