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

@ -76,26 +76,26 @@ void main() {
); );
await game.ensureAdd(initialsInputDisplay); await game.ensureAdd(initialsInputDisplay);
// Focus is already on the first letter // Focus is on the first letter
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump(); 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.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pump(); await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump(); await tester.pump();
// One more time // One more time
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pump(); await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump(); 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.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await tester.pump(); await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump(); await tester.pump();
}, },
verify: (game, tester) async { verify: (game, tester) async {
@ -136,14 +136,14 @@ void main() {
await game.ensureAdd( await game.ensureAdd(
InitialsLetterPrompt(hasFocus: true, position: Vector2.zero()), InitialsLetterPrompt(hasFocus: true, position: Vector2.zero()),
); );
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.pump(); await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump(); await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump(); await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.pump();
}, },
verify: (game, tester) async { verify: (game, tester) async {
final prompt = game.firstChild<InitialsLetterPrompt>(); final prompt = game.firstChild<InitialsLetterPrompt>();

Loading…
Cancel
Save