internal/gamepaddb: bug fix: platform was not initialized correctly

After 6552ae1dbe, 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
This commit is contained in:
Hajime Hoshi 2024-04-18 13:28:51 +09:00
parent 11223d9fae
commit c74e7fa943

View File

@ -39,12 +39,9 @@ const (
platformIOS
)
var currentPlatform platform
func init() {
func currentPlatform() platform {
if runtime.GOOS == "windows" {
currentPlatform = platformWindows
return
return platformWindows
}
if runtime.GOOS == "aix" ||
@ -56,24 +53,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
@ -336,7 +331,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]
}
@ -348,7 +343,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]
}
@ -544,7 +539,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
}