internal/gamepaddb: fix hat assignments for Android

Now Ebitengine's original mapping works, but the database doesn't
work due to differences of button assignments. Fix this later.

Updates #2309
This commit is contained in:
Hajime Hoshi 2022-09-08 00:18:50 +09:00
parent 521ec6f09b
commit a9653d1e7a

View File

@ -341,26 +341,30 @@ func toStandardGamepadAxis(str string) (StandardAxis, bool) {
} }
func buttonMappings(id string) map[StandardButton]*mapping { func buttonMappings(id string) map[StandardButton]*mapping {
if m, ok := gamepadButtonMappings[id]; ok { // TODO: Use the database instead of the original mapping (#2308).
return m // The buttons and axes assignments should be fixed.
}
if currentPlatform == platformAndroid { if currentPlatform == platformAndroid {
if addAndroidDefaultMappings(id) { if addAndroidDefaultMappings(id) {
return gamepadButtonMappings[id] return gamepadButtonMappings[id]
} }
} }
if m, ok := gamepadButtonMappings[id]; ok {
return m
}
return nil return nil
} }
func axisMappings(id string) map[StandardAxis]*mapping { func axisMappings(id string) map[StandardAxis]*mapping {
if m, ok := gamepadAxisMappings[id]; ok { // TODO: Use the database instead of the original mapping (#2308).
return m // The buttons and axes assignments should be fixed.
}
if currentPlatform == platformAndroid { if currentPlatform == platformAndroid {
if addAndroidDefaultMappings(id) { if addAndroidDefaultMappings(id) {
return gamepadAxisMappings[id] return gamepadAxisMappings[id]
} }
} }
if m, ok := gamepadAxisMappings[id]; ok {
return m
}
return nil return nil
} }
@ -711,30 +715,32 @@ func addAndroidDefaultMappings(id string) bool {
} }
} }
// TODO: Assign DPAD buttons correctly (#2308).
if buttonMask&(1<<SDLControllerButtonDpadUp) != 0 { if buttonMask&(1<<SDLControllerButtonDpadUp) != 0 {
gamepadButtonMappings[id][StandardButtonLeftTop] = &mapping{ gamepadButtonMappings[id][StandardButtonLeftTop] = &mapping{
Type: mappingTypeButton, Type: mappingTypeHat,
Index: SDLControllerButtonDpadUp, Index: 0,
HatState: HatUp,
} }
} }
if buttonMask&(1<<SDLControllerButtonDpadDown) != 0 { if buttonMask&(1<<SDLControllerButtonDpadDown) != 0 {
gamepadButtonMappings[id][StandardButtonLeftBottom] = &mapping{ gamepadButtonMappings[id][StandardButtonLeftBottom] = &mapping{
Type: mappingTypeButton, Type: mappingTypeHat,
Index: SDLControllerButtonDpadDown, Index: 0,
HatState: HatDown,
} }
} }
if buttonMask&(1<<SDLControllerButtonDpadLeft) != 0 { if buttonMask&(1<<SDLControllerButtonDpadLeft) != 0 {
gamepadButtonMappings[id][StandardButtonLeftLeft] = &mapping{ gamepadButtonMappings[id][StandardButtonLeftLeft] = &mapping{
Type: mappingTypeButton, Type: mappingTypeHat,
Index: SDLControllerButtonDpadLeft, Index: 0,
HatState: HatLeft,
} }
} }
if buttonMask&(1<<SDLControllerButtonDpadRight) != 0 { if buttonMask&(1<<SDLControllerButtonDpadRight) != 0 {
gamepadButtonMappings[id][StandardButtonLeftRight] = &mapping{ gamepadButtonMappings[id][StandardButtonLeftRight] = &mapping{
Type: mappingTypeButton, Type: mappingTypeHat,
Index: SDLControllerButtonDpadRight, Index: 0,
HatState: HatRight,
} }
} }