2021-08-30 13:12:30 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-08-31 15:20:16 +08:00
|
|
|
using System.Collections.Generic;
|
2021-08-30 13:12:30 +08:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using Newtonsoft.Json;
|
2021-08-31 15:20:16 +08:00
|
|
|
using osu.Framework.Lists;
|
2021-08-30 13:12:30 +08:00
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Legacy
|
|
|
|
{
|
|
|
|
public class LegacyControlPointInfo : ControlPointInfo
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// All sound points.
|
|
|
|
/// </summary>
|
|
|
|
[JsonProperty]
|
2021-09-03 15:16:40 +08:00
|
|
|
public IReadOnlyList<SampleControlPoint> SamplePoints => samplePoints;
|
2021-08-30 13:12:30 +08:00
|
|
|
|
2021-09-03 15:16:40 +08:00
|
|
|
private readonly SortedList<SampleControlPoint> samplePoints = new SortedList<SampleControlPoint>(Comparer<SampleControlPoint>.Default);
|
2021-08-30 13:12:30 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Finds the sound control point that is active at <paramref name="time"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="time">The time to find the sound control point at.</param>
|
|
|
|
/// <returns>The sound control point.</returns>
|
|
|
|
[NotNull]
|
|
|
|
public SampleControlPoint SamplePointAt(double time) => BinarySearchWithFallback(SamplePoints, time, SamplePoints.Count > 0 ? SamplePoints[0] : SampleControlPoint.DEFAULT);
|
|
|
|
|
2021-08-31 15:20:16 +08:00
|
|
|
/// <summary>
|
|
|
|
/// All difficulty points.
|
|
|
|
/// </summary>
|
|
|
|
[JsonProperty]
|
|
|
|
public IReadOnlyList<DifficultyControlPoint> DifficultyPoints => difficultyPoints;
|
|
|
|
|
|
|
|
private readonly SortedList<DifficultyControlPoint> difficultyPoints = new SortedList<DifficultyControlPoint>(Comparer<DifficultyControlPoint>.Default);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Finds the difficulty control point that is active at <paramref name="time"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="time">The time to find the difficulty control point at.</param>
|
|
|
|
/// <returns>The difficulty control point.</returns>
|
|
|
|
[NotNull]
|
|
|
|
public DifficultyControlPoint DifficultyPointAt(double time) => BinarySearchWithFallback(DifficultyPoints, time, DifficultyControlPoint.DEFAULT);
|
|
|
|
|
2021-08-30 13:12:30 +08:00
|
|
|
public override void Clear()
|
|
|
|
{
|
|
|
|
base.Clear();
|
|
|
|
samplePoints.Clear();
|
2021-08-31 15:20:16 +08:00
|
|
|
difficultyPoints.Clear();
|
2021-08-30 13:12:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool CheckAlreadyExisting(double time, ControlPoint newPoint)
|
|
|
|
{
|
2021-08-31 15:20:16 +08:00
|
|
|
switch (newPoint)
|
2021-08-30 13:12:30 +08:00
|
|
|
{
|
2022-06-24 20:25:23 +08:00
|
|
|
case SampleControlPoint:
|
2021-09-02 18:34:09 +08:00
|
|
|
// intentionally don't use SamplePointAt (we always need to consider the first sample point).
|
|
|
|
var existing = BinarySearch(SamplePoints, time);
|
|
|
|
return newPoint.IsRedundant(existing);
|
2021-08-31 15:20:16 +08:00
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
case DifficultyControlPoint:
|
2021-08-31 15:20:16 +08:00
|
|
|
return newPoint.IsRedundant(DifficultyPointAt(time));
|
2021-08-30 13:12:30 +08:00
|
|
|
|
2021-08-31 15:20:16 +08:00
|
|
|
default:
|
|
|
|
return base.CheckAlreadyExisting(time, newPoint);
|
|
|
|
}
|
2021-08-30 13:12:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void GroupItemAdded(ControlPoint controlPoint)
|
|
|
|
{
|
2021-08-31 15:20:16 +08:00
|
|
|
switch (controlPoint)
|
|
|
|
{
|
|
|
|
case SampleControlPoint typed:
|
|
|
|
samplePoints.Add(typed);
|
2021-09-06 21:04:37 +08:00
|
|
|
return;
|
2021-08-31 15:20:16 +08:00
|
|
|
|
|
|
|
case DifficultyControlPoint typed:
|
|
|
|
difficultyPoints.Add(typed);
|
2021-09-06 21:04:37 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
base.GroupItemAdded(controlPoint);
|
2021-08-31 15:20:16 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-08-30 13:12:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void GroupItemRemoved(ControlPoint controlPoint)
|
|
|
|
{
|
2021-08-31 15:20:16 +08:00
|
|
|
switch (controlPoint)
|
|
|
|
{
|
|
|
|
case SampleControlPoint typed:
|
|
|
|
samplePoints.Remove(typed);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DifficultyControlPoint typed:
|
|
|
|
difficultyPoints.Remove(typed);
|
|
|
|
break;
|
|
|
|
}
|
2021-08-30 13:12:30 +08:00
|
|
|
|
|
|
|
base.GroupItemRemoved(controlPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|