Files

3 lines
6.2 KiB
JavaScript
Raw Permalink Normal View History

2026-07-28 10:47:32 -04:00
var gdjs;(function(n){const o=class{constructor(){this._lastPressedKey=0;this._cursorX=0;this._cursorY=0;this._mouseX=0;this._mouseY=0;this._isMouseInsideCanvas=!0;this._wheelDeltaX=0;this._wheelDeltaY=0;this._wheelDeltaZ=0;this._mouseMovementX=0;this._mouseMovementY=0;this._touches={firstKey:()=>{for(const e in this._mouseOrTouches.items)if(e!=="1")return e;return null}};this._startedTouches=[];this._endedTouches=[];this._touchSimulateMouse=!0;this._lastStartedTouchIndex=0;this._lastEndedTouchIndex=0;this._pressedKeys=new Hashtable,this._justPressedKeys=new Hashtable,this._releasedKeys=new Hashtable,this._pressedMouseButtons=new Array(5),this._releasedMouseButtons=new Array(5),this._mouseOrTouches=new Hashtable}static getLocationAwareKeyCode(e,s){return s?96<=e&&e<=105?e:e+1e3*s:o._DEFAULT_LEFT_VARIANT_KEYS.indexOf(e)!==-1?e+1e3:e}onKeyPressed(e,s){const t=o.getLocationAwareKeyCode(e,s);this._pressedKeys.put(t,!0),this._justPressedKeys.put(t,!0),this._lastPressedKey=t}onKeyReleased(e,s){const t=o.getLocationAwareKeyCode(e,s);this._pressedKeys.put(t,!1),this._justPressedKeys.put(t,!1),this._releasedKeys.put(t,!0)}releaseAllPressedKeys(){for(const e in this._pressedKeys.items)this._pressedKeys.put(e,!1),this._justPressedKeys.put(e,!1),this._releasedKeys.put(e,!0)}clearAllPressedKeys(){this._pressedKeys.clear(),this._justPressedKeys.clear()}getLastPressedKey(){return this._lastPressedKey}isKeyPressed(e){return!!this._pressedKeys.get(e)}wasKeyJustPressed(e){return!!this._justPressedKeys.get(e)}wasKeyReleased(e){return!!this._releasedKeys.get(e)}anyKeyPressed(){for(const e in this._pressedKeys.items)if(this._pressedKeys.items.hasOwnProperty(e)&&this._pressedKeys.items[e])return!0;return!1}anyKeyReleased(){for(const e in this._releasedKeys.items)if(this._releasedKeys.items.hasOwnProperty(e)&&this._releasedKeys.items[e])return!0;return!1}exceptionallyGetAllJustPressedKeys(){const e=[];return this._justPressedKeys.keys(e),e.map(s=>parseInt(s,10))}onMouseMove(e,s,t){if(this._setCursorPosition(e,s),this._mouseX=e,this._mouseY=s,t){const{movementX:u,movementY:i}=t;u!==void 0&&(this._mouseMovementX+=u),i!==void 0&&(this._mouseMovementY+=i)}this.isMouseButtonPressed(o.MOUSE_LEFT_BUTTON)&&this._moveTouch(o.MOUSE_TOUCH_ID,this.getCursorX(),this.getCursorY())}_setCursorPosition(e,s){this._cursorX=e,this._cursorY=s}getCursorX(){return this._cursorX}getCursorY(){return this._cursorY}getMouseX(){return this._mouseX}getMouseY(){return this._mouseY}getMouseMovementX(){return this._mouseMovementX}getMouseMovementY(){return this._mouseMovementY}onMouseLeave(){this._isMouseInsideCanvas=!1}onMouseEnter(){this._isMouseInsideCanvas=!0}isMouseInsideCanvas(){return this._isMouseInsideCanvas}onMouseButtonPressed(e){this._setMouseButtonPressed(e),e===o.MOUSE_LEFT_BUTTON&&this._addTouch(o.MOUSE_TOUCH_ID,this.getCursorX(),this.getCursorY())}anyMouseButtonPressed(){for(const e in this._pressedMouseButtons)if(this._pressedMouseButtons[e])return!0;return!1}_setMouseButtonPressed(e){this._pressedMouseButtons[e]=!0,this._releasedMouseButtons[e]=!1}onMouseButtonReleased(e){this._setMouseButtonReleased(e),e===o.MOUSE_LEFT_BUTTON&&this._removeTouch(o.MOUSE_TOUCH_ID)}_setMouseButtonReleased(e){this._pressedMouseButtons[e]=!1,this._releasedMouseButtons[e]=!0}isMouseButtonPressed(e){return this._pressedMouseButtons[e]!==void 0&&this._pressedMouseButtons[e]}isMouseButtonReleased(e){return this._releasedMouseButtons[e]!==void 0&&this._releasedMouseButtons[e]}onMouseWheel(e,s,t){this._wheelDeltaY=e,s!==void 0&&(this._wheelDeltaX=s),t!==void 0&&(this._wheelDeltaZ=t)}getMouseWheelDelta(){return this._wheelDeltaY}getMouseWheelDeltaX(){return this._wheelDeltaX}getMouseWheelDeltaZ(){return this._wheelDeltaZ}getTouchX(e){return this._mouseOrTouches.containsKey(e)?this._mouseOrTouches.get(e).x:0}getTouchY(e){return this._mouseOrTouches.containsKey(e)?this._mouseOrTouches.get(e).y:0}hasTouchEnded(e){return this._mouseOrTouches.containsKey(e)?this._mouseOrTouches.get(e).justEnded:!1}getAllTouchIdentifiers(){o._allTouchIds.length=0;for(const e in this._mouseOrTouches.items)t
//# sourceMappingURL=inputmanager.js.map