internal/gamepaddb: refactoring

Updates #2936
This commit is contained in:
Hajime Hoshi 2024-03-29 13:18:13 +09:00
parent 941c97eba2
commit 24238e16af
3 changed files with 10 additions and 22 deletions

View File

@ -16,10 +16,6 @@
package gamepaddb
import (
_ "embed"
)
var additionalGLFWGamepads = []byte(`
78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,
78696e70757402000000000000000000,XInput Wheel (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,

View File

@ -1,7 +0,0 @@
78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,
78696e70757402000000000000000000,XInput Wheel (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,
78696e70757403000000000000000000,XInput Arcade Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,
78696e70757404000000000000000000,XInput Flight Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,
78696e70757405000000000000000000,XInput Dance Pad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,
78696e70757406000000000000000000,XInput Guitar (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,
78696e70757408000000000000000000,XInput Drum Kit (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,

View File

@ -79,8 +79,9 @@ func main() {
}
func run() error {
// Follow the standard comment rule (https://pkg.go.dev/cmd/go#hdr-Generate_Go_files_by_processing_source).
doNotEdit := "// Code generated by gen.go using 'go generate'. DO NOT EDIT."
// doNotEditor is a special comment for generated files.
// This follows the standard comment rule (https://pkg.go.dev/cmd/go#hdr-Generate_Go_files_by_processing_source).
const doNotEdit = "// Code generated by gen.go using 'go generate'. DO NOT EDIT."
type gamePadPlatform struct {
filenameSuffix string
@ -108,7 +109,7 @@ func run() error {
},
}
controllerDBs, err := splitControllersByPlatform(gameControllerDB)
controllerDBs, err := splitDBsByPlatform(gameControllerDB)
if err != nil {
return err
}
@ -116,12 +117,11 @@ func run() error {
for sdlPlatformName, platform := range platforms {
controllerDB, ok := controllerDBs[sdlPlatformName]
if !ok {
return fmt.Errorf("failed to find controller db for platform %s in gamecontrollerdb_txt", sdlPlatformName)
return fmt.Errorf("failed to find controller db for platform %s in gamecontrollerdb.txt", sdlPlatformName)
}
// write each chunk into separate text file for embedding into respective generated files
err = os.WriteFile(fmt.Sprintf("gamecontrollerdb_%s.txt", platform.filenameSuffix), []byte(controllerDB), 0666)
if err != nil {
// Write each chunk into separate text file for embedding into respective generated files.
if err = os.WriteFile(fmt.Sprintf("gamecontrollerdb_%s.txt", platform.filenameSuffix), []byte(controllerDB), 0666); err != nil {
return err
}
@ -137,7 +137,7 @@ func run() error {
}
defer f.Close()
err = tmpl.Execute(f, struct {
if err := tmpl.Execute(f, struct {
License string
DoNotEdit string
BuildConstraints string
@ -147,8 +147,7 @@ func run() error {
DoNotEdit: doNotEdit,
BuildConstraints: platform.buildConstraints,
FileNameSuffix: platform.filenameSuffix,
})
if err != nil {
}); err != nil {
return err
}
}
@ -156,7 +155,7 @@ func run() error {
return nil
}
func splitControllersByPlatform(controllerDB []byte) (map[string]string, error) {
func splitDBsByPlatform(controllerDB []byte) (map[string]string, error) {
s := bufio.NewScanner(bytes.NewReader(controllerDB))
dbs := map[string]string{}