mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 08:22:56 +08:00
Improve logic and add previously failing test
Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
This commit is contained in:
parent
21e18c9f6e
commit
df6570ebf5
@ -49,14 +49,33 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
[Test]
|
||||
public void TestStopAtTrackEnd()
|
||||
{
|
||||
AddStep("Reset clock", () => Clock.Seek(0));
|
||||
AddStep("Start clock", Clock.Start);
|
||||
AddAssert("Clock running", () => Clock.IsRunning);
|
||||
AddStep("Seek near end", () => Clock.Seek(Clock.TrackLength - 250));
|
||||
AddUntilStep("Clock stops", () => !Clock.IsRunning);
|
||||
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);
|
||||
AddStep("reset clock", () => Clock.Seek(0));
|
||||
|
||||
AddStep("start clock", Clock.Start);
|
||||
AddAssert("clock running", () => Clock.IsRunning);
|
||||
|
||||
AddStep("seek near end", () => Clock.Seek(Clock.TrackLength - 250));
|
||||
AddUntilStep("clock stops", () => !Clock.IsRunning);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,6 +172,10 @@ namespace osu.Game.Screens.Edit
|
||||
public void Start()
|
||||
{
|
||||
ClearTransforms();
|
||||
|
||||
if (playbackFinished)
|
||||
underlyingClock.Seek(0);
|
||||
|
||||
underlyingClock.Start();
|
||||
}
|
||||
|
||||
@ -222,21 +226,15 @@ namespace osu.Game.Screens.Edit
|
||||
{
|
||||
underlyingClock.ProcessFrame();
|
||||
|
||||
if (IsRunning)
|
||||
{
|
||||
var playbackAlreadyStopped = playbackFinished;
|
||||
playbackFinished = CurrentTime >= TrackLength;
|
||||
var playbackAlreadyStopped = playbackFinished;
|
||||
playbackFinished = CurrentTime >= TrackLength;
|
||||
|
||||
if (playbackFinished)
|
||||
{
|
||||
if (!playbackAlreadyStopped)
|
||||
{
|
||||
underlyingClock.Stop();
|
||||
underlyingClock.Seek(TrackLength);
|
||||
}
|
||||
else
|
||||
underlyingClock.Seek(0);
|
||||
}
|
||||
if (playbackFinished && !playbackAlreadyStopped)
|
||||
{
|
||||
if (IsRunning)
|
||||
underlyingClock.Stop();
|
||||
|
||||
underlyingClock.Seek(TrackLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user