internal/gamepaddb: allow the standard layout mapping for any platforms

Closes #1957
This commit is contained in:
Hajime Hoshi 2022-02-06 03:37:59 +09:00
parent 19bfc97a5e
commit 93b2a0756b
2 changed files with 13 additions and 4 deletions

View File

@ -304,6 +304,15 @@ func IsStandardGamepadLayoutAvailable(id GamepadID) bool {
// When using this facility to support new hardware, please also send a pull request to
// https://github.com/gabomdq/SDL_GameControllerDB to make your mapping available to everyone else.
//
// A platform field in a line corresponds with a GOOS like the following:
//
// "Windows": GOOS=windows
// "Mac OS X": GOOS=darwin (not ios)
// "Linux": GOOS=linux (not android)
// "Android": GOOS=android
// "iOS": GOOS=ios
// "": Any GOOS
//
// On platforms where gamepad mappings are not managed by Ebiten, this always returns false and nil.
//
// UpdateStandardGamepadLayoutMappings is concurrent-safe.

View File

@ -145,6 +145,8 @@ func processLine(line string, platform platform) error {
continue
}
tks := strings.Split(token, ":")
// Note that the platform part is listed in the definition of SDL_GetPlatform.
if tks[0] == "platform" {
switch tks[1] {
case "Windows":
@ -167,6 +169,8 @@ func processLine(line string, platform platform) error {
if platform != platformIOS {
return nil
}
case "":
// Allow any platforms
default:
return fmt.Errorf("gamepaddb: unexpected platform: %s", tks[1])
}
@ -503,10 +507,6 @@ func IsButtonPressed(id string, button StandardButton, state GamepadState) bool
// Update adds new gamepad mappings.
// The string must be in the format of SDL_GameControllerDB.
func Update(mapping []byte) (bool, error) {
if currentPlatform == platformUnknown {
return false, nil
}
mappingsM.Lock()
defer mappingsM.Unlock()