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 {
|
type Input struct {
|
||||||
keyStates [256]int
|
keyStates map[ebiten.Key]int
|
||||||
gamepadButtonStates map[ebiten.GamepadButton]int
|
gamepadButtonStates map[ebiten.GamepadButton]int
|
||||||
gamepadAbstractButtonStates map[abstractButton]int
|
gamepadAbstractButtonStates map[abstractButton]int
|
||||||
gamepadConfig gamepadConfig
|
gamepadConfig gamepadConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Input) StateForKey(key ebiten.Key) int {
|
func (i *Input) StateForKey(key ebiten.Key) int {
|
||||||
|
if i.keyStates == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
return i.keyStates[key]
|
return i.keyStates[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +55,10 @@ func (i *Input) stateForGamepadAbstractButton(b abstractButton) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Input) Update() {
|
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)) {
|
if !ebiten.IsKeyPressed(ebiten.Key(key)) {
|
||||||
i.keyStates[key] = 0
|
i.keyStates[key] = 0
|
||||||
continue
|
continue
|
||||||
|
@ -88,7 +88,7 @@ type Key int
|
|||||||
// Keys
|
// Keys
|
||||||
const (
|
const (
|
||||||
{{range $index, $name := .KeyNames}}Key{{$name}} = Key(ui.Key{{$name}})
|
{{range $index, $name := .KeyNames}}Key{{$name}} = Key(ui.Key{{$name}})
|
||||||
{{end}}
|
{{end}} KeyMax = Key{{.LastKeyName}}
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -279,6 +279,7 @@ func main() {
|
|||||||
"KeyCodeToName": keyCodeToName,
|
"KeyCodeToName": keyCodeToName,
|
||||||
"Codes": codes,
|
"Codes": codes,
|
||||||
"KeyNames": names,
|
"KeyNames": names,
|
||||||
|
"LastKeyName": names[len(names)-1],
|
||||||
"KeyNamesWithoutMods": namesWithoutMods,
|
"KeyNamesWithoutMods": namesWithoutMods,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user