mirror of
https://github.com/ppy/osu.git
synced 2025-03-06 03:03:05 +08:00
Add xmldoc and combine GroupAt / CreateGroup
This commit is contained in:
parent
2a6b3fd67c
commit
45da22afe9
@ -14,7 +14,7 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
public class ControlPointInfo
|
public class ControlPointInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Control point groups.
|
/// All control points grouped by time.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public IBindableList<ControlPointGroup> Groups => groups;
|
public IBindableList<ControlPointGroup> Groups => groups;
|
||||||
@ -107,6 +107,62 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
public double BPMMode =>
|
public double BPMMode =>
|
||||||
60000 / (TimingPoints.GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? new TimingControlPoint()).BeatLength;
|
60000 / (TimingPoints.GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? new TimingControlPoint()).BeatLength;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove all <see cref="ControlPointGroup"/>s and return to a pristine state.
|
||||||
|
/// </summary>
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
groups.Clear();
|
||||||
|
timingPoints.Clear();
|
||||||
|
difficultyPoints.Clear();
|
||||||
|
samplePoints.Clear();
|
||||||
|
effectPoints.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new <see cref="ControlPoint"/>. Note that the provided control point may not be added if the correct state is already present at the provided time.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">The time at which the control point should be added.</param>
|
||||||
|
/// <param name="controlPoint">The control point to add.</param>
|
||||||
|
/// <returns>Whether the control point was added.</returns>
|
||||||
|
public bool Add(double time, ControlPoint controlPoint)
|
||||||
|
{
|
||||||
|
if (checkAlreadyExisting(time, controlPoint))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
GroupAt(time, true).Add(controlPoint);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ControlPointGroup GroupAt(double time, bool addIfNotExisting = false)
|
||||||
|
{
|
||||||
|
var newGroup = new ControlPointGroup(time);
|
||||||
|
|
||||||
|
int i = groups.BinarySearch(newGroup);
|
||||||
|
|
||||||
|
if (i >= 0)
|
||||||
|
return groups[i];
|
||||||
|
|
||||||
|
if (addIfNotExisting)
|
||||||
|
{
|
||||||
|
newGroup.ItemAdded += groupItemAdded;
|
||||||
|
newGroup.ItemRemoved += groupItemRemoved;
|
||||||
|
|
||||||
|
groups.Insert(~i, newGroup);
|
||||||
|
return newGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveGroup(ControlPointGroup group)
|
||||||
|
{
|
||||||
|
group.ItemAdded -= groupItemAdded;
|
||||||
|
group.ItemRemoved -= groupItemRemoved;
|
||||||
|
|
||||||
|
groups.Remove(group);
|
||||||
|
}
|
||||||
|
|
||||||
/// <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.
|
/// Includes logic for returning a specific point when no matching point is found.
|
||||||
@ -161,33 +217,6 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
return list[l - 1];
|
return list[l - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(double time, ControlPoint newPoint, bool force = false)
|
|
||||||
{
|
|
||||||
if (!force && checkAlreadyExisting(time, newPoint))
|
|
||||||
return;
|
|
||||||
|
|
||||||
GroupAt(time, true).Add(newPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ControlPointGroup GroupAt(double time, bool createIfNotExisting = false)
|
|
||||||
{
|
|
||||||
var existing = Groups.FirstOrDefault(g => g.Time == time);
|
|
||||||
|
|
||||||
if (existing != null)
|
|
||||||
return existing;
|
|
||||||
|
|
||||||
if (createIfNotExisting)
|
|
||||||
{
|
|
||||||
var newGroup = new ControlPointGroup(time);
|
|
||||||
newGroup.ItemAdded += groupItemAdded;
|
|
||||||
newGroup.ItemRemoved += groupItemRemoved;
|
|
||||||
groups.Add(newGroup);
|
|
||||||
return newGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check whether <see cref="newPoint"/> should be added.
|
/// Check whether <see cref="newPoint"/> should be added.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -221,31 +250,9 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
return existing?.EquivalentTo(newPoint) == true;
|
return existing?.EquivalentTo(newPoint) == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void groupItemRemoved(ControlPoint obj)
|
private void groupItemAdded(ControlPoint controlPoint)
|
||||||
{
|
{
|
||||||
switch (obj)
|
switch (controlPoint)
|
||||||
{
|
|
||||||
case TimingControlPoint typed:
|
|
||||||
timingPoints.Remove(typed);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EffectControlPoint typed:
|
|
||||||
effectPoints.Remove(typed);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SampleControlPoint typed:
|
|
||||||
samplePoints.Remove(typed);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DifficultyControlPoint typed:
|
|
||||||
difficultyPoints.Remove(typed);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void groupItemAdded(ControlPoint obj)
|
|
||||||
{
|
|
||||||
switch (obj)
|
|
||||||
{
|
{
|
||||||
case TimingControlPoint typed:
|
case TimingControlPoint typed:
|
||||||
timingPoints.Add(typed);
|
timingPoints.Add(typed);
|
||||||
@ -265,29 +272,26 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
private void groupItemRemoved(ControlPoint controlPoint)
|
||||||
{
|
{
|
||||||
groups.Clear();
|
switch (controlPoint)
|
||||||
timingPoints.Clear();
|
|
||||||
difficultyPoints.Clear();
|
|
||||||
samplePoints.Clear();
|
|
||||||
effectPoints.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ControlPointGroup CreateGroup(double time)
|
|
||||||
{
|
{
|
||||||
var newGroup = new ControlPointGroup(time);
|
case TimingControlPoint typed:
|
||||||
|
timingPoints.Remove(typed);
|
||||||
|
break;
|
||||||
|
|
||||||
int i = groups.BinarySearch(newGroup);
|
case EffectControlPoint typed:
|
||||||
|
effectPoints.Remove(typed);
|
||||||
|
break;
|
||||||
|
|
||||||
if (i > 0)
|
case SampleControlPoint typed:
|
||||||
return groups[i];
|
samplePoints.Remove(typed);
|
||||||
|
break;
|
||||||
|
|
||||||
groups.Insert(~i, newGroup);
|
case DifficultyControlPoint typed:
|
||||||
|
difficultyPoints.Remove(typed);
|
||||||
return newGroup;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveGroup(ControlPointGroup group) => groups.Remove(group);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user