ebiten: add GamepadMapping

Closes #2775
This commit is contained in:
Hajime Hoshi 2024-03-16 15:35:25 +09:00
parent 9faa3f4601
commit b2a4033848
4 changed files with 247 additions and 87 deletions

View File

@ -193,6 +193,34 @@ func (g *Game) Draw(screen *ebiten.Image) {
if ebiten.IsStandardGamepadLayoutAvailable(id) { if ebiten.IsStandardGamepadLayoutAvailable(id) {
str += "\n" str += "\n"
str += standardMap(id) + "\n" str += standardMap(id) + "\n"
// Print unmapped buttons.
buttonIDs := map[ebiten.GamepadButton]struct{}{}
for i := 0; i < ebiten.GamepadButtonCount(id); i++ {
buttonIDs[ebiten.GamepadButton(i)] = struct{}{}
}
for _, m := range ebiten.GamepadMapping(id) {
if m.PhysicalType == ebiten.GamepadMappingTypeButton {
delete(buttonIDs, ebiten.GamepadButton(m.PhysicalIndex))
}
}
if len(buttonIDs) > 0 {
unmappedButtonIDs := make([]ebiten.GamepadButton, 0, len(buttonIDs))
for id := range buttonIDs {
unmappedButtonIDs = append(unmappedButtonIDs, id)
}
sort.Slice(unmappedButtonIDs, func(i, j int) bool {
return unmappedButtonIDs[i] < unmappedButtonIDs[j]
})
str += " Unmapped Buttons: "
for i, id := range unmappedButtonIDs {
str += fmt.Sprintf("%d", id)
if i < len(unmappedButtonIDs)-1 {
str += ", "
}
}
str += "\n"
}
} }
str += "\n" str += "\n"
} }

View File

@ -105,3 +105,32 @@ const (
StandardGamepadAxisRightStickVertical StandardGamepadAxis = gamepaddb.StandardAxisRightStickVertical StandardGamepadAxisRightStickVertical StandardGamepadAxis = gamepaddb.StandardAxisRightStickVertical
StandardGamepadAxisMax StandardGamepadAxis = StandardGamepadAxisRightStickVertical StandardGamepadAxisMax StandardGamepadAxis = StandardGamepadAxisRightStickVertical
) )
type GamepadMappingType = gamepaddb.MappingType
const (
GamepadMappingTypeButton GamepadMappingType = gamepaddb.MappingTypeButton
GamepadMappingTypeAxis GamepadMappingType = gamepaddb.MappingTypeAxis
)
type GamepadMappingItem struct {
StandardType GamepadMappingType
StandardIndex int
PhysicalType GamepadMappingType
PhysicalIndex int
PhysicalToStandardAxisScale float64
PhysicalToStandardAxisOffset float64
}
func GamepadMapping(id GamepadID) []GamepadMappingItem {
g := gamepad.Get(id)
if g == nil {
return nil
}
m := g.Mapping()
mapping := make([]GamepadMappingItem, len(m))
for i, v := range m {
mapping[i] = GamepadMappingItem(v)
}
return mapping
}

View File

