1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 23:05:37 +08:00

Move IBeatmap arg into context

This commit is contained in:
Naxess 2021-05-13 11:24:22 +02:00
parent b37cb3bdbe
commit 19800f5f7f
18 changed files with 76 additions and 78 deletions

View File

@ -225,14 +225,14 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
private void assertOk(IBeatmap beatmap)
{
var context = new BeatmapVerifierContext(new TestWorkingBeatmap(beatmap));
Assert.That(check.Run(beatmap, context), Is.Empty);
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
Assert.That(check.Run(context), Is.Empty);
}
private void assertOffscreenCircle(IBeatmap beatmap)
{
var context = new BeatmapVerifierContext(new TestWorkingBeatmap(beatmap));
var issues = check.Run(beatmap, context).ToList();
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckOffscreenObjects.IssueTemplateOffscreenCircle);
@ -240,8 +240,8 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
private void assertOffscreenSlider(IBeatmap beatmap)
{
var context = new BeatmapVerifierContext(new TestWorkingBeatmap(beatmap));
var issues = check.Run(beatmap, context).ToList();
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckOffscreenObjects.IssueTemplateOffscreenSlider);

View File

@ -2,7 +2,6 @@
// 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;
using osu.Game.Rulesets.Edit.Checks.Components;
using osu.Game.Rulesets.Osu.Objects;
@ -32,9 +31,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Checks
new IssueTemplateOffscreenSlider(this)
};
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context)
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
foreach (var hitobject in beatmap.HitObjects)
foreach (var hitobject in context.Beatmap.HitObjects)
{
switch (hitobject)
{

View File

@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Checks.Components;
using osu.Game.Rulesets.Osu.Edit.Checks;
@ -17,9 +16,9 @@ namespace osu.Game.Rulesets.Osu.Edit
new CheckOffscreenObjects()
};
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context)
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
return checks.SelectMany(check => check.Run(beatmap, context));
return checks.SelectMany(check => check.Run(context));
}
}
}

View File

@ -41,7 +41,7 @@ namespace osu.Game.Tests.Editing.Checks
mock.SetupGet(w => w.Beatmap).Returns(beatmap);
mock.SetupGet(w => w.Track).Returns((Track)null);
Assert.That(check.Run(beatmap, new BeatmapVerifierContext(mock.Object)), Is.Empty);
Assert.That(check.Run(new BeatmapVerifierContext(beatmap, mock.Object)), Is.Empty);
}
[Test]
@ -49,7 +49,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(192);
Assert.That(check.Run(beatmap, context), Is.Empty);
Assert.That(check.Run(context), Is.Empty);
}
[Test]
@ -57,7 +57,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(null);
var issues = check.Run(beatmap, context).ToList();
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateNoBitrate);
@ -68,7 +68,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(0);
var issues = check.Run(beatmap, context).ToList();
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateNoBitrate);
@ -79,7 +79,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(320);
var issues = check.Run(beatmap, context).ToList();
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateTooHighBitrate);
@ -90,7 +90,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(64);
var issues = check.Run(beatmap, context).ToList();
var issues = check.Run( context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateTooLowBitrate);
@ -98,7 +98,7 @@ namespace osu.Game.Tests.Editing.Checks
private BeatmapVerifierContext getContext(int? audioBitrate)
{
return new BeatmapVerifierContext(getMockWorkingBeatmap(audioBitrate).Object);
return new BeatmapVerifierContext(beatmap, getMockWorkingBeatmap(audioBitrate).Object);
}
/// <summary>

View File

