phaser3-rex-plugins
Version:
2 lines (1 loc) • 12.3 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).rexboundsplugin=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 i(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(s=n.key,r=void 0,"symbol"==typeof(r=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(s,"string"))?r:String(r)),n);}var s,r;}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(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&&o(t,e);}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(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 h(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 i,n=r(t);if(e){var s=r(this).constructor;i=Reflect.construct(n,arguments,s);}else i=n.apply(this,arguments);return u(this,i)}}function a(){return a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=r(t)););return t}(t,e);if(n){var s=Object.getOwnPropertyDescriptor(n,e);return s.get?s.get.call(arguments.length<3?t:i):s.value}},a.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):[]}},f=Phaser.Scene,l=function(t){return t instanceof f},v=Phaser.Game,y=function(t){return t instanceof v},p=Phaser.Utils.Objects.GetValue,d=function(){function i(t,n){e(this,i),this.setParent(t),this.isShutdown=!1,this.setEventEmitter(p(n,"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 n(i,[{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 i;return this.parent=e,this.scene=null==(i=e)||"object"!==t(i)?null:l(i)?i:i.scene&&l(i.scene)?i.scene:i.parent&&i.parent.scene&&l(i.parent.scene)?i.parent.scene:null,this.game=function(e){return null==e||"object"!==t(e)?null:y(e)?e:y(e.game)?e.game:l(e)?e.sys.game:l(e.scene)?e.scene.sys.game:void 0}(e),this}}]),i}();Object.assign(d.prototype,c);var m=Phaser.Utils.Objects.GetValue,g=function(t){s(o,t);var i=h(o);function o(t,n){var s;return e(this,o),(s=i.call(this,t,n))._isRunning=!1,s.isPaused=!1,s.tickingState=!1,s.setTickingMode(m(n,"tickingMode",1)),s}return n(o,[{key:"boot",value:function(){2!==this.tickingMode||this.tickingState||this.startTicking();}},{key:"shutdown",value:function(t){this.isShutdown||(this.stop(),this.tickingState&&this.stopTicking(),a(r(o.prototype),"shutdown",this).call(this,t));}},{key:"setTickingMode",value:function(t){"string"==typeof t&&(t=b[t]),this.tickingMode=t;}},{key:"startTicking",value:function(){this.tickingState=!0;}},{key:"stopTicking",value:function(){this.tickingState=!1;}},{key:"isRunning",get:function(){return this._isRunning},set:function(t){this._isRunning!==t&&(this._isRunning=t,1===this.tickingMode&&t!=this.tickingState&&(t?this.startTicking():this.stopTicking()));}},{key:"start",value:function(){return this.isPaused=!1,this.isRunning=!0,this}},{key:"pause",value:function(){return this.isRunning&&(this.isPaused=!0,this.isRunning=!1),this}},{key:"resume",value:function(){return this.isPaused&&(this.isRunning=!0),this}},{key:"stop",value:function(){return this.isPaused=!1,this.isRunning=!1,this}},{key:"complete",value:function(){this.isPaused=!1,this.isRunning=!1,this.emit("complete",this.parent,this);}}]),o}(d),b={no:0,lazy:1,always:2},E=Phaser.Utils.Objects.GetValue,k=function(t){s(o,t);var i=h(o);function o(t,n){var s;e(this,o);var r=(s=i.call(this,t,n)).scene?"update":"step";return s.tickEventName=E(n,"tickEventName",r),s.isSceneTicker=!w(s.tickEventName),s}return n(o,[{key:"startTicking",value:function(){a(r(o.prototype),"startTicking",this).call(this),this.isSceneTicker?this.scene.sys.events.on(this.tickEventName,this.update,this):this.game.events.on(this.tickEventName,this.update,this);}},{key:"stopTicking",value:function(){a(r(o.prototype),"stopTicking",this).call(this),this.isSceneTicker&&this.scene?this.scene.sys.events.off(this.tickEventName,this.update,this):this.game&&this.game.events.off(this.tickEventName,this.update,this);}}]),o}(g),w=function(t){return "step"===t||"poststep"===t},_=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},P=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height},x=Phaser.Geom.Rectangle,T=Phaser.Math.Vector2,R=Phaser.Math.RotateAround,O=function(t,e){if(void 0===e?e=new x:!0===e&&(void 0===S&&(S=new x),e=S),t.getBounds)return t.getBounds(e);var i,n,s,r,o,u,h,a;if(t.parentContainer){var c=t.parentContainer.getBoundsTransformMatrix();j(t,e),c.transformPoint(e.x,e.y,e),i=e.x,n=e.y,H(t,e),c.transformPoint(e.x,e.y,e),s=e.x,r=e.y,M(t,e),c.transformPoint(e.x,e.y,e),o=e.x,u=e.y,B(t,e),c.transformPoint(e.x,e.y,e),h=e.x,a=e.y;}else j(t,e),i=e.x,n=e.y,H(t,e),s=e.x,r=e.y,M(t,e),o=e.x,u=e.y,B(t,e),h=e.x,a=e.y;return e.x=Math.min(i,s,o,h),e.y=Math.min(n,r,u,a),e.width=Math.max(i,s,o,h)-e.x,e.height=Math.max(n,r,u,a)-e.y,e},S=void 0,j=function(t,e,i){return void 0===e?e=new T:!0===e&&(void 0===N&&(N=new T),e=N),t.getTopLeft?t.getTopLeft(e):(e.x=t.x-_(t)*t.originX,e.y=t.y-P(t)*t.originY,L(t,e,i))},H=function(t,e,i){return void 0===e?e=new T:!0===e&&(void 0===N&&(N=new T),e=N),t.getTopRight?t.getTopRight(e):(e.x=t.x-_(t)*t.originX+_(t),e.y=t.y-P(t)*t.originY,L(t,e,i))},M=function(t,e,i){return void 0===e?e=new T:!0===e&&(void 0===N&&(N=new T),e=N),t.getBottomLeft?t.getBottomLeft(e):(e.x=t.x-_(t)*t.originX,e.y=t.y-P(t)*t.originY+P(t),L(t,e,i))},B=function(t,e,i){return void 0===e?e=new T:!0===e&&(void 0===N&&(N=new T),e=N),t.getBottomRight?t.getBottomRight(e):(e.x=t.x-_(t)*t.originX+_(t),e.y=t.y-P(t)*t.originY+P(t),L(t,e,i))},N=void 0,L=function(t,e,i){(void 0===i&&(i=!1),0!==t.rotation&&R(e,t.x,t.y,t.rotation),i&&t.parentContainer)&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e);return e},A=Phaser.Geom.Rectangle,D=Phaser.Utils.Objects.GetValue,C=function(t){s(o,t);var i=h(o);function o(t,n){var s;return e(this,o),void 0===n&&(n={}),n.tickEventName="postupdate",(s=i.call(this,t,n)).bounds=new A,s.boundsTarget=void 0,s.boundsEnable={},s.clearHitResult(),s.resetFromJSON(n),s}return n(o,[{key:"resetFromJSON",value:function(t){var e=D(t,"target");return e?this.setBoundsTarget(e):(this.setBoundsTarget(),this.setBounds(D(t,"bounds"))),this.setEnable(D(t,"enable",!0)),this.setAlignMode(D(t,"alignMode",0)),this}},{key:"shutdown",value:function(t){this.isShutdown||a(r(o.prototype),"shutdown",this).call(this,t);}},{key:"setBoundsTarget",value:function(t){return this.boundsTarget=t,this}},{key:"setBounds",value:function(t){if(!t)return this;var e=this.bounds;return e.setSize(D(t,"width",0),D(t,"height",0)),t.hasOwnProperty("centerX")?e.centerX=t.centerX:e.x=D(t,"x",0),t.hasOwnProperty("centerY")?e.centerY=t.centerY:e.y=D(t,"y",0),this}},{key:"setEnable",value:function(t){void 0===t&&(t=!0);var e=this.boundsEnable;return "boolean"==typeof t?(e.left=t,e.right=t,e.top=t,e.bottom=t):(e.left=D(t,"left",!1),e.right=D(t,"right",!1),e.top=D(t,"top",!1),e.bottom=D(t,"bottom",!1)),this.isRunning=this.enable,this}},{key:"setAlignMode",value:function(t){return "string"==typeof t&&(t=G[t]),this.alignMode=t,this}},{key:"enable",get:function(){var t=this.boundsEnable;return t.left||t.right||t.top||t.bottom},set:function(t){this.setEnable(t);}},{key:"update",value:function(t,e){var i=this.parent;if(this.clearHitResult(),!this.enable)return this;var n=this.boundsTarget;n&&O(n,this.bounds);var s=this.bounds,r=this.boundsEnable,o=0===this.alignMode,u=o?O(i,!0):void 0;if(r.left){var h=o?u.left:i.x;(a=s.left-h)>0&&(i.x+=a,this.isHitAny=!0,this.isHitLeft=!0,this.emit("hitleft",this.parent,this));}if(r.right){var a,c=o?u.right:i.x;(a=s.right-c)<0&&(i.x+=a,this.isHitAny=!0,this.isHitRight=!0,this.emit("hitright",this.parent,this));}if(r.top){var f=o?u.top:i.y;(l=s.top-f)>0&&(i.y+=l,this.isHitAny=!0,this.isHitTop=!0,this.emit("hittop",this.parent,this));}if(r.bottom){var l,v=o?u.bottom:i.y;(l=s.bottom-v)<0&&(i.y+=l,this.isHitAny=!0,this.isHitBottom=!0,this.emit("hitbottom",this.parent,this));}this.isHitAny&&this.emit("hitany",this.parent,this);}},{key:"clearHitResult",value:function(){return this.isHitAny=!1,this.isHitLeft=!1,this.isHitRight=!1,this.isHitTop=!1,this.isHitBottom=!1,this}}]),o}(k),G={bounds:0,origin:1};return function(t){s(r,Phaser.Plugins.BasePlugin);var i=h(r);function r(t){return e(this,r),i.call(this,t)}return n(r,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e){return new C(t,e)}}]),r}()}));