Bug fix: compilation error on browsers and mobiles

This commit is contained in:
Hajime Hoshi 2019-03-30 23:53:27 +09:00
parent 7dca1889a1
commit 486a6134e4
4 changed files with 36 additions and 24 deletions

View File

@ -320,14 +320,18 @@ const inputKeysJSTmpl = `{{.License}}
package input package input
var keyToCodes = map[Key][]string{ import (
"github.com/hajimehoshi/ebiten/internal/driver"
)
var keyToCodes = map[driver.Key][]string{
{{range $name, $codes := .NameToJSKeyCodes}}driver.Key{{$name}}: []string{ {{range $name, $codes := .NameToJSKeyCodes}}driver.Key{{$name}}: []string{
{{range $code := $codes}}"{{$code}}",{{end}} {{range $code := $codes}}"{{$code}}",{{end}}
}, },
{{end}} {{end}}
} }
var keyCodeToKeyEdge = map[int]Key{ var keyCodeToKeyEdge = map[int]driver.Key{
{{range $code, $name := .KeyCodeToNameEdge}}{{$code}}: driver.Key{{$name}}, {{range $code, $name := .KeyCodeToNameEdge}}{{$code}}: driver.Key{{$name}},
{{end}} {{end}}
} }

View File

@ -20,6 +20,8 @@ import (
"unicode" "unicode"
"github.com/gopherjs/gopherwasm/js" "github.com/gopherjs/gopherwasm/js"
"github.com/hajimehoshi/ebiten/internal/driver"
) )
type mockRWLock struct{} type mockRWLock struct{}
@ -56,7 +58,7 @@ func (i *Input) ResetWheelValues() {
i.wheelY = 0 i.wheelY = 0
} }
func (i *Input) IsKeyPressed(key Key) bool { func (i *Input) IsKeyPressed(key driver.Key) bool {
if i.keyPressed != nil { if i.keyPressed != nil {
for _, c := range keyToCodes[key] { for _, c := range keyToCodes[key] {
if i.keyPressed[c] { if i.keyPressed[c] {
@ -77,13 +79,13 @@ func (i *Input) IsKeyPressed(key Key) bool {
return false return false
} }
var codeToMouseButton = map[int]MouseButton{ var codeToMouseButton = map[int]driver.MouseButton{
0: MouseButtonLeft, 0: driver.MouseButtonLeft,
1: MouseButtonMiddle, 1: driver.MouseButtonMiddle,
2: MouseButtonRight, 2: driver.MouseButtonRight,
} }
func (i *Input) IsMouseButtonPressed(button MouseButton) bool { func (i *Input) IsMouseButtonPressed(button driver.MouseButton) bool {
if i.mouseButtonPressed == nil { if i.mouseButtonPressed == nil {
i.mouseButtonPressed = map[int]bool{} i.mouseButtonPressed = map[int]bool{}
} }
@ -191,24 +193,24 @@ func OnKeyDown(e js.Value) {
c := e.Get("code") c := e.Get("code")
if c == js.Undefined() { if c == js.Undefined() {
code := e.Get("keyCode").Int() code := e.Get("keyCode").Int()
if keyCodeToKeyEdge[code] == KeyUp || if keyCodeToKeyEdge[code] == driver.KeyUp ||
keyCodeToKeyEdge[code] == KeyDown || keyCodeToKeyEdge[code] == driver.KeyDown ||
keyCodeToKeyEdge[code] == KeyLeft || keyCodeToKeyEdge[code] == driver.KeyLeft ||
keyCodeToKeyEdge[code] == KeyRight || keyCodeToKeyEdge[code] == driver.KeyRight ||
keyCodeToKeyEdge[code] == KeyBackspace || keyCodeToKeyEdge[code] == driver.KeyBackspace ||
keyCodeToKeyEdge[code] == KeyTab { keyCodeToKeyEdge[code] == driver.KeyTab {
e.Call("preventDefault") e.Call("preventDefault")
} }
theInput.keyDownEdge(code) theInput.keyDownEdge(code)
return return
} }
cs := c.String() cs := c.String()
if cs == keyToCodes[KeyUp][0] || if cs == keyToCodes[driver.KeyUp][0] ||
cs == keyToCodes[KeyDown][0] || cs == keyToCodes[driver.KeyDown][0] ||
cs == keyToCodes[KeyLeft][0] || cs == keyToCodes[driver.KeyLeft][0] ||
cs == keyToCodes[KeyRight][0] || cs == keyToCodes[driver.KeyRight][0] ||
cs == keyToCodes[KeyBackspace][0] || cs == keyToCodes[driver.KeyBackspace][0] ||
cs == keyToCodes[KeyTab][0] { cs == keyToCodes[driver.KeyTab][0] {
e.Call("preventDefault") e.Call("preventDefault")
} }
theInput.keyDown(cs) theInput.keyDown(cs)

View File

@ -18,6 +18,8 @@ package input
import ( import (
"sync" "sync"
"github.com/hajimehoshi/ebiten/internal/driver"
) )
type Input struct { type Input struct {
@ -32,7 +34,7 @@ func (i *Input) RuneBuffer() []rune {
return nil return nil
} }
func (i *Input) IsKeyPressed(key Key) bool { func (i *Input) IsKeyPressed(key driver.Key) bool {
return false return false
} }
@ -40,7 +42,7 @@ func (i *Input) Wheel() (xoff, yoff float64) {
return 0, 0 return 0, 0
} }
func (i *Input) IsMouseButtonPressed(key MouseButton) bool { func (i *Input) IsMouseButtonPressed(key driver.MouseButton) bool {
return false return false
} }

View File

@ -18,7 +18,11 @@
package input package input
var keyToCodes = map[Key][]string{ import (
"github.com/hajimehoshi/ebiten/internal/driver"
)
var keyToCodes = map[driver.Key][]string{
driver.Key0: { driver.Key0: {
"Digit0", "Digit0",
}, },
@ -321,7 +325,7 @@ var keyToCodes = map[Key][]string{
}, },
} }
var keyCodeToKeyEdge = map[int]Key{ var keyCodeToKeyEdge = map[int]driver.Key{
8: driver.KeyBackspace, 8: driver.KeyBackspace,
9: driver.KeyTab, 9: driver.KeyTab,
13: driver.KeyEnter, 13: driver.KeyEnter,