Merge pull request #20 from LoveEevee/all-gamepads

Fix gamepads with only one button
This commit is contained in:
Bui 2018-09-17 18:37:27 +01:00 committed by GitHub
commit f19fbf5371

View File

@ -9,23 +9,23 @@ class Gamepad{
this.menuBtn = {} this.menuBtn = {}
this.menuBtn[kbd["pause"]] = ["start"] this.menuBtn[kbd["pause"]] = ["start"]
this.b = { this.b = {
"a": "0", "a": 0,
"b": "1", "b": 1,
"x": "2", "x": 2,
"y": "3", "y": 3,
"lb": "4", "lb": 4,
"rb": "5", "rb": 5,
"lt": "6", "lt": 6,
"rt": "7", "rt": 7,
"back": "8", "back": 8,
"start": "9", "start": 9,
"ls": "10", "ls": 10,
"rs": "11", "rs": 11,
"u": "12", "u": 12,
"d": "13", "d": 13,
"l": "14", "l": 14,
"r": "15", "r": 15,
"guide": "16" "guide": 16
} }
this.btn = {} this.btn = {}
this.keyboard = keyboard this.keyboard = keyboard
@ -43,7 +43,7 @@ class Gamepad{
for(var bind in bindings){ for(var bind in bindings){
this.toRelease[bind] = bindings[bind].length this.toRelease[bind] = bindings[bind].length
} }
for(var btnName in gamepads[i].buttons){ for(var btnName = 0; btnName <= 16; btnName++){
buttonSearch: { buttonSearch: {
for(var bind in bindings){ for(var bind in bindings){
for(var name in bindings[bind]){ for(var name in bindings[bind]){
@ -63,12 +63,15 @@ class Gamepad{
var button = false var button = false
for(var i = 0; i < gamepads.length; i++){ for(var i = 0; i < gamepads.length; i++){
if(gamepads[i]){ if(gamepads[i]){
var btnPressed = gamepads[i].buttons[btnName].pressed var btn = gamepads[i].buttons[btnName]
if(btn){
var btnPressed = btn.pressed || btn.value >= 0.5
if(btnPressed){ if(btnPressed){
button = btnPressed button = btnPressed
} }
} }
} }
}
var pressed = !this.btn[btnName] && button var pressed = !this.btn[btnName] && button
var released = this.btn[btnName] && !button var released = this.btn[btnName] && !button
if(pressed){ if(pressed){