1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 06:47:25 +08:00
osu-lazer/osu.Game/Rulesets/Edit/Checks/CheckBackground.cs

58 lines
1.7 KiB
C#
Raw Normal View History

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
{
public class CheckBackground : ICheck
2021-04-10 19:03:16 +08:00
{
public CheckMetadata Metadata { get; } = new CheckMetadata
2021-04-10 19:03:16 +08:00
(
2021-04-12 14:32:52 +08:00
category: CheckCategory.Resources,
2021-04-10 19:03:16 +08:00
description: "Missing background."
);
public IEnumerable<IssueTemplate> PossibleTemplates => new[]
2021-04-10 19:03:16 +08:00
{
templateNoneSet,
templateDoesNotExist
};
private readonly IssueTemplate templateNoneSet = new IssueTemplate
(
2021-04-12 14:32:52 +08:00
type: IssueType.Problem,
2021-04-10 19:03:16 +08:00
unformattedMessage: "No background has been set."
);
private readonly IssueTemplate templateDoesNotExist = new IssueTemplate
(
2021-04-12 14:32:52 +08:00
type: IssueType.Problem,
2021-04-10 19:03:16 +08:00
unformattedMessage: "The background file \"{0}\" is does not exist."
);
public IEnumerable<Issue> Run(IBeatmap beatmap)
2021-04-10 19:03:16 +08:00
{
if (beatmap.Metadata.BackgroundFile == null)
{
yield return new Issue(this, templateNoneSet);
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;
yield return new Issue(this, templateDoesNotExist, beatmap.Metadata.BackgroundFile);
2021-04-10 19:03:16 +08:00
}
}
}