Before Width: | Height: | Size: 283 KiB After Width: | Height: | Size: 270 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 28 KiB |
@ -0,0 +1,36 @@
|
|||||||
|
import 'package:dashbook/dashbook.dart';
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
|
||||||
|
const _path =
|
||||||
|
'https://github.com/VGVentures/pinball/tree/main/packages/pinball_components/sandbox/lib/stories/';
|
||||||
|
|
||||||
|
extension StoryAddGame on Story {
|
||||||
|
void addGame({
|
||||||
|
required String title,
|
||||||
|
required String description,
|
||||||
|
required Game Function(DashbookContext) gameBuilder,
|
||||||
|
}) {
|
||||||
|
final _chapter = Chapter(
|
||||||
|
title,
|
||||||
|
(DashbookContext context) {
|
||||||
|
final game = gameBuilder(context);
|
||||||
|
if (game is Traceable) {
|
||||||
|
game.trace = context.boolProperty('Trace', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return GameWidget(game: game);
|
||||||
|
},
|
||||||
|
this,
|
||||||
|
codeLink: '$_path${name.toPath()}/${title.toPath()}',
|
||||||
|
info: description,
|
||||||
|
);
|
||||||
|
chapters.add(_chapter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension on String {
|
||||||
|
String toPath() {
|
||||||
|
return replaceAll(' ', '_')..toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,3 @@
|
|||||||
|
export 'add_game.dart';
|
||||||
export 'games.dart';
|
export 'games.dart';
|
||||||
export 'methods.dart';
|
|
||||||
export 'trace.dart';
|
export 'trace.dart';
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
String buildSourceLink(String path) {
|
|
||||||
return 'https://github.com/VGVentures/pinball/tree/main/packages/pinball_components/sandbox/lib/stories/$path';
|
|
||||||
}
|
|
@ -1,25 +1,36 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/alien_zone/alien_bumper_a_game.dart';
|
import 'package:sandbox/stories/alien_zone/alien_bumper_a_game.dart';
|
||||||
import 'package:sandbox/stories/alien_zone/alien_bumper_b_game.dart';
|
import 'package:sandbox/stories/alien_zone/alien_bumper_b_game.dart';
|
||||||
|
import 'package:sandbox/stories/alien_zone/spaceship_game.dart';
|
||||||
|
import 'package:sandbox/stories/alien_zone/spaceship_rail_game.dart';
|
||||||
|
import 'package:sandbox/stories/alien_zone/spaceship_ramp_game.dart';
|
||||||
|
|
||||||
void addAlienZoneStories(Dashbook dashbook) {
|
void addAlienZoneStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Alien Zone')
|
dashbook.storiesOf('Alien Zone')
|
||||||
..add(
|
..addGame(
|
||||||
'Alien Bumper A',
|
title: 'Alien Bumper A',
|
||||||
(context) => GameWidget(
|
description: AlienBumperAGame.description,
|
||||||
game: AlienBumperAGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => AlienBumperAGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('alien_zone/alien_bumper_a.dart'),
|
|
||||||
info: AlienBumperAGame.info,
|
|
||||||
)
|
)
|
||||||
..add(
|
..addGame(
|
||||||
'Alien Bumper B',
|
title: 'Alien Bumper B',
|
||||||
(context) => GameWidget(
|
description: AlienBumperBGame.description,
|
||||||
game: AlienBumperBGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => AlienBumperBGame(),
|
||||||
),
|
)
|
||||||
codeLink: buildSourceLink('alien_zone/alien_bumper_b.dart'),
|
..addGame(
|
||||||
info: AlienBumperAGame.info,
|
title: 'Spaceship',
|
||||||
|
description: SpaceshipGame.description,
|
||||||
|
gameBuilder: (_) => SpaceshipGame(),
|
||||||
|
)
|
||||||
|
..addGame(
|
||||||
|
title: 'Spaceship Rail',
|
||||||
|
description: SpaceshipRailGame.description,
|
||||||
|
gameBuilder: (_) => SpaceshipRailGame(),
|
||||||
|
)
|
||||||
|
..addGame(
|
||||||
|
title: 'Spaceship Ramp',
|
||||||
|
description: SpaceshipRampGame.description,
|
||||||
|
gameBuilder: (_) => SpaceshipRampGame(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,25 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/backboard/backboard_game_over_game.dart';
|
import 'package:sandbox/stories/backboard/backboard_game_over_game.dart';
|
||||||
import 'package:sandbox/stories/backboard/backboard_waiting_game.dart';
|
import 'package:sandbox/stories/backboard/backboard_waiting_game.dart';
|
||||||
|
|
||||||
void addBackboardStories(Dashbook dashbook) {
|
void addBackboardStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Backboard')
|
dashbook.storiesOf('Backboard')
|
||||||
..add(
|
..addGame(
|
||||||
'Waiting mode',
|
title: 'Waiting',
|
||||||
(context) => GameWidget(
|
description: BackboardWaitingGame.description,
|
||||||
game: BackboardWaitingGame(),
|
gameBuilder: (_) => BackboardWaitingGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('backboard/waiting.dart'),
|
|
||||||
info: BackboardWaitingGame.info,
|
|
||||||
)
|
)
|
||||||
..add(
|
..addGame(
|
||||||
'Game over',
|
title: 'Game over',
|
||||||
(context) => GameWidget(
|
description: BackboardGameOverGame.description,
|
||||||
game: BackboardGameOverGame(
|
gameBuilder: (context) => BackboardGameOverGame(
|
||||||
context.numberProperty('Score', 9000000000).toInt(),
|
context.numberProperty('Score', 9000000000).toInt(),
|
||||||
context.listProperty(
|
context.listProperty(
|
||||||
'Character',
|
'Character',
|
||||||
BackboardGameOverGame.characterIconPaths.keys.first,
|
BackboardGameOverGame.characterIconPaths.keys.first,
|
||||||
BackboardGameOverGame.characterIconPaths.keys.toList(),
|
BackboardGameOverGame.characterIconPaths.keys.toList(),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
codeLink: buildSourceLink('backboard/game_over.dart'),
|
|
||||||
info: BackboardGameOverGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/baseboard/baseboard_game.dart';
|
import 'package:sandbox/stories/baseboard/baseboard_game.dart';
|
||||||
|
|
||||||
void addBaseboardStories(Dashbook dashbook) {
|
void addBaseboardStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Baseboard').add(
|
dashbook.storiesOf('Baseboard').addGame(
|
||||||
'Basic',
|
title: 'Traced',
|
||||||
(context) => GameWidget(
|
description: BaseboardGame.description,
|
||||||
game: BaseboardGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => BaseboardGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('baseboard_game/basic.dart'),
|
|
||||||
info: BaseboardGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/boundaries/boundaries_game.dart';
|
import 'package:sandbox/stories/boundaries/boundaries_game.dart';
|
||||||
|
|
||||||
void addBoundariesStories(Dashbook dashbook) {
|
void addBoundariesStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Boundaries').add(
|
dashbook.storiesOf('Boundaries').addGame(
|
||||||
'Basic',
|
title: 'Traced',
|
||||||
(context) => GameWidget(
|
description: BoundariesGame.description,
|
||||||
game: BoundariesGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => BoundariesGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('boundaries_game/basic.dart'),
|
|
||||||
info: BoundariesGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/chrome_dino/chrome_dino_game.dart';
|
import 'package:sandbox/stories/chrome_dino/chrome_dino_game.dart';
|
||||||
|
|
||||||
void addChromeDinoStories(Dashbook dashbook) {
|
void addChromeDinoStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Chrome Dino').add(
|
dashbook.storiesOf('Chrome Dino').addGame(
|
||||||
'Basic',
|
title: 'Trace',
|
||||||
(context) => GameWidget(
|
description: ChromeDinoGame.description,
|
||||||
game: ChromeDinoGame(),
|
gameBuilder: (_) => ChromeDinoGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('chrome_dino/basic.dart'),
|
|
||||||
info: ChromeDinoGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flame/input.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
import 'package:sandbox/stories/ball/basic_ball_game.dart';
|
||||||
|
|
||||||
|
class DinoWallGame extends BallGame {
|
||||||
|
DinoWallGame() : super();
|
||||||
|
|
||||||
|
static const description = '''
|
||||||
|
Shows how DinoWalls are rendered.
|
||||||
|
|
||||||
|
- Activate the "trace" parameter to overlay the body.
|
||||||
|
- Tap anywhere on the screen to spawn a ball into the game.
|
||||||
|
''';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
await images.loadAll([
|
||||||
|
Assets.images.dino.dinoLandTop.keyName,
|
||||||
|
Assets.images.dino.dinoLandBottom.keyName,
|
||||||
|
]);
|
||||||
|
|
||||||
|
await addFromBlueprint(DinoWalls());
|
||||||
|
camera.followVector2(Vector2.zero());
|
||||||
|
await traceAllBodies();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import 'package:dashbook/dashbook.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
import 'package:sandbox/stories/dino_wall/dino_wall_game.dart';
|
||||||
|
|
||||||
|
void addDinoWallStories(Dashbook dashbook) {
|
||||||
|
dashbook.storiesOf('DinoWall').addGame(
|
||||||
|
title: 'Traced',
|
||||||
|
description: DinoWallGame.description,
|
||||||
|
gameBuilder: (_) => DinoWallGame(),
|
||||||
|
);
|
||||||
|
}
|
@ -1,13 +1,18 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
|
import 'package:sandbox/stories/effects/camera_zoom_game.dart';
|
||||||
import 'package:sandbox/stories/effects/fire_effect_game.dart';
|
import 'package:sandbox/stories/effects/fire_effect_game.dart';
|
||||||
|
|
||||||
void addEffectsStories(Dashbook dashbook) {
|
void addEffectsStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Effects').add(
|
dashbook.storiesOf('Effects')
|
||||||
'Fire Effect',
|
..addGame(
|
||||||
(context) => GameWidget(game: FireEffectGame()),
|
title: 'Fire',
|
||||||
codeLink: buildSourceLink('effects/fire_effect.dart'),
|
description: FireEffectGame.description,
|
||||||
info: FireEffectGame.info,
|
gameBuilder: (_) => FireEffectGame(),
|
||||||
);
|
)
|
||||||
|
..addGame(
|
||||||
|
title: 'CameraZoom',
|
||||||
|
description: CameraZoomGame.description,
|
||||||
|
gameBuilder: (_) => CameraZoomGame(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/flipper/flipper_game.dart';
|
import 'package:sandbox/stories/flipper/flipper_game.dart';
|
||||||
|
|
||||||
void addFlipperStories(Dashbook dashbook) {
|
void addFlipperStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Flipper').add(
|
dashbook.storiesOf('Flipper').addGame(
|
||||||
'Basic',
|
title: 'Traced',
|
||||||
(context) => GameWidget(
|
description: FlipperGame.description,
|
||||||
game: FlipperGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => FlipperGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('flipper/basic.dart'),
|
|
||||||
info: FlipperGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/google_word/google_letter_game.dart';
|
import 'package:sandbox/stories/google_word/google_letter_game.dart';
|
||||||
|
|
||||||
void addGoogleWordStories(Dashbook dashbook) {
|
void addGoogleWordStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Google Word').add(
|
dashbook.storiesOf('Google Word').addGame(
|
||||||
'Letter',
|
title: 'Letter 0',
|
||||||
(context) => GameWidget(
|
description: GoogleLetterGame.description,
|
||||||
game: GoogleLetterGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => GoogleLetterGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('google_word/letter.dart'),
|
|
||||||
info: GoogleLetterGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/kicker/kicker_game.dart';
|
import 'package:sandbox/stories/kicker/kicker_game.dart';
|
||||||
|
|
||||||
void addKickerStories(Dashbook dashbook) {
|
void addKickerStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Kickers').add(
|
dashbook.storiesOf('Kickers').addGame(
|
||||||
'Basic',
|
title: 'Traced',
|
||||||
(context) => GameWidget(
|
description: KickerGame.description,
|
||||||
game: KickerGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => KickerGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('kicker_game/basic.dart'),
|
|
||||||
info: KickerGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/launch_ramp/launch_ramp_game.dart';
|
import 'package:sandbox/stories/launch_ramp/launch_ramp_game.dart';
|
||||||
|
|
||||||
void addLaunchRampStories(Dashbook dashbook) {
|
void addLaunchRampStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('LaunchRamp').add(
|
dashbook.storiesOf('LaunchRamp').addGame(
|
||||||
'Basic',
|
title: 'Traced',
|
||||||
(context) => GameWidget(
|
description: LaunchRampGame.description,
|
||||||
game: LaunchRampGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => LaunchRampGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('launch_ramp/basic.dart'),
|
|
||||||
info: LaunchRampGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/layer/basic_layer_game.dart';
|
import 'package:sandbox/stories/layer/layer_game.dart';
|
||||||
|
|
||||||
void addLayerStories(Dashbook dashbook) {
|
void addLayerStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Layer').add(
|
dashbook.storiesOf('Layer').addGame(
|
||||||
'Layer',
|
title: 'Example',
|
||||||
(context) => GameWidget(
|
description: LayerGame.description,
|
||||||
game: BasicLayerGame(
|
gameBuilder: (_) => LayerGame(),
|
||||||
color: context.colorProperty('color', Colors.blue),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('layer/basic.dart'),
|
|
||||||
info: BasicLayerGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/multipliers/multipliers_game.dart';
|
import 'package:sandbox/stories/multipliers/multipliers_game.dart';
|
||||||
|
|
||||||
void addMultipliersStories(Dashbook dashbook) {
|
void addMultipliersStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Multipliers').add(
|
dashbook.storiesOf('Multipliers').addGame(
|
||||||
'Basic',
|
title: 'Assets',
|
||||||
(context) => GameWidget(
|
description: MultipliersGame.description,
|
||||||
game: MultipliersGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => MultipliersGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('multiplier/basic.dart'),
|
|
||||||
info: MultipliersGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/plunger/plunger_game.dart';
|
import 'package:sandbox/stories/plunger/plunger_game.dart';
|
||||||
|
|
||||||
void addPlungerStories(Dashbook dashbook) {
|
void addPlungerStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Plunger').add(
|
dashbook.storiesOf('Plunger').addGame(
|
||||||
'Basic',
|
title: 'Traced',
|
||||||
(context) => GameWidget(
|
description: PlungerGame.description,
|
||||||
game: PlungerGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => PlungerGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('plunger_game/basic.dart'),
|
|
||||||
info: PlungerGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/score_text/basic.dart';
|
import 'package:sandbox/stories/score_text/score_text_game.dart';
|
||||||
|
|
||||||
void addScoreTextStories(Dashbook dashbook) {
|
void addScoreTextStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('ScoreText').add(
|
dashbook.storiesOf('ScoreText').addGame(
|
||||||
'Basic',
|
title: 'Basic',
|
||||||
(context) => GameWidget(
|
description: ScoreTextGame.description,
|
||||||
game: ScoreTextBasicGame(),
|
gameBuilder: (_) => ScoreTextGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('score_text/basic.dart'),
|
|
||||||
info: ScoreTextBasicGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/slingshot/slingshot_game.dart';
|
import 'package:sandbox/stories/slingshot/slingshot_game.dart';
|
||||||
|
|
||||||
void addSlingshotStories(Dashbook dashbook) {
|
void addSlingshotStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Slingshots').add(
|
dashbook.storiesOf('Slingshots').addGame(
|
||||||
'Basic',
|
title: 'Traced',
|
||||||
(context) => GameWidget(
|
description: SlingshotGame.description,
|
||||||
game: SlingshotGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => SlingshotGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('slingshot_game/basic.dart'),
|
|
||||||
info: SlingshotGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
|
||||||
import 'package:sandbox/stories/spaceship/basic_spaceship_game.dart';
|
|
||||||
|
|
||||||
void addSpaceshipStories(Dashbook dashbook) {
|
|
||||||
dashbook.storiesOf('Spaceship').add(
|
|
||||||
'Basic',
|
|
||||||
(context) => GameWidget(
|
|
||||||
game: BasicSpaceshipGame(),
|
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('spaceship/basic.dart'),
|
|
||||||
info: BasicSpaceshipGame.info,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
|
||||||
import 'package:sandbox/stories/spaceship_rail/spaceship_rail_game.dart';
|
|
||||||
|
|
||||||
void addSpaceshipRailStories(Dashbook dashbook) {
|
|
||||||
dashbook.storiesOf('SpaceshipRail').add(
|
|
||||||
'Basic',
|
|
||||||
(context) => GameWidget(
|
|
||||||
game: SpaceshipRailGame()
|
|
||||||
..trace = context.boolProperty('Trace', true),
|
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('spaceship_rail/basic.dart'),
|
|
||||||
info: SpaceshipRailGame.info,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
|
||||||
import 'package:sandbox/stories/spaceship_ramp/spaceship_ramp_game.dart';
|
|
||||||
|
|
||||||
void addSpaceshipRampStories(Dashbook dashbook) {
|
|
||||||
dashbook.storiesOf('SpaceshipRamp').add(
|
|
||||||
'Basic',
|
|
||||||
(context) => GameWidget(
|
|
||||||
game: SpaceshipRampGame()
|
|
||||||
..trace = context.boolProperty('Trace', true),
|
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('spaceship_ramp/basic.dart'),
|
|
||||||
info: SpaceshipRampGame.info,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,15 +1,11 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
import 'package:dashbook/dashbook.dart';
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
import 'package:sandbox/common/common.dart';
|
||||||
import 'package:sandbox/stories/sparky_bumper/sparky_bumper_game.dart';
|
import 'package:sandbox/stories/sparky_bumper/sparky_bumper_game.dart';
|
||||||
|
|
||||||
void addSparkyBumperStories(Dashbook dashbook) {
|
void addSparkyBumperStories(Dashbook dashbook) {
|
||||||
dashbook.storiesOf('Sparky Bumpers').add(
|
dashbook.storiesOf('Sparky Bumpers').addGame(
|
||||||
'Basic',
|
title: 'Traced',
|
||||||
(context) => GameWidget(
|
description: SparkyBumperGame.description,
|
||||||
game: SparkyBumperGame()..trace = context.boolProperty('Trace', true),
|
gameBuilder: (_) => SparkyBumperGame(),
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('sparky_bumper/basic.dart'),
|
|
||||||
info: SparkyBumperGame.info,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
import 'package:dashbook/dashbook.dart';
|
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:sandbox/common/common.dart';
|
|
||||||
import 'package:sandbox/stories/zoom/basic_zoom_game.dart';
|
|
||||||
|
|
||||||
void addZoomStories(Dashbook dashbook) {
|
|
||||||
dashbook.storiesOf('CameraZoom').add(
|
|
||||||
'Basic',
|
|
||||||
(context) => GameWidget(
|
|
||||||
game: BasicCameraZoomGame(),
|
|
||||||
),
|
|
||||||
codeLink: buildSourceLink('zoom/basic_zoom_game.dart'),
|
|
||||||
info: BasicCameraZoomGame.info,
|
|
||||||
);
|
|
||||||
}
|
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 148 KiB |
@ -0,0 +1,102 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs
|
||||||
|
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame/image_composition.dart';
|
||||||
|
import 'package:flutter/material.dart' hide Animation;
|
||||||
|
|
||||||
|
/// {@template flame.widgets.sprite_animation_widget}
|
||||||
|
/// A [StatelessWidget] that renders a [SpriteAnimation].
|
||||||
|
/// {@endtemplate}
|
||||||
|
// TODO(arturplaczek): Remove when this PR will be merged.
|
||||||
|
// https://github.com/flame-engine/flame/pull/1552
|
||||||
|
class SpriteAnimationWidget extends StatelessWidget {
|
||||||
|
/// {@macro flame.widgets.sprite_animation_widget}
|
||||||
|
const SpriteAnimationWidget({
|
||||||
|
required this.controller,
|
||||||
|
this.anchor = Anchor.topLeft,
|
||||||
|
Key? key,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
/// The positioning [Anchor].
|
||||||
|
final Anchor anchor;
|
||||||
|
|
||||||
|
final SpriteAnimationController controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AnimatedBuilder(
|
||||||
|
animation: controller,
|
||||||
|
builder: (_, __) {
|
||||||
|
return CustomPaint(
|
||||||
|
painter: SpritePainter(
|
||||||
|
controller.animation.getSprite(),
|
||||||
|
anchor,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SpriteAnimationController extends AnimationController {
|
||||||
|
SpriteAnimationController({
|
||||||
|
required TickerProvider vsync,
|
||||||
|
required this.animation,
|
||||||
|
}) : super(vsync: vsync) {
|
||||||
|
duration = Duration(seconds: animation.totalDuration().ceil());
|
||||||
|
}
|
||||||
|
|
||||||
|
final SpriteAnimation animation;
|
||||||
|
|
||||||
|
double? _lastUpdated;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void notifyListeners() {
|
||||||
|
super.notifyListeners();
|
||||||
|
|
||||||
|
final now = DateTime.now().millisecond.toDouble();
|
||||||
|
final dt = max<double>(0, (now - (_lastUpdated ?? 0)) / 1000);
|
||||||
|
animation.update(dt);
|
||||||
|
_lastUpdated = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SpritePainter extends CustomPainter {
|
||||||
|
SpritePainter(
|
||||||
|
this._sprite,
|
||||||
|
this._anchor, {
|
||||||
|
double angle = 0,
|
||||||
|
}) : _angle = angle;
|
||||||
|
|
||||||
|
final Sprite _sprite;
|
||||||
|
final Anchor _anchor;
|
||||||
|
final double _angle;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(SpritePainter oldDelegate) {
|
||||||
|
return oldDelegate._sprite != _sprite ||
|
||||||
|
oldDelegate._anchor != _anchor ||
|
||||||
|
oldDelegate._angle != _angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
final boxSize = size.toVector2();
|
||||||
|
final rate = boxSize.clone()..divide(_sprite.srcSize);
|
||||||
|
final minRate = min(rate.x, rate.y);
|
||||||
|
final paintSize = _sprite.srcSize * minRate;
|
||||||
|
final anchorPosition = _anchor.toVector2();
|
||||||
|
final boxAnchorPosition = boxSize.clone()..multiply(anchorPosition);
|
||||||
|
final spriteAnchorPosition = anchorPosition..multiply(paintSize);
|
||||||
|
|
||||||
|
canvas
|
||||||
|
..translateVector(boxAnchorPosition..sub(spriteAnchorPosition))
|
||||||
|
..renderRotated(
|
||||||
|
_angle,
|
||||||
|
spriteAnchorPosition,
|
||||||
|
(canvas) => _sprite.render(canvas, size: paintSize),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
class MockSpriteAnimationController extends Mock
|
||||||
|
implements SpriteAnimationController {}
|
||||||
|
|
||||||
|
class MockSpriteAnimation extends Mock implements SpriteAnimation {}
|
||||||
|
|
||||||
|
class MockSprite extends Mock implements Sprite {}
|
||||||
|
|
||||||
|
// TODO(arturplaczek): Remove when this PR will be merged.
|
||||||
|
// https://github.com/flame-engine/flame/pull/1552
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('PinballSpriteAnimationWidget', () {
|
||||||
|
late SpriteAnimationController controller;
|
||||||
|
late SpriteAnimation animation;
|
||||||
|
late Sprite sprite;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
controller = MockSpriteAnimationController();
|
||||||
|
animation = MockSpriteAnimation();
|
||||||
|
sprite = MockSprite();
|
||||||
|
|
||||||
|
when(() => controller.animation).thenAnswer((_) => animation);
|
||||||
|
|
||||||
|
when(() => animation.totalDuration()).thenAnswer((_) => 1);
|
||||||
|
when(() => animation.getSprite()).thenAnswer((_) => sprite);
|
||||||
|
when(() => sprite.srcSize).thenAnswer((_) => Vector2(1, 1));
|
||||||
|
when(() => sprite.srcSize).thenAnswer((_) => Vector2(1, 1));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('renders correctly', (tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
SpriteAnimationWidget(
|
||||||
|
controller: controller,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(SpriteAnimationWidget), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('SpriteAnimationController is updating animations', () {
|
||||||
|
SpriteAnimationController(
|
||||||
|
vsync: const TestVSync(),
|
||||||
|
animation: animation,
|
||||||
|
).notifyListeners();
|
||||||
|
|
||||||
|
verify(() => animation.update(any())).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('SpritePainter shouldRepaint returns true when Sprite changed',
|
||||||
|
(tester) async {
|
||||||
|
final spritePainter = SpritePainter(
|
||||||
|
sprite,
|
||||||
|
Anchor.center,
|
||||||
|
angle: 45,
|
||||||
|
);
|
||||||
|
|
||||||
|
final anotherPainter = SpritePainter(
|
||||||
|
sprite,
|
||||||
|
Anchor.center,
|
||||||
|
angle: 30,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(spritePainter.shouldRepaint(anotherPainter), isTrue);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
library share_repository;
|
library share_repository;
|
||||||
|
|
||||||
|
export 'src/models/models.dart';
|
||||||
export 'src/share_repository.dart';
|
export 'src/share_repository.dart';
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
export 'share_platform.dart';
|
@ -0,0 +1,8 @@
|
|||||||
|
/// The platform that is being used to share a score.
|
||||||
|
enum SharePlatform {
|
||||||
|
/// Twitter platform.
|
||||||
|
twitter,
|
||||||
|
|
||||||
|
/// Facebook platform.
|
||||||
|
facebook,
|
||||||
|
}
|
@ -1,7 +1,30 @@
|
|||||||
|
import 'package:share_repository/share_repository.dart';
|
||||||
|
|
||||||
/// {@template share_repository}
|
/// {@template share_repository}
|
||||||
/// Repository to facilitate sharing scores.
|
/// Repository to facilitate sharing scores.
|
||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
class ShareRepository {
|
class ShareRepository {
|
||||||
/// {@macro share_repository}
|
/// {@macro share_repository}
|
||||||
const ShareRepository();
|
const ShareRepository({
|
||||||
|
required String appUrl,
|
||||||
|
}) : _appUrl = appUrl;
|
||||||
|
|
||||||
|
final String _appUrl;
|
||||||
|
|
||||||
|
/// Returns a url to share the [value] on the given [platform].
|
||||||
|
///
|
||||||
|
/// The returned url can be opened using the [url_launcher](https://pub.dev/packages/url_launcher) package.
|
||||||
|
String shareText({
|
||||||
|
required String value,
|
||||||
|
required SharePlatform platform,
|
||||||
|
}) {
|
||||||
|
final encodedUrl = Uri.encodeComponent(_appUrl);
|
||||||
|
final encodedShareText = Uri.encodeComponent(value);
|
||||||
|
switch (platform) {
|
||||||
|
case SharePlatform.twitter:
|
||||||
|
return 'https://twitter.com/intent/tweet?url=$encodedUrl&text=$encodedShareText';
|
||||||
|
case SharePlatform.facebook:
|
||||||
|
return 'https://www.facebook.com/sharer.php?u=$encodedUrl"e=$encodedShareText';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|