mirror of
https://github.com/osukey/osukey.git
synced 2025-05-09 23:57:18 +09:00
Merge branch 'no-auto-gen' into editor-timing-screen
This commit is contained in:
commit
51008cd215
@ -167,9 +167,9 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
var controlPoints = beatmap.ControlPointInfo;
|
var controlPoints = beatmap.ControlPointInfo;
|
||||||
|
|
||||||
Assert.AreEqual(4, controlPoints.TimingPoints.Count);
|
Assert.AreEqual(4, controlPoints.TimingPoints.Count);
|
||||||
Assert.AreEqual(5, controlPoints.DifficultyPoints.Count);
|
Assert.AreEqual(6, controlPoints.DifficultyPoints.Count);
|
||||||
Assert.AreEqual(34, controlPoints.SamplePoints.Count);
|
Assert.AreEqual(34, controlPoints.SamplePoints.Count);
|
||||||
Assert.AreEqual(8, controlPoints.EffectPoints.Count);
|
Assert.AreEqual(9, controlPoints.EffectPoints.Count);
|
||||||
|
|
||||||
var timingPoint = controlPoints.TimingPointAt(0);
|
var timingPoint = controlPoints.TimingPointAt(0);
|
||||||
Assert.AreEqual(956, timingPoint.Time);
|
Assert.AreEqual(956, timingPoint.Time);
|
||||||
@ -191,7 +191,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
Assert.AreEqual(1.0, difficultyPoint.SpeedMultiplier);
|
Assert.AreEqual(1.0, difficultyPoint.SpeedMultiplier);
|
||||||
|
|
||||||
difficultyPoint = controlPoints.DifficultyPointAt(48428);
|
difficultyPoint = controlPoints.DifficultyPointAt(48428);
|
||||||
Assert.AreEqual(0, difficultyPoint.Time);
|
Assert.AreEqual(956, difficultyPoint.Time);
|
||||||
Assert.AreEqual(1.0, difficultyPoint.SpeedMultiplier);
|
Assert.AreEqual(1.0, difficultyPoint.SpeedMultiplier);
|
||||||
|
|
||||||
difficultyPoint = controlPoints.DifficultyPointAt(116999);
|
difficultyPoint = controlPoints.DifficultyPointAt(116999);
|
||||||
|
@ -30,11 +30,13 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
|
|
||||||
public void Add(ControlPoint point)
|
public void Add(ControlPoint point)
|
||||||
{
|
{
|
||||||
point.AttachGroup(this);
|
var existing = controlPoints.FirstOrDefault(p => p.GetType() == point.GetType());
|
||||||
|
|
||||||
foreach (var existing in controlPoints.Where(p => p.GetType() == point.GetType()).ToArray())
|
if (existing != null)
|
||||||
Remove(existing);
|
Remove(existing);
|
||||||
|
|
||||||
|
point.AttachGroup(this);
|
||||||
|
|
||||||
controlPoints.Add(point);
|
controlPoints.Add(point);
|
||||||
ItemAdded?.Invoke(point);
|
ItemAdded?.Invoke(point);
|
||||||
}
|
}
|
||||||
|
@ -62,28 +62,28 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="time">The time to find the difficulty control point at.</param>
|
/// <param name="time">The time to find the difficulty control point at.</param>
|
||||||
/// <returns>The difficulty control point.</returns>
|
/// <returns>The difficulty control point.</returns>
|
||||||
public DifficultyControlPoint DifficultyPointAt(double time) => binarySearch(DifficultyPoints, time);
|
public DifficultyControlPoint DifficultyPointAt(double time) => binarySearchWithFallback(DifficultyPoints, time);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the effect control point that is active at <paramref name="time"/>.
|
/// Finds the effect control point that is active at <paramref name="time"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="time">The time to find the effect control point at.</param>
|
/// <param name="time">The time to find the effect control point at.</param>
|
||||||
/// <returns>The effect control point.</returns>
|
/// <returns>The effect control point.</returns>
|
||||||
public EffectControlPoint EffectPointAt(double time) => binarySearch(EffectPoints, time);
|
public EffectControlPoint EffectPointAt(double time) => binarySearchWithFallback(EffectPoints, time);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the sound control point that is active at <paramref name="time"/>.
|
/// Finds the sound control point that is active at <paramref name="time"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="time">The time to find the sound control point at.</param>
|
/// <param name="time">The time to find the sound control point at.</param>
|
||||||
/// <returns>The sound control point.</returns>
|
/// <returns>The sound control point.</returns>
|
||||||
public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, SamplePoints.Count > 0 ? SamplePoints[0] : null);
|
public SampleControlPoint SamplePointAt(double time) => binarySearchWithFallback(SamplePoints, time, SamplePoints.Count > 0 ? SamplePoints[0] : null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the timing control point that is active at <paramref name="time"/>.
|
/// Finds the timing control point that is active at <paramref name="time"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="time">The time to find the timing control point at.</param>
|
/// <param name="time">The time to find the timing control point at.</param>
|
||||||
/// <returns>The timing control point.</returns>
|
/// <returns>The timing control point.</returns>
|
||||||
public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.Count > 0 ? TimingPoints[0] : null);
|
public TimingControlPoint TimingPointAt(double time) => binarySearchWithFallback(TimingPoints, time, TimingPoints.Count > 0 ? TimingPoints[0] : null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the closest <see cref="ControlPoint"/> of the same type as <see cref="referencePoint"/> that is active at <paramref name="time"/>.
|
/// Finds the closest <see cref="ControlPoint"/> of the same type as <see cref="referencePoint"/> that is active at <paramref name="time"/>.
|
||||||
@ -95,13 +95,13 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
{
|
{
|
||||||
switch (referencePoint)
|
switch (referencePoint)
|
||||||
{
|
{
|
||||||
case TimingControlPoint _: return TimingPointAt(time);
|
case TimingControlPoint _: return binarySearch(TimingPoints, time);
|
||||||
|
|
||||||
case EffectControlPoint _: return EffectPointAt(time);
|
case EffectControlPoint _: return binarySearch(EffectPoints, time);
|
||||||
|
|
||||||
case SampleControlPoint _: return SamplePointAt(time);
|
case SampleControlPoint _: return binarySearch(SamplePoints, time);
|
||||||
|
|
||||||
case DifficultyControlPoint _: return DifficultyPointAt(time);
|
case DifficultyControlPoint _: return binarySearch(DifficultyPoints, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -130,22 +130,35 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Binary searches one of the control point lists to find the active control point at <paramref name="time"/>.
|
/// Binary searches one of the control point lists to find the active control point at <paramref name="time"/>.
|
||||||
|
/// Includes logic for returning a specific point when no matching point is found.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="list">The list to search.</param>
|
/// <param name="list">The list to search.</param>
|
||||||
/// <param name="time">The time to find the control point at.</param>
|
/// <param name="time">The time to find the control point at.</param>
|
||||||
/// <param name="prePoint">The control point to use when <paramref name="time"/> is before any control points. If null, a new control point will be constructed.</param>
|
/// <param name="prePoint">The control point to use when <paramref name="time"/> is before any control points. If null, a new control point will be constructed.</param>
|
||||||
/// <returns>The active control point at <paramref name="time"/>.</returns>
|
/// <returns>The active control point at <paramref name="time"/>, or a fallback <see cref="ControlPoint"/> if none found.</returns>
|
||||||
private T binarySearch<T>(IReadOnlyList<T> list, double time, T prePoint = null)
|
private T binarySearchWithFallback<T>(IReadOnlyList<T> list, double time, T prePoint = null)
|
||||||
where T : ControlPoint, new()
|
where T : ControlPoint, new()
|
||||||
|
{
|
||||||
|
return binarySearch(list, time) ?? prePoint ?? new T();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Binary searches one of the control point lists to find the active control point at <paramref name="time"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <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)
|
||||||
|
where T : ControlPoint
|
||||||
{
|
{
|
||||||
if (list == null)
|
if (list == null)
|
||||||
throw new ArgumentNullException(nameof(list));
|
throw new ArgumentNullException(nameof(list));
|
||||||
|
|
||||||
if (list.Count == 0)
|
if (list.Count == 0)
|
||||||
return new T();
|
return null;
|
||||||
|
|
||||||
if (time < list[0].Time)
|
if (time < list[0].Time)
|
||||||
return prePoint ?? new T();
|
return null;
|
||||||
|
|
||||||
if (time >= list[list.Count - 1].Time)
|
if (time >= list[list.Count - 1].Time)
|
||||||
return list[list.Count - 1];
|
return list[list.Count - 1];
|
||||||
@ -240,6 +253,13 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear() => groups.Clear();
|
public void Clear()
|
||||||
|
{
|
||||||
|
groups.Clear();
|
||||||
|
timingPoints.Clear();
|
||||||
|
difficultyPoints.Clear();
|
||||||
|
samplePoints.Clear();
|
||||||
|
effectPoints.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user