mirror of
https://github.com/ppy/osu.git
synced 2024-12-28 21:52:54 +08:00
104 lines
3.4 KiB
C#
104 lines
3.4 KiB
C#
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NUnit.Framework;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.MathUtils;
|
|
using osu.Framework.Timing;
|
|
using osu.Game.Screens.Play;
|
|
using OpenTK.Input;
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
{
|
|
[TestFixture]
|
|
public class TestCaseKeyCounter : ManualInputManagerTestCase
|
|
{
|
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
{
|
|
typeof(KeyCounterKeyboard),
|
|
typeof(KeyCounterMouse),
|
|
typeof(KeyCounterCollection)
|
|
};
|
|
|
|
public TestCaseKeyCounter()
|
|
{
|
|
KeyCounterKeyboard rewindTestKeyCounterKeyboard;
|
|
KeyCounterCollection kc = new KeyCounterCollection
|
|
{
|
|
Origin = Anchor.Centre,
|
|
Anchor = Anchor.Centre,
|
|
Children = new KeyCounter[]
|
|
{
|
|
rewindTestKeyCounterKeyboard = new KeyCounterKeyboard(Key.X),
|
|
new KeyCounterKeyboard(Key.X),
|
|
new KeyCounterMouse(MouseButton.Left),
|
|
new KeyCounterMouse(MouseButton.Right),
|
|
},
|
|
};
|
|
|
|
|
|
AddStep("Add random", () =>
|
|
{
|
|
Key key = (Key)((int)Key.A + RNG.Next(26));
|
|
kc.Add(new KeyCounterKeyboard(key));
|
|
});
|
|
AddSliderStep("Fade time", 0, 200, 50, v => kc.FadeTime = v);
|
|
|
|
Key testKey = ((KeyCounterKeyboard)kc.Children.First()).Key;
|
|
double time1 = 0;
|
|
|
|
AddStep($"Press {testKey} key", () =>
|
|
{
|
|
InputManager.PressKey(testKey);
|
|
InputManager.ReleaseKey(testKey);
|
|
});
|
|
|
|
AddAssert($"Check {testKey} counter after keypress", () => rewindTestKeyCounterKeyboard.CountPresses == 1);
|
|
|
|
AddStep($"Press {testKey} key", () =>
|
|
{
|
|
InputManager.PressKey(testKey);
|
|
InputManager.ReleaseKey(testKey);
|
|
time1 = Clock.CurrentTime;
|
|
});
|
|
|
|
AddAssert($"Check {testKey} counter after keypress", () => rewindTestKeyCounterKeyboard.CountPresses == 2);
|
|
|
|
IFrameBasedClock oldClock = null;
|
|
|
|
AddStep($"Rewind {testKey} counter once", () =>
|
|
{
|
|
oldClock = rewindTestKeyCounterKeyboard.Clock;
|
|
rewindTestKeyCounterKeyboard.Clock = new FramedOffsetClock(new FixedClock(time1 - 10));
|
|
});
|
|
|
|
AddAssert($"Check {testKey} counter after rewind", () => rewindTestKeyCounterKeyboard.CountPresses == 1);
|
|
|
|
AddStep($"Rewind {testKey} counter to zero", () => rewindTestKeyCounterKeyboard.Clock = new FramedOffsetClock(new FixedClock(0)));
|
|
|
|
AddAssert($"Check {testKey} counter after rewind", () => rewindTestKeyCounterKeyboard.CountPresses == 0);
|
|
|
|
AddStep("Restore clock", () => rewindTestKeyCounterKeyboard.Clock = oldClock);
|
|
|
|
Add(kc);
|
|
}
|
|
|
|
private class FixedClock : IClock
|
|
{
|
|
private readonly double time;
|
|
|
|
public FixedClock(double time)
|
|
{
|
|
this.time = time;
|
|
}
|
|
|
|
public double CurrentTime => time;
|
|
public double Rate => 1;
|
|
public bool IsRunning => false;
|
|
}
|
|
}
|
|
}
|