UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 6.3 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 s=function(t){return t instanceof e};const n=Phaser.Game;var i=function(t){return t instanceof n};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:s(e)?e:e.scene&&s(e.scene)?e.scene:e.parent&&e.parent.scene&&s(e.parent.scene)?e.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:i(t)?t:i(t.game)?t.game:s(t)?t.sys.game:s(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(o.prototype,t);const h=Phaser.GameObjects.Layer;var a=function(t){var e=t.displayList;return function(t){return t instanceof h}(e)?e:null},l=function(t){if(t.parentContainer)return l(t.parentContainer);var e=a(t);return e?l(e):t};class v extends o{constructor(t,e){super(t),this.targetCamera=void 0,this.boot()}boot(){this.scene.sys.events.on("prerender",this.resize,this)}destroy(){this.scene&&(this.scene.sys.events.off("prerender",this.resize,this),super.destroy())}resize(){var t=this.scene,e=this.parent,s=function(t){for(var e,s=l(t).cameraFilter,n=t.scene.sys.cameras.cameras,i=0,r=n.length;i<r;i++)if(!((s&(e=n[i]).id)>0))return e;return null}(e);if(s){e.setScrollFactor(0).setOrigin(.5);var n=t.sys.scale.gameSize,i=n.width,r=n.height,o=1/s.zoom,h=i/2,a=r/2,v=i*o,c=r*o;e.x===h&&e.y===a||e.setPosition(h,a),e.width===v&&e.height===c||e.setSize(v,c)}}}const c=Phaser.GameObjects.Rectangle;class u extends c{constructor(t,e,s){super(t,0,0,2,2,e,1),this.fullWindow=new v(this),this.setAlpha(s)}get tint(){return this.fillColor}set tint(t){this.setFillStyle(t,this.fillAlpha)}}const p=Phaser.Utils.Objects.GetValue;class m extends o{constructor(t,e){super(t,{eventEmitter:!1}),this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.setHitAreaMode(p(t,"hitAreaMode",0)),this.setEnable(p(t,"enable",!0)),this.setStopMode(p(t,"stopAllLevels",!0)),this}boot(){this.parent.on("pointerdown",(function(t,e,s,n){this.stopAllLevels&&n.stopPropagation()}),this).on("pointerup",(function(t,e,s,n){this.stopAllLevels&&n.stopPropagation()}),this).on("pointermove",(function(t,e,s,n){this.stopAllLevels&&n.stopPropagation()}),this).on("pointerover",(function(t,e,s,n){this.stopAllLevels&&n.stopPropagation()}),this).on("pointerout",(function(t,e){this.stopAllLevels&&e.stopPropagation()}),this)}setHitAreaMode(t){"string"==typeof t&&(t=d[t]);var e=this.parent;return e.input&&e.removeInteractive(),0===t?e.setInteractive():e.setInteractive({hitArea:{},hitAreaCallback:function(){return!0}}),this}setEnable(t){return void 0===t&&(t=!0),t?this.parent.setInteractive():this.parent.disableInteractive(),this.enable=t,this}setStopMode(t){return void 0===t&&(t=!0),this.stopAllLevels=t,this}toggleEnable(){return this.setEnable(!this.enable),this}}var d={default:0,fullWindow:1};const f=Phaser.Utils.Objects.GetValue;class E extends u{constructor(t,e){super(t,f(e,"color",0),f(e,"alpha",.8)),this.touchEventStop=new m(this,{hitAreaMode:1})}}function y(t){var e=new E(this.scene,t);return this.scene.add.existing(e),e}const g=Phaser.GameObjects.BuildGameObject;function _(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var s=new E(this.scene,t);return g(this.scene,s,t),s}var b=function(t){return null==t||""===t||0===t.length};class P extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexCover",y,_)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,e,s,n){if(void 0===n&&(n="."),"object"==typeof t)if(b(e)){if(null==s)return;"object"==typeof s&&(t=s)}else{"string"==typeof e&&(e=e.split(n));var i=e.pop(),r=function(t,e,s){var n=t;if(b(e));else{var i;"string"==typeof e&&(e=e.split("."));for(var r=0,o=e.length;r<o;r++){var h;null!=n[i=e[r]]&&"object"==typeof n[i]||(h=r===o-1?void 0===s?{}:s:{},n[i]=h),n=n[i]}}return n}(t,e);r[i]=s}}(window,"RexPlugins.GameObjects.Cover",E),P},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexcoverplugin=e();