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

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

@ -2,7 +2,6 @@
import 'package:flame_test/flame_test.dart'; import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';

Loading…
Cancel
Save