mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-11-15 07:21:50 +08:00
Check all connected gamepads
This commit is contained in:
parent
938931d7af
commit
6b34c19a30
@ -39,30 +39,38 @@ class Gamepad{
|
|||||||
var bindings = menuPlay ? this.menuBtn : this.gameBtn
|
var bindings = menuPlay ? this.menuBtn : this.gameBtn
|
||||||
for(var i = 0; i < gamepads.length; i++){
|
for(var i = 0; i < gamepads.length; i++){
|
||||||
if(gamepads[i]){
|
if(gamepads[i]){
|
||||||
var buttons = gamepads[i].buttons
|
|
||||||
this.toRelease = {}
|
this.toRelease = {}
|
||||||
for(var i in bindings){
|
for(var bind in bindings){
|
||||||
this.toRelease[i] = bindings[i].length
|
this.toRelease[bind] = bindings[bind].length
|
||||||
}
|
}
|
||||||
for(var btnName in buttons){
|
for(var btnName in gamepads[i].buttons){
|
||||||
buttonSearch: {
|
buttonSearch: {
|
||||||
for(var bind in bindings){
|
for(var bind in bindings){
|
||||||
for(var name in bindings[bind]){
|
for(var name in bindings[bind]){
|
||||||
if(btnName == this.b[bindings[bind][name]]){
|
if(btnName === this.b[bindings[bind][name]]){
|
||||||
this.checkButton(buttons, btnName, bind)
|
this.checkButton(gamepads, btnName, bind)
|
||||||
break buttonSearch
|
break buttonSearch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkButton(buttons, btnName, keyCode){
|
checkButton(gamepads, btnName, keyCode){
|
||||||
var button = buttons[btnName]
|
var button = false
|
||||||
var pressed = !this.btn[btnName] && button.pressed
|
for(var i = 0; i < gamepads.length; i++){
|
||||||
var released = this.btn[btnName] && !button.pressed
|
if(gamepads[i]){
|
||||||
|
var btnPressed = gamepads[i].buttons[btnName].pressed
|
||||||
|
if(btnPressed){
|
||||||
|
button = btnPressed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var pressed = !this.btn[btnName] && button
|
||||||
|
var released = this.btn[btnName] && !button
|
||||||
if(pressed){
|
if(pressed){
|
||||||
this.btn[btnName] = true
|
this.btn[btnName] = true
|
||||||
}else if(released){
|
}else if(released){
|
||||||
@ -73,12 +81,12 @@ class Gamepad{
|
|||||||
this.keyboard.setKey(keyCode, false)
|
this.keyboard.setKey(keyCode, false)
|
||||||
}
|
}
|
||||||
this.keyboard.setKey(keyCode, true)
|
this.keyboard.setKey(keyCode, true)
|
||||||
}else if(!button.pressed && this.keyboard.getKeys()[keyCode]){
|
}else if(!button && this.keyboard.getKeys()[keyCode]){
|
||||||
if(released){
|
if(released){
|
||||||
this.toRelease[keyCode + "released"] = true
|
this.toRelease[keyCode + "released"] = true
|
||||||
}
|
}
|
||||||
this.toRelease[keyCode]--
|
this.toRelease[keyCode]--
|
||||||
if(this.toRelease[keyCode] == 0 && this.toRelease[keyCode+"released"]){
|
if(this.toRelease[keyCode] === 0 && this.toRelease[keyCode + "released"]){
|
||||||
this.keyboard.setKey(keyCode, false)
|
this.keyboard.setKey(keyCode, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user