UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 33.2 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,h){i.updateData();var r=s.camera;r.addToRenderList(i);for(var a,n=t(i,r,h,!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++)(a=c[p]).visible&&a.webglRender(s,d,n,i,u,o,l)},renderCanvas:function(t,i,s,h){i.updateData(),s.addToRenderList(i);var r=t.currentContext;if(e(t,r,i,s,h)){for(var a,n=i._displayOriginX,o=i._displayOriginY,l=i.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 e in t)delete t[e];return t};const h=Phaser.GameObjects.Shape,r=Phaser.Utils.Array.Remove;class a extends h{constructor(t,e,i,s,h){void 0===e&&(e=0),void 0===i&&(i=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(e,i),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,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],r(this.geom,e)),this}}Object.assign(a.prototype,i);var n={setBoxFillStyle(t,e){return void 0===e&&(e=1),this.dirty=this.dirty||this.boxFillColor!==t||this.boxFillAlpha!==e,this.boxFillColor=t,this.boxFillAlpha=e,this},setUncheckedBoxFillStyle(t,e){return void 0===e&&(e=1),this.dirty=this.dirty||this.uncheckedBoxFillColor!==t||this.uncheckedBoxFillAlpha!==e,this.uncheckedBoxFillColor=t,this.uncheckedBoxFillAlpha=e,this},setBoxStrokeStyle(t,e,i){return void 0===i&&(i=1),this.dirty=this.dirty||this.boxLineWidth!==t||this.boxStrokeColor!==e||this.boxStrokeAlpha!==i,this.boxLineWidth=t,this.boxStrokeColor=e,this.boxStrokeAlpha=i,this},setUncheckedBoxStrokeStyle(t,e,i){return void 0===i&&(i=1),this.dirty=this.dirty||this.uncheckedBoxLineWidth!==t||this.uncheckedBoxStrokeColor!==e||this.uncheckedBoxStrokeAlpha!==i,this.uncheckedBoxLineWidth=t,this.uncheckedBoxStrokeColor=e,this.uncheckedBoxStrokeAlpha=i,this},setCheckerStyle(t,e){return void 0===e&&(e=1),this.dirty=this.dirty||this.checkerColor!==t||this.checkAlpha!==e,this.checkerColor=t,this.checkAlpha=e,this},setBoxShape(t){return void 0===t&&(t=!1),this.isCircleShape===t||(this.isCircleShape=t,this.isSizeChanged=!0,this.dirty=!0),this}},o={setBoxSize(t){return this.dirty=this.dirty||this.boxSize!==t,this.boxSize=t,this},setCheckerSize(t){return this.dirty=this.dirty||this.checkerSize!==t,this.checkerSize=t,this}},l={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}},u={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,h=t,r=i,a=0;a<s.length;a++){if(e=s[a],!h.hasOwnProperty(e)){r=i;break}h=r=h[e]}return r}(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 d{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,h,r,a){}canvasRender(t,e,i){}updateData(){this.dirty=!1}}Object.assign(d.prototype,l,u);var c=Phaser.Renderer.WebGL.Utils,p=Phaser.Renderer.WebGL.Utils;const v=Phaser.Geom.Polygon.Earcut;class g extends d{constructor(){super(),this.pathData=[],this.pathIndexes=[],this.closePath=!1}updateData(){return this.pathIndexes=v(this.pathData),super.updateData(),this}webglRender(t,e,i,s,h,r,a){this.isFilled&&function(t,e,i,s,h,r,a,n){var o,l,u,d,p,v=c.getTintAppendFloatAlpha(h.fillColor,h.fillAlpha*r),g=h.pathData,y=h.pathIndexes,m=g.length,k=Array(2*m),f=Array(m),S=0,b=0;for(o=0;o<m;o+=2)l=g[o]-a,u=g[o+1]-n,d=i.getX(l,u),p=i.getY(l,u),k[S++]=d,k[S++]=p,f[b++]=v;e.batch(t,y,k,f)}(t,e,i,0,this,h,r,a),this.isStroked&&function(t,e,i,s,h,r,a,n){var o=p.getTintAppendFloatAlpha(h.strokeColor,h.strokeAlpha*r),l=h.pathData,u=l.length-1,d=h.lineWidth,c=!h.closePath,v=s.customRenderNodes.StrokePath||s.defaultRenderNodes.StrokePath,g=[];c&&(u-=2);for(var y=0;y<u;y+=2){var m=l[y]-a,k=l[y+1]-n;y>0&&m===l[y-2]&&k===l[y-1]||g.push({x:m,y:k,width:d})}v.run(t,e,g,d,c,i,o,o,o,o)}(t,e,i,s,this,h,r,a)}canvasRender(t,e,i){var s=this.pathData,h=s.length-1,r=s[0]-e,a=s[1]-i;t.beginPath(),t.moveTo(r,a),this.closePath||(h-=2);for(var n=2;n<h;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 h=i||e.fillColor,r=s||e.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,e,i,s){var h=i||e.strokeColor,r=s||e.strokeAlpha,a=(16711680&h)>>>16,n=(65280&h)>>>8,o=255&h;t.strokeStyle="rgba("+a+","+n+","+o+","+r+")",t.lineWidth=e.lineWidth}(t,this),t.stroke())}}var y=function(t,e,i){var s=i.length;if(s>=2){var h=i[s-2],r=i[s-1];if(t===h&&e===r)return i}return i.push(t,e),i};const m=Phaser.Math.DegToRad;var k=function(t,e,i,s,h,r,a,n,o){a&&r>h?r-=360:!a&&r<h&&(r+=360);var l=m(r-h)/n;h=m(h);for(var u=0;u<=n;u++){var d=h+l*u,c=t+i*Math.cos(d),p=e+s*Math.sin(d);y(c,p,o)}return o};Phaser.Math.DegToRad;const f=Phaser.Math.Interpolation.QuadraticBezier,S=Phaser.Math.Interpolation.CubicBezier,b=Phaser.Math.Interpolation.CatmullRom;var P=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},D={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),y(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,h,r,a){return void 0===a&&(a=!1),k(t,e,i,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,e,i,s,h,r){return this.ellipticalArc(t,e,i,i,s,h,r),this},quadraticBezierTo(t,e,i,s){return function(t,e,i,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(f(d,n,t,i),f(d,o,e,s))}}(t,e,i,s,this.iterations,this.pathData),this.lastPointX=i,this.lastPointY=s,this},cubicBezierTo(t,e,i,s,h,r){return function(t,e,i,s,h,r,a,n){for(var o=n.length,l=n[o-2],u=n[o-1],d=1,c=a-1;d<=c;d++){var p=d/c;n.push(S(p,l,t,i,h),S(p,u,e,s,r))}}(t,e,i,s,h,r,this.iterations,this.pathData),this.lastPointX=h,this.lastPointY=r,this},catmullRomTo(...t){return function(t,e,i){for(var s=i.length,h=[i[s-2]],r=[i[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=e-1;a<=o;a++){var l=a/o;i.push(b(h,l),b(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],e=this.pathData[1];return t===this.lastPointX&&e===this.lastPointY||this.lineTo(t,e),this.closePath=!0,this},end(){return P(this.pathData),this}};const _=Phaser.Math.RotateAround;var T=function(t,e,i){for(var s=0,h=i.length-1;s<h;s+=2)i[s]+=t,i[s+1]+=e;return i};const x=Phaser.Math.DegToRad;Phaser.Math.RotateAround;var C={rotateAround(t,e,i){if(0===this.pathData.length)return this;!function(t,e,i,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],_(h,t,e,i),s[r]=h.x,s[r+1]=h.y}(t,e,i=x(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,h){for(var r=0,a=h.length-1;r<a;r+=2){var n=h[r]-t,o=h[r+1]-e;n*=i,o*=s,h[r]=n+t,h[r+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 T(t,e,this.pathData),this}},A={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 h=0,r=t.length;h<r;h++)t[h]=e[h+i]}(this.pathData,this.pathDataSave),this.pathDataSave=void 0,this.pathDataSaved=!1,this):this}};const R=Phaser.Math.Distance.Between,w=Phaser.Math.Wrap,E=Phaser.Math.Linear;var L=function(t,e,i,s,h){if(void 0===s&&(s=i,i=0),(i=F(i))!==(s=F(s))){var r=e[e.length-1],a=r*i,n=r*s;i<s?B(t,e,a,n,h):(B(t,e,a,r,h),B(t,e,0,n,h)),P(h)}},B=function(t,e,i,s,h){for(var r=i>0,a=0,n=e.length;a<n;a++){var o=2*a,l=e[a];if(r){if(l<i)continue;if(l==i)r=!1;else{var u=1-(l-i)/(l-e[a-1]);h.push(O(t,o-2,o,u)),h.push(O(t,o-1,o+1,u)),r=!1}}if(!(l<=s)){u=1-(l-s)/(l-e[a-1]),h.push(O(t,o-2,o,u)),h.push(O(t,o-1,o+1,u));break}if(h.push(t[o]),h.push(t[o+1]),l===s)break}},O=function(t,e,i,s){var h=t[e],r=t[i];return E(h,r,s)},F=function(t){return 0===t?0:t%1==0?1:w(t,0,1)},z={updateAccumulationLengths(){if(null==this.accumulationLengths)this.accumulationLengths=[];else if(this.accumulationLengths.length===this.pathData.length/2)return this;for(var t,e,i,s,h=this.accumulationLengths,r=this.pathData,a=0,n=0,o=r.length;n<o;n+=2)i=r[n],s=r[n+1],a+=void 0===t?0:R(t,e,i,s),h.push(a),t=i,e=s;return this.totalPathLength=a,this},setDisplayPathSegment(t,e){return this.pathDataSaved||(this.updateAccumulationLengths(),this.savePathData()),this.pathData.length=0,L(this.pathDataSave,this.accumulationLengths,t,e,this.pathData),this},appendFromPathSegment(t,e,i){return void 0===e?this.pathData.push(...t.pathData):(t.updateAccumulationLengths(),L(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}},j={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 M=Phaser.Geom.Polygon;class V{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 M),e.setTo(t),e}(this.pathData,t)}}Object.assign(V.prototype,D,C,A,z,j);class W extends g{constructor(){super(),this.builder=new V(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,h,r,a){return this.builder.ellipticalArc(t,e,i,s,h,r,a),this.dirty=!0,this}arc(t,e,i,s,h,r){return this.builder.arc(t,e,i,s,h,r),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,h,r){return this.builder.cubicBezierTo(t,e,i,s,h,r),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;const I=Phaser.Utils.Objects.GetValue;class N extends g{constructor(t,e,i,s,h,r){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=i),void 0===h&&(h=0),void 0===r&&(r=6),super(),this.setTopLeftPosition(t,e),this.setSize(i,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,e){return this.x=t,this.y=e,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,e){return this.width=t,this.height=e,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,e){return this.centerX=t,this.centerY=e,this}get radiusTL(){return this._radiusTL}set radiusTL(t){var e=t>0;this.dirty=this.dirty||this._radiusTL!==t||this._convexTL!==e,this._convexTL=e,this._radiusTL=Math.abs(t)}get radiusTR(){return this._radiusTR}set radiusTR(t){var e=t>0;this.dirty=this.dirty||this._radiusTR!==t||this._convexTR!==e,this._convexTR=e,this._radiusTR=Math.abs(t)}get radiusBL(){return this._radiusBL}set radiusBL(t){var e=t>0;this.dirty=this.dirty||this._radiusBL!==t||this._convexBL!==e,this._convexBL=e,this._radiusBL=Math.abs(t)}get radiusBR(){return this._radiusBR}set radiusBR(t){var e=t>0;this.dirty=this.dirty||this._radiusBR!==t||this._convexBR!==e,this._convexBR=e,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=I(t,"tl",0),this.radiusTR=I(t,"tr",0),this.radiusBL=I(t,"bl",0),this.radiusBR=I(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 e,i=this.width,s=this.height,h=this.iterations+1;return(e=this.radiusTL)>0?this._convexTL?k(e,e,e,e,180,270,!1,h,t):k(0,0,e,e,90,0,!0,h,t):y(0,0,t),(e=this.radiusTR)>0?this._convexTR?k(i-e,e,e,e,270,360,!1,h,t):k(i,0,e,e,180,90,!0,h,t):y(i,0,t),(e=this.radiusBR)>0?this._convexBR?k(i-e,s-e,e,e,0,90,!1,h,t):k(i,s,e,e,270,180,!0,h,t):y(i,s,t),(e=this.radiusBL)>0?this._convexBL?k(e,s-e,e,e,90,180,!1,h,t):k(0,s,e,e,360,270,!0,h,t):y(0,s,t),t.push(t[0],t[1]),T(this.x,this.y,t),super.updateData(),this}}Phaser.Renderer.WebGL.Utils;var X={buildShapes(){this.addShape((new N).setName("box")).addShape((new W).setName("checker"))},updateShapes(){var t=this.width/2,e=this.height/2,i=Math.min(t,e),s=2*i,h=t-i,r=e-i,a=this.boxLineWidth,n=Math.max(s/10,2),o=this.getShape("box"),l=this.getShape("checker");if(this.isSizeChanged){var u=s*(1-this.boxSize)/2,d=a/2,c=s*this.boxSize-a;o.setTopLeftPosition(h+d+u,r+d+u).setSize(c,c),this.isCircleShape?o.setRadius(c/2):o.setRadius(0),u=s*(1-this.checkerSize)/2;var p=s*this.checkerSize/4,v=1*p,g=2*p,y=3*p;l.startAt(v,g).lineTo(g,y).lineTo(y,v).offset(h+u,r+u).end()}this.checked?(o.fillStyle(this.boxFillColor,this.boxFillAlpha).lineStyle(a,this.boxStrokeColor,this.boxStrokeAlpha),l.lineStyle(n,this.checkerColor)):(o.fillStyle(this.uncheckedBoxFillColor,this.uncheckedBoxFillAlpha).lineStyle(a,this.uncheckedBoxStrokeColor,this.uncheckedBoxStrokeAlpha),l.lineStyle()),this.checked&&l.setDisplayPathSegment(this.checkerAnimProgress)}},Y={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 G=Phaser.Scene;var U=function(t){return t instanceof G};const J=Phaser.Game;var K=function(t){return t instanceof J};const q=Phaser.Utils.Objects.GetValue;class H{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(q(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:U(e)?e:e.scene&&U(e.scene)?e.scene:e.parent&&e.parent.scene&&U(e.parent.scene)?e.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:K(t)?t:K(t.game)?t.game:U(t)?t.sys.game:U(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(H.prototype,Y);const Q=Phaser.Utils.Objects.GetValue;class Z extends H{constructor(t,e){super(t,e),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(Q(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=$[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 $={no:0,lazy:1,always:2},tt=Phaser.Utils.Objects.GetValue;class et extends Z{constructor(t,e){super(t,e);var i=this.scene?"update":"step";this.tickEventName=tt(e,"tickEventName",i),this.isSceneTicker=!it(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 it=function(t){return"step"===t||"poststep"===t};const st=Phaser.Utils.Objects.GetValue,ht=Phaser.Math.Clamp;class rt{constructor(t){this.resetFromJSON(t)}resetFromJSON(t){this.state=st(t,"state",at),this.timeScale=st(t,"timeScale",1),this.delay=st(t,"delay",0),this.repeat=st(t,"repeat",0),this.repeatCounter=st(t,"repeatCounter",0),this.repeatDelay=st(t,"repeatDelay",0),this.duration=st(t,"duration",0),this.nowTime=st(t,"nowTime",0),this.justRestart=st(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?ot:nt,this.repeatCounter=0,this}stop(){return this.state=at,this}update(t,e){this.state!==at&&this.state!==ut&&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=lt)):(this.nowTime=this.duration,this.state=ut):this.nowTime>=0&&(this.state=ot))}get t(){var t;switch(this.state){case at:case nt:case lt:t=0;break;case ot:t=this.nowTime/this.duration;break;case ut:t=1}return ht(t,0,1)}set t(t){(t=ht(t,-1,1))<0?(this.state=nt,this.nowTime=-this.delay*t):(this.state=ot,this.nowTime=this.duration*t,1===t&&0!==this.repeat&&this.repeatCounter++)}setT(t){return this.t=t,this}get isIdle(){return this.state===at}get isDelay(){return this.state===nt}get isCountDown(){return this.state===ot}get isRunning(){return this.state===nt||this.state===ot}get isDone(){return this.state===ut}get isOddIteration(){return!(1&~this.repeatCounter)}get isEvenIteration(){return!(1&this.repeatCounter)}}const at=0,nt=1,ot=2,lt=3,ut=-1;class dt extends et{constructor(t,e){super(t,e),this.timer=new rt}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 ct=Phaser.Utils.Objects.GetValue,pt=Phaser.Utils.Objects.GetAdvancedValue,vt=Phaser.Tweens.Builders.GetEaseFunction;class gt extends dt{resetFromJSON(t){return this.timer.resetFromJSON(ct(t,"timer")),this.setEnable(ct(t,"enable",!0)),this.setTarget(ct(t,"target",this.parent)),this.setDelay(pt(t,"delay",0)),this.setDuration(pt(t,"duration",1e3)),this.setEase(ct(t,"ease","Linear")),this.setRepeat(ct(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=vt(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 yt=Phaser.Utils.Objects.GetValue,mt=Phaser.Math.Linear;class kt extends gt{constructor(t,e){super(t,e),this.resetFromJSON(),this.boot()}start(t){if(this.timer.isRunning)return this;var e=this.target;this.propertyKey=yt(t,"key","value");var i=e[this.propertyKey];return this.fromValue=yt(t,"from",i),this.toValue=yt(t,"to",i),this.setEase(yt(t,"ease",this.ease)),this.setDuration(yt(t,"duration",this.duration)),this.setRepeat(yt(t,"repeat",0)),this.setDelay(yt(t,"delay",0)),this.setRepeatDelay(yt(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]=mt(this.fromValue,this.toValue,i)}}var ft={setCheckerAnimationDuration(t){return void 0===t&&(t=0),this.checkerAnimDuration=t,this},playCheckerAnimation(){return void 0===this.checkerAnimProgressTask&&(this.checkerAnimProgressTask=new kt(this,{eventEmitter:null})),this.checkerAnimProgressTask.restart({key:"checkerAnimProgress",from:0,to:1,duration:this.checkerAnimDuration}),this},stopCheckerAnimation(){return void 0===this.checkerAnimProgressTask||this.checkerAnimProgressTask.stop(),this}},St={};Object.assign(St,n,o,X,ft);const bt=23730,Pt=Phaser.Utils.Objects.GetValue,Dt=Phaser.Utils.Objects.IsPlainObject;class _t extends a{constructor(t,e,i,s,h,r,a){Dt(e)?(e=Pt(a=e,"x",0),i=Pt(a,"y",0),s=Pt(a,"width",2),h=Pt(a,"height",2),r=Pt(a,"color",bt)):Dt(r)&&(r=Pt(a=r,"color",bt)),super(t,e,i,s,h),this.type="rexCheckbox",void 0===r&&(r=bt),this.setBoxShape(Pt(a,"circleBox",!1)),this.setBoxFillStyle(r,Pt(a,"boxFillAlpha",1)),this.setUncheckedBoxFillStyle(Pt(a,"uncheckedColor",null),Pt(a,"uncheckedBoxFillAlpha",1)),this.setBoxStrokeStyle(Pt(a,"boxLineWidth",4),Pt(a,"boxStrokeColor",r),Pt(a,"boxStrokeAlpha",1)),this.setUncheckedBoxStrokeStyle(this.boxLineWidth,Pt(a,"uncheckedBoxStrokeColor",this.boxStrokeColor),Pt(a,"uncheckedBoxStrokeAlpha",this.boxStrokeAlpha)),this.setCheckerStyle(Pt(a,"checkerColor",16777215),Pt(a,"checkerAlpha",1)),this.setBoxSize(Pt(a,"boxSize",1)),this.setCheckerSize(Pt(a,"checkerSize",1)),this.setCheckerAnimationDuration(Pt(a,"animationDuration",150)),this.buildShapes();var n=Pt(a,"checked");void 0===n&&(n=Pt(a,"value",!1)),this.setValue(n)}get value(){return this._value}set value(t){t=!!t,this._value!==t&&(this.dirty=!0,this._value=t,t?this.playCheckerAnimation():this.stopCheckerAnimation(),this.emit("valuechange",t))}setValue(t){return this.value=t,this}toggleValue(){return this.setValue(!this.value),this}get checked(){return this.value}set checked(t){this.value=t}setChecked(t){return void 0===t&&(t=!0),this.setValue(t),this}toggleChecked(){return this.toggleValue(),this}get checkerAnimProgress(){return this._checkerAnimProgress}set checkerAnimProgress(t){this._checkerAnimProgress!==t&&(this._checkerAnimProgress=t,this.dirty=!0)}}Object.assign(_t.prototype,St);const Tt=Phaser.Utils.Objects.GetValue;class xt extends H{constructor(t,e){super(t,e),this._enable=void 0,t.setInteractive(Tt(e,"inputConfig",void 0)),this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.pointer=void 0,this.lastClickTime=void 0,this.isDown=!1,this.isOver=!1,this.setEnable(Tt(t,"enable",!0)),this.setMode(Tt(t,"mode",1)),this.setClickInterval(Tt(t,"clickInterval",100)),this.setDragThreshold(Tt(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 e=t?"enable":"disable";this.emit(e,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=Ct[t]),this.mode=t,this}setClickInterval(t){return this.clickInterval=t,this}setDragThreshold(t){return this.dragThreshold=t,this}onPress(t,e,i,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,e,i,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,e){this.pointer===t&&this.cancel()}onMove(t,e,i,s){this.pointer===t&&void 0!==this.dragThreshold&&1===this.mode&&t.getDistance()>=this.dragThreshold&&this.cancel()}onOver(t,e,i,s){return this.enable?(this.isOver=!0,this.emit("over",this,this.parent,t,s),this):this}onOut(t,e){return this.enable?(this.isOver=!1,this.emit("out",this,this.parent,t,e),this):this}click(t,e,i){if(!this.enable)return this;if(void 0===t)return this.emit("click",this,this.parent,e,i),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,e,i)),this}cancel(){return this.pointer=void 0,this}}const Ct={press:0,pointerdown:0,release:1,pointerup:1},At=Phaser.Utils.Objects.GetValue,Rt=Phaser.Utils.Objects.IsPlainObject;return class extends _t{constructor(t,e,i,s,h,r,a){Rt(e)?(e=At(a=e,"x",0),i=At(a,"y",0),s=At(a,"width",2),h=At(a,"height",2),r=At(a,"color",bt)):Rt(r)&&(r=At(a=r,"color",bt)),super(t,e,i,s,h,r,a),this._click=new xt(this,At(a,"click")),this._click.on("click",(function(){this.toggleValue()}),this),this.setReadOnly(At(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=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexcheckbox=e();