refactor: input letter looping and reverse direction (#335)

* refactor: letter looping and reverse direction

* doc: update test comments to match changes
pull/320/head
Allison Ryan 3 years ago committed by GitHub
parent e9b902355d
commit 391f9cac8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -59,7 +59,7 @@ class InitialsInputDisplay extends Component with HasGameRef {
await add(
InitialsLetterPrompt(
position: Vector2(
11.4 + (2.3 * i),
10.8 + (2.5 * i),
-20,
),
hasFocus: i == 0,
@ -138,7 +138,7 @@ class _NameLabelTextComponent extends TextComponent
_NameLabelTextComponent()
: super(
anchor: Anchor.center,
position: Vector2(11.4, -24),
position: Vector2(10.8, -24),
textRenderer: _bodyTextPaint.copyWith(
(style) => style.copyWith(
color: PinballColors.red,
@ -158,7 +158,7 @@ class _CharacterIconSpriteComponent extends SpriteComponent with HasGameRef {
: _characterIconPath = characterIconPath,
super(
anchor: Anchor.center,
position: Vector2(8.4, -20),
position: Vector2(7.6, -20),
);
final String _characterIconPath;
@ -241,8 +241,9 @@ class InitialsLetterPrompt extends PositionComponent {
bool _cycle(bool up) {
if (_hasFocus) {
final newCharCode =
min(max(_charIndex + (up ? 1 : -1), 0), _alphabetLength);
var newCharCode = _charIndex + (up ? -1 : 1);
if (newCharCode < 0) newCharCode = _alphabetLength;
if (newCharCode > _alphabetLength) newCharCode = 0;
_input.text = String.fromCharCode(_alphabetCode + newCharCode);
_charIndex = newCharCode;

@ -76,26 +76,26 @@ void main() {
);
await game.ensureAdd(initialsInputDisplay);
// Focus is already on the first letter
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
// Focus is on the first letter
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
// Move to the next an press up again
// Move to the next an press down again
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
// One more time
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
// Back to the previous and increase one more
// Back to the previous and press down again
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
},
verify: (game, tester) async {
@ -136,14 +136,14 @@ void main() {
await game.ensureAdd(
InitialsLetterPrompt(hasFocus: true, position: Vector2.zero()),
);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.pump();
},
verify: (game, tester) async {
final prompt = game.firstChild<InitialsLetterPrompt>();

Loading…
Cancel
Save