31
31
32
32
from .driver import InputDriver
33
33
34
+ # Needed for Python 3.11 compatibility,
35
+ # as "int() in MyIntEnumSubclass" wasn't available until Python 3.12
36
+ _DEVICEID_ANALOG_MEMBERS = DeviceIdAnalog .__members__ .values ()
37
+ _DEVICEID_JOYPAD_MEMBERS = DeviceIdJoypad .__members__ .values ()
38
+ _DEVICEID_LIGHTGUN_MEMBERS = DeviceIdLightgun .__members__ .values ()
39
+ _DEVICEID_MOUSE_MEMBERS = DeviceIdMouse .__members__ .values ()
40
+ _KEY_MEMBERS = Key .__members__ .values ()
41
+
34
42
35
43
@dataclass (order = True , slots = True )
36
44
class Point :
@@ -279,7 +287,7 @@ def _lookup_port_state(
279
287
InputDevice .JOYPAD ,
280
288
_,
281
289
id ,
282
- ) if id in DeviceIdJoypad :
290
+ ) if id in _DEVICEID_JOYPAD_MEMBERS :
283
291
# When asking for a specific joypad button,
284
292
# return 1 (True) if its pressed and 0 (False) if not
285
293
# NOTE: id in DeviceInJoypad is perfectly valid
@@ -327,15 +335,15 @@ def _lookup_port_state(
327
335
InputDevice .ANALOG ,
328
336
DeviceIndexAnalog .LEFT ,
329
337
id ,
330
- ) if ( id in DeviceIdAnalog ) :
338
+ ) if id in _DEVICEID_ANALOG_MEMBERS :
331
339
analog_state : AnalogState
332
340
return analog_state .lstick [id ]
333
341
case (
334
342
AnalogState () as analog_state ,
335
343
InputDevice .ANALOG ,
336
344
DeviceIndexAnalog .RIGHT ,
337
345
id ,
338
- ) if ( id in DeviceIdAnalog ) :
346
+ ) if id in _DEVICEID_ANALOG_MEMBERS :
339
347
analog_state : AnalogState
340
348
return analog_state .rstick [id ]
341
349
case AnalogState (), _, _, _:
@@ -349,7 +357,7 @@ def _lookup_port_state(
349
357
InputDevice .MOUSE ,
350
358
_,
351
359
id ,
352
- ) if id in DeviceIdMouse :
360
+ ) if id in _DEVICEID_MOUSE_MEMBERS :
353
361
# When asking for a specific mouse button,
354
362
# return 1 (True) if its pressed and 0 (False) if not
355
363
mouse_state : MouseState
@@ -382,7 +390,7 @@ def _lookup_port_state(
382
390
InputDevice .KEYBOARD ,
383
391
_,
384
392
id ,
385
- ) if id in Key :
393
+ ) if id in _KEY_MEMBERS :
386
394
# KeyboardState overloads __getitem__ to return True for pressed keys
387
395
# and False for unpressed or invalid keys.
388
396
return keyboard_state [id ]
@@ -391,7 +399,7 @@ def _lookup_port_state(
391
399
return 0
392
400
393
401
# Yielding a Key value will expose it as a key press on the keyboard device.
394
- case Key (key ), InputDevice .KEYBOARD , _, id if key == id and id in Key :
402
+ case Key (key ), InputDevice .KEYBOARD , _, id if key == id and id in _KEY_MEMBERS :
395
403
return 1
396
404
case Key (_), _, _, _: # When yielding a Key in all other cases, return 0
397
405
return 0
@@ -400,7 +408,7 @@ def _lookup_port_state(
400
408
# with all other devices defaulting to 0.
401
409
# Index is ignored.
402
410
case LightGunState () as light_gun_state , InputDevice .LIGHTGUN , _, id if (
403
- id in DeviceIdLightgun
411
+ id in _DEVICEID_LIGHTGUN_MEMBERS
404
412
):
405
413
light_gun_state : LightGunState
406
414
return light_gun_state [id ]
0 commit comments