phaser3-rex-plugins
Version:
2 lines (1 loc) • 5.12 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 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},u=function(t){if(t.parentContainer)return u(t.parentContainer);var e=a(t);return e?u(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=u(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 l 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)}}function m(t,e){var s=new l(this.scene,t,e);return this.scene.add.existing(s),s}const d=Phaser.Utils.Objects.GetAdvancedValue,p=Phaser.GameObjects.BuildGameObject;function f(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var s=d(t,"color",void 0),n=d(t,"alpha",void 0),i=new l(this.scene,s,n);return p(this.scene,i,t),i}var E=function(t){return null!==t&&"object"==typeof t};class y extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexFullWindowRectangle",m,f)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,e,s,n="."){if(!E(t))return t;if(function(t){return null==t}(e)||""===e||Array.isArray(e)&&0===e.length)return t;if("string"==typeof e&&-1===e.indexOf(n)||"number"==typeof e)return t[e]=s,t;var i=function(t,e){return Array.isArray(t)||(t="string"!=typeof t||""===t.trim()?[]:t.split(e).filter(Boolean)),t}(e,n);if(0===i.length)return t;for(var r=t,o=i.length,h=0;h<o-1;h++){var a=i[h],u=r[a];E(u)||(r[a]={}),r=r[a]}r[i[o-1]]=s}(window,"RexPlugins.GameObjects.FullWindowRectangle",l),y},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexfullwindowrectangleplugin=e();