123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- /**
- * Key is used by Keyboard, Pointer, etc, to represent a key state.
- *
- * @class
- */
- function Key()
- {
- /**
- * Indicates if this key is currently pressed.
- *
- * @type {boolean}
- */
- this.pressed = false;
- /**
- * Indicates if this key was just pressed.
- *
- * @type {boolean}
- */
- this.justPressed = false;
-
- /**
- * Indicates if this key was just released.
- *
- * @type {boolean}
- */
- this.justReleased = false;
- }
- /**
- * Key down event.
- *
- * @type {number}
- */
- Key.DOWN = -1;
- /**
- * Key up event.
- *
- * @type {number}
- */
- Key.UP = 1;
- /**
- * Key reset event.
- *
- * @type {number}
- */
- Key.RESET = 0;
- Key.prototype.constructor = Key;
- /**
- * Update Key status based on new key state.
- *
- * @param {number} action Key action that was performed.
- */
- Key.prototype.update = function(action)
- {
- this.justPressed = false;
- this.justReleased = false;
- if(action === Key.DOWN)
- {
- if(this.pressed === false)
- {
- this.justPressed = true;
- }
- this.pressed = true;
- }
- else if(action === Key.UP)
- {
- if(this.pressed)
- {
- this.justReleased = true;
- }
- this.pressed = false;
- }
- else if(action === Key.RESET)
- {
- this.justReleased = false;
- this.justPressed = false;
- }
- };
- /**
- * Set this key attributes manually.
- *
- * @param {boolean} justPressed Indicates if the button was just pressed.
- * @param {boolean} pressed Indicates if the button is currently being pressed.
- * @param {boolean} justReleased Indicates if the button was just released.
- */
- Key.prototype.set = function(justPressed, pressed, justReleased)
- {
- this.justPressed = justPressed;
- this.pressed = pressed;
- this.justReleased = justReleased;
- };
- /**
- * Reset key to default values.
- */
- Key.prototype.reset = function()
- {
- this.justPressed = false;
- this.pressed = false;
- this.justReleased = false;
- };
- export {Key};
|