Skip to content

Commit

Permalink
internal/gamepaddb: bug fix: platform was not initialized correctly
Browse files Browse the repository at this point in the history
After 6552ae1, the order of the init
function calls changed, and then the platform was not initialized
correctly.

This change fixes this issue by not relying on an init function to
get the platform.

Closes #2964
  • Loading branch information
hajimehoshi committed Apr 18, 2024
1 parent b21ee6f commit 17d75bf
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions internal/gamepaddb/gamepaddb.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ const (
platformIOS
)

var currentPlatform platform

func init() {
func currentPlatform() platform {
if runtime.GOOS == "windows" {
currentPlatform = platformWindows
return
return platformWindows
}

if runtime.GOOS == "aix" ||
Expand All @@ -53,24 +50,22 @@ func init() {
runtime.GOOS == "netbsd" ||
runtime.GOOS == "openbsd" ||
runtime.GOOS == "solaris" {
currentPlatform = platformUnix
return
return platformUnix
}

if runtime.GOOS == "android" {
currentPlatform = platformAndroid
return
return platformAndroid
}

if runtime.GOOS == "ios" {
currentPlatform = platformIOS
return
return platformIOS
}

if runtime.GOOS == "darwin" {
currentPlatform = platformMacOS
return
return platformMacOS
}

return platformUnknown
}

type mappingType int
Expand Down Expand Up @@ -333,7 +328,7 @@ func buttonMappings(id string) map[StandardButton]mapping {
if m, ok := gamepadButtonMappings[id]; ok {
return m
}
if currentPlatform == platformAndroid {
if currentPlatform() == platformAndroid {
if addAndroidDefaultMappings(id) {
return gamepadButtonMappings[id]
}
Expand All @@ -345,7 +340,7 @@ func axisMappings(id string) map[StandardAxis]mapping {
if m, ok := gamepadAxisMappings[id]; ok {
return m
}
if currentPlatform == platformAndroid {
if currentPlatform() == platformAndroid {
if addAndroidDefaultMappings(id) {
return gamepadAxisMappings[id]
}
Expand Down Expand Up @@ -541,7 +536,7 @@ func Update(mappingData []byte) error {

for s.Scan() {
line := s.Text()
id, name, buttons, axes, err := parseLine(line, currentPlatform)
id, name, buttons, axes, err := parseLine(line, currentPlatform())
if err != nil {
return err
}
Expand Down

0 comments on commit 17d75bf

Please sign in to comment.