This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: made MapBounds immutable (#144)
* refactor: made MapBounds immutable * refactor: remove redundant import
- Loading branch information
Showing
7 changed files
with
47 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flame/components.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:trashy_road/src/game/models/models.dart'; | ||
|
||
@immutable | ||
class MapBounds { | ||
const MapBounds._(this.topLeft, this.bottomRight); | ||
|
||
/// Creates a [MapBounds] from the left, top, width and height. | ||
/// | ||
/// Similar to `Rect.fromLTWH` from `dart:ui`. | ||
factory MapBounds.fromLTWH(double x, double y, double width, double height) { | ||
final topLeft = UnmodifiableVector2View(x, y); | ||
final bottomRight = UnmodifiableVector2View(x + width, y + height); | ||
return MapBounds._(topLeft, bottomRight); | ||
} | ||
|
||
final UnmodifiableVector2View topLeft; | ||
final UnmodifiableVector2View bottomRight; | ||
|
||
bool isPointInside(Vector2 position) => | ||
position.x >= topLeft.x && | ||
position.x <= bottomRight.x && | ||
position.y <= bottomRight.y && | ||
position.y >= topLeft.y; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'map_bounds.dart'; | ||
export 'unmodifiable_vector2.dart'; |
10 changes: 10 additions & 0 deletions
10
packages/trashy_road/lib/src/game/models/unmodifiable_vector2.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:flame/components.dart' show Vector2; | ||
|
||
class UnmodifiableVector2View extends Vector2 { | ||
UnmodifiableVector2View(double x, double y) | ||
: super.fromFloat64List( | ||
UnmodifiableFloat64ListView(Float64List.fromList([x, y])), | ||
); | ||
} |