diff --git a/analysis_options.yaml b/analysis_options.yaml index ae572db20..1363648db 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,6 +1,11 @@ # Source of linter options: # http://dart-lang.github.io/linter/lints/options/options.html +analyzer: + strong-mode: + implicit-casts: false + implicit-dynamic: false + linter: rules: - always_declare_return_types diff --git a/doc/examples/isometric/lib/main.dart b/doc/examples/isometric/lib/main.dart index 4fd7caba4..6b01de3c8 100644 --- a/doc/examples/isometric/lib/main.dart +++ b/doc/examples/isometric/lib/main.dart @@ -12,7 +12,7 @@ import 'dart:ui'; const x = 500.0; const y = 500.0; -const s = 64; +const s = 64.0; final topLeft = Vector2(x, y); void main() async { @@ -64,12 +64,12 @@ class MyGame extends BaseGame with MouseMovementDetector { base = IsometricTileMapComponent( tileset, matrix, - destTileSize: Vector2.all(s.toDouble()), + destTileSize: Vector2.all(s), ) ..x = x ..y = y, ); - add(selector = Selector(s.toDouble(), selectorImage)); + add(selector = Selector(s, selectorImage)); } @override diff --git a/doc/images.md b/doc/images.md index c378a9ac7..f7d2f62b3 100644 --- a/doc/images.md +++ b/doc/images.md @@ -214,10 +214,9 @@ This constructor makes creating an Animation very easy using sprite sheets. If you use Aseprite for your animations, Flame does provide some support for Aseprite animation's JSON data. To use this feature you will need to export the Sprite Sheet's JSON data, and use something like the following snippet: ```dart - SpriteAnimation animation = await Animation.fromAsepriteData( - imageInstance, // Sprite Sheet image path - "./assets/chopper.json" // Sprite Sheet animation JSON data - ); + final image = await images.load('chopper.png'); + final jsonData = await assets.readJson('chopper.json'); + final animation = SpriteAnimation.fromAsepriteData(image, jsonData); ``` _Note: trimmed sprite sheets are not supported by flame, so if you export your sprite sheet this way, it will have the trimmed size, not the sprite original size._ diff --git a/lib/assets/assets_cache.dart b/lib/assets/assets_cache.dart index 0d749d7aa..62a957171 100644 --- a/lib/assets/assets_cache.dart +++ b/lib/assets/assets_cache.dart @@ -30,7 +30,7 @@ class AssetsCache { '"$fileName" is not a String Asset', ); - return _files[fileName].value; + return _files[fileName].value as String; } /// Reads a binary file from assets folder @@ -44,12 +44,12 @@ class AssetsCache { '"$fileName" is not a Binary Asset', ); - return _files[fileName].value; + return _files[fileName].value as List; } Future> readJson(String fileName) async { final String content = await readFile(fileName); - return jsonDecode(content); + return jsonDecode(content) as Map; } Future<_StringAsset> _readFile(String fileName) async { @@ -61,7 +61,7 @@ class AssetsCache { final data = await rootBundle.load('assets/$fileName'); final Uint8List list = Uint8List.view(data.buffer); - final bytes = List.from(list).cast(); + final bytes = List.from(list); return _BinaryAsset()..value = bytes; } } diff --git a/lib/components/parallax_component.dart b/lib/components/parallax_component.dart index b9d41a759..c0317e68e 100644 --- a/lib/components/parallax_component.dart +++ b/lib/components/parallax_component.dart @@ -74,7 +74,7 @@ class ParallaxLayer { // The image size so that it fulfills the LayerFill parameter _imageSize = - Vector2(_image.width.toDouble(), _image.height.toDouble()) / _scale; + Vector2Extension.fromInts(_image.width, _image.height) / _scale; // Number of images that can fit on the canvas plus one // to have something to scroll to without leaving canvas empty @@ -138,7 +138,7 @@ class ParallaxLayer { ); } - Future _load(filename) { + Future _load(String filename) { return Flame.images.load(filename).then((image) { _image = image; if (_screenSize != null) { diff --git a/lib/components/position_component.dart b/lib/components/position_component.dart index 3ff9489a3..5745be9d1 100644 --- a/lib/components/position_component.dart +++ b/lib/components/position_component.dart @@ -202,8 +202,8 @@ abstract class PositionComponent extends Component { return _children.remove(c); } - Iterable removeChildren( - bool Function(PositionComponent) test, + Iterable removeChildren( + bool Function(Component) test, ) { return _children.removeWhere(test); } diff --git a/lib/effects/combined_effect.dart b/lib/effects/combined_effect.dart index e9a86e120..ef04a66ea 100644 --- a/lib/effects/combined_effect.dart +++ b/lib/effects/combined_effect.dart @@ -14,7 +14,7 @@ class CombinedEffect extends PositionComponentEffect { this.offset = 0.0, bool isInfinite = false, bool isAlternating = false, - Function onComplete, + void Function() onComplete, }) : super(isInfinite, isAlternating, onComplete: onComplete) { assert( effects.every((effect) => effect.component == null), @@ -75,7 +75,7 @@ class CombinedEffect extends PositionComponentEffect { effects.forEach((effect) => effect.dispose()); } - void _updateEffect(final effect, double dt) { + void _updateEffect(PositionComponentEffect effect, double dt) { final isReverse = curveDirection.isNegative; final initialOffset = effects.indexOf(effect) * offset; final effectOffset = isReverse diff --git a/lib/effects/effects.dart b/lib/effects/effects.dart index f7aae6497..be1c5ba01 100644 --- a/lib/effects/effects.dart +++ b/lib/effects/effects.dart @@ -117,10 +117,10 @@ abstract class PositionComponentEffect Vector2 endSize; PositionComponentEffect( - initialIsInfinite, - initialIsAlternating, { - isRelative = false, - onComplete, + bool initialIsInfinite, + bool initialIsAlternating, { + bool isRelative = false, + void Function() onComplete, }) : super( initialIsInfinite, initialIsAlternating, diff --git a/lib/effects/move_effect.dart b/lib/effects/move_effect.dart index c26265fc4..a62ae60ac 100644 --- a/lib/effects/move_effect.dart +++ b/lib/effects/move_effect.dart @@ -30,10 +30,10 @@ class MoveEffect extends PositionComponentEffect { @required this.path, @required this.speed, this.curve, - isInfinite = false, - isAlternating = false, - isRelative = false, - Function onComplete, + bool isInfinite = false, + bool isAlternating = false, + bool isRelative = false, + void Function() onComplete, }) : super( isInfinite, isAlternating, diff --git a/lib/effects/rotate_effect.dart b/lib/effects/rotate_effect.dart index 29dceace5..0ffd075b7 100644 --- a/lib/effects/rotate_effect.dart +++ b/lib/effects/rotate_effect.dart @@ -14,10 +14,10 @@ class RotateEffect extends PositionComponentEffect { @required this.radians, // As many radians as you want to rotate @required this.speed, // In radians per second this.curve, - isInfinite = false, - isAlternating = false, - isRelative = false, - Function onComplete, + bool isInfinite = false, + bool isAlternating = false, + bool isRelative = false, + void Function() onComplete, }) : super( isInfinite, isAlternating, diff --git a/lib/effects/scale_effect.dart b/lib/effects/scale_effect.dart index 93a6b8936..5da12f1e1 100644 --- a/lib/effects/scale_effect.dart +++ b/lib/effects/scale_effect.dart @@ -15,10 +15,10 @@ class ScaleEffect extends PositionComponentEffect { @required this.size, @required this.speed, this.curve, - isInfinite = false, - isAlternating = false, - isRelative = false, - Function onComplete, + bool isInfinite = false, + bool isAlternating = false, + bool isRelative = false, + void Function() onComplete, }) : super( isInfinite, isAlternating, diff --git a/lib/effects/sequence_effect.dart b/lib/effects/sequence_effect.dart index d217fac58..5d442a5f8 100644 --- a/lib/effects/sequence_effect.dart +++ b/lib/effects/sequence_effect.dart @@ -12,9 +12,9 @@ class SequenceEffect extends PositionComponentEffect { SequenceEffect({ @required this.effects, - isInfinite = false, - isAlternating = false, - Function onComplete, + bool isInfinite = false, + bool isAlternating = false, + void Function() onComplete, }) : super(isInfinite, isAlternating, onComplete: onComplete) { assert( effects.every((effect) => effect.component == null), diff --git a/lib/game/game.dart b/lib/game/game.dart index 602bbb3a5..726102c12 100644 --- a/lib/game/game.dart +++ b/lib/game/game.dart @@ -55,7 +55,7 @@ abstract class Game { /// You can add it directly to the runApp method or inside your widget structure (if you use vanilla screens and widgets). Widget get widget => builder.build(this); - void _handleKeyEvent(e) { + void _handleKeyEvent(RawKeyEvent e) { (this as KeyboardEvents).onKeyEvent(e); } diff --git a/lib/game/widget_builder.dart b/lib/game/widget_builder.dart index e278f8112..ab58e885f 100644 --- a/lib/game/widget_builder.dart +++ b/lib/game/widget_builder.dart @@ -33,8 +33,7 @@ class _GenericTapEventHandler { } Widget _applyAdvancedGesturesDetectors(Game game, Widget child) { - final Map gestures = - {}; + final Map gestures = {}; final List<_GenericTapEventHandler> _tapHandlers = []; @@ -207,7 +206,7 @@ Widget _applyBasicGesturesDetectors(Game game, Widget child) { ); } -Widget _applyMouseDetectors(game, Widget child) { +Widget _applyMouseDetectors(Game game, Widget child) { return MouseRegion( child: Listener( child: child, @@ -300,7 +299,7 @@ class OverlayWidgetBuilder extends WidgetBuilder { return OverlayGameWidget( gameChild: container, - game: game, + game: game as HasWidgetsOverlay, key: UniqueKey(), ); } diff --git a/lib/nine_tile_box.dart b/lib/nine_tile_box.dart index 16ca1b0fe..9b918dd00 100644 --- a/lib/nine_tile_box.dart +++ b/lib/nine_tile_box.dart @@ -55,14 +55,14 @@ class NineTileBox { // horizontal sides final mx = size.x - 2 * destTileSize; - final middleLeft = position + Vector2(destTileSize.toDouble(), 0); + final middleLeft = position + Vector2Extension.fromInts(destTileSize, 0); _drawTile(c, _getDest(middleLeft, width: mx), 1, 0); final middleRight = middleLeft + Vector2(0, size.y - destTileSize); _drawTile(c, _getDest(middleRight, width: mx), 1, 2); // vertical sides final my = size.y - 2 * destTileSize; - final topCenter = position + Vector2(0, destTileSize.toDouble()); + final topCenter = position + Vector2Extension.fromInts(0, destTileSize); _drawTile(c, _getDest(topCenter, height: my), 0, 1); final bottomCenter = topCenter + Vector2(size.x - destTileSize, 0); _drawTile(c, _getDest(bottomCenter, height: my), 2, 1); diff --git a/lib/particles/accelerated_particle.dart b/lib/particles/accelerated_particle.dart index 0b8a1f0f4..b505b06a3 100644 --- a/lib/particles/accelerated_particle.dart +++ b/lib/particles/accelerated_particle.dart @@ -1,4 +1,3 @@ -import 'dart:math'; import 'dart:ui'; import 'package:flutter/foundation.dart'; @@ -41,7 +40,7 @@ class AcceleratedParticle extends CurvedParticle with SingleChildParticle { @override void update(double t) { speed += acceleration * t; - position += speed * t - (acceleration * pow(t, 2)) / 2; + position += speed * t - (acceleration * t * t) / 2; super.update(t); } diff --git a/lib/sprite.dart b/lib/sprite.dart index 9bcc84335..872f0091f 100644 --- a/lib/sprite.dart +++ b/lib/sprite.dart @@ -27,7 +27,7 @@ class Sprite { Vector2 get srcSize => Vector2(src.width, src.height); set srcSize(Vector2 size) { - size ??= Vector2(image.width.toDouble(), image.height.toDouble()); + size ??= Vector2Extension.fromInts(image.width, image.height); src = (srcPosition ?? Vector2.zero()).toPositionedRect(size); } diff --git a/lib/sprite_animation.dart b/lib/sprite_animation.dart index 8e7a476a8..dcd2f3005 100644 --- a/lib/sprite_animation.dart +++ b/lib/sprite_animation.dart @@ -127,16 +127,16 @@ class SpriteAnimation { Image image, Map jsonData, ) { - final Map jsonFrames = jsonData['frames']; + final jsonFrames = jsonData['frames'] as Map>; final frames = jsonFrames.values.map((value) { - final frameData = value['frame']; - final int x = frameData['x']; - final int y = frameData['y']; - final int width = frameData['w']; - final int height = frameData['h']; + final frameData = value['frame'] as Map; + final int x = frameData['x'] as int; + final int y = frameData['y'] as int; + final int width = frameData['w'] as int; + final int height = frameData['h'] as int; - final stepTime = value['duration'] / 1000; + final stepTime = (value['duration'] as int) / 1000; final Sprite sprite = Sprite( image, diff --git a/lib/sprite_batch.dart b/lib/sprite_batch.dart index 455d3973b..87149256d 100644 --- a/lib/sprite_batch.dart +++ b/lib/sprite_batch.dart @@ -13,10 +13,9 @@ class SpriteBatch { List colors = []; static const defaultBlendMode = BlendMode.srcOver; - static const defaultCullRect = null; + static const defaultColor = const Color(0x00000000); // transparent static final defaultPaint = Paint(); static final defaultTransform = RSTransform(1, 0, 0, 0); - static const defaultColor = const Color(0x00000000); // transparent SpriteBatch(this.atlas); @@ -28,7 +27,7 @@ class SpriteBatch { int get height => atlas.height; - Vector2 get size => Vector2(width.toDouble(), height.toDouble()); + Vector2 get size => Vector2Extension.fromInts(width, height); void addTransform({ @required Rect rect, @@ -77,7 +76,7 @@ class SpriteBatch { rects, colors, blendMode ?? defaultBlendMode, - cullRect ?? defaultCullRect, + cullRect, paint ?? defaultPaint, ); } diff --git a/lib/spritesheet.dart b/lib/spritesheet.dart index ae5b3560a..3d43799c8 100644 --- a/lib/spritesheet.dart +++ b/lib/spritesheet.dart @@ -69,11 +69,11 @@ class SpriteSheet { } Sprite _computeSprite(int spriteId) { - final i = (spriteId % columns).toDouble(); - final j = (spriteId ~/ columns).toDouble(); + final i = spriteId % columns; + final j = spriteId ~/ columns; return Sprite( image, - srcPosition: Vector2(i, j)..multiply(srcSize), + srcPosition: Vector2Extension.fromInts(i, j)..multiply(srcSize), srcSize: srcSize, ); } diff --git a/lib/text_config.dart b/lib/text_config.dart index aee148653..6721ec998 100644 --- a/lib/text_config.dart +++ b/lib/text_config.dart @@ -55,8 +55,8 @@ class TextConfig { /// For proper fonts of languages like Hebrew or Arabic, replace this with [TextDirection.rtl]. final TextDirection textDirection; - final MemoryCache _textPainterCache = - MemoryCache(); + final MemoryCache _textPainterCache = + MemoryCache(); /// Creates a constant [TextConfig] with sensible defaults. ///