1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 16:42:55 +08:00
osu-lazer/osu.Game/Rulesets/Edit/Checks/CheckUnusedAudioAtEnd.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
3.0 KiB
C#
Raw Normal View History

// 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;
using System.Collections.Generic;
2024-03-20 02:17:22 +08:00
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
using osu.Game.Storyboards;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckUnusedAudioAtEnd : ICheck
{
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Compose, "More than 20% unused audio at the end");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateUnusedAudioAtEnd(this),
new IssueTemplateUnusedAudioAtEndStoryboardOrVideo(this),
};
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
2024-03-20 02:17:22 +08:00
double mappedLength = context.Beatmap.HitObjects.Any() ? context.Beatmap.GetLastObjectTime() : 0;
double trackLength = context.WorkingBeatmap.Track.Length;
2024-03-19 00:27:43 +08:00
double mappedPercentage = Math.Round(mappedLength / trackLength * 100);
if (mappedPercentage < 80)
{
double percentageLeft = Math.Abs(mappedPercentage - 100);
bool storyboardIsPresent = isAnyStoryboardElementPresent(context.WorkingBeatmap.Storyboard);
if (storyboardIsPresent)
{
yield return new IssueTemplateUnusedAudioAtEndStoryboardOrVideo(this).Create(percentageLeft);
}
else
{
yield return new IssueTemplateUnusedAudioAtEnd(this).Create(percentageLeft);
}
}
}
private bool isAnyStoryboardElementPresent(Storyboard storyboard)
{
foreach (var layer in storyboard.Layers)
{
foreach (var _ in layer.Elements)
{
return true;
}
}
return false;
}
public class IssueTemplateUnusedAudioAtEnd : IssueTemplate
{
public IssueTemplateUnusedAudioAtEnd(ICheck check)
: base(check, IssueType.Warning, "Currently there is {0}% unused audio at the end. Ensure the outro significantly contributes to the song, otherwise cut the outro.")
{
}
public Issue Create(double percentageLeft) => new Issue(this, percentageLeft);
}
public class IssueTemplateUnusedAudioAtEndStoryboardOrVideo : IssueTemplate
{
public IssueTemplateUnusedAudioAtEndStoryboardOrVideo(ICheck check)
: base(check, IssueType.Warning, "Currently there is {0}% unused audio at the end. Ensure the outro significantly contributes to the song, or is being occupied by the video or storyboard, otherwise cut the outro.")
{
}
public Issue Create(double percentageLeft) => new Issue(this, percentageLeft);
}
}
}