2017-02-07 12:59:30 +08:00
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-08-31 11:33:01 +08:00
|
|
|
|
2016-08-31 12:51:00 +08:00
|
|
|
using osu.Game.Beatmaps.Timing;
|
2017-02-25 02:36:17 +08:00
|
|
|
using osu.Game.Modes;
|
2017-03-11 23:34:21 +08:00
|
|
|
using osu.Game.Modes.Objects;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2016-08-31 11:33:01 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps
|
|
|
|
{
|
2017-03-11 23:34:21 +08:00
|
|
|
/// <summary>
|
2017-03-12 00:08:34 +08:00
|
|
|
/// A Beatmap containing HitObjects.
|
2017-03-11 23:34:21 +08:00
|
|
|
/// </summary>
|
|
|
|
public class Beatmap<T> : BeatmapBase
|
|
|
|
where T : HitObject
|
|
|
|
{
|
2017-03-12 00:08:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The HitObjects this Beatmap contains.
|
|
|
|
/// </summary>
|
2017-03-11 23:34:21 +08:00
|
|
|
public List<T> HitObjects;
|
|
|
|
|
2017-03-12 00:08:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Constructs a new Beatmap containing HitObjects.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="original">If this Beatmap is a convert, the original Beatmap to use the properties of.</param>
|
2017-03-11 23:34:21 +08:00
|
|
|
public Beatmap(BeatmapBase original = null)
|
|
|
|
: base(original)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-27 19:39:04 +08:00
|
|
|
public double BPMMaximum => 60000 / (ControlPoints?.Where(c => c.BeatLength != 0).OrderBy(c => c.BeatLength).FirstOrDefault() ?? ControlPoint.Default).BeatLength;
|
|
|
|
public double BPMMinimum => 60000 / (ControlPoints?.Where(c => c.BeatLength != 0).OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? ControlPoint.Default).BeatLength;
|
2017-01-30 15:03:45 +08:00
|
|
|
public double BPMMode => BPMAt(ControlPoints.Where(c => c.BeatLength != 0).GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).First().First().Time);
|
2016-11-28 14:31:54 +08:00
|
|
|
|
2016-12-18 02:57:58 +08:00
|
|
|
public double BPMAt(double time)
|
|
|
|
{
|
|
|
|
return 60000 / BeatLengthAt(time);
|
|
|
|
}
|
|
|
|
|
2017-02-16 01:55:49 +08:00
|
|
|
public double BeatLengthAt(double time)
|
2016-11-28 14:31:54 +08:00
|
|
|
{
|
2017-02-16 01:55:49 +08:00
|
|
|
ControlPoint overridePoint;
|
|
|
|
ControlPoint timingPoint = TimingPointAt(time, out overridePoint);
|
|
|
|
return timingPoint.BeatLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ControlPoint TimingPointAt(double time, out ControlPoint overridePoint)
|
|
|
|
{
|
|
|
|
overridePoint = null;
|
2016-11-28 14:31:54 +08:00
|
|
|
|
2017-02-16 01:55:49 +08:00
|
|
|
ControlPoint timingPoint = null;
|
|
|
|
foreach (var controlPoint in ControlPoints)
|
2017-02-18 04:27:17 +08:00
|
|
|
{
|
2017-02-18 04:22:34 +08:00
|
|
|
// Some beatmaps have the first timingPoint (accidentally) start after the first HitObject(s).
|
|
|
|
// This null check makes it so that the first ControlPoint that makes a timing change is used as
|
|
|
|
// the timingPoint for those HitObject(s).
|
2017-02-17 14:27:42 +08:00
|
|
|
if (controlPoint.Time <= time || timingPoint == null)
|
2016-11-28 14:31:54 +08:00
|
|
|
{
|
2017-02-16 01:55:49 +08:00
|
|
|
if (controlPoint.TimingChange)
|
|
|
|
{
|
|
|
|
timingPoint = controlPoint;
|
|
|
|
overridePoint = null;
|
|
|
|
}
|
|
|
|
else overridePoint = controlPoint;
|
2016-11-28 14:31:54 +08:00
|
|
|
}
|
2017-02-16 01:55:49 +08:00
|
|
|
else break;
|
2017-02-18 00:36:00 +08:00
|
|
|
}
|
2016-11-28 14:31:54 +08:00
|
|
|
|
2017-02-18 14:54:16 +08:00
|
|
|
return timingPoint ?? ControlPoint.Default;
|
2016-11-28 14:31:54 +08:00
|
|
|
}
|
2017-03-11 23:34:21 +08:00
|
|
|
}
|
|
|
|
|
2017-03-12 00:08:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A Beatmap containing un-converted HitObjects.
|
|
|
|
/// </summary>
|
2017-03-11 23:34:21 +08:00
|
|
|
public class Beatmap : Beatmap<HitObject>
|
|
|
|
{
|
2017-03-12 00:08:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Calculates the star difficulty for this Beatmap.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The star difficulty.</returns>
|
2017-02-25 02:36:17 +08:00
|
|
|
public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate();
|
2017-03-11 23:34:21 +08:00
|
|
|
|
2017-03-12 00:08:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Converts this Beatmap to a <see cref="Beatmap{T}"/> containing another type of <see cref="HitObject"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The type of HitObject the new Beatmap should contain.</typeparam>
|
|
|
|
/// <returns></returns>
|
2017-03-12 01:26:10 +08:00
|
|
|
public Beatmap<T> ConvertTo<T>(PlayMode playMode) where T : HitObject
|
2017-03-11 23:34:21 +08:00
|
|
|
{
|
2017-03-12 01:26:10 +08:00
|
|
|
return Ruleset.GetRuleset(playMode).CreateBeatmapConverter<T>().Convert(this);
|
2017-03-11 23:34:21 +08:00
|
|
|
}
|
2016-08-31 11:33:01 +08:00
|
|
|
}
|
2016-10-19 22:31:10 +08:00
|
|
|
}
|