mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-29 16:05:47 +08:00
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:
@ -287,15 +287,13 @@ MyCollidable randomCollidable(
|
||||
final rng = random ?? Random();
|
||||
final rotationSpeed = 0.5 - rng.nextDouble();
|
||||
final shapeType = Shapes.values[rng.nextInt(Shapes.values.length)];
|
||||
switch (shapeType) {
|
||||
case Shapes.circle:
|
||||
return CollidableCircle(position, size, velocity, screenHitbox)
|
||||
..rotationSpeed = rotationSpeed;
|
||||
case Shapes.rectangle:
|
||||
return CollidableRectangle(position, size, velocity, screenHitbox)
|
||||
..rotationSpeed = rotationSpeed;
|
||||
case Shapes.polygon:
|
||||
return CollidablePolygon(position, size, velocity, screenHitbox)
|
||||
..rotationSpeed = rotationSpeed;
|
||||
}
|
||||
return switch (shapeType) {
|
||||
Shapes.circle => CollidableCircle(position, size, velocity, screenHitbox)
|
||||
..rotationSpeed = rotationSpeed,
|
||||
Shapes.rectangle =>
|
||||
CollidableRectangle(position, size, velocity, screenHitbox)
|
||||
..rotationSpeed = rotationSpeed,
|
||||
Shapes.polygon => CollidablePolygon(position, size, velocity, screenHitbox)
|
||||
..rotationSpeed = rotationSpeed,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user