-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added GamepadState that can be updated (#43)
- Loading branch information
1 parent
ca9916b
commit 0c9890e
Showing
5 changed files
with
67 additions
and
6 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
27 changes: 27 additions & 0 deletions
27
packages/gamepads_platform_interface/lib/api/gamepad_state.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,27 @@ | ||
import 'package:gamepads_platform_interface/api/gamepad_event.dart'; | ||
|
||
/// The current state of a gamepad. | ||
/// | ||
/// This class keeps mutable state and is intended to be kept up-to-date by | ||
/// calling [update] with the latest [GamepadEvent]. The [analogInputs] and | ||
/// [buttonInputs] maps correspond to [KeyType.analog] and [KeyType.button], | ||
/// respectively. | ||
class GamepadState { | ||
/// Contains inputs from events where [GamepadEvent.type] is [KeyType.analog]. | ||
final Map<String, double> analogInputs = {}; | ||
|
||
/// Contains inputs from events where [GamepadEvent.type] is [KeyType.button]. | ||
final Map<String, bool> buttonInputs = {}; | ||
|
||
/// Updates the state based on the given event. | ||
void update(GamepadEvent event) { | ||
switch (event.type) { | ||
case KeyType.analog: | ||
analogInputs[event.key] = event.value; | ||
break; | ||
case KeyType.button: | ||
buttonInputs[event.key] = event.value == 1; | ||
break; | ||
} | ||
} | ||
} |
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