Skip to content

Commit

Permalink
fix some lint
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelBarbosatec committed Dec 27, 2024
1 parent adb6b5d commit 62a9c7f
Show file tree
Hide file tree
Showing 36 changed files with 282 additions and 220 deletions.
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ include: package:flame_lint/analysis_options.yaml

analyzer:
errors:
avoid_bool_literals_in_conditional_expressions: ignore
avoid_catches_without_on_clauses: ignore
avoid_positional_boolean_parameters: ignore
comment_references: ignore
use_if_null_to_convert_nulls_to_bools: ignore
exclude:
- 'example/**'
2 changes: 1 addition & 1 deletion example/lib/shared/decoration/spikes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Spikes extends GameDecoration with Sensor<Attackable> {
position: position,
size: size ?? Vector2.all(DungeonMap.tileSize / 1.5),
) {
setSensorInterval(500);
sensorInterval = 500;
}

@override
Expand Down
6 changes: 4 additions & 2 deletions lib/background/background_image_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
///
/// Rafaelbarbosatec
/// on 30/11/21
library;

import 'package:bonfire/bonfire.dart';
import 'package:bonfire/camera/bonfire_camera.dart';
import 'package:bonfire/map/util/map_assets_manager.dart';
Expand Down Expand Up @@ -48,8 +50,8 @@ class BackgroundImageGame extends GameBackground with UseSprite {
if (camera.position != _lastPosition) {
_lastPosition = camera.position.clone();
position = _parallaxOffset.translated(
(camera.position.x * -(parallaxX / camera.zoom)),
(camera.position.y * -(parallaxY / camera.zoom)),
camera.position.x * -(parallaxX / camera.zoom),
camera.position.y * -(parallaxY / camera.zoom),
);
}
}
Expand Down
32 changes: 22 additions & 10 deletions lib/base/base_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class BaseGame extends FlameGame
@override
void updateTree(double dt) {
_gesturesComponents = [...world.children, ...camera.viewport.children]
.where((c) => _hasGesture(c))
.where(_hasGesture)
.cast<PointerDetectorHandler>();
super.updateTree(dt);
}
Expand All @@ -38,7 +38,9 @@ abstract class BaseGame extends FlameGame

