mirror of https://github.com/flutter/pinball.git
commit
01d4b8a8bf
@ -1,76 +0,0 @@
|
|||||||
import 'package:flutter/gestures.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:pinball/l10n/l10n.dart';
|
|
||||||
import 'package:pinball_ui/pinball_ui.dart';
|
|
||||||
|
|
||||||
/// {@template footer}
|
|
||||||
/// Footer widget with links to the main tech stack.
|
|
||||||
/// {@endtemplate}
|
|
||||||
class Footer extends StatelessWidget {
|
|
||||||
/// {@macro footer}
|
|
||||||
const Footer({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.fromLTRB(50, 0, 50, 32),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: const [
|
|
||||||
_MadeWithFlutterAndFirebase(),
|
|
||||||
_GoogleIO(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _GoogleIO extends StatelessWidget {
|
|
||||||
const _GoogleIO({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final l10n = context.l10n;
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
return Text(
|
|
||||||
l10n.footerGoogleIOText,
|
|
||||||
style: theme.textTheme.bodyText1!.copyWith(color: PinballColors.white),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MadeWithFlutterAndFirebase extends StatelessWidget {
|
|
||||||
const _MadeWithFlutterAndFirebase({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final l10n = context.l10n;
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
return RichText(
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
text: TextSpan(
|
|
||||||
text: l10n.footerMadeWithText,
|
|
||||||
style: theme.textTheme.bodyText1!.copyWith(color: PinballColors.white),
|
|
||||||
children: <TextSpan>[
|
|
||||||
TextSpan(
|
|
||||||
text: l10n.footerFlutterLinkText,
|
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () => openLink('https://flutter.dev'),
|
|
||||||
style: const TextStyle(
|
|
||||||
decoration: TextDecoration.underline,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const TextSpan(text: ' & '),
|
|
||||||
TextSpan(
|
|
||||||
text: l10n.footerFirebaseLinkText,
|
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () => openLink('https://firebase.google.com'),
|
|
||||||
style: const TextStyle(
|
|
||||||
decoration: TextDecoration.underline,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,5 @@
|
|||||||
export 'ball_spawning_behavior.dart';
|
export 'ball_spawning_behavior.dart';
|
||||||
|
export 'bonus_noise_behavior.dart';
|
||||||
export 'bumper_noise_behavior.dart';
|
export 'bumper_noise_behavior.dart';
|
||||||
export 'camera_focusing_behavior.dart';
|
export 'camera_focusing_behavior.dart';
|
||||||
export 'scoring_behavior.dart';
|
export 'scoring_behavior.dart';
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_bloc/flame_bloc.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball_audio/pinball_audio.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
/// Behavior that handles playing a bonus sound effect
|
||||||
|
class BonusNoiseBehavior extends Component {
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await add(
|
||||||
|
FlameBlocListener<GameBloc, GameState>(
|
||||||
|
listenWhen: (previous, current) {
|
||||||
|
return previous.bonusHistory.length != current.bonusHistory.length;
|
||||||
|
},
|
||||||
|
onNewState: (state) {
|
||||||
|
final bonus = state.bonusHistory.last;
|
||||||
|
final audioPlayer = readProvider<PinballPlayer>();
|
||||||
|
|
||||||
|
switch (bonus) {
|
||||||
|
case GameBonus.googleWord:
|
||||||
|
audioPlayer.play(PinballAudio.google);
|
||||||
|
break;
|
||||||
|
case GameBonus.sparkyTurboCharge:
|
||||||
|
audioPlayer.play(PinballAudio.sparky);
|
||||||
|
break;
|
||||||
|
case GameBonus.dinoChomp:
|
||||||
|
// TODO(erickzanardo): Add sound
|
||||||
|
break;
|
||||||
|
case GameBonus.androidSpaceship:
|
||||||
|
// TODO(erickzanardo): Add sound
|
||||||
|
break;
|
||||||
|
case GameBonus.dashNest:
|
||||||
|
// TODO(erickzanardo): Add sound
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
export 'more_information_dialog.dart';
|
@ -0,0 +1,218 @@
|
|||||||
|
import 'package:flutter/gestures.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
|
||||||
|
/// Inflates [MoreInformationDialog] using [showDialog].
|
||||||
|
Future<void> showMoreInformationDialog(BuildContext context) {
|
||||||
|
final gameWidgetWidth = MediaQuery.of(context).size.height * 9 / 16;
|
||||||
|
|
||||||
|
return showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierColor: PinballColors.transparent,
|
||||||
|
barrierDismissible: true,
|
||||||
|
builder: (_) {
|
||||||
|
return Center(
|
||||||
|
child: SizedBox(
|
||||||
|
height: gameWidgetWidth * 0.87,
|
||||||
|
width: gameWidgetWidth,
|
||||||
|
child: const MoreInformationDialog(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template more_information_dialog}
|
||||||
|
/// Dialog used to show informational links
|
||||||
|
/// {@endtemplate}
|
||||||
|
class MoreInformationDialog extends StatelessWidget {
|
||||||
|
/// {@macro more_information_dialog}
|
||||||
|
const MoreInformationDialog({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Material(
|
||||||
|
color: PinballColors.transparent,
|
||||||
|
child: _LinkBoxDecoration(
|
||||||
|
child: Column(
|
||||||
|
children: const [
|
||||||
|
SizedBox(height: 16),
|
||||||
|
_LinkBoxHeader(),
|
||||||
|
Expanded(
|
||||||
|
child: _LinkBoxBody(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LinkBoxHeader extends StatelessWidget {
|
||||||
|
const _LinkBoxHeader({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final l10n = context.l10n;
|
||||||
|
final indent = MediaQuery.of(context).size.width / 5;
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
l10n.linkBoxTitle,
|
||||||
|
style: Theme.of(context).textTheme.headline3!.copyWith(
|
||||||
|
color: PinballColors.blue,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Divider(
|
||||||
|
color: PinballColors.white,
|
||||||
|
endIndent: indent,
|
||||||
|
indent: indent,
|
||||||
|
thickness: 2,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LinkBoxDecoration extends StatelessWidget {
|
||||||
|
const _LinkBoxDecoration({
|
||||||
|
Key? key,
|
||||||
|
required this.child,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return DecoratedBox(
|
||||||
|
decoration: const CrtBackground().copyWith(
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
|
border: Border.all(
|
||||||
|
color: PinballColors.white,
|
||||||
|
width: 5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LinkBoxBody extends StatelessWidget {
|
||||||
|
const _LinkBoxBody({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final l10n = context.l10n;
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
|
const _MadeWithFlutterAndFirebase(),
|
||||||
|
_TextLink(
|
||||||
|
text: l10n.linkBoxOpenSourceCode,
|
||||||
|
link: _MoreInformationUrl.openSourceCode,
|
||||||
|
),
|
||||||
|
_TextLink(
|
||||||
|
text: l10n.linkBoxGoogleIOText,
|
||||||
|
link: _MoreInformationUrl.googleIOEvent,
|
||||||
|
),
|
||||||
|
_TextLink(
|
||||||
|
text: l10n.linkBoxFlutterGames,
|
||||||
|
link: _MoreInformationUrl.flutterGamesWebsite,
|
||||||
|
),
|
||||||
|
_TextLink(
|
||||||
|
text: l10n.linkBoxHowItsMade,
|
||||||
|
link: _MoreInformationUrl.howItsMadeArticle,
|
||||||
|
),
|
||||||
|
_TextLink(
|
||||||
|
text: l10n.linkBoxTermsOfService,
|
||||||
|
link: _MoreInformationUrl.termsOfService,
|
||||||
|
),
|
||||||
|
_TextLink(
|
||||||
|
text: l10n.linkBoxPrivacyPolicy,
|
||||||
|
link: _MoreInformationUrl.privacyPolicy,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TextLink extends StatelessWidget {
|
||||||
|
const _TextLink({
|
||||||
|
Key? key,
|
||||||
|
required this.text,
|
||||||
|
required this.link,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final String text;
|
||||||
|
final String link;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return InkWell(
|
||||||
|
onTap: () => openLink(link),
|
||||||
|
child: Text(
|
||||||
|
text,
|
||||||
|
style: theme.textTheme.headline5!.copyWith(
|
||||||
|
color: PinballColors.white,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MadeWithFlutterAndFirebase extends StatelessWidget {
|
||||||
|
const _MadeWithFlutterAndFirebase({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final l10n = context.l10n;
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return RichText(
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
text: TextSpan(
|
||||||
|
text: l10n.linkBoxMadeWithText,
|
||||||
|
style: theme.textTheme.headline5!.copyWith(color: PinballColors.white),
|
||||||
|
children: <TextSpan>[
|
||||||
|
TextSpan(
|
||||||
|
text: l10n.linkBoxFlutterLinkText,
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () => openLink(_MoreInformationUrl.flutterWebsite),
|
||||||
|
style: const TextStyle(
|
||||||
|
decoration: TextDecoration.underline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const TextSpan(text: ' & '),
|
||||||
|
TextSpan(
|
||||||
|
text: l10n.linkBoxFirebaseLinkText,
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () => openLink(_MoreInformationUrl.firebaseWebsite),
|
||||||
|
style: theme.textTheme.headline5!.copyWith(
|
||||||
|
decoration: TextDecoration.underline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _MoreInformationUrl {
|
||||||
|
static const flutterWebsite = 'https://flutter.dev';
|
||||||
|
static const firebaseWebsite = 'https://firebase.google.com';
|
||||||
|
static const openSourceCode = 'https://github.com/VGVentures/pinball';
|
||||||
|
static const googleIOEvent = 'https://events.google.com/io/';
|
||||||
|
static const flutterGamesWebsite = 'http://flutter.dev/games';
|
||||||
|
static const howItsMadeArticle =
|
||||||
|
'https://medium.com/flutter/i-o-pinball-powered-by-flutter-and-firebase-d22423f3f5d';
|
||||||
|
static const termsOfService = 'https://policies.google.com/terms';
|
||||||
|
static const privacyPolicy = 'https://policies.google.com/privacy';
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,186 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:flame_bloc/flame_bloc.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball/game/behaviors/behaviors.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball_audio/pinball_audio.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
class _TestGame extends Forge2DGame {
|
||||||
|
Future<void> pump(
|
||||||
|
BonusNoiseBehavior child, {
|
||||||
|
required PinballPlayer player,
|
||||||
|
required GameBloc bloc,
|
||||||
|
}) {
|
||||||
|
return ensureAdd(
|
||||||
|
FlameBlocProvider<GameBloc, GameState>.value(
|
||||||
|
value: bloc,
|
||||||
|
children: [
|
||||||
|
FlameProvider<PinballPlayer>.value(
|
||||||
|
player,
|
||||||
|
children: [
|
||||||
|
child,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MockPinballPlayer extends Mock implements PinballPlayer {}
|
||||||
|
|
||||||
|
class _MockGameBloc extends Mock implements GameBloc {}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
group('BonusNoiseBehavior', () {
|
||||||
|
late PinballPlayer player;
|
||||||
|
late GameBloc bloc;
|
||||||
|
final flameTester = FlameTester(_TestGame.new);
|
||||||
|
|
||||||
|
setUpAll(() {
|
||||||
|
registerFallbackValue(PinballAudio.google);
|
||||||
|
});
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
player = _MockPinballPlayer();
|
||||||
|
when(() => player.play(any())).thenAnswer((_) {});
|
||||||
|
bloc = _MockGameBloc();
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'plays google sound',
|
||||||
|
setUp: (game, _) async {
|
||||||
|
const state = GameState(
|
||||||
|
totalScore: 0,
|
||||||
|
roundScore: 0,
|
||||||
|
multiplier: 1,
|
||||||
|
rounds: 0,
|
||||||
|
bonusHistory: [GameBonus.googleWord],
|
||||||
|
status: GameStatus.playing,
|
||||||
|
);
|
||||||
|
const initialState = GameState.initial();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
Stream.fromIterable([initialState, state]),
|
||||||
|
initialState: initialState,
|
||||||
|
);
|
||||||
|
final behavior = BonusNoiseBehavior();
|
||||||
|
await game.pump(behavior, player: player, bloc: bloc);
|
||||||
|
},
|
||||||
|
verify: (_, __) async {
|
||||||
|
verify(() => player.play(PinballAudio.google)).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'plays sparky sound',
|
||||||
|
setUp: (game, _) async {
|
||||||
|
const state = GameState(
|
||||||
|
totalScore: 0,
|
||||||
|
roundScore: 0,
|
||||||
|
multiplier: 1,
|
||||||
|
rounds: 0,
|
||||||
|
bonusHistory: [GameBonus.sparkyTurboCharge],
|
||||||
|
status: GameStatus.playing,
|
||||||
|
);
|
||||||
|
const initialState = GameState.initial();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
Stream.fromIterable([initialState, state]),
|
||||||
|
initialState: initialState,
|
||||||
|
);
|
||||||
|
final behavior = BonusNoiseBehavior();
|
||||||
|
await game.pump(behavior, player: player, bloc: bloc);
|
||||||
|
},
|
||||||
|
verify: (_, __) async {
|
||||||
|
verify(() => player.play(PinballAudio.sparky)).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'plays dino chomp sound',
|
||||||
|
setUp: (game, _) async {
|
||||||
|
const state = GameState(
|
||||||
|
totalScore: 0,
|
||||||
|
roundScore: 0,
|
||||||
|
multiplier: 1,
|
||||||
|
rounds: 0,
|
||||||
|
bonusHistory: [GameBonus.dinoChomp],
|
||||||
|
status: GameStatus.playing,
|
||||||
|
);
|
||||||
|
const initialState = GameState.initial();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
Stream.fromIterable([initialState, state]),
|
||||||
|
initialState: initialState,
|
||||||
|
);
|
||||||
|
final behavior = BonusNoiseBehavior();
|
||||||
|
await game.pump(behavior, player: player, bloc: bloc);
|
||||||
|
},
|
||||||
|
verify: (_, __) async {
|
||||||
|
// TODO(erickzanardo): Change when the sound is implemented
|
||||||
|
verifyNever(() => player.play(any()));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'plays android spaceship sound',
|
||||||
|
setUp: (game, _) async {
|
||||||
|
const state = GameState(
|
||||||
|
totalScore: 0,
|
||||||
|
roundScore: 0,
|
||||||
|
multiplier: 1,
|
||||||
|
rounds: 0,
|
||||||
|
bonusHistory: [GameBonus.androidSpaceship],
|
||||||
|
status: GameStatus.playing,
|
||||||
|
);
|
||||||
|
const initialState = GameState.initial();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
Stream.fromIterable([initialState, state]),
|
||||||
|
initialState: initialState,
|
||||||
|
);
|
||||||
|
final behavior = BonusNoiseBehavior();
|
||||||
|
await game.pump(behavior, player: player, bloc: bloc);
|
||||||
|
},
|
||||||
|
verify: (_, __) async {
|
||||||
|
// TODO(erickzanardo): Change when the sound is implemented
|
||||||
|
verifyNever(() => player.play(any()));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'plays dash nest sound',
|
||||||
|
setUp: (game, _) async {
|
||||||
|
const state = GameState(
|
||||||
|
totalScore: 0,
|
||||||
|
roundScore: 0,
|
||||||
|
multiplier: 1,
|
||||||
|
rounds: 0,
|
||||||
|
bonusHistory: [GameBonus.dashNest],
|
||||||
|
status: GameStatus.playing,
|
||||||
|
);
|
||||||
|
const initialState = GameState.initial();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
Stream.fromIterable([initialState, state]),
|
||||||
|
initialState: initialState,
|
||||||
|
);
|
||||||
|
final behavior = BonusNoiseBehavior();
|
||||||
|
await game.pump(behavior, player: player, bloc: bloc);
|
||||||
|
},
|
||||||
|
verify: (_, __) async {
|
||||||
|
// TODO(erickzanardo): Change when the sound is implemented
|
||||||
|
verifyNever(() => player.play(any()));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue