2024-03-16 21:20:12 -03: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 ;
using System.Collections.Generic ;
2024-03-19 19:17:22 +01:00
using System.Linq ;
2024-03-18 14:02:33 -03:00
using osu.Game.Beatmaps ;
2024-03-16 21:20:12 -03:00
using osu.Game.Rulesets.Edit.Checks.Components ;
2024-03-18 16:08:41 -03:00
using osu.Game.Storyboards ;
2024-03-16 21:20:12 -03:00
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 ) ,
2024-03-18 16:08:41 -03:00
new IssueTemplateUnusedAudioAtEndStoryboardOrVideo ( this ) ,
2024-03-16 21:20:12 -03:00
} ;
public IEnumerable < Issue > Run ( BeatmapVerifierContext context )
{
2024-03-19 19:17:22 +01:00
double mappedLength = context . Beatmap . HitObjects . Any ( ) ? context . Beatmap . GetLastObjectTime ( ) : 0 ;
2024-03-16 21:20:12 -03:00
double trackLength = context . WorkingBeatmap . Track . Length ;
2024-03-18 13:27:43 -03:00
double mappedPercentage = Math . Round ( mappedLength / trackLength * 100 ) ;
2024-03-16 21:20:12 -03:00
if ( mappedPercentage < 80 )
{
2024-03-18 13:51:36 -03:00
double percentageLeft = Math . Abs ( mappedPercentage - 100 ) ;
2024-03-18 16:08:41 -03:00
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 ;
}
2024-03-16 21:20:12 -03:00
}
2024-03-18 16:08:41 -03:00
return false ;
2024-03-16 21:20:12 -03:00
}
public class IssueTemplateUnusedAudioAtEnd : IssueTemplate
{
public IssueTemplateUnusedAudioAtEnd ( ICheck check )
2024-03-18 13:51:36 -03:00
: 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." )
2024-03-16 21:20:12 -03:00
{
}
2024-03-18 13:51:36 -03:00
public Issue Create ( double percentageLeft ) = > new Issue ( this , percentageLeft ) ;
2024-03-16 21:20:12 -03:00
}
2024-03-18 16:08:41 -03:00
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 ) ;
}
2024-03-16 21:20:12 -03:00
}
}