1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 09:32:53 +08:00
osu-lazer/osu.Game.Tests/Gameplay/TestSceneStoryboardSamples.cs

222 lines
7.9 KiB
C#
Raw Normal View History

2020-01-02 14:23:41 +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
2020-01-02 14:23:41 +08:00
using System.Collections.Generic;
using System.IO;
using System.Threading;
2020-01-02 14:23:41 +08:00
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
2020-01-02 14:23:41 +08:00
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
2022-08-02 18:50:57 +08:00
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Textures;
2020-01-02 14:23:41 +08:00
using osu.Framework.IO.Stores;
2022-08-02 18:50:57 +08:00
using osu.Framework.Platform;
using osu.Framework.Testing;
2020-01-02 14:23:41 +08:00
using osu.Game.Audio;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.IO;
using osu.Game.Rulesets;
2020-06-15 10:18:12 +08:00
using osu.Game.Rulesets.Osu;
2021-04-20 17:26:30 +08:00
using osu.Game.Rulesets.UI;
2020-06-15 10:18:12 +08:00
using osu.Game.Screens.Play;
2020-01-02 14:23:41 +08:00
using osu.Game.Skinning;
2020-06-15 10:18:12 +08:00
using osu.Game.Storyboards;
using osu.Game.Storyboards.Drawables;
2020-01-02 14:23:41 +08:00
using osu.Game.Tests.Resources;
using osu.Game.Tests.Visual;
namespace osu.Game.Tests.Gameplay
{
[HeadlessTest]
2022-11-24 13:32:20 +08:00
public partial class TestSceneStoryboardSamples : OsuTestScene, IStorageResourceProvider
2020-01-02 14:23:41 +08:00
{
[Resolved]
private OsuConfigManager config { get; set; }
2022-08-02 18:50:57 +08:00
[Resolved]
private GameHost host { get; set; }
2020-01-02 14:23:41 +08:00
[Test]
public void TestRetrieveTopLevelSample()
{
ISkin skin = null;
ISample channel = null;
2020-01-02 14:23:41 +08:00
AddStep("create skin", () => skin = new TestSkin("test-sample", this));
2020-01-02 14:23:41 +08:00
AddStep("retrieve sample", () => channel = skin.GetSample(new SampleInfo("test-sample")));
AddAssert("sample is non-null", () => channel != null);
}
[Test]
public void TestRetrieveSampleInSubFolder()
{
ISkin skin = null;
ISample channel = null;
2020-01-02 14:23:41 +08:00
AddStep("create skin", () => skin = new TestSkin("folder/test-sample", this));
2020-01-02 14:23:41 +08:00
AddStep("retrieve sample", () => channel = skin.GetSample(new SampleInfo("folder/test-sample")));
AddAssert("sample is non-null", () => channel != null);
}
2020-06-15 10:18:12 +08:00
[Test]
public void TestSamplePlaybackAtZero()
{
GameplayClockContainer gameplayContainer = null;
DrawableStoryboardSample sample = null;
AddStep("create container", () =>
{
2020-08-06 17:31:08 +08:00
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
2021-04-20 17:26:30 +08:00
Add(gameplayContainer = new MasterGameplayClockContainer(working, 0)
2020-06-15 10:18:12 +08:00
{
2021-04-20 17:26:30 +08:00
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
}
2020-06-15 10:18:12 +08:00
});
});
AddStep("reset clock", () => gameplayContainer.Reset(startClock: true));
2020-06-15 10:18:12 +08:00
2021-04-20 15:51:00 +08:00
AddUntilStep("sample played", () => sample.RequestedPlaying);
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
}
/// <summary>
/// Sample at 0ms, start time at 1000ms (so the sample should not be played).
/// </summary>
2021-04-20 15:51:00 +08:00
[Test]
public void TestSampleHasLifetimeEndWithInitialClockTime()
{
MasterGameplayClockContainer gameplayContainer = null;
2021-04-20 15:51:00 +08:00
DrawableStoryboardSample sample = null;
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
const double start_time = 1000;
Add(gameplayContainer = new MasterGameplayClockContainer(working, start_time)
2021-04-20 15:51:00 +08:00
{
2021-04-20 17:26:30 +08:00
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
}
2021-04-20 15:51:00 +08:00
});
gameplayContainer.Reset(start_time);
2021-04-20 15:51:00 +08:00
});
AddStep("start time", () => gameplayContainer.Start());
AddUntilStep("sample not played", () => !sample.RequestedPlaying);
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
2020-06-15 10:18:12 +08:00
}
[Test]
public void TestSamplePlaybackWithBeatmapHitsoundsOff()
{
GameplayClockContainer gameplayContainer = null;
TestDrawableStoryboardSample sample = null;
AddStep("disable beatmap hitsounds", () => config.SetValue(OsuSetting.BeatmapHitsounds, false));
AddStep("setup storyboard sample", () =>
{
Beatmap.Value = new TestCustomSkinWorkingBeatmap(new OsuRuleset().RulesetInfo, this);
var beatmapSkinSourceContainer = new BeatmapSkinProvidingContainer(Beatmap.Value.Skin);
Add(gameplayContainer = new MasterGameplayClockContainer(Beatmap.Value, 0)
{
Child = beatmapSkinSourceContainer
});
beatmapSkinSourceContainer.Add(sample = new TestDrawableStoryboardSample(new StoryboardSampleInfo("test-sample", 1, 1))
{
Clock = gameplayContainer
});
});
AddStep("reset clock", () => gameplayContainer.Reset(startClock: true));
AddUntilStep("sample played", () => sample.IsPlayed);
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
AddStep("restore default", () => config.GetBindable<bool>(OsuSetting.BeatmapHitsounds).SetDefault());
}
2020-01-02 14:23:41 +08:00
private class TestSkin : LegacySkin
{
public TestSkin(string resourceName, IStorageResourceProvider resources)
: base(DefaultLegacySkin.CreateInfo(), resources, new TestResourceStore(resourceName))
2020-01-02 14:23:41 +08:00
{
}
}
private class TestResourceStore : IResourceStore<byte[]>
{
private readonly string resourceName;
public TestResourceStore(string resourceName)
{
this.resourceName = resourceName;
}
public byte[] Get(string name) => name == resourceName ? TestResources.GetStore().Get("Resources/Samples/test-sample.mp3") : null;
2020-01-02 14:23:41 +08:00
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
=> name == resourceName ? TestResources.GetStore().GetAsync("Resources/Samples/test-sample.mp3", cancellationToken) : null;
2020-01-02 14:23:41 +08:00
public Stream GetStream(string name) => name == resourceName ? TestResources.GetStore().GetStream("Resources/Samples/test-sample.mp3") : null;
2020-01-02 14:23:41 +08:00
public IEnumerable<string> GetAvailableResources() => new[] { resourceName };
public void Dispose()
{
}
}
2020-06-19 04:46:32 +08:00
private class TestCustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
{
private readonly IStorageResourceProvider resources;
2020-06-19 04:46:32 +08:00
public TestCustomSkinWorkingBeatmap(RulesetInfo ruleset, IStorageResourceProvider resources)
: base(ruleset, null, resources.AudioManager)
2020-06-19 04:46:32 +08:00
{
this.resources = resources;
2020-06-19 04:46:32 +08:00
}
protected internal override ISkin GetSkin() => new TestSkin("test-sample", resources);
2020-06-19 04:46:32 +08:00
}
2022-11-24 13:32:20 +08:00
private partial class TestDrawableStoryboardSample : DrawableStoryboardSample
2020-06-19 04:46:32 +08:00
{
public TestDrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
: base(sampleInfo)
{
}
}
#region IResourceStorageProvider
2022-08-02 18:50:57 +08:00
public IRenderer Renderer => host.Renderer;
public AudioManager AudioManager => Audio;
public IResourceStore<byte[]> Files => null;
public new IResourceStore<byte[]> Resources => base.Resources;
public RealmAccess RealmAccess => null;
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
#endregion
2020-01-02 14:23:41 +08:00
}
}