@ -408,3 +408,97 @@ func (g *Gamepad) Vibrate(duration time.Duration, strongMagnitude float64, weakM
g.native.vibrate(duration, strongMagnitude, weakMagnitude) g.native.vibrate(duration, strongMagnitude, weakMagnitude)
} }
type MappingItem struct {
StandardType gamepaddb.MappingType
StandardIndex int
PhysicalType gamepaddb.MappingType
PhysicalIndex int
PhysicalToStandardAxisScale float64
PhysicalToStandardAxisOffset float64
}
func (g *Gamepad) Mapping() []MappingItem {
g.m.Lock()
defer g.m.Unlock()
if g.native.hasOwnStandardLayoutMapping() {
var mapping []MappingItem
buttonCount := g.native.buttonCount() + g.native.hatCount()*4
if buttonCount > int(gamepaddb.StandardButtonMax)+1 {
buttonCount = int(gamepaddb.StandardButtonMax) + 1
}
for i := 0; i < buttonCount; i++ {
mapping = append(mapping, MappingItem{
StandardType: gamepaddb.MappingTypeButton,
StandardIndex: i,
PhysicalType: gamepaddb.MappingTypeButton,
PhysicalIndex: i,
})
}
axisCount := g.native.axisCount()
if axisCount > int(gamepaddb.StandardAxisMax)+1 {
axisCount = int(gamepaddb.StandardAxisMax) + 1
}
for i := 0; i < axisCount; i++ {
mapping = append(mapping, MappingItem{
StandardType: gamepaddb.MappingTypeAxis,
StandardIndex: i,
PhysicalType: gamepaddb.MappingTypeAxis,
PhysicalIndex: i,
PhysicalToStandardAxisScale: 1,
})
}
return mapping
}
var mapping []MappingItem
buttons, axes := gamepaddb.UnsafeMapping(g.sdlID)
for button, item := range buttons {
item := g.convertMappingItem(item)
item.StandardType = gamepaddb.MappingTypeButton
item.StandardIndex = int(button)
mapping = append(mapping, item)
}
for axis, item := range axes {
item := g.convertMappingItem(item)
item.StandardType = gamepaddb.MappingTypeAxis
item.StandardIndex = int(axis)
mapping = append(mapping, item)
}
return mapping
}
func (g *Gamepad) convertMappingItem(item gamepaddb.MappingItem) MappingItem {
var r MappingItem
switch item.Type {
case gamepaddb.MappingTypeButton:
r.PhysicalType = gamepaddb.MappingTypeButton
r.PhysicalIndex = item.Index
case gamepaddb.MappingTypeAxis:
r.PhysicalType = gamepaddb.MappingTypeAxis
r.PhysicalIndex = item.Index
r.PhysicalToStandardAxisScale = item.AxisScale
r.PhysicalToStandardAxisOffset = item.AxisOffset
case gamepaddb.MappingTypeHat:
// Convert a hat value to a button value.
r.PhysicalType = gamepaddb.MappingTypeButton
var offset int
switch item.HatState {
case hatUp:
offset = 0
case hatRight:
offset = 1
case hatDown:
offset = 2
case hatLeft:
offset = 3
}
r.PhysicalIndex = g.native.buttonCount() + 4*item.Index + offset
}
return r
}

View File

