mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 19:58:54 +01:00
internal/ui: refactoring: rename uiKeyToJSKey to uiKeyToJSCode
This commit is contained in:
parent
d10636d235
commit
7dd22fdc61
@ -593,7 +593,7 @@ import (
|
|||||||
"syscall/js"
|
"syscall/js"
|
||||||
)
|
)
|
||||||
|
|
||||||
var uiKeyToJSKey = map[Key]js.Value{
|
var uiKeyToJSCode = map[Key]js.Value{
|
||||||
{{range $name, $code := .UIKeyNameToJSKey}}Key{{$name}}: js.ValueOf({{$code | printf "%q"}}),
|
{{range $name, $code := .UIKeyNameToJSKey}}Key{{$name}}: js.ValueOf({{$code | printf "%q"}}),
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,11 @@ type touchInClient struct {
|
|||||||
y float64
|
y float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsKeyToID(key js.Value) Key {
|
func jsCodeToID(code js.Value) Key {
|
||||||
// js.Value cannot be used as a map key.
|
// js.Value cannot be used as a map key.
|
||||||
// As the number of keys is around 100, just a dumb loop should work.
|
// As the number of keys is around 100, just a dumb loop should work.
|
||||||
for uiKey, jsKey := range uiKeyToJSKey {
|
for uiKey, jsCode := range uiKeyToJSCode {
|
||||||
if jsKey.Equal(key) {
|
if jsCode.Equal(code) {
|
||||||
return uiKey
|
return uiKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ var codeToMouseButton = map[int]MouseButton{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) keyDown(code js.Value) {
|
func (u *UserInterface) keyDown(code js.Value) {
|
||||||
id := jsKeyToID(code)
|
id := jsCodeToID(code)
|
||||||
if id < 0 {
|
if id < 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ func (u *UserInterface) keyDown(code js.Value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) keyUp(code js.Value) {
|
func (u *UserInterface) keyUp(code js.Value) {
|
||||||
id := jsKeyToID(code)
|
id := jsCodeToID(code)
|
||||||
if id < 0 {
|
if id < 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ func (u *UserInterface) KeyName(key Key) string {
|
|||||||
u.keyboardLayoutMap = <-jsKeyboardGetLayoutMapCh
|
u.keyboardLayoutMap = <-jsKeyboardGetLayoutMapCh
|
||||||
}
|
}
|
||||||
|
|
||||||
n := u.keyboardLayoutMap.Call("get", uiKeyToJSKey[key])
|
n := u.keyboardLayoutMap.Call("get", uiKeyToJSCode[key])
|
||||||
if n.IsUndefined() {
|
if n.IsUndefined() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"syscall/js"
|
"syscall/js"
|
||||||
)
|
)
|
||||||
|
|
||||||
var uiKeyToJSKey = map[Key]js.Value{
|
var uiKeyToJSCode = map[Key]js.Value{
|
||||||
KeyA: js.ValueOf("KeyA"),
|
KeyA: js.ValueOf("KeyA"),
|
||||||
KeyAltLeft: js.ValueOf("AltLeft"),
|
KeyAltLeft: js.ValueOf("AltLeft"),
|
||||||
KeyAltRight: js.ValueOf("AltRight"),
|
KeyAltRight: js.ValueOf("AltRight"),
|
||||||
|
Loading…
Reference in New Issue
Block a user