refactor classes in game.dart to separate files

This commit is contained in:
Erlend Fagerheim
2020-04-20 21:02:50 +02:00
parent 2d9c525fdb
commit 2bc4b7ad9d
17 changed files with 385 additions and 381 deletions

View File

@ -1,5 +1,6 @@
import 'package:flutter/widgets.dart';
import '../gestures.dart';
import 'embedded_game_widget.dart';
import 'game.dart';
class WidgetBuilder {
@ -9,70 +10,53 @@ class WidgetBuilder {
return GestureDetector(
// Taps
onTap: game is TapDetector ? () => (game as TapDetector).onTap() : null,
onTapCancel: game is TapDetector
? () => (game as TapDetector).onTapCancel()
: null,
onTapDown: game is TapDetector
? (TapDownDetails d) => (game as TapDetector).onTapDown(d)
: null,
onTapUp: game is TapDetector
? (TapUpDetails d) => (game as TapDetector).onTapUp(d)
: null,
onTapCancel: game is TapDetector ? () => (game as TapDetector).onTapCancel() : null,
onTapDown:
game is TapDetector ? (TapDownDetails d) => (game as TapDetector).onTapDown(d) : null,
onTapUp: game is TapDetector ? (TapUpDetails d) => (game as TapDetector).onTapUp(d) : null,
// Secondary taps
onSecondaryTapDown: game is SecondaryTapDetector
? (TapDownDetails d) =>
(game as SecondaryTapDetector).onSecondaryTapDown(d)
? (TapDownDetails d) => (game as SecondaryTapDetector).onSecondaryTapDown(d)
: null,
onSecondaryTapUp: game is SecondaryTapDetector
? (TapUpDetails d) =>
(game as SecondaryTapDetector).onSecondaryTapUp(d)
? (TapUpDetails d) => (game as SecondaryTapDetector).onSecondaryTapUp(d)
: null,
onSecondaryTapCancel: game is SecondaryTapDetector
? () => (game as SecondaryTapDetector).onSecondaryTapCancel()
: null,
// Double tap
onDoubleTap: game is DoubleTapDetector
? () => (game as DoubleTapDetector).onDoubleTap()
: null,
onDoubleTap:
game is DoubleTapDetector ? () => (game as DoubleTapDetector).onDoubleTap() : null,
// Long presses
onLongPress: game is LongPressDetector
? () => (game as LongPressDetector).onLongPress()
: null,
onLongPress:
game is LongPressDetector ? () => (game as LongPressDetector).onLongPress() : null,
onLongPressStart: game is LongPressDetector
? (LongPressStartDetails d) =>
(game as LongPressDetector).onLongPressStart(d)
? (LongPressStartDetails d) => (game as LongPressDetector).onLongPressStart(d)
: null,
onLongPressMoveUpdate: game is LongPressDetector
? (LongPressMoveUpdateDetails d) =>
(game as LongPressDetector).onLongPressMoveUpdate(d)
: null,
onLongPressUp: game is LongPressDetector
? () => (game as LongPressDetector).onLongPressUp()
? (LongPressMoveUpdateDetails d) => (game as LongPressDetector).onLongPressMoveUpdate(d)
: null,
onLongPressUp:
game is LongPressDetector ? () => (game as LongPressDetector).onLongPressUp() : null,
onLongPressEnd: game is LongPressDetector
? (LongPressEndDetails d) =>
(game as LongPressDetector).onLongPressEnd(d)
? (LongPressEndDetails d) => (game as LongPressDetector).onLongPressEnd(d)
: null,
// Vertical drag
onVerticalDragDown: game is VerticalDragDetector
? (DragDownDetails d) =>
(game as VerticalDragDetector).onVerticalDragDown(d)
? (DragDownDetails d) => (game as VerticalDragDetector).onVerticalDragDown(d)
: null,
onVerticalDragStart: game is VerticalDragDetector
? (DragStartDetails d) =>
(game as VerticalDragDetector).onVerticalDragStart(d)
? (DragStartDetails d) => (game as VerticalDragDetector).onVerticalDragStart(d)
: null,
onVerticalDragUpdate: game is VerticalDragDetector
? (DragUpdateDetails d) =>
(game as VerticalDragDetector).onVerticalDragUpdate(d)
? (DragUpdateDetails d) => (game as VerticalDragDetector).onVerticalDragUpdate(d)
: null,
onVerticalDragEnd: game is VerticalDragDetector
? (DragEndDetails d) =>
(game as VerticalDragDetector).onVerticalDragEnd(d)
? (DragEndDetails d) => (game as VerticalDragDetector).onVerticalDragEnd(d)
: null,
onVerticalDragCancel: game is VerticalDragDetector
? () => (game as VerticalDragDetector).onVerticalDragCancel()
@ -80,20 +64,16 @@ class WidgetBuilder {
// Horizontal drag
onHorizontalDragDown: game is HorizontalDragDetector
? (DragDownDetails d) =>
(game as HorizontalDragDetector).onHorizontalDragDown(d)
? (DragDownDetails d) => (game as HorizontalDragDetector).onHorizontalDragDown(d)
: null,
onHorizontalDragStart: game is HorizontalDragDetector
? (DragStartDetails d) =>
(game as HorizontalDragDetector).onHorizontalDragStart(d)
? (DragStartDetails d) => (game as HorizontalDragDetector).onHorizontalDragStart(d)
: null,
onHorizontalDragUpdate: game is HorizontalDragDetector
? (DragUpdateDetails d) =>
(game as HorizontalDragDetector).onHorizontalDragUpdate(d)
? (DragUpdateDetails d) => (game as HorizontalDragDetector).onHorizontalDragUpdate(d)
: null,
onHorizontalDragEnd: game is HorizontalDragDetector
? (DragEndDetails d) =>
(game as HorizontalDragDetector).onHorizontalDragEnd(d)
? (DragEndDetails d) => (game as HorizontalDragDetector).onHorizontalDragEnd(d)
: null,
onHorizontalDragCancel: game is HorizontalDragDetector
? () => (game as HorizontalDragDetector).onHorizontalDragCancel()
@ -101,38 +81,29 @@ class WidgetBuilder {
// Force presses
onForcePressStart: game is ForcePressDetector
? (ForcePressDetails d) =>
(game as ForcePressDetector).onForcePressStart(d)
? (ForcePressDetails d) => (game as ForcePressDetector).onForcePressStart(d)
: null,
onForcePressPeak: game is ForcePressDetector
? (ForcePressDetails d) =>
(game as ForcePressDetector).onForcePressPeak(d)
? (ForcePressDetails d) => (game as ForcePressDetector).onForcePressPeak(d)
: null,
onForcePressUpdate: game is ForcePressDetector
? (ForcePressDetails d) =>
(game as ForcePressDetector).onForcePressUpdate(d)
? (ForcePressDetails d) => (game as ForcePressDetector).onForcePressUpdate(d)
: null,
onForcePressEnd: game is ForcePressDetector
? (ForcePressDetails d) =>
(game as ForcePressDetector).onForcePressEnd(d)
? (ForcePressDetails d) => (game as ForcePressDetector).onForcePressEnd(d)
: null,
// Pan
onPanDown: game is PanDetector
? (DragDownDetails d) => (game as PanDetector).onPanDown(d)
: null,
onPanStart: game is PanDetector
? (DragStartDetails d) => (game as PanDetector).onPanStart(d)
: null,
onPanDown:
game is PanDetector ? (DragDownDetails d) => (game as PanDetector).onPanDown(d) : null,
onPanStart:
game is PanDetector ? (DragStartDetails d) => (game as PanDetector).onPanStart(d) : null,
onPanUpdate: game is PanDetector
? (DragUpdateDetails d) => (game as PanDetector).onPanUpdate(d)
: null,
onPanEnd: game is PanDetector
? (DragEndDetails d) => (game as PanDetector).onPanEnd(d)
: null,
onPanCancel: game is PanDetector
? () => (game as PanDetector).onPanCancel()
: null,
onPanEnd:
game is PanDetector ? (DragEndDetails d) => (game as PanDetector).onPanEnd(d) : null,
onPanCancel: game is PanDetector ? () => (game as PanDetector).onPanCancel() : null,
// Scales
onScaleStart: game is ScaleDetector
@ -147,9 +118,7 @@ class WidgetBuilder {
child: Container(
color: game.backgroundColor(),
child: Directionality(
textDirection: TextDirection.ltr,
child: EmbeddedGameWidget(game))),
child: Directionality(textDirection: TextDirection.ltr, child: EmbeddedGameWidget(game))),
);
}
}
@ -185,8 +154,7 @@ class _OverlayGameWidgetState extends State<OverlayGameWidget> {
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.ltr,
child:
Stack(children: [widget.gameChild, ..._overlays.values.toList()]));
child: Stack(children: [widget.gameChild, ..._overlays.values.toList()]));
}
}
@ -197,7 +165,6 @@ class OverlayWidgetBuilder extends WidgetBuilder {
Widget build(Game game) {
final container = super.build(game);
return OverlayGameWidget(
gameChild: container, game: game, key: UniqueKey());
return OverlayGameWidget(gameChild: container, game: game, key: UniqueKey());
}
}