@ -102,12 +102,12 @@ func init() {
} }
} }
type mappingType int type MappingType int
const ( const (
mappingTypeButton mappingType = iota MappingTypeButton MappingType = iota
mappingTypeAxis MappingTypeAxis
mappingTypeHat MappingTypeHat
) )
const ( const (
@ -117,8 +117,8 @@ const (
HatLeft = 8 HatLeft = 8
) )
type mapping struct { type MappingItem struct {
Type mappingType Type MappingType
Index int Index int
AxisScale float64 AxisScale float64
AxisOffset float64 AxisOffset float64
@ -127,12 +127,12 @@ type mapping struct {
var ( var (
gamepadNames = map[string]string{} gamepadNames = map[string]string{}
gamepadButtonMappings = map[string]map[StandardButton]mapping{} gamepadButtonMappings = map[string]map[StandardButton]MappingItem{}
gamepadAxisMappings = map[string]map[StandardAxis]mapping{} gamepadAxisMappings = map[string]map[StandardAxis]MappingItem{}
mappingsM sync.RWMutex mappingsM sync.RWMutex
) )
func parseLine(line string, platform platform) (id string, name string, buttons map[StandardButton]mapping, axes map[StandardAxis]mapping, err error) { func parseLine(line string, platform platform) (id string, name string, buttons map[StandardButton]MappingItem, axes map[StandardAxis]MappingItem, err error) {
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
if len(line) == 0 { if len(line) == 0 {
return "", "", nil, nil, nil return "", "", nil, nil, nil
@ -192,7 +192,7 @@ func parseLine(line string, platform platform) (id string, name string, buttons
if b, ok := toStandardGamepadButton(tks[0]); ok { if b, ok := toStandardGamepadButton(tks[0]); ok {
if buttons == nil { if buttons == nil {
buttons = map[StandardButton]mapping{} buttons = map[StandardButton]MappingItem{}
} }
buttons[b] = gb buttons[b] = gb
continue continue
@ -200,7 +200,7 @@ func parseLine(line string, platform platform) (id string, name string, buttons
if a, ok := toStandardGamepadAxis(tks[0]); ok { if a, ok := toStandardGamepadAxis(tks[0]); ok {
if axes == nil { if axes == nil {
axes = map[StandardAxis]mapping{} axes = map[StandardAxis]MappingItem{}
} }
axes[a] = gb axes[a] = gb
continue continue
@ -213,7 +213,7 @@ func parseLine(line string, platform platform) (id string, name string, buttons
return tokens[0], tokens[1], buttons, axes, nil return tokens[0], tokens[1], buttons, axes, nil
} }
func parseMappingElement(str string) (mapping, error) { func parseMappingElement(str string) (MappingItem, error) {
switch { switch {
case str[0] == 'a' || strings.HasPrefix(str, "+a") || strings.HasPrefix(str, "-a"): case str[0] == 'a' || strings.HasPrefix(str, "+a") || strings.HasPrefix(str, "-a"):
var tilda bool var tilda bool
@ -259,11 +259,11 @@ func parseMappingElement(str string) (mapping, error) {
index, err := strconv.Atoi(numstr) index, err := strconv.Atoi(numstr)
if err != nil { if err != nil {
return mapping{}, err return MappingItem{}, err
} }
return mapping{ return MappingItem{
Type: mappingTypeAxis, Type: MappingTypeAxis,
Index: index, Index: index,
AxisScale: scale, AxisScale: scale,
AxisOffset: offset, AxisOffset: offset,
@ -272,34 +272,34 @@ func parseMappingElement(str string) (mapping, error) {
case str[0] == 'b': case str[0] == 'b':
index, err := strconv.Atoi(str[1:]) index, err := strconv.Atoi(str[1:])
if err != nil { if err != nil {
return mapping{}, err return MappingItem{}, err
} }
return mapping{ return MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: index, Index: index,
}, nil }, nil
case str[0] == 'h': case str[0] == 'h':
tokens := strings.Split(str[1:], ".") tokens := strings.Split(str[1:], ".")
if len(tokens) < 2 { if len(tokens) < 2 {
return mapping{}, fmt.Errorf("gamepaddb: unexpected hat: %s", str) return MappingItem{}, fmt.Errorf("gamepaddb: unexpected hat: %s", str)
} }
index, err := strconv.Atoi(tokens[0]) index, err := strconv.Atoi(tokens[0])
if err != nil { if err != nil {
return mapping{}, err return MappingItem{}, err
} }
hat, err := strconv.Atoi(tokens[1]) hat, err := strconv.Atoi(tokens[1])
if err != nil { if err != nil {
return mapping{}, err return MappingItem{}, err
} }
return mapping{ return MappingItem{
Type: mappingTypeHat, Type: MappingTypeHat,
Index: index, Index: index,
HatState: hat, HatState: hat,
}, nil }, nil
} }
return mapping{}, fmt.Errorf("gamepaddb: unepxected mapping: %s", str) return MappingItem{}, fmt.Errorf("gamepaddb: unepxected mapping: %s", str)
} }
func toStandardGamepadButton(str string) (StandardButton, bool) { func toStandardGamepadButton(str string) (StandardButton, bool) {
@ -358,7 +358,7 @@ func toStandardGamepadAxis(str string) (StandardAxis, bool) {
} }
} }
func buttonMappings(id string) map[StandardButton]mapping { func buttonMapping(id string) map[StandardButton]MappingItem {
if m, ok := gamepadButtonMappings[id]; ok { if m, ok := gamepadButtonMappings[id]; ok {
return m return m
} }
@ -370,7 +370,7 @@ func buttonMappings(id string) map[StandardButton]mapping {
return nil return nil
} }
func axisMappings(id string) map[StandardAxis]mapping { func axisMapping(id string) map[StandardAxis]MappingItem {
if m, ok := gamepadAxisMappings[id]; ok { if m, ok := gamepadAxisMappings[id]; ok {
return m return m
} }
@ -386,7 +386,7 @@ func HasStandardLayoutMapping(id string) bool {
mappingsM.RLock() mappingsM.RLock()
defer mappingsM.RUnlock() defer mappingsM.RUnlock()
return buttonMappings(id) != nil || axisMappings(id) != nil return buttonMapping(id) != nil || axisMapping(id) != nil
} }
type GamepadState interface { type GamepadState interface {
@ -406,7 +406,7 @@ func HasStandardAxis(id string, axis StandardAxis) bool {
mappingsM.RLock() mappingsM.RLock()
defer mappingsM.RUnlock() defer mappingsM.RUnlock()
mappings := axisMappings(id) mappings := axisMapping(id)
if mappings == nil { if mappings == nil {
return false return false
} }
@ -418,7 +418,7 @@ func StandardAxisValue(id string, axis StandardAxis, state GamepadState) float64
mappingsM.RLock() mappingsM.RLock()
defer mappingsM.RUnlock() defer mappingsM.RUnlock()
mappings := axisMappings(id) mappings := axisMapping(id)
if mappings == nil { if mappings == nil {
return 0 return 0
} }
@ -429,7 +429,7 @@ func StandardAxisValue(id string, axis StandardAxis, state GamepadState) float64
} }
switch mapping.Type { switch mapping.Type {
case mappingTypeAxis: case MappingTypeAxis:
v := state.Axis(mapping.Index)*mapping.AxisScale + mapping.AxisOffset v := state.Axis(mapping.Index)*mapping.AxisScale + mapping.AxisOffset
if v > 1 { if v > 1 {
return 1 return 1
@ -437,13 +437,13 @@ func StandardAxisValue(id string, axis StandardAxis, state GamepadState) float64
return -1 return -1
} }
return v return v
case mappingTypeButton: case MappingTypeButton:
if state.Button(mapping.Index) { if state.Button(mapping.Index) {
return 1 return 1
} else { } else {
return -1 return -1
} }
case mappingTypeHat: case MappingTypeHat:
if state.Hat(mapping.Index)&mapping.HatState != 0 { if state.Hat(mapping.Index)&mapping.HatState != 0 {
return 1 return 1
} else { } else {
@ -458,7 +458,7 @@ func HasStandardButton(id string, button StandardButton) bool {
mappingsM.RLock() mappingsM.RLock()
defer mappingsM.RUnlock() defer mappingsM.RUnlock()
mappings := buttonMappings(id) mappings := buttonMapping(id)
if mappings == nil { if mappings == nil {
return false return false
} }
@ -474,7 +474,7 @@ func StandardButtonValue(id string, button StandardButton, state GamepadState) f
} }
func standardButtonValue(id string, button StandardButton, state GamepadState) float64 { func standardButtonValue(id string, button StandardButton, state GamepadState) float64 {
mappings := buttonMappings(id) mappings := buttonMapping(id)
if mappings == nil { if mappings == nil {
return 0 return 0
} }
@ -485,7 +485,7 @@ func standardButtonValue(id string, button StandardButton, state GamepadState) f
} }
switch mapping.Type { switch mapping.Type {
case mappingTypeAxis: case MappingTypeAxis:
v := state.Axis(mapping.Index)*mapping.AxisScale + mapping.AxisOffset v := state.Axis(mapping.Index)*mapping.AxisScale + mapping.AxisOffset
if v > 1 { if v > 1 {
v = 1 v = 1
@ -494,12 +494,12 @@ func standardButtonValue(id string, button StandardButton, state GamepadState) f
} }
// Adjust [-1, 1] to [0, 1] // Adjust [-1, 1] to [0, 1]
return (v + 1) / 2 return (v + 1) / 2
case mappingTypeButton: case MappingTypeButton:
if state.Button(mapping.Index) { if state.Button(mapping.Index) {
return 1 return 1
} }
return 0 return 0
case mappingTypeHat: case MappingTypeHat:
if state.Hat(mapping.Index)&mapping.HatState != 0 { if state.Hat(mapping.Index)&mapping.HatState != 0 {
return 1 return 1
} }
@ -530,18 +530,27 @@ func IsStandardButtonPressed(id string, button StandardButton, state GamepadStat
} }
switch mapping.Type { switch mapping.Type {
case mappingTypeAxis: case MappingTypeAxis:
v := standardButtonValue(id, button, state) v := standardButtonValue(id, button, state)
return v > ButtonPressedThreshold return v > ButtonPressedThreshold
case mappingTypeButton: case MappingTypeButton:
return state.Button(mapping.Index) return state.Button(mapping.Index)
case mappingTypeHat: case MappingTypeHat:
return state.Hat(mapping.Index)&mapping.HatState != 0 return state.Hat(mapping.Index)&mapping.HatState != 0
} }
return false return false
} }
// UnsafeMapping returns the mapping of the gamepad.
// UnsafeMapping is unsafe. The returned values must not be modified.
func UnsafeMapping(id string) (map[StandardButton]MappingItem, map[StandardAxis]MappingItem) {
mappingsM.RLock()
defer mappingsM.RUnlock()
return buttonMapping(id), axisMapping(id)
}
// Update adds new gamepad mappings. // Update adds new gamepad mappings.
// The string must be in the format of SDL_GameControllerDB. // The string must be in the format of SDL_GameControllerDB.
// //
@ -556,8 +565,8 @@ func Update(mappingData []byte) error {
type parsedLine struct { type parsedLine struct {
id string id string
name string name string
buttons map[StandardButton]mapping buttons map[StandardButton]MappingItem
axes map[StandardAxis]mapping axes map[StandardAxis]MappingItem
} }
var lines []parsedLine var lines []parsedLine
@ -611,155 +620,155 @@ func addAndroidDefaultMappings(id string) bool {
return false return false
} }
gamepadButtonMappings[id] = map[StandardButton]mapping{} gamepadButtonMappings[id] = map[StandardButton]MappingItem{}
gamepadAxisMappings[id] = map[StandardAxis]mapping{} gamepadAxisMappings[id] = map[StandardAxis]MappingItem{}
// For mappings, see mobile/ebitenmobileview/input_android.go. // For mappings, see mobile/ebitenmobileview/input_android.go.
if buttonMask&(1<<SDLControllerButtonA) != 0 { if buttonMask&(1<<SDLControllerButtonA) != 0 {
gamepadButtonMappings[id][StandardButtonRightBottom] = mapping{ gamepadButtonMappings[id][StandardButtonRightBottom] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonA, Index: SDLControllerButtonA,
} }
} }
if buttonMask&(1<<SDLControllerButtonB) != 0 { if buttonMask&(1<<SDLControllerButtonB) != 0 {
gamepadButtonMappings[id][StandardButtonRightRight] = mapping{ gamepadButtonMappings[id][StandardButtonRightRight] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonB, Index: SDLControllerButtonB,
} }
} else { } else {
// Use the back button as "B" for easy UI navigation with TV remotes. // Use the back button as "B" for easy UI navigation with TV remotes.
gamepadButtonMappings[id][StandardButtonRightRight] = mapping{ gamepadButtonMappings[id][StandardButtonRightRight] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonBack, Index: SDLControllerButtonBack,
} }
buttonMask &^= uint16(1) << SDLControllerButtonBack buttonMask &^= uint16(1) << SDLControllerButtonBack
} }
if buttonMask&(1<<SDLControllerButtonX) != 0 { if buttonMask&(1<<SDLControllerButtonX) != 0 {
gamepadButtonMappings[id][StandardButtonRightLeft] = mapping{ gamepadButtonMappings[id][StandardButtonRightLeft] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonX, Index: SDLControllerButtonX,
} }
} }
if buttonMask&(1<<SDLControllerButtonY) != 0 { if buttonMask&(1<<SDLControllerButtonY) != 0 {
gamepadButtonMappings[id][StandardButtonRightTop] = mapping{ gamepadButtonMappings[id][StandardButtonRightTop] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonY, Index: SDLControllerButtonY,
} }
} }
if buttonMask&(1<<SDLControllerButtonBack) != 0 { if buttonMask&(1<<SDLControllerButtonBack) != 0 {
gamepadButtonMappings[id][StandardButtonCenterLeft] = mapping{ gamepadButtonMappings[id][StandardButtonCenterLeft] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonBack, Index: SDLControllerButtonBack,
} }
} }
if buttonMask&(1<<SDLControllerButtonGuide) != 0 { if buttonMask&(1<<SDLControllerButtonGuide) != 0 {
// TODO: If SDKVersion >= 30, add this code: // TODO: If SDKVersion >= 30, add this code:
// //
// gamepadButtonMappings[id][StandardButtonCenterCenter] = mapping{ // gamepadButtonMappings[id][StandardButtonCenterCenter] = MappingItem{
// Type: mappingTypeButton, // Type: mappingTypeButton,
// Index: SDLControllerButtonGuide, // Index: SDLControllerButtonGuide,
// } // }
} }
if buttonMask&(1<<SDLControllerButtonStart) != 0 { if buttonMask&(1<<SDLControllerButtonStart) != 0 {
gamepadButtonMappings[id][StandardButtonCenterRight] = mapping{ gamepadButtonMappings[id][StandardButtonCenterRight] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonStart, Index: SDLControllerButtonStart,
} }
} }
if buttonMask&(1<<SDLControllerButtonLeftStick) != 0 { if buttonMask&(1<<SDLControllerButtonLeftStick) != 0 {
gamepadButtonMappings[id][StandardButtonLeftStick] = mapping{ gamepadButtonMappings[id][StandardButtonLeftStick] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonLeftStick, Index: SDLControllerButtonLeftStick,
} }
} }
if buttonMask&(1<<SDLControllerButtonRightStick) != 0 { if buttonMask&(1<<SDLControllerButtonRightStick) != 0 {
gamepadButtonMappings[id][StandardButtonRightStick] = mapping{ gamepadButtonMappings[id][StandardButtonRightStick] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonRightStick, Index: SDLControllerButtonRightStick,
} }
} }
if buttonMask&(1<<SDLControllerButtonLeftShoulder) != 0 { if buttonMask&(1<<SDLControllerButtonLeftShoulder) != 0 {
gamepadButtonMappings[id][StandardButtonFrontTopLeft] = mapping{ gamepadButtonMappings[id][StandardButtonFrontTopLeft] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonLeftShoulder, Index: SDLControllerButtonLeftShoulder,
} }
} }
if buttonMask&(1<<SDLControllerButtonRightShoulder) != 0 { if buttonMask&(1<<SDLControllerButtonRightShoulder) != 0 {
gamepadButtonMappings[id][StandardButtonFrontTopRight] = mapping{ gamepadButtonMappings[id][StandardButtonFrontTopRight] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonRightShoulder, Index: SDLControllerButtonRightShoulder,
} }
} }
if buttonMask&(1<<SDLControllerButtonDpadUp) != 0 { if buttonMask&(1<<SDLControllerButtonDpadUp) != 0 {
gamepadButtonMappings[id][StandardButtonLeftTop] = mapping{ gamepadButtonMappings[id][StandardButtonLeftTop] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonDpadUp, Index: SDLControllerButtonDpadUp,
} }
} }
if buttonMask&(1<<SDLControllerButtonDpadDown) != 0 { if buttonMask&(1<<SDLControllerButtonDpadDown) != 0 {
gamepadButtonMappings[id][StandardButtonLeftBottom] = mapping{ gamepadButtonMappings[id][StandardButtonLeftBottom] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonDpadDown, Index: SDLControllerButtonDpadDown,
} }
} }
if buttonMask&(1<<SDLControllerButtonDpadLeft) != 0 { if buttonMask&(1<<SDLControllerButtonDpadLeft) != 0 {
gamepadButtonMappings[id][StandardButtonLeftLeft] = mapping{ gamepadButtonMappings[id][StandardButtonLeftLeft] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonDpadLeft, Index: SDLControllerButtonDpadLeft,
} }
} }
if buttonMask&(1<<SDLControllerButtonDpadRight) != 0 { if buttonMask&(1<<SDLControllerButtonDpadRight) != 0 {
gamepadButtonMappings[id][StandardButtonLeftRight] = mapping{ gamepadButtonMappings[id][StandardButtonLeftRight] = MappingItem{
Type: mappingTypeButton, Type: MappingTypeButton,
Index: SDLControllerButtonDpadRight, Index: SDLControllerButtonDpadRight,
} }
} }
if axisMask&(1<<SDLControllerAxisLeftX) != 0 { if axisMask&(1<<SDLControllerAxisLeftX) != 0 {
gamepadAxisMappings[id][StandardAxisLeftStickHorizontal] = mapping{ gamepadAxisMappings[id][StandardAxisLeftStickHorizontal] = MappingItem{
Type: mappingTypeAxis, Type: MappingTypeAxis,
Index: SDLControllerAxisLeftX, Index: SDLControllerAxisLeftX,
AxisScale: 1, AxisScale: 1,
AxisOffset: 0, AxisOffset: 0,
} }
} }
if axisMask&(1<<SDLControllerAxisLeftY) != 0 { if axisMask&(1<<SDLControllerAxisLeftY) != 0 {
gamepadAxisMappings[id][StandardAxisLeftStickVertical] = mapping{ gamepadAxisMappings[id][StandardAxisLeftStickVertical] = MappingItem{
Type: mappingTypeAxis, Type: MappingTypeAxis,
Index: SDLControllerAxisLeftY, Index: SDLControllerAxisLeftY,
AxisScale: 1, AxisScale: 1,
AxisOffset: 0, AxisOffset: 0,
} }
} }
if axisMask&(1<<SDLControllerAxisRightX) != 0 { if axisMask&(1<<SDLControllerAxisRightX) != 0 {
gamepadAxisMappings[id][StandardAxisRightStickHorizontal] = mapping{ gamepadAxisMappings[id][StandardAxisRightStickHorizontal] = MappingItem{
Type: mappingTypeAxis, Type: MappingTypeAxis,
Index: SDLControllerAxisRightX, Index: SDLControllerAxisRightX,
AxisScale: 1, AxisScale: 1,
AxisOffset: 0, AxisOffset: 0,
} }
} }
if axisMask&(1<<SDLControllerAxisRightY) != 0 { if axisMask&(1<<SDLControllerAxisRightY) != 0 {
gamepadAxisMappings[id][StandardAxisRightStickVertical] = mapping{ gamepadAxisMappings[id][StandardAxisRightStickVertical] = MappingItem{
Type: mappingTypeAxis, Type: MappingTypeAxis,
Index: SDLControllerAxisRightY, Index: SDLControllerAxisRightY,
AxisScale: 1, AxisScale: 1,
AxisOffset: 0, AxisOffset: 0,
} }
} }
if axisMask&(1<<SDLControllerAxisTriggerLeft) != 0 { if axisMask&(1<<SDLControllerAxisTriggerLeft) != 0 {
gamepadButtonMappings[id][StandardButtonFrontBottomLeft] = mapping{ gamepadButtonMappings[id][StandardButtonFrontBottomLeft] = MappingItem{
Type: mappingTypeAxis, Type: MappingTypeAxis,
Index: SDLControllerAxisTriggerLeft, Index: SDLControllerAxisTriggerLeft,
AxisScale: 1, AxisScale: 1,
AxisOffset: 0, AxisOffset: 0,
} }
} }
if axisMask&(1<<SDLControllerAxisTriggerRight) != 0 { if axisMask&(1<<SDLControllerAxisTriggerRight) != 0 {
gamepadButtonMappings[id][StandardButtonFrontBottomRight] = mapping{ gamepadButtonMappings[id][StandardButtonFrontBottomRight] = MappingItem{
Type: mappingTypeAxis, Type: MappingTypeAxis,
Index: SDLControllerAxisTriggerRight, Index: SDLControllerAxisTriggerRight,
AxisScale: 1, AxisScale: 1,
AxisOffset: 0, AxisOffset: 0,