input: Add KeyMax

This commit is contained in:
Hajime Hoshi 2016-09-03 15:28:37 +09:00
parent d62a90dfca
commit 730b0d5ff9
3 changed files with 11 additions and 3 deletions

View File

@ -27,13 +27,16 @@ var gamepadAbstractButtons = []abstractButton{
}
type Input struct {
keyStates [256]int
keyStates map[ebiten.Key]int
gamepadButtonStates map[ebiten.GamepadButton]int
gamepadAbstractButtonStates map[abstractButton]int
gamepadConfig gamepadConfig
}
func (i *Input) StateForKey(key ebiten.Key) int {
if i.keyStates == nil {
return 0
}
return i.keyStates[key]
}
@ -52,7 +55,10 @@ func (i *Input) stateForGamepadAbstractButton(b abstractButton) int {
}
func (i *Input) Update() {
for key := range i.keyStates {
if i.keyStates == nil {
i.keyStates = map[ebiten.Key]int{}
}
for key := ebiten.Key(0); key <= ebiten.KeyMax; key++ {
if !ebiten.IsKeyPressed(ebiten.Key(key)) {
i.keyStates[key] = 0
continue

View File

@ -88,7 +88,7 @@ type Key int
// Keys
const (
{{range $index, $name := .KeyNames}}Key{{$name}} = Key(ui.Key{{$name}})
{{end}}
{{end}} KeyMax = Key{{.LastKeyName}}
)
`
@ -279,6 +279,7 @@ func main() {
"KeyCodeToName": keyCodeToName,
"Codes": codes,
"KeyNames": names,
"LastKeyName": names[len(names)-1],
"KeyNamesWithoutMods": namesWithoutMods,
}); err != nil {
log.Fatal(err)

View File

@ -94,4 +94,5 @@ const (
KeySpace = Key(ui.KeySpace)
KeyTab = Key(ui.KeyTab)
KeyUp = Key(ui.KeyUp)
KeyMax = KeyUp
)