2020-10-05 04:16:45 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2020-10-05 19:22:07 +00:00
|
|
|
using System.Collections.Generic;
|
2020-10-05 04:16:45 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics.Audio;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
|
|
|
public class TestSceneGameplaySamplePlayback : PlayerTestScene
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestAllSamplesStopDuringSeek()
|
|
|
|
{
|
|
|
|
DrawableSlider slider = null;
|
|
|
|
DrawableSample[] samples = null;
|
2020-10-27 05:35:12 +00:00
|
|
|
ISamplePlaybackDisabler sampleDisabler = null;
|
2020-10-05 04:16:45 +00:00
|
|
|
|
|
|
|
AddStep("get variables", () =>
|
|
|
|
{
|
2020-10-27 05:35:12 +00:00
|
|
|
sampleDisabler = Player;
|
2020-10-05 04:16:45 +00:00
|
|
|
slider = Player.ChildrenOfType<DrawableSlider>().OrderBy(s => s.HitObject.StartTime).First();
|
|
|
|
samples = slider.ChildrenOfType<DrawableSample>().ToArray();
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for slider sliding then seek", () =>
|
|
|
|
{
|
|
|
|
if (!slider.Tracking.Value)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!samples.Any(s => s.Playing))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Player.ChildrenOfType<GameplayClockContainer>().First().Seek(40000);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2020-10-27 05:35:12 +00:00
|
|
|
AddAssert("sample playback disabled", () => sampleDisabler.SamplePlaybackDisabled.Value);
|
2020-10-05 04:16:45 +00:00
|
|
|
|
|
|
|
// because we are in frame stable context, it's quite likely that not all samples are "played" at this point.
|
|
|
|
// the important thing is that at least one started, and that sample has since stopped.
|
2020-10-05 19:22:07 +00:00
|
|
|
AddAssert("all looping samples stopped immediately", () => allStopped(allLoopingSounds));
|
|
|
|
AddUntilStep("all samples stopped eventually", () => allStopped(allSounds));
|
2020-10-05 04:16:45 +00:00
|
|
|
|
2020-10-27 05:35:12 +00:00
|
|
|
AddAssert("sample playback still disabled", () => sampleDisabler.SamplePlaybackDisabled.Value);
|
2020-10-05 04:16:45 +00:00
|
|
|
|
2020-10-27 05:35:12 +00:00
|
|
|
AddUntilStep("seek finished, sample playback enabled", () => !sampleDisabler.SamplePlaybackDisabled.Value);
|
2020-10-05 04:16:45 +00:00
|
|
|
AddUntilStep("any sample is playing", () => Player.ChildrenOfType<PausableSkinnableSound>().Any(s => s.IsPlaying));
|
|
|
|
}
|
|
|
|
|
2020-10-05 19:22:07 +00:00
|
|
|
private IEnumerable<PausableSkinnableSound> allSounds => Player.ChildrenOfType<PausableSkinnableSound>();
|
|
|
|
private IEnumerable<PausableSkinnableSound> allLoopingSounds => allSounds.Where(sound => sound.Looping);
|
|
|
|
|
|
|
|
private bool allStopped(IEnumerable<PausableSkinnableSound> sounds) => sounds.All(sound => !sound.IsPlaying);
|
|
|
|
|
2020-10-05 04:16:45 +00:00
|
|
|
protected override bool Autoplay => true;
|
|
|
|
|
|
|
|
protected override Ruleset CreatePlayerRuleset() => new OsuRuleset();
|
|
|
|
}
|
|
|
|
}
|