@petkoneo/phaser3-rex-plugins
Version:
2 lines (1 loc) • 9.23 kB
JavaScript
var t,e;t=void 0,e=function(){var t={setEventEmitter(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(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter(){return this._eventEmitter},on(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}};const e=Phaser.Scene;var i=function(t){return t instanceof e};const s=Phaser.Game;var n=function(t){return t instanceof s};const r=Phaser.Utils.Objects.GetValue;class o{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(r(e,"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))}shutdown(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)}destroy(t){this.shutdown(t)}onEnvDestroy(){this.destroy(!0)}onParentDestroy(t,e){this.destroy(e)}setParent(t){var e;return this.parent=t,this.scene=null==(e=t)||"object"!=typeof e?null:i(e)?e:e.scene&&i(e.scene)?e.scene:e.parent&&e.parent.scene&&i(e.parent.scene)?e.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:n(t)?t:n(t.game)?t.game:i(t)?t.sys.game:i(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(o.prototype,t);const h=Phaser.Utils.Objects.GetValue;class a extends o{constructor(t,e){super(t,e),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(h(e,"tickingMode",1))}boot(){2!==this.tickingMode||this.tickingState||this.startTicking()}shutdown(t){this.isShutdown||(this.stop(),this.tickingState&&this.stopTicking(),super.shutdown(t))}setTickingMode(t){"string"==typeof t&&(t=u[t]),this.tickingMode=t}startTicking(){this.tickingState=!0}stopTicking(){this.tickingState=!1}get isRunning(){return this._isRunning}set isRunning(t){this._isRunning!==t&&(this._isRunning=t,1===this.tickingMode&&t!=this.tickingState&&(t?this.startTicking():this.stopTicking()))}start(){return this.isPaused=!1,this.isRunning=!0,this}pause(){return this.isRunning&&(this.isPaused=!0,this.isRunning=!1),this}resume(){return this.isPaused&&(this.isPaused=!1,this.isRunning=!0),this}stop(){return this.isPaused=!1,this.isRunning=!1,this}complete(){this.isPaused=!1,this.isRunning=!1,this.emit("complete",this.parent,this)}}const u={no:0,lazy:1,always:2},d=Phaser.Utils.Objects.GetValue;class c extends a{constructor(t,e){super(t,e);var i=this.scene?"update":"step";this.tickEventName=d(e,"tickEventName",i),this.isSceneTicker=!p(this.tickEventName)}startTicking(){super.startTicking(),this.isSceneTicker?this.scene.sys.events.on(this.tickEventName,this.update,this):this.game.events.on(this.tickEventName,this.update,this)}stopTicking(){super.stopTicking(),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)}}var p=function(t){return"step"===t||"poststep"===t},g=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},m=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height};const v=Phaser.Geom.Rectangle,l=Phaser.Math.Vector2,y=Phaser.Math.RotateAround,f=Phaser.GameObjects.Container;var E=function(t,e){if(void 0===e?e=new v:!0===e&&(void 0===b&&(b=new v),e=b),t.getBounds&&!(t instanceof f))return t.getBounds(e);var i,s,n,r,o,h,a,u;if(t.parentContainer){var d=t.parentContainer.getBoundsTransformMatrix();x(t,e),d.transformPoint(e.x,e.y,e),i=e.x,s=e.y,_(t,e),d.transformPoint(e.x,e.y,e),n=e.x,r=e.y,w(t,e),d.transformPoint(e.x,e.y,e),o=e.x,h=e.y,P(t,e),d.transformPoint(e.x,e.y,e),a=e.x,u=e.y}else x(t,e),i=e.x,s=e.y,_(t,e),n=e.x,r=e.y,w(t,e),o=e.x,h=e.y,P(t,e),a=e.x,u=e.y;return e.x=Math.min(i,n,o,a),e.y=Math.min(s,r,h,u),e.width=Math.max(i,n,o,a)-e.x,e.height=Math.max(s,r,h,u)-e.y,e},b=void 0,x=function(t,e,i){return void 0===e?e=new l:!0===e&&(void 0===k&&(k=new l),e=k),t.getTopLeft?t.getTopLeft(e):(e.x=t.x-g(t)*t.originX,e.y=t.y-m(t)*t.originY,T(t,e,i))},_=function(t,e,i){return void 0===e?e=new l:!0===e&&(void 0===k&&(k=new l),e=k),t.getTopRight?t.getTopRight(e):(e.x=t.x-g(t)*t.originX+g(t),e.y=t.y-m(t)*t.originY,T(t,e,i))},w=function(t,e,i){return void 0===e?e=new l:!0===e&&(void 0===k&&(k=new l),e=k),t.getBottomLeft?t.getBottomLeft(e):(e.x=t.x-g(t)*t.originX,e.y=t.y-m(t)*t.originY+m(t),T(t,e,i))},P=function(t,e,i){return void 0===e?e=new l:!0===e&&(void 0===k&&(k=new l),e=k),t.getBottomRight?t.getBottomRight(e):(e.x=t.x-g(t)*t.originX+g(t),e.y=t.y-m(t)*t.originY+m(t),T(t,e,i))},k=void 0,T=function(t,e,i){return void 0===i&&(i=!1),0!==t.rotation&&y(e,t.x,t.y,t.rotation),i&&t.parentContainer&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e),e};const H=Phaser.Geom.Rectangle,M=Phaser.Utils.Objects.GetValue;class R extends c{constructor(t,e){void 0===e&&(e={}),e.tickEventName="postupdate",super(t,e),this.bounds=new H,this.boundsTarget=void 0,this.boundsEnable={},this.boundsHitMode={},this.clearHitResult(),this.resetFromJSON(e)}resetFromJSON(t){var e=M(t,"target");return e?this.setBoundsTarget(e):(this.setBoundsTarget(),this.setBounds(M(t,"bounds"))),this.setEnable(M(t,"enable",!0)),this.setBoundsHitMode(M(t,"boundsHitMode")),this.setAlignMode(M(t,"alignMode",this.hasWrapBoundHitMode?1:0)),this}shutdown(t){this.isShutdown||super.shutdown(t)}setBoundsTarget(t){return this.boundsTarget=t,this}setBounds(t){if(!t)return this;var e=this.bounds;return e.setSize(M(t,"width",0),M(t,"height",0)),t.hasOwnProperty("centerX")?e.centerX=t.centerX:e.x=M(t,"x",0),t.hasOwnProperty("centerY")?e.centerY=t.centerY:e.y=M(t,"y",0),this}setEnable(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=M(t,"left",!1),e.right=M(t,"right",!1),e.top=M(t,"top",!1),e.bottom=M(t,"bottom",!1)),this.isRunning=this.enable,this}setBoundsHitMode(t){void 0===t&&(t=0);var e=this.boundsHitMode;return e.left=L(M(t,"left",t)),e.right=L(M(t,"right",t)),e.top=L(M(t,"top",t)),e.bottom=L(M(t,"bottom",t)),this.hasWrapBoundHitMode=e.left+e.right+e.top+e.bottom>0,this}setAlignMode(t){return"string"==typeof t&&(t=S[t]),this.alignMode=t,this}get enable(){var t=this.boundsEnable;return t.left||t.right||t.top||t.bottom}set enable(t){this.setEnable(t)}update(t,e){var i=this.parent;if(this.clearHitResult(),!this.enable)return this;var s=this.boundsTarget;s&&E(s,this.bounds);var n,r,o,h,a,u,d=this.bounds,c=this.boundsEnable,p=this.boundsHitMode;if(0===this.alignMode){var g=E(i,!0);n=g.left,r=g.right,o=g.top,h=g.bottom}else n=i.x,r=i.x,o=i.y,h=i.y;c.left&&(a=d.left-n)>0&&(this.isHitAny=!0,this.isHitLeft=!0,0===p.left?i.x+=a:i.x=d.right-a,this.emit("hitleft",this.parent,this)),c.right&&(a=d.right-r)<0&&(this.isHitAny=!0,this.isHitRight=!0,0===p.left?i.x+=a:i.x=d.left-a,this.emit("hitright",this.parent,this)),c.top&&(u=d.top-o)>0&&(this.isHitAny=!0,this.isHitTop=!0,0===p.left?i.y+=u:i.y=d.bottom-u,this.emit("hittop",this.parent,this)),c.bottom&&(u=d.bottom-h)<0&&(this.isHitAny=!0,this.isHitBottom=!0,0===p.left?i.y+=u:i.y=d.top-u,this.emit("hitbottom",this.parent,this)),this.isHitAny&&this.emit("hitany",this.parent,this)}clearHitResult(){return this.isHitAny=!1,this.isHitLeft=!1,this.isHitRight=!1,this.isHitTop=!1,this.isHitBottom=!1,this}}const B={clamp:0,wrap:1},S={bounds:0,origin:1};var L=function(t){return"string"==typeof t&&(t=B[t]),t};class N extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e){return new R(t,e)}}return N},"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();