@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"projects": {
|
||||||
|
"default": "pinball-dev"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
@ -0,0 +1,28 @@
|
|||||||
|
const functions = require("firebase-functions");
|
||||||
|
const admin = require("firebase-admin");
|
||||||
|
admin.initializeApp();
|
||||||
|
|
||||||
|
const db = admin.firestore();
|
||||||
|
|
||||||
|
exports.timedLeaderboardCleanup = functions.firestore
|
||||||
|
.document("leaderboard/{leaderboardEntry}")
|
||||||
|
.onCreate(async (_, __) => {
|
||||||
|
functions.logger.info(
|
||||||
|
"Document created, getting all leaderboard documents"
|
||||||
|
);
|
||||||
|
const snapshot = await db
|
||||||
|
.collection("leaderboard")
|
||||||
|
.orderBy("score", "desc")
|
||||||
|
.offset(10)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
functions.logger.info(
|
||||||
|
`Preparing to delete ${snapshot.docs.length} documents.`
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
await Promise.all(snapshot.docs.map((doc) => doc.ref.delete()));
|
||||||
|
functions.logger.info("Success");
|
||||||
|
} catch (error) {
|
||||||
|
functions.logger.error(`Failed to delete documents ${error}`);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "functions",
|
||||||
|
"description": "Cloud Functions for Firebase",
|
||||||
|
"scripts": {
|
||||||
|
"serve": "firebase emulators:start --only functions",
|
||||||
|
"shell": "firebase functions:shell",
|
||||||
|
"start": "npm run shell",
|
||||||
|
"deploy": "firebase deploy --only functions",
|
||||||
|
"logs": "firebase functions:log"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "16"
|
||||||
|
},
|
||||||
|
"main": "index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"firebase-admin": "^10.0.2",
|
||||||
|
"firebase-functions": "^3.18.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"firebase-functions-test": "^0.2.0"
|
||||||
|
},
|
||||||
|
"private": true
|
||||||
|
}
|
@ -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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,20 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_bloc/flame_bloc.dart';
|
||||||
|
import 'package:pinball/select_character/select_character.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
/// Updates the launch [Ball] to reflect character selections.
|
||||||
|
class BallThemingBehavior extends Component
|
||||||
|
with
|
||||||
|
FlameBlocListenable<CharacterThemeCubit, CharacterThemeState>,
|
||||||
|
HasGameRef {
|
||||||
|
@override
|
||||||
|
void onNewState(CharacterThemeState state) {
|
||||||
|
gameRef
|
||||||
|
.descendants()
|
||||||
|
.whereType<Ball>()
|
||||||
|
.single
|
||||||
|
.bloc
|
||||||
|
.onThemeChanged(state.characterTheme);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
export 'ball_spawning_behavior.dart';
|
export 'ball_spawning_behavior.dart';
|
||||||
|
export 'ball_theming_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,38 @@
|
|||||||
|
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:
|
||||||
|
break;
|
||||||
|
case GameBonus.androidSpaceship:
|
||||||
|
break;
|
||||||
|
case GameBonus.dashNest:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,66 +0,0 @@
|
|||||||
// ignore_for_file: avoid_renaming_method_parameters
|
|
||||||
|
|
||||||
import 'package:flame/components.dart';
|
|
||||||
import 'package:flame_bloc/flame_bloc.dart';
|
|
||||||
import 'package:pinball/game/game.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
|
||||||
import 'package:pinball_flame/pinball_flame.dart';
|
|
||||||
import 'package:pinball_theme/pinball_theme.dart';
|
|
||||||
|
|
||||||
/// {@template controlled_ball}
|
|
||||||
/// A [Ball] with a [BallController] attached.
|
|
||||||
///
|
|
||||||
/// When a [Ball] is lost, if there aren't more [Ball]s in play and the game is
|
|
||||||
/// not over, a new [Ball] will be spawned.
|
|
||||||
/// {@endtemplate}
|
|
||||||
class ControlledBall extends Ball with Controls<BallController> {
|
|
||||||
/// A [Ball] that launches from the [Plunger].
|
|
||||||
ControlledBall.launch({
|
|
||||||
required CharacterTheme characterTheme,
|
|
||||||
}) : super(assetPath: characterTheme.ball.keyName) {
|
|
||||||
controller = BallController(this);
|
|
||||||
layer = Layer.launcher;
|
|
||||||
zIndex = ZIndexes.ballOnLaunchRamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// {@macro controlled_ball}
|
|
||||||
ControlledBall.bonus({
|
|
||||||
required CharacterTheme characterTheme,
|
|
||||||
}) : super(assetPath: characterTheme.ball.keyName) {
|
|
||||||
controller = BallController(this);
|
|
||||||
zIndex = ZIndexes.ballOnBoard;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// [Ball] used in [DebugPinballGame].
|
|
||||||
ControlledBall.debug() : super() {
|
|
||||||
controller = BallController(this);
|
|
||||||
zIndex = ZIndexes.ballOnBoard;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// {@template ball_controller}
|
|
||||||
/// Controller attached to a [Ball] that handles its game related logic.
|
|
||||||
/// {@endtemplate}
|
|
||||||
class BallController extends ComponentController<Ball>
|
|
||||||
with FlameBlocReader<GameBloc, GameState> {
|
|
||||||
/// {@macro ball_controller}
|
|
||||||
BallController(Ball ball) : super(ball);
|
|
||||||
|
|
||||||
/// Stops the [Ball] inside of the [SparkyComputer] while the turbo charge
|
|
||||||
/// sequence runs, then boosts the ball out of the computer.
|
|
||||||
Future<void> turboCharge() async {
|
|
||||||
bloc.add(const SparkyTurboChargeActivated());
|
|
||||||
|
|
||||||
component.stop();
|
|
||||||
// TODO(alestiago): Refactor this hard coded duration once the following is
|
|
||||||
// merged:
|
|
||||||
// https://github.com/flame-engine/flame/pull/1564
|
|
||||||
await Future<void>.delayed(
|
|
||||||
const Duration(milliseconds: 2583),
|
|
||||||
);
|
|
||||||
component.resume();
|
|
||||||
await component.add(
|
|
||||||
BallTurboChargingBehavior(impulse: Vector2(40, 110)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1 @@
|
|||||||
|
export 'sparky_computer_bonus_behavior.dart';
|
@ -0,0 +1,24 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_bloc/flame_bloc.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
/// Adds a [GameBonus.sparkyTurboCharge] when a [Ball] enters the
|
||||||
|
/// [SparkyComputer].
|
||||||
|
class SparkyComputerBonusBehavior extends Component
|
||||||
|
with ParentIsA<SparkyScorch>, FlameBlocReader<GameBloc, GameState> {
|
||||||
|
@override
|
||||||
|
void onMount() {
|
||||||
|
super.onMount();
|
||||||
|
final sparkyComputer = parent.firstChild<SparkyComputer>()!;
|
||||||
|
final animatronic = parent.firstChild<SparkyAnimatronic>()!;
|
||||||
|
sparkyComputer.bloc.stream.listen((state) async {
|
||||||
|
final listenWhen = state == SparkyComputerState.withBall;
|
||||||
|
if (!listenWhen) return;
|
||||||
|
|
||||||
|
bloc.add(const BonusActivated(GameBonus.sparkyTurboCharge));
|
||||||
|
animatronic.playing = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -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';
|
||||||
|
}
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 10 KiB |
@ -0,0 +1,15 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs
|
||||||
|
|
||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:pinball_theme/pinball_theme.dart';
|
||||||
|
|
||||||
|
part 'ball_state.dart';
|
||||||
|
|
||||||
|
class BallCubit extends Cubit<BallState> {
|
||||||
|
BallCubit() : super(const BallState.initial());
|
||||||
|
|
||||||
|
void onThemeChanged(CharacterTheme characterTheme) {
|
||||||
|
emit(BallState(characterTheme: characterTheme));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs
|
||||||
|
|
||||||
|
part of 'ball_cubit.dart';
|
||||||
|
|
||||||
|
class BallState extends Equatable {
|
||||||
|
const BallState({required this.characterTheme});
|
||||||
|
|
||||||
|
const BallState.initial() : this(characterTheme: const DashTheme());
|
||||||
|
|
||||||
|
final CharacterTheme characterTheme;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [characterTheme];
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
export 'sparky_computer_sensor_ball_contact_behavior.dart';
|
@ -0,0 +1,35 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
/// {@template sparky_computer_sensor_ball_contact_behavior}
|
||||||
|
/// When a [Ball] enters the [SparkyComputer] it is stopped for a period of time
|
||||||
|
/// before a [BallTurboChargingBehavior] is applied to it.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class SparkyComputerSensorBallContactBehavior
|
||||||
|
extends ContactBehavior<SparkyComputer> {
|
||||||
|
@override
|
||||||
|
Future<void> beginContact(Object other, Contact contact) async {
|
||||||
|
super.beginContact(other, contact);
|
||||||
|
if (other is! Ball) return;
|
||||||
|
|
||||||
|
other.stop();
|
||||||
|
parent.bloc.onBallEntered();
|
||||||
|
await parent.add(
|
||||||
|
TimerComponent(
|
||||||
|
period: 1.5,
|
||||||
|
removeOnFinish: true,
|
||||||
|
onTick: () async {
|
||||||
|
other.resume();
|
||||||
|
await other.add(
|
||||||
|
BallTurboChargingBehavior(
|
||||||
|
impulse: Vector2(40, 110),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
parent.bloc.onBallTurboCharged();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs
|
||||||
|
|
||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
|
||||||
|
part 'sparky_computer_state.dart';
|
||||||
|
|
||||||
|
class SparkyComputerCubit extends Cubit<SparkyComputerState> {
|
||||||
|
SparkyComputerCubit() : super(SparkyComputerState.withoutBall);
|
||||||
|
|
||||||
|
void onBallEntered() {
|
||||||
|
emit(SparkyComputerState.withBall);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onBallTurboCharged() {
|
||||||
|
emit(SparkyComputerState.withoutBall);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs
|
||||||
|
|
||||||
|
part of 'sparky_computer_cubit.dart';
|
||||||
|
|
||||||
|
enum SparkyComputerState {
|
||||||
|
withoutBall,
|
||||||
|
withBall,
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_theme/pinball_theme.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group(
|
||||||
|
'BallCubit',
|
||||||
|
() {
|
||||||
|
blocTest<BallCubit, BallState>(
|
||||||
|
'onThemeChanged emits new theme',
|
||||||
|
build: BallCubit.new,
|
||||||
|
act: (bloc) => bloc.onThemeChanged(const DinoTheme()),
|
||||||
|
expect: () => [const BallState(characterTheme: DinoTheme())],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
// ignore_for_file: prefer_const_constructors
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_theme/pinball_theme.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('BallState', () {
|
||||||
|
test('supports value equality', () {
|
||||||
|
expect(
|
||||||
|
BallState(characterTheme: DashTheme()),
|
||||||
|
equals(const BallState(characterTheme: DashTheme())),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('constructor', () {
|
||||||
|
test('can be instantiated', () {
|
||||||
|
expect(const BallState(characterTheme: DashTheme()), isNotNull);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 95 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
@ -0,0 +1,141 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:flame/components.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_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_components/src/components/sparky_computer/behaviors/behaviors.dart';
|
||||||
|
|
||||||
|
import '../../../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
class _MockSparkyComputerCubit extends Mock implements SparkyComputerCubit {}
|
||||||
|
|
||||||
|
class _MockBall extends Mock implements Ball {}
|
||||||
|
|
||||||
|
class _MockContact extends Mock implements Contact {}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'SparkyComputerSensorBallContactBehavior',
|
||||||
|
() {
|
||||||
|
test('can be instantiated', () {
|
||||||
|
expect(
|
||||||
|
SparkyComputerSensorBallContactBehavior(),
|
||||||
|
isA<SparkyComputerSensorBallContactBehavior>(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('beginContact', () {
|
||||||
|
flameTester.test(
|
||||||
|
'stops a ball',
|
||||||
|
(game) async {
|
||||||
|
final behavior = SparkyComputerSensorBallContactBehavior();
|
||||||
|
final bloc = _MockSparkyComputerCubit();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
const Stream<SparkyComputerState>.empty(),
|
||||||
|
initialState: SparkyComputerState.withoutBall,
|
||||||
|
);
|
||||||
|
|
||||||
|
final sparkyComputer = SparkyComputer.test(
|
||||||
|
bloc: bloc,
|
||||||
|
);
|
||||||
|
await sparkyComputer.add(behavior);
|
||||||
|
await game.ensureAdd(sparkyComputer);
|
||||||
|
|
||||||
|
final ball = _MockBall();
|
||||||
|
await behavior.beginContact(ball, _MockContact());
|
||||||
|
|
||||||
|
verify(ball.stop).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'emits onBallEntered when contacts with a ball',
|
||||||
|
(game) async {
|
||||||
|
final behavior = SparkyComputerSensorBallContactBehavior();
|
||||||
|
final bloc = _MockSparkyComputerCubit();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
const Stream<SparkyComputerState>.empty(),
|
||||||
|
initialState: SparkyComputerState.withoutBall,
|
||||||
|
);
|
||||||
|
|
||||||
|
final sparkyComputer = SparkyComputer.test(
|
||||||
|
bloc: bloc,
|
||||||
|
);
|
||||||
|
await sparkyComputer.add(behavior);
|
||||||
|
await game.ensureAdd(sparkyComputer);
|
||||||
|
|
||||||
|
await behavior.beginContact(_MockBall(), _MockContact());
|
||||||
|
|
||||||
|
verify(sparkyComputer.bloc.onBallEntered).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'adds TimerComponent when contacts with a ball',
|
||||||
|
(game) async {
|
||||||
|
final behavior = SparkyComputerSensorBallContactBehavior();
|
||||||
|
final bloc = _MockSparkyComputerCubit();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
const Stream<SparkyComputerState>.empty(),
|
||||||
|
initialState: SparkyComputerState.withoutBall,
|
||||||
|
);
|
||||||
|
|
||||||
|
final sparkyComputer = SparkyComputer.test(
|
||||||
|
bloc: bloc,
|
||||||
|
);
|
||||||
|
await sparkyComputer.add(behavior);
|
||||||
|
await game.ensureAdd(sparkyComputer);
|
||||||
|
|
||||||
|
await behavior.beginContact(_MockBall(), _MockContact());
|
||||||
|
await game.ready();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
sparkyComputer.firstChild<TimerComponent>(),
|
||||||
|
isA<TimerComponent>(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'TimerComponent resumes ball and calls onBallTurboCharged onTick',
|
||||||
|
(game) async {
|
||||||
|
final behavior = SparkyComputerSensorBallContactBehavior();
|
||||||
|
final bloc = _MockSparkyComputerCubit();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
const Stream<SparkyComputerState>.empty(),
|
||||||
|
initialState: SparkyComputerState.withoutBall,
|
||||||
|
);
|
||||||
|
|
||||||
|
final sparkyComputer = SparkyComputer.test(
|
||||||
|
bloc: bloc,
|
||||||
|
);
|
||||||
|
await sparkyComputer.add(behavior);
|
||||||
|
await game.ensureAdd(sparkyComputer);
|
||||||
|
|
||||||
|
final ball = _MockBall();
|
||||||
|
await behavior.beginContact(ball, _MockContact());
|
||||||
|
await game.ready();
|
||||||
|
game.update(
|
||||||
|
sparkyComputer.firstChild<TimerComponent>()!.timer.limit,
|
||||||
|
);
|
||||||
|
await game.ready();
|
||||||
|
|
||||||
|
verify(ball.resume).called(1);
|
||||||
|
verify(sparkyComputer.bloc.onBallTurboCharged).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|