Skip to content

Commit 119053c

Browse files
cabaniertoji
authored andcommitted
make controller-state resilient to gamepad changes
1 parent 870336f commit 119053c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

controller-state.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@
184184
class GamepadBoxSet extends Node {
185185
constructor(buttonCount, axesCount) {
186186
super();
187+
this.setup_buttons_and_axes(buttonCount, axesCount);
188+
}
187189

190+
setup_buttons_and_axes(buttonCount, axesCount) {
188191
let axesBoxCount = Math.ceil(axesCount / 2);
189192
let rowLength = Math.max(buttonCount, axesBoxCount);
190193

@@ -206,6 +209,12 @@
206209
}
207210

208211
update_state(gamepad) {
212+
if ((gamepad.buttons.length !== this.buttonBoxes.length)||(gamepad.axes.length/2 !== this.axesBoxes.length)) {
213+
this.clearNodes();
214+
this.buttonBoxes = [];
215+
this.axesBoxes = [];
216+
this.setup_buttons_and_axes(gamepad.buttons.length, gamepad.axes.length );
217+
}
209218
// The boxes associated with any given button will turn green if
210219
// touched and red if pressed. The box height will also scale based
211220
// on the button's value to make it appear like a button being pushed.

0 commit comments

Comments
 (0)