1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 07:22:54 +08:00

Fix test failures and general discrepancies

This commit is contained in:
smoogipoo 2021-01-20 14:05:35 +09:00
parent bdb9d4f7d0
commit 8ffbcc9860
5 changed files with 28 additions and 15 deletions

View File

@ -19,14 +19,14 @@ namespace osu.Game.Tests.Visual.Editing
public void TestSlidingSampleStopsOnSeek()
{
DrawableSlider slider = null;
SkinnableSound[] loopingSamples = null;
SkinnableSound[] onceOffSamples = null;
PoolableSkinnableSample[] loopingSamples = null;
PoolableSkinnableSample[] onceOffSamples = null;
AddStep("get first slider", () =>
{
slider = Editor.ChildrenOfType<DrawableSlider>().OrderBy(s => s.HitObject.StartTime).First();
onceOffSamples = slider.ChildrenOfType<SkinnableSound>().Where(s => !s.Looping).ToArray();
loopingSamples = slider.ChildrenOfType<SkinnableSound>().Where(s => s.Looping).ToArray();
onceOffSamples = slider.ChildrenOfType<PoolableSkinnableSample>().Where(s => !s.Looping).ToArray();
loopingSamples = slider.ChildrenOfType<PoolableSkinnableSample>().Where(s => s.Looping).ToArray();
});
AddStep("start playback", () => EditorClock.Start());
@ -36,15 +36,15 @@ namespace osu.Game.Tests.Visual.Editing
if (!slider.Tracking.Value)
return false;
if (!loopingSamples.Any(s => s.IsPlaying))
if (!loopingSamples.Any(s => s.Playing))
return false;
EditorClock.Seek(20000);
return true;
});
AddAssert("non-looping samples are playing", () => onceOffSamples.Length == 4 && loopingSamples.All(s => s.IsPlayed || s.IsPlaying));
AddAssert("looping samples are not playing", () => loopingSamples.Length == 1 && loopingSamples.All(s => s.IsPlayed && !s.IsPlaying));
AddAssert("non-looping samples are playing", () => onceOffSamples.Length == 4 && loopingSamples.All(s => s.Played || s.Playing));
AddAssert("looping samples are not playing", () => loopingSamples.Length == 1 && loopingSamples.All(s => s.Played && !s.Playing));
}
}
}

View File

@ -19,14 +19,14 @@ namespace osu.Game.Tests.Visual.Gameplay
public void TestAllSamplesStopDuringSeek()
{
DrawableSlider slider = null;
SkinnableSound[] samples = null;
PoolableSkinnableSample[] samples = null;
ISamplePlaybackDisabler sampleDisabler = null;
AddUntilStep("get variables", () =>
{
sampleDisabler = Player;
slider = Player.ChildrenOfType<DrawableSlider>().OrderBy(s => s.HitObject.StartTime).FirstOrDefault();
samples = slider?.ChildrenOfType<SkinnableSound>().ToArray();
samples = slider?.ChildrenOfType<PoolableSkinnableSample>().ToArray();
return slider != null;
});
@ -36,7 +36,7 @@ namespace osu.Game.Tests.Visual.Gameplay
if (!slider.Tracking.Value)
return false;
if (!samples.Any(s => s.IsPlaying))
if (!samples.Any(s => s.Playing))
return false;
Player.ChildrenOfType<GameplayClockContainer>().First().Seek(40000);

View File

@ -43,7 +43,11 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestStoppedSoundDoesntResumeAfterPause()
{
AddStep("start sample with looping", () => skinnableSound.Looping = true);
AddStep("start sample with looping", () =>
{
skinnableSound.Looping = true;
skinnableSound.Play();
});
AddUntilStep("wait for sample to start playing", () => skinnableSound.IsPlaying);
@ -62,7 +66,11 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestLoopingSoundResumesAfterPause()
{
AddStep("start sample with looping", () => skinnableSound.Looping = true);
AddStep("start sample with looping", () =>
{
skinnableSound.Looping = true;
skinnableSound.Play();
});
AddUntilStep("wait for sample to start playing", () => skinnableSound.IsPlaying);

View File

@ -155,7 +155,6 @@ namespace osu.Game.Graphics.UserInterface
return;
lastSampleValue = value;
lastSampleTime = Clock.CurrentTime;
var channel = sample.Play();

View File

@ -117,19 +117,25 @@ namespace osu.Game.Skinning
activeChannel = Sample.Play();
activeChannel.Looping = Looping;
Played = true;
}
/// <summary>
/// Stops the sample.
/// </summary>
public void Stop() => activeChannel?.Stop();
public void Stop()
{
activeChannel?.Stop();
activeChannel = null;
}
/// <summary>
/// Whether the sample is currently playing.
/// </summary>
public bool Playing => activeChannel?.Playing ?? false;
public bool Played => !activeChannel?.Playing ?? false;
public bool Played { get; private set; }
private bool looping;