Skip to content

Commit

Permalink
fix: analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ASGAlex committed Jul 25, 2023
1 parent 360c27f commit 4529e8a
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 15 deletions.
15 changes: 11 additions & 4 deletions example/lib/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -457,15 +457,21 @@ class MyWorld extends World with TapCallbacks, HasGameRef<SpatialGridExample> {
gameRef.spatialGrid.cells.forEach((rect, cell) {
if (cell.rect.containsPoint(tapPosition)) {
cellsUnderCursor.add(cell);
print(cell.outOfBoundsCounter);
if (kDebugMode) {
print(cell.outOfBoundsCounter);
}
// print('State: + ${cell.state}');
print('Rect: $rect');
if (kDebugMode) {
print('Rect: $rect');
}

// print('Components count: ${cell.components.length}');
}
});

print('========================================');
if (kDebugMode) {
print('========================================');
}
final list = componentsAtPoint(tapPosition).toList(growable: false);
for (final component in list) {
if (component is! HasGridSupport) {
Expand Down Expand Up @@ -543,7 +549,7 @@ class DemoMapLoader extends TiledMapLoader {
final waterAnimation =
getPreloadedTileData('tileset', 'Water')?.spriteAnimation;

final stepSize = waterAnimation?.ticker().getSprite().srcSize.x;
final stepSize = waterAnimation?.createTicker().getSprite().srcSize.x;
if (stepSize == null) {
return;
}
Expand Down Expand Up @@ -830,6 +836,7 @@ class Npc extends Player with DebuggerPause {
static Image? coloredSprite;

@override
// ignore: must_call_super
Future<void> render(Canvas canvas) async {
_createColoredSprite();
canvas.drawImage(coloredSprite!, Offset.zero, paint);
Expand Down
4 changes: 1 addition & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ environment:
# versions available, run `flutter pub outdated`.
dependencies:
flame: ^1.8.1
flame_spatial_grid: # ^1.0.2
path: ../

flame_spatial_grid: 0.8.0
flame_message_stream: 0.0.2

flutter:
Expand Down
6 changes: 5 additions & 1 deletion lib/src/collisions/bounding_hitbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ class BoundingHitbox extends RectangleHitbox
void _expandBoundingBox(ShapeHitbox component) {
final currentRect = shouldFillParent
? Rect.fromLTWH(
0, 0, parentWithGridSupport!.size.x, parentWithGridSupport!.size.y)
0,
0,
parentWithGridSupport!.size.x,
parentWithGridSupport!.size.y,
)
: toRect();
final addRect = component.toRect();
final newRect = currentRect.expandToInclude(addRect);
Expand Down
8 changes: 6 additions & 2 deletions lib/src/collisions/broadphase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,12 @@ class SpatialGridBroadphase<T extends Hitbox<T>> extends Broadphase<T> {
}
}

bool _canPairToCollide(ShapeHitbox activeItem, PositionComponent activeParent,
ShapeHitbox potentialItem, PositionComponent potentialParent) {
bool _canPairToCollide(
ShapeHitbox activeItem,
PositionComponent activeParent,
ShapeHitbox potentialItem,
PositionComponent potentialParent,
) {
var canToCollide = true;

if (activeItem is BoundingHitbox) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SpriteAnimationGlobalComponent extends SpriteAnimationComponent {
final String animationType;

@override
// ignore: must_call_super
void render(Canvas canvas) {
try {
(animationTicker! as SpriteAnimationTickerGlobal)
Expand All @@ -32,6 +33,7 @@ class SpriteAnimationGlobalComponent extends SpriteAnimationComponent {
size: size,
overridePaint: paint,
);
// ignore: avoid_catches_without_on_clauses
} catch (_) {}
}
}
Expand Down
6 changes: 4 additions & 2 deletions lib/src/components/has_grid_support.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flame/collisions.dart';
import 'package:flame/components.dart';
import 'package:flame/extensions.dart';
import 'package:flame_spatial_grid/flame_spatial_grid.dart';
import 'package:flutter/foundation.dart';
import 'package:meta/meta.dart';

/// Core mixin of spatial grid framework.
Expand Down Expand Up @@ -128,7 +129,6 @@ mixin HasGridSupport on PositionComponent {
BoundingHitboxFactory get boundingHitboxFactory => () => BoundingHitbox(
position: Vector2.zero(),
size: Vector2.zero(),
collisionType: CollisionType.inactive,
parentWithGridSupport: this,
);

Expand Down Expand Up @@ -315,7 +315,9 @@ mixin HasGridSupport on PositionComponent {
for (final cell in cellNeighbours) {
cell.outOfBoundsCounter--;
if (cell.outOfBoundsCounter < 0) {
print('outOfBoundsCounter should not be below zero!');
if (kDebugMode) {
print('outOfBoundsCounter should not be below zero!');
}
cell.outOfBoundsCounter = 0;
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/components/layers/cell_static_animation_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CellStaticAnimationLayer extends CellLayer {
for (final element in frames) {
element.sprite.image.dispose();
}
// ignore: avoid_catches_without_on_clauses
} catch (_) {}
}
animationComponent?.onRemove();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/tile_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ class TileComponent extends SpriteComponent

@override
SpriteAnimationTicker? get animationTicker =>
tileCache.spriteAnimation?.ticker();
tileCache.spriteAnimation?.createTicker();
}
1 change: 1 addition & 0 deletions lib/src/core/cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class Cell {
if (target is HasGridSupport && target.currentCell == this) {
return;
}
// ignore: avoid_catches_without_on_clauses
} catch (_) {}
}

Expand Down
10 changes: 8 additions & 2 deletions lib/src/core/has_spatial_grid_framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ mixin HasSpatialGridFramework on FlameGame
);
worldLoader.currentMap = initialMap;
} else {
// ignore: parameter_assignments
initialPosition = position;
}
}
Expand All @@ -211,6 +212,7 @@ mixin HasSpatialGridFramework on FlameGame
final position =
await map.searchInitialPosition(initialPositionChecker);
if (position != null) {
// ignore: parameter_assignments
initialPosition = position;
break;
}
Expand Down Expand Up @@ -486,7 +488,9 @@ mixin HasSpatialGridFramework on FlameGame
/// with [suspendedCellLifetime] is over.
int removeUnusedCells({bool forceCleanup = false, List<Cell>? unusedCells}) {
final cellsToRemove = unusedCells ?? _catchCellsForRemoval(forceCleanup);
print('removing unused cells: ${cellsToRemove.length}');
if (kDebugMode) {
print('removing unused cells: ${cellsToRemove.length}');
}
for (final cell in cellsToRemove) {
cell.remove();
}
Expand All @@ -500,7 +504,9 @@ mixin HasSpatialGridFramework on FlameGame
// }
// print('total: ${BoundingHitbox.weakRef.length}; Not null: $i');

print('removing unused cells DONE');
if (kDebugMode) {
print('removing unused cells DONE');
}
return cellsToRemove.length;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/src/tiled/tile_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ class TileCache {
void dispose() {
try {
sprite?.image.dispose();
// ignore: avoid_catches_without_on_clauses
} catch (_) {}

final frames = spriteAnimation?.frames;
if (frames != null) {
for (final frame in frames) {
try {
frame.sprite.image.dispose();
// ignore: avoid_catches_without_on_clauses
} catch (_) {}
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/tiled/tileset_manager.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ignore_for_file: comment_references

import 'dart:collection';

import 'package:flame/flame.dart';
import 'package:flame_spatial_grid/flame_spatial_grid.dart';
import 'package:flame_spatial_grid/src/tiled/tileset_parser.dart';
import 'package:flame_tiled/flame_tiled.dart';
// ignore: implementation_imports
import 'package:flame_tiled/src/tile_atlas.dart';
import 'package:meta/meta.dart';

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
flame_tiled: ^1.12.0
meta: ^1.8.0
tiled: any
xml: any

flutter:
sdk: flutter
Expand Down

0 comments on commit 4529e8a

Please sign in to comment.