refactor: simplify mixin

pull/157/head
Allison Ryan 4 years ago
parent 0044e4ed81
commit 986d8f145b

@ -26,7 +26,7 @@ extension BodyTrace on BodyComponent {
}
mixin Traceable on Forge2DGame {
bool get trace;
late final bool trace;
Future<void> traceAllBodies({
Color color = const Color(0xFFFF0000),

@ -5,10 +5,8 @@ import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/common/common.dart';
import 'package:sandbox/stories/ball/basic_ball_game.dart';
class BigDashNestBumperGame extends BasicBallGame {
BigDashNestBumperGame({
required this.trace,
}) : super(color: const Color(0xFF0000FF));
class BigDashNestBumperGame extends BasicBallGame with Traceable {
BigDashNestBumperGame() : super(color: const Color(0xFF0000FF));
static const info = '''
Shows how a BigDashNestBumper is rendered.
@ -16,8 +14,6 @@ class BigDashNestBumperGame extends BasicBallGame {
Activate the "trace" parameter to overlay the body.
''';
final bool trace;
@override
Future<void> onLoad() async {
await super.onLoad();
@ -28,6 +24,6 @@ class BigDashNestBumperGame extends BasicBallGame {
..priority = 1;
await add(bigDashNestBumper);
if (trace) bigDashNestBumper.trace();
await traceAllBodies();
}
}

@ -8,9 +8,8 @@ void addDashNestBumperStories(Dashbook dashbook) {
dashbook.storiesOf('Dash Nest Bumpers').add(
'Big',
(context) => GameWidget(
game: BigDashNestBumperGame(
trace: context.boolProperty('Trace', true),
),
game: BigDashNestBumperGame()
..trace = context.boolProperty('Trace', true),
),
codeLink: buildSourceLink('dash_nest_bumper/big.dart'),
info: BasicBallGame.info,

@ -7,10 +7,7 @@ import 'package:sandbox/common/common.dart';
import 'package:sandbox/stories/ball/basic_ball_game.dart';
class FlipperGame extends BasicBallGame with KeyboardEvents, Traceable {
FlipperGame({
required bool trace,
}) : _trace = trace,
super(color: Colors.blue);
FlipperGame() : super(color: Colors.blue);
static const info = '''
Shows how Flippers are rendered.
@ -31,11 +28,6 @@ class FlipperGame extends BasicBallGame with KeyboardEvents, Traceable {
LogicalKeyboardKey.keyD,
];
final bool _trace;
@override
bool get trace => _trace;
late Flipper leftFlipper;
late Flipper rightFlipper;

@ -7,9 +7,7 @@ void addFlipperStories(Dashbook dashbook) {
dashbook.storiesOf('Flipper').add(
'Basic',
(context) => GameWidget(
game: FlipperGame(
trace: context.boolProperty('Trace', true),
),
game: FlipperGame()..trace = context.boolProperty('Trace', true),
),
codeLink: buildSourceLink('flipper/basic.dart'),
info: FlipperGame.info,

@ -4,10 +4,7 @@ import 'package:sandbox/common/common.dart';
import 'package:sandbox/stories/ball/basic_ball_game.dart';
class KickerGame extends BasicBallGame with Traceable {
KickerGame({
required bool trace,
}) : _trace = trace,
super(color: const Color(0xFFFF0000));
KickerGame() : super(color: const Color(0xFFFF0000));
static const info = '''
Shows how Kickers are rendered.
@ -16,11 +13,6 @@ class KickerGame extends BasicBallGame with Traceable {
- Tap anywhere on the screen to spawn a ball into the game.
''';
final bool _trace;
@override
bool get trace => _trace;
@override
Future<void> onLoad() async {
await super.onLoad();

@ -7,9 +7,7 @@ void addKickerStories(Dashbook dashbook) {
dashbook.storiesOf('Kickers').add(
'Basic',
(context) => GameWidget(
game: KickerGame(
trace: context.boolProperty('Trace', true),
),
game: KickerGame()..trace = context.boolProperty('Trace', true),
),
codeLink: buildSourceLink('kicker_game/basic.dart'),
info: KickerGame.info,

@ -4,10 +4,7 @@ import 'package:sandbox/common/common.dart';
import 'package:sandbox/stories/ball/basic_ball_game.dart';
class SlingshotGame extends BasicBallGame with Traceable {
SlingshotGame({
required bool trace,
}) : _trace = trace,
super(color: const Color(0xFFFF0000));
SlingshotGame() : super(color: const Color(0xFFFF0000));
static const info = '''
Shows how Slingshots are rendered.
@ -16,11 +13,6 @@ class SlingshotGame extends BasicBallGame with Traceable {
- Tap anywhere on the screen to spawn a ball into the game.
''';
final bool _trace;
@override
bool get trace => _trace;
@override
Future<void> onLoad() async {
await super.onLoad();

@ -7,9 +7,7 @@ void addSlingshotStories(Dashbook dashbook) {
dashbook.storiesOf('Slingshots').add(
'Basic',
(context) => GameWidget(
game: SlingshotGame(
trace: context.boolProperty('Trace', true),
),
game: SlingshotGame()..trace = context.boolProperty('Trace', true),
),
codeLink: buildSourceLink('slingshot_game/basic.dart'),
info: SlingshotGame.info,

@ -6,10 +6,7 @@ import 'package:sandbox/common/common.dart';
import 'package:sandbox/stories/ball/basic_ball_game.dart';
class SparkyBumperGame extends BasicBallGame with Traceable {
SparkyBumperGame({
required bool trace,
}) : _trace = trace,
super(color: const Color(0xFF0000FF));
SparkyBumperGame() : super(color: const Color(0xFF0000FF));
static const info = '''
Shows how a SparkyBumper is rendered.
@ -17,11 +14,6 @@ class SparkyBumperGame extends BasicBallGame with Traceable {
Activate the "trace" parameter to overlay the body.
''';
final bool _trace;
@override
bool get trace => _trace;
@override
Future<void> onLoad() async {
await super.onLoad();

@ -7,9 +7,7 @@ void addSparkyBumperStories(Dashbook dashbook) {
dashbook.storiesOf('Sparky Bumpers').add(
'Basic',
(context) => GameWidget(
game: SparkyBumperGame(
trace: context.boolProperty('Trace', true),
),
game: SparkyBumperGame()..trace = context.boolProperty('Trace', true),
),
codeLink: buildSourceLink('sparky_bumper/basic.dart'),
info: SparkyBumperGame.info,

Loading…
Cancel
Save