@ -56,7 +56,7 @@ namespace osu.Game.Tests.Editing.Checks
beatmap.Metadata.BackgroundFile = null;
var context = getContext(null, System.Array.Empty<byte>());
Assert.That(check.Run(beatmap, context), Is.Empty);
Assert.That(check.Run(context), Is.Empty);
}
[Test]
@ -64,7 +64,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(new Texture(1920, 1080));
Assert.That(check.Run(beatmap, context), Is.Empty);
Assert.That(check.Run(context), Is.Empty);
}
[Test]
@ -72,7 +72,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(new Texture(3840, 2160));
var issues = check.Run(beatmap, context).ToList();
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateTooHighResolution);
@ -83,7 +83,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(new Texture(640, 480));
var issues = check.Run(beatmap, context).ToList();
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateLowResolution);
@ -94,7 +94,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(new Texture(100, 100));
var issues = check.Run(beatmap, context).ToList();
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateTooLowResolution);
@ -105,7 +105,7 @@ namespace osu.Game.Tests.Editing.Checks
{
var context = getContext(new Texture(1920, 1080), new byte[1024 * 1024 * 3]);
var issues = check.Run(beatmap, context).ToList();
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateTooUncompressed);
@ -113,7 +113,7 @@ namespace osu.Game.Tests.Editing.Checks
private BeatmapVerifierContext getContext(Texture background, [CanBeNull] byte[] fileBytes = null)
{
return new BeatmapVerifierContext(getMockWorkingBeatmap(background, fileBytes).Object);
return new BeatmapVerifierContext(beatmap, getMockWorkingBeatmap(background, fileBytes).Object);
}
/// <summary>

View File

@ -6,6 +6,7 @@ using System.Linq;
using Moq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Checks;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects;
@ -105,7 +106,7 @@ namespace osu.Game.Tests.Editing.Checks
new HitCircle { StartTime = 300 }
};
var issues = check.Run(getPlayableBeatmap(hitobjects), null).ToList();
var issues = check.Run(getContext(hitobjects)).ToList();
Assert.That(issues, Has.Count.EqualTo(3));
Assert.That(issues.Where(issue => issue.Template is CheckConcurrentObjects.IssueTemplateConcurrentDifferent).ToList(), Has.Count.EqualTo(2));
@ -164,12 +165,12 @@ namespace osu.Game.Tests.Editing.Checks
private void assertOk(List<HitObject> hitobjects)
{
Assert.That(check.Run(getPlayableBeatmap(hitobjects), null), Is.Empty);
Assert.That(check.Run(getContext(hitobjects)), Is.Empty);
}
private void assertConcurrentSame(List<HitObject> hitobjects, int count = 1)
{
var issues = check.Run(getPlayableBeatmap(hitobjects), null).ToList();
var issues = check.Run(getContext(hitobjects)).ToList();
Assert.That(issues, Has.Count.EqualTo(count));
Assert.That(issues.All(issue => issue.Template is CheckConcurrentObjects.IssueTemplateConcurrentSame));
@ -177,18 +178,18 @@ namespace osu.Game.Tests.Editing.Checks
private void assertConcurrentDifferent(List<HitObject> hitobjects, int count = 1)
{
var issues = check.Run(getPlayableBeatmap(hitobjects), null).ToList();
var issues = check.Run(getContext(hitobjects)).ToList();
Assert.That(issues, Has.Count.EqualTo(count));
Assert.That(issues.All(issue => issue.Template is CheckConcurrentObjects.IssueTemplateConcurrentDifferent));
}
private IBeatmap getPlayableBeatmap(List<HitObject> hitobjects)
private BeatmapVerifierContext getContext(List<HitObject> hitobjects)
{
return new Beatmap<HitObject>
return new BeatmapVerifierContext(new Beatmap<HitObject>
{
HitObjects = hitobjects
};
}, null);
}
}
}

View File

@ -46,8 +46,8 @@ namespace osu.Game.Tests.Editing.Checks
[Test]
public void TestBackgroundSetAndInFiles()
{
var context = new BeatmapVerifierContext(new TestWorkingBeatmap(beatmap));
Assert.That(check.Run(beatmap, context), Is.Empty);
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
Assert.That(check.Run(context), Is.Empty);
}
[Test]
@ -55,8 +55,8 @@ namespace osu.Game.Tests.Editing.Checks
{
beatmap.BeatmapInfo.BeatmapSet.Files.Clear();
var context = new BeatmapVerifierContext(new TestWorkingBeatmap(beatmap));
var issues = check.Run(beatmap, context).ToList();
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckFilePresence.IssueTemplateDoesNotExist);
@ -67,8 +67,8 @@ namespace osu.Game.Tests.Editing.Checks
{
beatmap.Metadata.BackgroundFile = null;
var context = new BeatmapVerifierContext(new TestWorkingBeatmap(beatmap));
var issues = check.Run(beatmap, context).ToList();
var context = new BeatmapVerifierContext(beatmap, new TestWorkingBeatmap(beatmap));
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckFilePresence.IssueTemplateNoneSet);

