1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 16:42:55 +08:00
osu-lazer/osu.Game.Tests/Gameplay/TestSceneStoryboardSamples.cs

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

214 lines
7.7 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.
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;
using osu.Framework.Graphics.Textures;
2020-01-02 14:23:41 +08:00
using osu.Framework.IO.Stores;
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]
public class TestSceneStoryboardSamples : OsuTestScene, IStorageResourceProvider
2020-01-02 14:23:41 +08:00
{
[Resolved]
private OsuConfigManager config { 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);
2020-08-17 14:38:16 +08:00
working.LoadTrack();
2020-08-06 17:31:08 +08:00
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
IsPaused = { Value = true },
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
}
2020-06-15 10:18:12 +08:00
});
});
2021-04-20 17:26:30 +08:00
AddStep("reset clock", () => gameplayContainer.Start());
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);
}
[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);
working.LoadTrack();
const double start_time = 1000;
Add(gameplayContainer = new MasterGameplayClockContainer(working, start_time)
2021-04-20 15:51:00 +08:00
{
StartTime = start_time,
2021-04-20 17:26:30 +08:00
IsPaused = { Value = true },
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
}
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.GameplayClock
});
});
AddStep("start", () => gameplayContainer.Start());
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
}
private class TestDrawableStoryboardSample : DrawableStoryboardSample
{
public TestDrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
: base(sampleInfo)
{
}
}
#region IResourceStorageProvider
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
}
}