Last active
September 15, 2020 12:26
-
-
Save Plnda/44a1fc04d957b033c60c6c77c0599ff0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var emulatedGamepad = { | |
id: "Emulated iOS Controller", | |
index: 0, | |
connected: true, | |
timestamp: 0, | |
mapping: "standard", | |
axes: [0, 0, 0, 0], | |
buttons: new Array(17).fill().map(m => ({pressed: false, touched: false, value: 0})) | |
} | |
navigator.getGamepads = function() { | |
window.webkit.messageHandlers.controller.postMessage({}).then((controllerData) => { | |
try { | |
var data = JSON.parse(controllerData); | |
for(let i = 0; i < data.buttons.length; i++) { | |
emulatedGamepad.buttons[i].pressed = data.buttons[i].pressed; | |
emulatedGamepad.buttons[i].value = data.buttons[i].value; | |
} | |
for(let i = 0; i < data.axes.length; i++) { | |
emulatedGamepad.axes[i] = data.axes[i] | |
} | |
} catch(e) { | |
} | |
}); | |
return [emulatedGamepad, null, null, null]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment