refactor: changed multiball and group

pull/235/head
RuiAlonso 3 years ago
parent 4bb2f25617
commit b9c59999a9

@ -15,8 +15,6 @@ class Multiball extends Component {
/// {@macro multiball}
Multiball._({
required Vector2 position,
required String onAssetPath,
required String offAssetPath,
double rotation = 0,
Iterable<Component>? children,
required this.bloc,
@ -25,10 +23,10 @@ class Multiball extends Component {
MultiballBlinkingBehavior(),
MultiballSpriteGroupComponent(
position: position,
onAssetPath: onAssetPath,
offAssetPath: offAssetPath,
litAssetPath: Assets.images.multiball.lit.keyName,
dimmedAssetPath: Assets.images.multiball.dimmed.keyName,
rotation: rotation,
state: bloc.state,
state: bloc.state.lightState,
),
...?children,
],
@ -39,8 +37,6 @@ class Multiball extends Component {
Iterable<Component>? children,
}) : this._(
position: Vector2(-23, 7.5),
onAssetPath: Assets.images.multiball.a.lit.keyName,
offAssetPath: Assets.images.multiball.a.dimmed.keyName,
rotation: -24 * math.pi / 180,
bloc: MultiballCubit(),
children: children,
@ -50,10 +46,8 @@ class Multiball extends Component {
Multiball.b({
Iterable<Component>? children,
}) : this._(
position: Vector2(-7, -6.5),
onAssetPath: Assets.images.multiball.b.lit.keyName,
offAssetPath: Assets.images.multiball.b.dimmed.keyName,
rotation: -5 * math.pi / 180,
position: Vector2(-7.2, -6.5),
rotation: -6 * math.pi / 180,
bloc: MultiballCubit(),
children: children,
);
@ -62,9 +56,7 @@ class Multiball extends Component {
Multiball.c({
Iterable<Component>? children,
}) : this._(
position: Vector2(-0.5, -9.5),
onAssetPath: Assets.images.multiball.c.lit.keyName,
offAssetPath: Assets.images.multiball.c.dimmed.keyName,
position: Vector2(-0.7, -9.5),
rotation: 3 * math.pi / 180,
bloc: MultiballCubit(),
children: children,
@ -75,8 +67,6 @@ class Multiball extends Component {
Iterable<Component>? children,
}) : this._(
position: Vector2(15, 7),
onAssetPath: Assets.images.multiball.d.lit.keyName,
offAssetPath: Assets.images.multiball.d.dimmed.keyName,
rotation: 24 * math.pi / 180,
bloc: MultiballCubit(),
children: children,
@ -108,17 +98,18 @@ class Multiball extends Component {
/// A [SpriteGroupComponent] for the multiball over the board.
/// {@endtemplate}
@visibleForTesting
class MultiballSpriteGroupComponent extends SpriteGroupComponent<MultiballState>
class MultiballSpriteGroupComponent
extends SpriteGroupComponent<MultiballLightState>
with HasGameRef, ParentIsA<Multiball> {
/// {@macro multiball_sprite_group_component}
MultiballSpriteGroupComponent({
required Vector2 position,
required String onAssetPath,
required String offAssetPath,
required String litAssetPath,
required String dimmedAssetPath,
required double rotation,
required MultiballState state,
}) : _litAssetPath = onAssetPath,
_dimmedAssetPath = offAssetPath,
required MultiballLightState state,
}) : _litAssetPath = litAssetPath,
_dimmedAssetPath = dimmedAssetPath,
super(
anchor: Anchor.center,
position: position,
@ -132,15 +123,16 @@ class MultiballSpriteGroupComponent extends SpriteGroupComponent<MultiballState>
@override
Future<void> onLoad() async {
await super.onLoad();
parent.bloc.stream.listen((state) => current = state);
parent.bloc.stream.listen((state) => current = state.lightState);
final sprites = {
MultiballState.lit: Sprite(gameRef.images.fromCache(_litAssetPath)),
MultiballState.dimmed: Sprite(gameRef.images.fromCache(_dimmedAssetPath)),
MultiballLightState.lit: Sprite(
gameRef.images.fromCache(_litAssetPath),
),
MultiballLightState.dimmed:
Sprite(gameRef.images.fromCache(_dimmedAssetPath)),
};
this.sprites = sprites;
current = MultiballState.dimmed;
size = sprites[current]!.originalSize / 10;
}
}

@ -1,7 +1,6 @@
// ignore_for_file: cascade_invocations
import 'package:bloc_test/bloc_test.dart';
import 'package:flame/components.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
@ -12,14 +11,8 @@ import '../../../helpers/helpers.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final assets = [
Assets.images.multiball.a.lit.keyName,
Assets.images.multiball.a.dimmed.keyName,
Assets.images.multiball.b.lit.keyName,
Assets.images.multiball.b.dimmed.keyName,
Assets.images.multiball.c.lit.keyName,
Assets.images.multiball.c.dimmed.keyName,
Assets.images.multiball.d.lit.keyName,
Assets.images.multiball.d.dimmed.keyName,
Assets.images.multiball.lit.keyName,
Assets.images.multiball.dimmed.keyName,
];
final flameTester = FlameTester(() => TestGame(assets));
@ -58,8 +51,8 @@ void main() {
final bloc = MockMultiballCubit();
whenListen(
bloc,
const Stream<MultiballState>.empty(),
initialState: MultiballState.dimmed,
const Stream<MultiballLightState>.empty(),
initialState: MultiballLightState.dimmed,
);
when(bloc.close).thenAnswer((_) async {});
final multiball = Multiball.test(bloc: bloc);

@ -2,7 +2,6 @@
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';

Loading…
Cancel
Save