mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
Add some new lint rules (#1117)
This commit is contained in:
@ -246,10 +246,10 @@ class SnowmanPart extends HitboxCircle {
|
||||
SnowmanPart(double definition, Vector2 relativeOffset, Color hitColor)
|
||||
: super(normalizedRadius: definition) {
|
||||
this.relativeOffset.setFrom(relativeOffset);
|
||||
hitPaint..color = startColor;
|
||||
hitPaint.color = startColor;
|
||||
onCollision = (Set<Vector2> intersectionPoints, HitboxShape other) {
|
||||
if (other.component is ScreenCollidable) {
|
||||
hitPaint..color = startColor;
|
||||
hitPaint.color = startColor;
|
||||
} else {
|
||||
hitPaint.color = hitColor.withOpacity(0.8);
|
||||
}
|
||||
|
||||
@ -94,13 +94,11 @@ class Compass extends PositionComponent {
|
||||
final angle = Transform2D.tau * (i / 12);
|
||||
// Note: rim takes up 0.1radius, so the lengths must be > than that
|
||||
final markLength = (i % 3 == 0) ? _radius * 0.2 : _radius * 0.15;
|
||||
_marksPath
|
||||
..moveTo(
|
||||
_marksPath.moveTo(
|
||||
_radius + _radius * sin(angle),
|
||||
_radius + _radius * cos(angle),
|
||||
);
|
||||
_marksPath
|
||||
..lineTo(
|
||||
_marksPath.lineTo(
|
||||
_radius + (_radius - markLength) * sin(angle),
|
||||
_radius + (_radius - markLength) * cos(angle),
|
||||
);
|
||||
|
||||
@ -5,8 +5,7 @@ import '../../commons/commons.dart';
|
||||
import 'pause_resume_game.dart';
|
||||
|
||||
void addSystemStories(Dashbook dashbook) {
|
||||
dashbook.storiesOf('System')
|
||||
..add(
|
||||
dashbook.storiesOf('System').add(
|
||||
'Pause/resume engine',
|
||||
(_) => GameWidget(game: PauseResumeGame()),
|
||||
codeLink: baseLink('system/pause_resume_game.dart'),
|
||||
|
||||
@ -5,8 +5,7 @@ import '../../commons/commons.dart';
|
||||
import 'isometric_tile_map.dart';
|
||||
|
||||
void addTileMapStories(Dashbook dashbook) {
|
||||
dashbook.storiesOf('Tile Maps')
|
||||
..add(
|
||||
dashbook.storiesOf('Tile Maps').add(
|
||||
'Isometric Tile Map',
|
||||
(_) => GameWidget(game: IsometricTileMapGame()),
|
||||
codeLink: baseLink('tile_maps/isometric_tile_map.dart'),
|
||||
|
||||
@ -93,7 +93,7 @@ class JoystickComponent extends HudMarginComponent with Draggable {
|
||||
void update(double dt) {
|
||||
super.update(dt);
|
||||
final knobRadius2 = knobRadius * knobRadius;
|
||||
delta..setFrom(_unscaledDelta);
|
||||
delta.setFrom(_unscaledDelta);
|
||||
if (delta.isZero() && _baseKnobPosition != knob!.position) {
|
||||
knob!.position = _baseKnobPosition;
|
||||
} else if (delta.length2 > knobRadius2) {
|
||||
|
||||
@ -67,8 +67,7 @@ class ParallaxComponent<T extends FlameGame> extends PositionComponent
|
||||
Anchor? anchor,
|
||||
int? priority,
|
||||
}) : _parallax = parallax,
|
||||
isFullscreen =
|
||||
size == null && !(parallax?.isSized ?? false) ? true : false,
|
||||
isFullscreen = size == null && !(parallax?.isSized ?? false),
|
||||
super(
|
||||
position: position,
|
||||
size: size ?? ((parallax?.isSized ?? false) ? parallax?.size : null),
|
||||
|
||||
@ -44,11 +44,11 @@ class StandardEffectController extends EffectController {
|
||||
this.atMaxDuration = 0.0,
|
||||
this.atMinDuration = 0.0,
|
||||
}) : assert(
|
||||
infinite ? repeatCount == null : true,
|
||||
!infinite || repeatCount == null,
|
||||
'An infinite animation cannot have a repeat count',
|
||||
),
|
||||
assert(
|
||||
!infinite ? (repeatCount ?? 1) > 0 : true,
|
||||
infinite || (repeatCount ?? 1) > 0,
|
||||
'repeatCount must be positive',
|
||||
),
|
||||
assert(duration > 0, 'duration must be positive'),
|
||||
|
||||
@ -31,7 +31,7 @@ abstract class Transform2DEffect extends Effect {
|
||||
if (parent is PositionComponent) {
|
||||
target = (parent! as PositionComponent).transform;
|
||||
}
|
||||
// TODO: add Camera support once it uses Transform2D
|
||||
// TODO(st-pasha): add Camera support once it uses Transform2D
|
||||
else {
|
||||
throw UnsupportedError(
|
||||
'Can only apply a Transform2DEffect to a PositionComponent class',
|
||||
|
||||
@ -90,7 +90,7 @@ abstract class Particle {
|
||||
///
|
||||
/// See `SingleChildParticle` or [ComposedParticle] for details.
|
||||
void setLifespan(double lifespan) {
|
||||
// TODO: Maybe make it into a setter/getter?
|
||||
// TODO(wolfenrain): Maybe make it into a setter/getter?
|
||||
_lifespan = lifespan;
|
||||
_timer?.stop();
|
||||
_timer = Timer(lifespan, onTick: () => _shouldBeRemoved = true)..start();
|
||||
|
||||
@ -264,7 +264,7 @@ class SpriteBatch {
|
||||
|
||||
if (kIsWeb) {
|
||||
for (final batchItem in _batchItems) {
|
||||
paint..blendMode = blendMode ?? paint.blendMode;
|
||||
paint.blendMode = blendMode ?? paint.blendMode;
|
||||
|
||||
canvas
|
||||
..save()
|
||||
|
||||
@ -200,7 +200,7 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO(luan) we can probably provide some helpers to facilitate testing events
|
||||
// TODO(luan): we can probably provide some helpers to facilitate testing events
|
||||
void _triggerMouseMove(HasHoverables game, double dx, double dy) {
|
||||
game.onMouseMove(
|
||||
PointerHoverInfo.fromDetails(
|
||||
|
||||
@ -31,7 +31,7 @@ void main() {
|
||||
});
|
||||
|
||||
flameGame.test('fixed ratio viewport has perfect ratio', (game) {
|
||||
game..camera.viewport = FixedResolutionViewport(Vector2.all(50));
|
||||
game.camera.viewport = FixedResolutionViewport(Vector2.all(50));
|
||||
game.onGameResize(Vector2.all(200.0));
|
||||
expect(game.canvasSize, Vector2.all(200.00));
|
||||
expect(game.size, Vector2.all(50.00));
|
||||
@ -52,7 +52,7 @@ void main() {
|
||||
});
|
||||
|
||||
flameGame.test('fixed ratio viewport maxes width', (game) {
|
||||
game..camera.viewport = FixedResolutionViewport(Vector2.all(50));
|
||||
game.camera.viewport = FixedResolutionViewport(Vector2.all(50));
|
||||
game.onGameResize(Vector2(100.0, 200.0));
|
||||
expect(game.canvasSize, Vector2(100.0, 200.00));
|
||||
expect(game.size, Vector2.all(50.00));
|
||||
@ -74,7 +74,7 @@ void main() {
|
||||
});
|
||||
|
||||
flameGame.test('fixed ratio viewport maxes height', (game) {
|
||||
game..camera.viewport = FixedResolutionViewport(Vector2(100.0, 400.0));
|
||||
game.camera.viewport = FixedResolutionViewport(Vector2(100.0, 400.0));
|
||||
game.onGameResize(Vector2(100.0, 200.0));
|
||||
expect(game.canvasSize, Vector2(100.0, 200.00));
|
||||
expect(game.size, Vector2(100.00, 400.0));
|
||||
|
||||
@ -198,7 +198,7 @@ void main() {
|
||||
game.projector.unprojectVector(Vector2.all(5)),
|
||||
Vector2.all(-100),
|
||||
);
|
||||
// TODO(luan) we might want to change the behaviour so that the zoom
|
||||
// TODO(luan): we might want to change the behaviour so that the zoom
|
||||
// is applied w.r.t. the relativeOffset and not topLeft
|
||||
|
||||
// for deltas, we consider only the zoom
|
||||
|
||||
@ -6,14 +6,10 @@ import 'package:flame_fire_atlas/flame_fire_atlas.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() async {
|
||||
try {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final game = ExampleGame();
|
||||
runApp(GameWidget(game: game));
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
class ExampleGame extends FlameGame with TapDetector {
|
||||
|
||||
@ -27,7 +27,7 @@ abstract class PositionBodyComponent<T extends Forge2DGame>
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
updatePositionComponent();
|
||||
positionComponent..anchor = Anchor.center;
|
||||
positionComponent.anchor = Anchor.center;
|
||||
gameRef.add(positionComponent);
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ abstract class PositionBodyComponent<T extends Forge2DGame>
|
||||
}
|
||||
|
||||
void updatePositionComponent() {
|
||||
positionComponent.position..setFrom(body.position);
|
||||
positionComponent.position.setFrom(body.position);
|
||||
positionComponent.position.y *= -1;
|
||||
positionComponent
|
||||
..angle = -angle
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# Source of linter options:
|
||||
# http://dart-lang.github.io/linter/lints/options/options.html
|
||||
# https://dart-lang.github.io/linter/lints/options/options.html
|
||||
|
||||
analyzer:
|
||||
strong-mode:
|
||||
@ -12,7 +12,9 @@ linter:
|
||||
- always_put_control_body_on_new_line
|
||||
- always_require_non_null_named_parameters
|
||||
- annotate_overrides
|
||||
- avoid_bool_literals_in_conditional_expressions
|
||||
- avoid_double_and_int_checks
|
||||
- avoid_catches_without_on_clauses
|
||||
- avoid_dynamic_calls
|
||||
- avoid_empty_else
|
||||
- avoid_equals_and_hash_code_on_mutable_classes
|
||||
@ -26,6 +28,7 @@ linter:
|
||||
- avoid_relative_lib_imports
|
||||
- avoid_return_types_on_setters
|
||||
- avoid_shadowing_type_parameters
|
||||
- avoid_single_cascade_in_expression_statements
|
||||
- avoid_slow_async_io
|
||||
- avoid_type_to_string
|
||||
- avoid_types_as_parameter_names
|
||||
@ -47,6 +50,7 @@ linter:
|
||||
- empty_statements
|
||||
- exhaustive_cases
|
||||
- file_names
|
||||
- flutter_style_todos
|
||||
- hash_and_equals
|
||||
- implementation_imports
|
||||
- invariant_booleans
|
||||
@ -91,7 +95,6 @@ linter:
|
||||
- prefer_is_not_empty
|
||||
- prefer_is_not_operator
|
||||
- prefer_iterable_whereType
|
||||
# - prefer_mixin
|
||||
- prefer_null_aware_operators
|
||||
- prefer_single_quotes
|
||||
- prefer_spread_collections
|
||||
@ -114,7 +117,9 @@ linter:
|
||||
- unnecessary_lambdas
|
||||
- unnecessary_new
|
||||
- unnecessary_null_aware_assignments
|
||||
- unnecessary_null_checks
|
||||
- unnecessary_null_in_if_null_operators
|
||||
- unnecessary_nullable_for_final_variable_declarations
|
||||
- unnecessary_overrides
|
||||
- unnecessary_parenthesis
|
||||
- unnecessary_raw_strings
|
||||
@ -128,4 +133,6 @@ linter:
|
||||
- use_function_type_syntax_for_parameters
|
||||
- use_is_even_rather_than_modulo
|
||||
- use_rethrow_when_possible
|
||||
- use_test_throws_matchers
|
||||
- valid_regexps
|
||||
- void_checks
|
||||
|
||||
Reference in New Issue
Block a user