mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Move samples to LegacyControlPointInfo
This commit is contained in:
@ -14,6 +14,64 @@ using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Beatmaps.ControlPoints
|
||||
{
|
||||
public class LegacyControlPointInfo : ControlPointInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// All sound points.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public IBindableList<SampleControlPoint> SamplePoints => samplePoints;
|
||||
|
||||
private readonly BindableList<SampleControlPoint> samplePoints = new BindableList<SampleControlPoint>();
|
||||
|
||||
/// <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);
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
samplePoints.Clear();
|
||||
}
|
||||
|
||||
protected override bool CheckAlreadyExisting(double time, ControlPoint newPoint)
|
||||
{
|
||||
if (newPoint is SampleControlPoint _)
|
||||
{
|
||||
var existing = BinarySearch(SamplePoints, time);
|
||||
return newPoint?.IsRedundant(existing) == true;
|
||||
}
|
||||
|
||||
return base.CheckAlreadyExisting(time, newPoint);
|
||||
}
|
||||
|
||||
protected override void GroupItemAdded(ControlPoint controlPoint)
|
||||
{
|
||||
if (controlPoint is SampleControlPoint typed)
|
||||
{
|
||||
samplePoints.Add(typed);
|
||||
return;
|
||||
}
|
||||
|
||||
base.GroupItemAdded(controlPoint);
|
||||
}
|
||||
|
||||
protected override void GroupItemRemoved(ControlPoint controlPoint)
|
||||
{
|
||||
if (controlPoint is SampleControlPoint typed)
|
||||
{
|
||||
samplePoints.Remove(typed);
|
||||
return;
|
||||
}
|
||||
|
||||
base.GroupItemRemoved(controlPoint);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ControlPointInfo : IDeepCloneable<ControlPointInfo>
|
||||
{
|
||||
@ -41,14 +99,6 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
|
||||
private readonly SortedList<DifficultyControlPoint> difficultyPoints = new SortedList<DifficultyControlPoint>(Comparer<DifficultyControlPoint>.Default);
|
||||
|
||||
/// <summary>
|
||||
/// All sound points.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public IBindableList<SampleControlPoint> SamplePoints => samplePoints;
|
||||
|
||||
private readonly BindableList<SampleControlPoint> samplePoints = new BindableList<SampleControlPoint>();
|
||||
|
||||
/// <summary>
|
||||
/// All effect points.
|
||||
/// </summary>
|
||||
@ -69,7 +119,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <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);
|
||||
public DifficultyControlPoint DifficultyPointAt(double time) => BinarySearchWithFallback(DifficultyPoints, time, DifficultyControlPoint.DEFAULT);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the effect control point that is active at <paramref name="time"/>.
|
||||
@ -77,15 +127,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <param name="time">The time to find the effect control point at.</param>
|
||||
/// <returns>The effect control point.</returns>
|
||||
[NotNull]
|
||||
public EffectControlPoint EffectPointAt(double time) => binarySearchWithFallback(EffectPoints, time, EffectControlPoint.DEFAULT);
|
||||
|
||||
/// <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);
|
||||
public EffectControlPoint EffectPointAt(double time) => BinarySearchWithFallback(EffectPoints, time, EffectControlPoint.DEFAULT);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the timing control point that is active at <paramref name="time"/>.
|
||||
@ -93,7 +135,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <param name="time">The time to find the timing control point at.</param>
|
||||
/// <returns>The timing control point.</returns>
|
||||
[NotNull]
|
||||
public TimingControlPoint TimingPointAt(double time) => binarySearchWithFallback(TimingPoints, time, TimingPoints.Count > 0 ? TimingPoints[0] : TimingControlPoint.DEFAULT);
|
||||
public TimingControlPoint TimingPointAt(double time) => BinarySearchWithFallback(TimingPoints, time, TimingPoints.Count > 0 ? TimingPoints[0] : TimingControlPoint.DEFAULT);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the maximum BPM represented by any timing control point.
|
||||
@ -112,12 +154,11 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <summary>
|
||||
/// Remove all <see cref="ControlPointGroup"/>s and return to a pristine state.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
public virtual void Clear()
|
||||
{
|
||||
groups.Clear();
|
||||
timingPoints.Clear();
|
||||
difficultyPoints.Clear();
|
||||
samplePoints.Clear();
|
||||
effectPoints.Clear();
|
||||
}
|
||||
|
||||
@ -129,7 +170,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <returns>Whether the control point was added.</returns>
|
||||
public bool Add(double time, ControlPoint controlPoint)
|
||||
{
|
||||
if (checkAlreadyExisting(time, controlPoint))
|
||||
if (CheckAlreadyExisting(time, controlPoint))
|
||||
return false;
|
||||
|
||||
GroupAt(time, true).Add(controlPoint);
|
||||
@ -147,8 +188,8 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
|
||||
if (addIfNotExisting)
|
||||
{
|
||||
newGroup.ItemAdded += groupItemAdded;
|
||||
newGroup.ItemRemoved += groupItemRemoved;
|
||||
newGroup.ItemAdded += GroupItemAdded;
|
||||
newGroup.ItemRemoved += GroupItemRemoved;
|
||||
|
||||
groups.Insert(~i, newGroup);
|
||||
return newGroup;
|
||||
@ -162,8 +203,8 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
foreach (var item in group.ControlPoints.ToArray())
|
||||
group.Remove(item);
|
||||
|
||||
group.ItemAdded -= groupItemAdded;
|
||||
group.ItemRemoved -= groupItemRemoved;
|
||||
group.ItemAdded -= GroupItemAdded;
|
||||
group.ItemRemoved -= GroupItemRemoved;
|
||||
|
||||
groups.Remove(group);
|
||||
}
|
||||
@ -228,10 +269,10 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <param name="time">The time to find the control point at.</param>
|
||||
/// <param name="fallback">The control point to use when <paramref name="time"/> is before any control points.</param>
|
||||
/// <returns>The active control point at <paramref name="time"/>, or a fallback <see cref="ControlPoint"/> if none found.</returns>
|
||||
private T binarySearchWithFallback<T>(IReadOnlyList<T> list, double time, T fallback)
|
||||
protected T BinarySearchWithFallback<T>(IReadOnlyList<T> list, double time, T fallback)
|
||||
where T : ControlPoint
|
||||
{
|
||||
return binarySearch(list, time) ?? fallback;
|
||||
return BinarySearch(list, time) ?? fallback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -240,7 +281,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <param name="list">The list to search.</param>
|
||||
/// <param name="time">The time to find the control point at.</param>
|
||||
/// <returns>The active control point at <paramref name="time"/>.</returns>
|
||||
private T binarySearch<T>(IReadOnlyList<T> list, double time)
|
||||
protected virtual T BinarySearch<T>(IReadOnlyList<T> list, double time)
|
||||
where T : ControlPoint
|
||||
{
|
||||
if (list == null)
|
||||
@ -280,7 +321,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// <param name="time">The time to find the timing control point at.</param>
|
||||
/// <param name="newPoint">A point to be added.</param>
|
||||
/// <returns>Whether the new point should be added.</returns>
|
||||
private bool checkAlreadyExisting(double time, ControlPoint newPoint)
|
||||
protected virtual bool CheckAlreadyExisting(double time, ControlPoint newPoint)
|
||||
{
|
||||
ControlPoint existing = null;
|
||||
|
||||
@ -288,17 +329,13 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
{
|
||||
case TimingControlPoint _:
|
||||
// Timing points are a special case and need to be added regardless of fallback availability.
|
||||
existing = binarySearch(TimingPoints, time);
|
||||
existing = BinarySearch(TimingPoints, time);
|
||||
break;
|
||||
|
||||
case EffectControlPoint _:
|
||||
existing = EffectPointAt(time);
|
||||
break;
|
||||
|
||||
case SampleControlPoint _:
|
||||
existing = binarySearch(SamplePoints, time);
|
||||
break;
|
||||
|
||||
case DifficultyControlPoint _:
|
||||
existing = DifficultyPointAt(time);
|
||||
break;
|
||||
@ -307,7 +344,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
return newPoint?.IsRedundant(existing) == true;
|
||||
}
|
||||
|
||||
private void groupItemAdded(ControlPoint controlPoint)
|
||||
protected virtual void GroupItemAdded(ControlPoint controlPoint)
|
||||
{
|
||||
switch (controlPoint)
|
||||
{
|
||||
@ -319,17 +356,13 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
effectPoints.Add(typed);
|
||||
break;
|
||||
|
||||
case SampleControlPoint typed:
|
||||
samplePoints.Add(typed);
|
||||
break;
|
||||
|
||||
case DifficultyControlPoint typed:
|
||||
difficultyPoints.Add(typed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void groupItemRemoved(ControlPoint controlPoint)
|
||||
protected virtual void GroupItemRemoved(ControlPoint controlPoint)
|
||||
{
|
||||
switch (controlPoint)
|
||||
{
|
||||
@ -341,10 +374,6 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
effectPoints.Remove(typed);
|
||||
break;
|
||||
|
||||
case SampleControlPoint typed:
|
||||
samplePoints.Remove(typed);
|
||||
break;
|
||||
|
||||
case DifficultyControlPoint typed:
|
||||
difficultyPoints.Remove(typed);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user