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