mirror of
https://github.com/ppy/osu.git
synced 2025-03-18 23:57:22 +08:00
Expose a version to indicate path changes
This commit is contained in:
parent
1585d83b96
commit
c9a66c0d07
@ -16,6 +16,13 @@ namespace osu.Game.Rulesets.Objects
|
||||
{
|
||||
public class SliderPath
|
||||
{
|
||||
/// <summary>
|
||||
/// The current version of this <see cref="SliderPath"/>. Updated when any change to the path occurs.
|
||||
/// </summary>
|
||||
public IBindable<int> Version => version;
|
||||
|
||||
private readonly Bindable<int> version = new Bindable<int>();
|
||||
|
||||
/// <summary>
|
||||
/// The user-set distance of the path. If non-null, <see cref="Distance"/> will match this value,
|
||||
/// and the path will be shortened/lengthened to match this length.
|
||||
@ -39,25 +46,23 @@ namespace osu.Game.Rulesets.Objects
|
||||
/// </summary>
|
||||
public SliderPath()
|
||||
{
|
||||
ExpectedDistance.ValueChanged += _ => pathCache.Invalidate();
|
||||
ExpectedDistance.ValueChanged += _ => invalidate();
|
||||
|
||||
ControlPoints.ItemsAdded += items =>
|
||||
{
|
||||
foreach (var c in items)
|
||||
c.Changed += onControlPointChanged;
|
||||
c.Changed += invalidate;
|
||||
|
||||
onControlPointChanged();
|
||||
invalidate();
|
||||
};
|
||||
|
||||
ControlPoints.ItemsRemoved += items =>
|
||||
{
|
||||
foreach (var c in items)
|
||||
c.Changed -= onControlPointChanged;
|
||||
c.Changed -= invalidate;
|
||||
|
||||
onControlPointChanged();
|
||||
invalidate();
|
||||
};
|
||||
|
||||
void onControlPointChanged() => pathCache.Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -141,6 +146,12 @@ namespace osu.Game.Rulesets.Objects
|
||||
return interpolateVertices(indexOfDistance(d), d);
|
||||
}
|
||||
|
||||
private void invalidate()
|
||||
{
|
||||
pathCache.Invalidate();
|
||||
version.Value++;
|
||||
}
|
||||
|
||||
private void ensureValid()
|
||||
{
|
||||
if (pathCache.IsValid)
|
||||
|
Loading…
x
Reference in New Issue
Block a user