1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 09:17:48 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneStoryboardSamplePlayback.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

153 lines
5.8 KiB
C#
Raw Normal View History

2021-01-25 06:46:54 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
2022-03-03 01:32:03 +08:00
using System;
2021-01-25 06:46:54 +08:00
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
2022-03-03 01:32:03 +08:00
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics.Audio;
2021-01-25 06:46:54 +08:00
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets;
2022-03-03 01:32:03 +08:00
using osu.Game.Rulesets.Mods;
2021-01-25 06:46:54 +08:00
using osu.Game.Rulesets.Osu;
2022-03-03 01:32:03 +08:00
using osu.Game.Rulesets.Osu.Mods;
2021-01-25 06:46:54 +08:00
using osu.Game.Storyboards;
using osu.Game.Storyboards.Drawables;
2022-03-03 01:32:03 +08:00
using osuTK.Input;
2021-01-25 06:46:54 +08:00
namespace osu.Game.Tests.Visual.Gameplay
{
public partial class TestSceneStoryboardSamplePlayback : PlayerTestScene
{
private Storyboard storyboard;
2022-03-03 01:32:03 +08:00
private IReadOnlyList<Mod> storyboardMods;
protected override bool HasCustomSteps => true;
2021-01-25 06:46:54 +08:00
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
config.SetValue(OsuSetting.ShowStoryboard, true);
2021-01-25 06:46:54 +08:00
storyboard = new Storyboard();
var backgroundLayer = storyboard.GetLayer("Background");
backgroundLayer.Add(new StoryboardSampleInfo("Intro/welcome.mp3", time: -7000, volume: 20));
backgroundLayer.Add(new StoryboardSampleInfo("Intro/welcome.mp3", time: -5000, volume: 20));
backgroundLayer.Add(new StoryboardSampleInfo("Intro/welcome.mp3", time: 0, volume: 20));
backgroundLayer.Add(new StoryboardSampleInfo("Intro/welcome.mp3", time: 2000, volume: 20));
2021-01-25 06:46:54 +08:00
}
2022-03-03 01:32:03 +08:00
[SetUp]
public void SetUp() => storyboardMods = Array.Empty<Mod>();
2022-03-03 01:32:03 +08:00
2021-01-25 06:46:54 +08:00
[Test]
public void TestStoryboardSamplesStopDuringPause()
{
2022-03-03 01:32:03 +08:00
createPlayerTest();
2021-01-25 06:46:54 +08:00
AddStep("player paused", () => Player.Pause());
AddAssert("player is currently paused", () => Player.GameplayClockContainer.IsPaused.Value);
2022-03-03 05:02:36 +08:00
allStoryboardSamplesStopped();
2021-01-25 06:46:54 +08:00
AddStep("player resume", () => Player.Resume());
waitUntilStoryboardSamplesPlay();
2021-01-25 06:46:54 +08:00
}
[Test]
public void TestStoryboardSamplesStopOnSkip()
{
createPlayerTest();
2021-01-25 06:46:54 +08:00
skipIntro();
2022-03-03 05:02:36 +08:00
allStoryboardSamplesStopped();
2021-01-25 06:46:54 +08:00
waitUntilStoryboardSamplesPlay();
2021-01-25 06:46:54 +08:00
}
2022-03-03 01:32:03 +08:00
[TestCase(typeof(OsuModDoubleTime), 1.5)]
[TestCase(typeof(OsuModDoubleTime), 2)]
[TestCase(typeof(OsuModHalfTime), 0.75)]
[TestCase(typeof(OsuModHalfTime), 0.5)]
public void TestStoryboardSamplesPlaybackWithRateAdjustMods(Type expectedMod, double expectedRate)
{
AddStep("setup mod", () =>
{
ModRateAdjust testedMod = (ModRateAdjust)Activator.CreateInstance(expectedMod).AsNonNull();
testedMod.SpeedChange.Value = expectedRate;
storyboardMods = new[] { testedMod };
});
createPlayerTest();
skipIntro();
2022-03-03 01:32:03 +08:00
AddAssert("sample playback rate matches mod rates", () => allStoryboardSamples.All(sound =>
sound.ChildrenOfType<DrawableSample>().First().AggregateFrequency.Value == expectedRate));
2022-03-03 01:32:03 +08:00
}
[TestCase(typeof(ModWindUp), 0.5, 2)]
[TestCase(typeof(ModWindUp), 1.51, 2)]
[TestCase(typeof(ModWindDown), 2, 0.5)]
[TestCase(typeof(ModWindDown), 0.99, 0.5)]
public void TestStoryboardSamplesPlaybackWithTimeRampMods(Type expectedMod, double initialRate, double finalRate)
{
AddStep("setup mod", () =>
{
ModTimeRamp testedMod = (ModTimeRamp)Activator.CreateInstance(expectedMod).AsNonNull();
testedMod.InitialRate.Value = initialRate;
testedMod.FinalRate.Value = finalRate;
storyboardMods = new[] { testedMod };
});
createPlayerTest();
skipIntro();
2022-03-03 01:32:03 +08:00
ModTimeRamp gameplayMod = null;
AddUntilStep("mod speed change updated", () =>
{
gameplayMod = Player.GameplayState.Mods.OfType<ModTimeRamp>().Single();
return gameplayMod.SpeedChange.Value != initialRate;
});
AddAssert("sample playback rate matches mod rates", () => allStoryboardSamples.All(sound =>
sound.ChildrenOfType<DrawableSample>().First().AggregateFrequency.Value == gameplayMod.SpeedChange.Value));
2022-03-03 01:32:03 +08:00
}
private void createPlayerTest()
2021-01-25 06:46:54 +08:00
{
CreateTest();
2022-03-03 01:32:03 +08:00
2021-12-22 17:12:01 +08:00
AddAssert("storyboard loaded", () => Player.Beatmap.Value.Storyboard != null);
waitUntilStoryboardSamplesPlay();
2021-01-25 06:46:54 +08:00
}
private void waitUntilStoryboardSamplesPlay() => AddUntilStep("any storyboard samples playing", () => allStoryboardSamples.Any(sound => sound.IsPlaying));
2022-03-03 05:02:36 +08:00
private void allStoryboardSamplesStopped() => AddAssert("all storyboard samples stopped immediately", () => allStoryboardSamples.All(sound => !sound.IsPlaying));
private void skipIntro() => AddStep("skip intro", () => InputManager.Key(Key.Space));
2021-01-25 06:46:54 +08:00
private IEnumerable<DrawableStoryboardSample> allStoryboardSamples => Player.ChildrenOfType<DrawableStoryboardSample>();
protected override bool AllowFail => false;
2022-03-03 01:32:03 +08:00
protected override TestPlayer CreatePlayer(Ruleset ruleset)
{
SelectedMods.Value = SelectedMods.Value.Concat(storyboardMods).ToArray();
return new TestPlayer(true, false);
}
2021-01-25 06:46:54 +08:00
protected override Ruleset CreatePlayerRuleset() => new OsuRuleset();
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) =>
new ClockBackedTestWorkingBeatmap(beatmap, storyboard ?? this.storyboard, Clock, Audio);
}
}