import { ControlScheme } from './controlScheme.type'; import { Keys } from './keys.enum'; /** * Core InputManager; utilised by the Game to defer the detection and management of user input * * @see Game */ export declare class InputManager { readonly controlScheme: ControlScheme; /** Buffer for user keypresses */ private readonly keyBuffer; /** Boolean indicating whether or not the left mouse button is currently down */ private mousePressed; /** Current position of the mouse within the window */ private mousePos; /** Position of last user click */ private clickPos; /** Position of last user double click */ private dblClickPos; /** Position of last user context click */ private contextClickPos; /** Keys to ignore in the handling of keyboard input */ private readonly ignoreKeys; /** * HTML Canvas */ private canvas; /** * The set of input handling methods, properly bound, useful in setting up and in tearing down */ private readonly boundHandlers; /** * Constructor. Initialise event handlers as appropriate based on the controlScheme * * @param canvas the HTML Canvas to register events upon * @param controlScheme the ControlScheme given to the Game's Config, used for optimising event registration and handling */ constructor(canvas: HTMLCanvasElement, controlScheme: ControlScheme); /** * Check if a given Key code is currently pressed by checking its presence within the keyBuffer * * @param code the Key code to check * * @returns a boolean indicating whether or not the key is pressed */ isKeyDown(code: Keys): boolean; /** * Check if the mouse is down * * @returns a boolean indicating whether or not the mouse is pressed */ isMouseDown(): boolean; /** * Tear down event handlers; called as part of Game destroy() */ destroy(): void; /** * keydown event handler. Add the Key pressed to the keyBuffer, if it's not ignored * * @param event the KeyboardEvent */ private onKeyDown; /** * keydown event handler. Remove the key pressed from the keyBuffer, if it's not ignored * * @param event the KeyboardEvent */ private onKeyUp; /** * mousedown event handler. Set the isMouseDown boolean */ private onMouseDown; /** * mouseup event handler. Set the isMouseDown boolean */ private onMouseUp; /** * click event handler. Set the last click position * * @param event the MouseEvent */ private onClick; /** * contextmenu event handler. Set the last context click posiiton * * @param event the MouseEvent */ private onContextMenu; /** * dblclick event handler. Set the last double click posiiton * * @param event the MouseEvent */ private onDoubleClick; /** * mousemove event handler. Set the current mouse position * * @param event the MouseEvent */ private onMouseMove; /** * Initialize keyboard event handling * * // TODO register on Canvas directly? */ private setupKeyboard; /** * Tear down keyboard event handling */ private tearDownKeyboard; /** * Initialize mouse event handling on the Canvas * * @param canvas the Canvas to register events upon */ private setupMouse; /** * Tear down mouse event handling * * @param canvas the Canvas to deregister events from */ private tearDownMouse; }