@override
void onPointerCancel(PointerCancelEvent event) {
if (!hasLayout || !enabledGestures) return;
if (!hasLayout || !enabledGestures) {
return;
}
for (final c in _gesturesComponents) {
if (c.handlerPointerCancel(event)) {
return;
Expand All @@ -48,7 +50,9 @@ abstract class BaseGame extends FlameGame

@override
void onPointerUp(PointerUpEvent event) {
if (!hasLayout || !enabledGestures) return;
if (!hasLayout || !enabledGestures) {
return;
}
for (final c in _gesturesComponents) {
if (c.handlerPointerUp(event)) {
return;
Expand All @@ -58,7 +62,9 @@ abstract class BaseGame extends FlameGame

@override
void onPointerMove(PointerMoveEvent event) {
if (!hasLayout || !enabledGestures) return;
if (!hasLayout || !enabledGestures) {
return;
}
for (final c in _gesturesComponents) {
if (c.handlerPointerMove(event)) {
return;
Expand All @@ -68,7 +74,9 @@ abstract class BaseGame extends FlameGame

@override
void onPointerDown(PointerDownEvent event) {
if (!hasLayout || !enabledGestures) return;
if (!hasLayout || !enabledGestures) {
return;
}
for (final c in _gesturesComponents) {
if (c.handlerPointerDown(event)) {
return;
Expand All @@ -78,7 +86,9 @@ abstract class BaseGame extends FlameGame

@override
void onPointerHover(PointerHoverEvent event) {
if (!hasLayout || !enabledGestures) return;
if (!hasLayout || !enabledGestures) {
return;
}
for (final c in _gesturesComponents) {
if (c.handlerPointerHover(event)) {
return;
Expand All @@ -88,7 +98,9 @@ abstract class BaseGame extends FlameGame

@override
void onPointerSignal(PointerSignalEvent event) {
if (!hasLayout || !enabledGestures) return;
if (!hasLayout || !enabledGestures) {
return;
}
for (final c in _gesturesComponents) {
if (c.handlerPointerSignal(event)) {
return;
Expand All @@ -101,11 +113,11 @@ abstract class BaseGame extends FlameGame
KeyEvent event,
Set<LogicalKeyboardKey> keysPressed,
) {
KeyEventResult result = KeyEventResult.ignored;
var result = KeyEventResult.ignored;
if (!enabledKeyboard) {
return result;
}
for (var listener in _keyboardComponents) {
for (final listener in _keyboardComponents) {
if (listener.onKeyboard(event, keysPressed)) {
result = KeyEventResult.handled;
}
Expand All @@ -115,7 +127,7 @@ abstract class BaseGame extends FlameGame

/// Verify if the Component contain gestures.
bool _hasGesture(Component c) {
return ((c is GameComponent && c.isVisible)) && ((c).hasGesture());
return (c is GameComponent && c.isVisible) && (c.hasGesture());
}

@override
Expand Down
18 changes: 0 additions & 18 deletions lib/base/bonfire_game_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:bonfire/bonfire.dart';
import 'package:bonfire/camera/bonfire_camera.dart';
import 'package:bonfire/color_filter/color_filter_component.dart';
import 'package:bonfire/lighting/lighting_component.dart';
import 'package:flame/game.dart';
// ignore: implementation_imports
import 'package:flame/src/game/overlay_manager.dart';
import 'package:flutter/widgets.dart';
Expand Down Expand Up @@ -40,23 +39,6 @@ abstract class BonfireGameInterface {
SceneBuilderStatus sceneBuilderStatus = SceneBuilderStatus();
double timeScale = 1.0;

/// A property that stores an [ActiveOverlaysNotifier]
///
/// This is useful to render widgets above a game, like a pause menu for
/// example.
/// Overlays visible or hidden via [overlays].add or [overlays].remove,
/// respectively.
///
/// Ex:
/// ```
/// final pauseOverlayIdentifier = 'PauseMenu';
/// overlays.add(pauseOverlayIdentifier); // marks 'PauseMenu' to be rendered.
/// overlays.remove(pauseOverlayIdentifier); // marks 'PauseMenu' to not be rendered.
/// ```
///
/// See also:
/// - GameWidget
/// - [Game.overlayManager]
// ignore: invalid_use_of_internal_member
OverlayManager get overlays;

Expand Down
34 changes: 24 additions & 10 deletions lib/base/game_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class GameComponent extends PositionComponent
InternalChecker,
HasPaint,
CollisionCallbacks {
final String _keyIntervalCheckIsVisible = "CHECK_VISIBLE";
final String _keyIntervalCheckIsVisible = 'CHECK_VISIBLE';
final int _intervalCheckIsVisible = 100;
Map<String, dynamic>? properties;

Expand All @@ -22,7 +22,14 @@ abstract class GameComponent extends PositionComponent
/// Param checks if this component is visible on the screen
bool _isVisibleInScreen = false;

bool get isVisible => _visible ? _isVisibleInScreen : false;
bool get isVisible {
if (_visible) {
return _isVisibleInScreen;
}

return false;
}

set isVisible(bool visible) {
_visible = visible;
}
Expand Down Expand Up @@ -67,7 +74,9 @@ abstract class GameComponent extends PositionComponent
}

void _checkIsVisible(double dt) {
if (!enabledCheckIsVisible) return;
if (!enabledCheckIsVisible) {
return;
}
if (checkInterval(
_keyIntervalCheckIsVisible,
_intervalCheckIsVisible,
Expand All @@ -90,7 +99,10 @@ abstract class GameComponent extends PositionComponent
/// Method that checks if this component is visible on the screen
@mustCallSuper
bool isVisibleInCamera() {
return hasGameRef ? gameRef.isVisibleInCamera(this) : false;
if (hasGameRef) {
return gameRef.isVisibleInCamera(this);
}
return false;
}

@override
Expand All @@ -101,8 +113,10 @@ abstract class GameComponent extends PositionComponent
}

void _onSetIfVisible() {
if (!_visible) return;
bool nowIsVisible = isVisibleInCamera();
if (!_visible) {
return;
}
var nowIsVisible = isVisibleInCamera();
if (isHud) {
nowIsVisible = true;
enabledCheckIsVisible = false;
Expand Down Expand Up @@ -134,7 +148,7 @@ abstract class GameComponent extends PositionComponent
void _confHitBoxRender(Component component) {
if (component is ShapeHitbox) {
if (gameRef.showCollisionArea) {
var paintCollition = Paint()
final paintCollition = Paint()
..color = gameRef.collisionAreaColor ?? const Color(0xffffffff);
if (this is Sensor) {
paintCollition.color = Sensor.color;
Expand All @@ -153,7 +167,7 @@ abstract class GameComponent extends PositionComponent

Rect get rectCollision {
if (_rectCollision == null) {
var list = children.query<ShapeHitbox>();
final list = children.query<ShapeHitbox>();
if (list.isNotEmpty) {
_rectCollision = list.fold(
list.first.toRect(),
Expand All @@ -163,7 +177,7 @@ abstract class GameComponent extends PositionComponent
);
}
}
var absoluteRect = toAbsoluteRect();
final absoluteRect = toAbsoluteRect();

if (_rectCollision != null) {
return _rectCollision!.translate(absoluteRect.left, absoluteRect.top);
Expand Down Expand Up @@ -245,7 +259,7 @@ abstract class GameComponent extends PositionComponent
}

List<ShapeHitbox> _getSensorsHitbox() {
var sensorHitBox = <ShapeHitbox>[];
final sensorHitBox = <ShapeHitbox>[];
gameRef.query<Sensor>(onlyVisible: true).forEach((e) {
sensorHitBox.addAll(e.children.query<ShapeHitbox>());
});
Expand Down
23 changes: 12 additions & 11 deletions lib/base/listener_game_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ typedef GameFactory<T extends Game> = T Function();
class ListenerGameWidget<T extends Game> extends StatefulWidget {
/// The game instance which this widget will render, if the normal constructor
/// is used.
/// If the [ListenerGameWidget.controlled] constructor is used, this will always be
/// `null`.
/// If the [ListenerGameWidget.controlled] constructor is used, this will
/// aways be `null`.
final T? game;

/// A function that creates a [Game] that this widget will render.
Expand Down Expand Up @@ -121,8 +121,8 @@ class ListenerGameWidget<T extends Game> extends StatefulWidget {
/// game.overlays.add('PauseMenu');
/// ```
ListenerGameWidget({
Key? key,
required T this.game,
super.key,
this.textDirection,
this.loadingBuilder,
this.errorBuilder,
Expand All @@ -133,8 +133,7 @@ class ListenerGameWidget<T extends Game> extends StatefulWidget {
this.autofocus = true,
this.mouseCursor,
this.addRepaintBoundary = true,
}) : gameFactory = null,
super(key: key) {
}) : gameFactory = null {
_initializeGame(game!);
}

Expand Down Expand Up @@ -198,11 +197,12 @@ class ListenerGameWidgetState<T extends Game>
///
/// This is needed because our build function invokes user code, which in turn
/// may change some of the [Game]'s properties which would require the
/// [ListenerGameWidget] to be rebuilt. However, Flutter doesn't allow widgets to be
/// [ListenerGameWidget] to be rebuilt. However, Flutter doesn't allow widgets
/// to be
/// marked dirty while they are building. So, this method is needed to avoid
/// such a limitation and ensure that the user code can set [Game]'s
/// properties freely, and that they will be propagated to the [ListenerGameWidget]
/// at the earliest opportunity.
/// properties freely, and that they will be propagated to the
/// [ListenerGameWidget] at the earliest opportunity.
Widget _protectedBuild(Widget Function() build) {
late final Widget result;
try {
Expand Down Expand Up @@ -382,9 +382,10 @@ class ListenerGameWidgetState<T extends Game>
Container();
}
currentGame.onGameResize(size);
// This should only be called if the game has already been
// loaded (in the case of resizing for example), since
// update otherwise should be called after onMount.
// This should only be called if the game has already
// been loaded (in the case of resizing for example),
// since update otherwise should be called after
// onMount.
if (!currentGame.paused && currentGame.isAttached) {
currentGame.update(0);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/behavior/behavior_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BehaviorManager extends Component with BonfireHasGameRef {

@override
void onMount() {
_comp = parent as GameComponent;
_comp = parent! as GameComponent;
super.onMount();
}
}
2 changes: 1 addition & 1 deletion lib/behavior/behaviors/b_contition/b_condition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class BCondition extends Behavior {
final Behavior? doElseBehavior;

BCondition({
dynamic id,
required this.condition,
required this.doBehavior,
dynamic id,
this.doElseBehavior,
}) : super(id);

Expand Down
4 changes: 2 additions & 2 deletions lib/behavior/behaviors/b_contition/conditions/c_can_see.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class CCanSee extends Condition {
@override
bool execute(GameComponent comp, BonfireGameInterface game) {
if (comp is Vision) {
bool see = false;
var see = false;
comp.seeComponent(
target,
radiusVision: radiusVision,
visionAngle: visionAngle,
angle: angle,
observed: (c) {
observed?.call(c);
return see = true;
see = true;
},
);
return see;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class CCanSeeType<T extends GameComponent> extends Condition {
@override
bool execute(GameComponent comp, BonfireGameInterface game) {
if (comp is Vision) {
bool see = false;
var see = false;
comp.seeComponentType<T>(
radiusVision: radiusVision,
visionAngle: visionAngle,
angle: angle,
observed: (c) {
observed?.call(c);
return see = true;
see = true;
},
);
return see;
Expand Down
Loading

0 comments on commit 62a9c7f

Please sign in to comment.