Gamepad: Add left stick and TaTaCon D-Pad
This commit is contained in:
parent
1c0261fe6d
commit
fac283174f
@ -18,7 +18,11 @@ class Gamepad{
|
|||||||
"d": 13,
|
"d": 13,
|
||||||
"l": 14,
|
"l": 14,
|
||||||
"r": 15,
|
"r": 15,
|
||||||
"guide": 16
|
"guide": 16,
|
||||||
|
"lsu": "lsu",
|
||||||
|
"lsr": "lsr",
|
||||||
|
"lsd": "lsd",
|
||||||
|
"lsl": "lsl"
|
||||||
}
|
}
|
||||||
this.btn = {}
|
this.btn = {}
|
||||||
if(callback){
|
if(callback){
|
||||||
@ -33,51 +37,83 @@ class Gamepad{
|
|||||||
}else{
|
}else{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var bindings = this.bindings
|
var bindings = this.bindings
|
||||||
|
|
||||||
|
var force = {
|
||||||
|
lsu: false,
|
||||||
|
lsr: false,
|
||||||
|
lsd: false,
|
||||||
|
lsl: false
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var i = 0; i < gamepads.length; i++){
|
||||||
|
if(gamepads[i]){
|
||||||
|
var axes = gamepads[i].axes
|
||||||
|
if(axes.length >= 2){
|
||||||
|
force.lsl = force.lsl || axes[0] <= -0.5
|
||||||
|
force.lsr = force.lsr || axes[0] >= 0.5
|
||||||
|
force.lsu = force.lsu || axes[1] <= -0.5
|
||||||
|
force.lsd = force.lsd || axes[1] >= 0.5
|
||||||
|
}
|
||||||
|
if(axes.length >= 10){
|
||||||
|
// TaTaCon left D-Pad
|
||||||
|
for(var pov = 0; pov < 8; pov++){
|
||||||
|
if(Math.abs(axes[9] - (pov / 3.5 - 1)) <= 0.01){
|
||||||
|
force.lsu = force.lsu || pov === 7 || pov === 0 || pov === 1
|
||||||
|
force.lsr = force.lsr || pov === 1 || pov === 2 || pov === 3
|
||||||
|
force.lsd = force.lsd || pov === 3 || pov === 4 || pov === 5
|
||||||
|
force.lsl = force.lsl || pov === 5 || pov === 6 || pov === 7
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(var i = 0; i < gamepads.length; i++){
|
for(var i = 0; i < gamepads.length; i++){
|
||||||
if(gamepads[i]){
|
if(gamepads[i]){
|
||||||
this.toRelease = {}
|
this.toRelease = {}
|
||||||
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 = 0; btnName <= 16; btnName++){
|
for(var bind in bindings){
|
||||||
buttonSearch: {
|
for(var name in bindings[bind]){
|
||||||
for(var bind in bindings){
|
var bindName = bindings[bind][name]
|
||||||
for(var name in bindings[bind]){
|
this.checkButton(gamepads, this.b[bindName], bind, callback, force[bindName])
|
||||||
if(btnName === this.b[bindings[bind][name]]){
|
|
||||||
this.checkButton(gamepads, btnName, bind, callback)
|
|
||||||
break buttonSearch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkButton(gamepads, btnName, keyCode, callback){
|
checkButton(gamepads, btnName, keyCode, callback, force){
|
||||||
var button = false
|
var button = false
|
||||||
|
|
||||||
for(var i = 0; i < gamepads.length; i++){
|
if(typeof force === "undefined"){
|
||||||
if(gamepads[i]){
|
for(var i = 0; i < gamepads.length; i++){
|
||||||
var btn = gamepads[i].buttons[btnName]
|
if(gamepads[i]){
|
||||||
if(btn){
|
var btn = gamepads[i].buttons[btnName]
|
||||||
var btnPressed = btn.pressed || btn.value >= 0.5
|
if(btn){
|
||||||
if(btnPressed){
|
var btnPressed = btn.pressed || btn.value >= 0.5
|
||||||
button = btnPressed
|
if(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
|
||||||
|
}else{
|
||||||
|
var pressed = !this.btn[btnName] && force
|
||||||
|
var released = this.btn[btnName] && !force
|
||||||
|
}
|
||||||
|
|
||||||
if(pressed){
|
if(pressed){
|
||||||
this.btn[btnName] = true
|
this.btn[btnName] = true
|
||||||
}else if(released){
|
}else if(released){
|
||||||
delete this.btn[btnName]
|
this.btn[btnName] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pressed){
|
if(pressed){
|
||||||
|
@ -189,8 +189,8 @@ class SongSelect{
|
|||||||
this.gamepad = new Gamepad({
|
this.gamepad = new Gamepad({
|
||||||
"13": ["b", "start", "ls", "rs"],
|
"13": ["b", "start", "ls", "rs"],
|
||||||
"8": ["a"],
|
"8": ["a"],
|
||||||
"37": ["l", "lb", "lt"],
|
"37": ["l", "lb", "lt", "lsl"],
|
||||||
"39": ["r", "rb", "rt"],
|
"39": ["r", "rb", "rt", "lsr"],
|
||||||
"ctrl": ["y"],
|
"ctrl": ["y"],
|
||||||
"shift": ["x"]
|
"shift": ["x"]
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user