mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
inpututil: Bug fix: prevGamepadButtondDurations was not copied correctly
This commit is contained in:
parent
252f4430d8
commit
59dc58a74c
@ -98,33 +98,29 @@ func (i *inputState) update() {
|
|||||||
|
|
||||||
// Gamepads
|
// Gamepads
|
||||||
|
|
||||||
// Copy the gamepad IDs
|
// Copy the gamepad IDs.
|
||||||
i.prevGamepadIDs = map[int]struct{}{}
|
i.prevGamepadIDs = map[int]struct{}{}
|
||||||
for id := range i.gamepadIDs {
|
for id := range i.gamepadIDs {
|
||||||
i.prevGamepadIDs[id] = struct{}{}
|
i.prevGamepadIDs[id] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the previous states first since some gamepad IDs might be already gone.
|
// Copy the gamepad button durations.
|
||||||
for id := range i.prevGamepadButtonDurations {
|
i.prevGamepadButtonDurations = map[int]map[ebiten.GamepadButton]int{}
|
||||||
for b := range i.prevGamepadButtonDurations[id] {
|
for id, ds := range i.gamepadButtonDurations {
|
||||||
i.prevGamepadButtonDurations[id][b] = 0
|
i.prevGamepadButtonDurations[id] = map[ebiten.GamepadButton]int{}
|
||||||
|
for b, d := range ds {
|
||||||
|
i.prevGamepadButtonDurations[id][b] = d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i.gamepadIDs = map[int]struct{}{}
|
i.gamepadIDs = map[int]struct{}{}
|
||||||
for _, id := range ebiten.GamepadIDs() {
|
for _, id := range ebiten.GamepadIDs() {
|
||||||
i.gamepadIDs[id] = struct{}{}
|
i.gamepadIDs[id] = struct{}{}
|
||||||
|
|
||||||
if _, ok := i.prevGamepadButtonDurations[id]; !ok {
|
|
||||||
i.prevGamepadButtonDurations[id] = map[ebiten.GamepadButton]int{}
|
|
||||||
}
|
|
||||||
if _, ok := i.gamepadButtonDurations[id]; !ok {
|
if _, ok := i.gamepadButtonDurations[id]; !ok {
|
||||||
i.gamepadButtonDurations[id] = map[ebiten.GamepadButton]int{}
|
i.gamepadButtonDurations[id] = map[ebiten.GamepadButton]int{}
|
||||||
}
|
}
|
||||||
|
|
||||||
n := ebiten.GamepadButtonNum(id)
|
n := ebiten.GamepadButtonNum(id)
|
||||||
for b := ebiten.GamepadButton(0); b < ebiten.GamepadButton(n); b++ {
|
for b := ebiten.GamepadButton(0); b < ebiten.GamepadButton(n); b++ {
|
||||||
i.prevGamepadButtonDurations[id][b] = i.gamepadButtonDurations[id][b]
|
|
||||||
if ebiten.IsGamepadButtonPressed(id, b) {
|
if ebiten.IsGamepadButtonPressed(id, b) {
|
||||||
i.gamepadButtonDurations[id][b]++
|
i.gamepadButtonDurations[id][b]++
|
||||||
} else {
|
} else {
|
||||||
@ -145,6 +141,7 @@ func (i *inputState) update() {
|
|||||||
// Touches
|
// Touches
|
||||||
ids := map[int]struct{}{}
|
ids := map[int]struct{}{}
|
||||||
|
|
||||||
|
// Copy the touch durations.
|
||||||
i.prevTouchDurations = map[int]int{}
|
i.prevTouchDurations = map[int]int{}
|
||||||
for id := range i.touchDurations {
|
for id := range i.touchDurations {
|
||||||
i.prevTouchDurations[id] = i.touchDurations[id]
|
i.prevTouchDurations[id] = i.touchDurations[id]
|
||||||
|
Loading…
Reference in New Issue
Block a user