Fixed JoyDeviceEvent (#2)

JoyDeviceEvent is now broken up into JoyDeviceAddedEvent and JoyDeviceRemovedEvent, added these two cases to reflect those changes.
This commit is contained in:
Matt 2018-12-16 19:02:26 -06:00 committed by Lilis Iskandar
parent 135df934c7
commit b9da832c23
1 changed files with 9 additions and 11 deletions

View File

@ -61,18 +61,16 @@ func run() int {
case *sdl.JoyHatEvent: case *sdl.JoyHatEvent:
fmt.Printf("[%d ms] JoyHat\ttype:%d\twhich:%d\that:%d\tvalue:%d\n", fmt.Printf("[%d ms] JoyHat\ttype:%d\twhich:%d\that:%d\tvalue:%d\n",
t.Timestamp, t.Type, t.Which, t.Hat, t.Value) t.Timestamp, t.Type, t.Which, t.Hat, t.Value)
case *sdl.JoyDeviceEvent: case *sdl.JoyDeviceAddedEvent:
if t.Type == sdl.JOYDEVICEADDED {
joysticks[int(t.Which)] = sdl.JoystickOpen(t.Which) joysticks[int(t.Which)] = sdl.JoystickOpen(t.Which)
if joysticks[int(t.Which)] != nil { if joysticks[int(t.Which)] != nil {
fmt.Printf("Joystick %d connected\n", t.Which) fmt.Printf("Joystick %d connected\n", t.Which)
} }
} else if t.Type == sdl.JOYDEVICEREMOVED { case *sdl.JoyDeviceRemovedEvent:
if joystick := joysticks[int(t.Which)]; joystick != nil { if joystick := joysticks[int(t.Which)]; joystick != nil {
joystick.Close() joystick.Close()
} }
fmt.Printf("Joystick %d disconnected\n", t.Which) fmt.Printf("Joystick %d disconnected\n", t.Which)
}
default: default:
fmt.Printf("Some event\n") fmt.Printf("Some event\n")
} }