1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 20:47:51 +08:00

Prepare classes for player loader test scene

This commit is contained in:
Craftplacer 2019-09-18 23:27:26 +02:00
parent 220fdd0a04
commit c3221e1a36
2 changed files with 96 additions and 10 deletions

View File

@ -3,14 +3,20 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.MathUtils;
using osu.Framework.Screens;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
@ -24,19 +30,35 @@ namespace osu.Game.Tests.Visual.Gameplay
public class TestScenePlayerLoader : ManualInputManagerTestScene
{
private TestPlayerLoader loader;
private OsuScreenStack stack;
private TestPlayerLoaderContainer container;
private TestPlayer player;
[Resolved]
private AudioManager audioManager { get; set; }
[SetUp]
public void Setup() => Schedule(() =>
{
InputManager.Child = stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both };
ResetPlayer(false);
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
});
/// <summary>
/// Sets the input manager child to a new test player loader container instance.
/// </summary>
/// <param name="interactive">If the test player should behave like the production one.</param>
public void ResetPlayer(bool interactive)
{
player = new TestPlayer(interactive, interactive);
loader = new TestPlayerLoader(() => player);
container = new TestPlayerLoaderContainer(loader);
InputManager.Child = container;
}
[Test]
public void TestBlockLoadViaMouseMovement()
{
AddStep("load dummy beatmap", () => stack.Push(loader = new TestPlayerLoader(() => new TestPlayer(false, false))));
AddStep("load dummy beatmap", () => ResetPlayer(false));
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
AddRepeatStep("move mouse", () => InputManager.MoveMouseTo(loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft + (loader.VisualSettings.ScreenSpaceDrawQuad.BottomRight - loader.VisualSettings.ScreenSpaceDrawQuad.TopLeft) * RNG.NextSingle()), 20);
AddAssert("loader still active", () => loader.IsCurrentScreen());
@ -49,13 +71,13 @@ namespace osu.Game.Tests.Visual.Gameplay
Player player = null;
SlowLoadPlayer slowPlayer = null;
AddStep("load dummy beatmap", () => stack.Push(loader = new TestPlayerLoader(() => player = new TestPlayer(false, false))));
AddStep("load dummy beatmap", () => ResetPlayer(false));
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
AddStep("load slow dummy beatmap", () =>
{
stack.Push(loader = new TestPlayerLoader(() => slowPlayer = new SlowLoadPlayer(false, false)));
InputManager.Children = container = new TestPlayerLoaderContainer(loader = new TestPlayerLoader(() => slowPlayer = new SlowLoadPlayer(false, false)));
Scheduler.AddDelayed(() => slowPlayer.AllowLoad.Set(), 5000);
});
@ -65,7 +87,6 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestModReinstantiation()
{
TestPlayer player = null;
TestMod gameMod = null;
TestMod playerMod1 = null;
TestMod playerMod2 = null;
@ -73,7 +94,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("load player", () =>
{
Mods.Value = new[] { gameMod = new TestMod() };
stack.Push(loader = new TestPlayerLoader(() => player = new TestPlayer()));
ResetPlayer(true);
});
AddUntilStep("wait for loader to become current", () => loader.IsCurrentScreen());
@ -97,6 +118,61 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("player mods applied", () => playerMod2.Applied);
}
[Test]
public void TestMutedNotification()
{
AddStep("set master volume to 0%", () => audioManager.Volume.Value = 0);
AddStep("reset notification lock", () => PlayerLoader.ResetNotificationLock());
//AddStep("reset notification overlay", () => notificationOverlay);
AddStep("load player", () => ResetPlayer(false));
AddUntilStep("wait for player", () => player.IsLoaded);
AddAssert("check for notification", () => container.NotificationOverlay.UnreadCount.Value == 1);
AddAssert("click notification", () =>
{
var scrollContainer = container.NotificationOverlay.Children.Last() as OsuScrollContainer;
var flowContainer = scrollContainer.Children.First() as FillFlowContainer<NotificationSection>;
return flowContainer.Children.First().First().Click();
});
AddAssert("check master volume", () => audioManager.Volume.IsDefault);
AddStep("restart player", () =>
{
var lastPlayer = player;
player = null;
lastPlayer.Restart();
});
}
private class TestPlayerLoaderContainer : Container
{
private TestPlayerLoader loader;
[Cached]
public NotificationOverlay NotificationOverlay { get; } = new NotificationOverlay
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
};
[Cached]
public VolumeOverlay VolumeOverlay { get; } = new VolumeOverlay
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
};
public TestPlayerLoaderContainer(TestPlayerLoader testPlayerLoader)
{
Children = new Drawable[]
{
loader = testPlayerLoader,
NotificationOverlay,
VolumeOverlay
};
}
}
private class TestPlayerLoader : PlayerLoader
{
public new VisualSettings VisualSettings => base.VisualSettings;

View File

@ -65,6 +65,9 @@ namespace osu.Game.Screens.Play
[Resolved]
private VolumeOverlay volumeOverlay { get; set; }
[Resolved]
private AudioManager audioManager { get; set; }
private static bool muteWarningShownOnce;
public PlayerLoader(Func<Player> createPlayer)
@ -79,7 +82,7 @@ namespace osu.Game.Screens.Play
}
[BackgroundDependencyLoader]
private void load(AudioManager audioManager, NotificationOverlay notificationOverlay)
private void load()
{
InternalChild = (content = new LogoTrackingContainer
{
@ -112,8 +115,6 @@ namespace osu.Game.Screens.Play
});
loadNewPlayer();
checkVolume(audioManager);
}
private void playerLoaded(Player player) => info.Loading = false;
@ -212,6 +213,7 @@ namespace osu.Game.Screens.Play
{
inputManager = GetContainingInputManager();
base.LoadComplete();
checkVolume(audioManager);
}
private ScheduledDelegate pushDebounce;
@ -526,5 +528,13 @@ namespace osu.Game.Screens.Play
};
}
}
/// <summary>
/// Sets <see cref="muteWarningShownOnce"/> to <see cref="false"/>, reserved for testing.
/// </summary>
public static void ResetNotificationLock()
{
muteWarningShownOnce = false;
}
}
}