Compare commits

...

2 Commits

Author SHA1 Message Date
Kenny Goodin
9037da3cf0 internal/gamepaddb: add missing license 2024-03-28 11:38:01 -04:00
Kenny Goodin
fd49f22a6c internal/gamepaddb: harden platform parsing, remove unnecessary
constraints from ios and android generated files
2024-03-28 11:35:23 -04:00
7 changed files with 52 additions and 60 deletions

View File

@ -14,8 +14,6 @@
// Code generated by gen.go using 'go generate'. DO NOT EDIT.
//go:build android
package gamepaddb
import (
@ -25,15 +23,8 @@ import (
//go:embed gamecontrollerdb_android.txt
var controllerBytes []byte
//go:embed gamecontrollerdb_glfw.txt
var glfwControllerBytes []byte
func init() {
if err := Update(controllerBytes); err != nil {
panic(err)
}
if err := Update(glfwControllerBytes); err != nil {
panic(err)
}
}

View File

@ -0,0 +1,37 @@
// Copyright 2024 The Ebitengine Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !android && !ios && !js && !microsoftgdk && !nintendosdk && !playstation5
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,
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,
`)
func init() {
if err := Update(additionalGLFWGamepads); err != nil {
panic(err)
}
}

View File

@ -14,8 +14,6 @@
// Code generated by gen.go using 'go generate'. DO NOT EDIT.
//go:build ios
package gamepaddb
import (
@ -25,15 +23,8 @@ import (
//go:embed gamecontrollerdb_ios.txt
var controllerBytes []byte
//go:embed gamecontrollerdb_glfw.txt
var glfwControllerBytes []byte
func init() {
if err := Update(controllerBytes); err != nil {
panic(err)
}
if err := Update(glfwControllerBytes); err != nil {
panic(err)
}
}

View File

@ -25,15 +25,8 @@ import (
//go:embed gamecontrollerdb_linbsd.txt
var controllerBytes []byte
//go:embed gamecontrollerdb_glfw.txt
var glfwControllerBytes []byte
func init() {
if err := Update(controllerBytes); err != nil {
panic(err)
}
if err := Update(glfwControllerBytes); err != nil {
panic(err)
}
}

View File

@ -14,7 +14,7 @@
// Code generated by gen.go using 'go generate'. DO NOT EDIT.
//go:build darwin && !ios
//go:build !ios
package gamepaddb
@ -25,15 +25,8 @@ import (
//go:embed gamecontrollerdb_macos_darwin.txt
var controllerBytes []byte
//go:embed gamecontrollerdb_glfw.txt
var glfwControllerBytes []byte
func init() {
if err := Update(controllerBytes); err != nil {
panic(err)
}
if err := Update(glfwControllerBytes); err != nil {
panic(err)
}
}

View File

@ -14,7 +14,7 @@
// Code generated by gen.go using 'go generate'. DO NOT EDIT.
//go:build windows && !microsoftgdk
//go:build !microsoftgdk
package gamepaddb
@ -25,15 +25,8 @@ import (
//go:embed gamecontrollerdb_windows.txt
var controllerBytes []byte
//go:embed gamecontrollerdb_glfw.txt
var glfwControllerBytes []byte
func init() {
if err := Update(controllerBytes); err != nil {
panic(err)
}
if err := Update(glfwControllerBytes); err != nil {
panic(err)
}
}

View File

@ -65,17 +65,11 @@ import (
//go:embed gamecontrollerdb_{{.FileNameSuffix}}.txt
var controllerBytes []byte
//go:embed gamecontrollerdb_glfw.txt
var glfwControllerBytes []byte
func init() {
if err := Update(controllerBytes); err != nil {
panic(err)
}
if err := Update(glfwControllerBytes); err != nil {
panic(err)
}
}`
func main() {
@ -96,23 +90,21 @@ func run() error {
platforms := map[string]gamePadPlatform{
"Windows": {
filenameSuffix: "windows",
buildConstraints: "//go:build windows && !microsoftgdk",
buildConstraints: "//go:build !microsoftgdk",
},
"Mac OS X": {
filenameSuffix: "macos_darwin",
buildConstraints: "//go:build darwin && !ios",
buildConstraints: "//go:build !ios",
},
"Linux": {
filenameSuffix: "linbsd",
buildConstraints: "//go:build (freebsd || (linux && !android) || netbsd || openbsd) && !nintendosdk && !playstation5",
},
"iOS": {
filenameSuffix: "ios",
buildConstraints: "//go:build ios",
filenameSuffix: "ios",
},
"Android": {
filenameSuffix: "android",
buildConstraints: "//go:build android",
filenameSuffix: "android",
},
}
@ -168,19 +160,21 @@ func splitControllersByPlatform(controllerDB []byte) (map[string]string, error)
s := bufio.NewScanner(bytes.NewReader(controllerDB))
dbs := map[string]string{}
var currentPlatform string
for s.Scan() {
line := s.Text()
if len(line) == 0 {
if strings.HasPrefix(line, "#") {
continue
}
if line[0] == '#' {
currentPlatform = strings.Replace(line, "# ", "", 1)
continue
parts := strings.Split(line, ",")
var platform string
for _, part := range parts {
if strings.HasPrefix(part, "platform:") {
platform = strings.Replace(part, "platform:", "", 1)
dbs[platform] += line + "\n"
break
}
}
dbs[currentPlatform] += line + "\n"
}
if err := s.Err(); err != nil {
return nil, err