1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 15:27:26 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneKeyCounter.cs
tsrk 1beec71037
refactor(KeyCounterDisplay): apply suggestions
I also took the freedom to add type checking, as we can't limit the
usage of `Add()` since it's a Container. The exception thrown also
advises of using the suggested `AddTrigger()` instead.
2023-02-22 14:58:27 +00:00

60 lines
2.1 KiB
C#

// 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.
#nullable disable
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Screens.Play;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Gameplay
{
[TestFixture]
public partial class TestSceneKeyCounter : OsuManualInputManagerTestScene
{
public TestSceneKeyCounter()
{
DefaultKeyCounter testCounter;
KeyCounterDisplay kc = new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new[]
{
testCounter = new DefaultKeyCounter(new KeyCounterKeyboardTrigger(Key.X)),
new DefaultKeyCounter(new KeyCounterKeyboardTrigger(Key.X)),
new DefaultKeyCounter(new KeyCounterMouseTrigger(MouseButton.Left)),
new DefaultKeyCounter(new KeyCounterMouseTrigger(MouseButton.Right)),
},
};
AddStep("Add random", () =>
{
Key key = (Key)((int)Key.A + RNG.Next(26));
kc.AddTrigger(new KeyCounterKeyboardTrigger(key));
});
Key testKey = ((KeyCounterKeyboardTrigger)kc.Children.First().Trigger).Key;
void addPressKeyStep()
{
AddStep($"Press {testKey} key", () => InputManager.Key(testKey));
}
addPressKeyStep();
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 1);
addPressKeyStep();
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses.Value == 2);
AddStep("Disable counting", () => testCounter.IsCounting.Value = false);
addPressKeyStep();
AddAssert($"Check {testKey} count has not changed", () => testCounter.CountPresses.Value == 2);
Add(kc);
}
}
}