2021-04-18 00:01:04 +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;
|
2021-11-10 12:06:11 +08:00
|
|
|
using System.IO;
|
2021-04-18 00:01:04 +08:00
|
|
|
using osu.Game.Rulesets.Edit.Checks.Components;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit.Checks
|
|
|
|
{
|
|
|
|
public class CheckBackgroundQuality : ICheck
|
|
|
|
{
|
|
|
|
// These are the requirements as stated in the Ranking Criteria.
|
|
|
|
// See https://osu.ppy.sh/wiki/en/Ranking_Criteria#rules.5
|
|
|
|
private const int min_width = 160;
|
|
|
|
private const int max_width = 2560;
|
|
|
|
private const int min_height = 120;
|
|
|
|
private const int max_height = 1440;
|
|
|
|
private const double max_filesize_mb = 2.5d;
|
|
|
|
|
|
|
|
// It's usually possible to find a higher resolution of the same image if lower than these.
|
|
|
|
private const int low_width = 960;
|
|
|
|
private const int low_height = 540;
|
|
|
|
|
|
|
|
public CheckMetadata Metadata { get; } = new CheckMetadata(CheckCategory.Resources, "Too high or low background resolution");
|
|
|
|
|
|
|
|
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
|
|
|
{
|
|
|
|
new IssueTemplateTooHighResolution(this),
|
|
|
|
new IssueTemplateTooLowResolution(this),
|
|
|
|
new IssueTemplateTooUncompressed(this)
|
|
|
|
};
|
|
|
|
|
2021-05-13 17:24:22 +08:00
|
|
|
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
2021-04-18 00:01:04 +08:00
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
string backgroundFile = context.Beatmap.Metadata?.BackgroundFile;
|
2021-04-18 07:19:25 +08:00
|
|
|
if (backgroundFile == null)
|
2021-04-18 00:01:04 +08:00
|
|
|
yield break;
|
|
|
|
|
2021-05-12 08:29:18 +08:00
|
|
|
var texture = context.WorkingBeatmap.Background;
|
2021-04-18 00:01:04 +08:00
|
|
|
if (texture == null)
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
if (texture.Width > max_width || texture.Height > max_height)
|
|
|
|
yield return new IssueTemplateTooHighResolution(this).Create(texture.Width, texture.Height);
|
|
|
|
|
|
|
|
if (texture.Width < min_width || texture.Height < min_height)
|
|
|
|
yield return new IssueTemplateTooLowResolution(this).Create(texture.Width, texture.Height);
|
2021-04-18 02:10:07 +08:00
|
|
|
else if (texture.Width < low_width || texture.Height < low_height)
|
2021-04-18 00:01:04 +08:00
|
|
|
yield return new IssueTemplateLowResolution(this).Create(texture.Width, texture.Height);
|
|
|
|
|
2022-01-12 21:34:07 +08:00
|
|
|
string storagePath = context.Beatmap.BeatmapInfo.BeatmapSet?.GetPathForFile(backgroundFile);
|
2021-04-18 00:01:04 +08:00
|
|
|
|
2021-11-10 12:06:11 +08:00
|
|
|
using (Stream stream = context.WorkingBeatmap.GetStream(storagePath))
|
|
|
|
{
|
|
|
|
double filesizeMb = stream.Length / (1024d * 1024d);
|
|
|
|
|
|
|
|
if (filesizeMb > max_filesize_mb)
|
|
|
|
yield return new IssueTemplateTooUncompressed(this).Create(filesizeMb);
|
|
|
|
}
|
2021-04-18 00:01:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public class IssueTemplateTooHighResolution : IssueTemplate
|
|
|
|
{
|
|
|
|
public IssueTemplateTooHighResolution(ICheck check)
|
|
|
|
: base(check, IssueType.Problem, "The background resolution ({0} x {1}) exceeds {2} x {3}.")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Issue Create(double width, double height) => new Issue(this, width, height, max_width, max_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class IssueTemplateTooLowResolution : IssueTemplate
|
|
|
|
{
|
|
|
|
public IssueTemplateTooLowResolution(ICheck check)
|
|
|
|
: base(check, IssueType.Problem, "The background resolution ({0} x {1}) is lower than {2} x {3}.")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Issue Create(double width, double height) => new Issue(this, width, height, min_width, min_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class IssueTemplateLowResolution : IssueTemplate
|
|
|
|
{
|
|
|
|
public IssueTemplateLowResolution(ICheck check)
|
|
|
|
: base(check, IssueType.Warning, "The background resolution ({0} x {1}) is lower than {2} x {3}.")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Issue Create(double width, double height) => new Issue(this, width, height, low_width, low_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class IssueTemplateTooUncompressed : IssueTemplate
|
|
|
|
{
|
|
|
|
public IssueTemplateTooUncompressed(ICheck check)
|
2021-04-20 07:34:05 +08:00
|
|
|
: base(check, IssueType.Problem, "The background filesize ({0:0.##} MB) exceeds {1} MB.")
|
2021-04-18 00:01:04 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Issue Create(double actualMb) => new Issue(this, actualMb, max_filesize_mb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|