phaser3-rex-plugins
Version:
2 lines (1 loc) • 9.19 kB
JavaScript
!function(t,e){"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();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,(r=i.key,s=void 0,"symbol"==typeof(s=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(r,"string"))?s:String(s)),i);}var r,s;}function i(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e);}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function u(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function a(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return !1}}();return function(){var n,i=s(t);if(e){var r=s(this).constructor;n=Reflect.construct(i,arguments,r);}else n=i.apply(this,arguments);return function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return u(t)}(this,n)}}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(arguments.length<3?t:n):r.value}},h.apply(this,arguments)}var c=function(t){r(o,t);var n=a(o);function o(t,i,r){var s;return e(this,o),(s=n.call(this,t,0,0,2,2,i,1)).setAlpha(r),s.setScrollFactor(0),s.boot(),s}return i(o,[{key:"boot",value:function(){this.scene.sys.events.on("prerender",this.resize,this);}},{key:"destroy",value:function(t){this.scene&&!this.ignoreDestroy&&(this.scene.sys.events.off("prerender",this.resize,this),h(s(o.prototype),"destroy",this).call(this,t));}},{key:"tint",get:function(){return this.fillColor},set:function(t){this.setFillStyle(t,this.fillAlpha);}},{key:"resize",value:function(){var t=this.scene,e=t.sys.scale.gameSize,n=t.sys.cameras.main,i=e.width,r=e.height,s=1/n.zoom,o=i/2,u=r/2,a=i*s,h=r*s;this.x===o&&this.y===u||this.setPosition(o,u),this.width===a&&this.height===h||this.setSize(a,h).setOrigin(.5);}}]),o}(Phaser.GameObjects.Rectangle),l={setEventEmitter:function(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:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},f=Phaser.Scene,v=function(t){return t instanceof f},p=Phaser.Game,y=function(t){return t instanceof p},m=Phaser.Utils.Objects.GetValue,d=function(){function n(t,i){e(this,n),this.setParent(t),this.isShutdown=!1,this.setEventEmitter(m(i,"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));}return i(n,[{key:"shutdown",value:function(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);}},{key:"destroy",value:function(t){this.shutdown(t);}},{key:"onEnvDestroy",value:function(){this.destroy(!0);}},{key:"onParentDestroy",value:function(t,e){this.destroy(e);}},{key:"setParent",value:function(e){var n;return this.parent=e,this.scene=null==(n=e)||"object"!==t(n)?null:v(n)?n:n.scene&&v(n.scene)?n.scene:n.parent&&n.parent.scene&&v(n.parent.scene)?n.parent.scene:null,this.game=function(e){return null==e||"object"!==t(e)?null:y(e)?e:y(e.game)?e.game:v(e)?e.sys.game:v(e.scene)?e.scene.sys.game:void 0}(e),this}}]),n}();Object.assign(d.prototype,l);var E=Phaser.Utils.Objects.GetValue,b=function(t){r(s,t);var n=a(s);function s(t,i){var r;return e(this,s),(r=n.call(this,t,{eventEmitter:!1})).resetFromJSON(i),r.boot(),r}return i(s,[{key:"resetFromJSON",value:function(t){return this.setHitAreaMode(E(t,"hitAreaMode",0)),this.setEnable(E(t,"enable",!0)),this.setStopMode(E(t,"stopAllLevels",!0)),this}},{key:"boot",value:function(){this.parent.on("pointerdown",(function(t,e,n,i){this.stopAllLevels&&i.stopPropagation();}),this).on("pointerup",(function(t,e,n,i){this.stopAllLevels&&i.stopPropagation();}),this).on("pointermove",(function(t,e,n,i){this.stopAllLevels&&i.stopPropagation();}),this).on("pointerover",(function(t,e,n,i){this.stopAllLevels&&i.stopPropagation();}),this).on("pointerout",(function(t,e){this.stopAllLevels&&e.stopPropagation();}),this);}},{key:"setHitAreaMode",value:function(t){"string"==typeof t&&(t=g[t]);var e=this.parent;return e.input&&e.removeInteractive(),0===t?e.setInteractive():e.setInteractive({hitArea:{},hitAreaCallback:function(){return !0}}),this}},{key:"setEnable",value:function(t){return void 0===t&&(t=!0),t?this.parent.setInteractive():this.parent.disableInteractive(),this.enable=t,this}},{key:"setStopMode",value:function(t){return void 0===t&&(t=!0),this.stopAllLevels=t,this}},{key:"toggleEnable",value:function(){return this.setEnable(!this.enable),this}}]),s}(d),g={default:0,fullWindow:1},_=Phaser.Utils.Objects.GetValue,w=function(t){r(s,t);var n=a(s);function s(t,i){var r;e(this,s);var o=_(i,"color",0),a=_(i,"alpha",.8);return (r=n.call(this,t,o,a)).touchEventStop=new b(u(r),{hitAreaMode:1}),r}return i(s)}(c);function P(t){var e=new w(this.scene,t);return this.scene.add.existing(e),e}var O=Phaser.GameObjects.BuildGameObject;function j(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var n=new w(this.scene,t);return O(this.scene,n,t),n}var S=function(t){return null==t||""===t||0===t.length},k=function(t){r(s,Phaser.Plugins.BasePlugin);var n=a(s);function s(t){var i;return e(this,s),i=n.call(this,t),t.registerGameObject("rexCover",P,j),i}return i(s,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}}]),s}();return function(e,n,i,r){if(void 0===r&&(r="."),"object"===t(e)){if(S(n)){if(null==i)return;"object"===t(i)&&(e=i);}else {"string"==typeof n&&(n=n.split(r));var s=n.pop(),o=function(e,n,i){var r=e;if(S(n));else {var s;"string"==typeof n&&(n=n.split("."));for(var o=0,u=n.length;o<u;o++){var a;null!=r[s=n[o]]&&"object"===t(r[s])||(a=o===u-1?void 0===i?{}:i:{},r[s]=a),r=r[s];}}return r}(e,n);o[s]=i;}}}(window,"RexPlugins.GameObjects.Cover",w),k}));