phaser4-rex-plugins
Version:
2 lines (1 loc) • 18.9 kB
JavaScript
var t,e;t=void 0,e=function(){const t=Phaser.GameObjects.GetCalcMatrix,e=Phaser.Renderer.Canvas.SetTransform;var s={renderWebGL:function(e,s,i,r){s.updateData();var h=i.camera;h.addToRenderList(s);for(var a,n=t(s,h,r,!i.useCanvas).calc,o=s._displayOriginX,l=s._displayOriginY,u=s.alpha,d=s.customRenderNodes.Submitter||s.defaultRenderNodes.Submitter,p=s.geom,c=0,y=p.length;c<y;c++)(a=p[c]).visible&&a.webglRender(i,d,n,s,u,o,l)},renderCanvas:function(t,s,i,r){s.updateData(),i.addToRenderList(s);var h=t.currentContext;if(e(t,h,s,i,r)){for(var a,n=s._displayOriginX,o=s._displayOriginY,l=s.geom,u=0,d=l.length;u<d;u++)(a=l[u]).visible&&a.canvasRender(h,n,o);h.restore()}}},i=function(t){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))t.length=0;else for(var e in t)delete t[e];return t};const r=Phaser.GameObjects.Shape,h=Phaser.Utils.Array.Remove;class a extends r{constructor(t,e,s,i,r){void 0===e&&(e=0),void 0===s&&(s=0),void 0===i&&(i=2),void 0===r&&(r=i),super(t,"rexShapes",[]),this._width=-1,this._height=-1,this.dirty=!0,this.isSizeChanged=!0,this.shapes={},this.setPosition(e,s),this.setSize(i,r),this.updateDisplayOrigin()}get width(){return this._width}set width(t){this.setSize(t,this._height)}get height(){return this._height}set height(t){this.setSize(this._width,t)}setDirty(t){return void 0===t&&(t=!0),this.dirty=t,this}setSize(t,e){this.isSizeChanged=this.isSizeChanged||this._width!==t||this._height!==e,this.dirty=this.dirty||this.isSizeChanged,this._width=t,this._height=e,this.updateDisplayOrigin();var s=this.input;return s&&!s.customHitArea&&(s.hitArea.width=t,s.hitArea.height=e),this}resize(t,e){return this.setSize(t,e),this}get fillColor(){return this._fillColor}set fillColor(t){this.setFillStyle(t,this._fillAlpha)}get fillAlpha(){return this._fillAlpha}set fillAlpha(t){this.setFillStyle(this._fillColor,t)}setFillStyle(t,e){return void 0===e&&(e=1),this.dirty=this.dirty||this.fillColor!==t||this.fillAlpha!==e,this._fillColor=t,this._fillAlpha=e,this}get lineWidth(){return this._lineWidth}set lineWidth(t){this.setStrokeStyle(t,this._strokeColor,this._strokeAlpha)}get strokeColor(){return this._strokeColor}set strokeColor(t){this.setStrokeStyle(this._lineWidth,t,this._strokeAlpha)}get strokeAlpha(){return this._strokeAlpha}set strokeAlpha(t){this.setStrokeStyle(this._lineWidth,this._strokeColor,t)}setStrokeStyle(t,e,s){return void 0===s&&(s=1),this.dirty=this.dirty||this.lineWidth!==t||this.strokeColor!==e||this.strokeAlpha!==s,this._lineWidth=t,this._strokeColor=e,this._strokeAlpha=s,this}updateShapes(){}updateData(){if(!this.dirty)return this;this.updateShapes();for(var t=this.geom,e=0,s=t.length;e<s;e++){var i=t[e];i.dirty&&i.updateData()}return this.isSizeChanged=!1,this.dirty=!1,this}clear(){return this.geom.length=0,i(this.shapes),this.dirty=!0,this}getShape(t){return this.shapes[t]}getShapes(){return this.geom}addShape(t){this.geom.push(t);var e=t.name;return e&&(this.shapes[e]=t),this.dirty=!0,this}deleteShape(t){var e=this.getShape(t);return e&&(delete this.shapes[t],h(this.geom,e)),this}}Object.assign(a.prototype,s);var n={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 o=Phaser.Scene;var l=function(t){return t instanceof o};const u=Phaser.Game;var d=function(t){return t instanceof u};const p=Phaser.Utils.Objects.GetValue;class c{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(p(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:l(e)?e:e.scene&&l(e.scene)?e.scene:e.parent&&e.parent.scene&&l(e.parent.scene)?e.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:d(t)?t:d(t.game)?t.game:l(t)?t.sys.game:l(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(c.prototype,n);const y=Phaser.Utils.Objects.GetValue;class v extends c{constructor(t,e){super(t,e),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(y(e,"tickingMode",1))}boot(){2!==this.tickingMode||this.tickingState||this.startTicking()}shutdown(t){this.isShutdown||(this.stop(),this.tickingState&&this.stopTicking(),super.shutdown(t))}setTickingMode(t){"string"==typeof t&&(t=g[t]),this.tickingMode=t}startTicking(){this.tickingState=!0}stopTicking(){this.tickingState=!1}get isRunning(){return this._isRunning}set isRunning(t){this._isRunning!==t&&(this._isRunning=t,1===this.tickingMode&&t!=this.tickingState&&(t?this.startTicking():this.stopTicking()))}start(){return this.isPaused=!1,this.isRunning=!0,this}pause(){return this.isRunning&&(this.isPaused=!0,this.isRunning=!1),this}resume(){return this.isPaused&&(this.isPaused=!1,this.isRunning=!0),this}stop(){return this.isPaused=!1,this.isRunning=!1,this}complete(){this.isPaused=!1,this.isRunning=!1,this.emit("complete",this.parent,this)}}const g={no:0,lazy:1,always:2},m=Phaser.Utils.Objects.GetValue;class f extends v{constructor(t,e){super(t,e);var s=this.scene?"update":"step";this.tickEventName=m(e,"tickEventName",s),this.isSceneTicker=!_(this.tickEventName)}startTicking(){super.startTicking(),this.isSceneTicker?this.scene.sys.events.on(this.tickEventName,this.update,this):this.game.events.on(this.tickEventName,this.update,this)}stopTicking(){super.stopTicking(),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)}}var _=function(t){return"step"===t||"poststep"===t};const D=Phaser.Utils.Objects.GetValue,k=Phaser.Math.Clamp;class S{constructor(t){this.resetFromJSON(t)}resetFromJSON(t){this.state=D(t,"state",E),this.timeScale=D(t,"timeScale",1),this.delay=D(t,"delay",0),this.repeat=D(t,"repeat",0),this.repeatCounter=D(t,"repeatCounter",0),this.repeatDelay=D(t,"repeatDelay",0),this.duration=D(t,"duration",0),this.nowTime=D(t,"nowTime",0),this.justRestart=D(t,"justRestart",!1)}toJSON(){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}}destroy(){}setTimeScale(t){return this.timeScale=t,this}setDelay(t){return void 0===t&&(t=0),this.delay=t,this}setDuration(t){return this.duration=t,this}setRepeat(t){return this.repeat=t,this}setRepeatInfinity(){return this.repeat=-1,this}setRepeatDelay(t){return this.repeatDelay=t,this}start(){return this.nowTime=this.delay>0?-this.delay:0,this.state=this.nowTime>=0?b:T,this.repeatCounter=0,this}stop(){return this.state=E,this}update(t,e){this.state!==E&&this.state!==w&&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=C)):(this.nowTime=this.duration,this.state=w):this.nowTime>=0&&(this.state=b))}get t(){var t;switch(this.state){case E:case T:case C:t=0;break;case b:t=this.nowTime/this.duration;break;case w:t=1}return k(t,0,1)}set t(t){(t=k(t,-1,1))<0?(this.state=T,this.nowTime=-this.delay*t):(this.state=b,this.nowTime=this.duration*t,1===t&&0!==this.repeat&&this.repeatCounter++)}setT(t){return this.t=t,this}get isIdle(){return this.state===E}get isDelay(){return this.state===T}get isCountDown(){return this.state===b}get isRunning(){return this.state===T||this.state===b}get isDone(){return this.state===w}get isOddIteration(){return!(1&~this.repeatCounter)}get isEvenIteration(){return!(1&this.repeatCounter)}}const E=0,T=1,b=2,C=3,w=-1;class P extends f{constructor(t,e){super(t,e),this.timer=new S}shutdown(t){this.isShutdown||(super.shutdown(t),this.timer.destroy(),this.timer=void 0)}start(){return this.timer.start(),super.start(),this}stop(){return this.timer.stop(),super.stop(),this}complete(){return this.timer.stop(),super.complete(),this}}const R=Phaser.Utils.Objects.GetValue,x=Phaser.Utils.Objects.GetAdvancedValue,A=Phaser.Tweens.Builders.GetEaseFunction;class O extends P{resetFromJSON(t){return this.timer.resetFromJSON(R(t,"timer")),this.setEnable(R(t,"enable",!0)),this.setTarget(R(t,"target",this.parent)),this.setDelay(x(t,"delay",0)),this.setDuration(x(t,"duration",1e3)),this.setEase(R(t,"ease","Linear")),this.setRepeat(R(t,"repeat",0)),this}setEnable(t){return null==t&&(t=!0),this.enable=t,this}setTarget(t){return void 0===t&&(t=this.parent),this.target=t,this}setDelay(t){return this.delay=t,this}setDuration(t){return this.duration=t,this}setRepeat(t){return this.repeat=t,this}setRepeatDelay(t){return this.repeatDelay=t,this}setEase(t){return void 0===t&&(t="Linear"),this.ease=t,this.easeFn=A(t),this}start(){return this.timer.isRunning||super.start(),this}restart(){return this.timer.stop(),this.start.apply(this,arguments),this}stop(t){return void 0===t&&(t=!1),super.stop(),t&&(this.timer.setT(1),this.updateTarget(this.target,this.timer),this.complete()),this}update(t,e){if(!this.isRunning||!this.enable||this.parent.hasOwnProperty("active")&&!this.parent.active)return this;var s=this.target,i=this.timer;return i.update(t,e),i.isDelay||this.updateTarget(s,i),this.emit("update",s,this),i.isDone&&this.complete(),this}updateTarget(t,e){}}const V=Phaser.Utils.Objects.GetValue,j=Phaser.Math.Linear;class F extends O{constructor(t,e){super(t,e),this.resetFromJSON(),this.boot()}start(t){if(this.timer.isRunning)return this;var e=this.target;this.propertyKey=V(t,"key","value");var s=e[this.propertyKey];return this.fromValue=V(t,"from",s),this.toValue=V(t,"to",s),this.setEase(V(t,"ease",this.ease)),this.setDuration(V(t,"duration",this.duration)),this.setRepeat(V(t,"repeat",0)),this.setDelay(V(t,"delay",0)),this.setRepeatDelay(V(t,"repeatDelay",0)),this.timer.setDuration(this.duration).setRepeat(this.repeat).setDelay(this.delay).setRepeatDelay(this.repeatDelay),e[this.propertyKey]=this.fromValue,super.start(),this}updateTarget(t,e){var s=e.t;s=this.easeFn(s),t[this.propertyKey]=j(this.fromValue,this.toValue,s)}}var N={start:function(t){return this.easeValueTask||(this.easeValueTask=new F(this,{eventEmitter:null})),void 0!==t&&(this.duration=t,this.easeValueTask.stop()),this.easeValueTask.isRunning||(this.easeValueTask.restart({key:"value",from:0,to:1,duration:this.duration,ease:this.ease,repeat:-1,delay:this.delay,repeatDelay:this.repeatDelay}),this.setDirty()),this},stop:function(){return this.easeValueTask?(this.easeValueTask.stop(),this.setDirty(),this):this},pause:function(){return this.easeValueTask?(this.easeValueTask.pause(),this.setDirty(),this):this},resume:function(){return this.easeValueTask?(this.easeValueTask.pause(),this.setDirty(),this):this}};const G=Phaser.Utils.Objects.GetValue;class L extends a{constructor(t,e){super(t,G(e,"x",0),G(e,"y",0),G(e,"width",64),G(e,"height",64)),this.resetFromConfig(e,!0),this.buildShapes(e),G(e,"start",!0)&&this.start()}resetFromConfig(t,e){var s;return void 0===e&&(e=!1),s=e?1e3:this.duration,this.setDuration(G(t,"duration",s)),s=e?"Linear":this.ease,this.setEase(G(t,"ease",s)),s=e?0:this.delay,this.setDelay(G(t,"delay",s)),s=e?0:this.repeatDelay,this.setRepeatDelay(G(t,"repeatDelay",s)),s=e?16777215:this.color,this.setColor(G(t,"color",s)),s=e?0:this.value,this.setValue(G(t,"value",s)),this}buildShapes(){}get centerX(){return this.width/2}get centerY(){return this.height/2}get radius(){return Math.min(this.centerX,this.centerY)}get color(){return this._color}set color(t){this.isColorChanged=this.isColorChanged||this._color!==t,this.dirty=this.dirty||this.isColorChanged,this._color=t,this.setShapesColor(t)}setColor(t){return this.color=t,this}setShapesColor(t){}get value(){return this._value}set value(t){t=Phaser.Math.Clamp(t,0,1),this.dirty=this.dirty||this._value!=t,this._value=t}setValue(t){return this.value=t,this}setDuration(t){return this.duration=t,this}setDelay(t){return this.delay=t,this}setRepeatDelay(t){return this.repeatDelay=t,this}setEase(t){return this.ease=t,this}get isRunning(){return!!this.tweenTask&&this.tweenTask.isRunning}}Object.assign(L.prototype,N);var W={fillStyle:function(t,e){return null==t?this.isFilled=!1:(void 0===e&&(e=1),this.isFilled=!0,this.fillColor=t,this.fillAlpha=e),this},lineStyle:function(t,e,s){return null==t||null==e?this.isStroked=!1:(void 0===s&&(s=1),this.isStroked=!0,this.lineWidth=t,this.strokeColor=e,this.strokeAlpha=s),this}},M={enableData(){return void 0===this.data&&(this.data={}),this},setData(t,e){if(this.enableData(),1===arguments.length){var s=t;for(t in s)this.data[t]=s[t]}else this.data[t]=e;return this},getData(t,e){return this.enableData(),void 0===t?this.data:function(t,e,s){if(!t||"number"==typeof t)return s;if("string"==typeof e){if(t.hasOwnProperty(e))return t[e];if(-1===e.indexOf("."))return s;e=e.split(".")}for(var i=e,r=t,h=s,a=0;a<i.length;a++){if(e=i[a],!r.hasOwnProperty(e)){h=s;break}r=h=r[e]}return h}(this.data,t,e)},incData(t,e,s){return void 0===s&&(s=0),this.enableData(),this.setData(t,this.getData(t,s)+e),this},mulData(t,e,s){return void 0===s&&(s=0),this.enableData(),this.setData(t,this.getData(t,s)*e),this},clearData(){return this.data&&i(this.data),this}};class z{constructor(){this.name=void 0,this.dirty=!0,this.visible=!0,this.data=void 0,this.isFilled=!1,this.fillColor=void 0,this.fillAlpha=1,this.isStroked=!1,this.lineWidth=1,this.strokeColor=void 0,this.strokeAlpha=1}setName(t){return this.name=t,this}setVisible(t){return void 0===t&&(t=!0),this.visible=t,this}reset(){return this.setVisible().fillStyle().lineStyle(),this}webglRender(t,e,s,i,r,h,a){}canvasRender(t,e,s){}updateData(){this.dirty=!1}}Object.assign(z.prototype,W,M);var U=Phaser.Renderer.WebGL.Utils,I=Phaser.Renderer.WebGL.Utils;const J=Phaser.Geom.Polygon.Earcut;class X extends z{constructor(){super(),this.pathData=[],this.pathIndexes=[],this.closePath=!1}updateData(){return this.pathIndexes=J(this.pathData),super.updateData(),this}webglRender(t,e,s,i,r,h,a){this.isFilled&&function(t,e,s,i,r,h,a,n){var o,l,u,d,p,c=U.getTintAppendFloatAlpha(r.fillColor,r.fillAlpha*h),y=r.pathData,v=r.pathIndexes,g=y.length,m=Array(2*g),f=Array(g),_=0,D=0;for(o=0;o<g;o+=2)l=y[o]-a,u=y[o+1]-n,d=s.getX(l,u),p=s.getY(l,u),m[_++]=d,m[_++]=p,f[D++]=c;e.batch(t,v,m,f)}(t,e,s,0,this,r,h,a),this.isStroked&&function(t,e,s,i,r,h,a,n){var o=I.getTintAppendFloatAlpha(r.strokeColor,r.strokeAlpha*h),l=r.pathData,u=l.length-1,d=r.lineWidth,p=!r.closePath,c=i.customRenderNodes.StrokePath||i.defaultRenderNodes.StrokePath,y=[];p&&(u-=2);for(var v=0;v<u;v+=2){var g=l[v]-a,m=l[v+1]-n;v>0&&g===l[v-2]&&m===l[v-1]||y.push({x:g,y:m,width:d})}c.run(t,e,y,d,p,s,o,o,o,o)}(t,e,s,i,this,r,h,a)}canvasRender(t,e,s){var i=this.pathData,r=i.length-1,h=i[0]-e,a=i[1]-s;t.beginPath(),t.moveTo(h,a),this.closePath||(r-=2);for(var n=2;n<r;n+=2){var o=i[n]-e,l=i[n+1]-s;t.lineTo(o,l)}this.closePath&&t.closePath(),this.isFilled&&(function(t,e,s,i){var r=s||e.fillColor,h=i||e.fillAlpha,a=(16711680&r)>>>16,n=(65280&r)>>>8,o=255&r;t.fillStyle="rgba("+a+","+n+","+o+","+h+")"}(t,this),t.fill()),this.isStroked&&(function(t,e,s,i){var r=s||e.strokeColor,h=i||e.strokeAlpha,a=(16711680&r)>>>16,n=(65280&r)>>>8,o=255&r;t.strokeStyle="rgba("+a+","+n+","+o+","+h+")",t.lineWidth=e.lineWidth}(t,this),t.stroke())}}class Y extends X{constructor(t,e,s,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===s&&(s=0),void 0===i&&(i=0),super(),this.setP0(t,e),this.setP1(s,i)}get x0(){return this._x0}set x0(t){this.dirty=this.dirty||this._x0!==t,this._x0=t}get y0(){return this._y0}set y0(t){this.dirty=this.dirty||this._y0!==t,this._y0=t}setP0(t,e){return this.x0=t,this.y0=e,this}get x1(){return this._x1}set x1(t){this.dirty=this.dirty||this._x1!==t,this._x1=t}get y1(){return this._y1}set y1(t){this.dirty=this.dirty||this._y1!==t,this._y1=t}setP1(t,e){return this.x1=t,this.y1=e,this}updateData(){return this.pathData.length=0,this.pathData.push(this.x0,this.y0),this.pathData.push(this.x1,this.y1),this.pathData.push(this.x0,this.y0),super.updateData(),this}}var K=function(t,e){return void 0===e&&(e=.5),t<=e?t/=e:t=1-(t-e)/(1-e),t};const B=Phaser.Math.Linear,H=Phaser.Math.Easing.Expo.In;var q={buildShapes(){for(var t=0;t<4;t++){var e=new Y;this.addShape(e)}},updateShapes(){for(var t=this.centerX,e=this.centerY,s=this.radius,i=t-s,r=e-s,h=2*s/2,a=2*s/2,n=this.getShapes(),o=n.length,l=0;l<o;l++){var u=i+h*(l%2+.5),d=r+a*(Math.floor(l/2)+.5),p=n[l],c=(this.value+.1*(o-l))%1;c=H(K(c));var y=(o-l)/o,v=B(.7,1,c)*a,g=B(.7,1,c)*h;p.lineStyle(g,this.color,y).setP0(u-v/2,d).setP1(u+v/2,d)}}};class Q extends L{constructor(t,e){super(t,e),this.type="rexSpinnerCube"}}return Object.assign(Q.prototype,q),Q},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexcubespinner=e();