mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-27 04:08:53 +01:00
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:
parent
11223d9fae
commit
c74e7fa943
@ -39,12 +39,9 @@ const (
|
|||||||
platformIOS
|
platformIOS
|
||||||
)
|
)
|
||||||
|
|
||||||
var currentPlatform platform
|
func currentPlatform() platform {
|
||||||
|
|
||||||
func init() {
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
currentPlatform = platformWindows
|
return platformWindows
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "aix" ||
|
if runtime.GOOS == "aix" ||
|
||||||
@ -56,24 +53,22 @@ func init() {
|
|||||||
runtime.GOOS == "netbsd" ||
|
runtime.GOOS == "netbsd" ||
|
||||||
runtime.GOOS == "openbsd" ||
|
runtime.GOOS == "openbsd" ||
|
||||||
runtime.GOOS == "solaris" {
|
runtime.GOOS == "solaris" {
|
||||||
currentPlatform = platformUnix
|
return platformUnix
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "android" {
|
if runtime.GOOS == "android" {
|
||||||
currentPlatform = platformAndroid
|
return platformAndroid
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "ios" {
|
if runtime.GOOS == "ios" {
|
||||||
currentPlatform = platformIOS
|
return platformIOS
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
currentPlatform = platformMacOS
|
return platformMacOS
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return platformUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
type mappingType int
|
type mappingType int
|
||||||
@ -336,7 +331,7 @@ func buttonMappings(id string) map[StandardButton]mapping {
|
|||||||
if m, ok := gamepadButtonMappings[id]; ok {
|
if m, ok := gamepadButtonMappings[id]; ok {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
if currentPlatform == platformAndroid {
|
if currentPlatform() == platformAndroid {
|
||||||
if addAndroidDefaultMappings(id) {
|
if addAndroidDefaultMappings(id) {
|
||||||
return gamepadButtonMappings[id]
|
return gamepadButtonMappings[id]
|
||||||
}
|
}
|
||||||
@ -348,7 +343,7 @@ func axisMappings(id string) map[StandardAxis]mapping {
|
|||||||
if m, ok := gamepadAxisMappings[id]; ok {
|
if m, ok := gamepadAxisMappings[id]; ok {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
if currentPlatform == platformAndroid {
|
if currentPlatform() == platformAndroid {
|
||||||
if addAndroidDefaultMappings(id) {
|
if addAndroidDefaultMappings(id) {
|
||||||
return gamepadAxisMappings[id]
|
return gamepadAxisMappings[id]
|
||||||
}
|
}
|
||||||
@ -544,7 +539,7 @@ func Update(mappingData []byte) error {
|
|||||||
|
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
line := s.Text()
|
line := s.Text()
|
||||||
id, name, buttons, axes, err := parseLine(line, currentPlatform)
|
id, name, buttons, axes, err := parseLine(line, currentPlatform())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user