phaser3-rex-plugins
Version:
2 lines (1 loc) • 16 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).rexscaleplugin=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 i(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(s=n.key,r=void 0,"symbol"==typeof(r=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(s,"string"))?r:String(r)),n);}var s,r;}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(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&&a(t,e);}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function o(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 function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function u(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 i,n=r(t);if(e){var s=r(this).constructor;i=Reflect.construct(n,arguments,s);}else i=n.apply(this,arguments);return o(this,i)}}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=r(t)););return t}(t,e);if(n){var s=Object.getOwnPropertyDescriptor(n,e);return s.get?s.get.call(arguments.length<3?t:i):s.value}},h.apply(this,arguments)}var c={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):[]}},l=Phaser.Scene,p=function(t){return t instanceof l},f=Phaser.Game,y=function(t){return t instanceof f},v=Phaser.Utils.Objects.GetValue,d=function(){function i(t,n){e(this,i),this.setParent(t),this.isShutdown=!1,this.setEventEmitter(v(n,"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 n(i,[{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 i;return this.parent=e,this.scene=null==(i=e)||"object"!==t(i)?null:p(i)?i:i.scene&&p(i.scene)?i.scene:i.parent&&i.parent.scene&&p(i.parent.scene)?i.parent.scene:null,this.game=function(e){return null==e||"object"!==t(e)?null:y(e)?e:y(e.game)?e.game:p(e)?e.sys.game:p(e.scene)?e.scene.sys.game:void 0}(e),this}}]),i}();Object.assign(d.prototype,c);var m=Phaser.Utils.Objects.GetValue,k=function(t){s(a,t);var i=u(a);function a(t,n){var s;return e(this,a),(s=i.call(this,t,n))._isRunning=!1,s.isPaused=!1,s.tickingState=!1,s.setTickingMode(m(n,"tickingMode",1)),s}return n(a,[{key:"boot",value:function(){2!==this.tickingMode||this.tickingState||this.startTicking();}},{key:"shutdown",value:function(t){this.isShutdown||(this.stop(),this.tickingState&&this.stopTicking(),h(r(a.prototype),"shutdown",this).call(this,t));}},{key:"setTickingMode",value:function(t){"string"==typeof t&&(t=g[t]),this.tickingMode=t;}},{key:"startTicking",value:function(){this.tickingState=!0;}},{key:"stopTicking",value:function(){this.tickingState=!1;}},{key:"isRunning",get:function(){return this._isRunning},set:function(t){this._isRunning!==t&&(this._isRunning=t,1===this.tickingMode&&t!=this.tickingState&&(t?this.startTicking():this.stopTicking()));}},{key:"start",value:function(){return this.isPaused=!1,this.isRunning=!0,this}},{key:"pause",value:function(){return this.isRunning&&(this.isPaused=!0,this.isRunning=!1),this}},{key:"resume",value:function(){return this.isPaused&&(this.isRunning=!0),this}},{key:"stop",value:function(){return this.isPaused=!1,this.isRunning=!1,this}},{key:"complete",value:function(){this.isPaused=!1,this.isRunning=!1,this.emit("complete",this.parent,this);}}]),a}(d),g={no:0,lazy:1,always:2},b=Phaser.Utils.Objects.GetValue,E=function(t){s(a,t);var i=u(a);function a(t,n){var s;e(this,a);var r=(s=i.call(this,t,n)).scene?"update":"step";return s.tickEventName=b(n,"tickEventName",r),s.isSceneTicker=!w(s.tickEventName),s}return n(a,[{key:"startTicking",value:function(){h(r(a.prototype),"startTicking",this).call(this),this.isSceneTicker?this.scene.sys.events.on(this.tickEventName,this.update,this):this.game.events.on(this.tickEventName,this.update,this);}},{key:"stopTicking",value:function(){h(r(a.prototype),"stopTicking",this).call(this),this.isSceneTicker&&this.scene?this.scene.sys.events.off(this.tickEventName,this.update,this):this.game&&this.game.events.off(this.tickEventName,this.update,this);}}]),a}(k),w=function(t){return "step"===t||"poststep"===t},S=Phaser.Utils.Objects.GetValue,_=Phaser.Math.Clamp,O=function(){function t(i){e(this,t),this.resetFromJSON(i);}return n(t,[{key:"resetFromJSON",value:function(t){this.state=S(t,"state",T),this.timeScale=S(t,"timeScale",1),this.delay=S(t,"delay",0),this.repeat=S(t,"repeat",0),this.repeatCounter=S(t,"repeatCounter",0),this.repeatDelay=S(t,"repeatDelay",0),this.duration=S(t,"duration",0),this.nowTime=S(t,"nowTime",0),this.justRestart=S(t,"justRestart",!1);}},{key:"toJSON",value:function(){return {state:this.state,timeScale:this.timeScale,delay:this.delay,repeat:this.repeat,repeatCounter:this.repeatCounter,repeatDelay:this.repeatDelay,duration:this.duration,nowTime:this.nowTime,justRestart:this.justRestart}}},{key:"destroy",value:function(){}},{key:"setTimeScale",value:function(t){return this.timeScale=t,this}},{key:"setDelay",value:function(t){return void 0===t&&(t=0),this.delay=t,this}},{key:"setDuration",value:function(t){return this.duration=t,this}},{key:"setRepeat",value:function(t){return this.repeat=t,this}},{key:"setRepeatInfinity",value:function(){return this.repeat=-1,this}},{key:"setRepeatDelay",value:function(t){return this.repeatDelay=t,this}},{key:"start",value:function(){return this.nowTime=this.delay>0?-this.delay:0,this.state=this.nowTime>=0?R:P,this.repeatCounter=0,this}},{key:"stop",value:function(){return this.state=T,this}},{key:"update",value:function(t,e){this.state!==T&&this.state!==D&&0!==e&&0!==this.timeScale&&(this.nowTime+=e*this.timeScale,this.justRestart=!1,this.nowTime>=this.duration?-1===this.repeat||this.repeatCounter<this.repeat?(this.repeatCounter++,this.justRestart=!0,this.nowTime-=this.duration,this.repeatDelay>0&&(this.nowTime-=this.repeatDelay,this.state=j)):(this.nowTime=this.duration,this.state=D):this.nowTime>=0&&(this.state=R));}},{key:"t",get:function(){var t;switch(this.state){case T:case P:case j:t=0;break;case R:t=this.nowTime/this.duration;break;case D:t=1;}return _(t,0,1)},set:function(t){(t=_(t,-1,1))<0?(this.state=P,this.nowTime=-this.delay*t):(this.state=R,this.nowTime=this.duration*t,1===t&&0!==this.repeat&&this.repeatCounter++);}},{key:"setT",value:function(t){return this.t=t,this}},{key:"isIdle",get:function(){return this.state===T}},{key:"isDelay",get:function(){return this.state===P}},{key:"isCountDown",get:function(){return this.state===R}},{key:"isRunning",get:function(){return this.state===P||this.state===R}},{key:"isDone",get:function(){return this.state===D}},{key:"isOddIteration",get:function(){return 1==(1&this.repeatCounter)}},{key:"isEvenIteration",get:function(){return 0==(1&this.repeatCounter)}}]),t}(),T=0,P=1,R=2,j=3,D=-1,N=function(t){s(a,t);var i=u(a);function a(t,n){var s;return e(this,a),(s=i.call(this,t,n)).timer=new O,s}return n(a,[{key:"shutdown",value:function(t){this.isShutdown||(h(r(a.prototype),"shutdown",this).call(this,t),this.timer.destroy(),this.timer=void 0);}},{key:"start",value:function(){return this.timer.start(),h(r(a.prototype),"start",this).call(this),this}},{key:"stop",value:function(){return this.timer.stop(),h(r(a.prototype),"stop",this).call(this),this}},{key:"complete",value:function(){return this.timer.stop(),h(r(a.prototype),"complete",this).call(this),this}}]),a}(E),X=Phaser.Utils.Objects.GetValue,x=Phaser.Utils.Objects.GetAdvancedValue,C=Phaser.Tweens.Builders.GetEaseFunction,Y=function(t){s(a,t);var i=u(a);function a(){return e(this,a),i.apply(this,arguments)}return n(a,[{key:"resetFromJSON",value:function(t){return this.timer.resetFromJSON(X(t,"timer")),this.setEnable(X(t,"enable",!0)),this.setTarget(X(t,"target",this.parent)),this.setDelay(x(t,"delay",0)),this.setDuration(x(t,"duration",1e3)),this.setEase(X(t,"ease","Linear")),this.setRepeat(X(t,"repeat",0)),this}},{key:"setEnable",value:function(t){return null==t&&(t=!0),this.enable=t,this}},{key:"setTarget",value:function(t){return void 0===t&&(t=this.parent),this.target=t,this}},{key:"setDelay",value:function(t){return this.delay=t,this}},{key:"setDuration",value:function(t){return this.duration=t,this}},{key:"setRepeat",value:function(t){return this.repeat=t,this}},{key:"setRepeatDelay",value:function(t){return this.repeatDelay=t,this}},{key:"setEase",value:function(t){return void 0===t&&(t="Linear"),this.ease=t,this.easeFn=C(t),this}},{key:"start",value:function(){return this.timer.isRunning||h(r(a.prototype),"start",this).call(this),this}},{key:"restart",value:function(){return this.timer.stop(),this.start.apply(this,arguments),this}},{key:"stop",value:function(t){return void 0===t&&(t=!1),h(r(a.prototype),"stop",this).call(this),t&&(this.timer.setT(1),this.updateGameObject(this.target,this.timer),this.complete()),this}},{key:"update",value:function(t,e){if(!this.isRunning||!this.enable||!this.parent.active)return this;var i=this.target,n=this.timer;return n.update(t,e),n.isDelay||this.updateGameObject(i,n),this.emit("update",i,this),n.isDone&&this.complete(),this}},{key:"updateGameObject",value:function(t,e){}}]),a}(N),F=Phaser.Utils.Objects.GetValue,G=Phaser.Utils.Objects.GetAdvancedValue,J=Phaser.Math.Linear,L=function(t){s(a,t);var i=u(a);function a(t,n){var s;return e(this,a),(s=i.call(this,t,n)).scaleStart={},s.scaleEnd={},s.resetFromJSON(n),s.boot(),s}return n(a,[{key:"resetFromJSON",value:function(t){return h(r(a.prototype),"resetFromJSON",this).call(this,t),this.setMode(F(t,"mode",0)),this.setScaleRange(G(t,"start",void 0),G(t,"end",0)),this}},{key:"setMode",value:function(t){return "string"==typeof t&&(t=M[t]),this.mode=t,this}},{key:"setScaleRange",value:function(t,e){return "number"==typeof t?(this.startX=t,this.startY=t):(this.startX=G(t,"x",this.parent.scaleX),this.startY=G(t,"y",this.parent.scaleY)),"number"==typeof e?(this.endX=e,this.endY=e):(this.endX=G(e,"x",void 0),this.endY=G(e,"y",void 0)),this.hasScaleX=void 0!==this.startX&&void 0!==this.endX,this.hasScaleY=void 0!==this.startY&&void 0!==this.endY,this}},{key:"start",value:function(){if(this.timer.isRunning)return this;var t=this.parent;this.hasScaleX&&(t.scaleX=this.startX),this.hasScaleY&&(t.scaleY=this.startY);var e=this.repeat;return 2===this.mode&&-1!==e&&(e=2*(e+1)-1),this.timer.setDelay(this.delay).setDuration(this.duration).setRepeat(e),h(r(a.prototype),"start",this).call(this),this}},{key:"updateGameObject",value:function(t,e){var i=e.t;e.isOddIteration&&(i=1-i),i=this.easeFn(i),this.hasScaleX&&(t.scaleX=J(this.startX,this.endX,i)),this.hasScaleY&&(t.scaleY=J(this.startY,this.endY,i));}},{key:"complete",value:function(){return h(r(a.prototype),"complete",this).call(this),1===this.mode&&this.parent.destroy(),this}}]),a}(Y),M={stop:0,destroy:1,yoyo:2},U=function(t){s(r,Phaser.Plugins.BasePlugin);var i=u(r);function r(t){return e(this,r),i.call(this,t)}return n(r,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e){return new L(t,e)}}]),r}(),V={scaleDown:function(t,e,i,n,s){void 0===n&&(n="Linear");var r={mode:0};switch(i){case 0:case"x":r.end={x:0};break;case 1:case"y":r.end={y:0};break;default:r.end=0;}return r.duration=e,r.ease=n,void 0===s?s=new L(t,r):s.resetFromJSON(r),s.restart(),s},scaleDownDestroy:function(t,e,i,n,s,r){void 0===n&&(n="Linear"),s instanceof L&&(r=s,s=void 0),void 0===s&&(s=!0);var a={};switch(a.mode=s?1:0,i){case 0:case"x":a.end={x:0};break;case 1:case"y":a.end={y:0};break;default:a.end=0;}return a.duration=e,a.ease=n,void 0===r?r=new L(t,a):r.resetFromJSON(a),r.restart(),r},popup:function(t,e,i,n,s){var r,a;switch(void 0===n&&(n="Cubic"),i){case 0:case"x":r={x:0},a={x:t.scaleX};break;case 1:case"y":r={y:0},a={y:t.scaleY};break;default:r=0,a=t.scale;}var o={mode:0,start:r,end:a,duration:e,ease:n};return void 0===s?s=new L(t,o):s.resetFromJSON(o),s.restart(),s},yoyo:function(t,e,i,n,s,r,a){var o,u;switch(void 0===i&&(i=1.2),void 0===n&&(n=0),void 0===r&&(r="Cubic"),s){case 0:case"x":o={x:t.scaleX},u={x:i};break;case 1:case"y":o={y:t.scaleX},u={y:i};break;default:o=t.scaleX,u=i;}var h={mode:2,start:o,end:u,duration:e/2,ease:r,repeat:n};return void 0===a?a=new L(t,h):a.resetFromJSON(h),a.restart(),a}};return Object.assign(U.prototype,V),U}));