-
Notifications
You must be signed in to change notification settings - Fork 8
/
internal_gamepad_utils.go
88 lines (76 loc) · 1.91 KB
/
internal_gamepad_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package input
import (
"strings"
"github.com/hajimehoshi/ebiten/v2"
)
type gamepadModel int
const (
gamepadUnknown gamepadModel = iota
gamepadStandard
gamepadFirefoxXinput
gamepadMicront
)
func guessGamepadModel(s string) gamepadModel {
s = strings.ToLower(s)
if s == "micront" {
return gamepadMicront
}
return gamepadUnknown
}
type gamepadInfo struct {
model gamepadModel
modelName string
axisCount int
axisValues [8]float64
prevAxisValues [8]float64
}
func isDPadButton(code int) bool {
switch ebiten.StandardGamepadButton(code) {
case ebiten.StandardGamepadButtonLeftTop:
return true
case ebiten.StandardGamepadButtonLeftRight:
return true
case ebiten.StandardGamepadButtonLeftBottom:
return true
case ebiten.StandardGamepadButtonLeftLeft:
return true
default:
return false
}
}
func firefoxXinputToXbox(b ebiten.StandardGamepadButton) ebiten.GamepadButton {
switch b {
case ebiten.StandardGamepadButtonCenterLeft:
return 6
case ebiten.StandardGamepadButtonCenterRight:
return 7
case ebiten.StandardGamepadButtonRightStick:
return 10
case ebiten.StandardGamepadButtonLeftStick:
return 9
default:
return ebiten.GamepadButton(b)
}
}
func microntToXbox(b ebiten.StandardGamepadButton) ebiten.GamepadButton {
switch b {
case ebiten.StandardGamepadButtonLeftTop:
return ebiten.GamepadButton12
case ebiten.StandardGamepadButtonLeftRight:
return ebiten.GamepadButton13
case ebiten.StandardGamepadButtonLeftBottom:
return ebiten.GamepadButton14
case ebiten.StandardGamepadButtonLeftLeft:
return ebiten.GamepadButton15
case ebiten.StandardGamepadButtonRightTop:
return ebiten.GamepadButton0
case ebiten.StandardGamepadButtonRightRight:
return ebiten.GamepadButton1
case ebiten.StandardGamepadButtonRightBottom:
return ebiten.GamepadButton2
case ebiten.StandardGamepadButtonRightLeft:
return ebiten.GamepadButton3
default:
return ebiten.GamepadButton(b)
}
}