2020-07-27 16:46:10 +08: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.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Audio;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
|
|
|
public class TestSceneSkinnableSound : OsuTestScene
|
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
private GameplayClock gameplayClock = new GameplayClock(new FramedClock());
|
|
|
|
|
2020-07-27 16:46:44 +08:00
|
|
|
private SkinnableSound skinnableSound;
|
2020-07-27 16:46:10 +08:00
|
|
|
|
|
|
|
[SetUp]
|
2020-07-27 18:03:21 +08:00
|
|
|
public void SetUp() => Schedule(() =>
|
2020-07-27 16:46:10 +08:00
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Clock = gameplayClock,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-07-27 17:02:14 +08:00
|
|
|
Child = skinnableSound = new SkinnableSound(new SampleInfo("normal-sliderslide"))
|
2020-07-27 16:46:10 +08:00
|
|
|
},
|
|
|
|
};
|
2020-07-27 18:03:21 +08:00
|
|
|
});
|
2020-07-27 16:46:10 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestStoppedSoundDoesntResumeAfterPause()
|
|
|
|
{
|
|
|
|
DrawableSample sample = null;
|
2020-07-27 17:02:14 +08:00
|
|
|
AddStep("start sample with looping", () =>
|
2020-07-27 16:46:10 +08:00
|
|
|
{
|
2020-07-27 17:02:14 +08:00
|
|
|
skinnableSound.Looping = true;
|
2020-07-27 16:46:44 +08:00
|
|
|
skinnableSound.Play();
|
|
|
|
sample = skinnableSound.ChildrenOfType<DrawableSample>().First();
|
2020-07-27 16:46:10 +08:00
|
|
|
});
|
|
|
|
|
2020-07-27 17:02:14 +08:00
|
|
|
AddAssert("sample playing", () => sample.Playing);
|
2020-07-27 16:46:10 +08:00
|
|
|
|
2020-07-27 16:46:44 +08:00
|
|
|
AddStep("stop sample", () => skinnableSound.Stop());
|
2020-07-27 16:46:10 +08:00
|
|
|
|
2020-07-27 17:02:14 +08:00
|
|
|
AddAssert("sample not playing", () => !sample.Playing);
|
2020-07-27 16:46:10 +08:00
|
|
|
|
|
|
|
AddStep("pause gameplay clock", () => gameplayClock.IsPaused.Value = true);
|
|
|
|
AddStep("resume gameplay clock", () => gameplayClock.IsPaused.Value = false);
|
|
|
|
|
|
|
|
AddAssert("sample not playing", () => !sample.Playing);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLoopingSoundResumesAfterPause()
|
|
|
|
{
|
|
|
|
DrawableSample sample = null;
|
2020-07-27 17:02:14 +08:00
|
|
|
AddStep("start sample with looping", () =>
|
2020-07-27 16:46:10 +08:00
|
|
|
{
|
2020-07-27 17:02:14 +08:00
|
|
|
skinnableSound.Looping = true;
|
2020-07-27 16:46:44 +08:00
|
|
|
skinnableSound.Play();
|
|
|
|
sample = skinnableSound.ChildrenOfType<DrawableSample>().First();
|
2020-07-27 16:46:10 +08:00
|
|
|
});
|
|
|
|
|
2020-07-27 17:02:14 +08:00
|
|
|
AddAssert("sample playing", () => sample.Playing);
|
2020-07-27 16:46:10 +08:00
|
|
|
|
|
|
|
AddStep("pause gameplay clock", () => gameplayClock.IsPaused.Value = true);
|
2020-07-27 17:02:14 +08:00
|
|
|
AddAssert("sample not playing", () => !sample.Playing);
|
2020-07-27 16:46:10 +08:00
|
|
|
|
|
|
|
AddStep("resume gameplay clock", () => gameplayClock.IsPaused.Value = false);
|
|
|
|
AddUntilStep("wait for sample to start playing", () => sample.Playing);
|
|
|
|
}
|
2020-07-27 17:02:14 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNonLoopingStopsWithPause()
|
|
|
|
{
|
|
|
|
DrawableSample sample = null;
|
|
|
|
AddStep("start sample", () =>
|
|
|
|
{
|
|
|
|
skinnableSound.Play();
|
|
|
|
sample = skinnableSound.ChildrenOfType<DrawableSample>().First();
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("sample playing", () => sample.Playing);
|
|
|
|
|
|
|
|
AddStep("pause gameplay clock", () => gameplayClock.IsPaused.Value = true);
|
|
|
|
AddAssert("sample not playing", () => !sample.Playing);
|
|
|
|
|
|
|
|
AddStep("resume gameplay clock", () => gameplayClock.IsPaused.Value = false);
|
|
|
|
AddAssert("sample not playing", () => !sample.Playing);
|
|
|
|
}
|
2020-07-27 16:46:10 +08:00
|
|
|
}
|
|
|
|
}
|