2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-19 13:07:55 +08:00
|
|
|
|
using System;
|
2019-04-08 17:32:05 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-06-26 17:24:34 +08:00
|
|
|
|
using System.Linq;
|
2018-05-23 16:37:39 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-05-23 17:52:09 +08:00
|
|
|
|
using osu.Framework.Audio;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-07-19 13:07:55 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Testing;
|
2018-05-23 16:37:39 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-06-26 17:24:34 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2019-04-08 17:32:05 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
2019-05-15 03:37:25 +08:00
|
|
|
|
public abstract class OsuTestScene : TestScene
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-04-08 17:32:05 +08:00
|
|
|
|
[Cached(typeof(Bindable<WorkingBeatmap>))]
|
|
|
|
|
[Cached(typeof(IBindable<WorkingBeatmap>))]
|
2018-05-28 16:55:41 +08:00
|
|
|
|
private readonly OsuTestBeatmap beatmap = new OsuTestBeatmap(new DummyWorkingBeatmap());
|
2019-04-08 17:32:05 +08:00
|
|
|
|
|
2018-06-06 19:16:20 +08:00
|
|
|
|
protected BindableBeatmap Beatmap => beatmap;
|
2018-05-23 16:37:39 +08:00
|
|
|
|
|
2019-04-08 17:32:05 +08:00
|
|
|
|
[Cached]
|
|
|
|
|
[Cached(typeof(IBindable<RulesetInfo>))]
|
2018-06-26 17:59:13 +08:00
|
|
|
|
protected readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
2018-06-26 17:24:34 +08:00
|
|
|
|
|
2019-04-08 17:32:05 +08:00
|
|
|
|
[Cached]
|
2019-04-10 16:13:12 +08:00
|
|
|
|
[Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))]
|
|
|
|
|
protected readonly Bindable<IReadOnlyList<Mod>> Mods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
2019-04-08 17:32:05 +08:00
|
|
|
|
|
2019-04-25 16:36:17 +08:00
|
|
|
|
protected new DependencyContainer Dependencies { get; private set; }
|
2018-05-23 16:37:39 +08:00
|
|
|
|
|
2018-07-19 13:07:55 +08:00
|
|
|
|
private readonly Lazy<Storage> localStorage;
|
|
|
|
|
protected Storage LocalStorage => localStorage.Value;
|
|
|
|
|
|
2018-07-11 16:07:14 +08:00
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2018-05-23 16:37:39 +08:00
|
|
|
|
{
|
2018-12-05 19:19:21 +08:00
|
|
|
|
// This is the earliest we can get OsuGameBase, which is used by the dummy working beatmap to find textures
|
2019-04-09 12:15:48 +08:00
|
|
|
|
beatmap.Default = new DummyWorkingBeatmap(parent.Get<OsuGameBase>());
|
2018-06-26 17:24:34 +08:00
|
|
|
|
|
2019-04-09 12:15:48 +08:00
|
|
|
|
return Dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2018-05-23 17:52:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
|
protected OsuTestScene()
|
2018-07-19 13:07:55 +08:00
|
|
|
|
{
|
2019-03-27 19:58:07 +08:00
|
|
|
|
localStorage = new Lazy<Storage>(() => new NativeStorage($"{GetType().Name}-{Guid.NewGuid()}"));
|
2018-07-19 13:07:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-28 16:55:41 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2018-06-26 17:24:34 +08:00
|
|
|
|
private void load(AudioManager audioManager, RulesetStore rulesets)
|
2018-05-28 16:55:41 +08:00
|
|
|
|
{
|
|
|
|
|
beatmap.SetAudioManager(audioManager);
|
2018-06-26 17:24:34 +08:00
|
|
|
|
|
2018-08-25 20:40:40 +08:00
|
|
|
|
Ruleset.Value = rulesets.AvailableRulesets.FirstOrDefault();
|
2018-05-28 16:55:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 11:53:32 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2018-05-23 17:52:09 +08:00
|
|
|
|
{
|
2018-05-24 11:53:32 +08:00
|
|
|
|
base.Dispose(isDisposing);
|
2018-05-23 17:52:09 +08:00
|
|
|
|
|
2019-02-13 14:14:34 +08:00
|
|
|
|
beatmap?.Value.Track.Stop();
|
2018-07-19 13:07:55 +08:00
|
|
|
|
|
|
|
|
|
if (localStorage.IsValueCreated)
|
2018-07-23 16:39:43 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
localStorage.Value.DeleteDirectory(".");
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// we don't really care if this fails; it will just leave folders lying around from test runs.
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-23 16:37:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
|
protected override ITestSceneTestRunner CreateRunner() => new OsuTestSceneTestRunner();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
|
public class OsuTestSceneTestRunner : OsuGameBase, ITestSceneTestRunner
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-05-14 17:39:56 +08:00
|
|
|
|
private TestSceneTestRunner.TestRunner runner;
|
2018-04-18 14:12:48 +08:00
|
|
|
|
|
2018-04-22 03:10:06 +08:00
|
|
|
|
protected override void LoadAsyncComplete()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-04-22 03:10:06 +08:00
|
|
|
|
// this has to be run here rather than LoadComplete because
|
2019-05-15 17:32:29 +08:00
|
|
|
|
// TestScene.cs is checking the IsLoaded state (on another thread) and expects
|
2018-04-22 03:10:06 +08:00
|
|
|
|
// the runner to be loaded at that point.
|
2019-05-14 17:39:56 +08:00
|
|
|
|
Add(runner = new TestSceneTestRunner.TestRunner());
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-04-18 14:12:48 +08:00
|
|
|
|
|
2019-05-14 17:39:56 +08:00
|
|
|
|
public void RunTestBlocking(TestScene test) => runner.RunTestBlocking(test);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-05-28 16:55:41 +08:00
|
|
|
|
|
2018-06-06 19:16:20 +08:00
|
|
|
|
private class OsuTestBeatmap : BindableBeatmap
|
2018-05-28 16:55:41 +08:00
|
|
|
|
{
|
|
|
|
|
public OsuTestBeatmap(WorkingBeatmap defaultValue)
|
|
|
|
|
: base(defaultValue)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetAudioManager(AudioManager audioManager) => RegisterAudioManager(audioManager);
|
|
|
|
|
|
2018-06-06 19:16:20 +08:00
|
|
|
|
public override BindableBeatmap GetBoundCopy()
|
2018-05-28 16:55:41 +08:00
|
|
|
|
{
|
|
|
|
|
var copy = new OsuTestBeatmap(Default);
|
|
|
|
|
copy.BindTo(this);
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|