Expose a version to indicate path changes

This commit is contained in:
smoogipoo 2019-12-05 18:31:28 +09:00
parent 1585d83b96
commit c9a66c0d07

View File

@ -16,6 +16,13 @@ namespace osu.Game.Rulesets.Objects
{ {
public class SliderPath 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> /// <summary>
/// The user-set distance of the path. If non-null, <see cref="Distance"/> will match this value, /// 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. /// and the path will be shortened/lengthened to match this length.
@ -39,25 +46,23 @@ namespace osu.Game.Rulesets.Objects
/// </summary> /// </summary>
public SliderPath() public SliderPath()
{ {
ExpectedDistance.ValueChanged += _ => pathCache.Invalidate(); ExpectedDistance.ValueChanged += _ => invalidate();
ControlPoints.ItemsAdded += items => ControlPoints.ItemsAdded += items =>
{ {
foreach (var c in items) foreach (var c in items)
c.Changed += onControlPointChanged; c.Changed += invalidate;
onControlPointChanged(); invalidate();
}; };
ControlPoints.ItemsRemoved += items => ControlPoints.ItemsRemoved += items =>
{ {
foreach (var c in items) foreach (var c in items)
c.Changed -= onControlPointChanged; c.Changed -= invalidate;
onControlPointChanged(); invalidate();
}; };
void onControlPointChanged() => pathCache.Invalidate();
} }
/// <summary> /// <summary>
@ -141,6 +146,12 @@ namespace osu.Game.Rulesets.Objects
return interpolateVertices(indexOfDistance(d), d); return interpolateVertices(indexOfDistance(d), d);
} }
private void invalidate()
{
pathCache.Invalidate();
version.Value++;
}
private void ensureValid() private void ensureValid()
{ {
if (pathCache.IsValid) if (pathCache.IsValid)