2023-01-18 23:37:36 +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 osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets.Edit.Checks.Components;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit.Checks
|
|
|
|
|
{
|
|
|
|
|
public class CheckPreviewTime : ICheck
|
|
|
|
|
{
|
2023-02-01 11:52:14 +08:00
|
|
|
|
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Timing, "Inconsistent or unset preview time");
|
2023-01-18 23:37:36 +08:00
|
|
|
|
|
|
|
|
|
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
|
|
|
|
|
{
|
|
|
|
|
new IssueTemplatePreviewTimeConflict(this),
|
|
|
|
|
new IssueTemplateHasNoPreviewTime(this),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
|
|
|
|
|
{
|
|
|
|
|
var diffList = context.Beatmap.BeatmapInfo.BeatmapSet?.Beatmaps ?? new List<BeatmapInfo>();
|
|
|
|
|
int previewTime = context.Beatmap.BeatmapInfo.Metadata.PreviewTime;
|
|
|
|
|
|
|
|
|
|
if (previewTime == -1)
|
|
|
|
|
yield return new IssueTemplateHasNoPreviewTime(this).Create();
|
|
|
|
|
|
|
|
|
|
foreach (var diff in diffList)
|
|
|
|
|
{
|
|
|
|
|
if (diff.Equals(context.Beatmap.BeatmapInfo))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (diff.Metadata.PreviewTime != previewTime)
|
2023-01-23 14:26:28 +08:00
|
|
|
|
yield return new IssueTemplatePreviewTimeConflict(this).Create(diff.DifficultyName, previewTime, diff.Metadata.PreviewTime);
|
2023-01-18 23:37:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class IssueTemplatePreviewTimeConflict : IssueTemplate
|
|
|
|
|
{
|
|
|
|
|
public IssueTemplatePreviewTimeConflict(ICheck check)
|
2023-02-01 11:52:14 +08:00
|
|
|
|
: base(check, IssueType.Problem, "Audio preview time {1} doesn't match \"{0}\"'s preview time. {2}")
|
2023-01-18 23:37:36 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 14:26:28 +08:00
|
|
|
|
public Issue Create(string diffName, int originalTime, int conflictTime) =>
|
|
|
|
|
// preview time should show (not set) when it is not set.
|
|
|
|
|
new Issue(this, diffName,
|
|
|
|
|
originalTime != -1 ? $"({originalTime:N0})" : "(not set)",
|
|
|
|
|
conflictTime != -1 ? $"({conflictTime:N0})" : "(not set)");
|
2023-01-18 23:37:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class IssueTemplateHasNoPreviewTime : IssueTemplate
|
|
|
|
|
{
|
|
|
|
|
public IssueTemplateHasNoPreviewTime(ICheck check)
|
2023-02-01 11:52:14 +08:00
|
|
|
|
: base(check, IssueType.Problem, "A preview point for this map is not set. Consider settings one from the Timing menu.")
|
2023-01-18 23:37:36 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Issue Create() => new Issue(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|