From c8782cfbf4bcd7c050dd18b8d18501e5a2191130 Mon Sep 17 00:00:00 2001 From: Erick Date: Thu, 24 Mar 2022 09:17:41 -0300 Subject: [PATCH 1/2] refactor: splitting `Ball` business from UI logic (#86) * feat: refactoring ball component to separate business from ui logic * fix: tests * fix: lint * fix: test coverage * Update lib/game/components/ball.dart Co-authored-by: Alejandro Santiago Co-authored-by: Alejandro Santiago --- .github/workflows/pinball_components.yaml | 2 +- lib/flame/blueprint.dart | 16 +- lib/game/components/ball.dart | 81 +++------ lib/game/components/baseboard.dart | 1 + lib/game/components/board.dart | 1 + lib/game/components/bonus_word.dart | 1 + lib/game/components/components.dart | 2 - lib/game/components/flipper.dart | 1 + lib/game/components/jetpack_ramp.dart | 1 + lib/game/components/joint_anchor.dart | 2 +- lib/game/components/kicker.dart | 1 + lib/game/components/launcher_ramp.dart | 1 + lib/game/components/pathway.dart | 2 +- lib/game/components/plunger.dart | 1 + lib/game/components/ramp_opening.dart | 1 + lib/game/components/round_bumper.dart | 1 + lib/game/components/score_points.dart | 5 +- lib/game/components/spaceship.dart | 3 +- lib/game/components/wall.dart | 3 +- lib/game/game_assets.dart | 3 +- lib/game/pinball_game.dart | 10 +- lib/gen/assets.gen.dart | 2 - .../pinball_components/analysis_options.yaml | 5 +- .../assets/images}/ball.png | Bin .../lib/gen/assets.gen.dart | 68 ++++++++ .../lib/pinball_components.dart | 1 + .../lib/src/components/ball.dart | 72 ++++++++ .../lib/src/components/components.dart | 3 + .../lib/src}/components/initial_position.dart | 0 .../lib/src}/components/layer.dart | 0 .../lib/src/pinball_components.dart | 8 +- packages/pinball_components/pubspec.yaml | 16 +- .../test/helpers/helpers.dart | 1 + .../test/helpers/test_game.dart | 7 + .../test/src/components/ball_test.dart | 162 ++++++++++++++++++ .../components/initial_position_test.dart | 2 +- .../test/src}/components/layer_test.dart | 2 +- .../test/src/pinball_components_test.dart | 11 -- pubspec.lock | 7 + pubspec.yaml | 2 + test/flame/blueprint_test.dart | 16 +- test/game/components/ball_test.dart | 156 +---------------- test/game/components/flipper_test.dart | 4 +- test/game/components/ramp_opening_test.dart | 1 + test/game/components/score_points_test.dart | 13 +- test/game/components/spaceship_test.dart | 1 + test/game/components/wall_test.dart | 9 +- test/game/pinball_game_test.dart | 1 + test/helpers/mocks.dart | 6 + 49 files changed, 441 insertions(+), 274 deletions(-) rename {assets/images/components => packages/pinball_components/assets/images}/ball.png (100%) create mode 100644 packages/pinball_components/lib/gen/assets.gen.dart create mode 100644 packages/pinball_components/lib/src/components/ball.dart create mode 100644 packages/pinball_components/lib/src/components/components.dart rename {lib/game => packages/pinball_components/lib/src}/components/initial_position.dart (100%) rename {lib/game => packages/pinball_components/lib/src}/components/layer.dart (100%) create mode 100644 packages/pinball_components/test/helpers/helpers.dart create mode 100644 packages/pinball_components/test/helpers/test_game.dart create mode 100644 packages/pinball_components/test/src/components/ball_test.dart rename {test/game => packages/pinball_components/test/src}/components/initial_position_test.dart (97%) rename {test/game => packages/pinball_components/test/src}/components/layer_test.dart (98%) delete mode 100644 packages/pinball_components/test/src/pinball_components_test.dart diff --git a/.github/workflows/pinball_components.yaml b/.github/workflows/pinball_components.yaml index cab60a54..bf1907f8 100644 --- a/.github/workflows/pinball_components.yaml +++ b/.github/workflows/pinball_components.yaml @@ -16,4 +16,4 @@ jobs: uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 with: working_directory: packages/pinball_components - coverage_excludes: "lib/src/generated/*.dart" + coverage_excludes: "lib/gen/*.dart" diff --git a/lib/flame/blueprint.dart b/lib/flame/blueprint.dart index 9f2a68f6..d536d650 100644 --- a/lib/flame/blueprint.dart +++ b/lib/flame/blueprint.dart @@ -12,19 +12,19 @@ const _attachedErrorMessage = "Can't add to attached Blueprints"; /// A [Blueprint] is a virtual way of grouping [Component]s /// that are related, but they need to be added directly on /// the [FlameGame] level. -abstract class Blueprint { +abstract class Blueprint { final List _components = []; bool _isAttached = false; /// Called before the the [Component]s managed /// by this blueprint is added to the [FlameGame] - void build(); + void build(T gameRef); /// Attach the [Component]s built on [build] to the [game] /// instance @mustCallSuper - Future attach(FlameGame game) async { - build(); + Future attach(T game) async { + build(game); await game.addAll(_components); _isAttached = true; } @@ -47,7 +47,7 @@ abstract class Blueprint { /// A [Blueprint] that provides additional /// structures specific to flame_forge2d -abstract class Forge2DBlueprint extends Blueprint { +abstract class Forge2DBlueprint extends Blueprint { final List _callbacks = []; /// Adds a single [ContactCallback] to this blueprint @@ -63,13 +63,11 @@ abstract class Forge2DBlueprint extends Blueprint { } @override - Future attach(FlameGame game) async { + Future attach(Forge2DGame game) async { await super.attach(game); - assert(game is Forge2DGame, 'Forge2DBlueprint used outside a Forge2DGame'); - for (final callback in _callbacks) { - (game as Forge2DGame).addContactCallback(callback); + game.addContactCallback(callback); } } diff --git a/lib/game/components/ball.dart b/lib/game/components/ball.dart index def21929..756a8a97 100644 --- a/lib/game/components/ball.dart +++ b/lib/game/components/ball.dart @@ -1,61 +1,40 @@ import 'package:flame/components.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; +import 'package:pinball/flame/blueprint.dart'; import 'package:pinball/game/game.dart'; -import 'package:pinball/gen/assets.gen.dart'; +import 'package:pinball_components/pinball_components.dart'; -/// {@template ball} -/// A solid, [BodyType.dynamic] sphere that rolls and bounces along the -/// [PinballGame]. +/// {@template ball_blueprint} +/// [Blueprint] which cretes a ball game object /// {@endtemplate} -class Ball extends BodyComponent with InitialPosition, Layered { - /// {@macro ball} - Ball() { - // TODO(ruimiguel): while developing Ball can be launched by clicking mouse, - // and default layer is Layer.all. But on final game Ball will be always be - // be launched from Plunger and LauncherRamp will modify it to Layer.board. - // We need to see what happens if Ball appears from other place like nest - // bumper, it will need to explicit change layer to Layer.board then. - layer = Layer.board; - } - - /// The size of the [Ball] - final Vector2 size = Vector2.all(2); +class BallBlueprint extends Blueprint { + /// {@macro ball_blueprint} + BallBlueprint({required this.position}); - @override - Future onLoad() async { - await super.onLoad(); - final sprite = await gameRef.loadSprite(Assets.images.components.ball.path); - final tint = gameRef.theme.characterTheme.ballColor.withOpacity(0.5); - await add( - SpriteComponent( - sprite: sprite, - size: size, - anchor: Anchor.center, - )..tint(tint), - ); - } + /// The initial position of the [Ball] + final Vector2 position; @override - Body createBody() { - final shape = CircleShape()..radius = size.x / 2; - - final fixtureDef = FixtureDef(shape)..density = 1; + void build(PinballGame gameRef) { + final baseColor = gameRef.theme.characterTheme.ballColor; + final ball = Ball(baseColor: baseColor)..add(BallController()); - final bodyDef = BodyDef() - ..position = initialPosition - ..userData = this - ..type = BodyType.dynamic; - - return world.createBody(bodyDef)..createFixture(fixtureDef); + add(ball..initialPosition = position + Vector2(0, ball.size.y / 2)); } +} +/// {@template ball} +/// A solid, [BodyType.dynamic] sphere that rolls and bounces along the +/// [PinballGame]. +/// {@endtemplate} +class BallController extends Component with HasGameRef { /// Removes the [Ball] from a [PinballGame]; spawning a new [Ball] if /// any are left. /// /// Triggered by [BottomWallBallContactCallback] when the [Ball] falls into /// a [BottomWall]. void lost() { - shouldRemove = true; + parent?.shouldRemove = true; final bloc = gameRef.read()..add(const BallLost()); @@ -64,19 +43,13 @@ class Ball extends BodyComponent with InitialPosition, Layered { gameRef.spawnBall(); } } +} - /// Immediatly and completly [stop]s the ball. - /// - /// The [Ball] will no longer be affected by any forces, including it's - /// weight and those emitted from collisions. - void stop() { - body.setType(BodyType.static); - } - - /// Allows the [Ball] to be affected by forces. - /// - /// If previously [stop]ed, the previous ball's velocity is not kept. - void resume() { - body.setType(BodyType.dynamic); +/// Adds helper methods to the [Ball] +extension BallX on Ball { + /// Returns the controller instance of the ball + // TODO(erickzanardo): Remove the need of an extension. + BallController get controller { + return children.whereType().first; } } diff --git a/lib/game/components/baseboard.dart b/lib/game/components/baseboard.dart index 48d38497..60d0ebe7 100644 --- a/lib/game/components/baseboard.dart +++ b/lib/game/components/baseboard.dart @@ -2,6 +2,7 @@ import 'dart:math' as math; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template baseboard} /// Straight, angled board piece to corral the [Ball] towards the [Flipper]s. diff --git a/lib/game/components/board.dart b/lib/game/components/board.dart index efa3f137..6e895d6e 100644 --- a/lib/game/components/board.dart +++ b/lib/game/components/board.dart @@ -1,5 +1,6 @@ import 'package:flame/components.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template board} /// The main flat surface of the [PinballGame], where the [Flipper]s, diff --git a/lib/game/components/bonus_word.dart b/lib/game/components/bonus_word.dart index cc6391e8..d97a9bd1 100644 --- a/lib/game/components/bonus_word.dart +++ b/lib/game/components/bonus_word.dart @@ -8,6 +8,7 @@ import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter/material.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template bonus_word} /// Loads all [BonusLetter]s to compose a [BonusWord]. diff --git a/lib/game/components/components.dart b/lib/game/components/components.dart index a255e652..1ed293da 100644 --- a/lib/game/components/components.dart +++ b/lib/game/components/components.dart @@ -4,12 +4,10 @@ export 'board.dart'; export 'board_side.dart'; export 'bonus_word.dart'; export 'flipper.dart'; -export 'initial_position.dart'; export 'jetpack_ramp.dart'; export 'joint_anchor.dart'; export 'kicker.dart'; export 'launcher_ramp.dart'; -export 'layer.dart'; export 'pathway.dart'; export 'plunger.dart'; export 'ramp_opening.dart'; diff --git a/lib/game/components/flipper.dart b/lib/game/components/flipper.dart index 48913934..6e64c781 100644 --- a/lib/game/components/flipper.dart +++ b/lib/game/components/flipper.dart @@ -6,6 +6,7 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter/services.dart'; import 'package:pinball/game/game.dart'; import 'package:pinball/gen/assets.gen.dart'; +import 'package:pinball_components/pinball_components.dart' hide Assets; const _leftFlipperKeys = [ LogicalKeyboardKey.arrowLeft, diff --git a/lib/game/components/jetpack_ramp.dart b/lib/game/components/jetpack_ramp.dart index 4afc36d1..a69b2111 100644 --- a/lib/game/components/jetpack_ramp.dart +++ b/lib/game/components/jetpack_ramp.dart @@ -4,6 +4,7 @@ import 'package:flame/components.dart'; import 'package:flame/extensions.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template jetpack_ramp} /// Represents the upper left blue ramp of the [Board]. diff --git a/lib/game/components/joint_anchor.dart b/lib/game/components/joint_anchor.dart index e945bd72..98b80ece 100644 --- a/lib/game/components/joint_anchor.dart +++ b/lib/game/components/joint_anchor.dart @@ -1,5 +1,5 @@ import 'package:flame_forge2d/flame_forge2d.dart'; -import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template joint_anchor} /// Non visual [BodyComponent] used to hold a [BodyType.dynamic] in [Joint]s diff --git a/lib/game/components/kicker.dart b/lib/game/components/kicker.dart index e4b2824d..dc55a52f 100644 --- a/lib/game/components/kicker.dart +++ b/lib/game/components/kicker.dart @@ -5,6 +5,7 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter/material.dart'; import 'package:geometry/geometry.dart' as geometry show centroid; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template kicker} /// Triangular [BodyType.static] body that propels the [Ball] towards the diff --git a/lib/game/components/launcher_ramp.dart b/lib/game/components/launcher_ramp.dart index 0b6e4dbf..aae9265f 100644 --- a/lib/game/components/launcher_ramp.dart +++ b/lib/game/components/launcher_ramp.dart @@ -4,6 +4,7 @@ import 'package:flame/components.dart'; import 'package:flame/extensions.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template launcher_ramp} /// The yellow left ramp, where the [Ball] goes through when launched from the diff --git a/lib/game/components/pathway.dart b/lib/game/components/pathway.dart index 819ed5f4..54c81464 100644 --- a/lib/game/components/pathway.dart +++ b/lib/game/components/pathway.dart @@ -2,7 +2,7 @@ import 'package:flame/extensions.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter/material.dart'; import 'package:geometry/geometry.dart'; -import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template pathway} /// [Pathway] creates lines of various shapes. diff --git a/lib/game/components/plunger.dart b/lib/game/components/plunger.dart index 934cd8ac..9791ec66 100644 --- a/lib/game/components/plunger.dart +++ b/lib/game/components/plunger.dart @@ -2,6 +2,7 @@ import 'package:flame/components.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter/services.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template plunger} /// [Plunger] serves as a spring, that shoots the ball on the right side of the diff --git a/lib/game/components/ramp_opening.dart b/lib/game/components/ramp_opening.dart index 2d8454dd..d8ddcc35 100644 --- a/lib/game/components/ramp_opening.dart +++ b/lib/game/components/ramp_opening.dart @@ -2,6 +2,7 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template ramp_orientation} /// Determines if a ramp is facing [up] or [down] on the [Board]. diff --git a/lib/game/components/round_bumper.dart b/lib/game/components/round_bumper.dart index 2f43a35b..969bddbe 100644 --- a/lib/game/components/round_bumper.dart +++ b/lib/game/components/round_bumper.dart @@ -1,5 +1,6 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template round_bumper} /// Circular body that repels a [Ball] on contact, increasing the score. diff --git a/lib/game/components/score_points.dart b/lib/game/components/score_points.dart index 97cea82a..12649137 100644 --- a/lib/game/components/score_points.dart +++ b/lib/game/components/score_points.dart @@ -2,6 +2,7 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template score_points} /// Specifies the amount of points received on [Ball] collision. @@ -26,6 +27,8 @@ class BallScorePointsCallback extends ContactCallback { ScorePoints scorePoints, Contact _, ) { - ball.gameRef.read().add(Scored(points: scorePoints.points)); + ball.controller.gameRef.read().add( + Scored(points: scorePoints.points), + ); } } diff --git a/lib/game/components/spaceship.dart b/lib/game/components/spaceship.dart index 8243a974..847e4ac8 100644 --- a/lib/game/components/spaceship.dart +++ b/lib/game/components/spaceship.dart @@ -8,6 +8,7 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/flame/blueprint.dart'; import 'package:pinball/game/game.dart'; import 'package:pinball/gen/assets.gen.dart'; +import 'package:pinball_components/pinball_components.dart' hide Assets; /// A [Blueprint] which creates the spaceship feature. class Spaceship extends Forge2DBlueprint { @@ -15,7 +16,7 @@ class Spaceship extends Forge2DBlueprint { static const radius = 10.0; @override - void build() { + void build(_) { final position = Vector2( PinballGame.boardBounds.left + radius + 15, PinballGame.boardBounds.center.dy + 30, diff --git a/lib/game/components/wall.dart b/lib/game/components/wall.dart index 7475715e..0fb57a41 100644 --- a/lib/game/components/wall.dart +++ b/lib/game/components/wall.dart @@ -4,6 +4,7 @@ import 'package:flame/extensions.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/game/components/components.dart'; import 'package:pinball/game/pinball_game.dart'; +import 'package:pinball_components/pinball_components.dart'; /// {@template wall} /// A continuous generic and [BodyType.static] barrier that divides a game area. @@ -77,6 +78,6 @@ class BottomWall extends Wall { class BottomWallBallContactCallback extends ContactCallback { @override void begin(Ball ball, BottomWall wall, Contact contact) { - ball.lost(); + ball.controller.lost(); } } diff --git a/lib/game/game_assets.dart b/lib/game/game_assets.dart index d19ef177..fdc1f332 100644 --- a/lib/game/game_assets.dart +++ b/lib/game/game_assets.dart @@ -1,12 +1,13 @@ import 'package:pinball/game/game.dart'; import 'package:pinball/gen/assets.gen.dart'; +import 'package:pinball_components/pinball_components.dart' as components; /// Add methods to help loading and caching game assets. extension PinballGameAssetsX on PinballGame { /// Pre load the initial assets of the game. Future preLoadAssets() async { await Future.wait([ - images.load(Assets.images.components.ball.path), + images.load(components.Assets.images.ball.keyName), images.load(Assets.images.components.flipper.path), images.load(Assets.images.components.spaceship.androidTop.path), images.load(Assets.images.components.spaceship.androidBottom.path), diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 3ce7fd77..681a6431 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -102,11 +102,7 @@ class PinballGame extends Forge2DGame } void spawnBall() { - final ball = Ball(); - add( - ball - ..initialPosition = plunger.body.position + Vector2(0, ball.size.y / 2), - ); + addFromBlueprint(BallBlueprint(position: plunger.body.position)); } } @@ -115,8 +111,6 @@ class DebugPinballGame extends PinballGame with TapDetector { @override void onTapUp(TapUpInfo info) { - add( - Ball()..initialPosition = info.eventPosition.game, - ); + addFromBlueprint(BallBlueprint(position: info.eventPosition.game)); } } diff --git a/lib/gen/assets.gen.dart b/lib/gen/assets.gen.dart index fe4bad8b..ba75412b 100644 --- a/lib/gen/assets.gen.dart +++ b/lib/gen/assets.gen.dart @@ -15,8 +15,6 @@ class $AssetsImagesGen { class $AssetsImagesComponentsGen { const $AssetsImagesComponentsGen(); - AssetGenImage get ball => - const AssetGenImage('assets/images/components/ball.png'); AssetGenImage get flipper => const AssetGenImage('assets/images/components/flipper.png'); AssetGenImage get sauce => diff --git a/packages/pinball_components/analysis_options.yaml b/packages/pinball_components/analysis_options.yaml index 3742fc3d..f8155aa6 100644 --- a/packages/pinball_components/analysis_options.yaml +++ b/packages/pinball_components/analysis_options.yaml @@ -1 +1,4 @@ -include: package:very_good_analysis/analysis_options.2.4.0.yaml \ No newline at end of file +include: package:very_good_analysis/analysis_options.2.4.0.yaml +analyzer: + exclude: + - lib/**/*.gen.dart diff --git a/assets/images/components/ball.png b/packages/pinball_components/assets/images/ball.png similarity index 100% rename from assets/images/components/ball.png rename to packages/pinball_components/assets/images/ball.png diff --git a/packages/pinball_components/lib/gen/assets.gen.dart b/packages/pinball_components/lib/gen/assets.gen.dart new file mode 100644 index 00000000..c4ed6ca0 --- /dev/null +++ b/packages/pinball_components/lib/gen/assets.gen.dart @@ -0,0 +1,68 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +import 'package:flutter/widgets.dart'; + +class $AssetsImagesGen { + const $AssetsImagesGen(); + + AssetGenImage get ball => const AssetGenImage('assets/images/ball.png'); +} + +class Assets { + Assets._(); + + static const $AssetsImagesGen images = $AssetsImagesGen(); +} + +class AssetGenImage extends AssetImage { + const AssetGenImage(String assetName) + : super(assetName, package: 'pinball_components'); + + Image image({ + Key? key, + ImageFrameBuilder? frameBuilder, + ImageLoadingBuilder? loadingBuilder, + ImageErrorWidgetBuilder? errorBuilder, + String? semanticLabel, + bool excludeFromSemantics = false, + double? width, + double? height, + Color? color, + BlendMode? colorBlendMode, + BoxFit? fit, + AlignmentGeometry alignment = Alignment.center, + ImageRepeat repeat = ImageRepeat.noRepeat, + Rect? centerSlice, + bool matchTextDirection = false, + bool gaplessPlayback = false, + bool isAntiAlias = false, + FilterQuality filterQuality = FilterQuality.low, + }) { + return Image( + key: key, + image: this, + frameBuilder: frameBuilder, + loadingBuilder: loadingBuilder, + errorBuilder: errorBuilder, + semanticLabel: semanticLabel, + excludeFromSemantics: excludeFromSemantics, + width: width, + height: height, + color: color, + colorBlendMode: colorBlendMode, + fit: fit, + alignment: alignment, + repeat: repeat, + centerSlice: centerSlice, + matchTextDirection: matchTextDirection, + gaplessPlayback: gaplessPlayback, + isAntiAlias: isAntiAlias, + filterQuality: filterQuality, + ); + } + + String get path => assetName; +} diff --git a/packages/pinball_components/lib/pinball_components.dart b/packages/pinball_components/lib/pinball_components.dart index a08579e5..b00b9d5b 100644 --- a/packages/pinball_components/lib/pinball_components.dart +++ b/packages/pinball_components/lib/pinball_components.dart @@ -1,3 +1,4 @@ library pinball_components; +export 'gen/assets.gen.dart'; export 'src/pinball_components.dart'; diff --git a/packages/pinball_components/lib/src/components/ball.dart b/packages/pinball_components/lib/src/components/ball.dart new file mode 100644 index 00000000..ec51cb47 --- /dev/null +++ b/packages/pinball_components/lib/src/components/ball.dart @@ -0,0 +1,72 @@ +import 'dart:ui'; + +import 'package:flame/components.dart'; +import 'package:flame_forge2d/flame_forge2d.dart'; +import 'package:pinball_components/pinball_components.dart'; + +/// {@template ball} +/// A solid, [BodyType.dynamic] sphere that rolls and bounces around +/// {@endtemplate} +class Ball extends BodyComponent + with Layered, InitialPosition { + /// {@macro ball_body} + Ball({ + required this.baseColor, + }) { + // TODO(ruimiguel): while developing Ball can be launched by clicking mouse, + // and default layer is Layer.all. But on final game Ball will be always be + // be launched from Plunger and LauncherRamp will modify it to Layer.board. + // We need to see what happens if Ball appears from other place like nest + // bumper, it will need to explicit change layer to Layer.board then. + layer = Layer.board; + } + + /// The size of the [Ball] + final Vector2 size = Vector2.all(2); + + /// The base [Color] used to tint this [Ball] + final Color baseColor; + + @override + Future onLoad() async { + await super.onLoad(); + final sprite = await gameRef.loadSprite(Assets.images.ball.keyName); + final tint = baseColor.withOpacity(0.5); + await add( + SpriteComponent( + sprite: sprite, + size: size, + anchor: Anchor.center, + )..tint(tint), + ); + } + + @override + Body createBody() { + final shape = CircleShape()..radius = size.x / 2; + + final fixtureDef = FixtureDef(shape)..density = 1; + + final bodyDef = BodyDef() + ..position = initialPosition + ..userData = this + ..type = BodyType.dynamic; + + return world.createBody(bodyDef)..createFixture(fixtureDef); + } + + /// Immediatly and completly [stop]s the ball. + /// + /// The [Ball] will no longer be affected by any forces, including it's + /// weight and those emitted from collisions. + void stop() { + body.setType(BodyType.static); + } + + /// Allows the [Ball] to be affected by forces. + /// + /// If previously [stop]ed, the previous ball's velocity is not kept. + void resume() { + body.setType(BodyType.dynamic); + } +} diff --git a/packages/pinball_components/lib/src/components/components.dart b/packages/pinball_components/lib/src/components/components.dart new file mode 100644 index 00000000..677bbd0c --- /dev/null +++ b/packages/pinball_components/lib/src/components/components.dart @@ -0,0 +1,3 @@ +export 'ball.dart'; +export 'initial_position.dart'; +export 'layer.dart'; diff --git a/lib/game/components/initial_position.dart b/packages/pinball_components/lib/src/components/initial_position.dart similarity index 100% rename from lib/game/components/initial_position.dart rename to packages/pinball_components/lib/src/components/initial_position.dart diff --git a/lib/game/components/layer.dart b/packages/pinball_components/lib/src/components/layer.dart similarity index 100% rename from lib/game/components/layer.dart rename to packages/pinball_components/lib/src/components/layer.dart diff --git a/packages/pinball_components/lib/src/pinball_components.dart b/packages/pinball_components/lib/src/pinball_components.dart index dbc4d6fd..003c1c49 100644 --- a/packages/pinball_components/lib/src/pinball_components.dart +++ b/packages/pinball_components/lib/src/pinball_components.dart @@ -1,7 +1 @@ -/// {@template pinball_components} -/// Package with the UI game components for the Pinball Game -/// {@endtemplate} -class PinballComponents { - /// {@macro pinball_components} - const PinballComponents(); -} +export 'components/components.dart'; diff --git a/packages/pinball_components/pubspec.yaml b/packages/pinball_components/pubspec.yaml index a3a990a0..56645a30 100644 --- a/packages/pinball_components/pubspec.yaml +++ b/packages/pinball_components/pubspec.yaml @@ -7,10 +7,24 @@ environment: sdk: ">=2.16.0 <3.0.0" dependencies: + flame: ^1.1.0-releasecandidate.6 + flame_forge2d: ^0.9.0-releasecandidate.6 flutter: sdk: flutter dev_dependencies: + flame_test: ^1.1.0 flutter_test: sdk: flutter - very_good_analysis: ^2.4.0 \ No newline at end of file + mocktail: ^0.2.0 + very_good_analysis: ^2.4.0 + +flutter: + generate: true + assets: + - assets/images/ + +flutter_gen: + line_length: 80 + assets: + package_parameter_enabled: true diff --git a/packages/pinball_components/test/helpers/helpers.dart b/packages/pinball_components/test/helpers/helpers.dart new file mode 100644 index 00000000..a8b9f7ff --- /dev/null +++ b/packages/pinball_components/test/helpers/helpers.dart @@ -0,0 +1 @@ +export 'test_game.dart'; diff --git a/packages/pinball_components/test/helpers/test_game.dart b/packages/pinball_components/test/helpers/test_game.dart new file mode 100644 index 00000000..a1219868 --- /dev/null +++ b/packages/pinball_components/test/helpers/test_game.dart @@ -0,0 +1,7 @@ +import 'package:flame_forge2d/flame_forge2d.dart'; + +class TestGame extends Forge2DGame { + TestGame() { + images.prefix = ''; + } +} diff --git a/packages/pinball_components/test/src/components/ball_test.dart b/packages/pinball_components/test/src/components/ball_test.dart new file mode 100644 index 00000000..682f1f73 --- /dev/null +++ b/packages/pinball_components/test/src/components/ball_test.dart @@ -0,0 +1,162 @@ +// ignore_for_file: cascade_invocations + +import 'package:flame_forge2d/flame_forge2d.dart'; +import 'package:flame_test/flame_test.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pinball_components/pinball_components.dart'; + +import '../../helpers/helpers.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + final flameTester = FlameTester(TestGame.new); + + group('Ball', () { + flameTester.test( + 'loads correctly', + (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ready(); + await game.ensureAdd(ball); + + expect(game.contains(ball), isTrue); + }, + ); + + group('body', () { + flameTester.test( + 'is dynamic', + (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + + expect(ball.body.bodyType, equals(BodyType.dynamic)); + }, + ); + + group('can be moved', () { + flameTester.test('by its weight', (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + + game.update(1); + expect(ball.body.position, isNot(equals(ball.initialPosition))); + }); + + flameTester.test('by applying velocity', (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + + ball.body.gravityScale = 0; + ball.body.linearVelocity.setValues(10, 10); + game.update(1); + expect(ball.body.position, isNot(equals(ball.initialPosition))); + }); + }); + }); + + group('fixture', () { + flameTester.test( + 'exists', + (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + + expect(ball.body.fixtures[0], isA()); + }, + ); + + flameTester.test( + 'is dense', + (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + + final fixture = ball.body.fixtures[0]; + expect(fixture.density, greaterThan(0)); + }, + ); + + flameTester.test( + 'shape is circular', + (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + + final fixture = ball.body.fixtures[0]; + expect(fixture.shape.shapeType, equals(ShapeType.circle)); + expect(fixture.shape.radius, equals(1)); + }, + ); + + flameTester.test( + 'has Layer.all as default filter maskBits', + (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ready(); + await game.ensureAdd(ball); + await game.ready(); + + final fixture = ball.body.fixtures[0]; + expect(fixture.filterData.maskBits, equals(Layer.board.maskBits)); + }, + ); + }); + + group('stop', () { + group("can't be moved", () { + flameTester.test('by its weight', (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + ball.stop(); + + game.update(1); + expect(ball.body.position, equals(ball.initialPosition)); + }); + }); + + flameTester.test('by applying velocity', (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + ball.stop(); + + ball.body.linearVelocity.setValues(10, 10); + game.update(1); + expect(ball.body.position, equals(ball.initialPosition)); + }); + }); + + group('resume', () { + group('can move', () { + flameTester.test( + 'by its weight when previously stopped', + (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + ball.stop(); + ball.resume(); + + game.update(1); + expect(ball.body.position, isNot(equals(ball.initialPosition))); + }, + ); + + flameTester.test( + 'by applying velocity when previously stopped', + (game) async { + final ball = Ball(baseColor: Colors.blue); + await game.ensureAdd(ball); + ball.stop(); + ball.resume(); + + ball.body.gravityScale = 0; + ball.body.linearVelocity.setValues(10, 10); + game.update(1); + expect(ball.body.position, isNot(equals(ball.initialPosition))); + }, + ); + }); + }); + }); +} diff --git a/test/game/components/initial_position_test.dart b/packages/pinball_components/test/src/components/initial_position_test.dart similarity index 97% rename from test/game/components/initial_position_test.dart rename to packages/pinball_components/test/src/components/initial_position_test.dart index ece083cc..9f015150 100644 --- a/test/game/components/initial_position_test.dart +++ b/packages/pinball_components/test/src/components/initial_position_test.dart @@ -3,7 +3,7 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; class TestBodyComponent extends BodyComponent with InitialPosition { @override diff --git a/test/game/components/layer_test.dart b/packages/pinball_components/test/src/components/layer_test.dart similarity index 98% rename from test/game/components/layer_test.dart rename to packages/pinball_components/test/src/components/layer_test.dart index 3aacdb49..1eaa9135 100644 --- a/test/game/components/layer_test.dart +++ b/packages/pinball_components/test/src/components/layer_test.dart @@ -4,7 +4,7 @@ import 'dart:math' as math; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; class TestBodyComponent extends BodyComponent with Layered { @override diff --git a/packages/pinball_components/test/src/pinball_components_test.dart b/packages/pinball_components/test/src/pinball_components_test.dart deleted file mode 100644 index 7359ddcb..00000000 --- a/packages/pinball_components/test/src/pinball_components_test.dart +++ /dev/null @@ -1,11 +0,0 @@ -// ignore_for_file: prefer_const_constructors -import 'package:flutter_test/flutter_test.dart'; -import 'package:pinball_components/pinball_components.dart'; - -void main() { - group('PinballComponents', () { - test('can be instantiated', () { - expect(PinballComponents(), isNotNull); - }); - }); -} diff --git a/pubspec.lock b/pubspec.lock index ac5fa36d..067559c4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -392,6 +392,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + pinball_components: + dependency: "direct main" + description: + path: "packages/pinball_components" + relative: true + source: path + version: "1.0.0+1" pinball_theme: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 838dd9ed..1efe9281 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,8 @@ dependencies: intl: ^0.17.0 leaderboard_repository: path: packages/leaderboard_repository + pinball_components: + path: packages/pinball_components pinball_theme: path: packages/pinball_theme diff --git a/test/flame/blueprint_test.dart b/test/flame/blueprint_test.dart index e521a83c..3a9f5ed3 100644 --- a/test/flame/blueprint_test.dart +++ b/test/flame/blueprint_test.dart @@ -1,5 +1,4 @@ import 'package:flame/components.dart'; -import 'package:flame/game.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:pinball/flame/blueprint.dart'; @@ -9,7 +8,7 @@ import '../helpers/helpers.dart'; class MyBlueprint extends Blueprint { @override - void build() { + void build(_) { add(Component()); addAll([Component(), Component()]); } @@ -17,7 +16,7 @@ class MyBlueprint extends Blueprint { class MyForge2dBlueprint extends Forge2DBlueprint { @override - void build() { + void build(_) { addContactCallback(MockContactCallback()); addAllContactCallback([MockContactCallback(), MockContactCallback()]); } @@ -26,7 +25,7 @@ class MyForge2dBlueprint extends Forge2DBlueprint { void main() { group('Blueprint', () { test('components can be added to it', () { - final blueprint = MyBlueprint()..build(); + final blueprint = MyBlueprint()..build(MockPinballGame()); expect(blueprint.components.length, equals(3)); }); @@ -59,7 +58,7 @@ void main() { }); test('callbacks can be added to it', () { - final blueprint = MyForge2dBlueprint()..build(); + final blueprint = MyForge2dBlueprint()..build(MockPinballGame()); expect(blueprint.callbacks.length, equals(3)); }); @@ -92,12 +91,5 @@ void main() { ); }, ); - - test('throws assertion error when used on a non Forge2dGame', () { - expect( - () => MyForge2dBlueprint().attach(FlameGame()), - throwsAssertionError, - ); - }); }); } diff --git a/test/game/components/ball_test.dart b/test/game/components/ball_test.dart index f94c1526..6419eef2 100644 --- a/test/game/components/ball_test.dart +++ b/test/game/components/ball_test.dart @@ -1,110 +1,17 @@ // ignore_for_file: cascade_invocations import 'package:bloc_test/bloc_test.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/game.dart'; +import 'package:pinball_components/pinball_components.dart'; import '../../helpers/helpers.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); - final flameTester = FlameTester(PinballGameTest.create); group('Ball', () { - flameTester.test( - 'loads correctly', - (game) async { - final ball = Ball(); - await game.ready(); - await game.ensureAdd(ball); - - expect(game.contains(ball), isTrue); - }, - ); - - group('body', () { - flameTester.test( - 'is dynamic', - (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - - expect(ball.body.bodyType, equals(BodyType.dynamic)); - }, - ); - - group('can be moved', () { - flameTester.test('by its weight', (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - - game.update(1); - expect(ball.body.position, isNot(equals(ball.initialPosition))); - }); - - flameTester.test('by applying velocity', (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - - ball.body.gravityScale = 0; - ball.body.linearVelocity.setValues(10, 10); - game.update(1); - expect(ball.body.position, isNot(equals(ball.initialPosition))); - }); - }); - }); - - group('fixture', () { - flameTester.test( - 'exists', - (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - - expect(ball.body.fixtures[0], isA()); - }, - ); - - flameTester.test( - 'is dense', - (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - - final fixture = ball.body.fixtures[0]; - expect(fixture.density, greaterThan(0)); - }, - ); - - flameTester.test( - 'shape is circular', - (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - - final fixture = ball.body.fixtures[0]; - expect(fixture.shape.shapeType, equals(ShapeType.circle)); - expect(fixture.shape.radius, equals(1)); - }, - ); - - flameTester.test( - 'has Layer.all as default filter maskBits', - (game) async { - final ball = Ball(); - await game.ready(); - await game.ensureAdd(ball); - await game.ready(); - - final fixture = ball.body.fixtures[0]; - expect(fixture.filterData.maskBits, equals(Layer.board.maskBits)); - }, - ); - }); - group('lost', () { late GameBloc gameBloc; @@ -124,7 +31,7 @@ void main() { (game, tester) async { await game.ready(); - game.children.whereType().first.lost(); + game.children.whereType().first.controller.lost(); await tester.pump(); verify(() => gameBloc.add(const BallLost())).called(1); @@ -136,7 +43,7 @@ void main() { (game, tester) async { await game.ready(); - game.children.whereType().first.lost(); + game.children.whereType().first.controller.lost(); await game.ready(); // Making sure that all additions are done expect( @@ -162,7 +69,7 @@ void main() { ); await game.ready(); - game.children.whereType().first.lost(); + game.children.whereType().first.controller.lost(); await tester.pump(); expect( @@ -172,60 +79,5 @@ void main() { }, ); }); - - group('stop', () { - group("can't be moved", () { - flameTester.test('by its weight', (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - ball.stop(); - - game.update(1); - expect(ball.body.position, equals(ball.initialPosition)); - }); - }); - - flameTester.test('by applying velocity', (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - ball.stop(); - - ball.body.linearVelocity.setValues(10, 10); - game.update(1); - expect(ball.body.position, equals(ball.initialPosition)); - }); - }); - - group('resume', () { - group('can move', () { - flameTester.test( - 'by its weight when previously stopped', - (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - ball.stop(); - ball.resume(); - - game.update(1); - expect(ball.body.position, isNot(equals(ball.initialPosition))); - }, - ); - - flameTester.test( - 'by applying velocity when previously stopped', - (game) async { - final ball = Ball(); - await game.ensureAdd(ball); - ball.stop(); - ball.resume(); - - ball.body.gravityScale = 0; - ball.body.linearVelocity.setValues(10, 10); - game.update(1); - expect(ball.body.position, isNot(equals(ball.initialPosition))); - }, - ); - }); - }); }); } diff --git a/test/game/components/flipper_test.dart b/test/game/components/flipper_test.dart index 3c12e37e..3e6429df 100644 --- a/test/game/components/flipper_test.dart +++ b/test/game/components/flipper_test.dart @@ -4,9 +4,11 @@ import 'dart:collection'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_test/flame_test.dart'; +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; import '../../helpers/helpers.dart'; @@ -81,7 +83,7 @@ void main() { final flipper = Flipper( side: BoardSide.left, ); - final ball = Ball(); + final ball = Ball(baseColor: Colors.white); await game.ready(); await game.ensureAddAll([flipper, ball]); diff --git a/test/game/components/ramp_opening_test.dart b/test/game/components/ramp_opening_test.dart index 1876f8ae..11cf8ddc 100644 --- a/test/game/components/ramp_opening_test.dart +++ b/test/game/components/ramp_opening_test.dart @@ -4,6 +4,7 @@ import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockingjay/mockingjay.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; import '../../helpers/helpers.dart'; diff --git a/test/game/components/score_points_test.dart b/test/game/components/score_points_test.dart index 9a93c078..30ec70db 100644 --- a/test/game/components/score_points_test.dart +++ b/test/game/components/score_points_test.dart @@ -1,9 +1,11 @@ +import 'package:flame/components.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; -class MockBall extends Mock implements Ball {} +import '../../helpers/helpers.dart'; class MockGameBloc extends Mock implements GameBloc {} @@ -28,12 +30,16 @@ void main() { late PinballGame game; late GameBloc bloc; late Ball ball; + late ComponentSet componentSet; + late BallController ballController; late FakeScorePoints fakeScorePoints; setUp(() { game = MockPinballGame(); bloc = MockGameBloc(); ball = MockBall(); + componentSet = MockComponentSet(); + ballController = MockBallController(); fakeScorePoints = FakeScorePoints(); }); @@ -45,7 +51,10 @@ void main() { test( 'emits Scored event with points', () { - when(() => ball.gameRef).thenReturn(game); + when(() => componentSet.whereType()) + .thenReturn([ballController]); + when(() => ball.children).thenReturn(componentSet); + when(() => ballController.gameRef).thenReturn(game); when(game.read).thenReturn(bloc); BallScorePointsCallback().begin( diff --git a/test/game/components/spaceship_test.dart b/test/game/components/spaceship_test.dart index c7eb24b2..52b12609 100644 --- a/test/game/components/spaceship_test.dart +++ b/test/game/components/spaceship_test.dart @@ -2,6 +2,7 @@ import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; import '../../helpers/helpers.dart'; diff --git a/test/game/components/wall_test.dart b/test/game/components/wall_test.dart index 53d387fa..18c7ea5b 100644 --- a/test/game/components/wall_test.dart +++ b/test/game/components/wall_test.dart @@ -17,11 +17,14 @@ void main() { test( 'removes the ball on begin contact when the wall is a bottom one', () { - final game = MockPinballGame(); final wall = MockBottomWall(); + final ballController = MockBallController(); final ball = MockBall(); + final componentSet = MockComponentSet(); - when(() => ball.gameRef).thenReturn(game); + when(() => componentSet.whereType()) + .thenReturn([ballController]); + when(() => ball.children).thenReturn(componentSet); BottomWallBallContactCallback() // Remove once https://github.com/flame-engine/flame/pull/1415 @@ -29,7 +32,7 @@ void main() { ..end(MockBall(), MockBottomWall(), MockContact()) ..begin(ball, wall, MockContact()); - verify(ball.lost).called(1); + verify(ballController.lost).called(1); }, ); }); diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index b9e0ac7d..65732608 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -5,6 +5,7 @@ import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball_components/pinball_components.dart'; import '../helpers/helpers.dart'; diff --git a/test/helpers/mocks.dart b/test/helpers/mocks.dart index 1e6b7289..bd9f82cf 100644 --- a/test/helpers/mocks.dart +++ b/test/helpers/mocks.dart @@ -1,3 +1,4 @@ +import 'package:flame/components.dart'; import 'package:flame/input.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter/foundation.dart'; @@ -6,6 +7,7 @@ import 'package:leaderboard_repository/leaderboard_repository.dart'; import 'package:mocktail/mocktail.dart'; import 'package:pinball/game/game.dart'; import 'package:pinball/theme/theme.dart'; +import 'package:pinball_components/pinball_components.dart'; class MockPinballGame extends Mock implements PinballGame {} @@ -17,6 +19,8 @@ class MockBody extends Mock implements Body {} class MockBall extends Mock implements Ball {} +class MockBallController extends Mock implements BallController {} + class MockContact extends Mock implements Contact {} class MockContactCallback extends Mock @@ -62,3 +66,5 @@ class MockFixture extends Mock implements Fixture {} class MockSpaceshipEntrance extends Mock implements SpaceshipEntrance {} class MockSpaceshipHole extends Mock implements SpaceshipHole {} + +class MockComponentSet extends Mock implements ComponentSet {} From 6caf50edc540bcc93a5d72e7eb086bb0c3936aa6 Mon Sep 17 00:00:00 2001 From: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> Date: Thu, 24 Mar 2022 08:31:21 -0500 Subject: [PATCH 2/2] fix: firestore connection (#91) --- web/__/firebase/8.9.1/firebase-firestore.js | 2 ++ web/index.html | 1 + 2 files changed, 3 insertions(+) create mode 100644 web/__/firebase/8.9.1/firebase-firestore.js diff --git a/web/__/firebase/8.9.1/firebase-firestore.js b/web/__/firebase/8.9.1/firebase-firestore.js new file mode 100644 index 00000000..b3968b7d --- /dev/null +++ b/web/__/firebase/8.9.1/firebase-firestore.js @@ -0,0 +1,2 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("@firebase/app")):"function"==typeof define&&define.amd?define(["@firebase/app"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).firebase)}(this,function(mm){"use strict";try{!function(){function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var e=t(mm),r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,r=arguments.length;ns[0]&&e[1]>6,c=63&c;u||(c=64,s||(h=64)),r.push(n[o>>2],n[(3&o)<<4|a>>4],n[h],n[c])}return r.join("")},encodeString:function(t,e){return this.HAS_NATIVE_SUPPORT&&!e?btoa(t):this.encodeByteArray(function(t){for(var e=[],n=0,r=0;r>6|192:(55296==(64512&i)&&r+1>18|240,e[n++]=i>>12&63|128):e[n++]=i>>12|224,e[n++]=i>>6&63|128),e[n++]=63&i|128)}return e}(t),e)},decodeString:function(t,e){return this.HAS_NATIVE_SUPPORT&&!e?atob(t):function(t){for(var e=[],n=0,r=0;n>10)),e[r++]=String.fromCharCode(56320+(1023&i))):(o=t[n++],s=t[n++],e[r++]=String.fromCharCode((15&a)<<12|(63&o)<<6|63&s))}return e.join("")}(this.decodeStringToByteArray(t,e))},decodeStringToByteArray:function(t,e){this.init_();for(var n=e?this.charToByteMapWebSafe_:this.charToByteMap_,r=[],i=0;i>4),64!==a&&(r.push(s<<4&240|a>>2),64!==u&&r.push(a<<6&192|u))}return r},init_:function(){if(!this.byteToCharMap_){this.byteToCharMap_={},this.charToByteMap_={},this.byteToCharMapWebSafe_={},this.charToByteMapWebSafe_={};for(var t=0;t=this.ENCODED_VALS_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(t)]=t,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(t)]=t)}}};function h(){return"undefined"!=typeof navigator&&"string"==typeof navigator.userAgent?navigator.userAgent:""}function i(){return!function(){try{return"[object process]"===Object.prototype.toString.call(global.process)}catch(t){return}}()&&navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")}var u,c="FirebaseError",l=(n(f,u=Error),f);function f(t,e,n){e=u.call(this,e)||this;return e.code=t,e.customData=n,e.name=c,Object.setPrototypeOf(e,f.prototype),Error.captureStackTrace&&Error.captureStackTrace(e,d.prototype.create),e}var d=(p.prototype.create=function(t){for(var e=[],n=1;n"})):"Error",t=this.serviceName+": "+t+" ("+o+").";return new l(o,t,i)},p);function p(t,e,n){this.service=t,this.serviceName=e,this.errors=n}var m,v=/\{\$([^}]+)}/g;function w(t){return t&&t._delegate?t._delegate:t}(N=m=m||{})[N.DEBUG=0]="DEBUG",N[N.VERBOSE=1]="VERBOSE",N[N.INFO=2]="INFO",N[N.WARN=3]="WARN",N[N.ERROR=4]="ERROR",N[N.SILENT=5]="SILENT";function b(t,e){for(var n=[],r=2;r=t.length?void 0:t)&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}var N,C="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},k={},R=C||self;function x(){}function O(t){var e=typeof t;return"array"==(e="object"!=e?e:t?Array.isArray(t)?"array":e:"null")||"object"==e&&"number"==typeof t.length}function L(t){var e=typeof t;return"object"==e&&null!=t||"function"==e}var P="closure_uid_"+(1e9*Math.random()>>>0),M=0;function F(t,e,n){return t.call.apply(t.bind,arguments)}function V(e,n,t){if(!e)throw Error();if(2parseFloat(dt)){ot=String(pt);break t}}ot=dt}var yt={};function gt(){return t=function(){for(var t=0,e=X(String(ot)).split("."),n=X("9").split("."),r=Math.max(e.length,n.length),i=0;0==t&&i>>0);function Vt(e){return"function"==typeof e?e:(e[Ft]||(e[Ft]=function(t){return e.handleEvent(t)}),e[Ft])}function Ut(){j.call(this),this.i=new At(this),(this.P=this).I=null}function qt(t,e){var n,r=t.I;if(r)for(n=[];r;r=r.I)n.push(r);if(t=t.P,r=e.type||e,"string"==typeof e?e=new wt(e,t):e instanceof wt?e.target=e.target||t:(s=e,rt(e=new wt(r,t),s)),s=!0,n)for(var i=n.length-1;0<=i;i--)var o=e.g=n[i],s=Bt(o,r,!0,e)&&s;if(s=Bt(o=e.g=t,r,!0,e)&&s,s=Bt(o,r,!1,e)&&s,n)for(i=0;io.length?Oe:(o=o.substr(a,s),i.C=a+s,o)))==Oe){4==e&&(t.o=4,ve(14),u=!1),le(t.j,t.m,null,"[Incomplete Response]");break}if(r==xe){t.o=4,ve(15),le(t.j,t.m,n,"[Invalid Chunk]"),u=!1;break}le(t.j,t.m,r,null),Ke(t,r)}Me(t)&&r!=Oe&&r!=xe&&(t.h.g="",t.C=0),4!=e||0!=n.length||t.h.h||(t.o=1,ve(16),u=!1),t.i=t.i&&u,u?0>4&15).toString(16)+(15&t).toString(16)}Ye.prototype.toString=function(){var t=[],e=this.j;e&&t.push(on(e,an,!0),":");var n=this.i;return!n&&"file"!=e||(t.push("//"),(e=this.s)&&t.push(on(e,an,!0),"@"),t.push(encodeURIComponent(String(n)).replace(/%25([0-9a-fA-F]{2})/g,"%$1")),null!=(n=this.m)&&t.push(":",String(n))),(n=this.l)&&(this.i&&"/"!=n.charAt(0)&&t.push("/"),t.push(on(n,"/"==n.charAt(0)?cn:un,!0))),(n=this.h.toString())&&t.push("?",n),(n=this.o)&&t.push("#",on(n,ln)),t.join("")};var an=/[#\/\?@]/g,un=/[#\?:]/g,cn=/[#\?]/g,hn=/[#\?@]/g,ln=/#/g;function fn(t,e){this.h=this.g=null,this.i=t||null,this.j=!!e}function dn(n){n.g||(n.g=new Qe,n.h=0,n.i&&function(t,e){if(t){t=t.split("&");for(var n=0;n2*t.i&&He(t)))}function yn(t,e){return dn(t),e=mn(t,e),ze(t.g.h,e)}function gn(t,e,n){pn(t,e),0=t.j}function In(t){return t.h?1:t.g?t.g.size:0}function _n(t,e){return t.h?t.h==e:t.g&&t.g.has(e)}function Sn(t,e){t.g?t.g.add(e):t.h=e}function An(t,e){t.h&&t.h==e?t.h=null:t.g&&t.g.has(e)&&t.g.delete(e)}function Dn(t){var e,n;if(null!=t.h)return t.i.concat(t.h.D);if(null==t.g||0===t.g.size)return z(t.i);var r=t.i;try{for(var i=D(t.g.values()),o=i.next();!o.done;o=i.next())var s=o.value,r=r.concat(s.D)}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r}function Nn(){}function Cn(){this.g=new Nn}function kn(t,e,n,r,i){try{e.onload=null,e.onerror=null,e.onabort=null,e.ontimeout=null,i(r)}catch(t){}}function Rn(t){this.l=t.$b||null,this.j=t.ib||!1}function xn(t,e){Ut.call(this),this.D=t,this.u=e,this.m=void 0,this.readyState=On,this.status=0,this.responseType=this.responseText=this.response=this.statusText="",this.onreadystatechange=null,this.v=new Headers,this.h=null,this.C="GET",this.B="",this.g=!1,this.A=this.j=this.l=null}wn.prototype.cancel=function(){var e,t;if(this.i=Dn(this),this.h)this.h.cancel(),this.h=null;else if(this.g&&0!==this.g.size){try{for(var n=D(this.g.values()),r=n.next();!r.done;r=n.next())r.value.cancel()}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}this.g.clear()}},Nn.prototype.stringify=function(t){return R.JSON.stringify(t,void 0)},Nn.prototype.parse=function(t){return R.JSON.parse(t,void 0)},B(Rn,Te),Rn.prototype.g=function(){return new xn(this.l,this.j)},Rn.prototype.i=(bn={},function(){return bn}),B(xn,Ut);var On=0;function Ln(t){t.j.read().then(t.Sa.bind(t)).catch(t.ha.bind(t))}function Pn(t){t.readyState=4,t.l=null,t.j=null,t.A=null,Mn(t)}function Mn(t){t.onreadystatechange&&t.onreadystatechange.call(t)}(N=xn.prototype).open=function(t,e){if(this.readyState!=On)throw this.abort(),Error("Error reopening a connection");this.C=t,this.B=e,this.readyState=1,Mn(this)},N.send=function(t){if(1!=this.readyState)throw this.abort(),Error("need to call open() first. ");this.g=!0;var e={headers:this.v,method:this.C,credentials:this.m,cache:void 0};t&&(e.body=t),(this.D||R).fetch(new Request(this.B,e)).then(this.Va.bind(this),this.ha.bind(this))},N.abort=function(){this.response=this.responseText="",this.v=new Headers,this.status=0,this.j&&this.j.cancel("Request was aborted."),1<=this.readyState&&this.g&&4!=this.readyState&&(this.g=!1,Pn(this)),this.readyState=On},N.Va=function(t){if(this.g&&(this.l=t,this.h||(this.status=this.l.status,this.statusText=this.l.statusText,this.h=t.headers,this.readyState=2,Mn(this)),this.g&&(this.readyState=3,Mn(this),this.g)))if("arraybuffer"===this.responseType)t.arrayBuffer().then(this.Ta.bind(this),this.ha.bind(this));else if(void 0!==R.ReadableStream&&"body"in t){if(this.j=t.body.getReader(),this.u){if(this.responseType)throw Error('responseType must be empty for "streamBinaryChunks" mode responses.');this.response=[]}else this.response=this.responseText="",this.A=new TextDecoder;Ln(this)}else t.text().then(this.Ua.bind(this),this.ha.bind(this))},N.Sa=function(t){var e;this.g&&(this.u&&t.value?this.response.push(t.value):this.u||(e=t.value||new Uint8Array(0),(e=this.A.decode(e,{stream:!t.done}))&&(this.response=this.responseText+=e)),(t.done?Pn:Mn)(this),3==this.readyState&&Ln(this))},N.Ua=function(t){this.g&&(this.response=this.responseText=t,Pn(this))},N.Ta=function(t){this.g&&(this.response=t,Pn(this))},N.ha=function(){this.g&&Pn(this)},N.setRequestHeader=function(t,e){this.v.append(t,e)},N.getResponseHeader=function(t){return this.h&&this.h.get(t.toLowerCase())||""},N.getAllResponseHeaders=function(){if(!this.h)return"";for(var t=[],e=this.h.entries(),n=e.next();!n.done;)n=n.value,t.push(n[0]+": "+n[1]),n=e.next();return t.join("\r\n")},Object.defineProperty(xn.prototype,"withCredentials",{get:function(){return"include"===this.m},set:function(t){this.m=t?"include":"same-origin"}});var Fn=R.JSON.parse;function Vn(t){Ut.call(this),this.headers=new Qe,this.u=t||null,this.h=!1,this.C=this.g=null,this.H="",this.m=0,this.j="",this.l=this.F=this.v=this.D=!1,this.B=0,this.A=null,this.J=Un,this.K=this.L=!1}B(Vn,Ut);var Un="",qn=/^https?$/i,Bn=["POST","PUT"];function jn(t){return"content-type"==t.toLowerCase()}function Kn(t,e){t.h=!1,t.g&&(t.l=!0,t.g.abort(),t.l=!1),t.j=e,t.m=5,Gn(t),Hn(t)}function Gn(t){t.D||(t.D=!0,qt(t,"complete"),qt(t,"error"))}function Qn(t){if(t.h&&void 0!==k&&(!t.C[1]||4!=Wn(t)||2!=t.ba()))if(t.v&&4==Wn(t))ne(t.Fa,0,t);else if(qt(t,"readystatechange"),4==Wn(t)){t.h=!1;try{var e,n,r,i,o=t.ba();t:switch(o){case 200:case 201:case 202:case 204:case 206:case 304:case 1223:var s=!0;break t;default:s=!1}if((e=s)||((n=0===o)&&(!(i=String(t.H).match(We)[1]||null)&&R.self&&R.self.location&&(i=(r=R.self.location.protocol).substr(0,r.length-1)),n=!qn.test(i?i.toLowerCase():"")),e=n),e)qt(t,"complete"),qt(t,"success");else{t.m=6;try{var a=2=r.i.j-(r.m?1:0)||(r.m?(r.l=i.D.concat(r.l),0):1==r.G||2==r.G||r.C>=(r.Xa?0:r.Ya)||(r.m=be(U(r.Ha,r,i),dr(r,r.C)),r.C++,0))))&&(2!=s||!ur(t)))switch(o&&0e.length?1:0},gi),ai=(n(yi,si=C),yi.prototype.construct=function(t,e,n){return new yi(t,e,n)},yi.prototype.canonicalString=function(){return this.toArray().join("/")},yi.prototype.toString=function(){return this.canonicalString()},yi.fromString=function(){for(var t=[],e=0;et.length&&Qr(),void 0===n?n=t.length-e:n>t.length-e&&Qr(),this.segments=t,this.offset=e,this.len=n}li.EMPTY_BYTE_STRING=new li("");var mi=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function vi(t){if(Hr(!!t),"string"!=typeof t)return{seconds:wi(t.seconds),nanos:wi(t.nanos)};var e=0,n=mi.exec(t);Hr(!!n),n[1]&&(n=((n=n[1])+"000000000").substr(0,9),e=Number(n));t=new Date(t);return{seconds:Math.floor(t.getTime()/1e3),nanos:e}}function wi(t){return"number"==typeof t?t:"string"==typeof t?Number(t):0}function bi(t){return"string"==typeof t?li.fromBase64String(t):li.fromUint8Array(t)}function Ei(t){return"server_timestamp"===(null===(t=((null===(t=null==t?void 0:t.mapValue)||void 0===t?void 0:t.fields)||{}).__type__)||void 0===t?void 0:t.stringValue)}function Ti(t){t=vi(t.mapValue.fields.__local_write_time__.timestampValue);return new Jr(t.seconds,t.nanos)}function Ii(t){return null==t}function _i(t){return 0===t&&1/t==-1/0}function Si(t){return"number"==typeof t&&Number.isInteger(t)&&!_i(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}var Ai=(Di.fromPath=function(t){return new Di(ai.fromString(t))},Di.fromName=function(t){return new Di(ai.fromString(t).popFirst(5))},Di.prototype.hasCollectionId=function(t){return 2<=this.path.length&&this.path.get(this.path.length-2)===t},Di.prototype.isEqual=function(t){return null!==t&&0===ai.comparator(this.path,t.path)},Di.prototype.toString=function(){return this.path.toString()},Di.comparator=function(t,e){return ai.comparator(t.path,e.path)},Di.isDocumentKey=function(t){return t.length%2==0},Di.fromSegments=function(t){return new Di(new ai(t.slice()))},Di);function Di(t){this.path=t}function Ni(t){return"nullValue"in t?0:"booleanValue"in t?1:"integerValue"in t||"doubleValue"in t?2:"timestampValue"in t?3:"stringValue"in t?5:"bytesValue"in t?6:"referenceValue"in t?7:"geoPointValue"in t?8:"arrayValue"in t?9:"mapValue"in t?Ei(t)?4:10:Qr()}function Ci(r,i){var t,e,n=Ni(r);if(n!==Ni(i))return!1;switch(n){case 0:return!0;case 1:return r.booleanValue===i.booleanValue;case 4:return Ti(r).isEqual(Ti(i));case 3:return function(t){if("string"==typeof r.timestampValue&&"string"==typeof t.timestampValue&&r.timestampValue.length===t.timestampValue.length)return r.timestampValue===t.timestampValue;var e=vi(r.timestampValue),t=vi(t.timestampValue);return e.seconds===t.seconds&&e.nanos===t.nanos}(i);case 5:return r.stringValue===i.stringValue;case 6:return e=i,bi(r.bytesValue).isEqual(bi(e.bytesValue));case 7:return r.referenceValue===i.referenceValue;case 8:return t=i,wi((e=r).geoPointValue.latitude)===wi(t.geoPointValue.latitude)&&wi(e.geoPointValue.longitude)===wi(t.geoPointValue.longitude);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return wi(t.integerValue)===wi(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){t=wi(t.doubleValue),e=wi(e.doubleValue);return t===e?_i(t)===_i(e):isNaN(t)&&isNaN(e)}return!1}(r,i);case 9:return Xr(r.arrayValue.values||[],i.arrayValue.values||[],Ci);case 10:return function(){var t,e=r.mapValue.fields||{},n=i.mapValue.fields||{};if(ni(e)!==ni(n))return!1;for(t in e)if(e.hasOwnProperty(t)&&(void 0===n[t]||!Ci(e[t],n[t])))return!1;return!0}();default:return Qr()}}function ki(t,e){return void 0!==(t.values||[]).find(function(t){return Ci(t,e)})}function Ri(t,e){var n,r,i,o=Ni(t),s=Ni(e);if(o!==s)return Yr(o,s);switch(o){case 0:return 0;case 1:return Yr(t.booleanValue,e.booleanValue);case 2:return r=e,i=wi(t.integerValue||t.doubleValue),r=wi(r.integerValue||r.doubleValue),i":return 0=":return 0<=t;default:return Qr()}},Ji.prototype.g=function(){return 0<=["<","<=",">",">=","!=","not-in"].indexOf(this.op)},Ji);function Ji(t,e,n){var r=this;return(r=Xi.call(this)||this).field=t,r.op=e,r.value=n,r}var Zi,to,eo,no=(n(ao,eo=$i),ao.prototype.matches=function(t){t=Ai.comparator(t.key,this.key);return this.m(t)},ao),ro=(n(so,to=$i),so.prototype.matches=function(e){return this.keys.some(function(t){return t.isEqual(e.key)})},so),io=(n(oo,Zi=$i),oo.prototype.matches=function(e){return!this.keys.some(function(t){return t.isEqual(e.key)})},oo);function oo(t,e){var n=this;return(n=Zi.call(this,t,"not-in",e)||this).keys=uo(0,e),n}function so(t,e){var n=this;return(n=to.call(this,t,"in",e)||this).keys=uo(0,e),n}function ao(t,e,n){var r=this;return(r=eo.call(this,t,e,n)||this).key=Ai.fromName(n.referenceValue),r}function uo(t,e){return((null===(e=e.arrayValue)||void 0===e?void 0:e.values)||[]).map(function(t){return Ai.fromName(t.referenceValue)})}var co,ho,lo,fo,po=(n(To,fo=$i),To.prototype.matches=function(t){t=t.data.field(this.field);return Mi(t)&&ki(t.arrayValue,this.value)},To),yo=(n(Eo,lo=$i),Eo.prototype.matches=function(t){t=t.data.field(this.field);return null!==t&&ki(this.value.arrayValue,t)},Eo),go=(n(bo,ho=$i),bo.prototype.matches=function(t){if(ki(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;t=t.data.field(this.field);return null!==t&&!ki(this.value.arrayValue,t)},bo),mo=(n(wo,co=$i),wo.prototype.matches=function(t){var e=this,t=t.data.field(this.field);return!(!Mi(t)||!t.arrayValue.values)&&t.arrayValue.values.some(function(t){return ki(e.value.arrayValue,t)})},wo),vo=function(t,e){this.position=t,this.before=e};function wo(t,e){return co.call(this,t,"array-contains-any",e)||this}function bo(t,e){return ho.call(this,t,"not-in",e)||this}function Eo(t,e){return lo.call(this,t,"in",e)||this}function To(t,e){return fo.call(this,t,"array-contains",e)||this}function Io(t){return(t.before?"b":"a")+":"+t.position.map(Oi).join(",")}var _o=function(t,e){void 0===e&&(e="asc"),this.field=t,this.dir=e};function So(t,e,n){for(var r=0,i=0;i":"GREATER_THAN",">=":"GREATER_THAN_OR_EQUAL","==":"EQUAL","!=":"NOT_EQUAL","array-contains":"ARRAY_CONTAINS",in:"IN","not-in":"NOT_IN","array-contains-any":"ARRAY_CONTAINS_ANY"},pa=function(t,e){this.databaseId=t,this.I=e};function ya(t,e){return t.I?new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")+"."+("000000000"+e.nanoseconds).slice(-9)+"Z":{seconds:""+e.seconds,nanos:e.nanoseconds}}function ga(t,e){return t.I?e.toBase64():e.toUint8Array()}function ma(t){return Hr(!!t),Zr.fromTimestamp((t=vi(t),new Jr(t.seconds,t.nanos)))}function va(t,e){return new ai(["projects",t.projectId,"databases",t.database]).child("documents").child(e).canonicalString()}function wa(t){t=ai.fromString(t);return Hr(Ua(t)),t}function ba(t,e){return va(t.databaseId,e.path)}function Ea(t,e){e=wa(e);if(e.get(1)!==t.databaseId.projectId)throw new Fr(Mr.INVALID_ARGUMENT,"Tried to deserialize key from different project: "+e.get(1)+" vs "+t.databaseId.projectId);if(e.get(3)!==t.databaseId.database)throw new Fr(Mr.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+e.get(3)+" vs "+t.databaseId.database);return new Ai(Sa(e))}function Ta(t,e){return va(t.databaseId,e)}function Ia(t){t=wa(t);return 4===t.length?ai.emptyPath():Sa(t)}function _a(t){return new ai(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function Sa(t){return Hr(4";case"GREATER_THAN_OR_EQUAL":return">=";case"LESS_THAN":return"<";case"LESS_THAN_OR_EQUAL":return"<=";case"ARRAY_CONTAINS":return"array-contains";case"IN":return"in";case"NOT_IN":return"not-in";case"ARRAY_CONTAINS_ANY":return"array-contains-any";case"OPERATOR_UNSPECIFIED":default:return Qr()}}(),t.fieldFilter.value)}function Va(t){switch(t.unaryFilter.op){case"IS_NAN":var e=Ma(t.unaryFilter.field);return $i.create(e,"==",{doubleValue:NaN});case"IS_NULL":e=Ma(t.unaryFilter.field);return $i.create(e,"==",{nullValue:"NULL_VALUE"});case"IS_NOT_NAN":var n=Ma(t.unaryFilter.field);return $i.create(n,"!=",{doubleValue:NaN});case"IS_NOT_NULL":n=Ma(t.unaryFilter.field);return $i.create(n,"!=",{nullValue:"NULL_VALUE"});case"OPERATOR_UNSPECIFIED":default:return Qr()}}function Ua(t){return 4<=t.length&&"projects"===t.get(0)&&"databases"===t.get(2)}function qa(t){for(var e="",n=0;n",t),this.store.put(t));return _u(t)},Iu.prototype.add=function(t){return Br("SimpleDb","ADD",this.store.name,t,t),_u(this.store.add(t))},Iu.prototype.get=function(e){var n=this;return _u(this.store.get(e)).next(function(t){return Br("SimpleDb","GET",n.store.name,e,t=void 0===t?null:t),t})},Iu.prototype.delete=function(t){return Br("SimpleDb","DELETE",this.store.name,t),_u(this.store.delete(t))},Iu.prototype.count=function(){return Br("SimpleDb","COUNT",this.store.name),_u(this.store.count())},Iu.prototype.Nt=function(t,e){var e=this.cursor(this.options(t,e)),n=[];return this.xt(e,function(t,e){n.push(e)}).next(function(){return n})},Iu.prototype.Ft=function(t,e){Br("SimpleDb","DELETE ALL",this.store.name);e=this.options(t,e);e.kt=!1;e=this.cursor(e);return this.xt(e,function(t,e,n){return n.delete()})},Iu.prototype.$t=function(t,e){e?n=t:(n={},e=t);var n=this.cursor(n);return this.xt(n,e)},Iu.prototype.Ot=function(r){var t=this.cursor({});return new hu(function(n,e){t.onerror=function(t){t=Au(t.target.error);e(t)},t.onsuccess=function(t){var e=t.target.result;e?r(e.primaryKey,e.value).next(function(t){t?e.continue():n()}):n()}})},Iu.prototype.xt=function(t,i){var o=[];return new hu(function(r,e){t.onerror=function(t){e(t.target.error)},t.onsuccess=function(t){var e,n=t.target.result;n?(e=new du(n),(t=i(n.primaryKey,n.value,e))instanceof hu&&(t=t.catch(function(t){return e.done(),hu.reject(t)}),o.push(t)),e.isDone?r():null===e.Dt?n.continue():n.continue(e.Dt)):r()}}).next(function(){return hu.waitFor(o)})},Iu.prototype.options=function(t,e){var n;return void 0!==t&&("string"==typeof t?n=t:e=t),{index:n,range:e}},Iu.prototype.cursor=function(t){var e="next";if(t.reverse&&(e="prev"),t.index){var n=this.store.index(t.index);return t.kt?n.openKeyCursor(t.range,e):n.openCursor(t.range,e)}return this.store.openCursor(t.range,e)},Iu);function Iu(t){this.store=t}function _u(t){return new hu(function(e,n){t.onsuccess=function(t){t=t.target.result;e(t)},t.onerror=function(t){t=Au(t.target.error);n(t)}})}var Su=!1;function Au(t){var e=fu._t(h());if(12.2<=e&&e<13){e="An internal error was encountered in the Indexed Database server";if(0<=t.message.indexOf(e)){var n=new Fr("internal","IOS_INDEXEDDB_BUG1: IndexedDb has thrown '"+e+"'. This is likely due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.");return Su||(Su=!0,setTimeout(function(){throw n},0)),n}}return t}var Du,Nu=(n(Cu,Du=C),Cu);function Cu(t,e){var n=this;return(n=Du.call(this)||this).Mt=t,n.currentSequenceNumber=e,n}function ku(t,e){return fu.It(t.Mt,e)}var Ru=(Fu.prototype.applyToRemoteDocument=function(t,e){for(var n,r,i,o,s,a,u=e.mutationResults,c=0;c=i),o=Gu(r.R,e)),n.done()}).next(function(){return o})},lc.prototype.getHighestUnacknowledgedBatchId=function(t){var e=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]),r=-1;return dc(t).$t({index:Ha.userMutationsIndex,range:e,reverse:!0},function(t,e,n){r=e.batchId,n.done()}).next(function(){return r})},lc.prototype.getAllMutationBatches=function(t){var e=this,n=IDBKeyRange.bound([this.userId,-1],[this.userId,Number.POSITIVE_INFINITY]);return dc(t).Nt(Ha.userMutationsIndex,n).next(function(t){return t.map(function(t){return Gu(e.R,t)})})},lc.prototype.getAllMutationBatchesAffectingDocumentKey=function(o,s){var a=this,t=za.prefixForPath(this.userId,s.path),t=IDBKeyRange.lowerBound(t),u=[];return pc(o).$t({range:t},function(t,e,n){var r=t[0],i=t[1],t=t[2],i=ja(i);if(r===a.userId&&s.path.isEqual(i))return dc(o).get(t).next(function(t){if(!t)throw Qr();Hr(t.userId===a.userId),u.push(Gu(a.R,t))});n.done()}).next(function(){return u})},lc.prototype.getAllMutationBatchesAffectingDocumentKeys=function(e,t){var s=this,a=new Ks(Yr),n=[];return t.forEach(function(o){var t=za.prefixForPath(s.userId,o.path),t=IDBKeyRange.lowerBound(t),t=pc(e).$t({range:t},function(t,e,n){var r=t[0],i=t[1],t=t[2],i=ja(i);r===s.userId&&o.path.isEqual(i)?a=a.add(t):n.done()});n.push(t)}),hu.waitFor(n).next(function(){return s.Wt(e,a)})},lc.prototype.getAllMutationBatchesAffectingQuery=function(t,e){var o=this,s=e.path,a=s.length+1,e=za.prefixForPath(this.userId,s),e=IDBKeyRange.lowerBound(e),u=new Ks(Yr);return pc(t).$t({range:e},function(t,e,n){var r=t[0],i=t[1],t=t[2],i=ja(i);r===o.userId&&s.isPrefixOf(i)?i.length===a&&(u=u.add(t)):n.done()}).next(function(){return o.Wt(t,u)})},lc.prototype.Wt=function(e,t){var n=this,r=[],i=[];return t.forEach(function(t){i.push(dc(e).get(t).next(function(t){if(null===t)throw Qr();Hr(t.userId===n.userId),r.push(Gu(n.R,t))}))}),hu.waitFor(i).next(function(){return r})},lc.prototype.removeMutationBatch=function(e,n){var r=this;return uc(e.Mt,this.userId,n).next(function(t){return e.addOnCommittedListener(function(){r.Gt(n.batchId)}),hu.forEach(t,function(t){return r.referenceDelegate.markPotentiallyOrphaned(e,t)})})},lc.prototype.Gt=function(t){delete this.Kt[t]},lc.prototype.performConsistencyCheck=function(e){var i=this;return this.checkEmpty(e).next(function(t){if(!t)return hu.resolve();var t=IDBKeyRange.lowerBound(za.prefixForUser(i.userId)),r=[];return pc(e).$t({range:t},function(t,e,n){t[0]===i.userId?(t=ja(t[1]),r.push(t)):n.done()}).next(function(){Hr(0===r.length)})})},lc.prototype.containsKey=function(t,e){return fc(t,this.userId,e)},lc.prototype.zt=function(t){var e=this;return yc(t).get(this.userId).next(function(t){return t||new Qa(e.userId,-1,"")})},lc);function lc(t,e,n,r){this.userId=t,this.R=e,this.Ut=n,this.referenceDelegate=r,this.Kt={}}function fc(t,o,e){var e=za.prefixForPath(o,e.path),s=e[1],e=IDBKeyRange.lowerBound(e),a=!1;return pc(t).$t({range:e,kt:!0},function(t,e,n){var r=t[0],i=t[1];t[2],r===o&&i===s&&(a=!0),n.done()}).next(function(){return a})}function dc(t){return ku(t,Ha.store)}function pc(t){return ku(t,za.store)}function yc(t){return ku(t,Qa.store)}var gc=(wc.prototype.next=function(){return this.Ht+=2,this.Ht},wc.Jt=function(){return new wc(0)},wc.Yt=function(){return new wc(-1)},wc),mc=(vc.prototype.allocateTargetId=function(n){var r=this;return this.Xt(n).next(function(t){var e=new gc(t.highestTargetId);return t.highestTargetId=e.next(),r.Zt(n,t).next(function(){return t.highestTargetId})})},vc.prototype.getLastRemoteSnapshotVersion=function(t){return this.Xt(t).next(function(t){return Zr.fromTimestamp(new Jr(t.lastRemoteSnapshotVersion.seconds,t.lastRemoteSnapshotVersion.nanoseconds))})},vc.prototype.getHighestSequenceNumber=function(t){return this.Xt(t).next(function(t){return t.highestListenSequenceNumber})},vc.prototype.setTargetsMetadata=function(e,n,r){var i=this;return this.Xt(e).next(function(t){return t.highestListenSequenceNumber=n,r&&(t.lastRemoteSnapshotVersion=r.toTimestamp()),n>t.highestListenSequenceNumber&&(t.highestListenSequenceNumber=n),i.Zt(e,t)})},vc.prototype.addTargetData=function(e,n){var r=this;return this.te(e,n).next(function(){return r.Xt(e).next(function(t){return t.targetCount+=1,r.ee(n,t),r.Zt(e,t)})})},vc.prototype.updateTargetData=function(t,e){return this.te(t,e)},vc.prototype.removeTargetData=function(e,t){var n=this;return this.removeMatchingKeysForTargetId(e,t.targetId).next(function(){return bc(e).delete(t.targetId)}).next(function(){return n.Xt(e)}).next(function(t){return Hr(0e.highestTargetId&&(e.highestTargetId=t.targetId,n=!0),t.sequenceNumber>e.highestListenSequenceNumber&&(e.highestListenSequenceNumber=t.sequenceNumber,n=!0),n},vc.prototype.getTargetCount=function(t){return this.Xt(t).next(function(t){return t.targetCount})},vc.prototype.getTargetData=function(t,r){var e=zi(r),e=IDBKeyRange.bound([e,Number.NEGATIVE_INFINITY],[e,Number.POSITIVE_INFINITY]),i=null;return bc(t).$t({range:e,index:Za.queryTargetsIndexName},function(t,e,n){e=Qu(e);Wi(r,e.target)&&(i=e,n.done())}).next(function(){return i})},vc.prototype.addMatchingKeys=function(n,t,r){var i=this,o=[],s=Tc(n);return t.forEach(function(t){var e=qa(t.path);o.push(s.put(new tu(r,e))),o.push(i.referenceDelegate.addReference(n,r,t))}),hu.waitFor(o)},vc.prototype.removeMatchingKeys=function(n,t,r){var i=this,o=Tc(n);return hu.forEach(t,function(t){var e=qa(t.path);return hu.waitFor([o.delete([r,e]),i.referenceDelegate.removeReference(n,r,t)])})},vc.prototype.removeMatchingKeysForTargetId=function(t,e){t=Tc(t),e=IDBKeyRange.bound([e],[e+1],!1,!0);return t.delete(e)},vc.prototype.getMatchingKeysForTargetId=function(t,e){var e=IDBKeyRange.bound([e],[e+1],!1,!0),t=Tc(t),r=$s();return t.$t({range:e,kt:!0},function(t,e,n){t=ja(t[1]),t=new Ai(t);r=r.add(t)}).next(function(){return r})},vc.prototype.containsKey=function(t,e){var e=qa(e.path),e=IDBKeyRange.bound([e],[$r(e)],!1,!0),i=0;return Tc(t).$t({index:tu.documentTargetsIndex,kt:!0,range:e},function(t,e,n){var r=t[0];t[1],0!==r&&(i++,n.done())}).next(function(){return 0h.params.maximumSequenceNumbersToCollect?(Br("LruGarbageCollector","Capping sequence numbers to collect down to the maximum of "+h.params.maximumSequenceNumbersToCollect+" from "+t),h.params.maximumSequenceNumbersToCollect):t,s=Date.now(),h.nthSequenceNumber(e,i)}).next(function(t){return r=t,a=Date.now(),h.removeTargets(e,r,n)}).next(function(t){return o=t,u=Date.now(),h.removeOrphanedDocuments(e,r)}).next(function(t){return c=Date.now(),qr()<=m.DEBUG&&Br("LruGarbageCollector","LRU Garbage Collection\n\tCounted targets in "+(s-l)+"ms\n\tDetermined least recently used "+i+" in "+(a-s)+"ms\n\tRemoved "+o+" targets in "+(u-a)+"ms\n\tRemoved "+t+" documents in "+(c-u)+"ms\nTotal Duration: "+(c-l)+"ms"),hu.resolve({didRun:!0,sequenceNumbersCollected:i,targetsRemoved:o,documentsRemoved:t})})},kc),Nc=(Cc.prototype.he=function(t){var n=this.de(t);return this.db.getTargetCache().getTargetCount(t).next(function(e){return n.next(function(t){return e+t})})},Cc.prototype.de=function(t){var e=0;return this.le(t,function(t){e++}).next(function(){return e})},Cc.prototype.forEachTarget=function(t,e){return this.db.getTargetCache().forEachTarget(t,e)},Cc.prototype.le=function(t,n){return this.we(t,function(t,e){return n(e)})},Cc.prototype.addReference=function(t,e,n){return Oc(t,n)},Cc.prototype.removeReference=function(t,e,n){return Oc(t,n)},Cc.prototype.removeTargets=function(t,e,n){return this.db.getTargetCache().removeTargets(t,e,n)},Cc.prototype.markPotentiallyOrphaned=Oc,Cc.prototype._e=function(t,e){return r=e,i=!1,yc(n=t).Ot(function(t){return fc(n,t,r).next(function(t){return t&&(i=!0),hu.resolve(!t)})}).next(function(){return i});var n,r,i},Cc.prototype.removeOrphanedDocuments=function(n,r){var i=this,o=this.db.getRemoteDocumentCache().newChangeBuffer(),s=[],a=0;return this.we(n,function(e,t){t<=r&&(t=i._e(n,e).next(function(t){if(!t)return a++,o.getEntry(n,e).next(function(){return o.removeEntry(e),Tc(n).delete([0,qa(e.path)])})}),s.push(t))}).next(function(){return hu.waitFor(s)}).next(function(){return o.apply(n)}).next(function(){return a})},Cc.prototype.removeTarget=function(t,e){e=e.withSequenceNumber(t.currentSequenceNumber);return this.db.getTargetCache().updateTargetData(t,e)},Cc.prototype.updateLimboDocument=Oc,Cc.prototype.we=function(t,r){var i,t=Tc(t),o=Or.o;return t.$t({index:tu.documentTargetsIndex},function(t,e){var n=t[0];t[1];t=e.path,e=e.sequenceNumber;0===n?(o!==Or.o&&r(new Ai(ja(i)),o),o=e,i=t):o=Or.o}).next(function(){o!==Or.o&&r(new Ai(ja(i)),o)})},Cc.prototype.getCacheSize=function(t){return this.db.getRemoteDocumentCache().getSize(t)},Cc);function Cc(t,e){this.db=t,this.garbageCollector=new Dc(this,e)}function kc(t,e){this.ae=t,this.params=e}function Rc(t,e){this.garbageCollector=t,this.asyncQueue=e,this.oe=!1,this.ce=null}function xc(t){this.ne=t,this.buffer=new Ks(_c),this.se=0}function Oc(t,e){return Tc(t).put((t=t.currentSequenceNumber,new tu(0,qa(e.path),t)))}var Lc,Pc=(Bc.prototype.get=function(t){var e=this.mapKeyFn(t),e=this.inner[e];if(void 0!==e)for(var n=0,r=e;n "+n),1))},Xc.prototype.We=function(){var t=this;null!==this.document&&"function"==typeof this.document.addEventListener&&(this.ke=function(){t.Se.enqueueAndForget(function(){return t.inForeground="visible"===t.document.visibilityState,t.je()})},this.document.addEventListener("visibilitychange",this.ke),this.inForeground="visible"===this.document.visibilityState)},Xc.prototype.an=function(){this.ke&&(this.document.removeEventListener("visibilitychange",this.ke),this.ke=null)},Xc.prototype.Ge=function(){var t,e=this;"function"==typeof(null===(t=this.window)||void 0===t?void 0:t.addEventListener)&&(this.Fe=function(){e.un(),i()&&navigator.appVersion.match("Version/14")&&e.Se.enterRestrictedMode(!0),e.Se.enqueueAndForget(function(){return e.shutdown()})},this.window.addEventListener("pagehide",this.Fe))},Xc.prototype.hn=function(){this.Fe&&(this.window.removeEventListener("pagehide",this.Fe),this.Fe=null)},Xc.prototype.cn=function(t){var e;try{var n=null!==(null===(e=this.Qe)||void 0===e?void 0:e.getItem(this.on(t)));return Br("IndexedDbPersistence","Client '"+t+"' "+(n?"is":"is not")+" zombied in LocalStorage"),n}catch(t){return jr("IndexedDbPersistence","Failed to get zombied client id.",t),!1}},Xc.prototype.un=function(){if(this.Qe)try{this.Qe.setItem(this.on(this.clientId),String(Date.now()))}catch(t){jr("Failed to set zombie client id.",t)}},Xc.prototype.ln=function(){if(this.Qe)try{this.Qe.removeItem(this.on(this.clientId))}catch(t){}},Xc.prototype.on=function(t){return"firestore_zombie_"+this.persistenceKey+"_"+t},Xc);function Xc(t,e,n,r,i,o,s,a,u,c){if(this.allowTabSynchronization=t,this.persistenceKey=e,this.clientId=n,this.Se=i,this.window=o,this.document=s,this.De=u,this.Ce=c,this.Ne=null,this.xe=!1,this.isPrimary=!1,this.networkEnabled=!0,this.Fe=null,this.inForeground=!1,this.ke=null,this.$e=null,this.Oe=Number.NEGATIVE_INFINITY,this.Me=function(t){return Promise.resolve()},!Xc.yt())throw new Fr(Mr.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");this.referenceDelegate=new Nc(this,r),this.Le=e+"main",this.R=new Lu(a),this.Be=new fu(this.Le,11,new Qc(this.R)),this.qe=new mc(this.referenceDelegate,this.R),this.Ut=new tc,this.Ue=(e=this.R,a=this.Ut,new Mc(e,a)),this.Ke=new Wu,this.window&&this.window.localStorage?this.Qe=this.window.localStorage:(this.Qe=null,!1===c&&jr("IndexedDbPersistence","LocalStorage is unavailable. As a result, persistence may not work reliably. In particular enablePersistence() could fail immediately after refreshing the page."))}function $c(t){return ku(t,Ka.store)}function Jc(t){return ku(t,ru.store)}function Zc(t,e){var n=t.projectId;return t.isDefaultDatabase||(n+="."+t.database),"firestore/"+e+"/"+n+"/"}function th(t,e){this.progress=t,this.wn=e}var eh=(uh.prototype.mn=function(e,n){var r=this;return this._n.getAllMutationBatchesAffectingDocumentKey(e,n).next(function(t){return r.yn(e,n,t)})},uh.prototype.yn=function(t,e,r){return this.Ue.getEntry(t,e).next(function(t){for(var e=0,n=r;ee?this._n[e]:null)},Bh.prototype.getHighestUnacknowledgedBatchId=function(){return hu.resolve(0===this._n.length?-1:this.ss-1)},Bh.prototype.getAllMutationBatches=function(t){return hu.resolve(this._n.slice())},Bh.prototype.getAllMutationBatchesAffectingDocumentKey=function(t,e){var n=this,r=new Sh(e,0),e=new Sh(e,Number.POSITIVE_INFINITY),i=[];return this.rs.forEachInRange([r,e],function(t){t=n.os(t.ns);i.push(t)}),hu.resolve(i)},Bh.prototype.getAllMutationBatchesAffectingDocumentKeys=function(t,e){var n=this,r=new Ks(Yr);return e.forEach(function(t){var e=new Sh(t,0),t=new Sh(t,Number.POSITIVE_INFINITY);n.rs.forEachInRange([e,t],function(t){r=r.add(t.ns)})}),hu.resolve(this.us(r))},Bh.prototype.getAllMutationBatchesAffectingQuery=function(t,e){var n=e.path,r=n.length+1,e=n;Ai.isDocumentKey(e)||(e=e.child(""));var e=new Sh(new Ai(e),0),i=new Ks(Yr);return this.rs.forEachWhile(function(t){var e=t.key.path;return!!n.isPrefixOf(e)&&(e.length===r&&(i=i.add(t.ns)),!0)},e),hu.resolve(this.us(i))},Bh.prototype.us=function(t){var e=this,n=[];return t.forEach(function(t){t=e.os(t);null!==t&&n.push(t)}),n},Bh.prototype.removeMutationBatch=function(n,r){var i=this;Hr(0===this.hs(r.batchId,"removed")),this._n.shift();var o=this.rs;return hu.forEach(r.mutations,function(t){var e=new Sh(t.key,r.batchId);return o=o.delete(e),i.referenceDelegate.markPotentiallyOrphaned(n,t.key)}).next(function(){i.rs=o})},Bh.prototype.Gt=function(t){},Bh.prototype.containsKey=function(t,e){var n=new Sh(e,0),n=this.rs.firstAfterOrEqual(n);return hu.resolve(e.isEqual(n&&n.key))},Bh.prototype.performConsistencyCheck=function(t){return this._n.length,hu.resolve()},Bh.prototype.hs=function(t,e){return this.cs(t)},Bh.prototype.cs=function(t){return 0===this._n.length?0:t-this._n[0].batchId},Bh.prototype.os=function(t){t=this.cs(t);return t<0||t>=this._n.length?null:this._n[t]},Bh),Dh=(qh.prototype.addEntry=function(t,e,n){var r=e.key,i=this.docs.get(r),o=i?i.size:0,i=this.ls(e);return this.docs=this.docs.insert(r,{document:e.clone(),size:i,readTime:n}),this.size+=i-o,this.Ut.addToCollectionParentIndex(t,r.path.popLast())},qh.prototype.removeEntry=function(t){var e=this.docs.get(t);e&&(this.docs=this.docs.remove(t),this.size-=e.size)},qh.prototype.getEntry=function(t,e){var n=this.docs.get(e);return hu.resolve(n?n.document.clone():Ki.newInvalidDocument(e))},qh.prototype.getEntries=function(t,e){var n=this,r=Qs;return e.forEach(function(t){var e=n.docs.get(t);r=r.insert(t,e?e.document.clone():Ki.newInvalidDocument(t))}),hu.resolve(r)},qh.prototype.getDocumentsMatchingQuery=function(t,e,n){for(var r=Qs,i=new Ai(e.path.child("")),o=this.docs.getIteratorFrom(i);o.hasNext();){var s=o.getNext(),a=s.key,u=s.value,s=u.document,u=u.readTime;if(!e.path.isPrefixOf(a.path))break;u.compareTo(n)<=0||Bo(e,s)&&(r=r.insert(s.key,s.clone()))}return hu.resolve(r)},qh.prototype.fs=function(t,e){return hu.forEach(this.docs,function(t){return e(t)})},qh.prototype.newChangeBuffer=function(t){return new Nh(this)},qh.prototype.getSize=function(t){return hu.resolve(this.size)},qh),Nh=(n(Uh,Th=_),Uh.prototype.applyChanges=function(n){var r=this,i=[];return this.changes.forEach(function(t,e){e.document.isValidDocument()?i.push(r.Ie.addEntry(n,e.document,r.getReadTime(t))):r.Ie.removeEntry(t)}),hu.waitFor(i)},Uh.prototype.getFromCache=function(t,e){return this.Ie.getEntry(t,e)},Uh.prototype.getAllFromCache=function(t,e){return this.Ie.getEntries(t,e)},Uh),Ch=(Vh.prototype.forEachTarget=function(t,n){return this.ds.forEach(function(t,e){return n(e)}),hu.resolve()},Vh.prototype.getLastRemoteSnapshotVersion=function(t){return hu.resolve(this.lastRemoteSnapshotVersion)},Vh.prototype.getHighestSequenceNumber=function(t){return hu.resolve(this.ws)},Vh.prototype.allocateTargetId=function(t){return this.highestTargetId=this.ys.next(),hu.resolve(this.highestTargetId)},Vh.prototype.setTargetsMetadata=function(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.ws&&(this.ws=e),hu.resolve()},Vh.prototype.te=function(t){this.ds.set(t.target,t);var e=t.targetId;e>this.highestTargetId&&(this.ys=new gc(e),this.highestTargetId=e),t.sequenceNumber>this.ws&&(this.ws=t.sequenceNumber)},Vh.prototype.addTargetData=function(t,e){return this.te(e),this.targetCount+=1,hu.resolve()},Vh.prototype.updateTargetData=function(t,e){return this.te(e),hu.resolve()},Vh.prototype.removeTargetData=function(t,e){return this.ds.delete(e.target),this._s.Zn(e.targetId),--this.targetCount,hu.resolve()},Vh.prototype.removeTargets=function(n,r,i){var o=this,s=0,a=[];return this.ds.forEach(function(t,e){e.sequenceNumber<=r&&null===i.get(e.targetId)&&(o.ds.delete(t),a.push(o.removeMatchingKeysForTargetId(n,e.targetId)),s++)}),hu.waitFor(a).next(function(){return s})},Vh.prototype.getTargetCount=function(t){return hu.resolve(this.targetCount)},Vh.prototype.getTargetData=function(t,e){e=this.ds.get(e)||null;return hu.resolve(e)},Vh.prototype.addMatchingKeys=function(t,e,n){return this._s.Jn(e,n),hu.resolve()},Vh.prototype.removeMatchingKeys=function(e,t,n){this._s.Xn(t,n);var r=this.persistence.referenceDelegate,i=[];return r&&t.forEach(function(t){i.push(r.markPotentiallyOrphaned(e,t))}),hu.waitFor(i)},Vh.prototype.removeMatchingKeysForTargetId=function(t,e){return this._s.Zn(e),hu.resolve()},Vh.prototype.getMatchingKeysForTargetId=function(t,e){e=this._s.es(e);return hu.resolve(e)},Vh.prototype.containsKey=function(t,e){return hu.resolve(this._s.containsKey(e))},Vh),kh=(Fh.prototype.start=function(){return Promise.resolve()},Fh.prototype.shutdown=function(){return this.xe=!1,Promise.resolve()},Object.defineProperty(Fh.prototype,"started",{get:function(){return this.xe},enumerable:!1,configurable:!0}),Fh.prototype.setDatabaseDeletedListener=function(){},Fh.prototype.setNetworkEnabled=function(){},Fh.prototype.getIndexManager=function(){return this.Ut},Fh.prototype.getMutationQueue=function(t){var e=this.gs[t.toKey()];return e||(e=new Ah(this.Ut,this.referenceDelegate),this.gs[t.toKey()]=e),e},Fh.prototype.getTargetCache=function(){return this.qe},Fh.prototype.getRemoteDocumentCache=function(){return this.Ue},Fh.prototype.getBundleCache=function(){return this.Ke},Fh.prototype.runTransaction=function(t,e,n){var r=this;Br("MemoryPersistence","Starting transaction:",t);var i=new Rh(this.Ne.next());return this.referenceDelegate.Es(),n(i).next(function(t){return r.referenceDelegate.Ts(i).next(function(){return t})}).toPromise().then(function(t){return i.raiseOnCommittedEvent(),t})},Fh.prototype.Is=function(e,n){return hu.or(Object.values(this.gs).map(function(t){return function(){return t.containsKey(e,n)}}))},Fh),Rh=(n(Mh,Eh=C),Mh),xh=(Ph.bs=function(t){return new Ph(t)},Object.defineProperty(Ph.prototype,"vs",{get:function(){if(this.Rs)return this.Rs;throw Qr()},enumerable:!1,configurable:!0}),Ph.prototype.addReference=function(t,e,n){return this.As.addReference(n,e),this.vs.delete(n.toString()),hu.resolve()},Ph.prototype.removeReference=function(t,e,n){return this.As.removeReference(n,e),this.vs.add(n.toString()),hu.resolve()},Ph.prototype.markPotentiallyOrphaned=function(t,e){return this.vs.add(e.toString()),hu.resolve()},Ph.prototype.removeTarget=function(t,e){var n=this;this.As.Zn(e.targetId).forEach(function(t){return n.vs.add(t.toString())});var r=this.persistence.getTargetCache();return r.getMatchingKeysForTargetId(t,e.targetId).next(function(t){t.forEach(function(t){return n.vs.add(t.toString())})}).next(function(){return r.removeTargetData(t,e)})},Ph.prototype.Es=function(){this.Rs=new Set},Ph.prototype.Ts=function(n){var r=this,i=this.persistence.getRemoteDocumentCache().newChangeBuffer();return hu.forEach(this.vs,function(t){var e=Ai.fromPath(t);return r.Ps(n,e).next(function(t){t||i.removeEntry(e)})}).next(function(){return r.Rs=null,i.apply(n)})},Ph.prototype.updateLimboDocument=function(t,e){var n=this;return this.Ps(t,e).next(function(t){t?n.vs.delete(e.toString()):n.vs.add(e.toString())})},Ph.prototype.ps=function(t){return 0},Ph.prototype.Ps=function(t,e){var n=this;return hu.or([function(){return hu.resolve(n.As.containsKey(e))},function(){return n.persistence.getTargetCache().containsKey(t,e)},function(){return n.persistence.Is(t,e)}])},Ph),Oh=(Lh.prototype.isAuthenticated=function(){return null!=this.uid},Lh.prototype.toKey=function(){return this.isAuthenticated()?"uid:"+this.uid:"anonymous-user"},Lh.prototype.isEqual=function(t){return t.uid===this.uid},Lh);function Lh(t){this.uid=t}function Ph(t){this.persistence=t,this.As=new _h,this.Rs=null}function Mh(t){var e=this;return(e=Eh.call(this)||this).currentSequenceNumber=t,e}function Fh(t,e){var n=this;this.gs={},this.Ne=new Or(0),this.xe=!1,this.xe=!0,this.referenceDelegate=t(this),this.qe=new Ch(this),this.Ut=new Ju,this.Ue=(t=this.Ut,new Dh(t,function(t){return n.referenceDelegate.ps(t)})),this.R=new Lu(e),this.Ke=new Ih(this.R)}function Vh(t){this.persistence=t,this.ds=new Pc(zi,Wi),this.lastRemoteSnapshotVersion=Zr.min(),this.highestTargetId=0,this.ws=0,this._s=new _h,this.targetCount=0,this.ys=gc.Jt()}function Uh(t){var e=this;return(e=Th.call(this)||this).Ie=t,e}function qh(t,e){this.Ut=t,this.ls=e,this.docs=new Ms(Ai.comparator),this.size=0}function Bh(t,e){this.Ut=t,this.referenceDelegate=e,this._n=[],this.ss=1,this.rs=new Ks(Sh.Gn)}function jh(t,e){this.key=t,this.ns=e}function Kh(){this.Wn=new Ks(Sh.Gn),this.zn=new Ks(Sh.Hn)}function Gh(t){this.R=t,this.Qn=new Map,this.jn=new Map}function Qh(t,e){return"firestore_clients_"+t+"_"+e}function Hh(t,e,n){n="firestore_mutations_"+t+"_"+n;return e.isAuthenticated()&&(n+="_"+e.uid),n}function zh(t,e){return"firestore_targets_"+t+"_"+e}Oh.UNAUTHENTICATED=new Oh(null),Oh.GOOGLE_CREDENTIALS=new Oh("google-credentials-uid"),Oh.FIRST_PARTY=new Oh("first-party-uid");var Wh,Yh=(vl.Vs=function(t,e,n){var r,i=JSON.parse(n),o="object"==typeof i&&-1!==["pending","acknowledged","rejected"].indexOf(i.state)&&(void 0===i.error||"object"==typeof i.error);return o&&i.error&&(o="string"==typeof i.error.message&&"string"==typeof i.error.code)&&(r=new Fr(i.error.code,i.error.message)),o?new vl(t,e,i.state,r):(jr("SharedClientState","Failed to parse mutation state for ID '"+e+"': "+n),null)},vl.prototype.Ss=function(){var t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)},vl),Xh=(ml.Vs=function(t,e){var n,r=JSON.parse(e),i="object"==typeof r&&-1!==["not-current","current","rejected"].indexOf(r.state)&&(void 0===r.error||"object"==typeof r.error);return i&&r.error&&(i="string"==typeof r.error.message&&"string"==typeof r.error.code)&&(n=new Fr(r.error.code,r.error.message)),i?new ml(t,r.state,n):(jr("SharedClientState","Failed to parse target state for ID '"+t+"': "+e),null)},ml.prototype.Ss=function(){var t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)},ml),$h=(gl.Vs=function(t,e){for(var n=JSON.parse(e),r="object"==typeof n&&n.activeTargetIds instanceof Array,i=Js,o=0;r&&othis.Bi&&(this.qi=this.Bi)},Ml.prototype.Gi=function(){null!==this.Ui&&(this.Ui.skipDelay(),this.Ui=null)},Ml.prototype.cancel=function(){null!==this.Ui&&(this.Ui.cancel(),this.Ui=null)},Ml.prototype.Wi=function(){return(Math.random()-.5)*this.qi},Ml),_=(Pl.prototype.tr=function(){return 1===this.state||2===this.state||4===this.state},Pl.prototype.er=function(){return 2===this.state},Pl.prototype.start=function(){3!==this.state?this.auth():this.nr()},Pl.prototype.stop=function(){return y(this,void 0,void 0,function(){return g(this,function(t){switch(t.label){case 0:return this.tr()?[4,this.close(0)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})},Pl.prototype.sr=function(){this.state=0,this.Zi.reset()},Pl.prototype.ir=function(){var t=this;this.er()&&null===this.Xi&&(this.Xi=this.Se.enqueueAfterDelay(this.zi,6e4,function(){return t.rr()}))},Pl.prototype.cr=function(t){this.ur(),this.stream.send(t)},Pl.prototype.rr=function(){return y(this,void 0,void 0,function(){return g(this,function(t){return this.er()?[2,this.close(0)]:[2]})})},Pl.prototype.ur=function(){this.Xi&&(this.Xi.cancel(),this.Xi=null)},Pl.prototype.close=function(e,n){return y(this,void 0,void 0,function(){return g(this,function(t){switch(t.label){case 0:return this.ur(),this.Zi.cancel(),this.Yi++,3!==e?this.Zi.reset():n&&n.code===Mr.RESOURCE_EXHAUSTED?(jr(n.toString()),jr("Using maximum backoff delay to prevent overloading the backend."),this.Zi.Qi()):n&&n.code===Mr.UNAUTHENTICATED&&this.Ji.invalidateToken(),null!==this.stream&&(this.ar(),this.stream.close(),this.stream=null),this.state=e,[4,this.listener.Ri(n)];case 1:return t.sent(),[2]}})})},Pl.prototype.ar=function(){},Pl.prototype.auth=function(){var n=this;this.state=1;var t=this.hr(this.Yi),e=this.Yi;this.Ji.getToken().then(function(t){n.Yi===e&&n.lr(t)},function(e){t(function(){var t=new Fr(Mr.UNKNOWN,"Fetching auth token failed: "+e.message);return n.dr(t)})})},Pl.prototype.lr=function(t){var e=this,n=this.hr(this.Yi);this.stream=this.wr(t),this.stream.Ii(function(){n(function(){return e.state=2,e.listener.Ii()})}),this.stream.Ri(function(t){n(function(){return e.dr(t)})}),this.stream.onMessage(function(t){n(function(){return e.onMessage(t)})})},Pl.prototype.nr=function(){var t=this;this.state=4,this.Zi.ji(function(){return y(t,void 0,void 0,function(){return g(this,function(t){return this.state=0,this.start(),[2]})})})},Pl.prototype.dr=function(t){return Br("PersistentStream","close with error: "+t),this.stream=null,this.close(3,t)},Pl.prototype.hr=function(e){var n=this;return function(t){n.Se.enqueueAndForget(function(){return n.Yi===e?t():(Br("PersistentStream","stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())})}},Pl),Dl=(n(Ll,Sl=_),Ll.prototype.wr=function(t){return this.Hi.Oi("Listen",t)},Ll.prototype.onMessage=function(t){this.Zi.reset();var e=function(t,e){if("targetChange"in e){e.targetChange;var n="NO_CHANGE"===(o=e.targetChange.targetChangeType||"NO_CHANGE")?0:"ADD"===o?1:"REMOVE"===o?2:"CURRENT"===o?3:"RESET"===o?4:Qr(),r=e.targetChange.targetIds||[],i=(s=e.targetChange.resumeToken,t.I?(Hr(void 0===s||"string"==typeof s),li.fromBase64String(s||"")):(Hr(void 0===s||s instanceof Uint8Array),li.fromUint8Array(s||new Uint8Array))),o=(a=e.targetChange.cause)&&(u=void 0===(c=a).code?Mr.UNKNOWN:Ps(c.code),new Fr(u,c.message||"")),s=new ra(n,r,i,o||null)}else if("documentChange"in e){e.documentChange,(n=e.documentChange).document,n.document.name,n.document.updateTime;var r=Ea(t,n.document.name),i=ma(n.document.updateTime),a=new Bi({mapValue:{fields:n.document.fields}}),u=(o=Ki.newFoundDocument(r,i,a),n.targetIds||[]),c=n.removedTargetIds||[];s=new ea(u,c,o.key,o)}else if("documentDelete"in e)e.documentDelete,(n=e.documentDelete).document,r=Ea(t,n.document),i=n.readTime?ma(n.readTime):Zr.min(),a=Ki.newNoDocument(r,i),o=n.removedTargetIds||[],s=new ea([],o,a.key,a);else if("documentRemove"in e)e.documentRemove,(n=e.documentRemove).document,r=Ea(t,n.document),i=n.removedTargetIds||[],s=new ea([],i,r,null);else{if(!("filter"in e))return Qr();e.filter;e=e.filter;e.targetId,n=e.count||0,r=new As(n),i=e.targetId,s=new na(i,r)}return s}(this.R,t),t=function(t){if(!("targetChange"in t))return Zr.min();t=t.targetChange;return(!t.targetIds||!t.targetIds.length)&&t.readTime?ma(t.readTime):Zr.min()}(t);return this.listener._r(e,t)},Ll.prototype.mr=function(t){var e,n,r,i={};i.database=_a(this.R),i.addTarget=(e=this.R,(r=Yi(r=(n=t).target)?{documents:ka(e,r)}:{query:Ra(e,r)}).targetId=n.targetId,0this.query.limit;){var n=ko(this.query)?h.last():h.first(),h=h.delete(n.key),c=c.delete(n.key);a.track({type:1,doc:n})}return{fo:h,mo:a,Nn:l,mutatedKeys:c}},Of.prototype.yo=function(t,e){return t.hasLocalMutations&&e.hasCommittedMutations&&!e.hasLocalMutations},Of.prototype.applyChanges=function(t,e,n){var o=this,r=this.fo;this.fo=t.fo,this.mutatedKeys=t.mutatedKeys;var i=t.mo.jr();i.sort(function(t,e){return r=t.type,i=e.type,n(r)-n(i)||o.lo(t.doc,e.doc);function n(t){switch(t){case 0:return 1;case 2:case 3:return 2;case 1:return 0;default:return Qr()}}var r,i}),this.po(n);var s=e?this.Eo():[],n=0===this.ho.size&&this.current?1:0,e=n!==this.ao;return this.ao=n,0!==i.length||e?{snapshot:new cf(this.query,t.fo,r,i,t.mutatedKeys,0==n,e,!1),To:s}:{To:s}},Of.prototype.zr=function(t){return this.current&&"Offline"===t?(this.current=!1,this.applyChanges({fo:this.fo,mo:new uf,mutatedKeys:this.mutatedKeys,Nn:!1},!1)):{To:[]}},Of.prototype.Io=function(t){return!this.uo.has(t)&&!!this.fo.has(t)&&!this.fo.get(t).hasLocalMutations},Of.prototype.po=function(t){var e=this;t&&(t.addedDocuments.forEach(function(t){return e.uo=e.uo.add(t)}),t.modifiedDocuments.forEach(function(t){}),t.removedDocuments.forEach(function(t){return e.uo=e.uo.delete(t)}),this.current=t.current)},Of.prototype.Eo=function(){var e=this;if(!this.current)return[];var n=this.ho;this.ho=$s(),this.fo.forEach(function(t){e.Io(t.key)&&(e.ho=e.ho.add(t.key))});var r=[];return n.forEach(function(t){e.ho.has(t)||r.push(new Df(t))}),this.ho.forEach(function(t){n.has(t)||r.push(new Af(t))}),r},Of.prototype.Ao=function(t){this.uo=t.Bn,this.ho=$s();t=this._o(t.documents);return this.applyChanges(t,!0)},Of.prototype.Ro=function(){return cf.fromInitialDocuments(this.query,this.fo,this.mutatedKeys,0===this.ao)},Of),Cf=function(t,e,n){this.query=t,this.targetId=e,this.view=n},kf=function(t){this.key=t,this.bo=!1},Rf=(Object.defineProperty(xf.prototype,"isPrimaryClient",{get:function(){return!0===this.$o},enumerable:!1,configurable:!0}),xf);function xf(t,e,n,r,i,o){this.localStore=t,this.remoteStore=e,this.eventManager=n,this.sharedClientState=r,this.currentUser=i,this.maxConcurrentLimboResolutions=o,this.vo={},this.Po=new Pc(Uo,Vo),this.Vo=new Map,this.So=new Set,this.Do=new Ms(Ai.comparator),this.Co=new Map,this.No=new _h,this.xo={},this.Fo=new Map,this.ko=gc.Yt(),this.onlineState="Unknown",this.$o=void 0}function Of(t,e){this.query=t,this.uo=e,this.ao=null,this.current=!1,this.ho=$s(),this.mutatedKeys=$s(),this.lo=jo(t),this.fo=new af(this.lo)}function Lf(i,o,s,a){return y(this,void 0,void 0,function(){var e,n,r;return g(this,function(t){switch(t.label){case 0:return i.Oo=function(t,e,n){return function(r,i,o,s){return y(this,void 0,void 0,function(){var e,n;return g(this,function(t){switch(t.label){case 0:return(e=i.view._o(o)).Nn?[4,mh(r.localStore,i.query,!1).then(function(t){t=t.documents;return i.view._o(t,e)})]:[3,2];case 1:e=t.sent(),t.label=2;case 2:return n=s&&s.targetChanges.get(i.targetId),n=i.view.applyChanges(e,r.isPrimaryClient,n),[2,(Gf(r,i.targetId,n.To),n.snapshot)]}})})}(i,t,e,n)},[4,mh(i.localStore,o,!0)];case 1:return n=t.sent(),r=new Nf(o,n.Bn),e=r._o(n.documents),n=ta.createSynthesizedTargetChangeForCurrentChange(s,a&&"Offline"!==i.onlineState),n=r.applyChanges(e,i.isPrimaryClient,n),Gf(i,s,n.To),r=new Cf(o,s,r),[2,(i.Po.set(o,r),i.Vo.has(s)?i.Vo.get(s).push(o):i.Vo.set(s,[o]),n.snapshot)]}})})}function Pf(f,d,p){return y(this,void 0,void 0,function(){var s,l;return g(this,function(t){switch(t.label){case 0:l=Zf(f),t.label=1;case 1:return t.trys.push([1,5,,6]),[4,(i=l.localStore,a=d,c=i,h=Jr.now(),o=a.reduce(function(t,e){return t.add(e.key)},$s()),c.persistence.runTransaction("Locally write mutations","readwrite",function(s){return c.Mn.pn(s,o).next(function(t){u=t;for(var e=[],n=0,r=a;n, or >=) must be on the same field. But you have inequality filters on '"+n.toString()+"' and '"+e.field.toString()+"'");n=xo(t);null!==n&&og(0,e.field,n)}t=function(t,e){for(var n=0,r=t.filters;ns.length)throw new Fr(Mr.INVALID_ARGUMENT,"Too many arguments provided to "+r+"(). The number of arguments must be less than or equal to the number of orderBy() clauses");for(var a=[],u=0;u, or >=) on field '"+e.toString()+"' and so you must also use '"+e.toString()+"' as your first argument to orderBy(), but your first orderBy() is on field '"+n.toString()+"' instead.")}sg.prototype.convertValue=function(t,e){switch(void 0===e&&(e="none"),Ni(t)){case 0:return null;case 1:return t.booleanValue;case 2:return wi(t.integerValue||t.doubleValue);case 3:return this.convertTimestamp(t.timestampValue);case 4:return this.convertServerTimestamp(t,e);case 5:return t.stringValue;case 6:return this.convertBytes(bi(t.bytesValue));case 7:return this.convertReference(t.referenceValue);case 8:return this.convertGeoPoint(t.geoPointValue);case 9:return this.convertArray(t.arrayValue,e);case 10:return this.convertObject(t.mapValue,e);default:throw Qr()}},sg.prototype.convertObject=function(t,n){var r=this,i={};return ri(t.fields,function(t,e){i[t]=r.convertValue(e,n)}),i},sg.prototype.convertGeoPoint=function(t){return new xp(wi(t.latitude),wi(t.longitude))},sg.prototype.convertArray=function(t,e){var n=this;return(t.values||[]).map(function(t){return n.convertValue(t,e)})},sg.prototype.convertServerTimestamp=function(t,e){switch(e){case"previous":var n=function t(e){e=e.mapValue.fields.__previous_value__;return Ei(e)?t(e):e}(t);return null==n?null:this.convertValue(n,e);case"estimate":return this.convertTimestamp(Ti(t));default:return null}},sg.prototype.convertTimestamp=function(t){t=vi(t);return new Jr(t.seconds,t.nanos)},sg.prototype.convertDocumentKey=function(t,e){var n=ai.fromString(t);Hr(Ua(n));t=new Pd(n.get(1),n.get(3)),n=new Ai(n.popFirst(5));return t.isEqual(e)||jr("Document "+n+" contains a document reference within a different database ("+t.projectId+"/"+t.database+") which is not supported. It will be treated as a reference in the current database ("+e.projectId+"/"+e.database+") instead."),n},_=sg;function sg(){}function ag(t,e,n){return t?n&&(n.merge||n.mergeFields)?t.toFirestore(e,n):t.toFirestore(e):e}var ug,cg=(n(fg,ug=_),fg.prototype.convertBytes=function(t){return new kp(t)},fg.prototype.convertReference=function(t){t=this.convertDocumentKey(t,this.firestore._databaseId);return new op(this.firestore,null,t)},fg),hg=(lg.prototype.set=function(t,e,n){this._verifyNotCommitted();t=dg(t,this._firestore),e=ag(t.converter,e,n),n=zp(this._dataReader,"WriteBatch.set",t._key,e,null!==t.converter,n);return this._mutations.push(n.toMutation(t._key,ls.none())),this},lg.prototype.update=function(t,e,n){for(var r=[],i=3;iPinball +