diff --git a/osu.Game/Screens/Edit/EditorClock.cs b/osu.Game/Screens/Edit/EditorClock.cs index ddde819757..a084096c3b 100644 --- a/osu.Game/Screens/Edit/EditorClock.cs +++ b/osu.Game/Screens/Edit/EditorClock.cs @@ -12,18 +12,20 @@ namespace osu.Game.Screens.Edit { public class EditorClock : DecoupleableInterpolatingFramedClock { - private readonly ControlPointInfo controlPointInfo; + public ControlPointInfo ControlPointInfo; + private readonly BindableBeatDivisor beatDivisor; public EditorClock(ControlPointInfo controlPointInfo, BindableBeatDivisor beatDivisor) { - this.controlPointInfo = controlPointInfo; this.beatDivisor = beatDivisor; + + ControlPointInfo = controlPointInfo; } public bool SeekSnapped(double position) { - var timingPoint = controlPointInfo.TimingPointAt(position); + var timingPoint = ControlPointInfo.TimingPointAt(position); double beatSnapLength = timingPoint.BeatLength / beatDivisor; // We will be snapping to beats within the timing point @@ -35,7 +37,7 @@ namespace osu.Game.Screens.Edit // Depending on beatSnapLength, we may snap to a beat that is beyond timingPoint's end time, but we want to instead snap to // the next timing point's start time - var nextTimingPoint = controlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time); + var nextTimingPoint = ControlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time); if (position > nextTimingPoint?.Time) position = nextTimingPoint.Time; @@ -56,19 +58,19 @@ namespace osu.Game.Screens.Edit private void seek(int direction, bool snapped) { - var timingPoint = controlPointInfo.TimingPointAt(CurrentTime); + var timingPoint = ControlPointInfo.TimingPointAt(CurrentTime); if (direction < 0 && timingPoint.Time == CurrentTime) { // When going backwards and we're at the boundary of two timing points, we compute the seek distance with the timing point which we are seeking into - int activeIndex = controlPointInfo.TimingPoints.IndexOf(timingPoint); + int activeIndex = ControlPointInfo.TimingPoints.IndexOf(timingPoint); while (activeIndex > 0 && CurrentTime == timingPoint.Time) - timingPoint = controlPointInfo.TimingPoints[--activeIndex]; + timingPoint = ControlPointInfo.TimingPoints[--activeIndex]; } double seekAmount = timingPoint.BeatLength / beatDivisor; double seekTime = CurrentTime + seekAmount * direction; - if (!snapped || controlPointInfo.TimingPoints.Count == 0) + if (!snapped || ControlPointInfo.TimingPoints.Count == 0) { Seek(seekTime); return; @@ -94,10 +96,10 @@ namespace osu.Game.Screens.Edit seekTime = timingPoint.Time + closestBeat * seekAmount; } - if (seekTime < timingPoint.Time && timingPoint != controlPointInfo.TimingPoints.First()) + if (seekTime < timingPoint.Time && timingPoint != ControlPointInfo.TimingPoints.First()) seekTime = timingPoint.Time; - var nextTimingPoint = controlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time); + var nextTimingPoint = ControlPointInfo.TimingPoints.FirstOrDefault(t => t.Time > timingPoint.Time); if (seekTime > nextTimingPoint?.Time) seekTime = nextTimingPoint.Time; diff --git a/osu.Game/Tests/Visual/EditorClockTestCase.cs b/osu.Game/Tests/Visual/EditorClockTestCase.cs index 202100c810..3e42f7a242 100644 --- a/osu.Game/Tests/Visual/EditorClockTestCase.cs +++ b/osu.Game/Tests/Visual/EditorClockTestCase.cs @@ -5,6 +5,7 @@ using osu.Framework.Allocation; using osu.Framework.Input; using osu.Framework.Timing; using osu.Game.Beatmaps; +using osu.Game.Beatmaps.ControlPoints; using osu.Game.Screens.Edit; using osu.Game.Screens.Edit.Screens.Compose; @@ -17,7 +18,7 @@ namespace osu.Game.Tests.Visual public abstract class EditorClockTestCase : OsuTestCase { protected readonly BindableBeatDivisor BeatDivisor = new BindableBeatDivisor(); - protected EditorClock Clock { get; private set; } + protected readonly EditorClock Clock; private DependencyContainer dependencies; @@ -26,31 +27,26 @@ namespace osu.Game.Tests.Visual private OsuGameBase osuGame; + protected EditorClockTestCase() + { + Clock = new EditorClock(new ControlPointInfo(), BeatDivisor) { IsCoupled = false }; + } + [BackgroundDependencyLoader] private void load(OsuGameBase osuGame) { this.osuGame = osuGame; dependencies.Cache(BeatDivisor); - - osuGame.Beatmap.ValueChanged += reinitializeClock; - reinitializeClock(osuGame.Beatmap.Value); - } - - protected override void Dispose(bool isDisposing) - { - osuGame.Beatmap.ValueChanged -= reinitializeClock; - - base.Dispose(isDisposing); - } - - private void reinitializeClock(WorkingBeatmap working) - { - Clock = new EditorClock(working.Beatmap.ControlPointInfo, BeatDivisor) { IsCoupled = false }; dependencies.CacheAs(Clock); dependencies.CacheAs(Clock); + + osuGame.Beatmap.ValueChanged += beatmapChanged; + beatmapChanged(osuGame.Beatmap.Value); } + private void beatmapChanged(WorkingBeatmap working) => Clock.ControlPointInfo = working.Beatmap.ControlPointInfo; + protected override bool OnWheel(InputState state) { if (state.Mouse.WheelDelta > 0) @@ -60,5 +56,12 @@ namespace osu.Game.Tests.Visual return true; } + + protected override void Dispose(bool isDisposing) + { + osuGame.Beatmap.ValueChanged -= beatmapChanged; + + base.Dispose(isDisposing); + } } }