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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<dfn>A new `Gamepad`</dfn> with optional |index:long| representing a
connected gamepad device is constructed by performing the following
steps:
</p>
<ol>
<li>Let |gamepad:Gamepad| be a newly created {{Gamepad}} instance:
<ol>
<li>Initialize |gamepad|'s {{Gamepad/id}} attribute to an
identification string for the gamepad.
</li>
<li>Initialize |gamepad|'s {{Gamepad/index}} attribute to the
result of [=selecting an unused gamepad index=] for |gamepad|.
<li>Initialize |gamepad|'s {{Gamepad/index}} attribute to:
<ul>
<li>|index|, if |index| is provided, or
</li>
<li>The result of [=selecting an unused gamepad index=] for
|gamepad|.
</li>
</ul>
</li>
<li>Initialize |gamepad|'s {{Gamepad/mapping}} attribute to the
result of [=selecting a mapping=] for the gamepad device.
Expand Down
Loading