mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 07:23:14 +08:00
Factor out general file presence checking
This allows us to use the same method of checking for other files that should exist, for example the audio file. By using the same method, they all share test cases too.
This commit is contained in:
parent
0502fbb429
commit
010720de74
@ -12,15 +12,15 @@ using osu.Game.Tests.Beatmaps;
|
||||
namespace osu.Game.Tests.Editing.Checks
|
||||
{
|
||||
[TestFixture]
|
||||
public class CheckBackgroundTest
|
||||
public class CheckFilePresenceTest
|
||||
{
|
||||
private CheckBackground check;
|
||||
private CheckBackgroundPresence check;
|
||||
private WorkingBeatmap beatmap;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
check = new CheckBackground();
|
||||
check = new CheckBackgroundPresence();
|
||||
beatmap = new TestWorkingBeatmap(new Beatmap<HitObject>
|
||||
{
|
||||
BeatmapInfo = new BeatmapInfo
|
||||
@ -51,7 +51,7 @@ namespace osu.Game.Tests.Editing.Checks
|
||||
var issues = check.Run(beatmap).ToList();
|
||||
|
||||
Assert.That(issues, Has.Count.EqualTo(1));
|
||||
Assert.That(issues.Single().Template is CheckBackground.IssueTemplateDoesNotExist);
|
||||
Assert.That(issues.Single().Template is CheckFilePresence.IssueTemplateDoesNotExist);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -62,7 +62,7 @@ namespace osu.Game.Tests.Editing.Checks
|
||||
var issues = check.Run(beatmap).ToList();
|
||||
|
||||
Assert.That(issues, Has.Count.EqualTo(1));
|
||||
Assert.That(issues.Single().Template is CheckBackground.IssueTemplateNoneSet);
|
||||
Assert.That(issues.Single().Template is CheckFilePresence.IssueTemplateNoneSet);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,8 +16,11 @@ namespace osu.Game.Rulesets.Edit
|
||||
{
|
||||
private readonly List<ICheck> checks = new List<ICheck>
|
||||
{
|
||||
new CheckBackground(),
|
||||
new CheckBackgroundQuality()
|
||||
// Resources
|
||||
new CheckBackgroundPresence(),
|
||||
new CheckBackgroundQuality(),
|
||||
// Audio
|
||||
new CheckAudioPresence(),
|
||||
};
|
||||
|
||||
public IEnumerable<Issue> Run(WorkingBeatmap workingBeatmap) => checks.SelectMany(check => check.Run(workingBeatmap));
|
||||
|
15
osu.Game/Rulesets/Edit/Checks/CheckBackgroundPresence.cs
Normal file
15
osu.Game/Rulesets/Edit/Checks/CheckBackgroundPresence.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// 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 osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit.Checks
|
||||
{
|
||||
public class CheckBackgroundPresence : CheckFilePresence
|
||||
{
|
||||
protected override CheckCategory Category => CheckCategory.Resources;
|
||||
protected override string TypeOfFile => "background";
|
||||
protected override string GetFilename(IWorkingBeatmap workingBeatmap) => workingBeatmap.Beatmap.Metadata?.BackgroundFile;
|
||||
}
|
||||
}
|
@ -7,9 +7,13 @@ using osu.Game.Rulesets.Edit.Checks.Components;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit.Checks
|
||||
{
|
||||
public class CheckBackground : ICheck
|
||||
public abstract class CheckFilePresence : ICheck
|
||||
{
|
||||
public CheckMetadata Metadata { get; } = new CheckMetadata(CheckCategory.Resources, "Missing background");
|
||||
protected abstract CheckCategory Category { get; }
|
||||
protected abstract string TypeOfFile { get; }
|
||||
protected abstract string GetFilename(IWorkingBeatmap workingBeatmap);
|
||||
|
||||
public CheckMetadata Metadata => new CheckMetadata(Category, $"Missing {TypeOfFile}");
|
||||
|
||||
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
||||
{
|
||||
@ -19,41 +23,41 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
|
||||
public IEnumerable<Issue> Run(IWorkingBeatmap workingBeatmap)
|
||||
{
|
||||
string backgroundFile = workingBeatmap.Beatmap.Metadata?.BackgroundFile;
|
||||
var filename = GetFilename(workingBeatmap);
|
||||
|
||||
if (backgroundFile == null)
|
||||
if (filename == null)
|
||||
{
|
||||
yield return new IssueTemplateNoneSet(this).Create();
|
||||
yield return new IssueTemplateNoneSet(this).Create(TypeOfFile);
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
// If the background is set, also make sure it still exists.
|
||||
var storagePath = workingBeatmap.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile);
|
||||
// If the file is set, also make sure it still exists.
|
||||
var storagePath = workingBeatmap.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(filename);
|
||||
if (storagePath != null)
|
||||
yield break;
|
||||
|
||||
yield return new IssueTemplateDoesNotExist(this).Create(backgroundFile);
|
||||
yield return new IssueTemplateDoesNotExist(this).Create(TypeOfFile, filename);
|
||||
}
|
||||
|
||||
public class IssueTemplateNoneSet : IssueTemplate
|
||||
{
|
||||
public IssueTemplateNoneSet(ICheck check)
|
||||
: base(check, IssueType.Problem, "No background has been set.")
|
||||
: base(check, IssueType.Problem, "No {0} has been set.")
|
||||
{
|
||||
}
|
||||
|
||||
public Issue Create() => new Issue(this);
|
||||
public Issue Create(string typeOfFile) => new Issue(this, typeOfFile);
|
||||
}
|
||||
|
||||
public class IssueTemplateDoesNotExist : IssueTemplate
|
||||
{
|
||||
public IssueTemplateDoesNotExist(ICheck check)
|
||||
: base(check, IssueType.Problem, "The background file \"{0}\" does not exist.")
|
||||
: base(check, IssueType.Problem, "The {0} file \"{1}\" does not exist.")
|
||||
{
|
||||
}
|
||||
|
||||
public Issue Create(string filename) => new Issue(this, filename);
|
||||
public Issue Create(string typeOfFile, string filename) => new Issue(this, typeOfFile, filename);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user