MCPcopy Index your code
hub / github.com/EmulatorJS/EmulatorJS / gamepadEvent

Method gamepadEvent

data/src/emulator.js:3350–3432  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

3348 }
3349 }
3350 gamepadEvent(e) {
3351 if (!this.started) return;
3352 const gamepadIndex = this.gamepadSelection.indexOf(this.gamepad.gamepads[e.gamepadIndex].id + "_" + this.gamepad.gamepads[e.gamepadIndex].index);
3353 if (gamepadIndex < 0) {
3354 return; // Gamepad not set anywhere
3355 }
3356 const value = function (value) {
3357 if (value > 0.5 || value < -0.5) {
3358 return (value > 0) ? 1 : -1;
3359 } else {
3360 return 0;
3361 }
3362 }(e.value || 0);
3363 if (this.controlPopup.parentElement.parentElement.getAttribute("hidden") === null) {
3364 if ("buttonup" === e.type || (e.type === "axischanged" && value === 0)) return;
3365 const num = this.controlPopup.getAttribute("button-num");
3366 const player = parseInt(this.controlPopup.getAttribute("player-num"));
3367 if (gamepadIndex !== player) return;
3368 if (!this.controls[player][num]) {
3369 this.controls[player][num] = {};
3370 }
3371 this.controls[player][num].value2 = e.label;
3372 this.controlPopup.parentElement.parentElement.setAttribute("hidden", "");
3373 this.checkGamepadInputs();
3374 this.saveSettings();
3375 return;
3376 }
3377 if (this.settingsMenu.style.display !== "none" || this.isPopupOpen()) return;
3378 const special = [16, 17, 18, 19, 20, 21, 22, 23];
3379 for (let i = 0; i < 4; i++) {
3380 if (gamepadIndex !== i) continue;
3381 for (let j = 0; j < 30; j++) {
3382 if (!this.controls[i][j] || this.controls[i][j].value2 === undefined) {
3383 continue;
3384 }
3385 const controlValue = this.controls[i][j].value2;
3386
3387 if (["buttonup", "buttondown"].includes(e.type) && (controlValue === e.label || controlValue === e.index)) {
3388 this.gameManager.simulateInput(i, j, (e.type === "buttonup" ? 0 : (special.includes(j) ? 0x7fff : 1)));
3389 } else if (e.type === "axischanged") {
3390 if (typeof controlValue === "string" && controlValue.split(":")[0] === e.axis) {
3391 if (special.includes(j)) {
3392 if (j === 16 || j === 17) {
3393 if (e.value > 0) {
3394 this.gameManager.simulateInput(i, 16, 0x7fff * e.value);
3395 this.gameManager.simulateInput(i, 17, 0);
3396 } else {
3397 this.gameManager.simulateInput(i, 17, -0x7fff * e.value);
3398 this.gameManager.simulateInput(i, 16, 0);
3399 }
3400 } else if (j === 18 || j === 19) {
3401 if (e.value > 0) {
3402 this.gameManager.simulateInput(i, 18, 0x7fff * e.value);
3403 this.gameManager.simulateInput(i, 19, 0);
3404 } else {
3405 this.gameManager.simulateInput(i, 19, -0x7fff * e.value);
3406 this.gameManager.simulateInput(i, 18, 0);
3407 }

Callers

nothing calls this directly

Calls 3

saveSettingsMethod · 0.95
isPopupOpenMethod · 0.95
simulateInputMethod · 0.80

Tested by

no test coverage detected