From abf512532e2f8d7e79d8b8fafe419b651fb1f896 Mon Sep 17 00:00:00 2001 From: Naxess <30292137+Naxesss@users.noreply.github.com> Date: Sun, 18 Apr 2021 01:19:25 +0200 Subject: [PATCH] Clean up check logic Makes use of the new `BeatmapSet.GetPathForFile` method and removes dependency on `WorkingBeatmap` specifically, allowing us to switch to `IWorkingBeatmap` later. --- osu.Game/Rulesets/Edit/Checks/CheckBackground.cs | 14 ++++++-------- .../Rulesets/Edit/Checks/CheckBackgroundQuality.cs | 5 +++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/osu.Game/Rulesets/Edit/Checks/CheckBackground.cs b/osu.Game/Rulesets/Edit/Checks/CheckBackground.cs index d2fffeea4e..637e603e17 100644 --- a/osu.Game/Rulesets/Edit/Checks/CheckBackground.cs +++ b/osu.Game/Rulesets/Edit/Checks/CheckBackground.cs @@ -2,7 +2,6 @@ // 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; @@ -20,7 +19,9 @@ namespace osu.Game.Rulesets.Edit.Checks public IEnumerable Run(WorkingBeatmap workingBeatmap) { - if (workingBeatmap.Metadata?.BackgroundFile == null) + string backgroundFile = workingBeatmap.Beatmap.Metadata?.BackgroundFile; + + if (backgroundFile == null) { yield return new IssueTemplateNoneSet(this).Create(); @@ -28,14 +29,11 @@ namespace osu.Game.Rulesets.Edit.Checks } // If the background is set, also make sure it still exists. - - var set = workingBeatmap.BeatmapInfo.BeatmapSet; - var file = set.Files.FirstOrDefault(f => f.Filename == workingBeatmap.Metadata.BackgroundFile); - - if (file != null) + var storagePath = workingBeatmap.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile); + if (storagePath != null) yield break; - yield return new IssueTemplateDoesNotExist(this).Create(workingBeatmap.Metadata.BackgroundFile); + yield return new IssueTemplateDoesNotExist(this).Create(backgroundFile); } public class IssueTemplateNoneSet : IssueTemplate diff --git a/osu.Game/Rulesets/Edit/Checks/CheckBackgroundQuality.cs b/osu.Game/Rulesets/Edit/Checks/CheckBackgroundQuality.cs index a3f363554e..48d536079a 100644 --- a/osu.Game/Rulesets/Edit/Checks/CheckBackgroundQuality.cs +++ b/osu.Game/Rulesets/Edit/Checks/CheckBackgroundQuality.cs @@ -32,7 +32,8 @@ namespace osu.Game.Rulesets.Edit.Checks public IEnumerable Run(WorkingBeatmap workingBeatmap) { - if (workingBeatmap.Metadata?.BackgroundFile == null) + var backgroundFile = workingBeatmap.Beatmap.Metadata?.BackgroundFile; + if (backgroundFile == null) yield break; var texture = workingBeatmap.Background; @@ -47,7 +48,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 = workingBeatmap.BeatmapInfo.BeatmapSet.GetPathForFile(workingBeatmap.Metadata.BackgroundFile); + string storagePath = workingBeatmap.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile); double filesizeMb = workingBeatmap.GetStream(storagePath).Length / (1024d * 1024d); if (filesizeMb > max_filesize_mb)