2020-07-27 08:46:10 +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-09-15 22:59:41 +00:00
|
|
|
using System;
|
2021-06-22 07:19:55 +00:00
|
|
|
using System.Collections.Generic;
|
2020-07-27 08:46:10 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2020-09-15 22:59:41 +00:00
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
using osu.Framework.Bindables;
|
2020-07-27 08:46:10 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Audio;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-09-15 22:59:41 +00:00
|
|
|
using osu.Framework.Graphics.OpenGL.Textures;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2020-07-27 08:46:10 +00: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
|
|
|
|
{
|
2020-09-15 22:59:41 +00:00
|
|
|
private TestSkinSourceContainer skinSource;
|
2020-09-30 06:45:14 +00:00
|
|
|
private PausableSkinnableSound skinnableSound;
|
2020-07-27 08:46:10 +00:00
|
|
|
|
|
|
|
[SetUp]
|
2020-10-14 12:40:49 +00:00
|
|
|
public void SetUpSteps()
|
2020-07-27 08:46:10 +00:00
|
|
|
{
|
2020-10-14 21:24:16 +00:00
|
|
|
AddStep("setup hierarchy", () =>
|
2020-07-27 08:46:10 +00:00
|
|
|
{
|
2021-05-27 06:39:35 +00:00
|
|
|
Child = skinSource = new TestSkinSourceContainer
|
2020-07-27 08:46:10 +00:00
|
|
|
{
|
2021-05-27 06:39:35 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-10-14 12:40:49 +00:00
|
|
|
};
|
2021-05-27 06:39:35 +00:00
|
|
|
|
|
|
|
// has to be added after the hierarchy above else the `ISkinSource` dependency won't be cached.
|
|
|
|
skinSource.Add(skinnableSound = new PausableSkinnableSound(new SampleInfo("Gameplay/normal-sliderslide")));
|
2020-10-14 12:40:49 +00:00
|
|
|
});
|
|
|
|
}
|
2020-07-27 08:46:10 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestStoppedSoundDoesntResumeAfterPause()
|
|
|
|
{
|
2021-01-20 05:05:35 +00:00
|
|
|
AddStep("start sample with looping", () =>
|
|
|
|
{
|
|
|
|
skinnableSound.Looping = true;
|
|
|
|
skinnableSound.Play();
|
|
|
|
});
|
2020-07-28 08:09:38 +00:00
|
|
|
|
2021-01-19 08:11:40 +00:00
|
|
|
AddUntilStep("wait for sample to start playing", () => skinnableSound.IsPlaying);
|
2020-07-27 08:46:10 +00:00
|
|
|
|
2020-07-27 08:46:44 +00:00
|
|
|
AddStep("stop sample", () => skinnableSound.Stop());
|
2020-07-27 08:46:10 +00:00
|
|
|
|
2021-01-19 08:11:40 +00:00
|
|
|
AddUntilStep("wait for sample to stop playing", () => !skinnableSound.IsPlaying);
|
2020-07-27 08:46:10 +00:00
|
|
|
|
2020-10-14 21:24:16 +00:00
|
|
|
AddStep("disable sample playback", () => skinSource.SamplePlaybackDisabled.Value = true);
|
2020-10-14 12:40:49 +00:00
|
|
|
|
2020-10-14 21:24:16 +00:00
|
|
|
AddStep("enable sample playback", () => skinSource.SamplePlaybackDisabled.Value = false);
|
2020-07-27 08:46:10 +00:00
|
|
|
|
2020-07-27 10:05:31 +00:00
|
|
|
AddWaitStep("wait a bit", 5);
|
2021-01-19 08:11:40 +00:00
|
|
|
AddAssert("sample not playing", () => !skinnableSound.IsPlaying);
|
2020-07-27 08:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLoopingSoundResumesAfterPause()
|
|
|
|
{
|
2021-01-20 05:05:35 +00:00
|
|
|
AddStep("start sample with looping", () =>
|
|
|
|
{
|
|
|
|
skinnableSound.Looping = true;
|
|
|
|
skinnableSound.Play();
|
|
|
|
});
|
2020-07-27 08:46:10 +00:00
|
|
|
|
2021-01-19 08:11:40 +00:00
|
|
|
AddUntilStep("wait for sample to start playing", () => skinnableSound.IsPlaying);
|
2020-07-27 08:46:10 +00:00
|
|
|
|
2020-10-14 21:24:16 +00:00
|
|
|
AddStep("disable sample playback", () => skinSource.SamplePlaybackDisabled.Value = true);
|
2021-01-19 08:11:40 +00:00
|
|
|
AddUntilStep("wait for sample to stop playing", () => !skinnableSound.IsPlaying);
|
2020-10-14 12:40:49 +00:00
|
|
|
|
2020-10-14 21:24:16 +00:00
|
|
|
AddStep("enable sample playback", () => skinSource.SamplePlaybackDisabled.Value = false);
|
2021-01-19 08:11:40 +00:00
|
|
|
AddUntilStep("wait for sample to start playing", () => skinnableSound.IsPlaying);
|
2020-07-27 08:46:10 +00:00
|
|
|
}
|
2020-07-27 09:02:14 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNonLoopingStopsWithPause()
|
|
|
|
{
|
2021-01-19 08:11:40 +00:00
|
|
|
AddStep("start sample", () => skinnableSound.Play());
|
2020-07-27 09:02:14 +00:00
|
|
|
|
2021-01-19 08:11:40 +00:00
|
|
|
AddAssert("sample playing", () => skinnableSound.IsPlaying);
|
2020-07-27 09:02:14 +00:00
|
|
|
|
2020-10-14 21:24:16 +00:00
|
|
|
AddStep("disable sample playback", () => skinSource.SamplePlaybackDisabled.Value = true);
|
2020-10-14 12:40:49 +00:00
|
|
|
|
2021-01-19 08:11:40 +00:00
|
|
|
AddUntilStep("sample not playing", () => !skinnableSound.IsPlaying);
|
2020-07-27 09:02:14 +00:00
|
|
|
|
2020-10-14 21:24:16 +00:00
|
|
|
AddStep("enable sample playback", () => skinSource.SamplePlaybackDisabled.Value = false);
|
2020-07-27 10:05:31 +00:00
|
|
|
|
2021-01-19 08:11:40 +00:00
|
|
|
AddAssert("sample not playing", () => !skinnableSound.IsPlaying);
|
|
|
|
AddAssert("sample not playing", () => !skinnableSound.IsPlaying);
|
|
|
|
AddAssert("sample not playing", () => !skinnableSound.IsPlaying);
|
2020-07-27 09:02:14 +00:00
|
|
|
}
|
2020-09-15 22:59:41 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSkinChangeDoesntPlayOnPause()
|
|
|
|
{
|
|
|
|
DrawableSample sample = null;
|
|
|
|
AddStep("start sample", () =>
|
|
|
|
{
|
|
|
|
skinnableSound.Play();
|
|
|
|
sample = skinnableSound.ChildrenOfType<DrawableSample>().Single();
|
|
|
|
});
|
|
|
|
|
2021-01-19 08:11:40 +00:00
|
|
|
AddAssert("sample playing", () => skinnableSound.IsPlaying);
|
2020-09-15 22:59:41 +00:00
|
|
|
|
2020-10-14 21:24:16 +00:00
|
|
|
AddStep("disable sample playback", () => skinSource.SamplePlaybackDisabled.Value = true);
|
2021-01-19 08:11:40 +00:00
|
|
|
AddUntilStep("wait for sample to stop playing", () => !skinnableSound.IsPlaying);
|
2020-09-15 22:59:41 +00:00
|
|
|
|
2020-09-19 02:55:28 +00:00
|
|
|
AddStep("trigger skin change", () => skinSource.TriggerSourceChanged());
|
2020-09-15 22:59:41 +00:00
|
|
|
|
2020-09-19 02:56:35 +00:00
|
|
|
AddAssert("retrieve and ensure current sample is different", () =>
|
2020-09-15 22:59:41 +00:00
|
|
|
{
|
2020-09-19 02:56:35 +00:00
|
|
|
DrawableSample oldSample = sample;
|
|
|
|
sample = skinnableSound.ChildrenOfType<DrawableSample>().Single();
|
|
|
|
return sample != oldSample;
|
2020-09-15 22:59:41 +00:00
|
|
|
});
|
|
|
|
|
2021-01-19 08:11:40 +00:00
|
|
|
AddAssert("new sample stopped", () => !skinnableSound.IsPlaying);
|
2020-10-14 21:24:16 +00:00
|
|
|
AddStep("enable sample playback", () => skinSource.SamplePlaybackDisabled.Value = false);
|
2020-09-15 22:59:41 +00:00
|
|
|
|
|
|
|
AddWaitStep("wait a bit", 5);
|
2021-01-19 08:11:40 +00:00
|
|
|
AddAssert("new sample not played", () => !skinnableSound.IsPlaying);
|
2020-09-15 22:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Cached(typeof(ISkinSource))]
|
2020-10-14 12:40:49 +00:00
|
|
|
[Cached(typeof(ISamplePlaybackDisabler))]
|
|
|
|
private class TestSkinSourceContainer : Container, ISkinSource, ISamplePlaybackDisabler
|
2020-09-15 22:59:41 +00:00
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private ISkinSource source { get; set; }
|
|
|
|
|
|
|
|
public event Action SourceChanged;
|
|
|
|
|
2020-10-14 12:40:49 +00:00
|
|
|
public Bindable<bool> SamplePlaybackDisabled { get; } = new Bindable<bool>();
|
|
|
|
|
|
|
|
IBindable<bool> ISamplePlaybackDisabler.SamplePlaybackDisabled => SamplePlaybackDisabled;
|
|
|
|
|
2020-09-15 22:59:41 +00:00
|
|
|
public Drawable GetDrawableComponent(ISkinComponent component) => source?.GetDrawableComponent(component);
|
|
|
|
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => source?.GetTexture(componentName, wrapModeS, wrapModeT);
|
2021-02-18 09:32:28 +00:00
|
|
|
public ISample GetSample(ISampleInfo sampleInfo) => source?.GetSample(sampleInfo);
|
2020-09-15 22:59:41 +00:00
|
|
|
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => source?.GetConfig<TLookup, TValue>(lookup);
|
2021-06-22 09:02:21 +00:00
|
|
|
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => lookupFunction(this) ? this : source?.FindProvider(lookupFunction);
|
2021-06-22 09:25:29 +00:00
|
|
|
public IEnumerable<ISkin> AllSources => new[] { this }.Concat(source?.AllSources ?? Enumerable.Empty<ISkin>());
|
2020-09-15 22:59:41 +00:00
|
|
|
|
|
|
|
public void TriggerSourceChanged()
|
|
|
|
{
|
|
|
|
SourceChanged?.Invoke();
|
|
|
|
}
|
|
|
|
}
|
2020-07-27 08:46:10 +00:00
|
|
|
}
|
|
|
|
}
|