From 298a781c8fe481234383189b83f2f472c9f6c309 Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Sat, 14 Dec 2024 21:45:54 +0000 Subject: [PATCH] refactors renames and other stuff --- .../camera_component_example.dart | 19 ++++++++++++++++--- .../lib/src/components/mixins/snapshot.dart | 9 ++++----- packages/flame/lib/src/extensions/canvas.dart | 3 ++- .../flame/lib/src/game/notifying_vector2.dart | 2 +- .../lib/src/rendering/rotate3d_decorator.dart | 3 ++- .../lib/src/rendering/shadow3d_decorator.dart | 3 ++- .../src/rendering/transform2d_decorator.dart | 3 ++- packages/flame/lib/src/sprite_batch.dart | 3 ++- .../test/components/mixins/snapshot_test.dart | 1 - .../flame/test/extensions/matrix4_test.dart | 2 +- .../flame_forge2d/lib/body_component.dart | 3 ++- packages/flame_forge2d/pubspec.yaml | 2 +- .../src/widgets/panels/hierarchy_view.dart | 2 +- 13 files changed, 36 insertions(+), 19 deletions(-) diff --git a/examples/lib/stories/camera_and_viewport/camera_component_example.dart b/examples/lib/stories/camera_and_viewport/camera_component_example.dart index e7cb8ea6d10..4e4b045dc08 100644 --- a/examples/lib/stories/camera_and_viewport/camera_component_example.dart +++ b/examples/lib/stories/camera_and_viewport/camera_component_example.dart @@ -1,4 +1,5 @@ import 'dart:math'; +import 'dart:typed_data'; import 'package:flame/camera.dart'; import 'package:flame/components.dart'; @@ -116,13 +117,25 @@ class Bezel extends PositionComponent { const Radius.circular(5.0), ), )) - .transform((Matrix4.identity()..rotateZ(pi / 4)).storage); + .transform( + Float64List.fromList( + (Matrix4.identity()..rotateZ(pi / 4)).storage, + ), + ); connector = (Path() ..addArc(Rect.fromLTRB(-outer, -outer, outer, outer), -0.22, 0.44)) - .transform((Matrix4.identity()..rotateZ(pi / 4)).storage); + .transform( + Float64List.fromList( + (Matrix4.identity()..rotateZ(pi / 4)).storage, + ), + ); specularHighlight = (Path() ..addOval(Rect.fromLTWH(-radius * 0.8, -8, 16, radius * 0.3))) - .transform((Matrix4.identity()..rotateZ(pi / 4)).storage); + .transform( + Float64List.fromList( + (Matrix4.identity()..rotateZ(pi / 4)).storage, + ), + ); glassPaint = Paint()..color = const Color(0x1400ffae); rimBorderPaint = Paint() diff --git a/packages/flame/lib/src/components/mixins/snapshot.dart b/packages/flame/lib/src/components/mixins/snapshot.dart index a8ac48689d3..3580467438b 100644 --- a/packages/flame/lib/src/components/mixins/snapshot.dart +++ b/packages/flame/lib/src/components/mixins/snapshot.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/components.dart'; @@ -47,7 +48,7 @@ mixin Snapshot on PositionComponent { } else { final recorder = PictureRecorder(); final canvas = Canvas(recorder); - canvas.transform(transform.storage); + canvas.transform(Float64List.fromList(transform.storage)); canvas.drawPicture(_picture!); final picture = recorder.endRecording(); return picture.toImageSync(width, height); @@ -63,7 +64,7 @@ mixin Snapshot on PositionComponent { final canvas = Canvas(recorder); final matrix = transformMatrix.clone(); matrix.invert(); - canvas.transform(matrix.storage); + canvas.transform(Float64List.fromList(matrix.storage)); super.renderTree(canvas); _picture = recorder.endRecording(); return _picture!; @@ -82,9 +83,7 @@ mixin Snapshot on PositionComponent { takeSnapshot(); } canvas.save(); - canvas.transform( - transformMatrix.storage, - ); + canvas.transform(Float64List.fromList(transformMatrix.storage)); canvas.drawPicture(_picture!); canvas.restore(); } else { diff --git a/packages/flame/lib/src/extensions/canvas.dart b/packages/flame/lib/src/extensions/canvas.dart index b9e739169e8..d54478a4a66 100644 --- a/packages/flame/lib/src/extensions/canvas.dart +++ b/packages/flame/lib/src/extensions/canvas.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/palette.dart'; @@ -59,6 +60,6 @@ extension CanvasExtension on Canvas { /// Use the [Transform2D] object to [transform] the canvas. void transform2D(Transform2D transform2D) { - transform(transform2D.transformMatrix.storage); + transform(Float64List.fromList(transform2D.transformMatrix.storage)); } } diff --git a/packages/flame/lib/src/game/notifying_vector2.dart b/packages/flame/lib/src/game/notifying_vector2.dart index 649aab4cd96..7c25662931c 100644 --- a/packages/flame/lib/src/game/notifying_vector2.dart +++ b/packages/flame/lib/src/game/notifying_vector2.dart @@ -185,5 +185,5 @@ class NotifyingVector2 extends Vector2 with ChangeNotifier { } @override - Float64List get storage => super.storage.asUnmodifiableView(); + Float32List get storage => super.storage.asUnmodifiableView(); } diff --git a/packages/flame/lib/src/rendering/rotate3d_decorator.dart b/packages/flame/lib/src/rendering/rotate3d_decorator.dart index 52c4fef05ed..647fdb1d579 100644 --- a/packages/flame/lib/src/rendering/rotate3d_decorator.dart +++ b/packages/flame/lib/src/rendering/rotate3d_decorator.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/geometry.dart'; @@ -61,7 +62,7 @@ class Rotate3DDecorator extends Decorator { ..rotateY(angleY) ..rotateZ(angleZ) ..translate(-center.x, -center.y); - canvas.transform(matrix.storage); + canvas.transform(Float64List.fromList(matrix.storage)); draw(canvas); canvas.restore(); } diff --git a/packages/flame/lib/src/rendering/shadow3d_decorator.dart b/packages/flame/lib/src/rendering/shadow3d_decorator.dart index 1e00569b812..600c57cf693 100644 --- a/packages/flame/lib/src/rendering/shadow3d_decorator.dart +++ b/packages/flame/lib/src/rendering/shadow3d_decorator.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/src/palette.dart'; @@ -156,7 +157,7 @@ class Shadow3DDecorator extends Decorator { canvas.saveLayer(null, _paint!); canvas.translate(base.x + _shift, base.y); - canvas.transform(_transformMatrix!.storage); + canvas.transform(Float64List.fromList(_transformMatrix!.storage)); draw(canvas); canvas.restore(); draw(canvas); diff --git a/packages/flame/lib/src/rendering/transform2d_decorator.dart b/packages/flame/lib/src/rendering/transform2d_decorator.dart index 3a1cd83401a..5585285305f 100644 --- a/packages/flame/lib/src/rendering/transform2d_decorator.dart +++ b/packages/flame/lib/src/rendering/transform2d_decorator.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/src/components/position_component.dart'; @@ -17,7 +18,7 @@ class Transform2DDecorator extends Decorator { @override void apply(void Function(Canvas) draw, Canvas canvas) { canvas.save(); - canvas.transform(transform2d.transformMatrix.storage); + canvas.transform(Float64List.fromList(transform2d.transformMatrix.storage)); draw(canvas); canvas.restore(); } diff --git a/packages/flame/lib/src/sprite_batch.dart b/packages/flame/lib/src/sprite_batch.dart index 6b3beeec0ae..b74477ef06b 100644 --- a/packages/flame/lib/src/sprite_batch.dart +++ b/packages/flame/lib/src/sprite_batch.dart @@ -1,5 +1,6 @@ import 'dart:collection'; import 'dart:math' show pi; +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/cache.dart'; @@ -431,7 +432,7 @@ class SpriteBatch { canvas ..save() - ..transform(batchItem.matrix.storage) + ..transform(Float64List.fromList(batchItem.matrix.storage)) ..drawRect(batchItem.destination, batchItem.paint) ..drawImageRect( atlas, diff --git a/packages/flame/test/components/mixins/snapshot_test.dart b/packages/flame/test/components/mixins/snapshot_test.dart index f02805c1858..2d86e6d3e49 100644 --- a/packages/flame/test/components/mixins/snapshot_test.dart +++ b/packages/flame/test/components/mixins/snapshot_test.dart @@ -5,7 +5,6 @@ import 'package:flame/components.dart'; import 'package:flame/extensions.dart'; import 'package:flame/game.dart'; import 'package:flame_test/flame_test.dart'; -import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flame/test/extensions/matrix4_test.dart b/packages/flame/test/extensions/matrix4_test.dart index 7f33c76c90a..b4ad5bfbdf9 100644 --- a/packages/flame/test/extensions/matrix4_test.dart +++ b/packages/flame/test/extensions/matrix4_test.dart @@ -1,6 +1,6 @@ import 'dart:math'; -import 'package:flame/extensions.dart'; +import 'package:flame/extensions_matrix4.dart'; import 'package:flame_test/flame_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; diff --git a/packages/flame_forge2d/lib/body_component.dart b/packages/flame_forge2d/lib/body_component.dart index 513fab088c9..404042f0dd2 100644 --- a/packages/flame_forge2d/lib/body_component.dart +++ b/packages/flame_forge2d/lib/body_component.dart @@ -3,6 +3,7 @@ import 'dart:ui'; import 'package:flame/components.dart' hide World; import 'package:flame/effects.dart'; import 'package:flame/extensions.dart'; +import 'package:flame/extensions_matrix4.dart'; import 'package:flame/game.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter/foundation.dart'; @@ -101,7 +102,7 @@ class BodyComponent extends Component _lastAngle = angle; } canvas.save(); - canvas.transform(matrix.storage); + canvas.transform(Float64List.fromList(matrix.storage)); super.renderTree(canvas); canvas.restore(); } diff --git a/packages/flame_forge2d/pubspec.yaml b/packages/flame_forge2d/pubspec.yaml index fe1af0b87bf..232db383323 100644 --- a/packages/flame_forge2d/pubspec.yaml +++ b/packages/flame_forge2d/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: flame: ^1.22.0 flutter: sdk: flutter - forge2d: ^0.13.1 + forge2d: ^0.14.0 dev_dependencies: dartdoc: ^8.0.8 diff --git a/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart b/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart index 65e72a6c57b..0226116996a 100644 --- a/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart +++ b/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart @@ -1,4 +1,4 @@ -import 'package:flame/components.dart'; +import 'package:flame/components.dart' show Component; import 'package:flame_studio/src/core/component_tree.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';