1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-31 11:23:20 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneKeysPerSecondCounter.cs

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

78 lines
2.7 KiB
C#
Raw Normal View History

// 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-07-29 00:37:50 +08:00
#nullable disable
using NUnit.Framework;
using osu.Framework.Graphics;
2022-08-05 21:53:06 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.UI;
2022-07-29 00:37:50 +08:00
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD.KPSCounter;
2022-07-29 00:37:50 +08:00
using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Gameplay
{
2022-08-05 21:53:06 +08:00
public class TestSceneKeysPerSecondCounter : PlayerTestScene
{
2022-08-05 21:53:06 +08:00
protected override Ruleset CreatePlayerRuleset() => new ManiaRuleset();
protected override bool HasCustomSteps => false;
protected override bool Autoplay => false;
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(true, false);
2022-07-29 00:37:50 +08:00
2022-08-05 21:53:06 +08:00
private GameplayClock gameplayClock;
private DrawableRuleset drawableRuleset;
2022-07-29 00:37:50 +08:00
2022-08-05 21:53:06 +08:00
private KeysPerSecondCounter counter;
private void createCounter()
2022-07-29 00:37:50 +08:00
{
2022-08-05 21:53:06 +08:00
AddStep("Create counter", () =>
2022-07-29 00:37:50 +08:00
{
2022-08-05 21:53:06 +08:00
gameplayClock = Player.GameplayClockContainer.GameplayClock;
drawableRuleset = Player.DrawableRuleset;
2022-07-29 00:37:50 +08:00
2022-08-05 21:53:06 +08:00
Player.HUDOverlay.Add(counter = new KeysPerSecondCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(5),
});
counter.SmoothingTime.Value = 0;
});
AddUntilStep("Counter created", () => Player.HUDOverlay.Contains(counter));
2022-07-29 00:37:50 +08:00
}
[Test]
2022-08-05 21:53:06 +08:00
public void TestBasic()
2022-07-29 00:37:50 +08:00
{
2022-08-05 21:53:06 +08:00
createCounter();
AddStep("press 1 key", () => InputManager.Key(Key.D));
AddAssert("KPS = 1", () => counter.Current.Value == 1);
AddUntilStep("Wait for KPS cooldown", () => counter.Current.Value <= 0);
AddStep("press 4 keys", () =>
{
InputManager.Key(Key.D);
InputManager.Key(Key.F);
InputManager.Key(Key.J);
InputManager.Key(Key.K);
});
AddAssert("KPS = 4", () => counter.Current.Value == 4);
AddStep("Pause player", () => Player.Pause());
AddAssert("KPS = 4", () => counter.Current.Value == 4);
AddStep("Resume player", () => Player.Resume());
AddStep("press 4 keys", () =>
{
InputManager.Key(Key.D);
InputManager.Key(Key.F);
InputManager.Key(Key.J);
InputManager.Key(Key.K);
});
AddAssert("KPS = 8", () => counter.Current.Value == 8);
2022-07-29 00:37:50 +08:00
}
}
}