2018-04-13 17:19:50 +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;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
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
|
|
|
|
{
|
2018-04-19 17:14:21 +08:00
|
|
|
public interface IBeatmap : IJsonSerializable
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// This beatmap's info.
|
|
|
|
/// </summary>
|
2018-04-19 19:44:38 +08:00
|
|
|
BeatmapInfo BeatmapInfo { get; set; }
|
2018-04-19 17:14:21 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This beatmap's metadata.
|
|
|
|
/// </summary>
|
|
|
|
BeatmapMetadata Metadata { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The control points in this beatmap.
|
|
|
|
/// </summary>
|
|
|
|
ControlPointInfo ControlPointInfo { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The breaks in this beatmap.
|
|
|
|
/// </summary>
|
|
|
|
List<BreakPeriod> Breaks { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Total amount of break time in the beatmap.
|
|
|
|
/// </summary>
|
|
|
|
double TotalBreakTime { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The hitobjects contained by this beatmap.
|
|
|
|
/// </summary>
|
|
|
|
IEnumerable<HitObject> HitObjects { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a shallow-clone of this beatmap and returns it.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The shallow-cloned beatmap.</returns>
|
|
|
|
IBeatmap Clone();
|
|
|
|
}
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A Beatmap containing converted HitObjects.
|
|
|
|
/// </summary>
|
2018-04-19 17:14:21 +08:00
|
|
|
public class Beatmap<T> : IBeatmap
|
2018-04-13 17:19:50 +08:00
|
|
|
where T : HitObject
|
|
|
|
{
|
2018-04-19 17:14:21 +08:00
|
|
|
public BeatmapInfo BeatmapInfo { get; set; } = new BeatmapInfo
|
|
|
|
{
|
|
|
|
Metadata = new BeatmapMetadata
|
|
|
|
{
|
|
|
|
Artist = @"Unknown",
|
|
|
|
Title = @"Unknown",
|
|
|
|
AuthorString = @"Unknown Creator",
|
|
|
|
},
|
|
|
|
Version = @"Normal",
|
|
|
|
BaseDifficulty = new BeatmapDifficulty()
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
public BeatmapMetadata Metadata => BeatmapInfo?.Metadata ?? BeatmapInfo?.BeatmapSet?.Metadata;
|
|
|
|
|
2018-04-19 17:14:21 +08:00
|
|
|
public ControlPointInfo ControlPointInfo { get; set; } = new ControlPointInfo();
|
|
|
|
|
|
|
|
public List<BreakPeriod> Breaks { get; set; } = new List<BreakPeriod>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Total amount of break time in the beatmap.
|
|
|
|
/// </summary>
|
|
|
|
[JsonIgnore]
|
|
|
|
public double TotalBreakTime => Breaks.Sum(b => b.Duration);
|
|
|
|
|
|
|
|
/// <summary>
|
2018-04-19 17:14:21 +08:00
|
|
|
/// The HitObjects this Beatmap contains.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
2018-04-19 17:14:21 +08:00
|
|
|
[JsonConverter(typeof(TypedListConverter<HitObject>))]
|
|
|
|
public List<T> HitObjects = new List<T>();
|
|
|
|
|
|
|
|
IEnumerable<HitObject> IBeatmap.HitObjects => HitObjects;
|
|
|
|
|
2018-04-19 17:50:21 +08:00
|
|
|
IBeatmap IBeatmap.Clone() => Clone();
|
|
|
|
|
|
|
|
public Beatmap<T> Clone()
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-04-19 17:50:21 +08:00
|
|
|
var newInstance = (Beatmap<T>)MemberwiseClone();
|
|
|
|
newInstance.BeatmapInfo = BeatmapInfo.DeepClone();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-04-19 17:50:21 +08:00
|
|
|
return newInstance;
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public class Beatmap : Beatmap<HitObject>
|
|
|
|
{
|
2018-04-19 17:50:21 +08:00
|
|
|
public Beatmap Clone() => (Beatmap)base.Clone();
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|