diff --git a/packages/pinball_components/lib/src/components/baseboard.dart b/packages/pinball_components/lib/src/components/baseboard.dart index 47ba4666..2965d17f 100644 --- a/packages/pinball_components/lib/src/components/baseboard.dart +++ b/packages/pinball_components/lib/src/components/baseboard.dart @@ -3,6 +3,7 @@ import 'dart:math' as math; import 'package:flame/components.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball_components/pinball_components.dart'; +import 'package:pinball_flame/pinball_flame.dart'; /// {@template baseboard} /// Wing-shaped board piece to corral the [Ball] towards the [Flipper]s. diff --git a/packages/pinball_components/lib/src/components/components.dart b/packages/pinball_components/lib/src/components/components.dart index 17f3746a..2e37f927 100644 --- a/packages/pinball_components/lib/src/components/components.dart +++ b/packages/pinball_components/lib/src/components/components.dart @@ -26,7 +26,6 @@ export 'multiplier/multiplier.dart'; export 'plunger.dart'; export 'rocket.dart'; export 'score_component/score_component.dart'; -export 'shapes/shapes.dart'; export 'signpost/signpost.dart'; export 'skill_shot/skill_shot.dart'; export 'slingshot.dart'; diff --git a/packages/pinball_components/pubspec.yaml b/packages/pinball_components/pubspec.yaml index 758ebe37..c430d670 100644 --- a/packages/pinball_components/pubspec.yaml +++ b/packages/pinball_components/pubspec.yaml @@ -17,8 +17,6 @@ dependencies: ref: a50d4a1e7d9eaf66726ed1bb9894c9d495547d8f flutter: sdk: flutter - geometry: - path: ../geometry intl: ^0.17.0 pinball_flame: path: ../pinball_flame diff --git a/packages/pinball_components/test/src/components/shapes/arc_shape_test.dart b/packages/pinball_components/test/src/components/shapes/arc_shape_test.dart deleted file mode 100644 index fe778872..00000000 --- a/packages/pinball_components/test/src/components/shapes/arc_shape_test.dart +++ /dev/null @@ -1,66 +0,0 @@ -import 'dart:math' as math; -import 'package:flame/extensions.dart'; -import 'package:flame/game.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:pinball_components/src/components/components.dart'; - -void main() { - group('ArcShape', () { - test('can be instantiated', () { - expect( - ArcShape( - center: Vector2.zero(), - arcRadius: 10, - angle: 2 * math.pi, - ), - isNotNull, - ); - }); - - group('copyWith', () { - test( - 'copies correctly ' - 'when no argument specified', () { - final arcShape = ArcShape( - center: Vector2.zero(), - arcRadius: 10, - angle: 2 * math.pi, - ); - final arcShapeCopied = arcShape.copyWith(); - - for (var index = 0; index < arcShape.vertices.length; index++) { - expect( - arcShape.vertices[index], - equals(arcShapeCopied.vertices[index]), - ); - } - }); - - test( - 'copies correctly ' - 'when all arguments specified', () { - final arcShapeExpected = ArcShape( - center: Vector2.all(10), - arcRadius: 15, - angle: 2 * math.pi, - ); - final arcShapeCopied = ArcShape( - center: Vector2.zero(), - arcRadius: 10, - angle: math.pi, - ).copyWith( - center: Vector2.all(10), - arcRadius: 15, - angle: 2 * math.pi, - ); - - for (var index = 0; index < arcShapeCopied.vertices.length; index++) { - expect( - arcShapeCopied.vertices[index], - equals(arcShapeExpected.vertices[index]), - ); - } - }); - }); - }); -} diff --git a/packages/pinball_components/test/src/components/shapes/bezier_curve_shape_test.dart b/packages/pinball_components/test/src/components/shapes/bezier_curve_shape_test.dart deleted file mode 100644 index 6a6adeb7..00000000 --- a/packages/pinball_components/test/src/components/shapes/bezier_curve_shape_test.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'dart:math' as math; -import 'package:flame/extensions.dart'; -import 'package:flame/game.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:pinball_components/src/components/components.dart'; - -void main() { - group('BezierCurveShape', () { - final controlPoints = [ - Vector2(0, 0), - Vector2(10, 0), - Vector2(0, 10), - Vector2(10, 10), - ]; - - test('can be instantiated', () { - expect( - BezierCurveShape( - controlPoints: controlPoints, - ), - isNotNull, - ); - }); - - group('rotate', () { - test('returns vertices rotated', () { - const rotationAngle = 2 * math.pi; - final controlPoints = [ - Vector2(0, 0), - Vector2(10, 0), - Vector2(0, 10), - Vector2(10, 10), - ]; - - final bezierCurveShape = BezierCurveShape( - controlPoints: controlPoints, - ); - final bezierCurveShapeRotated = BezierCurveShape( - controlPoints: controlPoints, - )..rotate(rotationAngle); - - for (var index = 0; index < bezierCurveShape.vertices.length; index++) { - expect( - bezierCurveShape.vertices[index]..rotate(rotationAngle), - equals(bezierCurveShapeRotated.vertices[index]), - ); - } - }); - }); - }); -} diff --git a/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart b/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart deleted file mode 100644 index 31f45cc1..00000000 --- a/packages/pinball_components/test/src/components/shapes/ellipse_shape_test.dart +++ /dev/null @@ -1,83 +0,0 @@ -import 'dart:math' as math; -import 'package:flame/extensions.dart'; -import 'package:flame/game.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:pinball_components/src/components/components.dart'; - -void main() { - group('EllipseShape', () { - test('can be instantiated', () { - expect( - EllipseShape( - center: Vector2.zero(), - majorRadius: 10, - minorRadius: 8, - ), - isNotNull, - ); - }); - - group('rotate', () { - test('returns vertices rotated', () { - const rotationAngle = 2 * math.pi; - final ellipseShape = EllipseShape( - center: Vector2.zero(), - majorRadius: 10, - minorRadius: 8, - ); - final ellipseShapeRotated = EllipseShape( - center: Vector2.zero(), - majorRadius: 10, - minorRadius: 8, - )..rotate(rotationAngle); - - for (var index = 0; index < ellipseShape.vertices.length; index++) { - expect( - ellipseShape.vertices[index]..rotate(rotationAngle), - equals(ellipseShapeRotated.vertices[index]), - ); - } - }); - }); - - group('copyWith', () { - test('returns same shape when no properties are passed', () { - final ellipseShape = EllipseShape( - center: Vector2.zero(), - majorRadius: 10, - minorRadius: 8, - ); - final ellipseShapeCopied = ellipseShape.copyWith(); - - for (var index = 0; index < ellipseShape.vertices.length; index++) { - expect( - ellipseShape.vertices[index], - equals(ellipseShapeCopied.vertices[index]), - ); - } - }); - - test('returns object with updated properties when are passed', () { - final ellipseShapeExpected = EllipseShape( - center: Vector2.all(10), - majorRadius: 10, - minorRadius: 8, - ); - final ellipseShapeCopied = EllipseShape( - center: Vector2.zero(), - majorRadius: 10, - minorRadius: 8, - ).copyWith(center: Vector2.all(10)); - - for (var index = 0; - index < ellipseShapeCopied.vertices.length; - index++) { - expect( - ellipseShapeCopied.vertices[index], - equals(ellipseShapeExpected.vertices[index]), - ); - } - }); - }); - }); -} diff --git a/packages/pinball_flame/lib/pinball_flame.dart b/packages/pinball_flame/lib/pinball_flame.dart index bc3cae0e..c40405cb 100644 --- a/packages/pinball_flame/lib/pinball_flame.dart +++ b/packages/pinball_flame/lib/pinball_flame.dart @@ -8,4 +8,5 @@ export 'src/keyboard_input_controller.dart'; export 'src/layer.dart'; export 'src/parent_is_a.dart'; export 'src/pinball_forge2d_game.dart'; +export 'src/shapes/shapes.dart'; export 'src/sprite_animation.dart'; diff --git a/packages/pinball_components/lib/src/components/shapes/arc_shape.dart b/packages/pinball_flame/lib/src/shapes/arc_shape.dart similarity index 73% rename from packages/pinball_components/lib/src/components/shapes/arc_shape.dart rename to packages/pinball_flame/lib/src/shapes/arc_shape.dart index d58bdf1e..780fa2d3 100644 --- a/packages/pinball_components/lib/src/components/shapes/arc_shape.dart +++ b/packages/pinball_flame/lib/src/shapes/arc_shape.dart @@ -35,17 +35,4 @@ class ArcShape extends ChainShape { /// Angle in radians to rotate the arc around its [center]. final double rotation; - - ArcShape copyWith({ - Vector2? center, - double? arcRadius, - double? angle, - double? rotation, - }) => - ArcShape( - center: center ?? this.center, - arcRadius: arcRadius ?? this.arcRadius, - angle: angle ?? this.angle, - rotation: rotation ?? this.rotation, - ); } diff --git a/packages/pinball_components/lib/src/components/shapes/bezier_curve_shape.dart b/packages/pinball_flame/lib/src/shapes/bezier_curve_shape.dart similarity index 75% rename from packages/pinball_components/lib/src/components/shapes/bezier_curve_shape.dart rename to packages/pinball_flame/lib/src/shapes/bezier_curve_shape.dart index 5fcf9e08..00d1bafb 100644 --- a/packages/pinball_components/lib/src/components/shapes/bezier_curve_shape.dart +++ b/packages/pinball_flame/lib/src/shapes/bezier_curve_shape.dart @@ -1,4 +1,3 @@ -import 'package:flame/extensions.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:geometry/geometry.dart'; @@ -18,9 +17,4 @@ class BezierCurveShape extends ChainShape { /// First and last [controlPoints] set the beginning and end of the curve, /// inner points between them set its final shape. final List controlPoints; - - /// Rotates the bezier curve by a given [angle] in radians. - void rotate(double angle) { - vertices.map((vector) => vector..rotate(angle)).toList(); - } } diff --git a/packages/pinball_components/lib/src/components/shapes/ellipse_shape.dart b/packages/pinball_flame/lib/src/shapes/ellipse_shape.dart similarity index 72% rename from packages/pinball_components/lib/src/components/shapes/ellipse_shape.dart rename to packages/pinball_flame/lib/src/shapes/ellipse_shape.dart index 488d3d6f..5c523a3f 100644 --- a/packages/pinball_components/lib/src/components/shapes/ellipse_shape.dart +++ b/packages/pinball_flame/lib/src/shapes/ellipse_shape.dart @@ -34,17 +34,8 @@ class EllipseShape extends ChainShape { /// Rotates the ellipse by a given [angle] in radians. void rotate(double angle) { - vertices.map((vector) => vector..rotate(angle)).toList(); + for (final vector in vertices) { + vector.rotate(angle); + } } - - EllipseShape copyWith({ - Vector2? center, - double? majorRadius, - double? minorRadius, - }) => - EllipseShape( - center: center ?? this.center, - majorRadius: majorRadius ?? this.majorRadius, - minorRadius: minorRadius ?? this.minorRadius, - ); } diff --git a/packages/pinball_components/lib/src/components/shapes/shapes.dart b/packages/pinball_flame/lib/src/shapes/shapes.dart similarity index 100% rename from packages/pinball_components/lib/src/components/shapes/shapes.dart rename to packages/pinball_flame/lib/src/shapes/shapes.dart diff --git a/packages/pinball_flame/pubspec.yaml b/packages/pinball_flame/pubspec.yaml index 4639a080..327951a1 100644 --- a/packages/pinball_flame/pubspec.yaml +++ b/packages/pinball_flame/pubspec.yaml @@ -17,6 +17,8 @@ dependencies: ref: a50d4a1e7d9eaf66726ed1bb9894c9d495547d8f flutter: sdk: flutter + geometry: + path: ../geometry dev_dependencies: flame_test: ^1.3.0 diff --git a/packages/pinball_flame/test/src/shapes/arc_shape_test.dart b/packages/pinball_flame/test/src/shapes/arc_shape_test.dart new file mode 100644 index 00000000..0c9f0a0f --- /dev/null +++ b/packages/pinball_flame/test/src/shapes/arc_shape_test.dart @@ -0,0 +1,20 @@ +import 'dart:math' as math; +import 'package:flame/extensions.dart'; +import 'package:flame/game.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pinball_flame/pinball_flame.dart'; + +void main() { + group('ArcShape', () { + test('can be instantiated', () { + expect( + ArcShape( + center: Vector2.zero(), + arcRadius: 10, + angle: 2 * math.pi, + ), + isA(), + ); + }); + }); +} diff --git a/packages/pinball_flame/test/src/shapes/bezier_curve_shape_test.dart b/packages/pinball_flame/test/src/shapes/bezier_curve_shape_test.dart new file mode 100644 index 00000000..c2328a2f --- /dev/null +++ b/packages/pinball_flame/test/src/shapes/bezier_curve_shape_test.dart @@ -0,0 +1,22 @@ +import 'package:flame/extensions.dart'; +import 'package:flame/game.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pinball_flame/pinball_flame.dart'; + +void main() { + group('BezierCurveShape', () { + test('can be instantiated', () { + expect( + BezierCurveShape( + controlPoints: [ + Vector2(0, 0), + Vector2(10, 0), + Vector2(0, 10), + Vector2(10, 10), + ], + ), + isA(), + ); + }); + }); +} diff --git a/packages/pinball_flame/test/src/shapes/ellipse_shape_test.dart b/packages/pinball_flame/test/src/shapes/ellipse_shape_test.dart new file mode 100644 index 00000000..0bb760d9 --- /dev/null +++ b/packages/pinball_flame/test/src/shapes/ellipse_shape_test.dart @@ -0,0 +1,41 @@ +import 'dart:math' as math; +import 'package:flame/extensions.dart'; +import 'package:flame/game.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pinball_flame/pinball_flame.dart'; + +void main() { + group('EllipseShape', () { + test('can be instantiated', () { + expect( + EllipseShape( + center: Vector2.zero(), + majorRadius: 10, + minorRadius: 8, + ), + isA(), + ); + }); + + test('rotate returns vertices rotated', () { + const rotationAngle = 2 * math.pi; + final ellipseShape = EllipseShape( + center: Vector2.zero(), + majorRadius: 10, + minorRadius: 8, + ); + final ellipseShapeRotated = EllipseShape( + center: Vector2.zero(), + majorRadius: 10, + minorRadius: 8, + )..rotate(rotationAngle); + + for (var index = 0; index < ellipseShape.vertices.length; index++) { + expect( + ellipseShape.vertices[index]..rotate(rotationAngle), + equals(ellipseShapeRotated.vertices[index]), + ); + } + }); + }); +}