Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gamepad support #539

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lucacasonato
Copy link
Contributor

@lucacasonato lucacasonato commented May 10, 2022

This commit adds support for playing PROXX with a gamepad. The gamepad
can be used both on the game board, and in the menus. On the game board
it can be used to clear (A or LB) or flag (X or RB) tiles, navigate the
board using the D-Pad, and switch into alt mode (B). On the menu, A can
be used to confirm (Start or Restart) and B can be used to go back or
cancel.

I tried to keep this relatively light-weight, but it does add a bit of
extra code to the initial bundle (the Gamepad handling specifically). If
the user does not use a game pad, the code will not cause any extra CPU
usage.

I have tested this on a Steamdeck, and on a Linux machine using an Xbox
One controller.

See me trying it out on my Steamdeck here: https://www.youtube.com/watch?v=094whsi4pdw

@lucacasonato lucacasonato changed the title [WIP]: gamepad support Gamepad support May 11, 2022
This commit adds support for playing PROXX with a gamepad. The gamepad
can be used both on the game board, and in the menus. On the game board
it can be used to clear (A or LB) or flag (X or RB) tiles, navigate the
board using the D-Pad, and switch into alt mode (B). On the menu, A can
be used to confirm (Start or Restart) and B can be used to go back or
cancel.

I tried to keep this relatively light-weight, but it does add a bit of
extra code to the initial bundle (the Gamepad handling specifically). If
the user does not use a game pad, the code will not cause any extra CPU
usage.
@lucacasonato lucacasonato changed the title Gamepad support Add gamepad support May 11, 2022
@jakearchibald
Copy link
Contributor

Thanks for getting this together! I'll review and merge when I get a bit of free time (next week hopefully)

@@ -150,10 +160,24 @@ export default class Game extends Component<Props, State> {
#
</span>
)}{" "}
{isGamepadConnected ? (
<span class={[gamepadButton, gamepadButtonA].join(" ")}>
A
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be very specific to particular gamepads, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. This is the key mapping for most Xbox derived gamepads, but will not match for JoyCons or Playstation controllers. I don't think the Gamepad API provides functionality to get the labels for each button, so this would have to be hardcoded based on gamepad vendor id / name most likely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ok, I'll need to address that in some way before landing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Just to clarify though: while the labels will not match (A on Xbox is X on PS), the actual input handling is correct. Pressing "X" on the PS controller will start a game etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s gonna be hard to find a perfect solution. We could add a map that maps from gamepad name to button config, and one fallback config...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants