1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 02:02:53 +08:00

Add beatmap extension for calculating length

This commit is contained in:
iiSaLMaN 2019-07-07 18:25:52 +03:00
parent 188c80374e
commit 65c8249c94
2 changed files with 13 additions and 4 deletions

View File

@ -8,6 +8,7 @@ using System.Linq;
using osu.Game.Beatmaps.ControlPoints;
using Newtonsoft.Json;
using osu.Game.IO.Serialization.Converters;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Beatmaps
{
@ -61,4 +62,15 @@ namespace osu.Game.Beatmaps
{
public new Beatmap Clone() => (Beatmap)base.Clone();
}
public static class BeatmapExtensions
{
public static double CalculateLength(this IBeatmap b)
{
HitObject lastObject = b.HitObjects.LastOrDefault();
var endTime = (lastObject as IHasEndTime)?.EndTime ?? lastObject?.StartTime ?? 0;
return endTime - b.HitObjects.FirstOrDefault()?.StartTime ?? 0;
}
}
}

View File

@ -289,14 +289,11 @@ namespace osu.Game.Screens.Select
if (b?.HitObjects?.Any() == true)
{
HitObject lastObject = b.HitObjects.LastOrDefault();
double endTime = (lastObject as IHasEndTime)?.EndTime ?? lastObject?.StartTime ?? 0;
labels.Add(new InfoLabel(new BeatmapStatistic
{
Name = "Length",
Icon = FontAwesome.Regular.Clock,
Content = TimeSpan.FromMilliseconds(endTime - b.HitObjects.First().StartTime).ToString(@"m\:ss"),
Content = TimeSpan.FromMilliseconds(b.CalculateLength()).ToString(@"m\:ss"),
}));
labels.Add(new InfoLabel(new BeatmapStatistic