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

89 lines
3.0 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
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;
using System.Linq;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.IO.Serialization;
using Newtonsoft.Json;
using osu.Game.IO.Serialization.Converters;
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> : IJsonSerializable
2017-03-11 23:34:21 +08:00
where T : HitObject
{
public BeatmapInfo BeatmapInfo = new BeatmapInfo();
public ControlPointInfo ControlPointInfo = new ControlPointInfo();
public List<BreakPeriod> Breaks = new List<BreakPeriod>();
2018-03-09 20:23:03 +08:00
[JsonIgnore]
public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata;
2017-03-12 00:08:34 +08:00
/// <summary>
/// The HitObjects this Beatmap contains.
/// </summary>
2017-12-07 13:40:28 +08:00
[JsonConverter(typeof(TypedListConverter<HitObject>))]
public List<T> HitObjects = new List<T>();
2017-03-11 23:34:21 +08:00
/// <summary>
/// Total amount of break time in the beatmap.
/// </summary>
2017-12-07 13:40:28 +08:00
[JsonIgnore]
public double TotalBreakTime => Breaks.Sum(b => b.Duration);
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<T> original = null)
2017-03-11 23:34:21 +08:00
{
BeatmapInfo = original?.BeatmapInfo.DeepClone() ?? BeatmapInfo;
ControlPointInfo = original?.ControlPointInfo ?? ControlPointInfo;
Breaks = original?.Breaks ?? Breaks;
HitObjects = original?.HitObjects ?? HitObjects;
if (original == null && Metadata == null)
{
// we may have no metadata in cases we weren't sourced from the database.
// let's fill it (and other related fields) so we don't need to null-check it in future usages.
BeatmapInfo = new BeatmapInfo
{
Metadata = new BeatmapMetadata
{
Artist = @"Unknown",
Title = @"Unknown",
AuthorString = @"Unknown Creator",
},
Version = @"Normal",
2017-10-19 13:05:11 +08:00
BaseDifficulty = new BeatmapDifficulty()
};
}
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-17 13:24:46 +08:00
/// <summary>
/// Constructs a new beatmap.
/// </summary>
/// <param name="original">The original beatmap to use the parameters of.</param>
2018-03-09 20:23:03 +08:00
public Beatmap(Beatmap original)
2017-03-17 13:24:46 +08:00
: base(original)
{
}
2018-03-09 20:23:03 +08:00
public Beatmap()
{
}
}
}