Skip to content

Commit 8cadff2

Browse files
lea108spydon
andauthored
feat: New package flame_gamepads (#3886)
Adds new package flame_gamepads. This package provides a GamepadCallbacks mixin to use gamepads library with Flame. --------- Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
1 parent fbd9b67 commit 8cadff2

18 files changed

Lines changed: 395 additions & 0 deletions

.github/.cspell/words_dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ rerasterize
2525
rescan
2626
Roboto
2727
tappable
28+
thumbstick
2829
underutilize

doc/bridge_packages/bridge_packages.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ Create texture atlases for games (bridge package for [FireAtlas]).
3636
A Box2D physics engine (bridge package for [Forge2D]).
3737
:::
3838

39+
:::{package} flame_gamepads
40+
41+
Support gamepad input in your game (bridge package for [gamepads])
42+
:::
43+
3944
:::{package} flame_isolate
4045

4146
Use isolates to offload heavy computations to another thread.
@@ -101,6 +106,7 @@ Load Typled sprite atlases with edge-repeated padding (bridge package for [Typle
101106
[Bloc]: https://github.com/felangel/bloc
102107
[FireAtlas]: https://github.com/flame-engine/fire-atlas
103108
[Forge2D]: https://github.com/flame-engine/forge2d
109+
[gamepads]: https://github.com/flame-engine/gamepads
104110
[Lottie]: https://pub.dev/packages/lottie
105111
[Rive]: https://rive.app/
106112
[Riverpod]: https://github.com/rrousselGit/riverpod
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# flame_gamepads
2+
3+
**flame_gamepads** provides helping bridge functionality to use the `gamepads` package in your flame
4+
game.
5+
6+
7+
## GamepadCallbacks mixin
8+
9+
Add `GamepadCallbacks` mixin to your component with the `with` keyword and override the
10+
`onGamepadEvent` method to receive callbacks when a gamepad event occurs.
11+
12+
```dart
13+
class PlayerComponent extends PositionComponent with GamepadCallbacks {
14+
@override
15+
void onGamepadEvent(NormalizedGamepadEvent event) {
16+
if (event.button == GamepadButton.a && event.value != 0) {
17+
// 'a' button pressed.
18+
}
19+
}
20+
}
21+
```
22+
23+
An example of how to use the API can be found
24+
[here](https://github.com/flame-engine/flame/tree/main/packages/flame_gamepads/example).
25+
26+
See the lib [gamepads](https://github.com/flame-engine/gamepads.dart) for more info on how to
27+
process the NormalizedGamepadEvent data.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
## 0.1.0
3+
4+
- Add GamepadCallbacks mixin

packages/flame_gamepads/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Blue Fire
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

packages/flame_gamepads/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!-- markdownlint-disable MD013 -->
2+
<p align="center">
3+
<a href="https://flame-engine.org">
4+
<img alt="flame" width="200px" src="https://user-images.githubusercontent.com/6718144/101553774-3bc7b000-39ad-11eb-8a6a-de2daa31bd64.png">
5+
</a>
6+
</p>
7+
8+
<p align="center">
9+
Support gamepad input in your game (bridge package for <a href="https://github.com/flame-engine/gamepads">gamepads</a>)
10+
</p>
11+
12+
<p align="center">
13+
<a title="Pub" href="https://pub.dev/packages/flame_gamepads" ><img src="https://img.shields.io/pub/v/flame_gamepads.svg?style=popout" /></a>
14+
<a title="Test" href="https://github.com/flame-engine/flame/actions?query=workflow%3Acicd+branch%3Amain"><img src="https://github.com/flame-engine/flame/actions/workflows/cicd.yml/badge.svg?branch=main&event=push"/></a>
15+
<a title="Discord" href="https://discord.gg/pxrBmy4"><img src="https://img.shields.io/discord/509714518008528896.svg"/></a>
16+
<a title="Melos" href="https://github.com/invertase/melos"><img src="https://img.shields.io/badge/maintained%20with-melos-f700ff.svg"/></a>
17+
</p>
18+
19+
---
20+
<!-- markdownlint-enable MD013 -->
21+
22+
<!-- markdownlint-disable-next-line MD002 -->
23+
24+
# flame_gamepads
25+
26+
Package to bridge the `gamepads` library to easy-to-use Flame bindings.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:flame_lint/analysis_options_with_dcm.yaml
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
# VS Code which you may wish to be included in version control, so this line
23+
# is commented out by default.
24+
#.vscode/
25+
26+
# Flutter/Dart/Pub related
27+
**/doc/api/
28+
**/ios/Flutter/.last_build_id
29+
.dart_tool/
30+
.flutter-plugins-dependencies
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
/coverage/
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Android Studio will place build artifacts here
43+
/android/app/debug
44+
/android/app/profile
45+
/android/app/release
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# flame_gamepads example
2+
3+
Simple project to showcase the usage of flame_gamepads input handling.
4+
5+
Use the left stick on your gamepad to control the player.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include: package:flame_lint/analysis_options_with_dcm.yaml
2+
3+
linter:
4+
rules:
5+
public_member_api_docs: false

0 commit comments

Comments
 (0)