webDeviceInputSystem.d.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import type { AbstractEngine } from "../Engines/abstractEngine";
  2. import type { IUIEvent } from "../Events/deviceInputEvents";
  3. import { DeviceType } from "./InputDevices/deviceEnums";
  4. import type { IDeviceInputSystem } from "./inputInterfaces";
  5. /** @internal */
  6. export declare class WebDeviceInputSystem implements IDeviceInputSystem {
  7. private _inputs;
  8. private _gamepads;
  9. private _keyboardActive;
  10. private _pointerActive;
  11. private _elementToAttachTo;
  12. private _metaKeys;
  13. private readonly _engine;
  14. private readonly _usingSafari;
  15. private readonly _usingMacOS;
  16. private _onDeviceConnected;
  17. private _onDeviceDisconnected;
  18. private _onInputChanged;
  19. private _keyboardDownEvent;
  20. private _keyboardUpEvent;
  21. private _keyboardBlurEvent;
  22. private _pointerMoveEvent;
  23. private _pointerDownEvent;
  24. private _pointerUpEvent;
  25. private _pointerCancelEvent;
  26. private _pointerWheelEvent;
  27. private _pointerBlurEvent;
  28. private _pointerMacOSChromeOutEvent;
  29. private _wheelEventName;
  30. private _eventsAttached;
  31. private _mouseId;
  32. private readonly _isUsingFirefox;
  33. private readonly _isUsingChromium;
  34. private _activeTouchIds;
  35. private _maxTouchPoints;
  36. private _pointerInputClearObserver;
  37. private _gamepadConnectedEvent;
  38. private _gamepadDisconnectedEvent;
  39. private _eventPrefix;
  40. /**
  41. * Constructor for the WebDeviceInputSystem
  42. * @param engine Engine to reference
  43. * @param onDeviceConnected Callback to execute when device is connected
  44. * @param onDeviceDisconnected Callback to execute when device is disconnected
  45. * @param onInputChanged Callback to execute when input changes on device
  46. */
  47. constructor(engine: AbstractEngine, onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => void, onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => void, onInputChanged: (deviceType: DeviceType, deviceSlot: number, eventData: IUIEvent) => void);
  48. /**
  49. * Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.
  50. * @param deviceType Enum specifying device type
  51. * @param deviceSlot "Slot" or index that device is referenced in
  52. * @param inputIndex Id of input to be checked
  53. * @returns Current value of input
  54. */
  55. pollInput(deviceType: DeviceType, deviceSlot: number, inputIndex: number): number;
  56. /**
  57. * Check for a specific device in the DeviceInputSystem
  58. * @param deviceType Type of device to check for
  59. * @returns bool with status of device's existence
  60. */
  61. isDeviceAvailable(deviceType: DeviceType): boolean;
  62. /**
  63. * Dispose of all the eventlisteners
  64. */
  65. dispose(): void;
  66. /**
  67. * Enable listening for user input events
  68. */
  69. private _enableEvents;
  70. /**
  71. * Disable listening for user input events
  72. */
  73. private _disableEvents;
  74. /**
  75. * Checks for existing connections to devices and register them, if necessary
  76. * Currently handles gamepads and mouse
  77. */
  78. private _checkForConnectedDevices;
  79. /**
  80. * Add a gamepad to the DeviceInputSystem
  81. * @param gamepad A single DOM Gamepad object
  82. */
  83. private _addGamePad;
  84. /**
  85. * Add pointer device to DeviceInputSystem
  86. * @param deviceType Type of Pointer to add
  87. * @param deviceSlot Pointer ID (0 for mouse, pointerId for Touch)
  88. * @param currentX Current X at point of adding
  89. * @param currentY Current Y at point of adding
  90. */
  91. private _addPointerDevice;
  92. /**
  93. * Add device and inputs to device array
  94. * @param deviceType Enum specifying device type
  95. * @param deviceSlot "Slot" or index that device is referenced in
  96. * @param numberOfInputs Number of input entries to create for given device
  97. */
  98. private _registerDevice;
  99. /**
  100. * Given a specific device name, remove that device from the device map
  101. * @param deviceType Enum specifying device type
  102. * @param deviceSlot "Slot" or index that device is referenced in
  103. */
  104. private _unregisterDevice;
  105. /**
  106. * Handle all actions that come from keyboard interaction
  107. */
  108. private _handleKeyActions;
  109. /**
  110. * Handle all actions that come from pointer interaction
  111. */
  112. private _handlePointerActions;
  113. /**
  114. * Handle all actions that come from gamepad interaction
  115. */
  116. private _handleGamepadActions;
  117. /**
  118. * Update all non-event based devices with each frame
  119. * @param deviceType Enum specifying device type
  120. * @param deviceSlot "Slot" or index that device is referenced in
  121. * @param inputIndex Id of input to be checked
  122. */
  123. private _updateDevice;
  124. /**
  125. * Gets DeviceType from the device name
  126. * @param deviceName Name of Device from DeviceInputSystem
  127. * @returns DeviceType enum value
  128. */
  129. private _getGamepadDeviceType;
  130. /**
  131. * Get DeviceType from a given pointer/mouse/touch event.
  132. * @param evt PointerEvent to evaluate
  133. * @returns DeviceType interpreted from event
  134. */
  135. private _getPointerType;
  136. }