phaser4-rex-plugins
Version:
8 lines (7 loc) • 31.4 kB
JavaScript
var t,i;t=void 0,i=function(){const t=Phaser.GameObjects.GetCalcMatrix,i=Phaser.Renderer.Canvas.SetTransform;var e={renderWebGL:function(i,e,s,h){e.updateData();var r=s.camera;r.addToRenderList(e);for(var a,n=t(e,r,h,!s.useCanvas).calc,o=e._displayOriginX,l=e._displayOriginY,u=e.alpha,d=e.customRenderNodes.Submitter||e.defaultRenderNodes.Submitter,p=e.geom,c=0,g=p.length;c<g;c++)(a=p[c]).visible&&a.webglRender(s,d,n,e,u,o,l)},renderCanvas:function(t,e,s,h){e.updateData(),s.addToRenderList(e);var r=t.currentContext;if(i(t,r,e,s,h)){for(var a,n=e._displayOriginX,o=e._displayOriginY,l=e.geom,u=0,d=l.length;u<d;u++)(a=l[u]).visible&&a.canvasRender(r,n,o);r.restore()}}},s=function(t){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))t.length=0;else for(var i in t)delete t[i];return t};const h=Phaser.GameObjects.Shape,r=Phaser.Utils.Array.Remove;class a extends h{constructor(t,i,e,s,h){void 0===i&&(i=0),void 0===e&&(e=0),void 0===s&&(s=2),void 0===h&&(h=s),super(t,"rexShapes",[]),this._width=-1,this._height=-1,this.dirty=!0,this.isSizeChanged=!0,this.shapes={},this.setPosition(i,e),this.setSize(s,h),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,i){this.isSizeChanged=this.isSizeChanged||this._width!==t||this._height!==i,this.dirty=this.dirty||this.isSizeChanged,this._width=t,this._height=i,this.updateDisplayOrigin();var e=this.input;return e&&!e.customHitArea&&(e.hitArea.width=t,e.hitArea.height=i),this}resize(t,i){return this.setSize(t,i),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,i){return void 0===i&&(i=1),this.dirty=this.dirty||this.fillColor!==t||this.fillAlpha!==i,this._fillColor=t,this._fillAlpha=i,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,i,e){return void 0===e&&(e=1),this.dirty=this.dirty||this.lineWidth!==t||this.strokeColor!==i||this.strokeAlpha!==e,this._lineWidth=t,this._strokeColor=i,this._strokeAlpha=e,this}updateShapes(){}updateData(){if(!this.dirty)return this;this.updateShapes();for(var t=this.geom,i=0,e=t.length;i<e;i++){var s=t[i];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 i=t.name;return i&&(this.shapes[i]=t),this.dirty=!0,this}deleteShape(t){var i=this.getShape(t);return i&&(delete this.shapes[t],r(this.geom,i)),this}}Object.assign(a.prototype,e);var n={setTrackFillStyle(t,i){return void 0===i&&(i=1),this.dirty=this.dirty||this.trackFillColor!==t||this.trackFillAlpha!==i,this.trackFillColor=t,this.trackFillAlpha=i,this},setFalseValueTrackFillStyle(t,i){return void 0===i&&(i=1),this.dirty=this.dirty||this.falseValueTrackColor!==t||this.uncheckedTrackFillAlpha!==i,this.falseValueTrackColor=t,this.falseValueTrackFillAlpha=i,this},setThumbStyle(t,i){return void 0===i&&(i=1),this.dirty=this.dirty||this.thumbColor!==t||this.checkAlpha!==i,this.thumbColor=t,this.thumbAlpha=i,this}},o={setTrackSize(t,i){return this.dirty=this.dirty||this.trackWidth!==t||this.trackHeight!==i,this.trackWidth=t,this.trackHeight=i,this},setTrackRadius(t){return this.dirty=this.dirty||this.trackRadius!==t,this.trackRadius=t,this},setThumbSize(t,i){return void 0===i&&(i=t),this.dirty=this.dirty||this.thumbWidth!==t||this.thumbHeight!==i,this.thumbWidth=t,this.thumbHeight=i,this},setThumbRadius(t){return this.dirty=this.dirty||this.thumbRadius!==t,this.thumbRadius=t,this}},l={setThumbPosition(t,i){return void 0===i&&(i=1-t),this.thumbLeftX=t,this.thumbRightX=i,this},setRTL(t){return void 0===t&&(t=!0),this.rtl=t,this}},u={fillStyle:function(t,i){return null==t?this.isFilled=!1:(void 0===i&&(i=1),this.isFilled=!0,this.fillColor=t,this.fillAlpha=i),this},lineStyle:function(t,i,e){return null==t||null==i?this.isStroked=!1:(void 0===e&&(e=1),this.isStroked=!0,this.lineWidth=t,this.strokeColor=i,this.strokeAlpha=e),this}},d={enableData(){return void 0===this.data&&(this.data={}),this},setData(t,i){if(this.enableData(),1===arguments.length){var e=t;for(t in e)this.data[t]=e[t]}else this.data[t]=i;return this},getData(t,i){return this.enableData(),void 0===t?this.data:function(t,i,e){if(!t||"number"==typeof t)return e;if("string"==typeof i){if(t.hasOwnProperty(i))return t[i];if(-1===i.indexOf("."))return e;i=i.split(".")}for(var s=i,h=t,r=e,a=0;a<s.length;a++){if(i=s[a],!h.hasOwnProperty(i)){r=e;break}h=r=h[i]}return r}(this.data,t,i)},incData(t,i,e){return void 0===e&&(e=0),this.enableData(),this.setData(t,this.getData(t,e)+i),this},mulData(t,i,e){return void 0===e&&(e=0),this.enableData(),this.setData(t,this.getData(t,e)*i),this},clearData(){return this.data&&s(this.data),this}};class p{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,i,e,s,h,r,a){}canvasRender(t,i,e){}updateData(){this.dirty=!1}}Object.assign(p.prototype,u,d);var c=Phaser.Renderer.WebGL.Utils,g=Phaser.Renderer.WebGL.Utils;const v=Phaser.Geom.Polygon.Earcut;class m extends p{constructor(){super(),this.pathData=[],this.pathIndexes=[],this.closePath=!1}updateData(){return this.pathIndexes=v(this.pathData),super.updateData(),this}webglRender(t,i,e,s,h,r,a){this.isFilled&&function(t,i,e,s,h,r,a,n){var o,l,u,d,p,g=c.getTintAppendFloatAlpha(h.fillColor,h.fillAlpha*r),v=h.pathData,m=h.pathIndexes,y=v.length,f=Array(2*y),D=Array(y),P=0,k=0;for(o=0;o<y;o+=2)l=v[o]-a,u=v[o+1]-n,d=e.getX(l,u),p=e.getY(l,u),f[P++]=d,f[P++]=p,D[k++]=g;i.batch(t,m,f,D)}(t,i,e,0,this,h,r,a),this.isStroked&&function(t,i,e,s,h,r,a,n){var o=g.getTintAppendFloatAlpha(h.strokeColor,h.strokeAlpha*r),l=h.pathData,u=l.length-1,d=h.lineWidth,p=!h.closePath,c=s.customRenderNodes.StrokePath||s.defaultRenderNodes.StrokePath,v=[];p&&(u-=2);for(var m=0;m<u;m+=2){var y=l[m]-a,f=l[m+1]-n;m>0&&y===l[m-2]&&f===l[m-1]||v.push({x:y,y:f,width:d})}c.run(t,i,v,d,p,e,o,o,o,o)}(t,i,e,s,this,h,r,a)}canvasRender(t,i,e){var s=this.pathData,h=s.length-1,r=s[0]-i,a=s[1]-e;t.beginPath(),t.moveTo(r,a),this.closePath||(h-=2);for(var n=2;n<h;n+=2){var o=s[n]-i,l=s[n+1]-e;t.lineTo(o,l)}this.closePath&&t.closePath(),this.isFilled&&(function(t,i,e,s){var h=e||i.fillColor,r=s||i.fillAlpha,a=(16711680&h)>>>16,n=(65280&h)>>>8,o=255&h;t.fillStyle="rgba("+a+","+n+","+o+","+r+")"}(t,this),t.fill()),this.isStroked&&(function(t,i,e,s){var h=e||i.strokeColor,r=s||i.strokeAlpha,a=(16711680&h)>>>16,n=(65280&h)>>>8,o=255&h;t.strokeStyle="rgba("+a+","+n+","+o+","+r+")",t.lineWidth=i.lineWidth}(t,this),t.stroke())}}var y=function(t,i,e){var s=e.length;if(s>=2){var h=e[s-2],r=e[s-1];if(t===h&&i===r)return e}return e.push(t,i),e};const f=Phaser.Math.DegToRad;var D=function(t,i,e,s,h,r,a,n,o){a&&r>h?r-=360:!a&&r<h&&(r+=360);var l=f(r-h)/n;h=f(h);for(var u=0;u<=n;u++){var d=h+l*u,p=t+e*Math.cos(d),c=i+s*Math.sin(d);y(p,c,o)}return o};Phaser.Math.DegToRad;const P=Phaser.Math.Interpolation.QuadraticBezier,k=Phaser.Math.Interpolation.CubicBezier,T=Phaser.Math.Interpolation.CatmullRom;var b=function(t){var i=t.length;if(i<2)return t;var e=t[i-2],s=t[i-1];return t.push(e),t.push(s),t},_={clear(){return this.start(),this},start(){return this.startAt(),this},startAt(t,i){return this.restorePathData(),this.accumulationLengths=void 0,function(t,i,e){e.length=0,null!=t&&e.push(t,i)}(t,i,this.pathData),this.firstPointX=t,this.firstPointY=i,this.lastPointX=t,this.lastPointY=i,this},lineTo(t,i,e){return void 0===e&&(e=!1),e&&(t+=this.lastPointX,i+=this.lastPointY),y(t,i,this.pathData),this.lastPointX=t,this.lastPointY=i,this},verticalLineTo(t,i){return this.lineTo(t,this.lastPointY,i),this},horizontalLineTo(t,i){return this.lineTo(this.lastPointX,t,i),this},ellipticalArc(t,i,e,s,h,r,a){return void 0===a&&(a=!1),D(t,i,e,s,h,r,a,this.iterations,this.pathData),this.lastPointX=this.pathData[this.pathData.length-2],this.lastPointY=this.pathData[this.pathData.length-1],this},arc(t,i,e,s,h,r){return this.ellipticalArc(t,i,e,e,s,h,r),this},quadraticBezierTo(t,i,e,s){return function(t,i,e,s,h,r){for(var a=r.length,n=r[a-2],o=r[a-1],l=1,u=h-1;l<=u;l++){var d=l/u;r.push(P(d,n,t,e),P(d,o,i,s))}}(t,i,e,s,this.iterations,this.pathData),this.lastPointX=e,this.lastPointY=s,this},cubicBezierTo(t,i,e,s,h,r){return function(t,i,e,s,h,r,a,n){for(var o=n.length,l=n[o-2],u=n[o-1],d=1,p=a-1;d<=p;d++){var c=d/p;n.push(k(c,l,t,e,h),k(c,u,i,s,r))}}(t,i,e,s,h,r,this.iterations,this.pathData),this.lastPointX=h,this.lastPointY=r,this},catmullRomTo(...t){return function(t,i,e){for(var s=e.length,h=[e[s-2]],r=[e[s-1]],a=0,n=t.length;a<n;a+=2)h.push(t[a]),r.push(t[a+1]);a=1;for(var o=i-1;a<=o;a++){var l=a/o;e.push(T(h,l),T(r,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],i=this.pathData[1];return t===this.lastPointX&&i===this.lastPointY||this.lineTo(t,i),this.closePath=!0,this},end(){return b(this.pathData),this}};const S=Phaser.Math.RotateAround;var R=function(t,i,e){for(var s=0,h=e.length-1;s<h;s+=2)e[s]+=t,e[s+1]+=i;return e};const w=Phaser.Math.DegToRad;Phaser.Math.RotateAround;var A={rotateAround(t,i,e){if(0===this.pathData.length)return this;!function(t,i,e,s){for(var h={x:0,y:0},r=0,a=s.length-1;r<a;r+=2)h.x=s[r],h.y=s[r+1],S(h,t,i,e),s[r]=h.x,s[r+1]=h.y}(t,i,e=w(e),this.pathData);var s=this.pathData.length;return this.lastPointX=this.pathData[s-2],this.lastPointY=this.pathData[s-1],this},scale(t,i,e,s){return 0===this.pathData.length||(function(t,i,e,s,h){for(var r=0,a=h.length-1;r<a;r+=2){var n=h[r]-t,o=h[r+1]-i;n*=e,o*=s,h[r]=n+t,h[r+1]=o+i}}(t,i,e,s,this.pathData),this.lastPointX=this.pathData[pathDataCnt-2],this.lastPointY=this.pathData[pathDataCnt-1]),this},offset(t,i){return R(t,i,this.pathData),this}},E={savePathData(){return this.pathDataSaved||(this.pathDataSave=[...this.pathData],this.pathData.length=0,this.pathDataSaved=!0),this},restorePathData(){return this.pathDataSaved?(function(t,i,e,s){void 0===e&&(e=0),void 0===s&&(s=i.length),t.length=s-e;for(var h=0,r=t.length;h<r;h++)t[h]=i[h+e]}(this.pathData,this.pathDataSave),this.pathDataSave=void 0,this.pathDataSaved=!1,this):this}};const C=Phaser.Math.Distance.Between,L=Phaser.Math.Wrap,O=Phaser.Math.Linear;var x=function(t,i,e,s,h){if(void 0===s&&(s=e,e=0),(e=V(e))!==(s=V(s))){var r=i[i.length-1],a=r*e,n=r*s;e<s?F(t,i,a,n,h):(F(t,i,a,r,h),F(t,i,0,n,h)),b(h)}},F=function(t,i,e,s,h){for(var r=e>0,a=0,n=i.length;a<n;a++){var o=2*a,l=i[a];if(r){if(l<e)continue;if(l==e)r=!1;else{var u=1-(l-e)/(l-i[a-1]);h.push(M(t,o-2,o,u)),h.push(M(t,o-1,o+1,u)),r=!1}}if(!(l<=s)){u=1-(l-s)/(l-i[a-1]),h.push(M(t,o-2,o,u)),h.push(M(t,o-1,o+1,u));break}if(h.push(t[o]),h.push(t[o+1]),l===s)break}},M=function(t,i,e,s){var h=t[i],r=t[e];return O(h,r,s)},V=function(t){return 0===t?0:t%1==0?1:L(t,0,1)},j={updateAccumulationLengths(){if(null==this.accumulationLengths)this.accumulationLengths=[];else if(this.accumulationLengths.length===this.pathData.length/2)return this;for(var t,i,e,s,h=this.accumulationLengths,r=this.pathData,a=0,n=0,o=r.length;n<o;n+=2)e=r[n],s=r[n+1],a+=void 0===t?0:C(t,i,e,s),h.push(a),t=e,i=s;return this.totalPathLength=a,this},setDisplayPathSegment(t,i){return this.pathDataSaved||(this.updateAccumulationLengths(),this.savePathData()),this.pathData.length=0,x(this.pathDataSave,this.accumulationLengths,t,i,this.pathData),this},appendFromPathSegment(t,i,e){return void 0===i?this.pathData.push(...t.pathData):(t.updateAccumulationLengths(),x(t.pathData,t.accumulationLengths,i,e,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}},B={draw(t,i,e){var s=this.toPoints();return i&&t.fillPoints(s,this.closePath,this.closePath),e&&t.strokePoints(s,this.closePath,this.closePath),this}};const z=Phaser.Geom.Polygon;Object.assign(class{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,i){void 0===i&&(i=[]);for(var e=0,s=t.length-1;e<s;e+=2)i.push({x:t[e],y:t[e+1]});return i}(this.pathData)}toPolygon(t){return function(t,i){return void 0===i&&(i=new z),i.setTo(t),i}(this.pathData,t)}}.prototype,_,A,E,j,B),Phaser.Renderer.WebGL.Utils;const W=Phaser.Utils.Objects.GetValue;class X extends m{constructor(t,i,e,s,h,r){void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=0),void 0===s&&(s=e),void 0===h&&(h=0),void 0===r&&(r=6),super(),this.setTopLeftPosition(t,i),this.setSize(e,s),this.setRadius(h),this.setIterations(r),this.closePath=!0}get x(){return this._x}set x(t){this.dirty=this.dirty||this._x!==t,this._x=t}get y(){return this._y}set y(t){this.dirty=this.dirty||this._y!==t,this._y=t}setTopLeftPosition(t,i){return this.x=t,this.y=i,this}get width(){return this._width}set width(t){this.dirty=this.dirty||this._width!==t,this._width=t}get height(){return this._height}set height(t){this.dirty=this.dirty||this._height!==t,this._height=t}setSize(t,i){return this.width=t,this.height=i,this}get centerX(){return this.x+this.width/2}set centerX(t){this.x=t-this.width/2}get centerY(){return this.y+this.height/2}set centerY(t){this.y=t-this.height/2}setCenterPosition(t,i){return this.centerX=t,this.centerY=i,this}get radiusTL(){return this._radiusTL}set radiusTL(t){var i=t>0;this.dirty=this.dirty||this._radiusTL!==t||this._convexTL!==i,this._convexTL=i,this._radiusTL=Math.abs(t)}get radiusTR(){return this._radiusTR}set radiusTR(t){var i=t>0;this.dirty=this.dirty||this._radiusTR!==t||this._convexTR!==i,this._convexTR=i,this._radiusTR=Math.abs(t)}get radiusBL(){return this._radiusBL}set radiusBL(t){var i=t>0;this.dirty=this.dirty||this._radiusBL!==t||this._convexBL!==i,this._convexBL=i,this._radiusBL=Math.abs(t)}get radiusBR(){return this._radiusBR}set radiusBR(t){var i=t>0;this.dirty=this.dirty||this._radiusBR!==t||this._convexBR!==i,this._convexBR=i,this._radiusBR=Math.abs(t)}get radius(){return Math.max(this.radiusTL,this.radiusTR,this.radiusBL,this.radiusBR)}set radius(t){"number"==typeof t?(this.radiusTL=t,this.radiusTR=t,this.radiusBL=t,this.radiusBR=t):(this.radiusTL=W(t,"tl",0),this.radiusTR=W(t,"tr",0),this.radiusBL=W(t,"bl",0),this.radiusBR=W(t,"br",0))}setRadius(t){return void 0===t&&(t=0),this.radius=t,this}get iterations(){return this._iterations}set iterations(t){this.dirty=this.dirty||this._iterations!==t,this._iterations=t}setIterations(t){return this.iterations=t,this}updateData(){var t=this.pathData;t.length=0;var i,e=this.width,s=this.height,h=this.iterations+1;return(i=this.radiusTL)>0?this._convexTL?D(i,i,i,i,180,270,!1,h,t):D(0,0,i,i,90,0,!0,h,t):y(0,0,t),(i=this.radiusTR)>0?this._convexTR?D(e-i,i,i,i,270,360,!1,h,t):D(e,0,i,i,180,90,!0,h,t):y(e,0,t),(i=this.radiusBR)>0?this._convexBR?D(e-i,s-i,i,i,0,90,!1,h,t):D(e,s,i,i,270,180,!0,h,t):y(e,s,t),(i=this.radiusBL)>0?this._convexBL?D(i,s-i,i,i,90,180,!1,h,t):D(0,s,i,i,360,270,!0,h,t):y(0,s,t),t.push(t[0],t[1]),R(this.x,this.y,t),super.updateData(),this}}Phaser.Renderer.WebGL.Utils;
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var N=function(t,i,e){return(i-t)*e+t},G=function(t){return t>>16&255},Y=function(t){return t>>8&255},I=function(t){return 255&t};const U=Phaser.Math.Linear;var H={buildShapes(){this.addShape((new X).setName("track")).addShape((new X).setName("thumb"))},updateShapes(){var t=this.width,i=this.height,e=this.value?this.toggleAnimProgress:1-this.toggleAnimProgress,s=this.getShape("track");if(this.isSizeChanged){var h=t*this.trackWidth,r=i*this.trackHeight,a=(t-h)/2,n=(i-r)/2,o=i*this.trackRadius;s.setTopLeftPosition(a,n).setSize(h,r).setRadius(o)}var l,u,d,p=(l=this.falseValueTrackColor,u=this.trackFillColor,d=e,(255&N(G(l),G(u),d))<<16|(255&N(Y(l),Y(u),d))<<8|255&N(I(l),I(u),d)),c=U(this.falseValueTrackFillAlpha,this.trackFillAlpha,e);s.fillStyle(p,c);var g=this.getShape("thumb");if(this.isSizeChanged){var v=t*this.thumbWidth,m=i*this.thumbHeight,y=i*this.thumbRadius;g.setSize(v,m).setRadius(y)}var f=U(this.thumbLeftX,this.thumbRightX,e)*t;this.rtl&&(f=t-f);var D=i/2;g.setCenterPosition(f,D),g.fillStyle(this.thumbColor,this.thumbAlpha)}},J={setEventEmitter(t,i){return void 0===i&&(i=Phaser.Events.EventEmitter),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new i: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 K=Phaser.Scene;var q=function(t){return t instanceof K};const Q=Phaser.Game;var Z=function(t){return t instanceof Q};const $=Phaser.Utils.Objects.GetValue;class tt{constructor(t,i){this.setParent(t),this.isShutdown=!1,this.setEventEmitter($(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))}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,i){this.destroy(i)}setParent(t){var i;return this.parent=t,this.scene=null==(i=t)||"object"!=typeof i?null:q(i)?i:i.scene&&q(i.scene)?i.scene:i.parent&&i.parent.scene&&q(i.parent.scene)?i.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:Z(t)?t:Z(t.game)?t.game:q(t)?t.sys.game:q(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(tt.prototype,J);const it=Phaser.Utils.Objects.GetValue;class et extends tt{constructor(t,i){super(t,i),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(it(i,"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=st[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 st={no:0,lazy:1,always:2},ht=Phaser.Utils.Objects.GetValue;class rt extends et{constructor(t,i){super(t,i);var e=this.scene?"update":"step";this.tickEventName=ht(i,"tickEventName",e),this.isSceneTicker=!at(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 at=function(t){return"step"===t||"poststep"===t};const nt=Phaser.Utils.Objects.GetValue,ot=Phaser.Math.Clamp;class lt{constructor(t){this.resetFromJSON(t)}resetFromJSON(t){this.state=nt(t,"state",ut),this.timeScale=nt(t,"timeScale",1),this.delay=nt(t,"delay",0),this.repeat=nt(t,"repeat",0),this.repeatCounter=nt(t,"repeatCounter",0),this.repeatDelay=nt(t,"repeatDelay",0),this.duration=nt(t,"duration",0),this.nowTime=nt(t,"nowTime",0),this.justRestart=nt(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?pt:dt,this.repeatCounter=0,this}stop(){return this.state=ut,this}update(t,i){this.state!==ut&&this.state!==gt&&0!==i&&0!==this.timeScale&&(this.nowTime+=i*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=ct)):(this.nowTime=this.duration,this.state=gt):this.nowTime>=0&&(this.state=pt))}get t(){var t;switch(this.state){case ut:case dt:case ct:t=0;break;case pt:t=this.nowTime/this.duration;break;case gt:t=1}return ot(t,0,1)}set t(t){(t=ot(t,-1,1))<0?(this.state=dt,this.nowTime=-this.delay*t):(this.state=pt,this.nowTime=this.duration*t,1===t&&0!==this.repeat&&this.repeatCounter++)}setT(t){return this.t=t,this}get isIdle(){return this.state===ut}get isDelay(){return this.state===dt}get isCountDown(){return this.state===pt}get isRunning(){return this.state===dt||this.state===pt}get isDone(){return this.state===gt}get isOddIteration(){return!(1&~this.repeatCounter)}get isEvenIteration(){return!(1&this.repeatCounter)}}const ut=0,dt=1,pt=2,ct=3,gt=-1;class vt extends rt{constructor(t,i){super(t,i),this.timer=new lt}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 mt=Phaser.Utils.Objects.GetValue,yt=Phaser.Utils.Objects.GetAdvancedValue,ft=Phaser.Tweens.Builders.GetEaseFunction;class Dt extends vt{resetFromJSON(t){return this.timer.resetFromJSON(mt(t,"timer")),this.setEnable(mt(t,"enable",!0)),this.setTarget(mt(t,"target",this.parent)),this.setDelay(yt(t,"delay",0)),this.setDuration(yt(t,"duration",1e3)),this.setEase(mt(t,"ease","Linear")),this.setRepeat(mt(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=ft(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,i){if(!this.isRunning||!this.enable||this.parent.hasOwnProperty("active")&&!this.parent.active)return this;var e=this.target,s=this.timer;return s.update(t,i),s.isDelay||this.updateTarget(e,s),this.emit("update",e,this),s.isDone&&this.complete(),this}updateTarget(t,i){}}const Pt=Phaser.Utils.Objects.GetValue,kt=Phaser.Math.Linear;class Tt extends Dt{constructor(t,i){super(t,i),this.resetFromJSON(),this.boot()}start(t){if(this.timer.isRunning)return this;var i=this.target;this.propertyKey=Pt(t,"key","value");var e=i[this.propertyKey];return this.fromValue=Pt(t,"from",e),this.toValue=Pt(t,"to",e),this.setEase(Pt(t,"ease",this.ease)),this.setDuration(Pt(t,"duration",this.duration)),this.setRepeat(Pt(t,"repeat",0)),this.setDelay(Pt(t,"delay",0)),this.setRepeatDelay(Pt(t,"repeatDelay",0)),this.timer.setDuration(this.duration).setRepeat(this.repeat).setDelay(this.delay).setRepeatDelay(this.repeatDelay),i[this.propertyKey]=this.fromValue,super.start(),this}updateTarget(t,i){var e=i.t;e=this.easeFn(e),t[this.propertyKey]=kt(this.fromValue,this.toValue,e)}}var bt={setToggleAnimationDuration(t){return void 0===t&&(t=0),this.toggleAnimDuration=t,this},playToggleAnimation(){return void 0===this.toggleAnimProgressTask&&(this.toggleAnimProgressTask=new Tt(this,{eventEmitter:null})),this.toggleAnimProgressTask.restart({key:"toggleAnimProgress",from:0,to:1,duration:this.toggleAnimDuration}),this},stopToggleAnimation(){return void 0===this.toggleAnimProgressTask||this.toggleAnimProgressTask.stop(),this}},_t={};Object.assign(_t,n,o,l,H,bt);const St=Phaser.Utils.Objects.GetValue,Rt=Phaser.Utils.Objects.IsPlainObject,wt=23730;class At extends a{constructor(t,i,e,s,h,r,a){Rt(i)?(i=St(a=i,"x",0),e=St(a,"y",0),s=St(a,"width",2),h=St(a,"height",2),r=St(a,"color",wt)):Rt(r)&&(r=St(a=r,"color",wt)),super(t,i,e,s,h),this.type="rexToggleSwitch",void 0===r&&(r=wt),this.setTrackFillStyle(r,St(a,"trackFillAlpha",1)),this.setFalseValueTrackFillStyle(St(a,"falseValueTrackColor",function(t){var i=.3*G(t)+.59*Y(t)+.11*I(t);return(255&i)<<16|(255&i)<<8|255&i}(r)),St(a,"falseValueTrackFillAlpha",1)),this.setThumbStyle(St(a,"thumbColor",16777215),St(a,"thumbAlpha",1)),this.setTrackSize(St(a,"trackWidth",.9),St(a,"trackHeight",.5)),this.setTrackRadius(St(a,"trackRadius",.5*this.trackHeight));var n=St(a,"thumbHeight",void 0),o=St(a,"thumbWidth",n);void 0===o&&(o=.9*this.trackHeight),this.setThumbSize(o,n),this.setThumbRadius(St(a,"thumbRadius",.5*this.thumbHeight)),this.setThumbPosition(St(a,"thumbLeft",.3),St(a,"thumbRight",void 0)),this.setRTL(St(a,"rtl",!1)),this.setToggleAnimationDuration(St(a,"animationDuration",150)),this.buildShapes(),this.setValue(St(a,"value",!1),0)}get value(){return this._value}set value(t){t=!!t,this._value!==t&&(this.dirty=!0,this._value=t,this.playToggleAnimation(),this.emit("valuechange",t))}setValue(t,i){void 0===i&&(i=this.toggleAnimDuration);var e=this.toggleAnimDuration;return this.toggleAnimDuration=i,this.value=t,this.toggleAnimDuration=e,this}toggleValue(t){return this.setValue(!this.value,t),this}get toggleAnimProgress(){return this._toggleAnimProgress}set toggleAnimProgress(t){this._toggleAnimProgress!==t&&(this._toggleAnimProgress=t,this.dirty=!0)}}Object.assign(At.prototype,_t);const Et=Phaser.Utils.Objects.GetValue;class Ct extends tt{constructor(t,i){super(t,i),this._enable=void 0,t.setInteractive(Et(i,"inputConfig",void 0)),this.resetFromJSON(i),this.boot()}resetFromJSON(t){return this.pointer=void 0,this.lastClickTime=void 0,this.isDown=!1,this.isOver=!1,this.setEnable(Et(t,"enable",!0)),this.setMode(Et(t,"mode",1)),this.setClickInterval(Et(t,"clickInterval",100)),this.setDragThreshold(Et(t,"threshold",void 0)),this}boot(){var t=this.parent;t.on("pointerdown",this.onPress,this),t.on("pointerup",this.onRelease,this),t.on("pointerout",this.onPointOut,this),t.on("pointermove",this.onMove,this),t.on("pointerover",this.onOver,this),t.on("pointerout",this.onOut,this)}shutdown(t){this.isShutdown||(this.pointer=null,super.shutdown(t))}get enable(){return this._enable}set enable(t){if(this._enable!==t){t||this.cancel(),this._enable=t;var i=t?"enable":"disable";this.emit(i,this,this.parent)}}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}toggleEnable(){return this.setEnable(!this.enable),this}setMode(t){return"string"==typeof t&&(t=Lt[t]),this.mode=t,this}setClickInterval(t){return this.clickInterval=t,this}setDragThreshold(t){return this.dragThreshold=t,this}onPress(t,i,e,s){void 0===this.pointer&&(this.pointer=t,this.isDown=!0,this.emit("down",this,this.parent,t,s),0===this.mode&&this.click(t.downTime,t,s))}onRelease(t,i,e,s){this.pointer===t&&(this.isDown=!1,this.emit("up",this,this.parent,t,s),1===this.mode&&this.click(t.upTime,t,s),this.pointer=void 0)}onPointOut(t,i){this.pointer===t&&this.cancel()}onMove(t,i,e,s){this.pointer===t&&void 0!==this.dragThreshold&&1===this.mode&&t.getDistance()>=this.dragThreshold&&this.cancel()}onOver(t,i,e,s){return this.enable?(this.isOver=!0,this.emit("over",this,this.parent,t,s),this):this}onOut(t,i){return this.enable?(this.isOver=!1,this.emit("out",this,this.parent,t,i),this):this}click(t,i,e){if(!this.enable)return this;if(void 0===t)return this.emit("click",this,this.parent,i,e),this;this.pointer=void 0;var s=this.lastClickTime;return void 0!==s&&t-s<=this.clickInterval||(this.lastClickTime=t,this.emit("click",this,this.parent,i,e)),this}cancel(){return this.pointer=void 0,this}}const Lt={press:0,pointerdown:0,release:1,pointerup:1},Ot=Phaser.Utils.Objects.GetValue;return class extends At{constructor(t,i,e,s,h,r,a){super(t,i,e,s,h,r,a),this._click=new Ct(this,Ot(a,"click")),this._click.on("click",(function(){this.toggleValue()}),this),this.setReadOnly(Ot(a,"readOnly",!1))}get readOnly(){return!this._click.enable}set readOnly(t){this._click.enable=!t}setReadOnly(t){return void 0===t&&(t=!0),this.readOnly=t,this}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).rextoggleswitch=i();