refactor: removed restart logic changes for another pr

pull/359/head
RuiAlonso 3 years ago
parent a017ec4d41
commit 45500885bb

@ -37,7 +37,6 @@ class CameraFocusingBehavior extends Component
case GameStatus.waiting:
break;
case GameStatus.playing:
case GameStatus.replaying:
_zoom(_foci['game']!);
break;
case GameStatus.gameOver:

@ -16,17 +16,12 @@ class GameBloc extends Bloc<GameEvent, GameState> {
on<SparkyTurboChargeActivated>(_onSparkyTurboChargeActivated);
on<GameOver>(_onGameOver);
on<GameStarted>(_onGameStarted);
on<GameRestarted>(_onGameRestarted);
}
void _onGameStarted(GameStarted _, Emitter emit) {
emit(state.copyWith(status: GameStatus.playing));
}
void _onGameRestarted(GameRestarted _, Emitter emit) {
emit(const GameState.initial().copyWith(status: GameStatus.replaying));
}
void _onGameOver(GameOver _, Emitter emit) {
emit(state.copyWith(status: GameStatus.gameOver));
}

@ -67,13 +67,6 @@ class GameStarted extends GameEvent {
List<Object?> get props => [];
}
class GameRestarted extends GameEvent {
const GameRestarted();
@override
List<Object?> get props => [];
}
class GameOver extends GameEvent {
const GameOver();

@ -70,7 +70,7 @@ class Backbox extends PositionComponent with ZIndex {
);
} else if (state is InitialsSuccessState) {
_display.add(
InfoDisplay(
GameOverInfoDisplay(
onShare: () {
_bloc.add(
ShareScoreRequested(

@ -1,4 +1,4 @@
export 'info_display.dart';
export 'game_over_info_display.dart';
export 'initials_input_display.dart';
export 'initials_submission_failure_display.dart';
export 'initials_submission_success_display.dart';

@ -10,11 +10,11 @@ import 'package:pinball_flame/pinball_flame.dart';
import 'package:pinball_ui/pinball_ui.dart';
/// Signature for the callback called when the user tries to share their score
/// from the [InfoDisplay].
/// from the [GameOverInfoDisplay].
typedef OnShareTap = void Function();
/// Signature for the callback called when the user tries to navigate to the
/// Google IO site from the [InfoDisplay].
/// Google IO site from the [GameOverInfoDisplay].
typedef OnNavigateTap = void Function();
final _titleTextPaint = TextPaint(
@ -52,12 +52,12 @@ final _descriptionTextPaint = TextPaint(
),
);
/// {@template info_display}
/// {@template game_over_info_display}
/// Display that handles shows to the user share or goto IO website.
/// {@endtemplate}
class InfoDisplay extends Component with HasGameRef {
/// {@macro info_display}
InfoDisplay({
class GameOverInfoDisplay extends Component with HasGameRef {
/// {@macro game_over_info_display}
GameOverInfoDisplay({
OnShareTap? onShare,
OnNavigateTap? onNavigate,
}) : super(
@ -72,7 +72,7 @@ class InfoDisplay extends Component with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
gameRef.overlays.add(PinballGame.replayButtonOverlay);
//gameRef.overlays.add(PinballGame.replayButtonOverlay);
}
}
@ -164,7 +164,7 @@ class _LinksComponent extends PositionComponent with HasGameRef {
position: Vector2(0, 9.2),
children: [
ShareLinkComponent(onTap: onShare),
GotoIOLinkComponent(onTap: onNavigate),
GoogleIOLinkComponent(onTap: onNavigate),
],
);
}
@ -198,12 +198,12 @@ class ShareLinkComponent extends TextComponent with HasGameRef, Tappable {
}
}
/// {@template goto_io_link_component}
/// {@template google_io_link_component}
/// Link button to navigate to Google I/O site.
/// {@endtemplate}
class GotoIOLinkComponent extends TextComponent with HasGameRef, Tappable {
/// {@macro goto_io_link_component}
GotoIOLinkComponent({
class GoogleIOLinkComponent extends TextComponent with HasGameRef, Tappable {
/// {@macro google_io_link_component}
GoogleIOLinkComponent({
OnNavigateTap? onTap,
}) : _onTap = onTap,
super(

@ -34,7 +34,6 @@ class StartGameBloc extends Bloc<StartGameEvent, StartGameState> {
emit(
state.copyWith(
status: StartGameStatus.selectCharacter,
restarted: true,
),
);
}

@ -22,33 +22,23 @@ class StartGameState extends Equatable {
/// {@macro start_game_state}
const StartGameState({
required this.status,
this.restarted = false,
});
/// Initial [StartGameState].
const StartGameState.initial()
: this(
status: StartGameStatus.initial,
restarted: false,
);
const StartGameState.initial() : this(status: StartGameStatus.initial);
/// Status of [StartGameState].
final StartGameStatus status;
/// Game has been restarted from game over screen.
final bool restarted;
/// Creates a copy of [StartGameState].
StartGameState copyWith({
StartGameStatus? status,
bool? restarted,
}) {
return StartGameState(
status: status ?? this.status,
restarted: restarted ?? this.restarted,
);
}
@override
List<Object> get props => [status, restarted];
List<Object> get props => [status];
}

@ -31,11 +31,7 @@ class StartGameListener extends StatelessWidget {
break;
case StartGameStatus.selectCharacter:
_onSelectCharacter(context);
if (state.restarted) {
context.read<GameBloc>().add(const GameRestarted());
} else {
context.read<GameBloc>().add(const GameStarted());
}
context.read<GameBloc>().add(const GameStarted());
break;
case StartGameStatus.howToPlay:
_onHowToPlay(context);

@ -38,20 +38,6 @@ void main() {
],
);
blocTest<GameBloc, GameState>(
'GameRestarted restarts the game',
build: GameBloc.new,
act: (bloc) => bloc.add(const GameRestarted()),
expect: () => [
isA<GameState>()
..having(
(state) => state.status,
'status',
GameStatus.replaying,
),
],
);
group('RoundLost', () {
blocTest<GameBloc, GameState>(
'decreases number of rounds '

@ -98,19 +98,6 @@ void main() {
});
});
group('GameRestarted', () {
test('can be instantiated', () {
expect(const GameRestarted(), isNotNull);
});
test('supports value equality', () {
expect(
GameRestarted(),
equals(const GameRestarted()),
);
});
});
group('SparkyTurboChargeActivated', () {
test('can be instantiated', () {
expect(const SparkyTurboChargeActivated(), isNotNull);

@ -232,7 +232,7 @@ void main() {
await game.pump(backbox);
expect(
game.descendants().whereType<InfoDisplay>().length,
game.descendants().whereType<GameOverInfoDisplay>().length,
equals(1),
);
},

@ -8,7 +8,7 @@ import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/bloc/game_bloc.dart';
import 'package:pinball/game/components/backbox/displays/info_display.dart';
import 'package:pinball/game/components/backbox/displays/game_over_info_display.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
@ -25,7 +25,7 @@ class _TestGame extends Forge2DGame with HasTappables {
);
}
Future<void> pump(InfoDisplay component) {
Future<void> pump(GameOverInfoDisplay component) {
return ensureAdd(
FlameBlocProvider<GameBloc, GameState>.value(
value: GameBloc(),
@ -71,7 +71,7 @@ void main() {
flameTester.test(
'loads correctly',
(game) async {
final component = InfoDisplay();
final component = GameOverInfoDisplay();
await game.pump(component);
expect(game.descendants(), contains(component));
},
@ -83,7 +83,7 @@ void main() {
var tapped = false;
final tapDownInfo = _MockTapDownInfo();
final component = InfoDisplay(
final component = GameOverInfoDisplay(
onShare: () => tapped = true,
);
await game.pump(component);
@ -103,7 +103,7 @@ void main() {
var tapped = false;
final tapDownInfo = _MockTapDownInfo();
final component = InfoDisplay(
final component = GameOverInfoDisplay(
onNavigate: () => tapped = true,
);
await game.pump(component);

@ -167,7 +167,7 @@ void main() {
await game.pump([component], pinballPlayer: player);
component.onNewState(
const GameState.initial().copyWith(status: GameStatus.replaying),
const GameState.initial().copyWith(status: GameStatus.playing),
);
expect(

@ -16,13 +16,12 @@ void main() {
);
blocTest<StartGameBloc, StartGameState>(
'on ReplayTapped changes status to selectCharacter and restarted enabled',
'on ReplayTapped changes status to selectCharacter',
build: StartGameBloc.new,
act: (bloc) => bloc.add(const ReplayTapped()),
expect: () => [
const StartGameState(
status: StartGameStatus.selectCharacter,
restarted: true,
)
],
);

@ -49,14 +49,12 @@ void main() {
);
final otherState = StartGameState(
status: StartGameStatus.play,
restarted: true,
);
expect(state, isNot(equals(otherState)));
expect(
state.copyWith(
status: otherState.status,
restarted: otherState.restarted,
),
equals(otherState),
);
@ -69,7 +67,6 @@ void main() {
testState.props,
equals([
StartGameStatus.selectCharacter,
false,
]),
);
});

@ -46,7 +46,7 @@ void main() {
});
testWidgets(
'calls GameStarted event only on play',
'calls GameStarted event',
(tester) async {
whenListen(
startGameBloc,
@ -66,38 +66,10 @@ void main() {
startGameBloc: startGameBloc,
);
verifyNever(() => gameBloc.add(const GameRestarted()));
verify(() => gameBloc.add(const GameStarted())).called(1);
},
);
testWidgets(
'calls GameRestarted event only on replay',
(tester) async {
whenListen(
startGameBloc,
Stream.value(
const StartGameState(
status: StartGameStatus.selectCharacter,
restarted: true,
),
),
initialState: const StartGameState.initial(),
);
await tester.pumpApp(
const StartGameListener(
child: SizedBox.shrink(),
),
gameBloc: gameBloc,
startGameBloc: startGameBloc,
);
verifyNever(() => gameBloc.add(const GameStarted()));
verify(() => gameBloc.add(const GameRestarted())).called(1);
},
);
testWidgets(
'shows SelectCharacter dialog',
(tester) async {

Loading…
Cancel
Save