mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 09:22:01 +01:00
inpututil: Bug fix: delete gamepad data that doesn't exist
This commit is contained in:
parent
8aa72d9576
commit
37b27d3a2d
@ -50,6 +50,7 @@ func (i *inputState) update() {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
|
||||
// Keyboard
|
||||
for k := ebiten.Key(0); k <= ebiten.KeyMax; k++ {
|
||||
if ebiten.IsKeyPressed(k) {
|
||||
i.keyStates[k]++
|
||||
@ -58,6 +59,7 @@ func (i *inputState) update() {
|
||||
}
|
||||
}
|
||||
|
||||
// Mouse
|
||||
for _, b := range []ebiten.MouseButton{
|
||||
ebiten.MouseButtonLeft,
|
||||
ebiten.MouseButtonRight,
|
||||
@ -70,7 +72,10 @@ func (i *inputState) update() {
|
||||
}
|
||||
}
|
||||
|
||||
// Gamepads
|
||||
ids := map[int]struct{}{}
|
||||
for _, id := range ebiten.GamepadIDs() {
|
||||
ids[id] = struct{}{}
|
||||
if _, ok := i.gamepadButtonStates[id]; !ok {
|
||||
i.gamepadButtonStates[id] = map[ebiten.GamepadButton]int{}
|
||||
}
|
||||
@ -83,13 +88,23 @@ func (i *inputState) update() {
|
||||
}
|
||||
}
|
||||
}
|
||||
idsToDelete := []int{}
|
||||
for id := range i.gamepadButtonStates {
|
||||
if _, ok := ids[id]; !ok {
|
||||
idsToDelete = append(idsToDelete, id)
|
||||
}
|
||||
}
|
||||
for _, id := range idsToDelete {
|
||||
delete(i.gamepadButtonStates, id)
|
||||
}
|
||||
|
||||
ids := map[int]struct{}{}
|
||||
// Touches
|
||||
ids = map[int]struct{}{}
|
||||
for _, t := range ebiten.Touches() {
|
||||
ids[t.ID()] = struct{}{}
|
||||
i.touchStates[t.ID()]++
|
||||
}
|
||||
idsToDelete := []int{}
|
||||
idsToDelete = []int{}
|
||||
for id := range i.touchStates {
|
||||
if _, ok := ids[id]; !ok {
|
||||
idsToDelete = append(idsToDelete, id)
|
||||
|
Loading…
Reference in New Issue
Block a user