1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 07:53:38 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableSound.cs

168 lines
6.2 KiB
C#
Raw Normal View History

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;
2020-07-27 16:46:10 +08:00
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
2020-07-27 16:46:10 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Textures;
2020-07-27 16:46:10 +08:00
using osu.Framework.Testing;
using osu.Game.Audio;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneSkinnableSound : OsuTestScene
{
private TestSkinSourceContainer skinSource;
private PausableSkinnableSound skinnableSound;
2020-07-27 16:46:10 +08:00
[SetUp]
2020-10-14 20:40:49 +08:00
public void SetUpSteps()
2020-07-27 16:46:10 +08:00
{
2020-10-15 05:24:16 +08:00
AddStep("setup hierarchy", () =>
2020-07-27 16:46:10 +08:00
{
2020-10-14 20:40:49 +08:00
Children = new Drawable[]
2020-07-27 16:46:10 +08:00
{
2020-10-14 20:40:49 +08:00
skinSource = new TestSkinSourceContainer
{
RelativeSizeAxes = Axes.Both,
Child = skinnableSound = new PausableSkinnableSound(new SampleInfo("Gameplay/normal-sliderslide"))
2020-10-14 20:40:49 +08:00
},
};
});
}
2020-07-27 16:46:10 +08:00
[Test]
public void TestStoppedSoundDoesntResumeAfterPause()
{
DrawableSample sample = null;
AddStep("start sample with looping", () =>
2020-07-27 16:46:10 +08:00
{
sample = skinnableSound.ChildrenOfType<DrawableSample>().First();
skinnableSound.Looping = true;
2020-07-27 16:46:44 +08:00
skinnableSound.Play();
2020-07-27 16:46:10 +08:00
});
AddUntilStep("wait for sample to start 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
AddUntilStep("wait for sample to stop playing", () => !sample.Playing);
2020-07-27 16:46:10 +08:00
2020-10-15 05:24:16 +08:00
AddStep("disable sample playback", () => skinSource.SamplePlaybackDisabled.Value = true);
2020-10-14 20:40:49 +08:00
2020-10-15 05:24:16 +08:00
AddStep("enable sample playback", () => skinSource.SamplePlaybackDisabled.Value = false);
2020-07-27 16:46:10 +08:00
AddWaitStep("wait a bit", 5);
2020-07-27 16:46:10 +08:00
AddAssert("sample not playing", () => !sample.Playing);
}
[Test]
public void TestLoopingSoundResumesAfterPause()
{
DrawableSample sample = null;
AddStep("start sample with looping", () =>
2020-07-27 16:46:10 +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
});
AddUntilStep("wait for sample to start playing", () => sample.Playing);
2020-07-27 16:46:10 +08:00
2020-10-15 05:24:16 +08:00
AddStep("disable sample playback", () => skinSource.SamplePlaybackDisabled.Value = true);
AddUntilStep("wait for sample to stop playing", () => !sample.Playing);
2020-10-14 20:40:49 +08:00
2020-10-15 05:24:16 +08:00
AddStep("enable sample playback", () => skinSource.SamplePlaybackDisabled.Value = false);
2020-10-14 20:40:49 +08:00
AddUntilStep("wait for sample to start playing", () => sample.Playing);
2020-07-27 16:46:10 +08:00
}
[Test]
public void TestNonLoopingStopsWithPause()
{
DrawableSample sample = null;
AddStep("start sample", () =>
{
skinnableSound.Play();
sample = skinnableSound.ChildrenOfType<DrawableSample>().First();
});
AddAssert("sample playing", () => sample.Playing);
2020-10-15 05:24:16 +08:00
AddStep("disable sample playback", () => skinSource.SamplePlaybackDisabled.Value = true);
2020-10-14 20:40:49 +08:00
AddUntilStep("sample not playing", () => !sample.Playing);
2020-10-15 05:24:16 +08:00
AddStep("enable sample playback", () => skinSource.SamplePlaybackDisabled.Value = false);
AddAssert("sample not playing", () => !sample.Playing);
AddAssert("sample not playing", () => !sample.Playing);
AddAssert("sample not playing", () => !sample.Playing);
}
[Test]
public void TestSkinChangeDoesntPlayOnPause()
{
DrawableSample sample = null;
AddStep("start sample", () =>
{
skinnableSound.Play();
sample = skinnableSound.ChildrenOfType<DrawableSample>().Single();
});
AddAssert("sample playing", () => sample.Playing);
2020-10-15 05:24:16 +08:00
AddStep("disable sample playback", () => skinSource.SamplePlaybackDisabled.Value = true);
AddUntilStep("wait for sample to stop playing", () => !sample.Playing);
2020-09-19 10:55:28 +08:00
AddStep("trigger skin change", () => skinSource.TriggerSourceChanged());
AddAssert("retrieve and ensure current sample is different", () =>
{
DrawableSample oldSample = sample;
sample = skinnableSound.ChildrenOfType<DrawableSample>().Single();
return sample != oldSample;
});
2020-09-19 10:55:39 +08:00
AddAssert("new sample stopped", () => !sample.Playing);
2020-10-15 05:24:16 +08:00
AddStep("enable sample playback", () => skinSource.SamplePlaybackDisabled.Value = false);
AddWaitStep("wait a bit", 5);
AddAssert("new sample not played", () => !sample.Playing);
}
[Cached(typeof(ISkinSource))]
2020-10-14 20:40:49 +08:00
[Cached(typeof(ISamplePlaybackDisabler))]
private class TestSkinSourceContainer : Container, ISkinSource, ISamplePlaybackDisabler
{
[Resolved]
private ISkinSource source { get; set; }
public event Action SourceChanged;
2020-10-14 20:40:49 +08:00
public Bindable<bool> SamplePlaybackDisabled { get; } = new Bindable<bool>();
IBindable<bool> ISamplePlaybackDisabler.SamplePlaybackDisabled => SamplePlaybackDisabled;
public Drawable GetDrawableComponent(ISkinComponent component) => source?.GetDrawableComponent(component);
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => source?.GetTexture(componentName, wrapModeS, wrapModeT);
public SampleChannel GetSample(ISampleInfo sampleInfo) => source?.GetSample(sampleInfo);
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => source?.GetConfig<TLookup, TValue>(lookup);
public void TriggerSourceChanged()
{
SourceChanged?.Invoke();
}
}
2020-07-27 16:46:10 +08:00
}
}