phaser4-rex-plugins
Version:
2 lines (1 loc) • 5.08 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},v=function(t){if(t.parentContainer)return v(t.parentContainer);var e=a(t);return e?v(e):t};class l 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=v(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,l=i*o,c=r*o;e.x===h&&e.y===a||e.setPosition(h,a),e.width===l&&e.height===c||e.setSize(l,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 l(this),this.setAlpha(s)}get tint(){return this.fillColor}set tint(t){this.setFillStyle(t,this.fillAlpha)}}function m(t,e){var s=new u(this.scene,t,e);return this.scene.add.existing(s),s}const p=Phaser.Utils.Objects.GetAdvancedValue,d=Phaser.GameObjects.BuildGameObject;function f(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var s=p(t,"color",void 0),n=p(t,"alpha",void 0),i=new u(this.scene,s,n);return d(this.scene,i,t),i}var E=function(t){return null==t||""===t||0===t.length};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(void 0===n&&(n="."),"object"==typeof t)if(E(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(E(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.FullWindowRectangle",u),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();