fix: use both flippers on mobile (#318)

Co-authored-by: Tom Arra <tarra3@gmail.com>
pull/328/head
Jochum van der Ploeg 3 years ago committed by GitHub
parent ca9679ba1d
commit 82588602eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,7 +18,7 @@ class PinballGame extends PinballForge2DGame
FlameBloc, FlameBloc,
HasKeyboardHandlerComponents, HasKeyboardHandlerComponents,
Controls<_GameBallsController>, Controls<_GameBallsController>,
TapDetector { MultiTouchTapDetector {
PinballGame({ PinballGame({
required this.characterTheme, required this.characterTheme,
required this.audio, required this.audio,
@ -80,7 +80,7 @@ class PinballGame extends PinballForge2DGame
BoardSide? focusedBoardSide; BoardSide? focusedBoardSide;
@override @override
void onTapDown(TapDownInfo info) { void onTapDown(int pointerId, TapDownInfo info) {
if (info.raw.kind == PointerDeviceKind.touch) { if (info.raw.kind == PointerDeviceKind.touch) {
final rocket = descendants().whereType<RocketSpriteComponent>().first; final rocket = descendants().whereType<RocketSpriteComponent>().first;
final bounds = rocket.topLeftPosition & rocket.size; final bounds = rocket.topLeftPosition & rocket.size;
@ -98,19 +98,19 @@ class PinballGame extends PinballForge2DGame
} }
} }
super.onTapDown(info); super.onTapDown(pointerId, info);
} }
@override @override
void onTapUp(TapUpInfo info) { void onTapUp(int pointerId, TapUpInfo info) {
_moveFlippersDown(); _moveFlippersDown();
super.onTapUp(info); super.onTapUp(pointerId, info);
} }
@override @override
void onTapCancel() { void onTapCancel(int pointerId) {
_moveFlippersDown(); _moveFlippersDown();
super.onTapCancel(); super.onTapCancel(pointerId);
} }
void _moveFlippersDown() { void _moveFlippersDown() {
@ -181,8 +181,8 @@ class DebugPinballGame extends PinballGame with FPSCounter {
} }
@override @override
void onTapUp(TapUpInfo info) { void onTapUp(int pointerId, TapUpInfo info) {
super.onTapUp(info); super.onTapUp(pointerId, info);
if (info.raw.kind == PointerDeviceKind.mouse) { if (info.raw.kind == PointerDeviceKind.mouse) {
final ball = ControlledBall.debug() final ball = ControlledBall.debug()

@ -323,7 +323,7 @@ void main() {
(flipper) => flipper.side == BoardSide.left, (flipper) => flipper.side == BoardSide.left,
); );
game.onTapDown(tapDownEvent); game.onTapDown(0, tapDownEvent);
expect(flippers.first.body.linearVelocity.y, isNegative); expect(flippers.first.body.linearVelocity.y, isNegative);
}); });
@ -346,7 +346,7 @@ void main() {
(flipper) => flipper.side == BoardSide.right, (flipper) => flipper.side == BoardSide.right,
); );
game.onTapDown(tapDownEvent); game.onTapDown(0, tapDownEvent);
expect(flippers.first.body.linearVelocity.y, isNegative); expect(flippers.first.body.linearVelocity.y, isNegative);
}); });
@ -369,14 +369,14 @@ void main() {
(flipper) => flipper.side == BoardSide.left, (flipper) => flipper.side == BoardSide.left,
); );
game.onTapDown(tapDownEvent); game.onTapDown(0, tapDownEvent);
expect(flippers.first.body.linearVelocity.y, isNegative); expect(flippers.first.body.linearVelocity.y, isNegative);
final tapUpEvent = _MockTapUpInfo(); final tapUpEvent = _MockTapUpInfo();
when(() => tapUpEvent.eventPosition).thenReturn(eventPosition); when(() => tapUpEvent.eventPosition).thenReturn(eventPosition);
game.onTapUp(tapUpEvent); game.onTapUp(0, tapUpEvent);
await game.ready(); await game.ready();
expect(flippers.first.body.linearVelocity.y, isPositive); expect(flippers.first.body.linearVelocity.y, isPositive);
@ -400,11 +400,11 @@ void main() {
(flipper) => flipper.side == BoardSide.left, (flipper) => flipper.side == BoardSide.left,
); );
game.onTapDown(tapDownEvent); game.onTapDown(0, tapDownEvent);
expect(flippers.first.body.linearVelocity.y, isNegative); expect(flippers.first.body.linearVelocity.y, isNegative);
game.onTapCancel(); game.onTapCancel(0);
expect(flippers.first.body.linearVelocity.y, isPositive); expect(flippers.first.body.linearVelocity.y, isPositive);
}); });
@ -426,7 +426,7 @@ void main() {
final plunger = game.descendants().whereType<Plunger>().first; final plunger = game.descendants().whereType<Plunger>().first;
game.onTapDown(tapDownEvent); game.onTapDown(0, tapDownEvent);
game.update(1); game.update(1);
@ -452,7 +452,7 @@ void main() {
final previousBalls = final previousBalls =
game.descendants().whereType<ControlledBall>().toList(); game.descendants().whereType<ControlledBall>().toList();
game.onTapUp(tapUpEvent); game.onTapUp(0, tapUpEvent);
await game.ready(); await game.ready();
expect( expect(

Loading…
Cancel
Save