Fix gamepad removal not working properly
This commit is contained in:
@ -19,20 +19,25 @@ public class Input
|
||||
internal func pressEvent(scan: SDL_Scancode, repeat r: Bool) { keyboard.pressEvent(scan: scan, repeat: r) }
|
||||
internal func releaseEvent(scan: SDL_Scancode) { keyboard.releaseEvent(scan: scan) }
|
||||
|
||||
internal func padConnectedEvent(index: Int32)
|
||||
internal func padConnectedEvent(deviceIndex: Int32)
|
||||
{
|
||||
guard let sdlPad = SDL_GameControllerOpen(index)
|
||||
else { return }
|
||||
let id = SDL_JoystickGetDeviceInstanceID(index)
|
||||
_pads[id] = GamePad(pad: sdlPad)
|
||||
print("Using gamepad #\(id), \"\(String(cString: SDL_GameControllerName(sdlPad)))\"")
|
||||
if _firstJoyID < 0 { _firstJoyID = id }
|
||||
if let pad = GamePad.open(device: deviceIndex)
|
||||
{
|
||||
print("Using gamepad #\(pad.instanceID), \"\(pad.name)\"")
|
||||
if _firstJoyID < 0
|
||||
{
|
||||
_firstJoyID = pad.instanceID
|
||||
}
|
||||
_pads[pad.instanceID] = pad
|
||||
}
|
||||
}
|
||||
|
||||
internal func padRemovedEvent(index: Int32)
|
||||
internal func padRemovedEvent(id: Int32)
|
||||
{
|
||||
let id = SDL_JoystickGetDeviceInstanceID(index)
|
||||
_pads.removeValue(forKey: id)
|
||||
if let pad = _pads.removeValue(forKey: id)
|
||||
{
|
||||
pad.close()
|
||||
}
|
||||
if id == _firstJoyID
|
||||
{
|
||||
_firstJoyID = _pads.keys.first ?? -1
|
||||
|
Reference in New Issue
Block a user