revert: changed `CameraFocusingBehavior` logic (#451)

* revert: changed CameraFocusingBehavior logic

* refactor: removed unnecessary type

Co-authored-by: Erick <erickzanardoo@gmail.com>

* fix: coverage

Co-authored-by: Erick <erickzanardoo@gmail.com>
Co-authored-by: Tom Arra <tarra3@gmail.com>
pull/453/head
Alejandro Santiago 2 years ago committed by GitHub
parent 1c8813e039
commit ad77839d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,3 @@
import 'dart:math';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame_bloc/flame_bloc.dart';
@ -43,30 +41,25 @@ class CameraFocusingBehavior extends Component
@override
void onGameResize(Vector2 size) {
super.onGameResize(size);
if (size == _previousSize) {
return;
}
if (size == _previousSize) return;
_previousSize.setFrom(size);
final maxWidth = size.x / 90;
final maxHeight = size.y / 160;
final scale = min(maxHeight, maxWidth);
_foci.addAll({
GameStatus.waiting: _FocusData(
zoom: scale + (maxWidth > maxHeight ? 0.3 : -0.5),
position: Vector2(0, -112),
),
GameStatus.playing: _FocusData(
zoom: scale + (maxWidth > maxHeight ? 0.5 : -0.2),
position: Vector2(0, -7.8),
),
GameStatus.gameOver: _FocusData(
zoom: scale + (maxWidth > maxHeight ? 2.8 : 3.3),
position: Vector2(0, -111),
),
});
_foci.addAll(
{
GameStatus.waiting: _FocusData(
zoom: size.y / 175,
position: _foci[GameStatus.waiting]?.position ?? Vector2(0, -112),
),
GameStatus.playing: _FocusData(
zoom: size.y / 165,
position: _foci[GameStatus.playing]?.position ?? Vector2(0, -7.8),
),
GameStatus.gameOver: _FocusData(
zoom: size.y / 100,
position: _foci[GameStatus.gameOver]?.position ?? Vector2(0, -111),
),
},
);
if (_activeFocus != null) {
_snap(_activeFocus!);

@ -34,6 +34,19 @@ void main() {
expect(game.descendants(), contains(behavior));
});
flameTester.test('resizes and snaps', (game) async {
final behavior = CameraFocusingBehavior();
await game.ensureAdd(
FlameBlocProvider<GameBloc, GameState>.value(
value: GameBloc(),
children: [behavior],
),
);
behavior.onGameResize(Vector2.all(10));
expect(game.camera.zoom, greaterThan(0));
});
flameTester.test(
'changes focus when loaded',
(game) async {
@ -53,20 +66,6 @@ void main() {
},
);
flameTester.test('sets zoom on resize', (game) async {
final behavior = CameraFocusingBehavior();
await game.ensureAdd(
FlameBlocProvider<GameBloc, GameState>.value(
value: GameBloc(),
children: [behavior],
),
);
game.onGameResize(game.canvasSize * 2);
expect(game.camera.zoom, equals(6.55));
});
flameTester.test(
'listenWhen only listens when status changes',
(game) async {

Loading…
Cancel
Save