UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 6.5 kB
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 n=function(t){return t instanceof e};const i=Phaser.Game;var s=function(t){return t instanceof i};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:n(e)?e:e.scene&&n(e.scene)?e.scene:e.parent&&e.parent.scene&&n(e.parent.scene)?e.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:s(t)?t:s(t.game)?t.game:n(t)?t.sys.game:n(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(o.prototype,t);var h=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},a=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height};const u=Phaser.Geom.Rectangle,c=Phaser.Math.Vector2,v=Phaser.Math.RotateAround,d=Phaser.GameObjects.Container;var l=void 0,m=function(t,e,n){return void 0===e?e=new c:!0===e&&(void 0===E&&(E=new c),e=E),t.getTopLeft?t.getTopLeft(e,n):(e.x=t.x-h(t)*t.originX,e.y=t.y-a(t)*t.originY,g(t,e,n))},f=function(t,e,n){return void 0===e?e=new c:!0===e&&(void 0===E&&(E=new c),e=E),t.getTopRight?t.getTopRight(e,n):(e.x=t.x-h(t)*t.originX+h(t),e.y=t.y-a(t)*t.originY,g(t,e,n))},p=function(t,e,n){return void 0===e?e=new c:!0===e&&(void 0===E&&(E=new c),e=E),t.getBottomLeft?t.getBottomLeft(e,n):(e.x=t.x-h(t)*t.originX,e.y=t.y-a(t)*t.originY+a(t),g(t,e,n))},y=function(t,e,n){return void 0===e?e=new c:!0===e&&(void 0===E&&(E=new c),e=E),t.getBottomRight?t.getBottomRight(e,n):(e.x=t.x-h(t)*t.originX+h(t),e.y=t.y-a(t)*t.originY+a(t),g(t,e,n))},E=void 0,g=function(t,e,n){return void 0===n&&(n=!1),0!==t.rotation&&v(e,t.x,t.y,t.rotation),n&&t.parentContainer&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e),e},x=function(t,e,n,i,s){if(!t)return!1;if(i&&!i(t,e,n))return!1;var r=function(t,e){if(void 0===e?e=new u:!0===e&&(void 0===l&&(l=new u),e=l),t.getBounds&&!(t instanceof d))return t.getBounds(e);var n,i,s,r,o,h,a,c;if(t.parentContainer){var v=t.parentContainer.getBoundsTransformMatrix();m(t,e),v.transformPoint(e.x,e.y,e),n=e.x,i=e.y,f(t,e),v.transformPoint(e.x,e.y,e),s=e.x,r=e.y,p(t,e),v.transformPoint(e.x,e.y,e),o=e.x,h=e.y,y(t,e),v.transformPoint(e.x,e.y,e),a=e.x,c=e.y}else m(t,e),n=e.x,i=e.y,f(t,e),s=e.x,r=e.y,p(t,e),o=e.x,h=e.y,y(t,e),a=e.x,c=e.y;return e.x=Math.min(n,s,o,a),e.y=Math.min(i,r,h,c),e.width=Math.max(n,s,o,a)-e.x,e.height=Math.max(i,r,h,c)-e.y,e}(t,!0);return!(!r.contains(e,n)||s&&!s(t,e,n))},_=function(t,e,n){var i=t.camera;return i?(void 0===n?n={}:!0===n&&(n=w),i===e?(n.x=t.worldX,n.y=t.worldY):i.getWorldPoint(t.x,t.y,n),n):null},w={},P=function(t,e,n,i){return function(t,e,n,i,s){var r,o=t.scene.sys.cameras.main,h=0===t.scrollFactorX&&0===t.scrollFactorY;if(e)return h?n(t,e.x,e.y,i,s):!!(r=_(e,o,!0))&&n(t,r.x,r.y,i,s);for(var a=t.scene.input.manager,u=a.pointersTotal,c=a.pointers,v=0;v<u;v++)if(e=c[v],h){if(n(t,e.x,e.y,i,s))return!0}else{if(!(r=_(e,o,!0)))continue;if(n(t,r.x,r.y,i,s))return!0}return!1}(t,e,x,n,i)};const b=Phaser.Utils.Objects.GetValue;class M extends o{constructor(t,e){switch(super(t,e),this.parent!==this.scene?this.focusMode=b(e,"focus",!0):this.focusMode=!1,"boolean"==typeof this.focusMode&&(this.focusMode=this.focusMode?1:0),this.setSpeed(b(e,"speed",.1)),this.setEnable(b(e,"enable",!0)),this.focusMode){case 0:case 2:this.scene.input.on("wheel",this.onSceneScroll,this);break;default:t.setInteractive(b(e,"inputConfig",void 0)).on("wheel",(function(t,e,n,i,s){this.tryScroll(n)}),this)}}destroy(){switch(this.focusMode){case 0:case 2:this.scene.input.off("wheel",this.onSceneScroll,this)}}onSceneScroll(t,e,n,i,s,r){(2!==this.focusMode||P(this.parent,t))&&this.tryScroll(i)}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}setSpeed(t){return this.speed=t,this}tryScroll(t){if(this.enable)return this.scroll(t),this}scroll(t){return t*=this.speed,this.emit("scroll",t,this.parent,this),this}}class S extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e){return new M(t,e)}}return S},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexmousewheelscrollerplugin=e();