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

@ -34,6 +34,19 @@ void main() {
expect(game.descendants(), contains(behavior)); 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( flameTester.test(
'changes focus when loaded', 'changes focus when loaded',
(game) async { (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( flameTester.test(
'listenWhen only listens when status changes', 'listenWhen only listens when status changes',
(game) async { (game) async {

Loading…
Cancel
Save