mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
input: Refactoring
This commit is contained in:
parent
83787123ac
commit
873128cc7e
32
genkeys.go
32
genkeys.go
@ -31,12 +31,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nameToCodes map[string][]string
|
nameToJSKeyCodes map[string][]string
|
||||||
keyCodeToNameEdge map[int]string
|
keyCodeToNameEdge map[int]string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
nameToCodes = map[string][]string{
|
nameToJSKeyCodes = map[string][]string{
|
||||||
"Comma": {"Comma"},
|
"Comma": {"Comma"},
|
||||||
"Period": {"Period"},
|
"Period": {"Period"},
|
||||||
"Alt": {"AltLeft", "AltRight"},
|
"Alt": {"AltLeft", "AltRight"},
|
||||||
@ -75,28 +75,28 @@ func init() {
|
|||||||
}
|
}
|
||||||
// ASCII: 0 - 9
|
// ASCII: 0 - 9
|
||||||
for c := '0'; c <= '9'; c++ {
|
for c := '0'; c <= '9'; c++ {
|
||||||
nameToCodes[string(c)] = []string{"Digit" + string(c)}
|
nameToJSKeyCodes[string(c)] = []string{"Digit" + string(c)}
|
||||||
}
|
}
|
||||||
// ASCII: A - Z
|
// ASCII: A - Z
|
||||||
for c := 'A'; c <= 'Z'; c++ {
|
for c := 'A'; c <= 'Z'; c++ {
|
||||||
nameToCodes[string(c)] = []string{"Key" + string(c)}
|
nameToJSKeyCodes[string(c)] = []string{"Key" + string(c)}
|
||||||
}
|
}
|
||||||
// Function keys
|
// Function keys
|
||||||
for i := 1; i <= 12; i++ {
|
for i := 1; i <= 12; i++ {
|
||||||
nameToCodes["F"+strconv.Itoa(i)] = []string{"F" + strconv.Itoa(i)}
|
nameToJSKeyCodes["F"+strconv.Itoa(i)] = []string{"F" + strconv.Itoa(i)}
|
||||||
}
|
}
|
||||||
// Numpad
|
// Numpad
|
||||||
// https://www.w3.org/TR/uievents-code/#key-numpad-section
|
// https://www.w3.org/TR/uievents-code/#key-numpad-section
|
||||||
for c := '0'; c <= '9'; c++ {
|
for c := '0'; c <= '9'; c++ {
|
||||||
nameToCodes["KP"+string(c)] = []string{"Numpad" + string(c)}
|
nameToJSKeyCodes["KP"+string(c)] = []string{"Numpad" + string(c)}
|
||||||
}
|
}
|
||||||
nameToCodes["KPDecimal"] = []string{"NumpadDecimal"}
|
nameToJSKeyCodes["KPDecimal"] = []string{"NumpadDecimal"}
|
||||||
nameToCodes["KPDivide"] = []string{"NumpadDivide"}
|
nameToJSKeyCodes["KPDivide"] = []string{"NumpadDivide"}
|
||||||
nameToCodes["KPMultiply"] = []string{"NumpadMultiply"}
|
nameToJSKeyCodes["KPMultiply"] = []string{"NumpadMultiply"}
|
||||||
nameToCodes["KPSubtract"] = []string{"NumpadSubtract"}
|
nameToJSKeyCodes["KPSubtract"] = []string{"NumpadSubtract"}
|
||||||
nameToCodes["KPAdd"] = []string{"NumpadAdd"}
|
nameToJSKeyCodes["KPAdd"] = []string{"NumpadAdd"}
|
||||||
nameToCodes["KPEnter"] = []string{"NumpadEnter"}
|
nameToJSKeyCodes["KPEnter"] = []string{"NumpadEnter"}
|
||||||
nameToCodes["KPEqual"] = []string{"NumpadEqual"}
|
nameToJSKeyCodes["KPEqual"] = []string{"NumpadEqual"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -256,7 +256,7 @@ const inputKeysJSTmpl = `{{.License}}
|
|||||||
package input
|
package input
|
||||||
|
|
||||||
var keyToCodes = map[Key][]string{
|
var keyToCodes = map[Key][]string{
|
||||||
{{range $name, $codes := .NameToCodes}}Key{{$name}}: []string{
|
{{range $name, $codes := .NameToJSKeyCodes}}Key{{$name}}: []string{
|
||||||
{{range $code := $codes}}"{{$code}}",{{end}}
|
{{range $code := $codes}}"{{$code}}",{{end}}
|
||||||
},
|
},
|
||||||
{{end}}
|
{{end}}
|
||||||
@ -368,7 +368,7 @@ func main() {
|
|||||||
namesSet := map[string]struct{}{}
|
namesSet := map[string]struct{}{}
|
||||||
namesWithoutModsSet := map[string]struct{}{}
|
namesWithoutModsSet := map[string]struct{}{}
|
||||||
codes := []string{}
|
codes := []string{}
|
||||||
for name, cs := range nameToCodes {
|
for name, cs := range nameToJSKeyCodes {
|
||||||
namesSet[name] = struct{}{}
|
namesSet[name] = struct{}{}
|
||||||
codes = append(codes, cs...)
|
codes = append(codes, cs...)
|
||||||
if name != "Alt" && name != "Control" && name != "Shift" {
|
if name != "Alt" && name != "Control" && name != "Shift" {
|
||||||
@ -425,7 +425,7 @@ func main() {
|
|||||||
"License": license,
|
"License": license,
|
||||||
"DoNotEdit": doNotEdit,
|
"DoNotEdit": doNotEdit,
|
||||||
"BuildTag": buildTag,
|
"BuildTag": buildTag,
|
||||||
"NameToCodes": nameToCodes,
|
"NameToJSKeyCodes": nameToJSKeyCodes,
|
||||||
"KeyCodeToNameEdge": keyCodeToNameEdge,
|
"KeyCodeToNameEdge": keyCodeToNameEdge,
|
||||||
"Codes": codes,
|
"Codes": codes,
|
||||||
"KeyNames": names,
|
"KeyNames": names,
|
||||||
|
Loading…
Reference in New Issue
Block a user