mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 15:33:05 +08:00
Test KeyCounter.RestoreState
This commit is contained in:
parent
8bb83a8fd9
commit
3134e14b37
@ -3,7 +3,9 @@
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.EventArgs;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Screens.Play;
|
||||
using OpenTK.Input;
|
||||
|
||||
@ -12,15 +14,18 @@ namespace osu.Game.Tests.Visual
|
||||
[TestFixture]
|
||||
public class TestCaseKeyCounter : OsuTestCase
|
||||
{
|
||||
private const Key rewind_test_key = Key.Z;
|
||||
|
||||
public TestCaseKeyCounter()
|
||||
{
|
||||
KeyCounterKeyboard rewindTestKeyCounterKeyboard;
|
||||
KeyCounterCollection kc = new KeyCounterCollection
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
Children = new KeyCounter[]
|
||||
{
|
||||
new KeyCounterKeyboard(Key.Z),
|
||||
rewindTestKeyCounterKeyboard = new KeyCounterKeyboard(rewind_test_key),
|
||||
new KeyCounterKeyboard(Key.X),
|
||||
new KeyCounterMouse(MouseButton.Left),
|
||||
new KeyCounterMouse(MouseButton.Right),
|
||||
@ -34,6 +39,28 @@ namespace osu.Game.Tests.Visual
|
||||
});
|
||||
AddSliderStep("Fade time", 0, 200, 50, v => kc.FadeTime = v);
|
||||
|
||||
var expectedCountPresses = rewindTestKeyCounterKeyboard.CountPresses + 1;
|
||||
AddStep($"Press {rewind_test_key} key", () =>
|
||||
{
|
||||
rewindTestKeyCounterKeyboard.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = rewind_test_key, Repeat = false });
|
||||
rewindTestKeyCounterKeyboard.TriggerOnKeyUp(null, new KeyUpEventArgs { Key = rewind_test_key });
|
||||
});
|
||||
|
||||
AddAssert($"Check {rewind_test_key} counter after keypress", () => rewindTestKeyCounterKeyboard.CountPresses == expectedCountPresses);
|
||||
|
||||
IFrameBasedClock counterClock = null;
|
||||
AddStep($"Rewind {rewind_test_key} counter", () =>
|
||||
{
|
||||
counterClock = rewindTestKeyCounterKeyboard.Clock;
|
||||
rewindTestKeyCounterKeyboard.Clock = new DecoupleableInterpolatingFramedClock();
|
||||
});
|
||||
|
||||
AddAssert($"Check {rewind_test_key} counter after rewind", () =>
|
||||
{
|
||||
rewindTestKeyCounterKeyboard.Clock = counterClock;
|
||||
return rewindTestKeyCounterKeyboard.CountPresses == 0;
|
||||
});
|
||||
|
||||
Add(kc);
|
||||
}
|
||||
}
|
||||
|
@ -152,11 +152,6 @@ namespace osu.Game.Screens.Play
|
||||
RestoreState(Clock.CurrentTime);
|
||||
}
|
||||
|
||||
public void RestoreState(double time)
|
||||
{
|
||||
var targetState = states.LastOrDefault(state => state.Time <= time) ?? states.LastOrDefault();
|
||||
var targetCount = targetState?.Count ?? 0;
|
||||
CountPresses = targetCount;
|
||||
}
|
||||
public void RestoreState(double time) => CountPresses = states.LastOrDefault(state => state.Time <= time)?.Count ?? 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user