refactor: Modernize switch; use switch-expressions and no break; (#3133)

Replaces the switch cases that can be replaces with switch expressions
and removes `break;` where it isn't needed.

https://dart.dev/language/branches#switch-statements
This commit is contained in:
Lukas Klingsbo
2024-04-18 23:41:08 +02:00
committed by GitHub
parent 69f5c388ce
commit b283b82f6c
29 changed files with 183 additions and 425 deletions

View File

@ -27,21 +27,19 @@ class _GestureHitboxesWorld extends World with TapCallbacks {
final shapeSize =
Vector2.all(100) + Vector2.all(50.0).scaled(_rng.nextDouble());
final shapeAngle = _rng.nextDouble() * 6;
ShapeHitbox hitbox;
switch (shapeType) {
case Shapes.circle:
hitbox = CircleHitbox();
case Shapes.rectangle:
hitbox = RectangleHitbox();
case Shapes.polygon:
final points = [
-Vector2.random(_rng),
Vector2.random(_rng)..x *= -1,
Vector2.random(_rng),
Vector2.random(_rng)..y *= -1,
];
hitbox = PolygonHitbox.relative(points, parentSize: shapeSize);
}
final hitbox = switch (shapeType) {
Shapes.circle => CircleHitbox(),
Shapes.rectangle => RectangleHitbox(),
Shapes.polygon => PolygonHitbox.relative(
[
-Vector2.random(_rng),
Vector2.random(_rng)..x *= -1,
Vector2.random(_rng),
Vector2.random(_rng)..y *= -1,
],
parentSize: shapeSize,
),
};
return MyShapeComponent(
hitbox: hitbox,
position: position,