From aa60ed3454036b212a5ce5a0aa4282443288c912 Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Thu, 17 Mar 2022 21:44:39 +0100 Subject: [PATCH] fix: fixed collision end from ramps --- ios/Flutter/Debug.xcconfig | 1 + ios/Flutter/Release.xcconfig | 1 + ios/Podfile | 41 +++++++++++ lib/game/components/ramp_opening.dart | 26 ++++--- test/game/components/ramp_opening_test.dart | 79 +++++++++++++++------ 5 files changed, 118 insertions(+), 30 deletions(-) create mode 100644 ios/Podfile diff --git a/ios/Flutter/Debug.xcconfig b/ios/Flutter/Debug.xcconfig index 592ceee8..ec97fc6f 100644 --- a/ios/Flutter/Debug.xcconfig +++ b/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Flutter/Release.xcconfig b/ios/Flutter/Release.xcconfig index 592ceee8..c4855bfe 100644 --- a/ios/Flutter/Release.xcconfig +++ b/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Podfile b/ios/Podfile new file mode 100644 index 00000000..1e8c3c90 --- /dev/null +++ b/ios/Podfile @@ -0,0 +1,41 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/lib/game/components/ramp_opening.dart b/lib/game/components/ramp_opening.dart index 96b1ec15..e0c95997 100644 --- a/lib/game/components/ramp_opening.dart +++ b/lib/game/components/ramp_opening.dart @@ -85,16 +85,22 @@ class RampOpeningBallContactCallback @override void end(Ball ball, Opening opening, Contact _) { - // TODO(ruimiguel): check what happens with ball that slightly touch - // Opening and goes out again. With InitialPosition change now doesn't work - // position.y comparison - /* - final isBallOutsideOpening = opening.orientation == RampOrientation.up - ? ball.body.position.y > opening.initialPosition.y - : ball.body.position.y < opening.initialPosition.y; + if (!ballsInside.contains(ball)) { + ball.layer = Layer.board; + } else { + // TODO(ruimiguel): change this code. Check what happens with ball that + // slightly touch Opening and goes out again. With InitialPosition change + // now doesn't work position.y comparison + final isBallOutsideOpening = + (opening.orientation == RampOrientation.down && + ball.body.linearVelocity.y < 0) || + (opening.orientation == RampOrientation.up && + ball.body.linearVelocity.y > 0); - if (isBallOutsideOpening) ball.layer = Layer.board; - */ - if (!ballsInside.contains(ball)) ball.layer = Layer.board; + if (isBallOutsideOpening) { + ball.layer = Layer.board; + ballsInside.remove(ball); + } + } } } diff --git a/test/game/components/ramp_opening_test.dart b/test/game/components/ramp_opening_test.dart index abd38d47..2b206e26 100644 --- a/test/game/components/ramp_opening_test.dart +++ b/test/game/components/ramp_opening_test.dart @@ -144,9 +144,6 @@ void main() { callback.begin(ball, area, MockContact()); verify(() => ball.layer = area.pathwayLayer).called(1); - - callback.end(ball, area, MockContact()); - verifyNever(() => ball.layer = Layer.board); }); flameTester.test( @@ -194,9 +191,6 @@ void main() { callback.begin(ball, area, MockContact()); verify(() => ball.layer = area.pathwayLayer).called(1); - - callback.end(ball, area, MockContact()); - verifyNever(() => ball.layer = Layer.board); }); flameTester.test( @@ -220,15 +214,12 @@ void main() { callback.begin(ball, area, MockContact()); expect(callback.ballsInside.contains(ball), isTrue); - - callback.end(ball, area, MockContact()); }, ); flameTester.test( 'removes ball from ballsInside ' - 'when a ball enters upwards into a down oriented path ' - 'but falls again outside', (game) async { + 'when a ball exits from a downward oriented ramp', (game) async { final ball = MockBall(); final body = MockBody(); final area = TestRampOpening( @@ -239,6 +230,7 @@ void main() { when(() => ball.body).thenReturn(body); when(() => body.position).thenReturn(Vector2.zero()); + when(() => body.linearVelocity).thenReturn(Vector2(0, -1)); when(() => ball.layer).thenReturn(Layer.board); await game.ready(); @@ -250,17 +242,13 @@ void main() { expect(callback.ballsInside.length, equals(1)); expect(callback.ballsInside.first, ball); - // TODO(ruimiguel): check what happens with ball that slightly touch - // Opening and goes out again. With InitialPosition change now doesn't - // work position.y comparison callback.end(ball, area, MockContact()); - //expect(callback.ballsInside.isEmpty, true); + expect(callback.ballsInside.isEmpty, true); }); flameTester.test( 'changes ball layer ' - 'when a ball enters upwards into a down oriented path ' - 'but falls again outside', (game) async { + 'when a ball exits from a downward oriented ramp', (game) async { final ball = MockBall(); final body = MockBody(); final area = TestRampOpening( @@ -271,6 +259,33 @@ void main() { when(() => ball.body).thenReturn(body); when(() => body.position).thenReturn(Vector2.zero()); + when(() => body.linearVelocity).thenReturn(Vector2(0, -1)); + when(() => ball.layer).thenReturn(Layer.board); + + await game.ready(); + await game.ensureAdd(area); + + callback.begin(ball, area, MockContact()); + verify(() => ball.layer = Layer.jetpack).called(1); + + callback.end(ball, area, MockContact()); + verify(() => ball.layer = Layer.board); + }); + + flameTester.test( + 'removes ball from ballsInside ' + 'when a ball exits from a upward oriented ramp', (game) async { + final ball = MockBall(); + final body = MockBody(); + final area = TestRampOpening( + orientation: RampOrientation.up, + pathwayLayer: Layer.jetpack, + )..initialPosition = Vector2(0, 10); + final callback = TestRampOpeningBallContactCallback(); + + when(() => ball.body).thenReturn(body); + when(() => body.position).thenReturn(Vector2.zero()); + when(() => body.linearVelocity).thenReturn(Vector2(0, 1)); when(() => ball.layer).thenReturn(Layer.board); await game.ready(); @@ -278,14 +293,38 @@ void main() { expect(callback.ballsInside.isEmpty, isTrue); + callback.begin(ball, area, MockContact()); + expect(callback.ballsInside.length, equals(1)); + expect(callback.ballsInside.first, ball); + + callback.end(ball, area, MockContact()); + expect(callback.ballsInside.isEmpty, true); + }); + + flameTester.test( + 'changes ball layer ' + 'when a ball exits from a upward oriented ramp', (game) async { + final ball = MockBall(); + final body = MockBody(); + final area = TestRampOpening( + orientation: RampOrientation.up, + pathwayLayer: Layer.jetpack, + )..initialPosition = Vector2(0, 10); + final callback = TestRampOpeningBallContactCallback(); + + when(() => ball.body).thenReturn(body); + when(() => body.position).thenReturn(Vector2.zero()); + when(() => body.linearVelocity).thenReturn(Vector2(0, 1)); + when(() => ball.layer).thenReturn(Layer.board); + + await game.ready(); + await game.ensureAdd(area); + callback.begin(ball, area, MockContact()); verify(() => ball.layer = Layer.jetpack).called(1); - // TODO(ruimiguel): check what happens with ball that slightly touch - // Opening and goes out again. With InitialPosition change now doesn't - // work position.y comparison callback.end(ball, area, MockContact()); - //verify(() => ball.layer = Layer.board); + verify(() => ball.layer = Layer.board); }); }); }