1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-05 10:53:10 +08:00

Improve logic and add previously failing test

Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
This commit is contained in:
voidedWarranties 2021-03-17 15:31:16 -07:00
parent 21e18c9f6e
commit df6570ebf5
2 changed files with 39 additions and 22 deletions

View File

@ -49,14 +49,33 @@ namespace osu.Game.Tests.Visual.Editing
[Test] [Test]
public void TestStopAtTrackEnd() public void TestStopAtTrackEnd()
{ {
AddStep("Reset clock", () => Clock.Seek(0)); AddStep("reset clock", () => Clock.Seek(0));
AddStep("Start clock", Clock.Start);
AddAssert("Clock running", () => Clock.IsRunning); AddStep("start clock", Clock.Start);
AddStep("Seek near end", () => Clock.Seek(Clock.TrackLength - 250)); AddAssert("clock running", () => Clock.IsRunning);
AddUntilStep("Clock stops", () => !Clock.IsRunning);
AddAssert("Clock stopped at end", () => Clock.CurrentTime == Clock.TrackLength); AddStep("seek near end", () => Clock.Seek(Clock.TrackLength - 250));
AddStep("Start clock again", Clock.Start); AddUntilStep("clock stops", () => !Clock.IsRunning);
AddAssert("Clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500);
AddAssert("clock stopped at end", () => Clock.CurrentTime == Clock.TrackLength);
AddStep("start clock again", Clock.Start);
AddAssert("clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500);
}
[Test]
public void TestWrapWhenStoppedAtTrackEnd()
{
AddStep("reset clock", () => Clock.Seek(0));
AddStep("stop clock", Clock.Stop);
AddAssert("clock stopped", () => !Clock.IsRunning);
AddStep("seek exactly to end", () => Clock.Seek(Clock.TrackLength));
AddAssert("clock stopped at end", () => Clock.CurrentTime == Clock.TrackLength);
AddStep("start clock again", Clock.Start);
AddAssert("clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500);
} }
} }
} }

View File

@ -172,6 +172,10 @@ namespace osu.Game.Screens.Edit
public void Start() public void Start()
{ {
ClearTransforms(); ClearTransforms();
if (playbackFinished)
underlyingClock.Seek(0);
underlyingClock.Start(); underlyingClock.Start();
} }
@ -222,21 +226,15 @@ namespace osu.Game.Screens.Edit
{ {
underlyingClock.ProcessFrame(); underlyingClock.ProcessFrame();
if (IsRunning) var playbackAlreadyStopped = playbackFinished;
{ playbackFinished = CurrentTime >= TrackLength;
var playbackAlreadyStopped = playbackFinished;
playbackFinished = CurrentTime >= TrackLength;
if (playbackFinished) if (playbackFinished && !playbackAlreadyStopped)
{ {
if (!playbackAlreadyStopped) if (IsRunning)
{ underlyingClock.Stop();
underlyingClock.Stop();
underlyingClock.Seek(TrackLength); underlyingClock.Seek(TrackLength);
}
else
underlyingClock.Seek(0);
}
} }
} }