Compare commits

..

1 Commits

Author SHA1 Message Date
Kenny
d3b209e3be
Merge 466f0c000c into dc77c655af 2024-03-27 11:19:20 -04:00

View File

@ -93,7 +93,7 @@ func run() error {
buildConstraints string
}
platforms := map[string]gamePadPlatform{
supported := map[string]gamePadPlatform{
"Windows": {
filenameSuffix: "windows",
buildConstraints: "//go:build windows && !microsoftgdk",
@ -121,22 +121,27 @@ func run() error {
return err
}
for sdlPlatformName, platform := range platforms {
controllerDB, ok := controllerDBs[sdlPlatformName]
for sdlName, platform := range supported {
controllerDB, ok := controllerDBs[sdlName]
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", sdlName)
}
// 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)
txtFile, err := os.Create(fmt.Sprintf("gamecontrollerdb_%s.txt", platform.filenameSuffix))
if err != nil {
return err
return fmt.Errorf("failed to open file: %v", err)
}
defer txtFile.Close()
written, err := txtFile.Write(controllerDB)
if err != nil {
return fmt.Errorf("failed to write controller db for %s, expected to write %d bytes, wrote %d: %v", sdlName, len(controllerDB), written, err)
}
path := fmt.Sprintf("db_%s.go", platform.filenameSuffix)
tmpl, err := template.New(path).Parse(dbTemplate)
if err != nil {
return err
return fmt.Errorf("failed to parse template: %v", err)
}
f, err := os.Create(path)
@ -164,23 +169,46 @@ func run() error {
return nil
}
func splitControllersByPlatform(controllerDB []byte) (map[string]string, error) {
func splitControllersByPlatform(controllerDB []byte) (map[string][]byte, error) {
s := bufio.NewScanner(bytes.NewReader(controllerDB))
dbs := map[string]string{}
dbs := map[string][]byte{}
var currentPlatform string
buf := bytes.Buffer{}
for s.Scan() {
line := s.Text()
if len(line) == 0 {
chunk := s.Bytes()
if len(chunk) == 0 {
continue
}
if line[0] == '#' {
currentPlatform = strings.Replace(line, "# ", "", 1)
continue
}
if chunk[0] == '#' {
if currentPlatform != "" && buf.Len() > 0 {
dbs[currentPlatform] = bytes.Clone(buf.Bytes())
buf.Reset()
}
dbs[currentPlatform] += line + "\n"
platform := strings.Replace(string(chunk), "# ", "", 1)
switch platform {
case "Windows":
currentPlatform = "Windows"
case "Mac OS X":
currentPlatform = "Mac OS X"
case "iOS":
currentPlatform = "iOS"
case "Android":
currentPlatform = "Android"
case "Linux":
currentPlatform = "Linux"
default:
continue
}
} else {
buf.Write(chunk)
buf.WriteByte('\n')
}
}
if currentPlatform != "" && buf.Len() > 0 {
dbs[currentPlatform] = bytes.Clone(buf.Bytes())
}
if err := s.Err(); err != nil {
return nil, err