phaser3-rex-plugins
Version:
2 lines (1 loc) • 11.1 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexclickoutsideplugin=e();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,(r=i.key,o=void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(r,"string"))?o:String(o)),i);}var r,o;}function i(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&s(t,e);}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function u(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function a(t){var e=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(t){return !1}}();return function(){var n,i=o(t);if(e){var r=o(this).constructor;n=Reflect.construct(i,arguments,r);}else n=i.apply(this,arguments);return u(this,n)}}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=o(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(arguments.length<3?t:n):r.value}},h.apply(this,arguments)}var c={setEventEmitter:function(t,e){return void 0===e&&(e=Phaser.Events.EventEmitter),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},l=Phaser.Scene,f=function(t){return t instanceof l},v=Phaser.Game,p=function(t){return t instanceof v},y=Phaser.Utils.Objects.GetValue,d=function(){function n(t,i){e(this,n),this.setParent(t),this.isShutdown=!1,this.setEventEmitter(y(i,"eventEmitter",!0)),this.parent&&(this.parent===this.scene?this.scene.sys.events.once("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.once("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.once("destroy",this.onParentDestroy,this));}return i(n,[{key:"shutdown",value:function(t){this.isShutdown||(this.parent&&(this.parent===this.scene?this.scene.sys.events.off("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.off("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.off("destroy",this.onParentDestroy,this)),this.destroyEventEmitter(),this.parent=void 0,this.scene=void 0,this.game=void 0,this.isShutdown=!0);}},{key:"destroy",value:function(t){this.shutdown(t);}},{key:"onEnvDestroy",value:function(){this.destroy(!0);}},{key:"onParentDestroy",value:function(t,e){this.destroy(e);}},{key:"setParent",value:function(e){var n;return this.parent=e,this.scene=null==(n=e)||"object"!==t(n)?null:f(n)?n:n.scene&&f(n.scene)?n.scene:n.parent&&n.parent.scene&&f(n.parent.scene)?n.parent.scene:null,this.game=function(e){return null==e||"object"!==t(e)?null:p(e)?e:p(e.game)?e.game:f(e)?e.sys.game:f(e.scene)?e.scene.sys.game:void 0}(e),this}}]),n}();Object.assign(d.prototype,c);var m=function(t,e,n,i){if(e)return !(n&&!n(t,e))&&(!!g(t,e)&&!(i&&!i(t,e)));for(var r=t.scene.input.manager,o=r.pointersTotal,s=r.pointers,u=0;u<o;u++)if(e=s[u],(!n||n(t,e))&&g(t,e)&&(!i||i(t,e)))return !0;return !1},g=function(t,e){for(var n=t.scene,i=n.input.cameras.getCamerasBelowPointer(e),r=n.input.manager,o=[t],s=0,u=i.length;s<u;s++)if(r.hitTest(e,o,i[s],E),E.length>0)return E.length=0,!0;return E.length=0,!1},E=[],b=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},w=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height},_=Phaser.Geom.Rectangle,P=Phaser.Math.Vector2,k=Phaser.Math.RotateAround,x=void 0,T=function(t,e,n){return void 0===e?e=new P:!0===e&&(void 0===S&&(S=new P),e=S),t.getTopLeft?t.getTopLeft(e):(e.x=t.x-b(t)*t.originX,e.y=t.y-w(t)*t.originY,C(t,e,n))},O=function(t,e,n){return void 0===e?e=new P:!0===e&&(void 0===S&&(S=new P),e=S),t.getTopRight?t.getTopRight(e):(e.x=t.x-b(t)*t.originX+b(t),e.y=t.y-w(t)*t.originY,C(t,e,n))},j=function(t,e,n){return void 0===e?e=new P:!0===e&&(void 0===S&&(S=new P),e=S),t.getBottomLeft?t.getBottomLeft(e):(e.x=t.x-b(t)*t.originX,e.y=t.y-w(t)*t.originY+w(t),C(t,e,n))},R=function(t,e,n){return void 0===e?e=new P:!0===e&&(void 0===S&&(S=new P),e=S),t.getBottomRight?t.getBottomRight(e):(e.x=t.x-b(t)*t.originX+b(t),e.y=t.y-w(t)*t.originY+w(t),C(t,e,n))},S=void 0,C=function(t,e,n){(void 0===n&&(n=!1),0!==t.rotation&&k(e,t.x,t.y,t.rotation),n&&t.parentContainer)&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e);return e},D=function(t,e,n,i,r){if(!t)return !1;if(i&&!i(t,e,n))return !1;var o=function(t,e){if(void 0===e?e=new _:!0===e&&(void 0===x&&(x=new _),e=x),t.getBounds)return t.getBounds(e);var n,i,r,o,s,u,a,h;if(t.parentContainer){var c=t.parentContainer.getBoundsTransformMatrix();T(t,e),c.transformPoint(e.x,e.y,e),n=e.x,i=e.y,O(t,e),c.transformPoint(e.x,e.y,e),r=e.x,o=e.y,j(t,e),c.transformPoint(e.x,e.y,e),s=e.x,u=e.y,R(t,e),c.transformPoint(e.x,e.y,e),a=e.x,h=e.y;}else T(t,e),n=e.x,i=e.y,O(t,e),r=e.x,o=e.y,j(t,e),s=e.x,u=e.y,R(t,e),a=e.x,h=e.y;return e.x=Math.min(n,r,s,a),e.y=Math.min(i,o,u,h),e.width=Math.max(n,r,s,a)-e.x,e.height=Math.max(i,o,u,h)-e.y,e}(t,!0);return !!o.contains(e,n)&&!(r&&!r(t,e,n))},M=function(t,e,n,i){if(e)return D(t,e.worldX,e.worldY,n,i);for(var r=t.scene.input.manager,o=r.pointersTotal,s=r.pointers,u=0;u<o;u++)if(e=s[u],D(t,e.worldX,e.worldY,n,i))return !0;return !1},B=Phaser.Utils.Objects.GetValue,I=function(t){r(s,t);var n=a(s);function s(t,i){var r;e(this,s),(r=n.call(this,t,i))._enable=void 0;var o=B(i,"inputConfig",void 0);return o&&t.setInteractive(o),r.resetFromJSON(i),r.boot(),r}return i(s,[{key:"resetFromJSON",value:function(t){return this.pointer=void 0,this.lastClickTime=void 0,this.setEnable(B(t,"enable",!0)),this.setMode(B(t,"mode",1)),this.setClickInterval(B(t,"clickInterval",100)),this.setDragThreshold(B(t,"threshold",void 0)),this}},{key:"boot",value:function(){var t=this.parent.scene;t.input.on("pointerdown",this.onPress,this),t.input.on("pointerup",this.onRelease,this),t.input.on("pointermove",this.onMove,this);}},{key:"shutdown",value:function(t){if(!this.isShutdown){var e=this.parent.scene;e.input.off("pointerdown",this.onPress,this),e.input.off("pointerup",this.onRelease,this),e.input.off("pointermove",this.onMove,this),this.pointer=null,h(o(s.prototype),"shutdown",this).call(this,t);}}},{key:"enable",get:function(){return this._enable},set:function(t){if(this._enable!==t){t||this.cancel(),this._enable=t;var e=t?"enable":"disable";this.emit(e,this,this.parent);}}},{key:"setEnable",value:function(t){return void 0===t&&(t=!0),this.enable=t,this}},{key:"toggleEnable",value:function(){return this.setEnable(!this.enable),this}},{key:"setMode",value:function(t){return "string"==typeof t&&(t=L[t]),this.mode=t,this}},{key:"setClickInterval",value:function(t){return this.clickInterval=t,this}},{key:"setDragThreshold",value:function(t){return this.dragThreshold=t,this}},{key:"isPointerInside",value:function(t){var e=this.parent;return (e.input?m:M)(e,t)}},{key:"onPress",value:function(t){this.parent.willRender(t.camera)&&void 0===this.pointer&&(this.pointer=t,0===this.mode&&(this.isPointerInside(t)||this.click(t.downTime,t)));}},{key:"onRelease",value:function(t){this.parent.willRender(t.camera)&&this.pointer===t&&(1===this.mode&&(this.isPointerInside(t)||this.click(t.upTime,t)),this.pointer=void 0);}},{key:"onMove",value:function(t,e,n,i){this.pointer===t&&void 0!==this.dragThreshold&&1===this.mode&&(t.getDistance()>=this.dragThreshold||this.isPointerInside(t))&&this.cancel();}},{key:"click",value:function(t,e){if(!this.enable)return this;if(void 0===t)return this.emit("clickoutside",this,this.parent,e),this;this.pointer=void 0;var n=this.lastClickTime;return void 0!==n&&t-n<=this.clickInterval||(this.lastClickTime=t,this.emit("clickoutside",this,this.parent,e)),this}},{key:"cancel",value:function(){return this.pointer=void 0,this}}]),s}(d),L={press:0,pointerdown:0,release:1,pointerup:1};return function(t){r(o,Phaser.Plugins.BasePlugin);var n=a(o);function o(t){return e(this,o),n.call(this,t)}return i(o,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e){return new I(t,e)}}]),o}()}));