UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 34.8 kB
var t,e;t=void 0,e=function(){const t=Phaser.GameObjects.GetCalcMatrix,e=Phaser.Renderer.Canvas.SetTransform;var i={renderWebGL:function(e,i,s,r){i.updateData();var a=s.camera;a.addToRenderList(i);for(var h,n=t(i,a,r,!s.useCanvas).calc,o=i._displayOriginX,l=i._displayOriginY,u=i.alpha,d=i.customRenderNodes.Submitter||i.defaultRenderNodes.Submitter,c=i.geom,p=0,v=c.length;p<v;p++)(h=c[p]).visible&&h.webglRender(s,d,n,i,u,o,l)},renderCanvas:function(t,i,s,r){i.updateData(),s.addToRenderList(i);var a=t.currentContext;if(e(t,a,i,s,r)){for(var h,n=i._displayOriginX,o=i._displayOriginY,l=i.geom,u=0,d=l.length;u<d;u++)(h=l[u]).visible&&h.canvasRender(a,n,o);a.restore()}}},s=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,a=Phaser.Utils.Array.Remove;class h extends r{constructor(t,e,i,s,r){void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=2),void 0===r&&(r=s),super(t,"rexShapes",[]),this._width=-1,this._height=-1,this.dirty=!0,this.isSizeChanged=!0,this.shapes={},this.setPosition(e,i),this.setSize(s,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 i=this.input;return i&&!i.customHitArea&&(i.hitArea.width=t,i.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,i){return void 0===i&&(i=1),this.dirty=this.dirty||this.lineWidth!==t||this.strokeColor!==e||this.strokeAlpha!==i,this._lineWidth=t,this._strokeColor=e,this._strokeAlpha=i,this}updateShapes(){}updateData(){if(!this.dirty)return this;this.updateShapes();for(var t=this.geom,e=0,i=t.length;e<i;e++){var s=t[e];s.dirty&&s.updateData()}return this.isSizeChanged=!1,this.dirty=!1,this}clear(){return this.geom.length=0,s(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],a(this.geom,e)),this}}Object.assign(h.prototype,i);const n=Phaser.Math.Linear,o=Phaser.Math.Percent;var l={setValue(t,e,i){return null==t||(void 0!==e&&(t=o(t,e,i)),this.value=t),this},addValue(t,e,i){return void 0!==e&&(t=o(t,e,i)),this.value+=t,this},getValue(t,e){var i=this.value;return void 0!==t&&void 0!==e&&(i=n(t,e,i)),i}},u={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 d=Phaser.Scene;var c=function(t){return t instanceof d};const p=Phaser.Game;var v=function(t){return t instanceof p};const y=Phaser.Utils.Objects.GetValue;class g{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(y(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:c(e)?e:e.scene&&c(e.scene)?e.scene:e.parent&&e.parent.scene&&c(e.parent.scene)?e.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:v(t)?t:v(t.game)?t.game:c(t)?t.sys.game:c(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(g.prototype,u);const m=Phaser.Utils.Objects.GetValue;class f extends g{constructor(t,e){super(t,e),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(m(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=P[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 P={no:0,lazy:1,always:2},b=Phaser.Utils.Objects.GetValue;class k extends f{constructor(t,e){super(t,e);var i=this.scene?"update":"step";this.tickEventName=b(e,"tickEventName",i),this.isSceneTicker=!D(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 D=function(t){return"step"===t||"poststep"===t};const T=Phaser.Utils.Objects.GetValue,x=Phaser.Math.Clamp;class S{constructor(t){this.resetFromJSON(t)}resetFromJSON(t){this.state=T(t,"state",R),this.timeScale=T(t,"timeScale",1),this.delay=T(t,"delay",0),this.repeat=T(t,"repeat",0),this.repeatCounter=T(t,"repeatCounter",0),this.repeatDelay=T(t,"repeatDelay",0),this.duration=T(t,"duration",0),this.nowTime=T(t,"nowTime",0),this.justRestart=T(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?E:_,this.repeatCounter=0,this}stop(){return this.state=R,this}update(t,e){this.state!==R&&this.state!==A&&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=A):this.nowTime>=0&&(this.state=E))}get t(){var t;switch(this.state){case R:case _:case C:t=0;break;case E:t=this.nowTime/this.duration;break;case A:t=1}return x(t,0,1)}set t(t){(t=x(t,-1,1))<0?(this.state=_,this.nowTime=-this.delay*t):(this.state=E,this.nowTime=this.duration*t,1===t&&0!==this.repeat&&this.repeatCounter++)}setT(t){return this.t=t,this}get isIdle(){return this.state===R}get isDelay(){return this.state===_}get isCountDown(){return this.state===E}get isRunning(){return this.state===_||this.state===E}get isDone(){return this.state===A}get isOddIteration(){return!(1&~this.repeatCounter)}get isEvenIteration(){return!(1&this.repeatCounter)}}const R=0,_=1,E=2,C=3,A=-1;class w extends k{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 M=Phaser.Utils.Objects.GetValue,L=Phaser.Utils.Objects.GetAdvancedValue,V=Phaser.Tweens.Builders.GetEaseFunction;class O extends w{resetFromJSON(t){return this.timer.resetFromJSON(M(t,"timer")),this.setEnable(M(t,"enable",!0)),this.setTarget(M(t,"target",this.parent)),this.setDelay(L(t,"delay",0)),this.setDuration(L(t,"duration",1e3)),this.setEase(M(t,"ease","Linear")),this.setRepeat(M(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=V(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 i=this.target,s=this.timer;return s.update(t,e),s.isDelay||this.updateTarget(i,s),this.emit("update",i,this),s.isDone&&this.complete(),this}updateTarget(t,e){}}const G=Phaser.Utils.Objects.GetValue,j=Phaser.Math.Linear;class B 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=G(t,"key","value");var i=e[this.propertyKey];return this.fromValue=G(t,"from",i),this.toValue=G(t,"to",i),this.setEase(G(t,"ease",this.ease)),this.setDuration(G(t,"duration",this.duration)),this.setRepeat(G(t,"repeat",0)),this.setDelay(G(t,"delay",0)),this.setRepeatDelay(G(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 i=e.t;i=this.easeFn(i),t[this.propertyKey]=j(this.fromValue,this.toValue,i)}}const F=Phaser.Math.Percent;var N={setEaseValuePropName(t){return this.easeValuePropName=t,this},setEaseValueDuration(t){return this.easeValueDuration=t,this},setEaseValueFunction(t){return this.easeFunction=t,this},stopEaseValue(){return this.easeValueTask&&this.easeValueTask.stop(),this},easeValueTo(t,e,i){return null==t||(void 0!==e&&(t=F(t,e,i)),void 0===this.easeValueTask&&(this.easeValueTask=new B(this,{eventEmitter:null})),this.easeValueTask.restart({key:this.easeValuePropName,to:t,duration:this.easeValueDuration,ease:this.easeFunction})),this},easeValueRepeat(t,e,i,s){return void 0===i&&(i=-1),void 0===s&&(s=0),void 0===this.easeValueTask&&(this.easeValueTask=new B(this,{eventEmitter:null})),this.easeValueTask.restart({key:this.easeValuePropName,from:t,to:e,duration:this.easeValueDuration,ease:this.easeFunction,repeat:i,repeatDelay:s}),this}};const z=Phaser.Utils.Objects.GetValue,X=Phaser.Math.Clamp;var Y={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,i){return null==t||null==e?this.isStroked=!1:(void 0===i&&(i=1),this.isStroked=!0,this.lineWidth=t,this.strokeColor=e,this.strokeAlpha=i),this}},W={enableData(){return void 0===this.data&&(this.data={}),this},setData(t,e){if(this.enableData(),1===arguments.length){var i=t;for(t in i)this.data[t]=i[t]}else this.data[t]=e;return this},getData(t,e){return this.enableData(),void 0===t?this.data:function(t,e,i){if(!t||"number"==typeof t)return i;if("string"==typeof e){if(t.hasOwnProperty(e))return t[e];if(-1===e.indexOf("."))return i;e=e.split(".")}for(var s=e,r=t,a=i,h=0;h<s.length;h++){if(e=s[h],!r.hasOwnProperty(e)){a=i;break}r=a=r[e]}return a}(this.data,t,e)},incData(t,e,i){return void 0===i&&(i=0),this.enableData(),this.setData(t,this.getData(t,i)+e),this},mulData(t,e,i){return void 0===i&&(i=0),this.enableData(),this.setData(t,this.getData(t,i)*e),this},clearData(){return this.data&&s(this.data),this}};class I{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,i,s,r,a,h){}canvasRender(t,e,i){}updateData(){this.dirty=!1}}Object.assign(I.prototype,Y,W);var U=Phaser.Renderer.WebGL.Utils,J=Phaser.Renderer.WebGL.Utils;const K=Phaser.Geom.Polygon.Earcut;class q extends I{constructor(){super(),this.pathData=[],this.pathIndexes=[],this.closePath=!1}updateData(){return this.pathIndexes=K(this.pathData),super.updateData(),this}webglRender(t,e,i,s,r,a,h){this.isFilled&&function(t,e,i,s,r,a,h,n){var o,l,u,d,c,p=U.getTintAppendFloatAlpha(r.fillColor,r.fillAlpha*a),v=r.pathData,y=r.pathIndexes,g=v.length,m=Array(2*g),f=Array(g),P=0,b=0;for(o=0;o<g;o+=2)l=v[o]-h,u=v[o+1]-n,d=i.getX(l,u),c=i.getY(l,u),m[P++]=d,m[P++]=c,f[b++]=p;e.batch(t,y,m,f)}(t,e,i,0,this,r,a,h),this.isStroked&&function(t,e,i,s,r,a,h,n){var o=J.getTintAppendFloatAlpha(r.strokeColor,r.strokeAlpha*a),l=r.pathData,u=l.length-1,d=r.lineWidth,c=!r.closePath,p=s.customRenderNodes.StrokePath||s.defaultRenderNodes.StrokePath,v=[];c&&(u-=2);for(var y=0;y<u;y+=2){var g=l[y]-h,m=l[y+1]-n;y>0&&g===l[y-2]&&m===l[y-1]||v.push({x:g,y:m,width:d})}p.run(t,e,v,d,c,i,o,o,o,o)}(t,e,i,s,this,r,a,h)}canvasRender(t,e,i){var s=this.pathData,r=s.length-1,a=s[0]-e,h=s[1]-i;t.beginPath(),t.moveTo(a,h),this.closePath||(r-=2);for(var n=2;n<r;n+=2){var o=s[n]-e,l=s[n+1]-i;t.lineTo(o,l)}this.closePath&&t.closePath(),this.isFilled&&(function(t,e,i,s){var r=i||e.fillColor,a=s||e.fillAlpha,h=(16711680&r)>>>16,n=(65280&r)>>>8,o=255&r;t.fillStyle="rgba("+h+","+n+","+o+","+a+")"}(t,this),t.fill()),this.isStroked&&(function(t,e,i,s){var r=i||e.strokeColor,a=s||e.strokeAlpha,h=(16711680&r)>>>16,n=(65280&r)>>>8,o=255&r;t.strokeStyle="rgba("+h+","+n+","+o+","+a+")",t.lineWidth=e.lineWidth}(t,this),t.stroke())}}var H=function(t,e,i){var s=i.length;if(s>=2){var r=i[s-2],a=i[s-1];if(t===r&&e===a)return i}return i.push(t,e),i};const Q=Phaser.Math.DegToRad;Phaser.Math.DegToRad;const Z=Phaser.Math.Interpolation.QuadraticBezier,$=Phaser.Math.Interpolation.CubicBezier,tt=Phaser.Math.Interpolation.CatmullRom;var et=function(t){var e=t.length;if(e<2)return t;var i=t[e-2],s=t[e-1];return t.push(i),t.push(s),t},it={clear(){return this.start(),this},start(){return this.startAt(),this},startAt(t,e){return this.restorePathData(),this.accumulationLengths=void 0,function(t,e,i){i.length=0,null!=t&&i.push(t,e)}(t,e,this.pathData),this.firstPointX=t,this.firstPointY=e,this.lastPointX=t,this.lastPointY=e,this},lineTo(t,e,i){return void 0===i&&(i=!1),i&&(t+=this.lastPointX,e+=this.lastPointY),H(t,e,this.pathData),this.lastPointX=t,this.lastPointY=e,this},verticalLineTo(t,e){return this.lineTo(t,this.lastPointY,e),this},horizontalLineTo(t,e){return this.lineTo(this.lastPointX,t,e),this},ellipticalArc(t,e,i,s,r,a,h){return void 0===h&&(h=!1),function(t,e,i,s,r,a,h,n,o){h&&a>r?a-=360:!h&&a<r&&(a+=360);var l=Q(a-r)/n;r=Q(r);for(var u=0;u<=n;u++){var d=r+l*u,c=t+i*Math.cos(d),p=e+s*Math.sin(d);H(c,p,o)}}(t,e,i,s,r,a,h,this.iterations,this.pathData),this.lastPointX=this.pathData[this.pathData.length-2],this.lastPointY=this.pathData[this.pathData.length-1],this},arc(t,e,i,s,r,a){return this.ellipticalArc(t,e,i,i,s,r,a),this},quadraticBezierTo(t,e,i,s){return function(t,e,i,s,r,a){for(var h=a.length,n=a[h-2],o=a[h-1],l=1,u=r-1;l<=u;l++){var d=l/u;a.push(Z(d,n,t,i),Z(d,o,e,s))}}(t,e,i,s,this.iterations,this.pathData),this.lastPointX=i,this.lastPointY=s,this},cubicBezierTo(t,e,i,s,r,a){return function(t,e,i,s,r,a,h,n){for(var o=n.length,l=n[o-2],u=n[o-1],d=1,c=h-1;d<=c;d++){var p=d/c;n.push($(p,l,t,i,r),$(p,u,e,s,a))}}(t,e,i,s,r,a,this.iterations,this.pathData),this.lastPointX=r,this.lastPointY=a,this},catmullRomTo(...t){return function(t,e,i){for(var s=i.length,r=[i[s-2]],a=[i[s-1]],h=0,n=t.length;h<n;h+=2)r.push(t[h]),a.push(t[h+1]);h=1;for(var o=e-1;h<=o;h++){var l=h/o;i.push(tt(r,l),tt(a,l))}}(t,this.iterations,this.pathData),this.lastPointX=t[t.length-2],this.lastPointY=t[t.length-1],this},close(){var t=this.pathData[0],e=this.pathData[1];return t===this.lastPointX&&e===this.lastPointY||this.lineTo(t,e),this.closePath=!0,this},end(){return et(this.pathData),this}};const st=Phaser.Math.RotateAround,rt=Phaser.Math.DegToRad;Phaser.Math.RotateAround;var at={rotateAround(t,e,i){if(0===this.pathData.length)return this;!function(t,e,i,s){for(var r={x:0,y:0},a=0,h=s.length-1;a<h;a+=2)r.x=s[a],r.y=s[a+1],st(r,t,e,i),s[a]=r.x,s[a+1]=r.y}(t,e,i=rt(i),this.pathData);var s=this.pathData.length;return this.lastPointX=this.pathData[s-2],this.lastPointY=this.pathData[s-1],this},scale(t,e,i,s){return 0===this.pathData.length||(function(t,e,i,s,r){for(var a=0,h=r.length-1;a<h;a+=2){var n=r[a]-t,o=r[a+1]-e;n*=i,o*=s,r[a]=n+t,r[a+1]=o+e}}(t,e,i,s,this.pathData),this.lastPointX=this.pathData[pathDataCnt-2],this.lastPointY=this.pathData[pathDataCnt-1]),this},offset(t,e){return function(t,e,i){for(var s=0,r=i.length-1;s<r;s+=2)i[s]+=t,i[s+1]+=e}(t,e,this.pathData),this}},ht={savePathData(){return this.pathDataSaved||(this.pathDataSave=[...this.pathData],this.pathData.length=0,this.pathDataSaved=!0),this},restorePathData(){return this.pathDataSaved?(function(t,e,i,s){void 0===i&&(i=0),void 0===s&&(s=e.length),t.length=s-i;for(var r=0,a=t.length;r<a;r++)t[r]=e[r+i]}(this.pathData,this.pathDataSave),this.pathDataSave=void 0,this.pathDataSaved=!1,this):this}};const nt=Phaser.Math.Distance.Between,ot=Phaser.Math.Wrap,lt=Phaser.Math.Linear;var ut=function(t,e,i,s,r){if(void 0===s&&(s=i,i=0),(i=pt(i))!==(s=pt(s))){var a=e[e.length-1],h=a*i,n=a*s;i<s?dt(t,e,h,n,r):(dt(t,e,h,a,r),dt(t,e,0,n,r)),et(r)}},dt=function(t,e,i,s,r){for(var a=i>0,h=0,n=e.length;h<n;h++){var o=2*h,l=e[h];if(a){if(l<i)continue;if(l==i)a=!1;else{var u=1-(l-i)/(l-e[h-1]);r.push(ct(t,o-2,o,u)),r.push(ct(t,o-1,o+1,u)),a=!1}}if(!(l<=s)){u=1-(l-s)/(l-e[h-1]),r.push(ct(t,o-2,o,u)),r.push(ct(t,o-1,o+1,u));break}if(r.push(t[o]),r.push(t[o+1]),l===s)break}},ct=function(t,e,i,s){var r=t[e],a=t[i];return lt(r,a,s)},pt=function(t){return 0===t?0:t%1==0?1:ot(t,0,1)},vt={updateAccumulationLengths(){if(null==this.accumulationLengths)this.accumulationLengths=[];else if(this.accumulationLengths.length===this.pathData.length/2)return this;for(var t,e,i,s,r=this.accumulationLengths,a=this.pathData,h=0,n=0,o=a.length;n<o;n+=2)i=a[n],s=a[n+1],h+=void 0===t?0:nt(t,e,i,s),r.push(h),t=i,e=s;return this.totalPathLength=h,this},setDisplayPathSegment(t,e){return this.pathDataSaved||(this.updateAccumulationLengths(),this.savePathData()),this.pathData.length=0,ut(this.pathDataSave,this.accumulationLengths,t,e,this.pathData),this},appendFromPathSegment(t,e,i){return void 0===e?this.pathData.push(...t.pathData):(t.updateAccumulationLengths(),ut(t.pathData,t.accumulationLengths,e,i,this.pathData)),this.firstPointX=this.pathData[0],this.firstPointY=this.pathData[1],this.lastPointX=this.pathData[this.pathData.length-2],this.lastPointY=this.pathData[this.pathData.length-1],this}},yt={draw(t,e,i){var s=this.toPoints();return e&&t.fillPoints(s,this.closePath,this.closePath),i&&t.strokePoints(s,this.closePath,this.closePath),this}};const gt=Phaser.Geom.Polygon;class mt{constructor(t){void 0===t&&(t=[]),this.pathData=t,this.closePath=!1,this.setIterations(32),this.firstPointX=void 0,this.firstPointY=void 0,this.lastPointX=void 0,this.lastPointY=void 0,this.accumulationLengths=void 0}setIterations(t){return this.iterations=t,this}toPoints(){return function(t,e){void 0===e&&(e=[]);for(var i=0,s=t.length-1;i<s;i+=2)e.push({x:t[i],y:t[i+1]});return e}(this.pathData)}toPolygon(t){return function(t,e){return void 0===e&&(e=new gt),e.setTo(t),e}(this.pathData,t)}}Object.assign(mt.prototype,it,at,ht,vt,yt);class ft extends q{constructor(){super(),this.builder=new mt(this.pathData)}get iterations(){return this.builder.iterations}set iterations(t){this.dirty=this.dirty||this.builder.iterations!==t,this.builder.setIterations(t)}setIterations(t){return this.iterations=t,this}get lastPointX(){return this.builder.lastPointX}get lastPointY(){return this.builder.lastPointY}start(){return this.builder.start(),this.dirty=!0,this}startAt(t,e){return this.builder.startAt(t,e),this.dirty=!0,this}lineTo(t,e,i){return this.builder.lineTo(t,e,i),this.dirty=!0,this}verticalLineTo(t,e){return this.builder.verticalLineTo(t,e),this.dirty=!0,this}horizontalLineTo(t,e){return this.builder.horizontalLineTo(t,e),this.dirty=!0,this}ellipticalArc(t,e,i,s,r,a,h){return this.builder.ellipticalArc(t,e,i,s,r,a,h),this.dirty=!0,this}arc(t,e,i,s,r,a){return this.builder.arc(t,e,i,s,r,a),this.dirty=!0,this}quadraticBezierTo(t,e,i,s){return this.builder.quadraticBezierTo(t,e,i,s),this.dirty=!0,this}cubicBezierTo(t,e,i,s,r,a){return this.builder.cubicBezierTo(t,e,i,s,r,a),this.dirty=!0,this}catmullRomTo(...t){return this.builder.catmullRomTo(...t),this.dirty=!0,this}close(){return this.builder.close(),this.closePath=this.builder.closePath,this.dirty=!0,this}end(){return this.builder.end(),this.dirty=!0,this}rotateAround(t,e,i){return this.builder.rotateAround(t,e,i),this.dirty=!0,this}scale(t,e,i,s){return this.builder.scale(t,e,i,s),this.dirty=!0,this}offset(t,e){return this.builder.offset(t,e),this.dirty=!0,this}toPolygon(t){return this.builder.toPolygon(t)}appendPathFrom(t,e,i){return this.builder.appendFromPathSegment(t.builder,e,i),this}copyPathFrom(t,e,i){return this.builder.clear().appendFromPathSegment(t.builder,e,i),this}setDisplayPathSegment(t,e){return this.builder.setDisplayPathSegment(t,e),this}}Phaser.Renderer.WebGL.Utils,Phaser.Utils.Objects.GetValue,Phaser.Renderer.WebGL.Utils;var Pt=function(t){return t.x>0&&t.y>0},bt=function(t,e,i,s,r){t.setIterations(r).start();var a=s.tl;if(Pt(a))if(a.convex){var h=a.x,n=a.y;t.ellipticalArc(h,n,a.x,a.y,180,270,!1)}else h=0,n=0,t.ellipticalArc(h,n,a.x,a.y,90,0,!0);else t.lineTo(0,0);return a=s.tr,Pt(a)?a.convex?(h=e-a.x,n=a.y,t.ellipticalArc(h,n,a.x,a.y,270,360,!1)):(h=e,n=0,t.ellipticalArc(h,n,a.x,a.y,180,90,!0)):t.lineTo(e,0),a=s.br,Pt(a)?a.convex?(h=e-a.x,n=i-a.y,t.ellipticalArc(h,n,a.x,a.y,0,90,!1)):(h=e,n=i,t.ellipticalArc(h,n,a.x,a.y,270,180,!0)):t.lineTo(e,i),a=s.bl,Pt(a)?a.convex?(h=a.x,n=i-a.y,t.ellipticalArc(h,n,a.x,a.y,90,180,!1)):(h=0,n=i,t.ellipticalArc(h,n,a.x,a.y,360,270,!0)):t.lineTo(0,i),t.close(),t},kt=Phaser.Math.RadToDeg,Dt=function(t,e,i,s,r){var a=e*r,h=s.tl;if(Pt(h)){l=a>h.x?90:kt(Math.acos((h.x-a)/h.x));var n=h.x,o=h.y;t.ellipticalArc(n,o,h.x,h.y,180,180+l,!1)}else t.lineTo(0,0);if(h=s.tr,Pt(h)&&a>e-h.x){var l=90-kt(Math.acos((a-(e-h.x))/h.x));n=e-h.x,o=h.y,t.ellipticalArc(n,o,h.x,h.y,270,270+l,!1)}else t.lineTo(a,0);h=s.br,Pt(h)&&a>e-h.x?(l=90-kt(Math.acos((a-(e-h.x))/h.x)),n=e-h.x,o=i-h.y,t.ellipticalArc(n,o,h.x,h.y,90-l,90,!1)):t.lineTo(a,i),h=s.bl,Pt(h)?(l=a>h.x?90:kt(Math.acos((h.x-a)/h.x)),n=h.x,o=i-h.y,t.ellipticalArc(n,o,h.x,h.y,180-l,180,!1)):t.lineTo(0,i)},Tt=Phaser.Math.RadToDeg,xt=function(t,e,i,s,r){var a=i*r,h=s.tl;if(Pt(h)){l=a>h.y?90:Tt(Math.acos((h.y-a)/h.y));var n=h.x,o=h.y;t.ellipticalArc(n,o,h.x,h.y,270-l,270,!1)}else t.lineTo(0,0);if(h=s.tr,Pt(h)?(l=a>h.y?90:Tt(Math.acos((h.y-a)/h.y)),n=e-h.x,o=h.y,t.ellipticalArc(n,o,h.x,h.y,270,270+l,!1)):t.lineTo(e,0),h=s.br,Pt(h)&&a>i-h.y){var l=90-Tt(Math.acos((a-(i-h.y))/h.y));n=e-h.x,o=i-h.y,t.ellipticalArc(n,o,h.x,h.y,0,0+l,!1)}else t.lineTo(e,a);h=s.bl,Pt(h)&&a>i-h.y?(l=90-Tt(Math.acos((a-(i-h.y))/h.y)),n=h.x,o=i-h.y,t.ellipticalArc(n,o,h.x,h.y,180-l,180,!1)):t.lineTo(0,a)},St=Phaser.Math.RadToDeg,Rt=function(t,e,i,s,r){var a=e*r,h=s.tr;if(Pt(h)){l=a>h.x?90:St(Math.acos((h.x-a)/h.x));var n=e-h.x,o=h.y;t.ellipticalArc(n,o,h.x,h.y,360-l,360,!1)}else t.lineTo(e,0);if(h=s.br,Pt(h)?(l=a>h.x?90:St(Math.acos((h.x-a)/h.x)),n=e-h.x,o=i-h.y,t.ellipticalArc(n,o,h.x,h.y,0,0+l,!1)):t.lineTo(e,i),h=s.bl,Pt(h)&&a>e-h.x){var l=90-St(Math.acos((a-(e-h.x))/h.x));n=h.x,o=i-h.y,t.ellipticalArc(n,o,h.x,h.y,90,90+l,!1)}else t.lineTo(e-a,i);h=s.tl,Pt(h)&&a>e-h.x?(l=90-St(Math.acos((a-(e-h.x))/h.x)),n=h.x,o=h.y,t.ellipticalArc(n,o,h.x,h.y,270-l,270,!1)):t.lineTo(e-a,0)},_t=Phaser.Math.RadToDeg,Et=function(t,e,i,s,r){var a=i*r,h=s.br;if(Pt(h)){l=a>h.y?90:_t(Math.acos((h.y-a)/h.y));var n=e-h.x,o=i-h.y;t.ellipticalArc(n,o,h.x,h.y,90-l,90,!1)}else t.lineTo(e,i);if(h=s.bl,Pt(h)?(l=a>h.y?90:_t(Math.acos((h.y-a)/h.y)),n=h.x,o=i-h.y,t.ellipticalArc(n,o,h.x,h.y,90,90+l,!1)):t.lineTo(0,i),h=s.tl,Pt(h)&&a>i-h.y){var l=90-_t(Math.acos((a-(i-h.y))/h.y));n=h.x,o=h.y,t.ellipticalArc(n,o,h.x,h.y,180,180+l,!1)}else t.lineTo(0,i-a);h=s.tr,Pt(h)&&a>i-h.y?(l=90-_t(Math.acos((a-(i-h.y))/h.y)),n=e-h.x,o=h.y,t.ellipticalArc(n,o,h.x,h.y,360-l,360,!1)):t.lineTo(e,i-a)};const Ct=Phaser.Utils.Objects.GetValue;class At{constructor(t,e,i,s,r){void 0===t&&(t=0),void 0===e&&(e=t),void 0===i&&(i=0),void 0===s&&(s=0),void 0===r&&(r=0),this.cornerRadius={},this._width=0,this._height=0,this.setTo(t,e,i,s,r)}setTo(t,e,i,s,r){return this.setPosition(t,e),this.setRadius(r),this.setSize(i,s),this}setPosition(t,e){return this.x=t,this.y=e,this}setRadius(t){return void 0===t&&(t=0),this.radius=t,this}setSize(t,e){return this.width=t,this.height=e,this}get minWidth(){var t=this.cornerRadius;return Math.max(t.tl.x+t.tr.x,t.bl.x+t.br.x)}get minHeight(){var t=this.cornerRadius;return Math.max(t.tl.y+t.bl.y,t.tr.y+t.br.y)}get width(){return this._width}set width(t){null==t&&(t=0),this._width=Math.max(t,this.minWidth)}get height(){return this._height}set height(t){null==t&&(t=0),this._height=Math.max(t,this.minHeight)}get radius(){var t=this.cornerRadius;return Math.max(t.tl.x,t.tl.y,t.tr.x,t.tr.y,t.bl.x,t.bl.y,t.br.x,t.br.y)}set radius(t){var e,i;"number"==typeof t?(e=t,i=t):(e=Ct(t,"x",0),i=Ct(t,"y",0));var s=this.cornerRadius;s.tl=wt(Ct(t,"tl",void 0),e,i),s.tr=wt(Ct(t,"tr",void 0),e,i),s.bl=wt(Ct(t,"bl",void 0),e,i),s.br=wt(Ct(t,"br",void 0),e,i)}get radiusTL(){var t=this.cornerRadius.tl;return Math.max(t.x,t.y)}set radiusTL(t){Mt(this.cornerRadius.tl,t)}get radiusTR(){var t=this.cornerRadius.tr;return Math.max(t.x,t.y)}set radiusTR(t){Mt(this.cornerRadius.tr,t)}get radiusBL(){var t=this.cornerRadius.bl;return Math.max(t.x,t.y)}set radiusBL(t){Mt(this.cornerRadius.bl,t)}get radiusBR(){var t=this.cornerRadius.br;return Math.max(t.x,t.y)}set radiusBR(t){Mt(this.cornerRadius.br,t)}}var wt=function(t,e,i){return void 0===t?t={x:e,y:i}:"number"==typeof t&&(t={x:t,y:t}),Lt(t),t},Mt=function(t,e){"number"==typeof e?(t.x=e,t.y=e):(t.x=Ct(e,"x",0),t.y=Ct(e,"y",0)),Lt(t)},Lt=function(t){t.convex=t.x>=0||t.y>=0,t.x=Math.abs(t.x),t.y=Math.abs(t.y)},Vt={x:0,h:0,horizontal:0,"left-to-right":0,y:1,v:1,vertical:1,"top-to-bottom":1};const Ot=Phaser.Utils.Objects.GetValue,Gt=Phaser.Utils.Objects.IsPlainObject;class jt extends(function(t){class e extends t{bootProgressBase(t){this.eventEmitter=z(t,"eventEmitter",this);var e=z(t,"valuechangeCallback",null);if(null!==e){var i=z(t,"valuechangeCallbackScope",void 0);this.eventEmitter.on("valuechange",e,i)}return this.setEaseValuePropName("value").setEaseValueDuration(z(t,"easeValue.duration",0)).setEaseValueFunction(z(t,"easeValue.ease","Linear")),this}get value(){return this._value}set value(t){t=X(t,0,1);var e=this._value,i=e!=t;this.dirty=this.dirty||i,this._value=t,i&&this.eventEmitter.emit("valuechange",this._value,e,this.eventEmitter)}}return Object.assign(e.prototype,l,N),e}(h)){constructor(t,e,i,s,r,a,h,n,o){Gt(e)?(e=(o=e).x,i=o.y,s=o.width,r=o.height,a=o.radius,h=o.barColor,n=o.value):Gt(s)?(s=(o=s).width,r=o.height,a=o.radius,h=o.barColor,n=o.value):Gt(a)&&(a=(o=a).radius,h=o.barColor,n=o.value),void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=1),void 0===r&&(r=s),void 0===a&&(a=0),void 0===n&&(n=0),super(t,e,i,s,r,o),this.type="rexRoundRectangleProgress",this.rrGeom=new At,this.bootProgressBase(o),this.addShape((new ft).setName("trackFill")).addShape((new ft).setName("bar")).addShape((new ft).setName("trackStroke")),this.setTrackColor(Ot(o,"trackColor",void 0)),this.setBarColor(h),this.setTrackStroke(Ot(o,"trackStrokeThickness",2),Ot(o,"trackStrokeColor",void 0)),this.setOrientation(Ot(o,"orientation",0)),this.setRTL(Ot(o,"rtl",!1)),this.setRadius(a),this.setIteration(Ot(a,"iteration",void 0)),this.setValue(n)}get trackColor(){return this._trackColor}set trackColor(t){this.dirty=this.dirty||this._trackColor!=t,this._trackColor=t}setTrackColor(t){return this.trackColor=t,this}get trackStrokeColor(){return this._trackStrokeColor}set trackStrokeColor(t){this.dirty=this.dirty||this._trackStrokeColor!=t,this._trackStrokeColor=t}get trackStrokeThickness(){return this._trackStrokeThickness}set trackStrokeThickness(t){this.dirty=this.dirty||this._trackStrokeThickness!=t,this._trackStrokeThickness=t}setTrackStroke(t,e){return this.trackStrokeThickness=t,this.trackStrokeColor=e,this}get barColor(){return this._barColor}set barColor(t){this.dirty=this.dirty||this._barColor!=t,this._barColor=t}setBarColor(t){return this.barColor=t,this}get orientation(){return this._orientation}set orientation(t){var e;"string"==typeof(e=t)&&(e=Vt[e]),t=e,this.dirty=this.dirty||this._orientation!=t,this._orientation=t}setOrientation(t){return this.orientation=t,this}get rtl(){return this._rtl}set rtl(t){t=!!t,this.dirty=this.dirty||this._rtl!=t,this._rtl=t}setRTL(t){return void 0===t&&(t=!0),this.rtl=t,this}get radius(){return this.rrGeom.radius}set radius(t){this.rrGeom.setRadius(t),this.dirty=!0}get radiusTL(){return this.rrGeom.radiusTL}set radiusTL(t){this.rrGeom.radiusTL=t,this.dirty=!0}get radiusTR(){return this.rrGeom.radiusTR}set radiusTR(t){this.rrGeom.radiusTR=t,this.dirty=!0}get radiusBL(){return this.rrGeom.radiusBL}set radiusBL(t){this.rrGeom.radiusBL=t,this.dirty=!0}get radiusBR(){return this.rrGeom.radiusBR}set radiusBR(t){this.rrGeom.radiusBR=t,this.dirty=!0}setRadius(t){return void 0===t&&(t=0),this.radius=t,this}setRadiusTL(t){return void 0===t&&(t=0),this.radiusTL=t,this}setRadiusTR(t){return void 0===t&&(t=0),this.radiusTR=t,this}setRadiusBL(t){return void 0===t&&(t=0),this.radiusBL=t,this}setRadiusBR(t){return void 0===t&&(t=0),this.radiusBR=t,this}get cornerRadius(){return this.rrGeom.cornerRadius}set cornerRadius(t){this.radius=t}setCornerRadius(t){return this.setRadius(t)}get iteration(){return this._iteration}set iteration(t){void 0!==this._iteration?this._iteration!==t&&(this._iteration=t,this.dirty=!0):this._iteration=t}setIteration(t){return void 0===t&&(t=6),this.iteration=t,this}}var Bt={updateShapes:function(){var t=this.width,e=this.height,i=this.rrGeom.cornerRadius,s=this.value,r=this.orientation,a=this.rtl,h=this.iteration+1,n=this.getShape("trackFill");n.fillStyle(this.trackColor),n.isFilled&&bt(n,t,e,i,h);var o=this.getShape("bar");o.fillStyle(this.barColor),o.isFilled&&function(t,e,i,s,r,a,h,n){t.setIterations(n).start(),0===r||(1===r?bt(t,e,i,s,n):((0===a?h?Rt:Dt:h?Et:xt)(t,e,i,s,r),t.close()))}(o,t,e,i,s,r,a,h);var l=this.getShape("trackStroke");l.lineStyle(this.trackStrokeThickness,this.trackStrokeColor),l.isStroked&&bt(l,t,e,i,h)}};function Ft(t,e,i,s,r,a,h){var n=new jt(this.scene,t,e,i,s,r,a,h);return this.scene.add.existing(n),n}Object.assign(jt.prototype,Bt);const Nt=Phaser.GameObjects.BuildGameObject;function zt(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=new jt(this.scene,t);return Nt(this.scene,i,t),i}var Xt=function(t){return null==t||""===t||0===t.length};class Yt extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexRoundRectangleProgress",Ft,zt)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,e,i,s){if(void 0===s&&(s="."),"object"==typeof t)if(Xt(e)){if(null==i)return;"object"==typeof i&&(t=i)}else{"string"==typeof e&&(e=e.split(s));var r=e.pop(),a=function(t,e,i){var s=t;if(Xt(e));else{var r;"string"==typeof e&&(e=e.split("."));for(var a=0,h=e.length;a<h;a++){var n;null!=s[r=e[a]]&&"object"==typeof s[r]||(n=a===h-1?void 0===i?{}:i:{},s[r]=n),s=s[r]}}return s}(t,e);a[r]=i}}(window,"RexPlugins.GameObjects.RoundRectangleProgress",jt),Yt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexroundrectangleprogressplugin=e();