deviceSource.d.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import type { DeviceType } from "./deviceEnums";
  2. import { Observable } from "../../Misc/observable";
  3. import type { DeviceInput } from "./deviceTypes";
  4. import type { IDeviceInputSystem } from "../inputInterfaces";
  5. import type { IKeyboardEvent, IPointerEvent, IWheelEvent } from "../../Events/deviceInputEvents";
  6. /**
  7. * Subset of DeviceInput that only handles pointers and keyboard
  8. */
  9. export type DeviceSourceEvent<T extends DeviceType> = T extends DeviceType.Keyboard ? IKeyboardEvent : T extends DeviceType.Mouse ? IWheelEvent | IPointerEvent : T extends DeviceType.Touch ? IPointerEvent : never;
  10. /**
  11. * Class that handles all input for a specific device
  12. */
  13. export declare class DeviceSource<T extends DeviceType> {
  14. /** Type of device */
  15. readonly deviceType: T;
  16. /** "Slot" or index that device is referenced in */
  17. readonly deviceSlot: number;
  18. /**
  19. * Observable to handle device input changes per device
  20. */
  21. readonly onInputChangedObservable: Observable<DeviceSourceEvent<T>>;
  22. private readonly _deviceInputSystem;
  23. /**
  24. * Default Constructor
  25. * @param deviceInputSystem - Reference to DeviceInputSystem
  26. * @param deviceType - Type of device
  27. * @param deviceSlot - "Slot" or index that device is referenced in
  28. */
  29. constructor(deviceInputSystem: IDeviceInputSystem,
  30. /** Type of device */
  31. deviceType: T,
  32. /** "Slot" or index that device is referenced in */
  33. deviceSlot?: number);
  34. /**
  35. * Get input for specific input
  36. * @param inputIndex - index of specific input on device
  37. * @returns Input value from DeviceInputSystem
  38. */
  39. getInput(inputIndex: DeviceInput<T>): number;
  40. }