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

Allow initializing the gamepad index to a specific value #193

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from

Conversation

nondebug
Copy link
Collaborator

@nondebug nondebug commented Feb 9, 2024

Closes #???

The following tasks have been completed:

  • Modified Web platform tests (link to pull request)

Implementation commitment:


Preview | Diff

@@ -650,17 +650,24 @@ <h3>
Constructing a `Gamepad`
</h3>
<p>
<dfn>A new `Gamepad`</dfn> representing a connected gamepad device is
constructed by performing the following steps:
Copy link
Member

Choose a reason for hiding this comment

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

Who provides the index originally? I guess it's the UA. I wonder if we should make this more consistent by making it mandatory to pass the index. Would that work across browsers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The UA shouldn't decide the index, it's decided by the "select an unused gamepad index" algorithm which is based on the sequence of previous gamepad connections/disconnections.

Let's make |index| mandatory by moving index selection into the "when a gamepad becomes available on the system" steps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looking at this again I now remember why it's done this way. The "select an unused gamepad index" algorithm needs to access the Navigator object. Currently it does so by creating a Gamepad object and then finding the navigator via the Gamepad's relevant global object. If we want to pass the index into the "a new Gamepad with index" steps then we need to get the Navigator object from somewhere else, since the Gamepad doesn't exist yet. This would need to happen in the "When a gamepad becomes available on the system" steps.

Is there a way to find the relevant global object without referencing an existing object? The current method seems kind of magical, how did the Gamepad know what its relevant global object should be when it was created? We could abuse the same trick by creating a dummy object just to get its global object, but I assume there's a better way to specify this that doesn't involve creating a dummy object.

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.

None yet

2 participants