Skip to content

Commit

Permalink
internal/gamepaddb: allow the standard layout mapping for any platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Feb 5, 2022
1 parent 19bfc97 commit 93b2a07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions internal/gamepaddb/gamepaddb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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])
}
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 93b2a07

Please sign in to comment.