Merge pull request #13235 from ekrctb/update-lifetime-1

Update hit object lifetime on `HitObject.DefaultsApplied`
This commit is contained in:
Dan Balasescu
2021-05-31 14:44:40 +09:00
committed by GitHub
2 changed files with 40 additions and 3 deletions

View File

@ -35,7 +35,11 @@ namespace osu.Game.Rulesets.Objects
HitObject = hitObject;
startTimeBindable.BindTo(HitObject.StartTimeBindable);
startTimeBindable.BindValueChanged(onStartTimeChanged, true);
startTimeBindable.BindValueChanged(_ => setInitialLifetime(), true);
// Subscribe to this event before the DrawableHitObject so that the local callback is invoked before the entry is re-applied as a result of DefaultsApplied.
// This way, the DrawableHitObject can use OnApply() to overwrite the LifetimeStart that was set inside setInitialLifetime().
HitObject.DefaultsApplied += _ => setInitialLifetime();
}
// The lifetime, as set by the hitobject.
@ -88,8 +92,8 @@ namespace osu.Game.Rulesets.Objects
protected virtual double InitialLifetimeOffset => 10000;
/// <summary>
/// Resets <see cref="LifetimeEntry.LifetimeStart"/> according to the change in start time of the <see cref="HitObject"/>.
/// Set <see cref="LifetimeEntry.LifetimeStart"/> using <see cref="InitialLifetimeOffset"/>.
/// </summary>
private void onStartTimeChanged(ValueChangedEvent<double> startTime) => LifetimeStart = HitObject.StartTime - InitialLifetimeOffset;
private void setInitialLifetime() => LifetimeStart = HitObject.StartTime - InitialLifetimeOffset;
}
}