From 0b9c1733895c4da04fb35da5735ab704647868fb Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Tue, 8 Oct 2019 13:47:43 -0700 Subject: [PATCH] Squashed commit of the following: commit 0a292cc67ea8d261057b9f9e5c32028e3436436c Author: Luigi Rosso Date: Tue Oct 8 13:39:57 2019 -0700 Bumping versions and changelogs. commit 431a98e4804efe6d073a9b55a9ce1a5f23c7ca4d Author: Luigi Rosso Date: Tue Oct 8 13:35:26 2019 -0700 Fixing up analysis issues for #169 commit 72fb6fc743ed3a241c7c51e5a8ebc90836f734ba Merge: 4d00202 dc68dea Author: Luigi Rosso Date: Tue Oct 8 13:02:17 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter commit 4d00202a4f24b2c3d581b28cb15b953ec91c9f3c Author: Luigi Rosso Date: Tue Oct 8 13:02:11 2019 -0700 Cleaning up analysis issues. commit dc68dea6d57cb504d1a867c7e4c5b6768ec5dfe2 Merge: 5ca8d49 f1d9749 Author: Luigi Rosso Date: Tue Oct 8 11:06:53 2019 -0700 Merge pull request #168 from mehmetf/master Escalate the severity of unused imports in analyzer commit f1d97496a2679f470202f17298cd76a0411d7a8c Author: Mehmet Fidanboylu Date: Tue Oct 8 10:20:58 2019 -0700 Do the same changes to flare_dart commit 64f395edf7c6f8419a7a461e46664ff3723cfa78 Author: Mehmet Fidanboylu Date: Tue Oct 8 10:17:51 2019 -0700 Escalate the severity of unused imports in analyzer commit 5ca8d49c09406d1ac62ffffd4d0c5082744be7a3 Author: Luigi Rosso Date: Mon Oct 7 11:22:38 2019 -0700 Bumping versions and changelog. commit 874ce8e0b77a8ffc3eea9027cb31e2b75437da01 Author: Luigi Rosso Date: Mon Oct 7 11:20:28 2019 -0700 Adding support for nodes inside of shapes. commit 4d06431f341b426dd5cc41529a49c115e6354c51 Author: Luigi Rosso Date: Fri Oct 4 18:06:09 2019 -0700 Introducing FlareTesting.setup(); commit 2c5f4200535d679fd3092d1b6aa15ff71d85b869 Author: Luigi Rosso Date: Fri Oct 4 13:44:25 2019 -0700 Clamping trim start/end. commit daba34d11233391e7277b157bc117b8bbb626982 Author: Luigi Rosso Date: Mon Sep 30 21:21:55 2019 +0200 Cherry picking critical lints from #1 63 and updating for pub. --- example/change_color/android/app/build.gradle | 2 +- .../change_color/android/gradle.properties | 1 + .../ios/Runner.xcodeproj/project.pbxproj | 4 - .../ios/Runner.xcodeproj/project.pbxproj | 4 - example/favorite/test/widget_test.dart | 20 -- .../penguin_dance/android/app/build.gradle | 2 +- .../penguin_dance/android/gradle.properties | 1 + .../ios/Runner.xcodeproj/project.pbxproj | 4 - example/teddy/android/app/build.gradle | 2 +- example/teddy/android/gradle.properties | 1 + flare_dart/CHANGELOG.md | 4 + flare_dart/analysis_options.yaml | 4 +- flare_dart/lib/actor.dart | 14 +- flare_dart/lib/actor_artboard.dart | 116 +++++------ flare_dart/lib/actor_axis_constraint.dart | 42 ++-- flare_dart/lib/actor_bone.dart | 10 +- flare_dart/lib/actor_bone_base.dart | 6 +- flare_dart/lib/actor_color.dart | 30 +-- flare_dart/lib/actor_component.dart | 9 +- flare_dart/lib/actor_constraint.dart | 7 +- flare_dart/lib/actor_distance_constraint.dart | 43 ++-- flare_dart/lib/actor_drawable.dart | 21 +- flare_dart/lib/actor_ellipse.dart | 35 ++-- flare_dart/lib/actor_event.dart | 4 +- flare_dart/lib/actor_flags.dart | 10 +- flare_dart/lib/actor_ik_constraint.dart | 57 +++--- flare_dart/lib/actor_image.dart | 13 +- flare_dart/lib/actor_jelly_bone.dart | 13 +- flare_dart/lib/actor_node.dart | 49 ++--- flare_dart/lib/actor_node_solo.dart | 27 +-- flare_dart/lib/actor_path.dart | 15 +- flare_dart/lib/actor_polygon.dart | 18 +- flare_dart/lib/actor_rectangle.dart | 4 +- flare_dart/lib/actor_root_bone.dart | 12 +- flare_dart/lib/actor_rotation_constraint.dart | 57 +++--- flare_dart/lib/actor_scale_constraint.dart | 68 +++---- flare_dart/lib/actor_skin.dart | 10 +- flare_dart/lib/actor_skinnable.dart | 14 +- flare_dart/lib/actor_star.dart | 4 +- flare_dart/lib/actor_targeted_constraint.dart | 3 +- .../lib/actor_transform_constraint.dart | 41 ++-- .../lib/actor_translation_constraint.dart | 63 +++--- flare_dart/lib/actor_triangle.dart | 17 +- flare_dart/lib/animation/actor_animation.dart | 74 +++---- .../lib/animation/interpolation/cubic.dart | 10 +- .../animation/interpolation/cubic_ease.dart | 36 ++-- flare_dart/lib/animation/keyframe.dart | 20 +- flare_dart/lib/animation/property_types.dart | 146 +++++++------- flare_dart/lib/block_reader.dart | 13 +- flare_dart/lib/block_types.dart | 190 +++++++++--------- flare_dart/lib/dependency_sorter.dart | 4 +- flare_dart/lib/jelly_component.dart | 68 ++++--- flare_dart/lib/json_block_reader.dart | 42 ++-- flare_dart/lib/json_reader.dart | 130 +++++++----- flare_dart/lib/math/aabb.dart | 2 +- flare_dart/lib/math/mat2d.dart | 4 +- flare_dart/lib/math/vec2d.dart | 4 +- flare_dart/lib/path_point.dart | 39 ++-- flare_dart/lib/stream_reader.dart | 2 +- flare_dart/lib/transform_space.dart | 4 +- flare_dart/pubspec.yaml | 2 +- flare_flutter/CHANGELOG.md | 4 + flare_flutter/analysis_options.yaml | 4 +- flare_flutter/lib/flare.dart | 23 +-- flare_flutter/lib/flare_cache.dart | 2 +- flare_flutter/lib/flare_controller.dart | 6 +- flare_flutter/lib/flare_controls.dart | 19 +- flare_flutter/pubspec.yaml | 2 +- 68 files changed, 870 insertions(+), 861 deletions(-) diff --git a/example/change_color/android/app/build.gradle b/example/change_color/android/app/build.gradle index 8898f0c..d91dc73 100644 --- a/example/change_color/android/app/build.gradle +++ b/example/change_color/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 27 + compileSdkVersion 28 lintOptions { disable 'InvalidPackage' diff --git a/example/change_color/android/gradle.properties b/example/change_color/android/gradle.properties index 8bd86f6..7be3d8b 100644 --- a/example/change_color/android/gradle.properties +++ b/example/change_color/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true diff --git a/example/change_color/ios/Runner.xcodeproj/project.pbxproj b/example/change_color/ios/Runner.xcodeproj/project.pbxproj index 21912b0..d7a8fb3 100644 --- a/example/change_color/ios/Runner.xcodeproj/project.pbxproj +++ b/example/change_color/ios/Runner.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -40,7 +39,6 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; @@ -73,7 +71,6 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEBA1CF902C7004384FC /* Flutter.framework */, @@ -190,7 +187,6 @@ 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/example/favorite/ios/Runner.xcodeproj/project.pbxproj b/example/favorite/ios/Runner.xcodeproj/project.pbxproj index 50d60b4..69666c2 100644 --- a/example/favorite/ios/Runner.xcodeproj/project.pbxproj +++ b/example/favorite/ios/Runner.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -40,7 +39,6 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; @@ -73,7 +71,6 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEBA1CF902C7004384FC /* Flutter.framework */, @@ -190,7 +187,6 @@ 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/example/favorite/test/widget_test.dart b/example/favorite/test/widget_test.dart index e7b4c82..728bdcc 100644 --- a/example/favorite/test/widget_test.dart +++ b/example/favorite/test/widget_test.dart @@ -5,26 +5,6 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:heart_demo/main.dart'; void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); } diff --git a/example/penguin_dance/android/app/build.gradle b/example/penguin_dance/android/app/build.gradle index 3ebc742..869280f 100644 --- a/example/penguin_dance/android/app/build.gradle +++ b/example/penguin_dance/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 27 + compileSdkVersion 28 lintOptions { disable 'InvalidPackage' diff --git a/example/penguin_dance/android/gradle.properties b/example/penguin_dance/android/gradle.properties index 8bd86f6..7be3d8b 100644 --- a/example/penguin_dance/android/gradle.properties +++ b/example/penguin_dance/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true diff --git a/example/penguin_dance/ios/Runner.xcodeproj/project.pbxproj b/example/penguin_dance/ios/Runner.xcodeproj/project.pbxproj index 5f752c4..e3e0401 100644 --- a/example/penguin_dance/ios/Runner.xcodeproj/project.pbxproj +++ b/example/penguin_dance/ios/Runner.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -40,7 +39,6 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; @@ -73,7 +71,6 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEBA1CF902C7004384FC /* Flutter.framework */, @@ -190,7 +187,6 @@ 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/example/teddy/android/app/build.gradle b/example/teddy/android/app/build.gradle index da9bfe2..3bfafe6 100644 --- a/example/teddy/android/app/build.gradle +++ b/example/teddy/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 27 + compileSdkVersion 28 lintOptions { disable 'InvalidPackage' diff --git a/example/teddy/android/gradle.properties b/example/teddy/android/gradle.properties index 8bd86f6..7be3d8b 100644 --- a/example/teddy/android/gradle.properties +++ b/example/teddy/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true diff --git a/flare_dart/CHANGELOG.md b/flare_dart/CHANGELOG.md index 10ea2d8..da4b500 100644 --- a/flare_dart/CHANGELOG.md +++ b/flare_dart/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.4.10] - 2019-10-08 13:38:26 + +- Fixing up various static analysis issues. + ## [1.4.9] - 2019-10-07 11:20:58 - Supporting Nodes inside of Shapes, effectively adding multiple transform spaces inside of a shape. diff --git a/flare_dart/analysis_options.yaml b/flare_dart/analysis_options.yaml index 2da0fe6..7f8d90e 100644 --- a/flare_dart/analysis_options.yaml +++ b/flare_dart/analysis_options.yaml @@ -2,6 +2,8 @@ analyzer: strong-mode: implicit-casts: false implicit-dynamic: false + errors: + unused_import: error linter: rules: @@ -85,7 +87,7 @@ linter: - prefer_is_empty - prefer_is_not_empty - prefer_iterable_whereType - - prefer_mixin + # - prefer_mixin - prefer_null_aware_operators - prefer_typing_uninitialized_variables - prefer_void_to_null diff --git a/flare_dart/lib/actor.dart b/flare_dart/lib/actor.dart index 929fdf2..98ca45a 100644 --- a/flare_dart/lib/actor.dart +++ b/flare_dart/lib/actor.dart @@ -121,8 +121,8 @@ abstract class Actor { if (F != 70 || L != 76 || A != 65 || R != 82 || E != 69) { Uint8List charCodes = data.buffer.asUint8List(); String stringData = String.fromCharCodes(charCodes); - var jsonActor = jsonDecode(stringData); - Map jsonObject = Map(); + dynamic jsonActor = jsonDecode(stringData); + Map jsonObject = {}; jsonObject["container"] = jsonActor; inputData = jsonObject; } @@ -131,13 +131,13 @@ abstract class Actor { _version = reader.readVersion(); StreamReader block; - while ((block = reader.readNextBlock(BlockTypesMap)) != null) { + while ((block = reader.readNextBlock(blockTypesMap)) != null) { switch (block.blockType) { - case BlockTypes.Artboards: + case BlockTypes.artboards: readArtboardsBlock(block); break; - case BlockTypes.Atlases: + case BlockTypes.atlases: List rawAtlases = await readAtlasesBlock(block, context); success = await loadAtlases(rawAtlases); break; @@ -154,12 +154,12 @@ abstract class Actor { for (int artboardIndex = 0, end = _artboards.length; artboardIndex < end; artboardIndex++) { - StreamReader artboardBlock = block.readNextBlock(BlockTypesMap); + StreamReader artboardBlock = block.readNextBlock(blockTypesMap); if (artboardBlock == null) { break; } switch (artboardBlock.blockType) { - case BlockTypes.ActorArtboard: + case BlockTypes.actorArtboard: { ActorArtboard artboard = makeArtboard(); artboard.read(artboardBlock); diff --git a/flare_dart/lib/actor_artboard.dart b/flare_dart/lib/actor_artboard.dart index 841884c..e7c3abb 100644 --- a/flare_dart/lib/actor_artboard.dart +++ b/flare_dart/lib/actor_artboard.dart @@ -36,7 +36,7 @@ import "math/vec2d.dart"; import "stream_reader.dart"; class ActorArtboard { - int _flags = ActorFlags.IsDrawOrderDirty; + int _flags = ActorFlags.isDrawOrderDirty; int _drawableNodeCount = 0; int _nodeCount = 0; int _dirtDepth = 0; @@ -69,14 +69,14 @@ class ActorArtboard { set overrideColor(Float32List value) { _overrideColor = value; for (final ActorDrawable drawable in _drawableNodes) { - addDirt(drawable, DirtyFlags.PaintDirty, true); + addDirt(drawable, DirtyFlags.paintDirty, true); } } set modulateOpacity(double value) { _modulateOpacity = value; for (final ActorDrawable drawable in _drawableNodes) { - addDirt(drawable, DirtyFlags.PaintDirty, true); + addDirt(drawable, DirtyFlags.paintDirty, true); } } @@ -119,7 +119,7 @@ class ActorArtboard { component.graphOrder = graphOrder++; component.dirtMask = 255; } - _flags |= ActorFlags.IsDirty; + _flags |= ActorFlags.isDirty; } bool addDirt(ActorComponent component, int value, bool recurse) { @@ -132,7 +132,7 @@ class ActorArtboard { int dirt = component.dirtMask | value; component.dirtMask = dirt; - _flags |= ActorFlags.IsDirty; + _flags |= ActorFlags.isDirty; component.onDirty(dirt); @@ -147,7 +147,7 @@ class ActorArtboard { } List dependents = component.dependents; if (dependents != null) { - for (ActorComponent d in dependents) { + for (final ActorComponent d in dependents) { addDirt(d, value, recurse); } } @@ -174,7 +174,7 @@ class ActorArtboard { } void markDrawOrderDirty() { - _flags |= ActorFlags.IsDrawOrderDirty; + _flags |= ActorFlags.isDrawOrderDirty; } ActorArtboard makeInstance() { @@ -267,12 +267,12 @@ class ActorArtboard { } void advance(double seconds) { - if ((_flags & ActorFlags.IsDirty) != 0) { + if ((_flags & ActorFlags.isDirty) != 0) { const int maxSteps = 100; int step = 0; int count = _dependencyOrder.length; - while ((_flags & ActorFlags.IsDirty) != 0 && step < maxSteps) { - _flags &= ~ActorFlags.IsDirty; + while ((_flags & ActorFlags.isDirty) != 0 && step < maxSteps) { + _flags &= ~ActorFlags.isDirty; // Track dirt depth here so that if something else marks // dirty, we restart. for (int i = 0; i < count; i++) { @@ -292,8 +292,8 @@ class ActorArtboard { } } - if ((_flags & ActorFlags.IsDrawOrderDirty) != 0) { - _flags &= ~ActorFlags.IsDrawOrderDirty; + if ((_flags & ActorFlags.isDrawOrderDirty) != 0) { + _flags &= ~ActorFlags.isDrawOrderDirty; if (_drawableNodes != null) { _drawableNodes.sort((a, b) => a.drawOrder.compareTo(b.drawOrder)); @@ -319,12 +319,12 @@ class ActorArtboard { _color[3] = color[3]; StreamReader block; - while ((block = reader.readNextBlock(BlockTypesMap)) != null) { + while ((block = reader.readNextBlock(blockTypesMap)) != null) { switch (block.blockType) { - case BlockTypes.Components: + case BlockTypes.components: readComponentsBlock(block); break; - case BlockTypes.Animations: + case BlockTypes.animations: readAnimationsBlock(block); break; } @@ -341,21 +341,21 @@ class ActorArtboard { for (int componentIndex = 1, end = componentCount + 1; componentIndex < end; componentIndex++) { - StreamReader nodeBlock = block.readNextBlock(BlockTypesMap); + StreamReader nodeBlock = block.readNextBlock(blockTypesMap); if (nodeBlock == null) { break; } ActorComponent component; switch (nodeBlock.blockType) { - case BlockTypes.ActorNode: + case BlockTypes.actorNode: component = ActorNode.read(this, nodeBlock, null); break; - case BlockTypes.ActorBone: + case BlockTypes.actorBone: component = ActorBone.read(this, nodeBlock, null); break; - case BlockTypes.ActorRootBone: + case BlockTypes.actorRootBone: component = ActorRootBone.read(this, nodeBlock, null); break; @@ -368,152 +368,152 @@ class ActorArtboard { // .sequenceFrames.last.atlasIndex; // Last atlasIndex is the biggest // break; - case BlockTypes.ActorImage: + case BlockTypes.actorImage: component = ActorImage.read(this, nodeBlock, actor.makeImageNode()); if ((component as ActorImage).textureIndex > actor.maxTextureIndex) { actor.maxTextureIndex = (component as ActorImage).textureIndex; } break; - case BlockTypes.ActorIKTarget: + case BlockTypes.actorIKTarget: //component = ActorIKTarget.Read(this, nodeBlock); break; - case BlockTypes.ActorEvent: + case BlockTypes.actorEvent: component = ActorEvent.read(this, nodeBlock, null); break; - case BlockTypes.CustomIntProperty: + case BlockTypes.customIntProperty: //component = CustomIntProperty.Read(this, nodeBlock); break; - case BlockTypes.CustomFloatProperty: + case BlockTypes.customFloatProperty: //component = CustomFloatProperty.Read(this, nodeBlock); break; - case BlockTypes.CustomStringProperty: + case BlockTypes.customStringProperty: //component = CustomStringProperty.Read(this, nodeBlock); break; - case BlockTypes.CustomBooleanProperty: + case BlockTypes.customBooleanProperty: //component = CustomBooleanProperty.Read(this, nodeBlock); break; - case BlockTypes.ActorColliderRectangle: + case BlockTypes.actorColliderRectangle: //component = ActorColliderRectangle.Read(this, nodeBlock); break; - case BlockTypes.ActorColliderTriangle: + case BlockTypes.actorColliderTriangle: //component = ActorColliderTriangle.Read(this, nodeBlock); break; - case BlockTypes.ActorColliderCircle: + case BlockTypes.actorColliderCircle: //component = ActorColliderCircle.Read(this, nodeBlock); break; - case BlockTypes.ActorColliderPolygon: + case BlockTypes.actorColliderPolygon: //component = ActorColliderPolygon.Read(this, nodeBlock); break; - case BlockTypes.ActorColliderLine: + case BlockTypes.actorColliderLine: //component = ActorColliderLine.Read(this, nodeBlock); break; - case BlockTypes.ActorNodeSolo: + case BlockTypes.actorNodeSolo: component = ActorNodeSolo.read(this, nodeBlock, null); break; - case BlockTypes.ActorJellyBone: + case BlockTypes.actorJellyBone: component = ActorJellyBone.read(this, nodeBlock, null); break; - case BlockTypes.JellyComponent: + case BlockTypes.jellyComponent: component = JellyComponent.read(this, nodeBlock, null); break; - case BlockTypes.ActorIKConstraint: + case BlockTypes.actorIKConstraint: component = ActorIKConstraint.read(this, nodeBlock, null); break; - case BlockTypes.ActorDistanceConstraint: + case BlockTypes.actorDistanceConstraint: component = ActorDistanceConstraint.read(this, nodeBlock, null); break; - case BlockTypes.ActorTranslationConstraint: + case BlockTypes.actorTranslationConstraint: component = ActorTranslationConstraint.read(this, nodeBlock, null); break; - case BlockTypes.ActorScaleConstraint: + case BlockTypes.actorScaleConstraint: component = ActorScaleConstraint.read(this, nodeBlock, null); break; - case BlockTypes.ActorRotationConstraint: + case BlockTypes.actorRotationConstraint: component = ActorRotationConstraint.read(this, nodeBlock, null); break; - case BlockTypes.ActorTransformConstraint: + case BlockTypes.actorTransformConstraint: component = ActorTransformConstraint.read(this, nodeBlock, null); break; - case BlockTypes.ActorShape: + case BlockTypes.actorShape: component = ActorShape.read(this, nodeBlock, actor.makeShapeNode(null)); break; - case BlockTypes.ActorPath: + case BlockTypes.actorPath: component = ActorPath.read(this, nodeBlock, actor.makePathNode()); break; - case BlockTypes.ColorFill: + case BlockTypes.colorFill: component = ColorFill.read(this, nodeBlock, actor.makeColorFill()); break; - case BlockTypes.ColorStroke: + case BlockTypes.colorStroke: component = ColorStroke.read(this, nodeBlock, actor.makeColorStroke()); break; - case BlockTypes.GradientFill: + case BlockTypes.gradientFill: component = GradientFill.read(this, nodeBlock, actor.makeGradientFill()); break; - case BlockTypes.GradientStroke: + case BlockTypes.gradientStroke: component = GradientStroke.read(this, nodeBlock, actor.makeGradientStroke()); break; - case BlockTypes.RadialGradientFill: + case BlockTypes.radialGradientFill: component = RadialGradientFill.read(this, nodeBlock, actor.makeRadialFill()); break; - case BlockTypes.RadialGradientStroke: + case BlockTypes.radialGradientStroke: component = RadialGradientStroke.read( this, nodeBlock, actor.makeRadialStroke()); break; - case BlockTypes.ActorEllipse: + case BlockTypes.actorEllipse: component = ActorEllipse.read(this, nodeBlock, actor.makeEllipse()); break; - case BlockTypes.ActorRectangle: + case BlockTypes.actorRectangle: component = ActorRectangle.read(this, nodeBlock, actor.makeRectangle()); break; - case BlockTypes.ActorTriangle: + case BlockTypes.actorTriangle: component = ActorTriangle.read(this, nodeBlock, actor.makeTriangle()); break; - case BlockTypes.ActorStar: + case BlockTypes.actorStar: component = ActorStar.read(this, nodeBlock, actor.makeStar()); break; - case BlockTypes.ActorPolygon: + case BlockTypes.actorPolygon: component = ActorPolygon.read(this, nodeBlock, actor.makePolygon()); break; - case BlockTypes.ActorSkin: + case BlockTypes.actorSkin: component = ActorComponent.read(this, nodeBlock, ActorSkin()); break; } @@ -582,9 +582,9 @@ class ActorArtboard { StreamReader animationBlock; int animationIndex = 0; - while ((animationBlock = block.readNextBlock(BlockTypesMap)) != null) { + while ((animationBlock = block.readNextBlock(blockTypesMap)) != null) { switch (animationBlock.blockType) { - case BlockTypes.Animation: + case BlockTypes.animation: ActorAnimation anim = ActorAnimation.read(animationBlock, _components); _animations[animationIndex++] = anim; @@ -594,8 +594,8 @@ class ActorArtboard { } AABB artboardAABB() { - double minX = -_origin[0] * width; - double minY = -_origin[1] * height; + double minX = -1 * _origin[0] * width; + double minY = -1 * _origin[1] * height; return AABB.fromValues(minX, minY, minX + _width, minY + height); } diff --git a/flare_dart/lib/actor_axis_constraint.dart b/flare_dart/lib/actor_axis_constraint.dart index 54b9606..a4266b3 100644 --- a/flare_dart/lib/actor_axis_constraint.dart +++ b/flare_dart/lib/actor_axis_constraint.dart @@ -1,7 +1,7 @@ import "actor_artboard.dart"; import "actor_targeted_constraint.dart"; -import "transform_space.dart"; import "stream_reader.dart"; +import "transform_space.dart"; abstract class ActorAxisConstraint extends ActorTargetedConstraint { bool _copyX = false; @@ -19,9 +19,9 @@ abstract class ActorAxisConstraint extends ActorTargetedConstraint { double _minY = 0.0; double _maxY = 0.0; - int _sourceSpace = TransformSpace.World; - int _destSpace = TransformSpace.World; - int _minMaxSpace = TransformSpace.World; + int _sourceSpace = TransformSpace.world; + int _destSpace = TransformSpace.world; + int _minMaxSpace = TransformSpace.world; ActorAxisConstraint() : super(); @@ -91,24 +91,24 @@ abstract class ActorAxisConstraint extends ActorTargetedConstraint { } @override - onDirty(int dirt) { + void onDirty(int dirt) { markDirty(); } - get copyX => _copyX; - get copyY => _copyY; - get destSpace => _destSpace; - get enableMaxX => _enableMaxX; - get enableMaxY => _enableMaxY; - get enableMinX => _enableMinX; - get enableMinY => _enableMinY; - get maxX => _maxX; - get maxY => _maxY; - get minMaxSpace => _minMaxSpace; - get minX => _minX; - get minY => _minY; - get offset => _offset; - get scaleX => _scaleX; - get scaleY => _scaleY; - get sourceSpace => _sourceSpace; + bool get copyX => _copyX; + bool get copyY => _copyY; + int get destSpace => _destSpace; + bool get enableMaxX => _enableMaxX; + bool get enableMaxY => _enableMaxY; + bool get enableMinX => _enableMinX; + bool get enableMinY => _enableMinY; + double get maxX => _maxX; + double get maxY => _maxY; + int get minMaxSpace => _minMaxSpace; + double get minX => _minX; + double get minY => _minY; + bool get offset => _offset; + double get scaleX => _scaleX; + double get scaleY => _scaleY; + int get sourceSpace => _sourceSpace; } diff --git a/flare_dart/lib/actor_bone.dart b/flare_dart/lib/actor_bone.dart index 9b2a737..9895bfa 100644 --- a/flare_dart/lib/actor_bone.dart +++ b/flare_dart/lib/actor_bone.dart @@ -1,9 +1,9 @@ -import "stream_reader.dart"; import "actor_artboard.dart"; import "actor_bone_base.dart"; import "actor_component.dart"; import "actor_node.dart"; import "jelly_component.dart"; +import "stream_reader.dart"; class ActorBone extends ActorBoneBase { ActorBone _firstBone; @@ -13,18 +13,20 @@ class ActorBone extends ActorBoneBase { return _firstBone; } + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorBone instanceNode = ActorBone(); instanceNode.copyBoneBase(this, resetArtboard); return instanceNode; } + @override void completeResolve() { super.completeResolve(); if (children == null) { return; } - for (ActorNode node in children) { + for (final ActorNode node in children) { if (node is ActorBone) { _firstBone = node; return; @@ -34,9 +36,7 @@ class ActorBone extends ActorBoneBase { static ActorBone read( ActorArtboard artboard, StreamReader reader, ActorBone node) { - if (node == null) { - node = ActorBone(); - } + node ??= ActorBone(); ActorBoneBase.read(artboard, reader, node); return node; } diff --git a/flare_dart/lib/actor_bone_base.dart b/flare_dart/lib/actor_bone_base.dart index 815ea37..e12fb25 100644 --- a/flare_dart/lib/actor_bone_base.dart +++ b/flare_dart/lib/actor_bone_base.dart @@ -1,8 +1,8 @@ -import "stream_reader.dart"; import "actor_artboard.dart"; import "actor_node.dart"; -import "math/vec2d.dart"; import "math/mat2d.dart"; +import "math/vec2d.dart"; +import "stream_reader.dart"; class ActorBoneBase extends ActorNode { double _length; @@ -19,7 +19,7 @@ class ActorBoneBase extends ActorNode { if (children == null) { return; } - for (ActorNode node in children) { + for (final ActorNode node in children) { if (node is ActorBoneBase) { node.x = value; } diff --git a/flare_dart/lib/actor_color.dart b/flare_dart/lib/actor_color.dart index d904d92..e962712 100644 --- a/flare_dart/lib/actor_color.dart +++ b/flare_dart/lib/actor_color.dart @@ -10,23 +10,23 @@ import 'math/mat2d.dart'; import "math/vec2d.dart"; import "stream_reader.dart"; -enum FillRule { EvenOdd, NonZero } -enum StrokeCap { Butt, Round, Square } -enum StrokeJoin { Miter, Round, Bevel } -enum TrimPath { Off, Sequential, Synced } +enum FillRule { evenOdd, nonZero } +enum StrokeCap { butt, round, square } +enum StrokeJoin { miter, round, bevel } +enum TrimPath { off, sequential, synced } final HashMap fillRuleLookup = HashMap.fromIterables( - [0, 1], [FillRule.EvenOdd, FillRule.NonZero]); + [0, 1], [FillRule.evenOdd, FillRule.nonZero]); final HashMap strokeCapLookup = HashMap.fromIterables( - [0, 1, 2], [StrokeCap.Butt, StrokeCap.Round, StrokeCap.Square]); + [0, 1, 2], [StrokeCap.butt, StrokeCap.round, StrokeCap.square]); final HashMap strokeJoinLookup = HashMap.fromIterables( - [0, 1, 2], [StrokeJoin.Miter, StrokeJoin.Round, StrokeJoin.Bevel]); + [0, 1, 2], [StrokeJoin.miter, StrokeJoin.round, StrokeJoin.bevel]); final HashMap trimPathLookup = HashMap.fromIterables( - [0, 1, 2], [TrimPath.Off, TrimPath.Sequential, TrimPath.Synced]); + [0, 1, 2], [TrimPath.off, TrimPath.sequential, TrimPath.synced]); abstract class ActorPaint extends ActorComponent { double _opacity = 1.0; @@ -60,7 +60,7 @@ abstract class ActorPaint extends ActorComponent { ActorShape get shape => parent as ActorShape; void markPaintDirty() { - artboard.addDirt(this, DirtyFlags.PaintDirty, false); + artboard.addDirt(this, DirtyFlags.paintDirty, false); } } @@ -111,7 +111,7 @@ abstract class ActorColor extends ActorPaint { } abstract class ActorFill { - FillRule _fillRule = FillRule.EvenOdd; + FillRule _fillRule = FillRule.evenOdd; FillRule get fillRule => _fillRule; static void read( @@ -137,15 +137,15 @@ abstract class ActorStroke { markPaintDirty(); } - StrokeCap _cap = StrokeCap.Butt; - StrokeJoin _join = StrokeJoin.Miter; + StrokeCap _cap = StrokeCap.butt; + StrokeJoin _join = StrokeJoin.miter; StrokeCap get cap => _cap; StrokeJoin get join => _join; - TrimPath _trim = TrimPath.Off; + TrimPath _trim = TrimPath.off; TrimPath get trim => _trim; - bool get isTrimmed => _trim != TrimPath.Off; + bool get isTrimmed => _trim != TrimPath.off; double _trimStart = 0.0; double get trimStart => _trimStart; @@ -188,7 +188,7 @@ abstract class ActorStroke { component._join = strokeJoinLookup[reader.readUint8("join")]; if (artboard.actor.version >= 20) { component._trim = - trimPathLookup[reader.readUint8("trim")] ?? TrimPath.Off; + trimPathLookup[reader.readUint8("trim")] ?? TrimPath.off; if (component.isTrimmed) { component._trimStart = reader.readFloat32("start"); component._trimEnd = reader.readFloat32("end"); diff --git a/flare_dart/lib/actor_component.dart b/flare_dart/lib/actor_component.dart index b3a5fa5..ae6543f 100644 --- a/flare_dart/lib/actor_component.dart +++ b/flare_dart/lib/actor_component.dart @@ -1,6 +1,6 @@ -import "stream_reader.dart"; import "actor_artboard.dart"; import "actor_node.dart"; +import "stream_reader.dart"; abstract class ActorComponent { String _name = "Unnamed"; @@ -12,11 +12,8 @@ abstract class ActorComponent { int dirtMask = 0; List dependents; - ActorComponent.withArtboard(ActorArtboard artboard) { - this.artboard = artboard; - } - - ActorComponent() {} + ActorComponent(); + ActorComponent.withArtboard(this.artboard); String get name { return _name; diff --git a/flare_dart/lib/actor_constraint.dart b/flare_dart/lib/actor_constraint.dart index 3389680..9282c79 100644 --- a/flare_dart/lib/actor_constraint.dart +++ b/flare_dart/lib/actor_constraint.dart @@ -1,6 +1,6 @@ +import "actor_artboard.dart"; import "actor_component.dart"; import "actor_node.dart"; -import "actor_artboard.dart"; import "stream_reader.dart"; abstract class ActorConstraint extends ActorComponent { @@ -19,6 +19,7 @@ abstract class ActorConstraint extends ActorComponent { markDirty(); } + @override void onDirty(int dirt) { markDirty(); } @@ -41,10 +42,12 @@ abstract class ActorConstraint extends ActorComponent { void constrain(ActorNode node); + @override void resolveComponentIndices(List components) { super.resolveComponentIndices(components); if (parent != null) { - // This works because nodes are exported in hierarchy order, so we are assured constraints get added in order as we resolve indices. + // This works because nodes are exported in hierarchy order, + // so we are assured constraints get added in order as we resolve indices. parent.addConstraint(this); } } diff --git a/flare_dart/lib/actor_distance_constraint.dart b/flare_dart/lib/actor_distance_constraint.dart index 34bf607..5ff91d5 100644 --- a/flare_dart/lib/actor_distance_constraint.dart +++ b/flare_dart/lib/actor_distance_constraint.dart @@ -1,27 +1,25 @@ import "actor_artboard.dart"; import "actor_node.dart"; import "actor_targeted_constraint.dart"; -import "stream_reader.dart"; -import "math/vec2d.dart"; import "math/mat2d.dart"; +import "math/vec2d.dart"; +import "stream_reader.dart"; class DistanceMode { - static const int Closer = 0; - static const int Further = 1; - static const int Exact = 2; + static const int closer = 0; + static const int further = 1; + static const int exact = 2; } class ActorDistanceConstraint extends ActorTargetedConstraint { double _distance = 100.0; - int _mode = DistanceMode.Closer; + int _mode = DistanceMode.closer; ActorDistanceConstraint() : super(); static ActorDistanceConstraint read(ActorArtboard artboard, StreamReader reader, ActorDistanceConstraint component) { - if (component == null) { - component = ActorDistanceConstraint(); - } + component ??= ActorDistanceConstraint(); ActorTargetedConstraint.read(artboard, reader, component); component._distance = reader.readFloat32("distance"); @@ -45,26 +43,26 @@ class ActorDistanceConstraint extends ActorTargetedConstraint { } @override - constrain(ActorNode node) { - ActorNode t = this.target; + void constrain(ActorNode node) { + ActorNode t = target as ActorNode; if (t == null) { return; } - ActorNode p = this.parent; + ActorNode p = parent; Vec2D targetTranslation = t.getWorldTranslation(Vec2D()); Vec2D ourTranslation = p.getWorldTranslation(Vec2D()); Vec2D toTarget = Vec2D.subtract(Vec2D(), ourTranslation, targetTranslation); double currentDistance = Vec2D.length(toTarget); switch (_mode) { - case DistanceMode.Closer: + case DistanceMode.closer: if (currentDistance < _distance) { return; } break; - case DistanceMode.Further: + case DistanceMode.further: if (currentDistance > _distance) { return; } @@ -85,23 +83,26 @@ class ActorDistanceConstraint extends ActorTargetedConstraint { world[5] = position[1]; } - void update(int dirt) {} - void completeResolve() {} - - get distance => _distance; - get mode => _mode; + double get distance => _distance; + int get mode => _mode; set distance(double d) { if (_distance != d) { _distance = d; - this.markDirty(); + markDirty(); } } set mode(int m) { if (_mode != m) { _mode = m; - this.markDirty(); + markDirty(); } } + + @override + void completeResolve() {} + + @override + void update(int dirt) {} } diff --git a/flare_dart/lib/actor_drawable.dart b/flare_dart/lib/actor_drawable.dart index 9f53d5e..fa8116e 100644 --- a/flare_dart/lib/actor_drawable.dart +++ b/flare_dart/lib/actor_drawable.dart @@ -2,10 +2,10 @@ import 'package:flare_dart/actor_artboard.dart'; import 'package:flare_dart/actor_shape.dart'; import 'package:flare_dart/stream_reader.dart'; -import "math/aabb.dart"; import "actor_node.dart"; +import "math/aabb.dart"; -enum BlendModes { Normal, Multiply, Screen, Additive } +enum BlendModes { normal, multiply, screen, additive } abstract class ActorDrawable extends ActorNode { List> _clipShapes; @@ -38,7 +38,11 @@ abstract class ActorDrawable extends ActorNode { ActorNode.read(artboard, reader, component); component.isHidden = !reader.readBool("isVisible"); - component.blendModeId = artboard.actor.version < 21 ? 3 : reader.readUint8("blendMode"); + if (artboard.actor.version < 21) { + component.blendModeId = 3; + } else { + component.blendModeId = reader.readUint8("blendMode"); + } component.drawOrder = reader.readUint16("drawOrder"); return component; @@ -55,12 +59,13 @@ abstract class ActorDrawable extends ActorNode { AABB computeAABB(); void initializeGraphics() {} + @override void completeResolve() { - _clipShapes = List>(); + _clipShapes = >[]; List> clippers = allClips; - for (List clips in clippers) { - List shapes = List(); - for (ActorClip clip in clips) { + for (final List clips in clippers) { + List shapes = []; + for (final ActorClip clip in clips) { clip.node.all((ActorNode node) { if (node is ActorShape) { shapes.add(node); @@ -68,7 +73,7 @@ abstract class ActorDrawable extends ActorNode { return true; }); } - if (shapes.length > 0) { + if (shapes.isNotEmpty) { _clipShapes.add(shapes); } } diff --git a/flare_dart/lib/actor_ellipse.dart b/flare_dart/lib/actor_ellipse.dart index 5550f0f..84ce985 100644 --- a/flare_dart/lib/actor_ellipse.dart +++ b/flare_dart/lib/actor_ellipse.dart @@ -1,14 +1,15 @@ -import "actor_component.dart"; import "actor_artboard.dart"; +import "actor_component.dart"; import "actor_node.dart"; -import "math/vec2d.dart"; -import "stream_reader.dart"; import "actor_path.dart"; +import "math/vec2d.dart"; import "path_point.dart"; +import "stream_reader.dart"; -const double CircleConstant = 0.55; +const double circleConstant = 0.55; class ActorEllipse extends ActorProceduralPath { + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorEllipse instance = ActorEllipse(); instance.copyPath(this, resetArtboard); @@ -20,9 +21,7 @@ class ActorEllipse extends ActorProceduralPath { static ActorEllipse read( ActorArtboard artboard, StreamReader reader, ActorEllipse component) { - if (component == null) { - component = ActorEllipse(); - } + component ??= ActorEllipse(); ActorNode.read(artboard, reader, component); @@ -36,20 +35,20 @@ class ActorEllipse extends ActorProceduralPath { List _ellipsePathPoints = []; _ellipsePathPoints.add(CubicPathPoint.fromValues( Vec2D.fromValues(0.0, -radiusY), - Vec2D.fromValues(-radiusX * CircleConstant, -radiusY), - Vec2D.fromValues(radiusX * CircleConstant, -radiusY))); + Vec2D.fromValues(-radiusX * circleConstant, -radiusY), + Vec2D.fromValues(radiusX * circleConstant, -radiusY))); _ellipsePathPoints.add(CubicPathPoint.fromValues( Vec2D.fromValues(radiusX, 0.0), - Vec2D.fromValues(radiusX, CircleConstant * -radiusY), - Vec2D.fromValues(radiusX, CircleConstant * radiusY))); + Vec2D.fromValues(radiusX, circleConstant * -radiusY), + Vec2D.fromValues(radiusX, circleConstant * radiusY))); _ellipsePathPoints.add(CubicPathPoint.fromValues( Vec2D.fromValues(0.0, radiusY), - Vec2D.fromValues(radiusX * CircleConstant, radiusY), - Vec2D.fromValues(-radiusX * CircleConstant, radiusY))); + Vec2D.fromValues(radiusX * circleConstant, radiusY), + Vec2D.fromValues(-radiusX * circleConstant, radiusY))); _ellipsePathPoints.add(CubicPathPoint.fromValues( Vec2D.fromValues(-radiusX, 0.0), - Vec2D.fromValues(-radiusX, radiusY * CircleConstant), - Vec2D.fromValues(-radiusX, -radiusY * CircleConstant))); + Vec2D.fromValues(-radiusX, radiusY * circleConstant), + Vec2D.fromValues(-radiusX, -radiusY * circleConstant))); return _ellipsePathPoints; } @@ -57,9 +56,9 @@ class ActorEllipse extends ActorProceduralPath { bool get isClosed => true; bool get doesDraw { - return !this.renderCollapsed; + return !renderCollapsed; } - double get radiusX => this.width / 2; - double get radiusY => this.height / 2; + double get radiusX => width / 2; + double get radiusY => height / 2; } diff --git a/flare_dart/lib/actor_event.dart b/flare_dart/lib/actor_event.dart index 755cd20..857e433 100644 --- a/flare_dart/lib/actor_event.dart +++ b/flare_dart/lib/actor_event.dart @@ -5,9 +5,7 @@ import "stream_reader.dart"; class ActorEvent extends ActorComponent { static ActorComponent read( ActorArtboard artboard, StreamReader reader, ActorEvent component) { - if (component == null) { - component = ActorEvent(); - } + component ??= ActorEvent(); ActorComponent.read(artboard, reader, component); diff --git a/flare_dart/lib/actor_flags.dart b/flare_dart/lib/actor_flags.dart index 448473b..d990261 100644 --- a/flare_dart/lib/actor_flags.dart +++ b/flare_dart/lib/actor_flags.dart @@ -1,10 +1,10 @@ class ActorFlags { - static const int IsDrawOrderDirty = 1 << 0; - static const int IsDirty = 1 << 1; + static const int isDrawOrderDirty = 1 << 0; + static const int isDirty = 1 << 1; } class DirtyFlags { - static const int TransformDirty = 1 << 0; - static const int WorldTransformDirty = 1 << 1; - static const int PaintDirty = 1 << 2; + static const int transformDirty = 1 << 0; + static const int worldTransformDirty = 1 << 1; + static const int paintDirty = 1 << 2; } \ No newline at end of file diff --git a/flare_dart/lib/actor_ik_constraint.dart b/flare_dart/lib/actor_ik_constraint.dart index 513e3f5..f740ef1 100644 --- a/flare_dart/lib/actor_ik_constraint.dart +++ b/flare_dart/lib/actor_ik_constraint.dart @@ -1,13 +1,13 @@ -import "actor_targeted_constraint.dart"; -import "actor_node.dart"; +import "dart:math"; +import "actor_artboard.dart"; import "actor_bone.dart"; import "actor_component.dart"; -import "actor_artboard.dart"; -import "stream_reader.dart"; -import "math/transform_components.dart"; +import "actor_node.dart"; +import "actor_targeted_constraint.dart"; import "math/mat2d.dart"; +import "math/transform_components.dart"; import "math/vec2d.dart"; -import "dart:math"; +import "stream_reader.dart"; class InfluencedBone { int boneIdx; @@ -30,14 +30,15 @@ class ActorIKConstraint extends ActorTargetedConstraint { List _fkChain; List _boneData; + @override void resolveComponentIndices(List components) { super.resolveComponentIndices(components); if (_influencedBones != null) { - for (InfluencedBone influenced in _influencedBones) { + for (final InfluencedBone influenced in _influencedBones) { influenced.bone = components[influenced.boneIdx] as ActorBone; - // Mark peer constraints, N.B. that we're not adding it to the parent bone - // as we're constraining it anyway. + // Mark peer constraints, N.B. that we're not adding it to the + // parent bone as we're constraining it anyway. if (influenced.bone != parent) { influenced.bone.addPeerConstraint(this); } @@ -45,8 +46,9 @@ class ActorIKConstraint extends ActorTargetedConstraint { } } + @override void completeResolve() { - if (_influencedBones == null || _influencedBones.length == 0) { + if (_influencedBones == null || _influencedBones.isEmpty) { return; } @@ -65,7 +67,7 @@ class ActorIKConstraint extends ActorTargetedConstraint { int idx = count - 1; while (end != null && end != start.parent) { BoneChain bc = BoneChain(); - bc.bone = end; + bc.bone = end as ActorBone; bc.angle = 0.0; bc.included = allIn; bc.transformComponents = TransformComponents(); @@ -76,8 +78,8 @@ class ActorIKConstraint extends ActorTargetedConstraint { } // Make sure bones are good. - _boneData = List(); - for (InfluencedBone bone in _influencedBones) { + _boneData = []; + for (final InfluencedBone bone in _influencedBones) { BoneChain item = _fkChain.firstWhere( (chainItem) => chainItem.bone == bone.bone, orElse: () => null); @@ -97,7 +99,7 @@ class ActorIKConstraint extends ActorTargetedConstraint { } // Finally mark dependencies. - for (InfluencedBone bone in _influencedBones) { + for (final InfluencedBone bone in _influencedBones) { // Don't mark dependency on parent as ActorComponent already does this. if (bone.bone == parent) { continue; @@ -110,15 +112,16 @@ class ActorIKConstraint extends ActorTargetedConstraint { artboard.addDependency(this, target); } - // All the first level children of the influenced bones should depend on the final bone. + // All the first level children of the influenced bones should + // depend on the final bone. BoneChain tip = _fkChain[_fkChain.length - 1]; - for (BoneChain fk in _fkChain) { + for (final BoneChain fk in _fkChain) { if (fk == tip) { continue; } ActorBone bone = fk.bone; - for (ActorNode node in bone.children) { + for (final ActorNode node in bone.children) { BoneChain item = _fkChain.firstWhere( (chainItem) => chainItem.bone == node, orElse: () => null); @@ -133,9 +136,7 @@ class ActorIKConstraint extends ActorTargetedConstraint { static ActorIKConstraint read(ActorArtboard artboard, StreamReader reader, ActorIKConstraint component) { - if (component == null) { - component = ActorIKConstraint(); - } + component ??= ActorIKConstraint(); ActorTargetedConstraint.read(artboard, reader, component); component._invertDirection = reader.readBool("isInverted"); @@ -147,7 +148,8 @@ class ActorIKConstraint extends ActorTargetedConstraint { for (int i = 0; i < numInfluencedBones; i++) { InfluencedBone ib = InfluencedBone(); ib.boneIdx = reader.readId( - ""); // No label here, we're just clearing the elements from the array. + // No label here, we're just clearing the elements from the array. + ""); component._influencedBones[i] = ib; } } @@ -155,20 +157,21 @@ class ActorIKConstraint extends ActorTargetedConstraint { return component; } + @override void constrain(ActorNode node) { - ActorNode target = this.target; + ActorNode target = this.target as ActorNode; if (target == null) { return; } Vec2D worldTargetTranslation = Vec2D(); target.getWorldTranslation(worldTargetTranslation); - if (_influencedBones.length == 0) { + if (_influencedBones.isEmpty) { return; } // Decompose the chain. - for (BoneChain item in _fkChain) { + for (final BoneChain item in _fkChain) { ActorBone bone = item.bone; Mat2D parentWorld = bone.parent.worldTransform; Mat2D.invert(item.parentWorldInverse, parentWorld); @@ -196,7 +199,7 @@ class ActorIKConstraint extends ActorTargetedConstraint { // At the end, mix the FK angle with the IK angle by strength if (strength != 1.0) { - for (BoneChain fk in _fkChain) { + for (final BoneChain fk in _fkChain) { if (!fk.included) { ActorBone bone = fk.bone; Mat2D.multiply( @@ -274,7 +277,7 @@ class ActorIKConstraint extends ActorTargetedConstraint { Vec2D pA = b1.getWorldTranslation(Vec2D()); Vec2D pC = firstChild.bone.getWorldTranslation(Vec2D()); Vec2D pB = b2.getTipWorldTranslation(Vec2D()); - ; + Vec2D pBT = Vec2D.clone(worldTargetTranslation); pA = Vec2D.transformMat2D(pA, pA, iworld); @@ -337,6 +340,7 @@ class ActorIKConstraint extends ActorTargetedConstraint { firstChild.angle = r2; } + @override ActorComponent makeInstance(ActorArtboard artboard) { ActorIKConstraint instance = ActorIKConstraint(); instance.copyIKConstraint(this, artboard); @@ -357,5 +361,6 @@ class ActorIKConstraint extends ActorTargetedConstraint { } } + @override void update(int dirt) {} } diff --git a/flare_dart/lib/actor_image.dart b/flare_dart/lib/actor_image.dart index 2d00985..9a96446 100644 --- a/flare_dart/lib/actor_image.dart +++ b/flare_dart/lib/actor_image.dart @@ -1,12 +1,12 @@ import 'dart:typed_data'; import 'package:flare_dart/actor_skinnable.dart'; -import "stream_reader.dart"; -import "math/mat2d.dart"; import "actor_artboard.dart"; import "actor_component.dart"; import "actor_drawable.dart"; import "math/aabb.dart"; +import "math/mat2d.dart"; +import "stream_reader.dart"; class SequenceFrame { final int _atlasIndex; @@ -23,9 +23,6 @@ class SequenceFrame { } class ActorImage extends ActorDrawable with ActorSkinnable { - @override - int drawIndex; - @override int drawOrder; @@ -130,9 +127,7 @@ class ActorImage extends ActorDrawable with ActorSkinnable { static ActorImage read( ActorArtboard artboard, StreamReader reader, ActorImage node) { - if (node == null) { - node = ActorImage(); - } + node ??= ActorImage(); ActorDrawable.read(artboard, reader, node); ActorSkinnable.read(artboard, reader, node); @@ -200,11 +195,13 @@ class ActorImage extends ActorDrawable with ActorSkinnable { // return node; // } + @override void resolveComponentIndices(List components) { super.resolveComponentIndices(components); resolveSkinnable(components); } + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorImage instanceNode = resetArtboard.actor.makeImageNode(); instanceNode.copyImage(this, resetArtboard); diff --git a/flare_dart/lib/actor_jelly_bone.dart b/flare_dart/lib/actor_jelly_bone.dart index ab8ccd8..648bf54 100644 --- a/flare_dart/lib/actor_jelly_bone.dart +++ b/flare_dart/lib/actor_jelly_bone.dart @@ -1,9 +1,10 @@ -import "stream_reader.dart"; import "actor_artboard.dart"; import "actor_bone_base.dart"; import "actor_component.dart"; +import "stream_reader.dart"; class ActorJellyBone extends ActorBoneBase { + @override ActorComponent makeInstance(ActorArtboard artboard) { ActorJellyBone instanceNode = ActorJellyBone(); instanceNode.copyBoneBase(this, artboard); @@ -12,12 +13,12 @@ class ActorJellyBone extends ActorBoneBase { static ActorJellyBone read( ActorArtboard artboard, StreamReader reader, ActorJellyBone node) { - if (node == null) { - node = ActorJellyBone(); - } + node ??= ActorJellyBone(); - // The Jelly Bone has a specialized read that doesn't go down the typical node path, this is because majority of the transform properties - // of the Jelly Bone are controlled by the Jelly Controller and are unnecessary for serialization. + // The Jelly Bone has a specialized read that doesn't go down the typical + // node path, this is because majority of the transform properties + // of the Jelly Bone are controlled by the Jelly Controller and are + // unnecessary for serialization. ActorComponent.read(artboard, reader, node); node.opacity = reader.readFloat32("opacity"); node.collapsedVisibility = reader.readBool("isCollapsed"); diff --git a/flare_dart/lib/actor_node.dart b/flare_dart/lib/actor_node.dart index 7e81097..ab5f6d8 100644 --- a/flare_dart/lib/actor_node.dart +++ b/flare_dart/lib/actor_node.dart @@ -1,10 +1,10 @@ -import "stream_reader.dart"; import "actor_artboard.dart"; -import "math/mat2d.dart"; -import "math/vec2d.dart"; import "actor_component.dart"; import "actor_constraint.dart"; import "actor_flags.dart"; +import "math/mat2d.dart"; +import "math/vec2d.dart"; +import "stream_reader.dart"; typedef bool NodeWalkCallback(ActorNode node); @@ -12,9 +12,7 @@ class ActorClip { int clipIdx; ActorNode node; - ActorClip(int idx) { - clipIdx = idx; - } + ActorClip(this.clipIdx); } class ActorNode extends ActorComponent { @@ -38,8 +36,8 @@ class ActorNode extends ActorComponent { List _constraints; List _peerConstraints; - static const int TransformDirty = DirtyFlags.TransformDirty; - static const int WorldTransformDirty = DirtyFlags.WorldTransformDirty; + static const int transformDirty = DirtyFlags.transformDirty; + static const int worldTransformDirty = DirtyFlags.worldTransformDirty; ActorNode(); ActorNode.withArtboard(ActorArtboard artboard) : super.withArtboard(artboard); @@ -70,7 +68,9 @@ class ActorNode extends ActorComponent { return _worldTransform; } - // N.B. this should only be done if you really know what you're doing. Generally you want to manipulate the local translation, rotation, and scale of a Node. + // N.B. this should only be done if you really know what you're doing. + // Generally you want to manipulate the local translation, rotation, + // and scale of a Node. set worldTransform(Mat2D value) { Mat2D.copy(_worldTransform, value); } @@ -177,7 +177,7 @@ class ActorNode extends ActorComponent { List> get allClips { // Find clips. - List> all = List>(); + List> all = >[]; ActorNode clipSearch = this; while (clipSearch != null) { if (clipSearch.clips != null) { @@ -194,10 +194,10 @@ class ActorNode extends ActorComponent { // Still loading? return; } - if (!artboard.addDirt(this, TransformDirty, false)) { + if (!artboard.addDirt(this, transformDirty, false)) { return; } - artboard.addDirt(this, WorldTransformDirty, true); + artboard.addDirt(this, worldTransformDirty, true); } void updateTransform() { @@ -229,9 +229,7 @@ class ActorNode extends ActorComponent { static ActorNode read( ActorArtboard artboard, StreamReader reader, ActorNode node) { - if (node == null) { - node = ActorNode(); - } + node ??= ActorNode(); ActorComponent.read(artboard, reader, node); Vec2D.copyFromList( node._translation, reader.readFloat32Array(2, "translation")); @@ -257,9 +255,7 @@ class ActorNode extends ActorComponent { node.parent._children.remove(node); } node.parent = this; - if (_children == null) { - _children = List(); - } + _children ??= []; _children.add(node); } @@ -267,6 +263,7 @@ class ActorNode extends ActorComponent { return _children; } + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorNode instanceNode = ActorNode(); instanceNode.copyNode(this, resetArtboard); @@ -294,12 +291,11 @@ class ActorNode extends ActorComponent { } } + @override void onDirty(int dirt) {} bool addConstraint(ActorConstraint constraint) { - if (_constraints == null) { - _constraints = List(); - } + _constraints ??= []; if (_constraints.contains(constraint)) { return false; } @@ -308,9 +304,7 @@ class ActorNode extends ActorComponent { } bool addPeerConstraint(ActorConstraint constraint) { - if (_peerConstraints == null) { - _peerConstraints = List(); - } + _peerConstraints ??= []; if (_peerConstraints.contains(constraint)) { return false; } @@ -326,14 +320,15 @@ class ActorNode extends ActorComponent { : _constraints + _peerConstraints) ?? []; + @override void update(int dirt) { - if ((dirt & TransformDirty) == TransformDirty) { + if ((dirt & transformDirty) == transformDirty) { updateTransform(); } - if ((dirt & WorldTransformDirty) == WorldTransformDirty) { + if ((dirt & worldTransformDirty) == worldTransformDirty) { updateWorldTransform(); if (_constraints != null) { - for (ActorConstraint constraint in _constraints) { + for (final ActorConstraint constraint in _constraints) { if (constraint.isEnabled) { constraint.constrain(this); } diff --git a/flare_dart/lib/actor_node_solo.dart b/flare_dart/lib/actor_node_solo.dart index ef33b51..da8ce52 100644 --- a/flare_dart/lib/actor_node_solo.dart +++ b/flare_dart/lib/actor_node_solo.dart @@ -1,33 +1,35 @@ +import "dart:math"; + import "actor_artboard.dart"; import "actor_component.dart"; import "actor_node.dart"; import "stream_reader.dart"; -import "dart:math"; class ActorNodeSolo extends ActorNode { int _activeChildIndex = 0; set activeChildIndex(int idx) { - if (idx != this._activeChildIndex) { - this.setActiveChildIndex(idx); + if (idx != _activeChildIndex) { + setActiveChildIndex(idx); } } int get activeChildIndex { - return this._activeChildIndex; + return _activeChildIndex; } void setActiveChildIndex(int idx) { - if (this.children != null) { - this._activeChildIndex = min(this.children.length, max(0, idx)); - for (int i = 0; i < this.children.length; i++) { - var child = this.children[i]; - bool cv = (i != (this._activeChildIndex - 1)); + if (children != null) { + _activeChildIndex = min(children.length, max(0, idx)); + for (int i = 0; i < children.length; i++) { + var child = children[i]; + bool cv = i != (_activeChildIndex - 1); child.collapsedVisibility = cv; // Setter } } } + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorNodeSolo soloInstance = ActorNodeSolo(); soloInstance.copySolo(this, resetArtboard); @@ -41,17 +43,16 @@ class ActorNodeSolo extends ActorNode { static ActorNodeSolo read( ActorArtboard artboard, StreamReader reader, ActorNodeSolo node) { - if (node == null) { - node = ActorNodeSolo(); - } + node ??= ActorNodeSolo(); ActorNode.read(artboard, reader, node); node._activeChildIndex = reader.readUint32("activeChild"); return node; } + @override void completeResolve() { super.completeResolve(); - this.setActiveChildIndex(this.activeChildIndex); + setActiveChildIndex(activeChildIndex); } } diff --git a/flare_dart/lib/actor_path.dart b/flare_dart/lib/actor_path.dart index 44ed3ae..8c795ca 100644 --- a/flare_dart/lib/actor_path.dart +++ b/flare_dart/lib/actor_path.dart @@ -221,7 +221,7 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath { @override Mat2D get pathTransform => isConnectedToBones ? null : worldTransform; - static const int VertexDeformDirty = 1 << 1; + static const int vertexDeformDirty = 1 << 1; @override List get points => _points; @@ -258,14 +258,14 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath { return; } int length = points.fold(0, (int previous, PathPoint point) { - return previous + 2 + (point.pointType == PointType.Straight ? 1 : 4); + return previous + 2 + (point.pointType == PointType.straight ? 1 : 4); }); Float32List vertices = Float32List(length); int readIdx = 0; for (final PathPoint point in points) { vertices[readIdx++] = point.translation[0]; vertices[readIdx++] = point.translation[1]; - if (point.pointType == PointType.Straight) { + if (point.pointType == PointType.straight) { // radius vertices[readIdx++] = (point as StraightPathPoint).radius; } else { @@ -284,19 +284,19 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath { if (artboard == null) { return; } - artboard.addDirt(this, VertexDeformDirty, false); + artboard.addDirt(this, vertexDeformDirty, false); } @override void update(int dirt) { if (vertexDeform != null && - (dirt & VertexDeformDirty) == VertexDeformDirty) { + (dirt & vertexDeformDirty) == vertexDeformDirty) { int readIdx = 0; for (final PathPoint point in _points) { point.translation[0] = vertexDeform[readIdx++]; point.translation[1] = vertexDeform[readIdx++]; switch (point.pointType) { - case PointType.Straight: + case PointType.straight: (point as StraightPathPoint).radius = vertexDeform[readIdx++]; break; @@ -332,7 +332,7 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath { PathPoint point; PointType type = pointTypeLookup[reader.readUint8("pointType")]; switch (type) { - case PointType.Straight: + case PointType.straight: { point = StraightPathPoint(); break; @@ -356,6 +356,7 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath { return component; } + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorPath instanceEvent = ActorPath(); instanceEvent.copyPath(this, resetArtboard); diff --git a/flare_dart/lib/actor_polygon.dart b/flare_dart/lib/actor_polygon.dart index 06a312a..2cf1dc4 100644 --- a/flare_dart/lib/actor_polygon.dart +++ b/flare_dart/lib/actor_polygon.dart @@ -1,17 +1,19 @@ import "dart:math"; + import "actor_artboard.dart"; +import "actor_component.dart"; import "actor_node.dart"; -import "math/vec2d.dart"; -import "stream_reader.dart"; import "actor_path.dart"; +import "math/vec2d.dart"; import "path_point.dart"; -import "actor_component.dart"; +import "stream_reader.dart"; class ActorPolygon extends ActorProceduralPath { int sides = 5; @override void invalidatePath() {} + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorPolygon instance = ActorPolygon(); instance.copyPolygon(this, resetArtboard); @@ -25,9 +27,7 @@ class ActorPolygon extends ActorProceduralPath { static ActorPolygon read( ActorArtboard artboard, StreamReader reader, ActorPolygon component) { - if (component == null) { - component = ActorPolygon(); - } + component ??= ActorPolygon(); ActorNode.read(artboard, reader, component); @@ -53,7 +53,7 @@ class ActorPolygon extends ActorProceduralPath { } bool get isClosed => true; - bool get doesDraw => !this.renderCollapsed; - double get radiusX => this.width / 2; - double get radiusY => this.height / 2; + bool get doesDraw => !renderCollapsed; + double get radiusX => width / 2; + double get radiusY => height / 2; } diff --git a/flare_dart/lib/actor_rectangle.dart b/flare_dart/lib/actor_rectangle.dart index 4a6a838..24f9d14 100644 --- a/flare_dart/lib/actor_rectangle.dart +++ b/flare_dart/lib/actor_rectangle.dart @@ -28,9 +28,7 @@ class ActorRectangle extends ActorProceduralPath { static ActorRectangle read( ActorArtboard artboard, StreamReader reader, ActorRectangle component) { - if (component == null) { - component = ActorRectangle(); - } + component ??= ActorRectangle(); ActorNode.read(artboard, reader, component); diff --git a/flare_dart/lib/actor_root_bone.dart b/flare_dart/lib/actor_root_bone.dart index a244646..c47f6cb 100644 --- a/flare_dart/lib/actor_root_bone.dart +++ b/flare_dart/lib/actor_root_bone.dart @@ -1,8 +1,8 @@ -import "stream_reader.dart"; import "actor_artboard.dart"; -import "actor_node.dart"; import "actor_bone.dart"; import "actor_component.dart"; +import "actor_node.dart"; +import "stream_reader.dart"; class ActorRootBone extends ActorNode { ActorBone _firstBone; @@ -11,12 +11,13 @@ class ActorRootBone extends ActorNode { return _firstBone; } + @override void completeResolve() { super.completeResolve(); if (children == null) { return; } - for (ActorNode node in children) { + for (final ActorNode node in children) { if (node is ActorBone) { _firstBone = node; return; @@ -24,6 +25,7 @@ class ActorRootBone extends ActorNode { } } + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorRootBone instanceNode = ActorRootBone(); instanceNode.copyNode(this, resetArtboard); @@ -32,9 +34,7 @@ class ActorRootBone extends ActorNode { static ActorRootBone read( ActorArtboard artboard, StreamReader reader, ActorRootBone node) { - if (node == null) { - node = ActorRootBone(); - } + node ??= ActorRootBone(); ActorNode.read(artboard, reader, node); return node; } diff --git a/flare_dart/lib/actor_rotation_constraint.dart b/flare_dart/lib/actor_rotation_constraint.dart index 23cb680..05b967c 100644 --- a/flare_dart/lib/actor_rotation_constraint.dart +++ b/flare_dart/lib/actor_rotation_constraint.dart @@ -1,34 +1,32 @@ -import "actor_targeted_constraint.dart"; -import "actor_node.dart"; -import "actor_component.dart"; +import "dart:math"; import "actor_artboard.dart"; -import "stream_reader.dart"; -import "math/transform_components.dart"; +import "actor_component.dart"; +import "actor_node.dart"; +import "actor_targeted_constraint.dart"; import "math/mat2d.dart"; -import "dart:math"; +import "math/transform_components.dart"; +import "stream_reader.dart"; import "transform_space.dart"; class ActorRotationConstraint extends ActorTargetedConstraint { - static const double PI2 = pi * 2.0; + static const double pi2 = pi * 2.0; bool _copy = false; double _scale = 1.0; bool _enableMin = false; bool _enableMax = false; - double _max = PI2; - double _min = -PI2; + double _max = pi2; + double _min = -pi2; bool _offset = false; - int _sourceSpace = TransformSpace.World; - int _destSpace = TransformSpace.World; - int _minMaxSpace = TransformSpace.World; - TransformComponents _componentsA = TransformComponents(); - TransformComponents _componentsB = TransformComponents(); + int _sourceSpace = TransformSpace.world; + int _destSpace = TransformSpace.world; + int _minMaxSpace = TransformSpace.world; + final TransformComponents _componentsA = TransformComponents(); + final TransformComponents _componentsB = TransformComponents(); static ActorRotationConstraint read(ActorArtboard artboard, StreamReader reader, ActorRotationConstraint component) { - if (component == null) { - component = ActorRotationConstraint(); - } + component ??= ActorRotationConstraint(); ActorTargetedConstraint.read(artboard, reader, component); component._copy = reader.readBool("copy"); if (component._copy) { @@ -51,8 +49,9 @@ class ActorRotationConstraint extends ActorTargetedConstraint { return component; } + @override void constrain(ActorNode node) { - ActorNode target = this.target; + ActorNode target = this.target as ActorNode; ActorNode grandParent = parent.parent; Mat2D transformA = parent.worldTransform; @@ -68,7 +67,7 @@ class ActorRotationConstraint extends ActorTargetedConstraint { _componentsB[5] = _componentsA[5]; } else { Mat2D.copy(transformB, target.worldTransform); - if (_sourceSpace == TransformSpace.Local) { + if (_sourceSpace == TransformSpace.local) { ActorNode sourceGrandParent = target.parent; if (sourceGrandParent != null) { Mat2D inverse = Mat2D(); @@ -82,7 +81,7 @@ class ActorRotationConstraint extends ActorTargetedConstraint { if (!_copy) { _componentsB.rotation = - _destSpace == TransformSpace.Local ? 1.0 : _componentsA.rotation; + _destSpace == TransformSpace.local ? 1.0 : _componentsA.rotation; } else { _componentsB.rotation *= _scale; if (_offset) { @@ -90,9 +89,10 @@ class ActorRotationConstraint extends ActorTargetedConstraint { } } - if (_destSpace == TransformSpace.Local) { + if (_destSpace == TransformSpace.local) { // Destination space is in parent transform coordinates. - // Recompose the parent local transform and get it in world, then decompose the world for interpolation. + // Recompose the parent local transform and get it in world, + // then decompose the world for interpolation. if (grandParent != null) { Mat2D.compose(transformB, _componentsB); Mat2D.multiply(transformB, grandParent.worldTransform, transformB); @@ -102,7 +102,7 @@ class ActorRotationConstraint extends ActorTargetedConstraint { } bool clampLocal = - _minMaxSpace == TransformSpace.Local && grandParent != null; + _minMaxSpace == TransformSpace.local && grandParent != null; if (clampLocal) { // Apply min max in local space, so transform to local coordinates first. Mat2D.compose(transformB, _componentsB); @@ -126,14 +126,14 @@ class ActorRotationConstraint extends ActorTargetedConstraint { Mat2D.decompose(transformB, _componentsB); } - double angleA = _componentsA.rotation % PI2; - double angleB = _componentsB.rotation % PI2; + double angleA = _componentsA.rotation % pi2; + double angleB = _componentsB.rotation % pi2; double diff = angleB - angleA; if (diff > pi) { - diff -= PI2; + diff -= pi2; } else if (diff < -pi) { - diff += PI2; + diff += pi2; } _componentsB.rotation = _componentsA.rotation + diff * strength; _componentsB.x = _componentsA.x; @@ -145,6 +145,7 @@ class ActorRotationConstraint extends ActorTargetedConstraint { Mat2D.compose(parent.worldTransform, _componentsB); } + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorRotationConstraint instance = ActorRotationConstraint(); instance.copyRotationConstraint(this, resetArtboard); @@ -168,6 +169,8 @@ class ActorRotationConstraint extends ActorTargetedConstraint { _minMaxSpace = node._minMaxSpace; } + @override void update(int dirt) {} + @override void completeResolve() {} } diff --git a/flare_dart/lib/actor_scale_constraint.dart b/flare_dart/lib/actor_scale_constraint.dart index 9386f0c..3e62066 100644 --- a/flare_dart/lib/actor_scale_constraint.dart +++ b/flare_dart/lib/actor_scale_constraint.dart @@ -1,37 +1,36 @@ import "actor_artboard.dart"; -import "actor_node.dart"; -import "stream_reader.dart"; import "actor_axis_constraint.dart"; +import 'actor_component.dart'; +import "actor_node.dart"; import "math/mat2d.dart"; import "math/transform_components.dart"; +import "stream_reader.dart"; import "transform_space.dart"; class ActorScaleConstraint extends ActorAxisConstraint { - TransformComponents _componentsA = TransformComponents(); - TransformComponents _componentsB = TransformComponents(); + final TransformComponents _componentsA = TransformComponents(); + final TransformComponents _componentsB = TransformComponents(); ActorScaleConstraint() : super(); static ActorScaleConstraint read(ActorArtboard artboard, StreamReader reader, ActorScaleConstraint component) { - if (component == null) { - component = ActorScaleConstraint(); - } + component ??= ActorScaleConstraint(); ActorAxisConstraint.read(artboard, reader, component); return component; } @override - makeInstance(ActorArtboard resetArtboard) { + ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorScaleConstraint node = ActorScaleConstraint(); node.copyAxisConstraint(this, resetArtboard); return node; } @override - constrain(ActorNode node) { - ActorNode t = this.target; - ActorNode p = this.parent; + void constrain(ActorNode node) { + ActorNode t = target as ActorNode; + ActorNode p = parent; ActorNode grandParent = p.parent; Mat2D transformA = parent.worldTransform; @@ -47,7 +46,7 @@ class ActorScaleConstraint extends ActorAxisConstraint { _componentsB[5] = _componentsA[5]; } else { Mat2D.copy(transformB, t.worldTransform); - if (sourceSpace == TransformSpace.Local) { + if (sourceSpace == TransformSpace.local) { ActorNode sourceGrandParent = t.parent; if (sourceGrandParent != null) { Mat2D inverse = Mat2D(); @@ -57,30 +56,31 @@ class ActorScaleConstraint extends ActorAxisConstraint { } Mat2D.decompose(transformB, _componentsB); - if (!this.copyX) { + if (!copyX) { _componentsB[2] = - this.destSpace == TransformSpace.Local ? 1.0 : _componentsA[2]; + destSpace == TransformSpace.local ? 1.0 : _componentsA[2]; } else { - _componentsB[2] *= this.scaleX; - if (this.offset) { + _componentsB[2] *= scaleX; + if (offset) { _componentsB[2] *= parent.scaleX; } } - if (!this.copyY) { + if (!copyY) { _componentsB[3] = - this.destSpace == TransformSpace.Local ? 0.0 : _componentsA[3]; + destSpace == TransformSpace.local ? 0.0 : _componentsA[3]; } else { - _componentsB[3] *= this.scaleY; + _componentsB[3] *= scaleY; - if (this.offset) { + if (offset) { _componentsB[3] *= parent.scaleY; } } - if (destSpace == TransformSpace.Local) { + if (destSpace == TransformSpace.local) { // Destination space is in parent transform coordinates. - // Recompose the parent local transform and get it in world, then decompose the world for interpolation. + // Recompose the parent local transform and get it in world, + // then decompose the world for interpolation. if (grandParent != null) { Mat2D.compose(transformB, _componentsB); Mat2D.multiply(transformB, grandParent.worldTransform, transformB); @@ -90,7 +90,7 @@ class ActorScaleConstraint extends ActorAxisConstraint { } bool clampLocal = - (minMaxSpace == TransformSpace.Local && grandParent != null); + minMaxSpace == TransformSpace.local && grandParent != null; if (clampLocal) { // Apply min max in local space, so transform to local coordinates first. Mat2D.compose(transformB, _componentsB); @@ -99,17 +99,17 @@ class ActorScaleConstraint extends ActorAxisConstraint { Mat2D.multiply(transformB, inverse, transformB); Mat2D.decompose(transformB, _componentsB); } - if (this.enableMaxX && _componentsB[2] > this.maxX) { - _componentsB[2] = this.maxX; + if (enableMaxX && _componentsB[2] > maxX) { + _componentsB[2] = maxX; } - if (this.enableMinX && _componentsB[2] < this.minX) { - _componentsB[2] = this.minX; + if (enableMinX && _componentsB[2] < minX) { + _componentsB[2] = minX; } - if (this.enableMaxY && _componentsB[3] > this.maxY) { - _componentsB[3] = this.maxY; + if (enableMaxY && _componentsB[3] > maxY) { + _componentsB[3] = maxY; } - if (this.enableMinY && _componentsB[3] < this.minY) { - _componentsB[3] = this.minY; + if (enableMinY && _componentsB[3] < minY) { + _componentsB[3] = minY; } if (clampLocal) { // Transform back to world. @@ -118,13 +118,13 @@ class ActorScaleConstraint extends ActorAxisConstraint { Mat2D.decompose(transformB, _componentsB); } - double ti = 1.0 - this.strength; + double ti = 1.0 - strength; _componentsB[4] = _componentsA[4]; _componentsB[0] = _componentsA[0]; _componentsB[1] = _componentsA[1]; - _componentsB[2] = _componentsA[2] * ti + _componentsB[2] * this.strength; - _componentsB[3] = _componentsA[3] * ti + _componentsB[3] * this.strength; + _componentsB[2] = _componentsA[2] * ti + _componentsB[2] * strength; + _componentsB[3] = _componentsA[3] * ti + _componentsB[3] * strength; _componentsB[5] = _componentsA[5]; Mat2D.compose(parent.worldTransform, _componentsB); diff --git a/flare_dart/lib/actor_skin.dart b/flare_dart/lib/actor_skin.dart index f58d72b..f81a4d0 100644 --- a/flare_dart/lib/actor_skin.dart +++ b/flare_dart/lib/actor_skin.dart @@ -1,9 +1,9 @@ import "dart:typed_data"; -import "actor_skinnable.dart"; import "actor_artboard.dart"; import "actor_component.dart"; -import "math/mat2d.dart"; import "actor_constraint.dart"; +import "actor_skinnable.dart"; +import "math/mat2d.dart"; class ActorSkin extends ActorComponent { Float32List _boneMatrices; @@ -39,7 +39,7 @@ class ActorSkin extends ActorComponent { Mat2D mat = Mat2D(); - for (SkinnedBone cb in connectedBones) { + for (final SkinnedBone cb in connectedBones) { if (cb.node == null) { _boneMatrices[bidx++] = 1.0; _boneMatrices[bidx++] = 0.0; @@ -74,12 +74,12 @@ class ActorSkin extends ActorComponent { artboard.addDependency(this, skinnable as ActorComponent); if (skinnable.isConnectedToBones) { List connectedBones = skinnable.connectedBones; - for (SkinnedBone skinnedBone in connectedBones) { + for (final SkinnedBone skinnedBone in connectedBones) { artboard.addDependency(this, skinnedBone.node); List constraints = skinnedBone.node.allConstraints; if (constraints != null) { - for (ActorConstraint constraint in constraints) { + for (final ActorConstraint constraint in constraints) { artboard.addDependency(this, constraint); } } diff --git a/flare_dart/lib/actor_skinnable.dart b/flare_dart/lib/actor_skinnable.dart index d9868e9..8509394 100644 --- a/flare_dart/lib/actor_skinnable.dart +++ b/flare_dart/lib/actor_skinnable.dart @@ -1,10 +1,9 @@ import 'package:flare_dart/actor_skin.dart'; - -import "stream_reader.dart"; import "actor_artboard.dart"; -import "math/mat2d.dart"; -import "actor_node.dart"; import "actor_component.dart"; +import "actor_node.dart"; +import "math/mat2d.dart"; +import "stream_reader.dart"; class SkinnedBone { int boneIdx; @@ -20,7 +19,7 @@ abstract class ActorSkinnable { List get connectedBones => _connectedBones; bool get isConnectedToBones => - _connectedBones != null && _connectedBones.length > 0; + _connectedBones != null && _connectedBones.isNotEmpty; static ActorSkinnable read( ActorArtboard artboard, StreamReader reader, ActorSkinnable node) { @@ -33,14 +32,15 @@ abstract class ActorSkinnable { SkinnedBone bc = SkinnedBone(); reader.openObject("bone"); bc.boneIdx = reader.readId("component"); - Mat2D.copyFromList(bc.bind, reader.readFloat32Array(6, "bind")); + Mat2D.copyFromList(bc.bind, reader.readFloat32Array(6, "bind")); reader.closeObject(); Mat2D.invert(bc.inverseBind, bc.bind); node._connectedBones[i] = bc; } reader.closeArray(); Mat2D worldOverride = Mat2D(); - Mat2D.copyFromList(worldOverride, reader.readFloat32Array(6, "worldTransform")); + Mat2D.copyFromList( + worldOverride, reader.readFloat32Array(6, "worldTransform")); node.worldTransformOverride = worldOverride; } else { reader.closeArray(); diff --git a/flare_dart/lib/actor_star.dart b/flare_dart/lib/actor_star.dart index 16d11de..e7cb1c4 100644 --- a/flare_dart/lib/actor_star.dart +++ b/flare_dart/lib/actor_star.dart @@ -29,9 +29,7 @@ class ActorStar extends ActorProceduralPath { static ActorStar read( ActorArtboard artboard, StreamReader reader, ActorStar component) { - if (component == null) { - component = ActorStar(); - } + component ??= ActorStar(); ActorNode.read(artboard, reader, component); diff --git a/flare_dart/lib/actor_targeted_constraint.dart b/flare_dart/lib/actor_targeted_constraint.dart index a8b8b35..c50e0dc 100644 --- a/flare_dart/lib/actor_targeted_constraint.dart +++ b/flare_dart/lib/actor_targeted_constraint.dart @@ -1,6 +1,6 @@ +import "actor_artboard.dart"; import "actor_component.dart"; import "actor_constraint.dart"; -import "actor_artboard.dart"; import "stream_reader.dart"; abstract class ActorTargetedConstraint extends ActorConstraint { @@ -11,6 +11,7 @@ abstract class ActorTargetedConstraint extends ActorConstraint { return _target; } + @override void resolveComponentIndices(List components) { super.resolveComponentIndices(components); if (_targetIdx != 0) { diff --git a/flare_dart/lib/actor_transform_constraint.dart b/flare_dart/lib/actor_transform_constraint.dart index cec2b8f..a577fac 100644 --- a/flare_dart/lib/actor_transform_constraint.dart +++ b/flare_dart/lib/actor_transform_constraint.dart @@ -1,27 +1,26 @@ import "dart:math"; import "actor_artboard.dart"; +import 'actor_component.dart'; import "actor_node.dart"; import "actor_targeted_constraint.dart"; import "math/mat2d.dart"; import "math/transform_components.dart"; -import "transform_space.dart"; import "stream_reader.dart"; +import "transform_space.dart"; const pi2 = pi * 2; class ActorTransformConstraint extends ActorTargetedConstraint { - int _sourceSpace = TransformSpace.World; - int _destSpace = TransformSpace.World; - TransformComponents _componentsA = TransformComponents(); - TransformComponents _componentsB = TransformComponents(); + int _sourceSpace = TransformSpace.world; + int _destSpace = TransformSpace.world; + final TransformComponents _componentsA = TransformComponents(); + final TransformComponents _componentsB = TransformComponents(); ActorTransformConstraint() : super(); static ActorTransformConstraint read(ActorArtboard artboard, StreamReader reader, ActorTransformConstraint component) { - if (component == null) { - component = ActorTransformConstraint(); - } + component ??= ActorTransformConstraint(); ActorTargetedConstraint.read(artboard, reader, component); component._sourceSpace = reader.readUint8("sourceSpaceId"); @@ -31,13 +30,13 @@ class ActorTransformConstraint extends ActorTargetedConstraint { } @override - makeInstance(ActorArtboard resetArtboard) { + ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorTransformConstraint node = ActorTransformConstraint(); node.copyTransformConstraint(this, resetArtboard); return node; } - copyTransformConstraint( + void copyTransformConstraint( ActorTransformConstraint node, ActorArtboard resetArtboard) { copyTargetedConstraint(node, resetArtboard); _sourceSpace = node._sourceSpace; @@ -45,8 +44,8 @@ class ActorTransformConstraint extends ActorTargetedConstraint { } @override - constrain(ActorNode node) { - ActorNode t = this.target; + void constrain(ActorNode node) { + ActorNode t = target as ActorNode; if (t == null) { return; } @@ -55,7 +54,7 @@ class ActorTransformConstraint extends ActorTargetedConstraint { Mat2D transformA = parent.worldTransform; Mat2D transformB = Mat2D.clone(t.worldTransform); - if (_sourceSpace == TransformSpace.Local) { + if (_sourceSpace == TransformSpace.local) { ActorNode grandParent = target.parent; if (grandParent != null) { Mat2D inverse = Mat2D(); @@ -63,7 +62,7 @@ class ActorTransformConstraint extends ActorTargetedConstraint { Mat2D.multiply(transformB, inverse, transformB); } } - if (_destSpace == TransformSpace.Local) { + if (_destSpace == TransformSpace.local) { ActorNode grandParent = parent.parent; if (grandParent != null) { Mat2D.multiply(transformB, grandParent.worldTransform, transformB); @@ -81,14 +80,14 @@ class ActorTransformConstraint extends ActorTargetedConstraint { diff += pi2; } - double ti = 1.0 - this.strength; + double ti = 1.0 - strength; - _componentsB[4] = angleA + diff * this.strength; - _componentsB[0] = _componentsA[0] * ti + _componentsB[0] * this.strength; - _componentsB[1] = _componentsA[1] * ti + _componentsB[1] * this.strength; - _componentsB[2] = _componentsA[2] * ti + _componentsB[2] * this.strength; - _componentsB[3] = _componentsA[3] * ti + _componentsB[3] * this.strength; - _componentsB[5] = _componentsA[5] * ti + _componentsB[5] * this.strength; + _componentsB[4] = angleA + diff * strength; + _componentsB[0] = _componentsA[0] * ti + _componentsB[0] * strength; + _componentsB[1] = _componentsA[1] * ti + _componentsB[1] * strength; + _componentsB[2] = _componentsA[2] * ti + _componentsB[2] * strength; + _componentsB[3] = _componentsA[3] * ti + _componentsB[3] * strength; + _componentsB[5] = _componentsA[5] * ti + _componentsB[5] * strength; Mat2D.compose(parent.worldTransform, _componentsB); } diff --git a/flare_dart/lib/actor_translation_constraint.dart b/flare_dart/lib/actor_translation_constraint.dart index d086d6f..05c5d9f 100644 --- a/flare_dart/lib/actor_translation_constraint.dart +++ b/flare_dart/lib/actor_translation_constraint.dart @@ -1,35 +1,34 @@ import "actor_artboard.dart"; -import "actor_node.dart"; import "actor_axis_constraint.dart"; -import "math/vec2d.dart"; +import "actor_component.dart"; +import "actor_node.dart"; import "math/mat2d.dart"; -import "transform_space.dart"; +import "math/vec2d.dart"; import "stream_reader.dart"; +import "transform_space.dart"; class ActorTranslationConstraint extends ActorAxisConstraint { ActorTranslationConstraint() : super(); static ActorTranslationConstraint read(ActorArtboard artboard, StreamReader reader, ActorTranslationConstraint component) { - if (component == null) { - component = ActorTranslationConstraint(); - } + component ??= ActorTranslationConstraint(); ActorAxisConstraint.read(artboard, reader, component); return component; } @override - makeInstance(ActorArtboard resetArtboard) { + ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorTranslationConstraint node = ActorTranslationConstraint(); node.copyAxisConstraint(this, resetArtboard); return node; } @override - constrain(ActorNode node) { - ActorNode t = this.target; - ActorNode p = this.parent; + void constrain(ActorNode node) { + ActorNode t = target as ActorNode; + ActorNode p = parent; ActorNode grandParent = p.parent; Mat2D transformA = parent.worldTransform; @@ -40,7 +39,7 @@ class ActorTranslationConstraint extends ActorAxisConstraint { Vec2D.copy(translationB, translationA); } else { Mat2D transformB = Mat2D.clone(t.worldTransform); - if (this.sourceSpace == TransformSpace.Local) { + if (sourceSpace == TransformSpace.local) { ActorNode sourceGrandParent = t.parent; if (sourceGrandParent != null) { Mat2D inverse = Mat2D(); @@ -51,27 +50,27 @@ class ActorTranslationConstraint extends ActorAxisConstraint { translationB[0] = transformB[4]; translationB[1] = transformB[5]; - if (!this.copyX) { + if (!copyX) { translationB[0] = - destSpace == TransformSpace.Local ? 0.0 : translationA[0]; + destSpace == TransformSpace.local ? 0.0 : translationA[0]; } else { - translationB[0] *= this.scaleX; - if (this.offset) { + translationB[0] *= scaleX; + if (offset) { translationB[0] += parent.translation[0]; } } - if (!this.copyY) { + if (!copyY) { translationB[1] = - destSpace == TransformSpace.Local ? 0.0 : translationA[1]; + destSpace == TransformSpace.local ? 0.0 : translationA[1]; } else { - translationB[1] *= this.scaleY; - if (this.offset) { + translationB[1] *= scaleY; + if (offset) { translationB[1] += parent.translation[1]; } } - if (destSpace == TransformSpace.Local) { + if (destSpace == TransformSpace.local) { if (grandParent != null) { Vec2D.transformMat2D( translationB, translationB, grandParent.worldTransform); @@ -80,7 +79,7 @@ class ActorTranslationConstraint extends ActorAxisConstraint { } bool clampLocal = - (minMaxSpace == TransformSpace.Local && grandParent != null); + minMaxSpace == TransformSpace.local && grandParent != null; if (clampLocal) { // Apply min max in local space, so transform to local coordinates first. Mat2D temp = Mat2D(); @@ -88,17 +87,17 @@ class ActorTranslationConstraint extends ActorAxisConstraint { // Get our target world coordinates in parent local. Vec2D.transformMat2D(translationB, translationB, temp); } - if (this.enableMaxX && translationB[0] > this.maxX) { - translationB[0] = this.maxX; + if (enableMaxX && translationB[0] > maxX) { + translationB[0] = maxX; } - if (this.enableMinX && translationB[0] < this.minX) { - translationB[0] = this.minX; + if (enableMinX && translationB[0] < minX) { + translationB[0] = minX; } - if (this.enableMaxY && translationB[1] > this.maxY) { - translationB[1] = this.maxY; + if (enableMaxY && translationB[1] > maxY) { + translationB[1] = maxY; } - if (this.enableMinY && translationB[1] < this.minY) { - translationB[1] = this.minY; + if (enableMinY && translationB[1] < minY) { + translationB[1] = minY; } if (clampLocal) { // Transform back to world. @@ -106,11 +105,11 @@ class ActorTranslationConstraint extends ActorAxisConstraint { translationB, translationB, grandParent.worldTransform); } - double ti = 1.0 - this.strength; + double ti = 1.0 - strength; // Just interpolate world translation - transformA[4] = translationA[0] * ti + translationB[0] * this.strength; - transformA[5] = translationA[1] * ti + translationB[1] * this.strength; + transformA[4] = translationA[0] * ti + translationB[0] * strength; + transformA[5] = translationA[1] * ti + translationB[1] * strength; } @override diff --git a/flare_dart/lib/actor_triangle.dart b/flare_dart/lib/actor_triangle.dart index 84924bf..ac56e41 100644 --- a/flare_dart/lib/actor_triangle.dart +++ b/flare_dart/lib/actor_triangle.dart @@ -1,15 +1,16 @@ import "actor_artboard.dart"; +import "actor_component.dart"; import "actor_node.dart"; -import "math/vec2d.dart"; -import "stream_reader.dart"; import "actor_path.dart"; +import "math/vec2d.dart"; import "path_point.dart"; -import "actor_component.dart"; +import "stream_reader.dart"; class ActorTriangle extends ActorProceduralPath { @override void invalidatePath() {} + @override ActorComponent makeInstance(ActorArtboard resetArtboard) { ActorTriangle instance = ActorTriangle(); instance.copyPath(this, resetArtboard); @@ -18,9 +19,7 @@ class ActorTriangle extends ActorProceduralPath { static ActorTriangle read( ActorArtboard artboard, StreamReader reader, ActorTriangle component) { - if (component == null) { - component = ActorTriangle(); - } + component ??= ActorTriangle(); ActorNode.read(artboard, reader, component); @@ -43,7 +42,7 @@ class ActorTriangle extends ActorProceduralPath { } bool get isClosed => true; - bool get doesDraw => !this.renderCollapsed; - double get radiusX => this.width / 2; - double get radiusY => this.height / 2; + bool get doesDraw => !renderCollapsed; + double get radiusX => width / 2; + double get radiusY => height / 2; } diff --git a/flare_dart/lib/animation/actor_animation.dart b/flare_dart/lib/animation/actor_animation.dart index 7daeeac..4ecdeaa 100644 --- a/flare_dart/lib/animation/actor_animation.dart +++ b/flare_dart/lib/animation/actor_animation.dart @@ -20,7 +20,7 @@ class PropertyAnimation { } static PropertyAnimation read(StreamReader reader, ActorComponent component) { - StreamReader propertyBlock = reader.readNextBlock(PropertyTypesMap); + StreamReader propertyBlock = reader.readNextBlock(propertyTypesMap); if (propertyBlock == null) { return null; } @@ -30,107 +30,107 @@ class PropertyAnimation { KeyFrameReader keyFrameReader; switch (propertyAnimation._type) { - case PropertyTypes.PosX: + case PropertyTypes.posX: keyFrameReader = KeyFramePosX.read; break; - case PropertyTypes.PosY: + case PropertyTypes.posY: keyFrameReader = KeyFramePosY.read; break; - case PropertyTypes.ScaleX: + case PropertyTypes.scaleX: keyFrameReader = KeyFrameScaleX.read; break; - case PropertyTypes.ScaleY: + case PropertyTypes.scaleY: keyFrameReader = KeyFrameScaleY.read; break; - case PropertyTypes.Rotation: + case PropertyTypes.rotation: keyFrameReader = KeyFrameRotation.read; break; - case PropertyTypes.Opacity: + case PropertyTypes.opacity: keyFrameReader = KeyFrameOpacity.read; break; - case PropertyTypes.DrawOrder: + case PropertyTypes.drawOrder: keyFrameReader = KeyFrameDrawOrder.read; break; - case PropertyTypes.Length: + case PropertyTypes.length: keyFrameReader = KeyFrameLength.read; break; - case PropertyTypes.ImageVertices: + case PropertyTypes.imageVertices: keyFrameReader = KeyFrameImageVertices.read; break; - case PropertyTypes.ConstraintStrength: + case PropertyTypes.constraintStrength: keyFrameReader = KeyFrameConstraintStrength.read; break; - case PropertyTypes.Trigger: + case PropertyTypes.trigger: keyFrameReader = KeyFrameTrigger.read; break; - case PropertyTypes.IntProperty: + case PropertyTypes.intProperty: keyFrameReader = KeyFrameIntProperty.read; break; - case PropertyTypes.FloatProperty: + case PropertyTypes.floatProperty: keyFrameReader = KeyFrameFloatProperty.read; break; - case PropertyTypes.StringProperty: + case PropertyTypes.stringProperty: keyFrameReader = KeyFrameStringProperty.read; break; - case PropertyTypes.BooleanProperty: + case PropertyTypes.booleanProperty: keyFrameReader = KeyFrameBooleanProperty.read; break; - case PropertyTypes.CollisionEnabled: + case PropertyTypes.collisionEnabled: keyFrameReader = KeyFrameCollisionEnabledProperty.read; break; - case PropertyTypes.ActiveChildIndex: + case PropertyTypes.activeChildIndex: keyFrameReader = KeyFrameActiveChild.read; break; - case PropertyTypes.Sequence: + case PropertyTypes.sequence: keyFrameReader = KeyFrameSequence.read; break; - case PropertyTypes.PathVertices: + case PropertyTypes.pathVertices: keyFrameReader = KeyFramePathVertices.read; break; - case PropertyTypes.FillColor: + case PropertyTypes.fillColor: keyFrameReader = KeyFrameFillColor.read; break; - case PropertyTypes.FillGradient: + case PropertyTypes.fillGradient: keyFrameReader = KeyFrameGradient.read; break; - case PropertyTypes.StrokeGradient: + case PropertyTypes.strokeGradient: keyFrameReader = KeyFrameGradient.read; break; - case PropertyTypes.FillRadial: + case PropertyTypes.fillRadial: keyFrameReader = KeyFrameRadial.read; break; - case PropertyTypes.StrokeRadial: + case PropertyTypes.strokeRadial: keyFrameReader = KeyFrameRadial.read; break; - case PropertyTypes.StrokeColor: + case PropertyTypes.strokeColor: keyFrameReader = KeyFrameStrokeColor.read; break; - case PropertyTypes.StrokeWidth: + case PropertyTypes.strokeWidth: keyFrameReader = KeyFrameStrokeWidth.read; break; - case PropertyTypes.StrokeOpacity: - case PropertyTypes.FillOpacity: + case PropertyTypes.strokeOpacity: + case PropertyTypes.fillOpacity: keyFrameReader = KeyFramePaintOpacity.read; break; - case PropertyTypes.ShapeWidth: + case PropertyTypes.shapeWidth: keyFrameReader = KeyFrameShapeWidth.read; break; - case PropertyTypes.ShapeHeight: + case PropertyTypes.shapeHeight: keyFrameReader = KeyFrameShapeHeight.read; break; - case PropertyTypes.CornerRadius: + case PropertyTypes.cornerRadius: keyFrameReader = KeyFrameCornerRadius.read; break; - case PropertyTypes.InnerRadius: + case PropertyTypes.innerRadius: keyFrameReader = KeyFrameInnerRadius.read; break; - case PropertyTypes.StrokeStart: + case PropertyTypes.strokeStart: keyFrameReader = KeyFrameStrokeStart.read; break; - case PropertyTypes.StrokeEnd: + case PropertyTypes.strokeEnd: keyFrameReader = KeyFrameStrokeEnd.read; break; - case PropertyTypes.StrokeOffset: + case PropertyTypes.strokeOffset: keyFrameReader = KeyFrameStrokeOffset.read; break; } @@ -306,7 +306,7 @@ class ActorAnimation { ComponentAnimation keyedComponent = _triggerComponents[i]; for (final PropertyAnimation property in keyedComponent.properties) { switch (property.propertyType) { - case PropertyTypes.Trigger: + case PropertyTypes.trigger: List keyFrames = property.keyFrames; int kfl = keyFrames.length; diff --git a/flare_dart/lib/animation/interpolation/cubic.dart b/flare_dart/lib/animation/interpolation/cubic.dart index 6fac6aa..72d2146 100644 --- a/flare_dart/lib/animation/interpolation/cubic.dart +++ b/flare_dart/lib/animation/interpolation/cubic.dart @@ -1,16 +1,20 @@ -import "./interpolator.dart"; import "../../stream_reader.dart"; +import "./interpolator.dart"; import "cubic_ease.dart"; class CubicInterpolator extends Interpolator { CubicEase _cubic; + @override double getEasedMix(double mix) { return _cubic.ease(mix); } bool read(StreamReader reader) { - _cubic = CubicEase.make(reader.readFloat32("cubicX1"), reader.readFloat32("cubicY1"), - reader.readFloat32("cubicX2"), reader.readFloat32("cubicY2")); + _cubic = CubicEase.make( + reader.readFloat32("cubicX1"), + reader.readFloat32("cubicY1"), + reader.readFloat32("cubicX2"), + reader.readFloat32("cubicY2")); return true; } } diff --git a/flare_dart/lib/animation/interpolation/cubic_ease.dart b/flare_dart/lib/animation/interpolation/cubic_ease.dart index 975aa41..d39b003 100644 --- a/flare_dart/lib/animation/interpolation/cubic_ease.dart +++ b/flare_dart/lib/animation/interpolation/cubic_ease.dart @@ -1,13 +1,13 @@ import 'dart:typed_data'; // Implements https://github.com/gre/bezier-easing/blob/master/src/index.js -const int NewtonIterations = 4; -const double NewtonMinSlope = 0.001; -const double SubdivisionPrecision = 0.0000001; -const int SubdivisionMaxIterations = 10; +const int newtonIterations = 4; +const double newtonMinSlope = 0.001; +const double subdivisionPrecision = 0.0000001; +const int subdivisionMaxIterations = 10; -const int SplineTableSize = 11; -const double SampleStepSize = 1.0 / (SplineTableSize - 1.0); +const int splineTableSize = 11; +const double sampleStepSize = 1.0 / (splineTableSize - 1.0); // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. double calcBezier(double aT, double aA1, double aA2) { @@ -24,7 +24,7 @@ double getSlope(double aT, double aA1, double aA2) { } double newtonRaphsonIterate(double aX, double aGuessT, double mX1, double mX2) { - for (int i = 0; i < NewtonIterations; ++i) { + for (int i = 0; i < newtonIterations; ++i) { double currentSlope = getSlope(aGuessT, mX1, mX2); if (currentSlope == 0.0) { return aGuessT; @@ -59,32 +59,32 @@ class Cubic extends CubicEase { final double x1, y1, x2, y2; Cubic(this.x1, this.y1, this.x2, this.y2) { // Precompute values table - _values = Float64List(SplineTableSize); - for (int i = 0; i < SplineTableSize; ++i) { - _values[i] = calcBezier(i * SampleStepSize, x1, x2); + _values = Float64List(splineTableSize); + for (int i = 0; i < splineTableSize; ++i) { + _values[i] = calcBezier(i * sampleStepSize, x1, x2); } } double getT(double x) { double intervalStart = 0.0; int currentSample = 1; - int lastSample = SplineTableSize - 1; + int lastSample = splineTableSize - 1; for (; currentSample != lastSample && _values[currentSample] <= x; ++currentSample) { - intervalStart += SampleStepSize; + intervalStart += sampleStepSize; } --currentSample; // Interpolate to provide an initial guess for t var dist = (x - _values[currentSample]) / (_values[currentSample + 1] - _values[currentSample]); - var guessForT = intervalStart + dist * SampleStepSize; + var guessForT = intervalStart + dist * sampleStepSize; var initialSlope = getSlope(guessForT, x1, x2); - if (initialSlope >= NewtonMinSlope) { - for (int i = 0; i < NewtonIterations; ++i) { + if (initialSlope >= newtonMinSlope) { + for (int i = 0; i < newtonIterations; ++i) { double currentSlope = getSlope(guessForT, x1, x2); if (currentSlope == 0.0) { return guessForT; @@ -96,7 +96,7 @@ class Cubic extends CubicEase { } else if (initialSlope == 0.0) { return guessForT; } else { - double aB = intervalStart + SampleStepSize; + double aB = intervalStart + sampleStepSize; double currentX, currentT; int i = 0; do { @@ -107,8 +107,8 @@ class Cubic extends CubicEase { } else { intervalStart = currentT; } - } while (currentX.abs() > SubdivisionPrecision && - ++i < SubdivisionMaxIterations); + } while (currentX.abs() > subdivisionPrecision && + ++i < subdivisionMaxIterations); return currentT; } } diff --git a/flare_dart/lib/animation/keyframe.dart b/flare_dart/lib/animation/keyframe.dart index 55c77e2..a04847c 100644 --- a/flare_dart/lib/animation/keyframe.dart +++ b/flare_dart/lib/animation/keyframe.dart @@ -20,7 +20,7 @@ import "./interpolation/hold.dart"; import "./interpolation/interpolator.dart"; import "./interpolation/linear.dart"; -enum InterpolationTypes { Hold, Linear, Cubic } +enum InterpolationTypes { hold, linear, cubic } HashMap interpolationTypesLookup = HashMap.fromIterables([ @@ -28,9 +28,9 @@ HashMap interpolationTypesLookup = 1, 2 ], [ - InterpolationTypes.Hold, - InterpolationTypes.Linear, - InterpolationTypes.Cubic + InterpolationTypes.hold, + InterpolationTypes.linear, + InterpolationTypes.cubic ]); abstract class KeyFrame { @@ -66,16 +66,16 @@ abstract class KeyFrameWithInterpolation extends KeyFrame { int type = reader.readUint8("interpolatorType"); InterpolationTypes actualType = interpolationTypesLookup[type]; - actualType ??= InterpolationTypes.Linear; + actualType ??= InterpolationTypes.linear; switch (actualType) { - case InterpolationTypes.Hold: + case InterpolationTypes.hold: frame._interpolator = HoldInterpolator.instance; break; - case InterpolationTypes.Linear: + case InterpolationTypes.linear: frame._interpolator = LinearInterpolator.instance; break; - case InterpolationTypes.Cubic: + case InterpolationTypes.cubic: { CubicInterpolator interpolator = CubicInterpolator(); if (interpolator.read(reader)) { @@ -703,7 +703,7 @@ class KeyFramePathVertices extends KeyFrameWithInterpolation { ActorPath pathNode = component as ActorPath; int length = pathNode.points.fold(0, (int previous, PathPoint point) { - return previous + 2 + (point.pointType == PointType.Straight ? 1 : 4); + return previous + 2 + (point.pointType == PointType.straight ? 1 : 4); }); frame._vertices = Float32List(length); int readIdx = 0; @@ -711,7 +711,7 @@ class KeyFramePathVertices extends KeyFrameWithInterpolation { for (final PathPoint point in pathNode.points) { frame._vertices[readIdx++] = reader.readFloat32("translationX"); frame._vertices[readIdx++] = reader.readFloat32("translationY"); - if (point.pointType == PointType.Straight) { + if (point.pointType == PointType.straight) { // radius frame._vertices[readIdx++] = reader.readFloat32("radius"); } else { diff --git a/flare_dart/lib/animation/property_types.dart b/flare_dart/lib/animation/property_types.dart index 2106e07..c2a9e43 100644 --- a/flare_dart/lib/animation/property_types.dart +++ b/flare_dart/lib/animation/property_types.dart @@ -1,77 +1,77 @@ class PropertyTypes { - static const int Unknown = 0; - static const int PosX = 1; - static const int PosY = 2; - static const int ScaleX = 3; - static const int ScaleY = 4; - static const int Rotation = 5; - static const int Opacity = 6; - static const int DrawOrder = 7; - static const int Length = 8; - static const int ImageVertices = 9; - static const int ConstraintStrength = 10; - static const int Trigger = 11; - static const int IntProperty = 12; - static const int FloatProperty = 13; - static const int StringProperty = 14; - static const int BooleanProperty = 15; - static const int CollisionEnabled = 16; - static const int Sequence = 17; - static const int ActiveChildIndex = 18; - static const int PathVertices = 19; - static const int FillColor = 20; - static const int FillGradient = 21; - static const int FillRadial = 22; - static const int StrokeColor = 23; - static const int StrokeGradient = 24; - static const int StrokeRadial = 25; - static const int StrokeWidth = 26; - static const int StrokeOpacity = 27; - static const int FillOpacity = 28; - static const int ShapeWidth = 29; - static const int ShapeHeight = 30; - static const int CornerRadius = 31; - static const int InnerRadius = 32; - static const int StrokeStart = 33; - static const int StrokeEnd = 34; - static const int StrokeOffset = 35; + static const int unknown = 0; + static const int posX = 1; + static const int posY = 2; + static const int scaleX = 3; + static const int scaleY = 4; + static const int rotation = 5; + static const int opacity = 6; + static const int drawOrder = 7; + static const int length = 8; + static const int imageVertices = 9; + static const int constraintStrength = 10; + static const int trigger = 11; + static const int intProperty = 12; + static const int floatProperty = 13; + static const int stringProperty = 14; + static const int booleanProperty = 15; + static const int collisionEnabled = 16; + static const int sequence = 17; + static const int activeChildIndex = 18; + static const int pathVertices = 19; + static const int fillColor = 20; + static const int fillGradient = 21; + static const int fillRadial = 22; + static const int strokeColor = 23; + static const int strokeGradient = 24; + static const int strokeRadial = 25; + static const int strokeWidth = 26; + static const int strokeOpacity = 27; + static const int fillOpacity = 28; + static const int shapeWidth = 29; + static const int shapeHeight = 30; + static const int cornerRadius = 31; + static const int innerRadius = 32; + static const int strokeStart = 33; + static const int strokeEnd = 34; + static const int strokeOffset = 35; } -const Map PropertyTypesMap = { - "unknown": PropertyTypes.Unknown, - "posX": PropertyTypes.PosX, - "posY": PropertyTypes.PosY, - "scaleX": PropertyTypes.ScaleX, - "scaleY": PropertyTypes.ScaleY, - "rotation": PropertyTypes.Rotation, - "opacity": PropertyTypes.Opacity, - "drawOrder": PropertyTypes.DrawOrder, - "length": PropertyTypes.Length, - "vertices": PropertyTypes.ImageVertices, - "strength": PropertyTypes.ConstraintStrength, - "trigger": PropertyTypes.Trigger, - "intValue": PropertyTypes.IntProperty, - "floatValue": PropertyTypes.FloatProperty, - "stringValue": PropertyTypes.StringProperty, - "boolValue": PropertyTypes.BooleanProperty, - "isCollisionEnabled": PropertyTypes.CollisionEnabled, - "sequence": PropertyTypes.Sequence, - "activeChild": PropertyTypes.ActiveChildIndex, - "pathVertices": PropertyTypes.PathVertices, - "fillColor": PropertyTypes.FillColor, - "fillGradient": PropertyTypes.FillGradient, - "fillRadial": PropertyTypes.FillRadial, - "strokeColor": PropertyTypes.StrokeColor, - "strokeGradient": PropertyTypes.StrokeGradient, - "strokeRadial": PropertyTypes.StrokeRadial, - "strokeWidth": PropertyTypes.StrokeWidth, - "strokeOpacity": PropertyTypes.StrokeOpacity, - "fillOpacity": PropertyTypes.FillOpacity, - "width": PropertyTypes.ShapeWidth, - "height": PropertyTypes.ShapeHeight, - "cornerRadius": PropertyTypes.CornerRadius, - "innerRadius": PropertyTypes.InnerRadius, - "strokeStart": PropertyTypes.StrokeStart, - "strokeEnd": PropertyTypes.StrokeEnd, - "strokeOffset": PropertyTypes.StrokeOffset, +const Map propertyTypesMap = { + "unknown": PropertyTypes.unknown, + "posX": PropertyTypes.posX, + "posY": PropertyTypes.posY, + "scaleX": PropertyTypes.scaleX, + "scaleY": PropertyTypes.scaleY, + "rotation": PropertyTypes.rotation, + "opacity": PropertyTypes.opacity, + "drawOrder": PropertyTypes.drawOrder, + "length": PropertyTypes.length, + "vertices": PropertyTypes.imageVertices, + "strength": PropertyTypes.constraintStrength, + "trigger": PropertyTypes.trigger, + "intValue": PropertyTypes.intProperty, + "floatValue": PropertyTypes.floatProperty, + "stringValue": PropertyTypes.stringProperty, + "boolValue": PropertyTypes.booleanProperty, + "isCollisionEnabled": PropertyTypes.collisionEnabled, + "sequence": PropertyTypes.sequence, + "activeChild": PropertyTypes.activeChildIndex, + "pathVertices": PropertyTypes.pathVertices, + "fillColor": PropertyTypes.fillColor, + "fillGradient": PropertyTypes.fillGradient, + "fillRadial": PropertyTypes.fillRadial, + "strokeColor": PropertyTypes.strokeColor, + "strokeGradient": PropertyTypes.strokeGradient, + "strokeRadial": PropertyTypes.strokeRadial, + "strokeWidth": PropertyTypes.strokeWidth, + "strokeOpacity": PropertyTypes.strokeOpacity, + "fillOpacity": PropertyTypes.fillOpacity, + "width": PropertyTypes.shapeWidth, + "height": PropertyTypes.shapeHeight, + "cornerRadius": PropertyTypes.cornerRadius, + "innerRadius": PropertyTypes.innerRadius, + "strokeStart": PropertyTypes.strokeStart, + "strokeEnd": PropertyTypes.strokeEnd, + "strokeOffset": PropertyTypes.strokeOffset, }; diff --git a/flare_dart/lib/block_reader.dart b/flare_dart/lib/block_reader.dart index 4cc823b..526214b 100644 --- a/flare_dart/lib/block_reader.dart +++ b/flare_dart/lib/block_reader.dart @@ -1,5 +1,5 @@ -import "binary_reader.dart"; import 'dart:typed_data'; +import "binary_reader.dart"; class BlockReader extends BinaryReader { @override @@ -9,18 +9,17 @@ class BlockReader extends BinaryReader { blockType = 0; } - BlockReader.fromBlock(int type, ByteData stream) : super(stream) { - blockType = type; - } + BlockReader.fromBlock(this.blockType, ByteData stream) : super(stream); - // A block is defined as a TLV with type of one byte, length of 4 bytes, and then the value following. + // A block is defined as a TLV with type of one byte, length of 4 bytes, + // and then the value following. + @override BlockReader readNextBlock(Map types) { - if (isEOF()) { return null; } int blockType = readUint8(); int length = readUint32(); - return BlockReader.fromBlock(blockType, readBytes(length)); + return BlockReader.fromBlock(blockType, readBytes(length)); } } diff --git a/flare_dart/lib/block_types.dart b/flare_dart/lib/block_types.dart index 8d5ec68..b62e140 100644 --- a/flare_dart/lib/block_types.dart +++ b/flare_dart/lib/block_types.dart @@ -1,99 +1,99 @@ -const Map BlockTypesMap = { - "unknown": BlockTypes.Unknown, - "nodes": BlockTypes.Components, - "node": BlockTypes.ActorNode, - "bone": BlockTypes.ActorBone, - "rootBone": BlockTypes.ActorRootBone, - "image": BlockTypes.ActorImage, - "view": BlockTypes.View, - "animation": BlockTypes.Animation, - "animations": BlockTypes.Animations, - "atlases": BlockTypes.Atlases, - "atlas": BlockTypes.Atlas, - "event": BlockTypes.ActorEvent, - "customInt": BlockTypes.CustomIntProperty, - "customFloat": BlockTypes.CustomFloatProperty, - "customString": BlockTypes.CustomStringProperty, - "customBoolean": BlockTypes.CustomBooleanProperty, - "rectangleCollider": BlockTypes.ActorColliderRectangle, - "triangleCollider": BlockTypes.ActorColliderTriangle, - "circleCollider": BlockTypes.ActorColliderCircle, - "polygonCollider": BlockTypes.ActorColliderPolygon, - "lineCollider": BlockTypes.ActorColliderLine, - "imageSequence": BlockTypes.ActorImageSequence, - "solo": BlockTypes.ActorNodeSolo, - "jelly": BlockTypes.JellyComponent, - "jellyBone": BlockTypes.ActorJellyBone, - "ikConstraint": BlockTypes.ActorIKConstraint, - "distanceConstraint": BlockTypes.ActorDistanceConstraint, - "translationConstraint": BlockTypes.ActorTranslationConstraint, - "rotationConstraint": BlockTypes.ActorRotationConstraint, - "scaleConstraint": BlockTypes.ActorScaleConstraint, - "transformConstraint": BlockTypes.ActorTransformConstraint, - "shape": BlockTypes.ActorShape, - "path": BlockTypes.ActorPath, - "colorFill": BlockTypes.ColorFill, - "colorStroke": BlockTypes.ColorStroke, - "gradientFill": BlockTypes.GradientFill, - "gradientStroke": BlockTypes.GradientStroke, - "radialGradientFill": BlockTypes.RadialGradientFill, - "radialGradientStroke": BlockTypes.RadialGradientStroke, - "ellipse": BlockTypes.ActorEllipse, - "rectangle": BlockTypes.ActorRectangle, - "triangle": BlockTypes.ActorTriangle, - "star": BlockTypes.ActorStar, - "polygon": BlockTypes.ActorPolygon, - "artboards": BlockTypes.Artboards, - "artboard": BlockTypes.ActorArtboard +const Map blockTypesMap = { + "unknown": BlockTypes.unknown, + "nodes": BlockTypes.components, + "node": BlockTypes.actorNode, + "bone": BlockTypes.actorBone, + "rootBone": BlockTypes.actorRootBone, + "image": BlockTypes.actorImage, + "view": BlockTypes.view, + "animation": BlockTypes.animation, + "animations": BlockTypes.animations, + "atlases": BlockTypes.atlases, + "atlas": BlockTypes.atlas, + "event": BlockTypes.actorEvent, + "customInt": BlockTypes.customIntProperty, + "customFloat": BlockTypes.customFloatProperty, + "customString": BlockTypes.customStringProperty, + "customBoolean": BlockTypes.customBooleanProperty, + "rectangleCollider": BlockTypes.actorColliderRectangle, + "triangleCollider": BlockTypes.actorColliderTriangle, + "circleCollider": BlockTypes.actorColliderCircle, + "polygonCollider": BlockTypes.actorColliderPolygon, + "lineCollider": BlockTypes.actorColliderLine, + "imageSequence": BlockTypes.actorImageSequence, + "solo": BlockTypes.actorNodeSolo, + "jelly": BlockTypes.jellyComponent, + "jellyBone": BlockTypes.actorJellyBone, + "ikConstraint": BlockTypes.actorIKConstraint, + "distanceConstraint": BlockTypes.actorDistanceConstraint, + "translationConstraint": BlockTypes.actorTranslationConstraint, + "rotationConstraint": BlockTypes.actorRotationConstraint, + "scaleConstraint": BlockTypes.actorScaleConstraint, + "transformConstraint": BlockTypes.actorTransformConstraint, + "shape": BlockTypes.actorShape, + "path": BlockTypes.actorPath, + "colorFill": BlockTypes.colorFill, + "colorStroke": BlockTypes.colorStroke, + "gradientFill": BlockTypes.gradientFill, + "gradientStroke": BlockTypes.gradientStroke, + "radialGradientFill": BlockTypes.radialGradientFill, + "radialGradientStroke": BlockTypes.radialGradientStroke, + "ellipse": BlockTypes.actorEllipse, + "rectangle": BlockTypes.actorRectangle, + "triangle": BlockTypes.actorTriangle, + "star": BlockTypes.actorStar, + "polygon": BlockTypes.actorPolygon, + "artboards": BlockTypes.artboards, + "artboard": BlockTypes.actorArtboard }; class BlockTypes { - static const int Unknown = 0; - static const int Components = 1; - static const int ActorNode = 2; - static const int ActorBone = 3; - static const int ActorRootBone = 4; - static const int ActorImage = 5; - static const int View = 6; - static const int Animation = 7; - static const int Animations = 8; - static const int Atlases = 9; - static const int Atlas = 10; - static const int ActorIKTarget = 11; - static const int ActorEvent = 12; - static const int CustomIntProperty = 13; - static const int CustomFloatProperty = 14; - static const int CustomStringProperty = 15; - static const int CustomBooleanProperty = 16; - static const int ActorColliderRectangle = 17; - static const int ActorColliderTriangle = 18; - static const int ActorColliderCircle = 19; - static const int ActorColliderPolygon = 20; - static const int ActorColliderLine = 21; - static const int ActorImageSequence = 22; - static const int ActorNodeSolo = 23; - static const int JellyComponent = 28; - static const int ActorJellyBone = 29; - static const int ActorIKConstraint = 30; - static const int ActorDistanceConstraint = 31; - static const int ActorTranslationConstraint = 32; - static const int ActorRotationConstraint = 33; - static const int ActorScaleConstraint = 34; - static const int ActorTransformConstraint = 35; - static const int ActorShape = 100; - static const int ActorPath = 101; - static const int ColorFill = 102; - static const int ColorStroke = 103; - static const int GradientFill = 104; - static const int GradientStroke = 105; - static const int RadialGradientFill = 106; - static const int RadialGradientStroke = 107; - static const int ActorEllipse = 108; - static const int ActorRectangle = 109; - static const int ActorTriangle = 110; - static const int ActorStar = 111; - static const int ActorPolygon = 112; - static const int ActorSkin = 113; - static const int ActorArtboard = 114; - static const int Artboards = 115; + static const int unknown = 0; + static const int components = 1; + static const int actorNode = 2; + static const int actorBone = 3; + static const int actorRootBone = 4; + static const int actorImage = 5; + static const int view = 6; + static const int animation = 7; + static const int animations = 8; + static const int atlases = 9; + static const int atlas = 10; + static const int actorIKTarget = 11; + static const int actorEvent = 12; + static const int customIntProperty = 13; + static const int customFloatProperty = 14; + static const int customStringProperty = 15; + static const int customBooleanProperty = 16; + static const int actorColliderRectangle = 17; + static const int actorColliderTriangle = 18; + static const int actorColliderCircle = 19; + static const int actorColliderPolygon = 20; + static const int actorColliderLine = 21; + static const int actorImageSequence = 22; + static const int actorNodeSolo = 23; + static const int jellyComponent = 28; + static const int actorJellyBone = 29; + static const int actorIKConstraint = 30; + static const int actorDistanceConstraint = 31; + static const int actorTranslationConstraint = 32; + static const int actorRotationConstraint = 33; + static const int actorScaleConstraint = 34; + static const int actorTransformConstraint = 35; + static const int actorShape = 100; + static const int actorPath = 101; + static const int colorFill = 102; + static const int colorStroke = 103; + static const int gradientFill = 104; + static const int gradientStroke = 105; + static const int radialGradientFill = 106; + static const int radialGradientStroke = 107; + static const int actorEllipse = 108; + static const int actorRectangle = 109; + static const int actorTriangle = 110; + static const int actorStar = 111; + static const int actorPolygon = 112; + static const int actorSkin = 113; + static const int actorArtboard = 114; + static const int artboards = 115; } diff --git a/flare_dart/lib/dependency_sorter.dart b/flare_dart/lib/dependency_sorter.dart index 8cb074a..98df48d 100644 --- a/flare_dart/lib/dependency_sorter.dart +++ b/flare_dart/lib/dependency_sorter.dart @@ -12,7 +12,7 @@ class DependencySorter { } List sort(ActorComponent root) { - _order = List(); + _order = []; if (!visit(root)) { return null; } @@ -32,7 +32,7 @@ class DependencySorter { List dependents = n.dependents; if (dependents != null) { - for (ActorComponent d in dependents) { + for (final ActorComponent d in dependents) { if (!visit(d)) { return false; } diff --git a/flare_dart/lib/jelly_component.dart b/flare_dart/lib/jelly_component.dart index e7815e7..ecf4579 100644 --- a/flare_dart/lib/jelly_component.dart +++ b/flare_dart/lib/jelly_component.dart @@ -1,26 +1,26 @@ -import "stream_reader.dart"; +import "dart:math"; import "actor_artboard.dart"; -import "actor_jelly_bone.dart"; +import "actor_bone.dart"; import "actor_component.dart"; +import "actor_constraint.dart"; +import "actor_jelly_bone.dart"; import "actor_node.dart"; -import "actor_bone.dart"; -import "math/vec2d.dart"; -import "math/mat2d.dart"; -import "dart:math"; import "actor_root_bone.dart"; -import "actor_constraint.dart"; +import "math/mat2d.dart"; +import "math/vec2d.dart"; +import "stream_reader.dart"; class JellyComponent extends ActorComponent { - static const int JellyMax = 16; - static double OptimalDistance = 4.0 * (sqrt(2.0) - 1.0) / 3.0; - static double CurveConstant = OptimalDistance * sqrt(2.0) * 0.5; - static const double Epsilon = 0.001; // Intentionally agressive. + static const int jellyMax = 16; + static double optimalDistance = 4.0 * (sqrt(2.0) - 1.0) / 3.0; + static double curveConstant = optimalDistance * sqrt(2.0) * 0.5; + static const double epsilon = 0.001; // Intentionally agressive. static bool fuzzyEquals(Vec2D a, Vec2D b) { double a0 = a[0], a1 = a[1]; double b0 = b[0], b1 = b[1]; - return ((a0 - b0).abs() <= Epsilon * max(1.0, max(a0.abs(), b0.abs())) && - (a1 - b1).abs() <= Epsilon * max(1.0, max(a1.abs(), b1.abs()))); + return (a0 - b0).abs() <= epsilon * max(1.0, max(a0.abs(), b0.abs())) && + (a1 - b1).abs() <= epsilon * max(1.0, max(a1.abs(), b1.abs())); } static void forwardDiffBezier(double c0, double c1, double c2, double c3, @@ -51,7 +51,7 @@ class JellyComponent extends ActorComponent { } List normalizeCurve(List curve, int numSegments) { - List points = List(); + List points = []; int curvePointCount = curve.length; List distances = List(curvePointCount); distances[0] = 0.0; @@ -121,11 +121,12 @@ class JellyComponent extends ActorComponent { _cachedOut = Vec2D(); _cachedIn = Vec2D(); - _jellyPoints = List(JellyMax + 1); - for (var i = 0; i <= JellyMax; i++) { + _jellyPoints = List(jellyMax + 1); + for (var i = 0; i <= jellyMax; i++) { _jellyPoints[i] = Vec2D(); } } + @override ActorComponent makeInstance(ActorArtboard artboard) { JellyComponent instance = JellyComponent(); instance.copyJelly(this, artboard); @@ -142,6 +143,7 @@ class JellyComponent extends ActorComponent { _outTargetIdx = component._outTargetIdx; } + @override void resolveComponentIndices(List components) { super.resolveComponentIndices(components); @@ -162,8 +164,8 @@ class JellyComponent extends ActorComponent { artboard.addDependency(this, firstBone); dependencyConstraints += firstBone.allConstraints; - // If we don't have an out target and the child jelly does have an in target - // we are dependent on that target's position. + // If we don't have an out target and the child jelly does have an + // in target we are dependent on that target's position. if (_outTarget == null && firstBone.jelly != null && firstBone.jelly.inTarget != null) { @@ -172,7 +174,7 @@ class JellyComponent extends ActorComponent { } } if (bone.parent is ActorBone) { - ActorBone parentBone = bone.parent; + ActorBone parentBone = bone.parent as ActorBone; JellyComponent parentBoneJelly = parentBone.jelly; if (parentBoneJelly != null && parentBoneJelly.outTarget != null) { artboard.addDependency(this, parentBoneJelly.outTarget); @@ -193,11 +195,12 @@ class JellyComponent extends ActorComponent { // We want to depend on any and all constraints that our dependents have. Set constraints = Set.from(dependencyConstraints); - for (ActorConstraint constraint in constraints) { + for (final ActorConstraint constraint in constraints) { artboard.addDependency(this, constraint); } } + @override void completeResolve() { //super.completeResolve(); ActorBone bone = parent as ActorBone; @@ -209,11 +212,12 @@ class JellyComponent extends ActorComponent { return; } - _bones = List(); - for (ActorNode child in children) { + _bones = []; + for (final ActorNode child in children) { if (child is ActorJellyBone) { _bones.add(child); - // Make sure the jelly doesn't update until the jelly component has updated + // Make sure the jelly doesn't update until + // the jelly component has updated artboard.addDependency(child, this); } } @@ -221,9 +225,7 @@ class JellyComponent extends ActorComponent { static JellyComponent read( ActorArtboard artboard, StreamReader reader, JellyComponent node) { - if (node == null) { - node = JellyComponent(); - } + node ??= JellyComponent(); ActorComponent.read(artboard, reader, node); node._easeIn = reader.readFloat32("easeIn"); @@ -263,8 +265,8 @@ class JellyComponent extends ActorComponent { Vec2D q2 = _outPoint; Vec2D q3 = tipPosition; - forwardDiffBezier(q0[0], q1[0], q2[0], q3[0], _jellyPoints, JellyMax, 0); - forwardDiffBezier(q0[1], q1[1], q2[1], q3[1], _jellyPoints, JellyMax, 1); + forwardDiffBezier(q0[0], q1[0], q2[0], q3[0], _jellyPoints, jellyMax, 0); + forwardDiffBezier(q0[1], q1[1], q2[1], q3[1], _jellyPoints, jellyMax, 1); List normalizedPoints = normalizeCurve(_jellyPoints, _bones.length); @@ -337,12 +339,12 @@ class JellyComponent extends ActorComponent { Vec2D.transformMat2(_inDirection, sum, inverseWorld); Vec2D.normalize(_inDirection, _inDirection); } - _inPoint[0] = _inDirection[0] * _easeIn * bone.length * CurveConstant; - _inPoint[1] = _inDirection[1] * _easeIn * bone.length * CurveConstant; + _inPoint[0] = _inDirection[0] * _easeIn * bone.length * curveConstant; + _inPoint[1] = _inDirection[1] * _easeIn * bone.length * curveConstant; } else { _inDirection[0] = 1.0; _inDirection[1] = 0.0; - _inPoint[0] = _inDirection[0] * _easeIn * bone.length * CurveConstant; + _inPoint[0] = _inDirection[0] * _easeIn * bone.length * curveConstant; } if (_outTarget != null) { @@ -374,7 +376,7 @@ class JellyComponent extends ActorComponent { } Vec2D.normalize(_outDirection, _outDirection); Vec2D scaledOut = Vec2D.scale( - Vec2D(), _outDirection, _easeOut * bone.length * CurveConstant); + Vec2D(), _outDirection, _easeOut * bone.length * curveConstant); _outPoint[0] = bone.length; _outPoint[1] = 0.0; Vec2D.add(_outPoint, _outPoint, scaledOut); @@ -383,7 +385,7 @@ class JellyComponent extends ActorComponent { _outDirection[1] = 0.0; Vec2D scaledOut = Vec2D.scale( - Vec2D(), _outDirection, _easeOut * bone.length * CurveConstant); + Vec2D(), _outDirection, _easeOut * bone.length * curveConstant); _outPoint[0] = bone.length; _outPoint[1] = 0.0; Vec2D.add(_outPoint, _outPoint, scaledOut); diff --git a/flare_dart/lib/json_block_reader.dart b/flare_dart/lib/json_block_reader.dart index 2f7774e..6bc6de8 100644 --- a/flare_dart/lib/json_block_reader.dart +++ b/flare_dart/lib/json_block_reader.dart @@ -1,28 +1,24 @@ import "json_reader.dart"; class JSONBlockReader extends JSONReader { - @override - int blockType; - - JSONBlockReader(Map object) - : blockType = 0, - super(object); + JSONBlockReader(Map object) : super(object); JSONBlockReader.fromObject(int type, Map object) : super(object) { blockType = type; } + @override JSONBlockReader readNextBlock([Map blockTypes]) { if (isEOF()) { return null; } - var obj = Map(); - obj["container"] = this._peek(); - var type = this.readBlockType(blockTypes); - var c = this.context.first; + var obj = {}; + obj["container"] = _peek(); + var type = readBlockType(blockTypes); + dynamic c = context.first; if (c is Map) { - c.remove(this.nextKey); + c.remove(nextKey); } else if (c is List) { c.removeAt(0); } @@ -30,35 +26,35 @@ class JSONBlockReader extends JSONReader { return JSONBlockReader.fromObject(type, obj); } - readBlockType(Map blockTypes) { - var next = this._peek(); - var bType; + int readBlockType(Map blockTypes) { + dynamic next = _peek(); + int bType; if (next is Map) { - var c = this.context.first; + dynamic c = context.first; if (c is Map) { - bType = blockTypes[this.nextKey]; + bType = blockTypes[nextKey]; } else if (c is List) { // Objects are serialized with "type" property. - var nType = next["type"]; + dynamic nType = next["type"]; bType = blockTypes[nType]; } } else if (next is List) { // Arrays are serialized as "type": [Array]. - bType = blockTypes[this.nextKey]; + bType = blockTypes[nextKey]; } return bType; } - _peek() { - var stream = this.context.first; - var next; + dynamic _peek() { + dynamic stream = context.first; + dynamic next; if (stream is Map) { - next = stream[this.nextKey]; + next = stream[nextKey]; } else if (stream is List) { next = stream[0]; } return next; } - get nextKey => this.context.first.keys.first; + dynamic get nextKey => context.first.keys.first; } diff --git a/flare_dart/lib/json_reader.dart b/flare_dart/lib/json_reader.dart index b880365..6e95d90 100644 --- a/flare_dart/lib/json_reader.dart +++ b/flare_dart/lib/json_reader.dart @@ -13,58 +13,70 @@ abstract class JSONReader implements StreamReader { JSONReader(Map object) { _readObject = object["container"]; - _context = ListQueue(); + _context = ListQueue(); _context.addFirst(_readObject); } - dynamic readProp(String label) { - var head = _context.first; + T readProp(String label) { + dynamic head = _context.first; if (head is Map) { - var prop = head[label]; + dynamic prop = head[label]; head.remove(label); - return prop; + if (prop is T) { + return prop; + } else { + return null; + } } else if (head is List) { - return head.removeAt(0); + dynamic prop = head.removeAt(0); + if (prop is T) { + return prop; + } else { + return null; + } } return null; } @override - readFloat32(label) { - num f = this.readProp(label); - return f.toDouble(); + double readFloat32(String label) { + num f = readProp(label); + return f?.toDouble() ?? 0.0; } // Reads the array into ar @override Float32List readFloat32Array(int length, String label) { var ar = Float32List(length); - this._readArray(ar, label); - return ar; + _readArray(ar, label); + return ar; } void _readArray(List ar, String label) { - List array = this.readProp(label); + List array = readProp(label); + if (array == null) { + return; + } for (int i = 0; i < ar.length; i++) { - num val = array[i]; + num val = array[i] as num; ar[i] = ar.first is double ? val.toDouble() : val.toInt(); } } @override - double readFloat64(label) { - num f = this.readProp(label); - return f.toDouble(); + double readFloat64(String label) { + num f = readProp(label); + return f?.toDouble() ?? 0; } @override - int readUint8(label) { - return this.readProp(label); + int readUint8(String label) { + return readProp(label) ?? 0; } @override int readUint8Length() { - return this._readLength(); + return _readLength(); } @override @@ -73,106 +85,114 @@ abstract class JSONReader implements StreamReader { } @override - int readInt8(label) { - return this.readProp(label); + int readInt8(String label) { + return readProp(label) ?? 0; } @override - int readUint16(label) { - return this.readProp(label); + int readUint16(String label) { + return readProp(label) ?? 0; } @override Uint8List readUint8Array(int length, String label) { - var ar = Uint8List(length); - this._readArray(ar, label); + var ar = Uint8List(length); + _readArray(ar, label); return ar; } @override Uint16List readUint16Array(int length, String label) { - var ar = Uint16List(length); - this._readArray(ar, label); - return ar; + var ar = Uint16List(length); + _readArray(ar, label); + return ar; } @override - int readInt16(label) { - return this.readProp(label); + int readInt16(String label) { + return readProp(label) ?? 0; } @override int readUint16Length() { - return this._readLength(); + return _readLength(); } @override int readUint32Length() { - return this._readLength(); + return _readLength(); } @override - int readUint32(label) { - return this.readProp(label); + int readUint32(String label) { + return readProp(label) ?? 0; } @override - int readInt32(label) { - return this.readProp(label); + int readInt32(String label) { + return readProp(label) ?? 0; } @override int readVersion() { - return this.readProp("version"); + return readProp("version") ?? 0; } @override - readString(label) { - return this.readProp(label); + String readString(String label) { + return readProp(label) ?? ""; } @override - readBool(String label) { - return this.readProp(label); + bool readBool(String label) { + return readProp(label) ?? false; } // @hasOffset flag is needed for older (up until version 14) files. - // Since the JSON Reader has been added in version 15, the field here is optional. + // Since the JSON Reader has been added in version 15, the field + // here is optional. @override - readId(String label) { - var val = this.readProp(label); - return val is num ? val + 1 : 0; + int readId(String label) { + var val = readProp(label); + return val != null ? val.toInt() + 1 : 0; } @override - openArray(label) { - var array = this.readProp(label); + void openArray(String label) { + dynamic array = readProp(label); _context.addFirst(array); } @override - closeArray() { + void closeArray() { _context.removeFirst(); } @override - openObject(label) { - var o = this.readProp(label); + void openObject(String label) { + dynamic o = readProp(label); _context.addFirst(o); } @override - closeObject() { - this._context.removeFirst(); + void closeObject() { + _context.removeFirst(); } - int _readLength() => - _context.first.length; // Maps and Lists both have a `length` property. + int _readLength() { + if (_context.first is List) { + return (_context.first as List).length; + } else if (_context.first is Map) { + return (_context.first as Map).length; + } + return 0; + } + @override Uint8List readAsset() { String encodedAsset = readString("data"); // are we sure we need a label here? - return Base64Decoder().convert(encodedAsset, 22); + return const Base64Decoder().convert(encodedAsset, 22); } @override diff --git a/flare_dart/lib/math/aabb.dart b/flare_dart/lib/math/aabb.dart index 36e3c04..f0212f4 100644 --- a/flare_dart/lib/math/aabb.dart +++ b/flare_dart/lib/math/aabb.dart @@ -33,7 +33,7 @@ class AABB { return _buffer[idx]; } - operator []=(int idx, double v) { + void operator []=(int idx, double v) { _buffer[idx] = v; } diff --git a/flare_dart/lib/math/mat2d.dart b/flare_dart/lib/math/mat2d.dart index 4c6f08f..326ee54 100644 --- a/flare_dart/lib/math/mat2d.dart +++ b/flare_dart/lib/math/mat2d.dart @@ -1,7 +1,7 @@ -import "dart:typed_data"; import "dart:math"; -import "vec2d.dart"; +import "dart:typed_data"; import "transform_components.dart"; +import "vec2d.dart"; class Mat2D { Float32List _buffer; diff --git a/flare_dart/lib/math/vec2d.dart b/flare_dart/lib/math/vec2d.dart index cfa13a3..2478bbb 100644 --- a/flare_dart/lib/math/vec2d.dart +++ b/flare_dart/lib/math/vec2d.dart @@ -106,8 +106,8 @@ class Vec2D { } static Vec2D negate(Vec2D result, Vec2D a) { - result[0] = -a[0]; - result[1] = -a[1]; + result[0] = -1 * a[0]; + result[1] = -1 * a[1]; return result; } diff --git a/flare_dart/lib/path_point.dart b/flare_dart/lib/path_point.dart index b1d3aef..7bdb6aa 100644 --- a/flare_dart/lib/path_point.dart +++ b/flare_dart/lib/path_point.dart @@ -1,10 +1,10 @@ +import "dart:collection"; import "dart:typed_data"; +import "math/mat2d.dart"; import "math/vec2d.dart"; -import "dart:collection"; import "stream_reader.dart"; -import "math/mat2d.dart"; -enum PointType { Straight, Mirror, Disconnected, Asymmetric } +enum PointType { straight, mirror, disconnected, asymmetric } HashMap pointTypeLookup = HashMap.fromIterables([ @@ -13,10 +13,10 @@ HashMap pointTypeLookup = 2, 3 ], [ - PointType.Straight, - PointType.Mirror, - PointType.Disconnected, - PointType.Asymmetric + PointType.straight, + PointType.mirror, + PointType.disconnected, + PointType.asymmetric ]); abstract class PathPoint { @@ -38,8 +38,8 @@ abstract class PathPoint { PathPoint makeInstance(); - copy(PathPoint from) { - this._type = from._type; + void copy(PathPoint from) { + _type = from._type; Vec2D.copy(_translation, from._translation); if (from._weights != null) { _weights = Float32List.fromList(from._weights); @@ -69,26 +69,26 @@ abstract class PathPoint { class StraightPathPoint extends PathPoint { double radius = 0.0; - StraightPathPoint() : super(PointType.Straight); + StraightPathPoint() : super(PointType.straight); StraightPathPoint.fromTranslation(Vec2D translation) - : super(PointType.Straight) { - this._translation = translation; + : super(PointType.straight) { + _translation = translation; } - StraightPathPoint.fromValues(Vec2D translation, double r) - : super(PointType.Straight) { + StraightPathPoint.fromValues(Vec2D translation, this.radius) + : super(PointType.straight) { _translation = translation; - radius = r; } + @override PathPoint makeInstance() { StraightPathPoint node = StraightPathPoint(); node.copyStraight(this); return node; } - copyStraight(StraightPathPoint from) { + void copyStraight(StraightPathPoint from) { super.copy(from); radius = from.radius; } @@ -151,24 +151,26 @@ class CubicPathPoint extends PathPoint { } CubicPathPoint.fromValues(Vec2D translation, Vec2D inPoint, Vec2D outPoint) - : super(PointType.Disconnected) { + : super(PointType.disconnected) { _translation = translation; _in = inPoint; _out = outPoint; } + @override PathPoint makeInstance() { CubicPathPoint node = CubicPathPoint(_type); node.copyCubic(this); return node; } - copyCubic(from) { + void copyCubic(CubicPathPoint from) { super.copy(from); Vec2D.copy(_in, from._in); Vec2D.copy(_out, from._out); } + @override int readPoint(StreamReader reader, bool isConnectedToBones) { Vec2D.copyFromList(_in, reader.readFloat32Array(2, "in")); Vec2D.copyFromList(_out, reader.readFloat32Array(2, "out")); @@ -178,6 +180,7 @@ class CubicPathPoint extends PathPoint { return 0; } + @override PathPoint transformed(Mat2D transform) { CubicPathPoint result = super.transformed(transform) as CubicPathPoint; Vec2D.transformMat2D(result.inPoint, result.inPoint, transform); diff --git a/flare_dart/lib/stream_reader.dart b/flare_dart/lib/stream_reader.dart index d7289e1..4fa8aac 100644 --- a/flare_dart/lib/stream_reader.dart +++ b/flare_dart/lib/stream_reader.dart @@ -7,7 +7,7 @@ abstract class StreamReader { int blockType = 0; // Instantiate the right type of Reader based on the input values - factory StreamReader(data) { + factory StreamReader(dynamic data) { StreamReader reader; if (data is ByteData) { reader = BlockReader(data); diff --git a/flare_dart/lib/transform_space.dart b/flare_dart/lib/transform_space.dart index c68a824..b882881 100644 --- a/flare_dart/lib/transform_space.dart +++ b/flare_dart/lib/transform_space.dart @@ -1,4 +1,4 @@ class TransformSpace { - static const int Local = 0; - static const int World = 1; + static const int local = 0; + static const int world = 1; } diff --git a/flare_dart/pubspec.yaml b/flare_dart/pubspec.yaml index 45334e9..093b26f 100644 --- a/flare_dart/pubspec.yaml +++ b/flare_dart/pubspec.yaml @@ -1,6 +1,6 @@ name: flare_dart description: Vector design and runtime animation. -version: 1.4.9 +version: 1.4.10 author: "2Dimensions Team " homepage: https://github.com/2d-inc/Flare-Flutter environment: diff --git a/flare_flutter/CHANGELOG.md b/flare_flutter/CHANGELOG.md index 031fc0a..06f49be 100644 --- a/flare_flutter/CHANGELOG.md +++ b/flare_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.5.14] - 2019-10-08 13:38:55 + +- Fixing up various static analysis issues. + ## [1.5.13] - 2019-10-07 11:21:29 - Using latest flare_dart with support for Nodes inside of Shapes (Paths with multiple transform spaces). diff --git a/flare_flutter/analysis_options.yaml b/flare_flutter/analysis_options.yaml index 2da0fe6..7f8d90e 100644 --- a/flare_flutter/analysis_options.yaml +++ b/flare_flutter/analysis_options.yaml @@ -2,6 +2,8 @@ analyzer: strong-mode: implicit-casts: false implicit-dynamic: false + errors: + unused_import: error linter: rules: @@ -85,7 +87,7 @@ linter: - prefer_is_empty - prefer_is_not_empty - prefer_iterable_whereType - - prefer_mixin + # - prefer_mixin - prefer_null_aware_operators - prefer_typing_uninitialized_variables - prefer_void_to_null diff --git a/flare_flutter/lib/flare.dart b/flare_flutter/lib/flare.dart index 2609d03..8dfb1f3 100644 --- a/flare_flutter/lib/flare.dart +++ b/flare_flutter/lib/flare.dart @@ -22,7 +22,6 @@ import 'package:flare_dart/actor_rectangle.dart'; import 'package:flare_dart/actor_star.dart'; import 'package:flare_dart/actor_triangle.dart'; import 'package:flare_dart/actor_color.dart'; -import 'package:flare_dart/actor_node.dart'; import 'package:flare_dart/actor_drawable.dart'; import 'package:flare_dart/math/mat2d.dart'; import 'package:flare_dart/math/vec2d.dart'; @@ -68,10 +67,10 @@ abstract class FlutterFill { void paint(ActorFill fill, ui.Canvas canvas, ui.Path path) { switch (fill.fillRule) { - case FillRule.EvenOdd: + case FillRule.evenOdd: path.fillType = ui.PathFillType.evenOdd; break; - case FillRule.NonZero: + case FillRule.nonZero: path.fillType = ui.PathFillType.nonZero; break; } @@ -98,11 +97,11 @@ abstract class FlutterStroke { static ui.StrokeCap getStrokeCap(StrokeCap cap) { switch (cap) { - case StrokeCap.Butt: + case StrokeCap.butt: return ui.StrokeCap.butt; - case StrokeCap.Round: + case StrokeCap.round: return ui.StrokeCap.round; - case StrokeCap.Square: + case StrokeCap.square: return ui.StrokeCap.square; } return ui.StrokeCap.butt; @@ -110,11 +109,11 @@ abstract class FlutterStroke { static ui.StrokeJoin getStrokeJoin(StrokeJoin join) { switch (join) { - case StrokeJoin.Miter: + case StrokeJoin.miter: return ui.StrokeJoin.miter; - case StrokeJoin.Round: + case StrokeJoin.round: return ui.StrokeJoin.round; - case StrokeJoin.Bevel: + case StrokeJoin.bevel: return ui.StrokeJoin.bevel; } return ui.StrokeJoin.miter; @@ -127,7 +126,7 @@ abstract class FlutterStroke { if (stroke.isTrimmed) { if (effectPath == null) { - bool isSequential = stroke.trim == TrimPath.Sequential; + bool isSequential = stroke.trim == TrimPath.sequential; double start = stroke.trimStart.clamp(0, 1).toDouble(); double end = stroke.trimEnd.clamp(0, 1).toDouble(); double offset = stroke.trimOffset; @@ -892,7 +891,7 @@ abstract class FlutterPathPointsPath implements FlutterPath { for (int i = 0; i < pl; i++) { PathPoint point = pts[i]; switch (point.pointType) { - case PointType.Straight: + case PointType.straight: { StraightPathPoint straightPoint = point as StraightPathPoint; double radius = straightPoint.radius; @@ -1172,7 +1171,7 @@ class FlutterActorImage extends ActorImage with FlutterActorDrawable { @override void update(int dirt) { super.update(dirt); - if (dirt & DirtyFlags.PaintDirty != 0) { + if (dirt & DirtyFlags.paintDirty != 0) { onPaintUpdated(_paint); } } diff --git a/flare_flutter/lib/flare_cache.dart b/flare_flutter/lib/flare_cache.dart index d2dc161..a60bc6d 100644 --- a/flare_flutter/lib/flare_cache.dart +++ b/flare_flutter/lib/flare_cache.dart @@ -9,7 +9,7 @@ class FlareCache extends AssetBundleCache { FlareCache(AssetBundle bundle) : super(bundle); static bool doesPrune = true; - static Duration pruneDelay = Duration(seconds: 2); + static Duration pruneDelay = const Duration(seconds: 2); @override bool get isPruningEnabled => doesPrune; diff --git a/flare_flutter/lib/flare_controller.dart b/flare_flutter/lib/flare_controller.dart index abc4eee..ebdda43 100644 --- a/flare_flutter/lib/flare_controller.dart +++ b/flare_flutter/lib/flare_controller.dart @@ -1,6 +1,6 @@ -import 'flare.dart'; import 'package:flare_dart/math/mat2d.dart'; import 'package:flutter/foundation.dart'; +import 'flare.dart'; /// /// [FlareController] is a general-purpose interface for customizing @@ -17,8 +17,8 @@ import 'package:flutter/foundation.dart'; /// /// [FlareController]s can implement three methods: /// - [initialize()] is called when the [FlareActor] is first created. -/// - [setViewTransform()] and [advance()] are called every time the [FlareActor] -/// widget is repainted. +/// - [setViewTransform()] and [advance()] are called every time the +/// [FlareActor] widget is repainted. /// /// A basic implementation can be found in [FlareControls]. diff --git a/flare_flutter/lib/flare_controls.dart b/flare_flutter/lib/flare_controls.dart index 7d5238f..d0fdee5 100644 --- a/flare_flutter/lib/flare_controls.dart +++ b/flare_flutter/lib/flare_controls.dart @@ -1,8 +1,8 @@ import 'dart:math'; +import 'package:flare_dart/math/mat2d.dart'; import 'flare.dart'; import 'flare_actor.dart'; import 'flare_controller.dart'; -import 'package:flare_dart/math/mat2d.dart'; /// [FlareControls] is a concrete implementation of the [FlareController]. /// @@ -15,13 +15,14 @@ class FlareControls extends FlareController { /// The current [ActorAnimation]. String _animationName; - double _mixSeconds = 0.1; + final double _mixSeconds = 0.1; /// The [FlareAnimationLayer]s currently active. - List _animationLayers = []; + final List _animationLayers = []; /// Called at initialization time, it stores the reference /// to the current [FlutterActorArtboard]. + @override void initialize(FlutterActorArtboard artboard) { _artboard = artboard; } @@ -46,6 +47,7 @@ class FlareControls extends FlareController { } } + @override void setViewTransform(Mat2D viewTransform) {} /// Advance all the [FlareAnimationLayer]s that are currently controlled @@ -53,6 +55,7 @@ class FlareControls extends FlareController { /// /// If an animation completes during the current frame (and doesn't loop), /// the [onCompleted()] callback will be triggered. + @override bool advance(FlutterActorArtboard artboard, double elapsed) { int lastFullyMixed = -1; double lastMix = 0.0; @@ -61,8 +64,8 @@ class FlareControls extends FlareController { List completed = []; /// This loop will mix all the currently active animation layers so that, - /// if an animation is played on top of the current one, it'll smoothly mix between - /// the two instead of immediately switching to the new one. + /// if an animation is played on top of the current one, it'll smoothly mix + /// between the two instead of immediately switching to the new one. for (int i = 0; i < _animationLayers.length; i++) { FlareAnimationLayer layer = _animationLayers[i]; layer.mix += elapsed; @@ -92,8 +95,8 @@ class FlareControls extends FlareController { } } - /// Removes the last fully mixed animation, if more than one animation is present. - /// If only one animation is playing (e.g. idle), nothing happens. + /// Removes the last fully mixed animation, if more than one animation is + /// present. If only one animation is playing (e.g. idle), nothing happens. /// Since animations are added to the end of [_animationLayers], /// everything before the last fully mixed animation can be /// assumed to be also fully mixed too. @@ -108,7 +111,7 @@ class FlareControls extends FlareController { } /// Notify of the completed animations. - for (FlareAnimationLayer animation in completed) { + for (final FlareAnimationLayer animation in completed) { _animationLayers.remove(animation); onCompleted(animation.name); } diff --git a/flare_flutter/pubspec.yaml b/flare_flutter/pubspec.yaml index 9985d82..667f039 100644 --- a/flare_flutter/pubspec.yaml +++ b/flare_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: flare_flutter description: Vector design and runtime animation for Flutter. -version: 1.5.13 +version: 1.5.14 author: "2Dimensions Team " homepage: https://github.com/2d-inc/Flare-Flutter environment: