UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 5.6 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexcursoratboundplugin=t();}(undefined,(function(){function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,(r=o.key,i=void 0,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(r,"string"))?i:String(i)),o);}var r,i;}function n(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&i(e,t);}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function i(e,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},i(e,t)}function s(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function u(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return !1}}();return function(){var n,o=r(e);if(t){var i=r(this).constructor;n=Reflect.construct(o,arguments,i);}else n=o.apply(this,arguments);return s(this,n)}}function c(){return c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var o=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=r(e)););return e}(e,t);if(o){var i=Object.getOwnPropertyDescriptor(o,t);return i.get?i.get.call(arguments.length<3?e:n):i.value}},c.apply(this,arguments)}var f=Phaser.Input.Keyboard.Key,y=Phaser.Input.Keyboard.KeyCodes,a=function(){function t(n){e(this,t),this.cursorKeys={up:new f(n,y.UP),down:new f(n,y.DOWN),left:new f(n,y.LEFT),right:new f(n,y.RIGHT)},this.noKeyDown=!0;}return n(t,[{key:"shutdown",value:function(e){for(var t in this.cursorKeys)this.cursorKeys[t].destroy();this.cursorKeys=void 0;}},{key:"destroy",value:function(e){shutdown(e);}},{key:"createCursorKeys",value:function(){return this.cursorKeys}},{key:"setKeyState",value:function(e,t){var n=this.cursorKeys[e];return n.enabled?(t&&(this.noKeyDown=!1),n.isDown!==t&&(l.timeStamp=Date.now(),l.keyCode=n.keyCode,t?n.onDown(l):n.onUp(l)),this):this}},{key:"clearAllKeysState",value:function(){for(var e in this.noKeyDown=!0,this.cursorKeys)this.setKeyState(e,!1);return this}},{key:"getKeyState",value:function(e){return this.cursorKeys[e]}},{key:"upKeyDown",get:function(){return this.cursorKeys.up.isDown}},{key:"downKeyDown",get:function(){return this.cursorKeys.down.isDown}},{key:"leftKeyDown",get:function(){return this.cursorKeys.left.isDown}},{key:"rightKeyDown",get:function(){return this.cursorKeys.right.isDown}},{key:"anyKeyDown",get:function(){return !this.noKeyDown}}]),t}(),l={timeStamp:0,keyCode:0,altKey:!1,ctrlKey:!1,shiftKey:!1,metaKey:!1,location:0},h=Phaser.Cameras.Scene2D.BaseCamera,p=Phaser.Geom.Rectangle,d=function(e,t,n){return t instanceof h||(n=t,t=void 0),void 0===n?n=new p:!0===n&&(n=v),t?e.scale.getViewPort(t,n):e.scale.getViewPort(n)},v=new p,w=Phaser.Utils.Objects.GetValue,b=function(t){o(s,t);var i=u(s);function s(t,n){var o;e(this,s),(o=i.call(this,t)).scene=t,o.sensitiveDistance=w(n,"sensitiveDistance",20);var r=w(n,"bounds",void 0);return void 0===r&&(r=d(t)),o.bounds=r,o.boot(),o}return n(s,[{key:"boot",value:function(){this.scene.input.on("pointermove",this.onPointerMove,this),this.scene.sys.events.once("shutdown",this.destroy,this);}},{key:"shutdown",value:function(){this.scene&&(this.scene.input.off("pointermove",this.onPointerMove,this),this.scene.sys.events.off("shutdown",this.destroy,this),this.scene=void 0,c(r(s.prototype),"shutdown",this).call(this));}},{key:"destroy",value:function(){this.shutdown();}},{key:"onPointerMove",value:function(e){var t=e.x,n=e.y,o=this.bounds.left,r=this.bounds.right,i=this.bounds.top,s=this.bounds.bottom,u=this.sensitiveDistance,c=t>=o&&t<=o+u,f=t<=r&&t>=r-u,y=n>=i&&n<=i+u,a=n<=s&&n>=s-u;this.clearAllKeysState(),this.setKeyState("left",c),this.setKeyState("right",f),this.setKeyState("up",y),this.setKeyState("down",a);}},{key:"up",get:function(){return this.upKeyDown}},{key:"down",get:function(){return this.downKeyDown}},{key:"left",get:function(){return this.leftKeyDown}},{key:"right",get:function(){return this.rightKeyDown}},{key:"noKey",get:function(){return this.noKeyDown}}]),s}(a);return function(t){o(i,Phaser.Plugins.BasePlugin);var r=u(i);function i(t){return e(this,i),r.call(this,t)}return n(i,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(e,t){return new b(e,t)}}]),i}()}));