-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputmanager.js
2 lines (2 loc) · 3.39 KB
/
inputmanager.js
1
2
var gdjs;(function(n){const o=class{constructor(){this._lastPressedKey=0;this._mouseX=0;this._mouseY=0;this._mouseWheelDelta=0;this._startedTouches=[];this._endedTouches=[];this._touchSimulateMouse=!0;this._pressedKeys=new Hashtable,this._releasedKeys=new Hashtable,this._pressedMouseButtons=new Array(5),this._releasedMouseButtons=new Array(5),this._touches=new Hashtable}_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=this._getLocationAwareKeyCode(e,s);this._pressedKeys.put(t,!0),this._lastPressedKey=t}onKeyReleased(e,s){const t=this._getLocationAwareKeyCode(e,s);this._pressedKeys.put(t,!1),this._releasedKeys.put(t,!0)}getLastPressedKey(){return this._lastPressedKey}isKeyPressed(e){return this._pressedKeys.containsKey(e)&&this._pressedKeys.get(e)}wasKeyReleased(e){return this._releasedKeys.containsKey(e)&&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}onMouseMove(e,s){this._mouseX=e,this._mouseY=s}getMouseX(){return this._mouseX}getMouseY(){return this._mouseY}onMouseButtonPressed(e){this._pressedMouseButtons[e]=!0,this._releasedMouseButtons[e]=!1}onMouseButtonReleased(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){this._mouseWheelDelta=e}getMouseWheelDelta(){return this._mouseWheelDelta}getTouchX(e){return this._touches.containsKey(e)?this._touches.get(e).x:0}getTouchY(e){return this._touches.containsKey(e)?this._touches.get(e).y:0}getAllTouchIdentifiers(){o._allTouchIds.length=0;for(const e in this._touches.items)this._touches.items.hasOwnProperty(e)&&o._allTouchIds.push(parseInt(e,10));return o._allTouchIds}onTouchStart(e,s,t){this._startedTouches.push(e),this._touches.put(e,{x:s,y:t,justEnded:!1}),this._touchSimulateMouse&&(this.onMouseMove(s,t),this.onMouseButtonPressed(o.MOUSE_LEFT_BUTTON))}onTouchMove(e,s,t){const r=this._touches.get(e);!r||(r.x=s,r.y=t,this._touchSimulateMouse&&this.onMouseMove(s,t))}onTouchEnd(e){this._endedTouches.push(e),this._touches.containsKey(e)&&(this._touches.get(e).justEnded=!0),this._touchSimulateMouse&&this.onMouseButtonReleased(o.MOUSE_LEFT_BUTTON)}getStartedTouchIdentifiers(){return this._startedTouches}popStartedTouch(){return this._startedTouches.shift()}popEndedTouch(){return this._endedTouches.shift()}touchSimulateMouse(e){e===void 0&&(e=!0),this._touchSimulateMouse=e}onFrameEnded(){for(const e in this._touches.items)this._touches.items.hasOwnProperty(e)&&this._touches.items[e].justEnded&&this._touches.remove(e);this._startedTouches.length=0,this._endedTouches.length=0,this._releasedKeys.clear(),this._releasedMouseButtons.length=0,this._mouseWheelDelta=0}isScrollingUp(){return this.getMouseWheelDelta()>0}isScrollingDown(){return this.getMouseWheelDelta()<0}};let u=o;u.MOUSE_LEFT_BUTTON=0,u.MOUSE_RIGHT_BUTTON=1,u.MOUSE_MIDDLE_BUTTON=2,u._DEFAULT_LEFT_VARIANT_KEYS=[16,17,18,91],u._allTouchIds=[],n.InputManager=u})(gdjs||(gdjs={}));
//# sourceMappingURL=inputmanager.js.map