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 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 22:37:47 +08:00
|
|
|
public CheckMetadata Metadata { get; } = new CheckMetadata(CheckCategory.Resources, "Missing background");
|
2021-04-10 19:03:16 +08:00
|
|
|
|
2021-04-12 23:12:37 +08:00
|
|
|
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
|
|
|
{
|
|
|
|
new IssueTemplateNoneSet(this),
|
|
|
|
new IssueTemplateDoesNotExist(this)
|
|
|
|
};
|
2021-04-12 21:47:26 +08:00
|
|
|
|
2021-04-18 07:21:20 +08:00
|
|
|
public IEnumerable<Issue> Run(IWorkingBeatmap workingBeatmap)
|
2021-04-10 19:03:16 +08:00
|
|
|
{
|
2021-04-18 07:19:25 +08:00
|
|
|
string backgroundFile = workingBeatmap.Beatmap.Metadata?.BackgroundFile;
|
|
|
|
|
|
|
|
if (backgroundFile == null)
|
2021-04-10 19:03:16 +08:00
|
|
|
{
|
2021-04-12 23:12:37 +08:00
|
|
|
yield return new IssueTemplateNoneSet(this).Create();
|
2021-04-10 19:03:16 +08:00
|
|
|
|
|
|
|
yield break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the background is set, also make sure it still exists.
|
2021-04-18 07:19:25 +08:00
|
|
|
var storagePath = workingBeatmap.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile);
|
|
|
|
if (storagePath != null)
|
2021-04-10 19:03:16 +08:00
|
|
|
yield break;
|
|
|
|
|
2021-04-18 07:19:25 +08:00
|
|
|
yield return new IssueTemplateDoesNotExist(this).Create(backgroundFile);
|
2021-04-10 19:03:16 +08:00
|
|
|
}
|
2021-04-12 22:36:10 +08:00
|
|
|
|
2021-04-13 08:29:25 +08:00
|
|
|
public class IssueTemplateNoneSet : IssueTemplate
|
2021-04-12 22:36:10 +08:00
|
|
|
{
|
2021-04-12 23:28:12 +08:00
|
|
|
public IssueTemplateNoneSet(ICheck check)
|
2021-04-13 19:57:56 +08:00
|
|
|
: base(check, IssueType.Problem, "No background has been set.")
|
2021-04-12 22:36:10 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Issue Create() => new Issue(this);
|
|
|
|
}
|
|
|
|
|
2021-04-13 08:29:25 +08:00
|
|
|
public class IssueTemplateDoesNotExist : IssueTemplate
|
2021-04-12 22:36:10 +08:00
|
|
|
{
|
2021-04-12 23:28:12 +08:00
|
|
|
public IssueTemplateDoesNotExist(ICheck check)
|
|
|
|
: base(check, IssueType.Problem, "The background file \"{0}\" does not exist.")
|
2021-04-12 22:36:10 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Issue Create(string filename) => new Issue(this, filename);
|
|
|
|
}
|
2021-04-10 19:03:16 +08:00
|
|
|
}
|
|
|
|
}
|