2019-01-24 16:43:03 +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.
2018-04-13 17:19:50 +08:00
2021-02-08 17:52:50 +08:00
using System ;
2016-08-31 12:51:00 +08:00
using osu.Game.Beatmaps.Timing ;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects ;
2017-03-11 23:34:21 +08:00
using System.Collections.Generic ;
2017-05-22 09:12:33 +08:00
using System.Linq ;
2017-05-23 12:55:18 +08:00
using osu.Game.Beatmaps.ControlPoints ;
2017-12-05 23:37:37 +08:00
using Newtonsoft.Json ;
using osu.Game.IO.Serialization.Converters ;
2018-04-13 17:19:50 +08:00
2016-08-31 11:33:01 +08:00
namespace osu.Game.Beatmaps
{
2019-08-28 19:19:22 +08:00
public class Beatmap < T > : IBeatmap < T >
2017-03-11 23:34:21 +08:00
where T : HitObject
{
2021-10-02 11:34:29 +08:00
private BeatmapDifficulty difficulty = new BeatmapDifficulty ( ) ;
public BeatmapDifficulty Difficulty
{
get = > difficulty ;
set
{
difficulty = value ;
2023-11-23 16:28:16 +08:00
beatmapInfo . Difficulty = difficulty . Clone ( ) ;
2021-10-02 11:34:29 +08:00
}
}
private BeatmapInfo beatmapInfo ;
public BeatmapInfo BeatmapInfo
{
get = > beatmapInfo ;
set
{
beatmapInfo = value ;
2023-11-23 16:28:16 +08:00
Difficulty = beatmapInfo . Difficulty . Clone ( ) ;
2021-10-02 11:34:29 +08:00
}
}
public Beatmap ( )
2018-04-19 17:14:21 +08:00
{
2021-10-02 11:34:29 +08:00
beatmapInfo = new BeatmapInfo
2018-04-19 17:14:21 +08:00
{
2021-10-02 11:34:29 +08:00
Metadata = new BeatmapMetadata
{
Artist = @"Unknown" ,
Title = @"Unknown" ,
2022-01-18 22:30:40 +08:00
Author = { Username = @"Unknown Creator" } ,
2021-10-02 11:34:29 +08:00
} ,
2021-11-11 16:19:53 +08:00
DifficultyName = @"Normal" ,
2022-01-18 21:57:39 +08:00
Difficulty = Difficulty ,
2021-10-02 11:34:29 +08:00
} ;
}
2018-04-13 17:19:50 +08:00
2017-12-05 23:37:37 +08:00
[JsonIgnore]
2021-11-24 11:16:08 +08:00
public BeatmapMetadata Metadata = > BeatmapInfo . Metadata ;
2018-04-13 17:19:50 +08:00
2018-04-19 17:14:21 +08:00
public ControlPointInfo ControlPointInfo { get ; set ; } = new ControlPointInfo ( ) ;
2024-07-02 10:13:20 +08:00
public List < BreakPeriod > Breaks { get ; set ; } = new List < BreakPeriod > ( ) ;
2018-04-13 17:19:50 +08:00
2024-04-29 22:26:44 +08:00
public List < string > UnhandledEventLines { get ; set ; } = new List < string > ( ) ;
2017-12-07 13:40:28 +08:00
[JsonIgnore]
2017-05-22 09:12:33 +08:00
public double TotalBreakTime = > Breaks . Sum ( b = > b . Duration ) ;
2018-04-13 17:19:50 +08:00
2018-04-19 17:14:21 +08:00
[JsonConverter(typeof(TypedListConverter<HitObject>))]
2019-08-28 19:19:22 +08:00
public List < T > HitObjects { get ; set ; } = new List < T > ( ) ;
IReadOnlyList < T > IBeatmap < T > . HitObjects = > HitObjects ;
2018-04-19 17:14:21 +08:00
2018-10-11 18:53:07 +08:00
IReadOnlyList < HitObject > IBeatmap . HitObjects = > HitObjects ;
2018-04-19 17:14:21 +08:00
2018-05-07 09:51:17 +08:00
public virtual IEnumerable < BeatmapStatistic > GetStatistics ( ) = > Enumerable . Empty < BeatmapStatistic > ( ) ;
2021-01-15 13:28:49 +08:00
public double GetMostCommonBeatLength ( )
{
2022-12-02 15:05:14 +08:00
double lastTime ;
2022-12-01 16:43:54 +08:00
2021-01-15 13:28:49 +08:00
// The last playable time in the beatmap - the last timing point extends to this time.
// Note: This is more accurate and may present different results because osu-stable didn't have the ability to calculate slider durations in this context.
2022-12-02 15:05:14 +08:00
if ( ! HitObjects . Any ( ) )
lastTime = ControlPointInfo . TimingPoints . LastOrDefault ( ) ? . Time ? ? 0 ;
else
lastTime = this . GetLastObjectTime ( ) ;
2021-01-15 13:28:49 +08:00
2021-02-08 18:03:19 +08:00
var mostCommon =
2021-01-15 13:28:49 +08:00
// Construct a set of (beatLength, duration) tuples for each individual timing point.
ControlPointInfo . TimingPoints . Select ( ( t , i ) = >
{
if ( t . Time > lastTime )
return ( beatLength : t . BeatLength , 0 ) ;
2022-01-11 12:53:51 +08:00
// osu-stable forced the first control point to start at 0.
// This is reproduced here to maintain compatibility around osu!mania scroll speed and song select display.
2022-01-11 11:55:12 +08:00
double currentTime = i = = 0 ? 0 : t . Time ;
2021-10-27 12:04:41 +08:00
double nextTime = i = = ControlPointInfo . TimingPoints . Count - 1 ? lastTime : ControlPointInfo . TimingPoints [ i + 1 ] . Time ;
2022-01-11 11:55:12 +08:00
return ( beatLength : t . BeatLength , duration : nextTime - currentTime ) ;
2021-01-15 13:28:49 +08:00
} )
// Aggregate durations into a set of (beatLength, duration) tuples for each beat length
2021-02-08 17:52:50 +08:00
. GroupBy ( t = > Math . Round ( t . beatLength * 1000 ) / 1000 )
2021-01-15 13:28:49 +08:00
. Select ( g = > ( beatLength : g . Key , duration : g . Sum ( t = > t . duration ) ) )
2023-05-08 15:55:48 +08:00
// Get the most common one, or 0 as a suitable default (see handling below)
2021-02-08 18:03:19 +08:00
. OrderByDescending ( i = > i . duration ) . FirstOrDefault ( ) ;
2021-01-15 13:28:49 +08:00
2023-05-08 15:55:48 +08:00
if ( mostCommon . beatLength = = 0 )
return TimingControlPoint . DEFAULT_BEAT_LENGTH ;
2021-02-08 18:03:19 +08:00
return mostCommon . beatLength ;
2021-01-15 13:28:49 +08:00
}
2018-04-19 17:50:21 +08:00
IBeatmap IBeatmap . Clone ( ) = > Clone ( ) ;
2021-01-15 16:34:01 +08:00
public Beatmap < T > Clone ( ) = > ( Beatmap < T > ) MemberwiseClone ( ) ;
2023-11-23 16:11:40 +08:00
public override string ToString ( ) = > BeatmapInfo . ToString ( ) ;
2017-03-11 23:34:21 +08:00
}
2018-04-13 17:19:50 +08:00
2017-03-11 23:34:21 +08:00
public class Beatmap : Beatmap < HitObject >
{
2016-08-31 11:33:01 +08:00
}
2016-10-19 22:31:10 +08:00
}