View File

@ -7,6 +7,7 @@ using Moq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Checks;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
@ -105,7 +106,7 @@ namespace osu.Game.Tests.Editing.Checks
getSliderMock(startTime: 98, endTime: 398.75d).Object
};
var issues = check.Run(getPlayableBeatmap(hitobjects), null).ToList();
var issues = check.Run(getContext(hitobjects)).ToList();
Assert.That(issues, Has.Count.EqualTo(2));
Assert.That(issues.Any(issue => issue.Template is CheckUnsnappedObjects.IssueTemplateSmallUnsnap));
@ -124,12 +125,12 @@ namespace osu.Game.Tests.Editing.Checks
private void assertOk(List<HitObject> hitobjects)
{
Assert.That(check.Run(getPlayableBeatmap(hitobjects), null), Is.Empty);
Assert.That(check.Run(getContext(hitobjects)), Is.Empty);
}
private void assert1Ms(List<HitObject> hitobjects, int count = 1)
{
var issues = check.Run(getPlayableBeatmap(hitobjects), null).ToList();
var issues = check.Run(getContext(hitobjects)).ToList();
Assert.That(issues, Has.Count.EqualTo(count));
Assert.That(issues.All(issue => issue.Template is CheckUnsnappedObjects.IssueTemplateSmallUnsnap));
@ -137,19 +138,19 @@ namespace osu.Game.Tests.Editing.Checks
private void assert2Ms(List<HitObject> hitobjects, int count = 1)
{
var issues = check.Run(getPlayableBeatmap(hitobjects), null).ToList();
var issues = check.Run(getContext(hitobjects)).ToList();
Assert.That(issues, Has.Count.EqualTo(count));
Assert.That(issues.All(issue => issue.Template is CheckUnsnappedObjects.IssueTemplateLargeUnsnap));
}
private IBeatmap getPlayableBeatmap(List<HitObject> hitobjects)
private BeatmapVerifierContext getContext(List<HitObject> hitobjects)
{
return new Beatmap<HitObject>
return new BeatmapVerifierContext(new Beatmap<HitObject>
{
ControlPointInfo = cpi,
HitObjects = hitobjects
};
}, null);
}
}
}

View File

@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks;
using osu.Game.Rulesets.Edit.Checks.Components;
@ -29,9 +28,9 @@ namespace osu.Game.Rulesets.Edit
new CheckConcurrentObjects()
};
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context)
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
return checks.SelectMany(check => check.Run(beatmap, context));
return checks.SelectMany(check => check.Run(context));
}
}
}

View File

@ -11,6 +11,11 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
public class BeatmapVerifierContext
{
/// <summary>
/// The playable beatmap instance of the current beatmap.
/// </summary>
public readonly IBeatmap Beatmap;
/// <summary>
/// The working beatmap instance of the current beatmap.
/// </summary>
@ -21,8 +26,9 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
public DifficultyRating InterpretedDifficulty;
public BeatmapVerifierContext(IWorkingBeatmap workingBeatmap, DifficultyRating difficultyRating = DifficultyRating.ExpertPlus)
public BeatmapVerifierContext(IBeatmap beatmap, IWorkingBeatmap workingBeatmap, DifficultyRating difficultyRating = DifficultyRating.ExpertPlus)
{
Beatmap = beatmap;
WorkingBeatmap = workingBeatmap;
InterpretedDifficulty = difficultyRating;
}

View File

@ -2,7 +2,6 @@
// 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
@ -26,9 +25,9 @@ namespace osu.Game.Rulesets.Edit.Checks
new IssueTemplateNoBitrate(this)
};
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context)
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var audioFile = beatmap.Metadata?.AudioFile;
var audioFile = context.Beatmap.Metadata?.AudioFile;
if (audioFile == null)
yield break;

View File

@ -2,7 +2,6 @@
// 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
@ -30,9 +29,9 @@ namespace osu.Game.Rulesets.Edit.Checks
new IssueTemplateTooUncompressed(this)
};
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context)
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var backgroundFile = beatmap.Metadata?.BackgroundFile;
var backgroundFile = context.Beatmap.Metadata?.BackgroundFile;
if (backgroundFile == null)
yield break;
@ -48,7 +47,7 @@ namespace osu.Game.Rulesets.Edit.Checks
else if (texture.Width < low_width || texture.Height < low_height)
yield return new IssueTemplateLowResolution(this).Create(texture.Width, texture.Height);
string storagePath = beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile);
string storagePath = context.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile);
double filesizeMb = context.WorkingBeatmap.GetStream(storagePath).Length / (1024d * 1024d);
if (filesizeMb > max_filesize_mb)

