UNPKG

duckengine

Version:
97 lines (96 loc) 2.8 kB
import Game from '../../game'; import Scene from '../../scene'; import KeyboardInput from '../keyboardInput'; /** * @class Key * @classdesc Creates a DuckEngine Key * @description The Key Class. Stores info about a key's state * @since 2.0.0 */ export default class Key { /** * @memberof Key * @description The keyCode * @type number * @since 2.0.0 */ keyCode: number; /** * @memberof Key * @description The Key descriptor * @type string * @since 2.0.0 */ descriptor: string; /** * @memberof Key * @description Game instance * @type Game * @since 2.0.0 */ game: Game; /** * @memberof Key * @description Scene instance * @type Scene * @since 2.0.0 */ scene: Scene; /** * @memberof Key * @description The KeyboardInput that the key is attached to * @type KeyboardInput * @since 2.0.0 */ keyboardInput: KeyboardInput; /** * @memberof Key * @description Key down state * @type boolean * @since 2.0.0 */ isDown: boolean; /** * @memberof Key * @description Key up state * @type boolean * @since 2.0.0 */ isUp: boolean; /** * @memberof Key * @description Key just pressed state * @type boolean * @since 2.0.0 */ isJustPressed: boolean; /** * @memberof Key * @description Key basic state of up or down, up being false, down being true * @type boolean * @since 2.0.0 */ state: boolean; /** * @constructor Key * @description Creates a Key instance * @param {number} keyCode The Key keyCode * @param {string} descriptor The Key descriptor, used to set the value to KeyboardInput.keys * @param {Game} game Game instance * @param {Scene} scene Scene instance * @param { (e:KeyboardEvent) => any } [keyDown] Key Down callback * @param { (e:KeyboardEvent) => any } [keyUp] Key Up callback * @param { (e:KeyboardEvent) => any } [keyJustPressed] Key Just Pressed callback * @param { (e:KeyboardEvent) => any } [keyState] Key State callback * @since 2.0.0 */ constructor(keyCode: number, descriptor: string, game: Game, scene: Scene, keyboardInput: KeyboardInput, keyDown?: (e: KeyboardEvent) => any, keyUp?: (e: KeyboardEvent) => any, keyJustPressed?: (e: KeyboardEvent) => any, keyState?: (e: KeyboardEvent, state: boolean) => any); protected registerListeners(): void; /** * @memberof Key * @description Creates on event on event emitter to listen for input * @param {(key:Key, e:KeyboardEvent) => any} cb Callback to call on input * @since 2.0.0 */ onInput(cb: (key: Key, e: KeyboardEvent) => any): void; }