mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
Enable strong strict mode on dartalyzer
This commit is contained in:
@ -1,6 +1,11 @@
|
|||||||
# Source of linter options:
|
# Source of linter options:
|
||||||
# http://dart-lang.github.io/linter/lints/options/options.html
|
# http://dart-lang.github.io/linter/lints/options/options.html
|
||||||
|
|
||||||
|
analyzer:
|
||||||
|
strong-mode:
|
||||||
|
implicit-casts: false
|
||||||
|
implicit-dynamic: false
|
||||||
|
|
||||||
linter:
|
linter:
|
||||||
rules:
|
rules:
|
||||||
- always_declare_return_types
|
- always_declare_return_types
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import 'dart:ui';
|
|||||||
|
|
||||||
const x = 500.0;
|
const x = 500.0;
|
||||||
const y = 500.0;
|
const y = 500.0;
|
||||||
const s = 64;
|
const s = 64.0;
|
||||||
final topLeft = Vector2(x, y);
|
final topLeft = Vector2(x, y);
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
@ -64,12 +64,12 @@ class MyGame extends BaseGame with MouseMovementDetector {
|
|||||||
base = IsometricTileMapComponent(
|
base = IsometricTileMapComponent(
|
||||||
tileset,
|
tileset,
|
||||||
matrix,
|
matrix,
|
||||||
destTileSize: Vector2.all(s.toDouble()),
|
destTileSize: Vector2.all(s),
|
||||||
)
|
)
|
||||||
..x = x
|
..x = x
|
||||||
..y = y,
|
..y = y,
|
||||||
);
|
);
|
||||||
add(selector = Selector(s.toDouble(), selectorImage));
|
add(selector = Selector(s, selectorImage));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -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:
|
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
|
```dart
|
||||||
SpriteAnimation animation = await Animation.fromAsepriteData(
|
final image = await images.load('chopper.png');
|
||||||
imageInstance, // Sprite Sheet image path
|
final jsonData = await assets.readJson('chopper.json');
|
||||||
"./assets/chopper.json" // Sprite Sheet animation JSON data
|
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._
|
_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._
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class AssetsCache {
|
|||||||
'"$fileName" is not a String Asset',
|
'"$fileName" is not a String Asset',
|
||||||
);
|
);
|
||||||
|
|
||||||
return _files[fileName].value;
|
return _files[fileName].value as String;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a binary file from assets folder
|
/// Reads a binary file from assets folder
|
||||||
@ -44,12 +44,12 @@ class AssetsCache {
|
|||||||
'"$fileName" is not a Binary Asset',
|
'"$fileName" is not a Binary Asset',
|
||||||
);
|
);
|
||||||
|
|
||||||
return _files[fileName].value;
|
return _files[fileName].value as List<int>;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> readJson(String fileName) async {
|
Future<Map<String, dynamic>> readJson(String fileName) async {
|
||||||
final String content = await readFile(fileName);
|
final String content = await readFile(fileName);
|
||||||
return jsonDecode(content);
|
return jsonDecode(content) as Map<String, dynamic>;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<_StringAsset> _readFile(String fileName) async {
|
Future<_StringAsset> _readFile(String fileName) async {
|
||||||
@ -61,7 +61,7 @@ class AssetsCache {
|
|||||||
final data = await rootBundle.load('assets/$fileName');
|
final data = await rootBundle.load('assets/$fileName');
|
||||||
final Uint8List list = Uint8List.view(data.buffer);
|
final Uint8List list = Uint8List.view(data.buffer);
|
||||||
|
|
||||||
final bytes = List.from(list).cast<int>();
|
final bytes = List<int>.from(list);
|
||||||
return _BinaryAsset()..value = bytes;
|
return _BinaryAsset()..value = bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,7 +74,7 @@ class ParallaxLayer {
|
|||||||
|
|
||||||
// The image size so that it fulfills the LayerFill parameter
|
// The image size so that it fulfills the LayerFill parameter
|
||||||
_imageSize =
|
_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
|
// Number of images that can fit on the canvas plus one
|
||||||
// to have something to scroll to without leaving canvas empty
|
// to have something to scroll to without leaving canvas empty
|
||||||
@ -138,7 +138,7 @@ class ParallaxLayer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Image> _load(filename) {
|
Future<Image> _load(String filename) {
|
||||||
return Flame.images.load(filename).then((image) {
|
return Flame.images.load(filename).then((image) {
|
||||||
_image = image;
|
_image = image;
|
||||||
if (_screenSize != null) {
|
if (_screenSize != null) {
|
||||||
|
|||||||
@ -202,8 +202,8 @@ abstract class PositionComponent extends Component {
|
|||||||
return _children.remove(c);
|
return _children.remove(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable<PositionComponent> removeChildren(
|
Iterable<Component> removeChildren(
|
||||||
bool Function(PositionComponent) test,
|
bool Function(Component) test,
|
||||||
) {
|
) {
|
||||||
return _children.removeWhere(test);
|
return _children.removeWhere(test);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class CombinedEffect extends PositionComponentEffect {
|
|||||||
this.offset = 0.0,
|
this.offset = 0.0,
|
||||||
bool isInfinite = false,
|
bool isInfinite = false,
|
||||||
bool isAlternating = false,
|
bool isAlternating = false,
|
||||||
Function onComplete,
|
void Function() onComplete,
|
||||||
}) : super(isInfinite, isAlternating, onComplete: onComplete) {
|
}) : super(isInfinite, isAlternating, onComplete: onComplete) {
|
||||||
assert(
|
assert(
|
||||||
effects.every((effect) => effect.component == null),
|
effects.every((effect) => effect.component == null),
|
||||||
@ -75,7 +75,7 @@ class CombinedEffect extends PositionComponentEffect {
|
|||||||
effects.forEach((effect) => effect.dispose());
|
effects.forEach((effect) => effect.dispose());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateEffect(final effect, double dt) {
|
void _updateEffect(PositionComponentEffect effect, double dt) {
|
||||||
final isReverse = curveDirection.isNegative;
|
final isReverse = curveDirection.isNegative;
|
||||||
final initialOffset = effects.indexOf(effect) * offset;
|
final initialOffset = effects.indexOf(effect) * offset;
|
||||||
final effectOffset = isReverse
|
final effectOffset = isReverse
|
||||||
|
|||||||
@ -117,10 +117,10 @@ abstract class PositionComponentEffect
|
|||||||
Vector2 endSize;
|
Vector2 endSize;
|
||||||
|
|
||||||
PositionComponentEffect(
|
PositionComponentEffect(
|
||||||
initialIsInfinite,
|
bool initialIsInfinite,
|
||||||
initialIsAlternating, {
|
bool initialIsAlternating, {
|
||||||
isRelative = false,
|
bool isRelative = false,
|
||||||
onComplete,
|
void Function() onComplete,
|
||||||
}) : super(
|
}) : super(
|
||||||
initialIsInfinite,
|
initialIsInfinite,
|
||||||
initialIsAlternating,
|
initialIsAlternating,
|
||||||
|
|||||||
@ -30,10 +30,10 @@ class MoveEffect extends PositionComponentEffect {
|
|||||||
@required this.path,
|
@required this.path,
|
||||||
@required this.speed,
|
@required this.speed,
|
||||||
this.curve,
|
this.curve,
|
||||||
isInfinite = false,
|
bool isInfinite = false,
|
||||||
isAlternating = false,
|
bool isAlternating = false,
|
||||||
isRelative = false,
|
bool isRelative = false,
|
||||||
Function onComplete,
|
void Function() onComplete,
|
||||||
}) : super(
|
}) : super(
|
||||||
isInfinite,
|
isInfinite,
|
||||||
isAlternating,
|
isAlternating,
|
||||||
|
|||||||
@ -14,10 +14,10 @@ class RotateEffect extends PositionComponentEffect {
|
|||||||
@required this.radians, // As many radians as you want to rotate
|
@required this.radians, // As many radians as you want to rotate
|
||||||
@required this.speed, // In radians per second
|
@required this.speed, // In radians per second
|
||||||
this.curve,
|
this.curve,
|
||||||
isInfinite = false,
|
bool isInfinite = false,
|
||||||
isAlternating = false,
|
bool isAlternating = false,
|
||||||
isRelative = false,
|
bool isRelative = false,
|
||||||
Function onComplete,
|
void Function() onComplete,
|
||||||
}) : super(
|
}) : super(
|
||||||
isInfinite,
|
isInfinite,
|
||||||
isAlternating,
|
isAlternating,
|
||||||
|
|||||||
@ -15,10 +15,10 @@ class ScaleEffect extends PositionComponentEffect {
|
|||||||
@required this.size,
|
@required this.size,
|
||||||
@required this.speed,
|
@required this.speed,
|
||||||
this.curve,
|
this.curve,
|
||||||
isInfinite = false,
|
bool isInfinite = false,
|
||||||
isAlternating = false,
|
bool isAlternating = false,
|
||||||
isRelative = false,
|
bool isRelative = false,
|
||||||
Function onComplete,
|
void Function() onComplete,
|
||||||
}) : super(
|
}) : super(
|
||||||
isInfinite,
|
isInfinite,
|
||||||
isAlternating,
|
isAlternating,
|
||||||
|
|||||||
@ -12,9 +12,9 @@ class SequenceEffect extends PositionComponentEffect {
|
|||||||
|
|
||||||
SequenceEffect({
|
SequenceEffect({
|
||||||
@required this.effects,
|
@required this.effects,
|
||||||
isInfinite = false,
|
bool isInfinite = false,
|
||||||
isAlternating = false,
|
bool isAlternating = false,
|
||||||
Function onComplete,
|
void Function() onComplete,
|
||||||
}) : super(isInfinite, isAlternating, onComplete: onComplete) {
|
}) : super(isInfinite, isAlternating, onComplete: onComplete) {
|
||||||
assert(
|
assert(
|
||||||
effects.every((effect) => effect.component == null),
|
effects.every((effect) => effect.component == null),
|
||||||
|
|||||||
@ -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).
|
/// 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);
|
Widget get widget => builder.build(this);
|
||||||
|
|
||||||
void _handleKeyEvent(e) {
|
void _handleKeyEvent(RawKeyEvent e) {
|
||||||
(this as KeyboardEvents).onKeyEvent(e);
|
(this as KeyboardEvents).onKeyEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,8 +33,7 @@ class _GenericTapEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _applyAdvancedGesturesDetectors(Game game, Widget child) {
|
Widget _applyAdvancedGesturesDetectors(Game game, Widget child) {
|
||||||
final Map<Type, GestureRecognizerFactory> gestures =
|
final Map<Type, GestureRecognizerFactory> gestures = {};
|
||||||
<Type, GestureRecognizerFactory>{};
|
|
||||||
|
|
||||||
final List<_GenericTapEventHandler> _tapHandlers = [];
|
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(
|
return MouseRegion(
|
||||||
child: Listener(
|
child: Listener(
|
||||||
child: child,
|
child: child,
|
||||||
@ -300,7 +299,7 @@ class OverlayWidgetBuilder extends WidgetBuilder {
|
|||||||
|
|
||||||
return OverlayGameWidget(
|
return OverlayGameWidget(
|
||||||
gameChild: container,
|
gameChild: container,
|
||||||
game: game,
|
game: game as HasWidgetsOverlay,
|
||||||
key: UniqueKey(),
|
key: UniqueKey(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,14 +55,14 @@ class NineTileBox {
|
|||||||
|
|
||||||
// horizontal sides
|
// horizontal sides
|
||||||
final mx = size.x - 2 * destTileSize;
|
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);
|
_drawTile(c, _getDest(middleLeft, width: mx), 1, 0);
|
||||||
final middleRight = middleLeft + Vector2(0, size.y - destTileSize);
|
final middleRight = middleLeft + Vector2(0, size.y - destTileSize);
|
||||||
_drawTile(c, _getDest(middleRight, width: mx), 1, 2);
|
_drawTile(c, _getDest(middleRight, width: mx), 1, 2);
|
||||||
|
|
||||||
// vertical sides
|
// vertical sides
|
||||||
final my = size.y - 2 * destTileSize;
|
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);
|
_drawTile(c, _getDest(topCenter, height: my), 0, 1);
|
||||||
final bottomCenter = topCenter + Vector2(size.x - destTileSize, 0);
|
final bottomCenter = topCenter + Vector2(size.x - destTileSize, 0);
|
||||||
_drawTile(c, _getDest(bottomCenter, height: my), 2, 1);
|
_drawTile(c, _getDest(bottomCenter, height: my), 2, 1);
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import 'dart:math';
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
@ -41,7 +40,7 @@ class AcceleratedParticle extends CurvedParticle with SingleChildParticle {
|
|||||||
@override
|
@override
|
||||||
void update(double t) {
|
void update(double t) {
|
||||||
speed += acceleration * t;
|
speed += acceleration * t;
|
||||||
position += speed * t - (acceleration * pow(t, 2)) / 2;
|
position += speed * t - (acceleration * t * t) / 2;
|
||||||
|
|
||||||
super.update(t);
|
super.update(t);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ class Sprite {
|
|||||||
Vector2 get srcSize => Vector2(src.width, src.height);
|
Vector2 get srcSize => Vector2(src.width, src.height);
|
||||||
|
|
||||||
set srcSize(Vector2 size) {
|
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);
|
src = (srcPosition ?? Vector2.zero()).toPositionedRect(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -127,16 +127,16 @@ class SpriteAnimation {
|
|||||||
Image image,
|
Image image,
|
||||||
Map<String, dynamic> jsonData,
|
Map<String, dynamic> jsonData,
|
||||||
) {
|
) {
|
||||||
final Map<String, dynamic> jsonFrames = jsonData['frames'];
|
final jsonFrames = jsonData['frames'] as Map<String, Map<String, dynamic>>;
|
||||||
|
|
||||||
final frames = jsonFrames.values.map((value) {
|
final frames = jsonFrames.values.map((value) {
|
||||||
final frameData = value['frame'];
|
final frameData = value['frame'] as Map<String, dynamic>;
|
||||||
final int x = frameData['x'];
|
final int x = frameData['x'] as int;
|
||||||
final int y = frameData['y'];
|
final int y = frameData['y'] as int;
|
||||||
final int width = frameData['w'];
|
final int width = frameData['w'] as int;
|
||||||
final int height = frameData['h'];
|
final int height = frameData['h'] as int;
|
||||||
|
|
||||||
final stepTime = value['duration'] / 1000;
|
final stepTime = (value['duration'] as int) / 1000;
|
||||||
|
|
||||||
final Sprite sprite = Sprite(
|
final Sprite sprite = Sprite(
|
||||||
image,
|
image,
|
||||||
|
|||||||
@ -13,10 +13,9 @@ class SpriteBatch {
|
|||||||
List<Color> colors = [];
|
List<Color> colors = [];
|
||||||
|
|
||||||
static const defaultBlendMode = BlendMode.srcOver;
|
static const defaultBlendMode = BlendMode.srcOver;
|
||||||
static const defaultCullRect = null;
|
static const defaultColor = const Color(0x00000000); // transparent
|
||||||
static final defaultPaint = Paint();
|
static final defaultPaint = Paint();
|
||||||
static final defaultTransform = RSTransform(1, 0, 0, 0);
|
static final defaultTransform = RSTransform(1, 0, 0, 0);
|
||||||
static const defaultColor = const Color(0x00000000); // transparent
|
|
||||||
|
|
||||||
SpriteBatch(this.atlas);
|
SpriteBatch(this.atlas);
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ class SpriteBatch {
|
|||||||
|
|
||||||
int get height => atlas.height;
|
int get height => atlas.height;
|
||||||
|
|
||||||
Vector2 get size => Vector2(width.toDouble(), height.toDouble());
|
Vector2 get size => Vector2Extension.fromInts(width, height);
|
||||||
|
|
||||||
void addTransform({
|
void addTransform({
|
||||||
@required Rect rect,
|
@required Rect rect,
|
||||||
@ -77,7 +76,7 @@ class SpriteBatch {
|
|||||||
rects,
|
rects,
|
||||||
colors,
|
colors,
|
||||||
blendMode ?? defaultBlendMode,
|
blendMode ?? defaultBlendMode,
|
||||||
cullRect ?? defaultCullRect,
|
cullRect,
|
||||||
paint ?? defaultPaint,
|
paint ?? defaultPaint,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,11 +69,11 @@ class SpriteSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Sprite _computeSprite(int spriteId) {
|
Sprite _computeSprite(int spriteId) {
|
||||||
final i = (spriteId % columns).toDouble();
|
final i = spriteId % columns;
|
||||||
final j = (spriteId ~/ columns).toDouble();
|
final j = spriteId ~/ columns;
|
||||||
return Sprite(
|
return Sprite(
|
||||||
image,
|
image,
|
||||||
srcPosition: Vector2(i, j)..multiply(srcSize),
|
srcPosition: Vector2Extension.fromInts(i, j)..multiply(srcSize),
|
||||||
srcSize: srcSize,
|
srcSize: srcSize,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,8 +55,8 @@ class TextConfig {
|
|||||||
/// For proper fonts of languages like Hebrew or Arabic, replace this with [TextDirection.rtl].
|
/// For proper fonts of languages like Hebrew or Arabic, replace this with [TextDirection.rtl].
|
||||||
final TextDirection textDirection;
|
final TextDirection textDirection;
|
||||||
|
|
||||||
final MemoryCache _textPainterCache =
|
final MemoryCache<String, material.TextPainter> _textPainterCache =
|
||||||
MemoryCache<String, material.TextPainter>();
|
MemoryCache();
|
||||||
|
|
||||||
/// Creates a constant [TextConfig] with sensible defaults.
|
/// Creates a constant [TextConfig] with sensible defaults.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user