View File

@ -2,7 +2,6 @@
// 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;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
@ -22,15 +21,15 @@ namespace osu.Game.Rulesets.Edit.Checks
new IssueTemplateConcurrentDifferent(this)
};
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context)
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
for (int i = 0; i < beatmap.HitObjects.Count - 1; ++i)
for (int i = 0; i < context.Beatmap.HitObjects.Count - 1; ++i)
{
var hitobject = beatmap.HitObjects[i];
var hitobject = context.Beatmap.HitObjects[i];
for (int j = i + 1; j < beatmap.HitObjects.Count; ++j)
for (int j = i + 1; j < context.Beatmap.HitObjects.Count; ++j)
{
var nextHitobject = beatmap.HitObjects[j];
var nextHitobject = context.Beatmap.HitObjects[j];
// Accounts for rulesets with hitobjects separated by columns, such as Mania.
// In these cases we only care about concurrent objects within the same column.

View File

@ -21,9 +21,9 @@ namespace osu.Game.Rulesets.Edit.Checks
new IssueTemplateDoesNotExist(this)
};
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context)
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var filename = GetFilename(beatmap);
var filename = GetFilename(context.Beatmap);
if (filename == null)
{
@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Edit.Checks
}
// If the file is set, also make sure it still exists.
var storagePath = beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(filename);
var storagePath = context.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(filename);
if (storagePath != null)
yield break;

View File

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
@ -22,11 +21,11 @@ namespace osu.Game.Rulesets.Edit.Checks
new IssueTemplateSmallUnsnap(this)
};
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context)
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var controlPointInfo = beatmap.ControlPointInfo;
var controlPointInfo = context.Beatmap.ControlPointInfo;
foreach (var hitobject in beatmap.HitObjects)
foreach (var hitobject in context.Beatmap.HitObjects)
{
double startUnsnap = hitobject.StartTime - controlPointInfo.GetClosestSnappedTime(hitobject.StartTime);
string startPostfix = hitobject is IHasDuration ? "start" : "";

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Game.Beatmaps;
namespace osu.Game.Rulesets.Edit.Checks.Components
{
@ -24,8 +23,7 @@ namespace osu.Game.Rulesets.Edit.Checks.Components
/// <summary>
/// Runs this check and returns any issues detected for the provided beatmap.
/// </summary>
/// <param name="beatmap">The playable beatmap of the beatmap to run the check on.</param>
/// <param name="context">The beatmap verifier context associated with the beatmap.</param>
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context);
public IEnumerable<Issue> Run(BeatmapVerifierContext context);
}
}

View File

@ -2,7 +2,6 @@
// 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
@ -12,6 +11,6 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
public interface IBeatmapVerifier
{
public IEnumerable<Issue> Run(IBeatmap beatmap, BeatmapVerifierContext context);
public IEnumerable<Issue> Run(BeatmapVerifierContext context);
}
}

View File

@ -45,7 +45,7 @@ namespace osu.Game.Screens.Edit.Verify
generalVerifier = new BeatmapVerifier();
rulesetVerifier = beatmap.BeatmapInfo.Ruleset?.CreateInstance()?.CreateBeatmapVerifier();
context = new BeatmapVerifierContext(workingBeatmap.Value, verify.InterpretedDifficulty.Value);
context = new BeatmapVerifierContext(beatmap, workingBeatmap.Value, verify.InterpretedDifficulty.Value);
verify.InterpretedDifficulty.BindValueChanged(change =>
{
context.InterpretedDifficulty = change.NewValue;
@ -98,10 +98,10 @@ namespace osu.Game.Screens.Edit.Verify
private void refresh()
{
var issues = generalVerifier.Run(beatmap, context);
var issues = generalVerifier.Run(context);
if (rulesetVerifier != null)
issues = issues.Concat(rulesetVerifier.Run(beatmap, context));
issues = issues.Concat(rulesetVerifier.Run(context));
issues = filter(issues);