1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:07:25 +08:00
osu-lazer/osu.Game/Beatmaps/Beatmap.cs

102 lines
3.9 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using osu.Game.Beatmaps.Timing;
using osu.Game.Database;
using osu.Game.Modes;
2017-03-11 23:34:21 +08:00
using osu.Game.Modes.Objects;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Beatmaps
{
2017-03-11 23:34:21 +08:00
/// <summary>
/// A Beatmap containing converted HitObjects.
2017-03-11 23:34:21 +08:00
/// </summary>
public class Beatmap<T>
2017-03-11 23:34:21 +08:00
where T : HitObject
{
public BeatmapInfo BeatmapInfo;
public List<ControlPoint> ControlPoints;
2017-03-14 16:14:11 +08:00
public readonly List<Color4> ComboColors = new List<Color4>
{
new Color4(17, 136, 170, 255),
new Color4(102, 136, 0, 255),
new Color4(204, 102, 0, 255),
new Color4(121, 9, 13, 255)
};
public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata;
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.
2017-03-12 00:08:34 +08:00
/// </summary>
/// <param name="original">The original beatmap to use the parameters of.</param>
public Beatmap(Beatmap original = null)
2017-03-11 23:34:21 +08:00
{
BeatmapInfo = original?.BeatmapInfo ?? BeatmapInfo;
ControlPoints = original?.ControlPoints ?? ControlPoints;
ComboColors = original?.ComboColors ?? ComboColors;
2017-03-11 23:34:21 +08:00
}
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-12-18 02:57:58 +08:00
public double BPMAt(double time)
{
return 60000 / BeatLengthAt(time);
}
public double BeatLengthAt(double time)
{
ControlPoint overridePoint;
ControlPoint timingPoint = TimingPointAt(time, out overridePoint);
return timingPoint.BeatLength;
}
public ControlPoint TimingPointAt(double time, out ControlPoint overridePoint)
{
overridePoint = null;
ControlPoint timingPoint = null;
foreach (var controlPoint in ControlPoints)
{
// 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).
if (controlPoint.Time <= time || timingPoint == null)
{
if (controlPoint.TimingChange)
{
timingPoint = controlPoint;
overridePoint = null;
}
else overridePoint = controlPoint;
}
else break;
}
return timingPoint ?? ControlPoint.Default;
}
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>
public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate();
}
}