-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add TiledObjectHealpers extension on TiledObject (#3032)
This PR adds an extension on `TiledObject` to allow getting the object's `position` and `size` as `Vector2` objects. --------- Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
- Loading branch information
1 parent
d78f7f8
commit 78380b9
Showing
3 changed files
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:flame/components.dart'; | ||
import 'package:flame_tiled/flame_tiled.dart'; | ||
|
||
/// This extension adds some helpers for [TiledObject] that make it easier to | ||
/// use it with Flame. | ||
extension TiledObjectHelpers on TiledObject { | ||
/// Returns the position of this tiled object as a Vector2. | ||
Vector2 get position => Vector2(x, y); | ||
|
||
/// Returns the size of this tiled object as a Vector2. | ||
Vector2 get size => Vector2(width, height); | ||
} |
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,32 @@ | ||
import 'package:flame_tiled/flame_tiled.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('TiledObjectHelpers', () { | ||
test('position returns correct values', () { | ||
final tiledObject = TiledObject(id: 0); | ||
|
||
expect(tiledObject.position.x, 0); | ||
expect(tiledObject.position.y, 0); | ||
|
||
tiledObject.x = 26; | ||
tiledObject.y = 83; | ||
|
||
expect(tiledObject.position.x, 26); | ||
expect(tiledObject.position.y, 83); | ||
}); | ||
|
||
test('size returns correct values', () { | ||
final tiledObject = TiledObject(id: 0); | ||
|
||
expect(tiledObject.size.x, 0); | ||
expect(tiledObject.size.y, 0); | ||
|
||
tiledObject.width = 59; | ||
tiledObject.height = 42; | ||
|
||
expect(tiledObject.size.x, 59); | ||
expect(tiledObject.size.y, 42); | ||
}); | ||
}); | ||
} |