mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
input: Add KeyMax
This commit is contained in:
parent
d62a90dfca
commit
730b0d5ff9
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user