phaser3-rex-plugins
Version:
2 lines (1 loc) • 28.8 kB
JavaScript
var t,i;t=void 0,i=function(){const t=Phaser.GameObjects.GetCalcMatrix,i=Phaser.Renderer.Canvas.SetTransform;var s={renderWebGL:function(i,s,e,h){s.updateData(),e.addToRenderList(s);var a=i.pipelines.set(s.pipeline),r=t(s,e,h),n=a.calcMatrix.copyFrom(r.calc),o=s._displayOriginX,l=s._displayOriginY,u=e.alpha*s.alpha;i.pipelines.preBatch(s);for(var d,p=s.geom,c=0,v=p.length;c<v;c++)(d=p[c]).visible&&d.webglRender(a,n,u,o,l);i.pipelines.postBatch(s)},renderCanvas:function(t,s,e,h){s.updateData(),e.addToRenderList(s);var a=t.currentContext;if(i(t,a,s,e,h)){for(var r,n=s._displayOriginX,o=s._displayOriginY,l=s.geom,u=0,d=l.length;u<d;u++)(r=l[u]).visible&&r.canvasRender(a,n,o);a.restore()}}},e=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,a=Phaser.Utils.Array.Remove;class r extends h{constructor(t,i,s,e,h){void 0===i&&(i=0),void 0===s&&(s=0),void 0===e&&(e=2),void 0===h&&(h=e),super(t,"rexShapes",[]),this._width=-1,this._height=-1,this.dirty=!0,this.isSizeChanged=!0,this.shapes={},this.setPosition(i,s),this.setSize(e,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 s=this.input;return s&&!s.customHitArea&&(s.hitArea.width=t,s.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,s){return void 0===s&&(s=1),this.dirty=this.dirty||this.lineWidth!==t||this.strokeColor!==i||this.strokeAlpha!==s,this._lineWidth=t,this._strokeColor=i,this._strokeAlpha=s,this}updateShapes(){}updateData(){if(!this.dirty)return this;this.updateShapes();for(var t=this.geom,i=0,s=t.length;i<s;i++){var e=t[i];e.dirty&&e.updateData()}return this.isSizeChanged=!1,this.dirty=!1,this}clear(){return this.geom.length=0,e(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],a(this.geom,i)),this}}Object.assign(r.prototype,s);var n={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,s){return null==t||null==i?this.isStroked=!1:(void 0===s&&(s=1),this.isStroked=!0,this.lineWidth=t,this.strokeColor=i,this.strokeAlpha=s),this}},o=function(t,i,s){for(var e=t,h=s,a=0,r=i.length;a<r;a++){var n=i[a];if(!e||"object"!=typeof e&&"function"!=typeof e||!(n in e))return l.found=!1,l;e=h=e[n]}return l.found=!0,l.value=h,l},l={},u={enableData(){return void 0===this.data&&(this.data={}),this},setData(t,i){if(this.enableData(),1===arguments.length){var s=t;for(t in s)this.data[t]=s[t]}else this.data[t]=i;return this},getData(t,i){return this.enableData(),void 0===t?this.data:function(t,i,s,e){var h=t&&("object"==typeof t||"function"==typeof t),a=e&&("object"==typeof e||"function"==typeof e);if(!h&&!a)return s;var r=String(i);if(h&&r in t)return t[r];if(a&&r in e)return e[r];if(-1===r.indexOf("."))return s;var n=r.split(".");if(h){var l=o(t,n,s);if(l.found)return l.value}if(a){var u=o(e,n,s);if(u.found)return u.value}return s}(this.data,t,i)},incData(t,i,s){return void 0===s&&(s=0),this.enableData(),this.setData(t,this.getData(t,s)+i),this},mulData(t,i,s){return void 0===s&&(s=0),this.enableData(),this.setData(t,this.getData(t,s)*i),this},clearData(){return this.data&&e(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,i,s,e,h){}canvasRender(t,i,s){}updateData(){this.dirty=!1}}Object.assign(d.prototype,n,u);var p=Phaser.Renderer.WebGL.Utils,c=function(t,i,s,e,h,a){for(var r=p.getTintAppendFloatAlpha(s.fillColor,s.fillAlpha*e),n=s.pathData,o=s.pathIndexes,l=0;l<o.length;l+=3){var u=2*o[l],d=2*o[l+1],c=2*o[l+2],v=n[u+0]-h,g=n[u+1]-a,y=n[d+0]-h,f=n[d+1]-a,P=n[c+0]-h,D=n[c+1]-a,_=i.getX(v,g),x=i.getY(v,g),b=i.getX(y,f),k=i.getY(y,f),S=i.getX(P,D),T=i.getY(P,D);t.batchTri(s,_,x,b,k,S,T,0,0,1,1,r,r,r,2)}},v=Phaser.Renderer.WebGL.Utils,g=function(t,i,s,e,h){var a=t.strokeTint,r=v.getTintAppendFloatAlpha(i.strokeColor,i.strokeAlpha*s);a.TL=r,a.TR=r,a.BL=r,a.BR=r;var n,o,l=i.isDashed&&!!i.strokePathData,u=l?i.strokePathData:i.pathData,d=u.length-1,p=i.lineWidth,c=p/2,g=u[0]-e,y=u[1]-h;if(i.closePath||(d-=2),l){var f=i.strokePathMask,P=0,D=0;for(_=2;_<d;_+=2)n=u[_]-e,o=u[_+1]-h,f[P]?(t.batchLine(g,y,n,o,c,c,p,D,!1),D++):D=0,g=n,y=o,P++}else for(var _=2;_<d;_+=2)n=u[_]-e,o=u[_+1]-h,t.batchLine(g,y,n,o,c,c,p,_-2,!!i.closePath&&_===d-1),g=n,y=o},y=function(t,i,s,e){var h=s||i.fillColor,a=e||i.fillAlpha,r=(16711680&h)>>>16,n=(65280&h)>>>8,o=255&h;t.fillStyle="rgba("+r+","+n+","+o+","+a+")"},f=function(t,i,s,e){var h=i.pathData;if(h&&!(h.length<4)){var a=h.length-1,r=h[0]-s,n=h[1]-e;t.beginPath(),t.moveTo(r,n),i.closePath||(a-=2);for(var o=2;o<a;o+=2){var l=h[o]-s,u=h[o+1]-e;t.lineTo(l,u)}i.closePath&&t.closePath(),y(t,i),t.fill()}},P=function(t,i,s,e){var h=i.isDashed&&!!i.strokePathData,a=h?i.strokePathData:i.pathData;if(a&&!(a.length<4)){var r=a.length-1,n=a[0]-s,o=a[1]-e;if(function(t,i,s,e){var h=s||i.strokeColor,a=e||i.strokeAlpha,r=(16711680&h)>>>16,n=(65280&h)>>>8,o=255&h;t.strokeStyle="rgba("+r+","+n+","+o+","+a+")",t.lineWidth=i.lineWidth}(t,i),t.beginPath(),i.closePath||(r-=2),h){var l=i.strokePathMask,u=0;for(d=2;d<r;d+=2)p=a[d]-s,c=a[d+1]-e,l[u]&&(t.moveTo(n,o),t.lineTo(p,c)),n=p,o=c,u++}else{t.moveTo(n,o);for(var d=2;d<r;d+=2){var p=a[d]-s,c=a[d+1]-e;t.lineTo(p,c)}i.closePath&&t.closePath()}t.stroke()}};const D=1e-6,_=10,x=.5;var b=function(t,i){return function(t){if(!Array.isArray(t))return null;for(var i=[],s=0,e=t.length;s<e;s++){var h=Number(t[s]);isFinite(h)&&h>0&&i.push(h)}return i.length>0?i:null}(t)||function(t,i){var{segments:s=_,drawRatio:e=x}=t;if(s=Math.round(s),!isFinite(s)||s<=0)return null;if(!(i>D))return null;var h=i/s;if(!(h>D))return null;if((e=Math.max(0,Math.min(1,e)))>=.999999)return null;var a=h*e;a<=D&&(a=D);var r=h-a;return r<=D?null:[a,r]}(t,i)},k=function(t,i,s){if(t&&!(t.length<4)){var e=t.length-1;if(i||(e-=2),!(e<2))for(var h=t[0],a=t[1],r=2;r<e;r+=2){var n=t[r],o=t[r+1];s(h,a,n,o),h=n,a=o}}},S=function(t,i,s){void 0===i&&(i={}),void 0===s&&(s={});var{closePath:e=!1,dashPattern:h,dashOffset:a=0}=i,r=function(t,i){var s=0;return k(t,i,(function(t,i,e,h){var a=e-t,r=h-i;s+=Math.sqrt(a*a+r*r)})),s}(t,e);if(null===(h=b(h,r)))return null;for(var n=[],o=[],l=0,u=0,d=h.length;u<d;u++)l+=h[u];if(l<=D)return s.strokePathData=t?t.slice():[],s.strokePathMask=void 0,s;for(var p=0,c=!0,v=h[p],g=function(){p=(p+1)%h.length,c=!c,v=h[p]},y=function(t,i){return isFinite(t)||(t=0),(t%=i)<0&&(t+=i),t}(a,l);y>D;)y<v-D?(v-=y,y=0):(y-=v,g());var f=function(t,i,s,e,h){if(0===n.length)n.push(t,i);else{var a=n[n.length-2],r=n[n.length-1];a===t&&r===i||n.push(t,i)}n.push(s,e),o.push(h?1:0)};return k(t,e,(function(t,i,s,e){var h=s-t,a=e-i,r=Math.sqrt(h*h+a*a);if(!(r<=D))for(var n=0;n<r-D;){var o=Math.min(v,r-n);if(o<=D)g();else{var l=n/r,u=(n+o)/r;f(t+h*l,i+a*l,t+h*u,i+a*u,c),n+=o,(v-=o)<=D&&g()}}})),!e&&n.length>=2&&n.push(n[n.length-2],n[n.length-1]),s.strokePathData=n,s.strokePathMask=o,s},T={setDashPattern:function(t,i){return this.dashPattern=t,this.dashOffset=i||0,this.isDashed=!!t,this},clearDashPattern:function(){return this.setDashPattern(),this},setDashed:function(t){return void 0===t&&(t=!0),this.isDashed=t,this}},m={buildStrokePath:function(){if(this.isDashed){var t=S(this.pathData,{closePath:this.closePath,dashPattern:this.dashPattern,dashOffset:this.dashOffset},this);t?(this.strokePathData=t.strokePathData,this.strokePathMask=t.strokePathMask):this.isDashed=!1}return this}};Object.assign(m,T);const A=Phaser.Geom.Polygon.Earcut;class R extends d{constructor(){super(),this.pathData=[],this.isDashed=!1,this.strokePathData=void 0,this.strokePathMask=void 0,this.dashPattern=void 0,this.dashOffset=0,this.pathIndexes=[],this.closePath=!1}updateData(){return this.pathIndexes=A(this.pathData),super.updateData(),this.buildStrokePath(),this}webglRender(t,i,s,e,h){this.isFilled&&c(t,i,this,s,e,h),this.isStroked&&g(t,this,s,e,h)}canvasRender(t,i,s){this.isFilled&&f(t,this,i,s),this.isStroked&&P(t,this,i,s)}}Object.assign(R.prototype,m);var L=function(t,i,s){var e=s.length;if(e>=2){var h=s[e-2],a=s[e-1];if(t===h&&i===a)return s}return s.push(t,i),s};const w=Phaser.Math.DegToRad;var C=function(t,i,s,e,h,a,r,n,o){r&&a>h?a-=360:!r&&a<h&&(a+=360);var l=w(a-h)/n;h=w(h);for(var u=0;u<=n;u++){var d=h+l*u,p=t+s*Math.cos(d),c=i+e*Math.sin(d);L(p,c,o)}return o};Phaser.Math.DegToRad;class X extends R{constructor(t,i,s,e,h,a,r,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===s&&(s=0),void 0===e&&(e=0),void 0===h&&(h=0),void 0===a&&(a=360),void 0===r&&(r=!1),void 0===n&&(n=!1),super(),this.setCenterPosition(t,i),this.setRadius(s,e),this.setAngle(h,a,r),this.setPie(n),this.setIterations(32)}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}setCenterPosition(t,i){return void 0===i&&(i=t),this.x=t,this.y=i,this}get radiusX(){return this._radiusX}set radiusX(t){this.dirty=this.dirty||this._radiusX!==t,this._radiusX=t}get radiusY(){return this._radiusY}set radiusY(t){this.dirty=this.dirty||this._radiusY!==t,this._radiusY=t}setRadius(t,i){return void 0===i&&(i=t),this.radiusX=t,this.radiusY=i,this}get startAngle(){return this._startAngle}set startAngle(t){this.dirty=this.dirty||this._startAngle!==t,this._startAngle=t}get endAngle(){return this._endAngle}set endAngle(t){this.dirty=this.dirty||this._endAngle!==t,this._endAngle=t}get anticlockwise(){return this._anticlockwise}set anticlockwise(t){this.dirty=this.dirty||this._anticlockwise!==t,this._anticlockwise=t}setAngle(t,i,s){return void 0===s&&(s=!1),this.startAngle=t,this.endAngle=i,this.anticlockwise=s,this}get pie(){return this._pie}set pie(t){this.dirty=this.dirty||this._pie!==t,this._pie=t}setPie(t){return void 0===t&&(t=!0),this.pie=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(){return this.pathData.length=0,this.pie&&this.pathData.push(this.x,this.y),C(this.x,this.y,this.radiusX,this.radiusY,this.startAngle,this.endAngle,this.anticlockwise,this.iterations,this.pathData),this.pie&&this.pathData.push(this.x,this.y),this.pathData.push(this.pathData[0],this.pathData[1]),super.updateData(),this}}const Y=Phaser.Math.Interpolation.QuadraticBezier,B=Phaser.Math.Interpolation.CubicBezier,M=Phaser.Math.Interpolation.CatmullRom;var O=function(t){var i=t.length;if(i<2)return t;var s=t[i-2],e=t[i-1];return t.push(s),t.push(e),t},F={clear(){return this.start(),this},start(){return this.startAt(),this},startAt(t,i){return this.restorePathData(),this.accumulationLengths=void 0,function(t,i,s){s.length=0,null!=t&&s.push(t,i)}(t,i,this.pathData),this.firstPointX=t,this.firstPointY=i,this.lastPointX=t,this.lastPointY=i,this},lineTo(t,i,s){return void 0===s&&(s=!1),s&&(t+=this.lastPointX,i+=this.lastPointY),L(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,s,e,h,a,r){return void 0===r&&(r=!1),C(t,i,s,e,h,a,r,this.iterations,this.pathData),this.lastPointX=this.pathData[this.pathData.length-2],this.lastPointY=this.pathData[this.pathData.length-1],this},arc(t,i,s,e,h,a){return this.ellipticalArc(t,i,s,s,e,h,a),this},quadraticBezierTo(t,i,s,e){return function(t,i,s,e,h,a){for(var r=a.length,n=a[r-2],o=a[r-1],l=1,u=h-1;l<=u;l++){var d=l/u;a.push(Y(d,n,t,s),Y(d,o,i,e))}}(t,i,s,e,this.iterations,this.pathData),this.lastPointX=s,this.lastPointY=e,this},cubicBezierTo(t,i,s,e,h,a){return function(t,i,s,e,h,a,r,n){for(var o=n.length,l=n[o-2],u=n[o-1],d=1,p=r-1;d<=p;d++){var c=d/p;n.push(B(c,l,t,s,h),B(c,u,i,e,a))}}(t,i,s,e,h,a,this.iterations,this.pathData),this.lastPointX=h,this.lastPointY=a,this},catmullRomTo(...t){return function(t,i,s){for(var e=s.length,h=[s[e-2]],a=[s[e-1]],r=0,n=t.length;r<n;r+=2)h.push(t[r]),a.push(t[r+1]);r=1;for(var o=i-1;r<=o;r++){var l=r/o;s.push(M(h,l),M(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],i=this.pathData[1];return t===this.lastPointX&&i===this.lastPointY||this.lineTo(t,i),this.closePath=!0,this},end(){return O(this.pathData),this}};const z=Phaser.Math.RotateAround;var j=function(t,i,s){for(var e=0,h=s.length-1;e<h;e+=2)s[e]+=t,s[e+1]+=i;return s};const I=Phaser.Math.DegToRad;Phaser.Math.RotateAround;var W={rotateAround(t,i,s){if(0===this.pathData.length)return this;!function(t,i,s,e){for(var h={x:0,y:0},a=0,r=e.length-1;a<r;a+=2)h.x=e[a],h.y=e[a+1],z(h,t,i,s),e[a]=h.x,e[a+1]=h.y}(t,i,s=I(s),this.pathData);var e=this.pathData.length;return this.lastPointX=this.pathData[e-2],this.lastPointY=this.pathData[e-1],this},scale(t,i,s,e){return 0===this.pathData.length||(function(t,i,s,e,h){for(var a=0,r=h.length-1;a<r;a+=2){var n=h[a]-t,o=h[a+1]-i;n*=s,o*=e,h[a]=n+t,h[a+1]=o+i}}(t,i,s,e,this.pathData),this.lastPointX=this.pathData[pathDataCnt-2],this.lastPointY=this.pathData[pathDataCnt-1]),this},offset(t,i){return j(t,i,this.pathData),this}},G={savePathData(){return this.pathDataSaved||(this.pathDataSave=[...this.pathData],this.pathData.length=0,this.pathDataSaved=!0),this},restorePathData(){return this.pathDataSaved?(function(t,i,s,e){void 0===s&&(s=0),void 0===e&&(e=i.length),t.length=e-s;for(var h=0,a=t.length;h<a;h++)t[h]=i[h+s]}(this.pathData,this.pathDataSave),this.pathDataSave=void 0,this.pathDataSaved=!1,this):this}};const U=Phaser.Math.Distance.Between,q=Phaser.Math.Wrap,V=Phaser.Math.Linear;var N=function(t,i,s,e,h){if(void 0===e&&(e=s,s=0),(s=Q(s))!==(e=Q(e))){var a=i[i.length-1],r=a*s,n=a*e;s<e?E(t,i,r,n,h):(E(t,i,r,a,h),E(t,i,0,n,h)),O(h)}},E=function(t,i,s,e,h){for(var a=s>0,r=0,n=i.length;r<n;r++){var o=2*r,l=i[r];if(a){if(l<s)continue;if(l==s)a=!1;else{var u=1-(l-s)/(l-i[r-1]);h.push(H(t,o-2,o,u)),h.push(H(t,o-1,o+1,u)),a=!1}}if(!(l<=e)){u=1-(l-e)/(l-i[r-1]),h.push(H(t,o-2,o,u)),h.push(H(t,o-1,o+1,u));break}if(h.push(t[o]),h.push(t[o+1]),l===e)break}},H=function(t,i,s,e){var h=t[i],a=t[s];return V(h,a,e)},Q=function(t){return 0===t?0:t%1==0?1:q(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,s,e,h=this.accumulationLengths,a=this.pathData,r=0,n=0,o=a.length;n<o;n+=2)s=a[n],e=a[n+1],r+=void 0===t?0:U(t,i,s,e),h.push(r),t=s,i=e;return this.totalPathLength=r,this},setDisplayPathSegment(t,i){return this.pathDataSaved||(this.updateAccumulationLengths(),this.savePathData()),this.pathData.length=0,N(this.pathDataSave,this.accumulationLengths,t,i,this.pathData),this},appendFromPathSegment(t,i,s){return void 0===i?this.pathData.push(...t.pathData):(t.updateAccumulationLengths(),N(t.pathData,t.accumulationLengths,i,s,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}},K={draw(t,i,s){var e=this.toPoints();return i&&t.fillPoints(e,this.closePath,this.closePath),s&&t.strokePoints(e,this.closePath,this.closePath),this}};const Z=Phaser.Geom.Polygon;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 s=0,e=t.length-1;s<e;s+=2)i.push({x:t[s],y:t[s+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)}}Object.assign($.prototype,F,W,G,J,K);const tt=Phaser.Renderer.WebGL.Utils.getTintAppendFloatAlpha;class it extends d{constructor(t,i,s,e){void 0===t&&(t=0),void 0===i&&(i=0),void 0===s&&(s=0),void 0===e&&(e=s),super(),this.pathData=[],this.isDashed=!1,this.strokePathData=void 0,this.strokePathMask=void 0,this.dashPattern=void 0,this.dashOffset=0,this.closePath=!0,this.setTopLeftPosition(t,i),this.setSize(s,e)}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}updateData(){this.pathData.length=0;var t=this.x,i=t+this.width,s=this.y,e=s+this.height;return this.pathData.push(t,s),this.pathData.push(i,s),this.pathData.push(i,e),this.pathData.push(t,e),this.pathData.push(t,s),super.updateData(),this.buildStrokePath(),this}webglRender(t,i,s,e,h){if(this.isFilled){var a=t.fillTint,r=tt(this.fillColor,this.fillAlpha*s);a.TL=r,a.TR=r,a.BL=r,a.BR=r,t.batchFillRect(-e+this.x,-h+this.y,this.width,this.height)}this.isStroked&&g(t,this,s,e,h)}canvasRender(t,i,s){this.isFilled&&(y(t,this),t.fillRect(-i,-s,this.width,this.height)),this.isStroked&&P(t,this,i,s)}}Object.assign(it.prototype,m);const st=Phaser.Utils.Objects.GetValue,et=Phaser.Geom.Polygon.Earcut;class ht extends d{constructor(t,i,s,e,h,a){void 0===t&&(t=0),void 0===i&&(i=0),void 0===s&&(s=0),void 0===e&&(e=0),void 0===h&&(h=0),void 0===a&&(a=0),super(),this.pathData=[],this.isDashed=!1,this.strokePathData=void 0,this.strokePathMask=void 0,this.dashPattern=void 0,this.dashOffset=0,this.pathIndexes=[],this.closePath=!0,this.setP0(t,i),this.setP1(s,e),this.setP2(h,a)}get x0(){return this._x0}set x0(t){this.dirty=this.dirty||this._x0!==t,this._x0=t}get y0(){return this._y0}set y0(t){this.dirty=this.dirty||this._y0!==t,this._y0=t}setP0(t,i){return this.x0=t,this.y0=i,this}get x1(){return this._x1}set x1(t){this.dirty=this.dirty||this._x1!==t,this._x1=t}get y1(){return this._y1}set y1(t){this.dirty=this.dirty||this._y1!==t,this._y1=t}setP1(t,i){return this.x1=t,this.y1=i,this}get x2(){return this._x2}set x2(t){this.dirty=this.dirty||this._x2!==t,this._x2=t}get y2(){return this._y2}set y2(t){this.dirty=this.dirty||this._y2!==t,this._y2=t}setP2(t,i){return this.dirty=this.dirty||this.x2!==t||this.y2!==i,this.x2=t,this.y2=i,this}updateData(){return this.pathData.length=0,this.pathData.push(this.x0,this.y0),this.pathData.push(this.x1,this.y1),this.pathData.push(this.x2,this.y2),this.pathData.push(this.x0,this.y0),this.pathIndexes=et(this.pathData),super.updateData(),this.buildStrokePath(),this}webglRender(t,i,s,e,h){this.isFilled&&c(t,i,this,s,e,h),this.isStroked&&g(t,this,s,e,h)}canvasRender(t,i,s){this.isFilled&&f(t,this,i,s),this.isStroked&&P(t,this,i,s)}}Object.assign(ht.prototype,m);const at={arc:X,circle:class extends X{constructor(t,i,s){super(t,i,s,s,0,360)}},curve:class extends R{constructor(t){super(),this.setCurve(t),this.setIterations(32)}get curve(){return this._curve}set curve(t){this.dirty=this.dirty||this._curve!==t,this._curve=t}setCurve(t){return this.curve=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(){this.pathData.length=0;for(var t=this.curve.getPoints(this.iterations),i=0,s=t.length;i<s;i++)this.pathData.push(t[i].x,t[i].y);return this.pathData.push(t[0].x,t[0].y),super.updateData(),this}},ellipse:class extends X{constructor(t,i,s,e){super(t,i,s,e,0,360)}},line:class extends R{constructor(t,i,s,e){void 0===t&&(t=0),void 0===i&&(i=0),void 0===s&&(s=0),void 0===e&&(e=0),super(),this.setP0(t,i),this.setP1(s,e)}get x0(){return this._x0}set x0(t){this.dirty=this.dirty||this._x0!==t,this._x0=t}get y0(){return this._y0}set y0(t){this.dirty=this.dirty||this._y0!==t,this._y0=t}setP0(t,i){return this.x0=t,this.y0=i,this}get x1(){return this._x1}set x1(t){this.dirty=this.dirty||this._x1!==t,this._x1=t}get y1(){return this._y1}set y1(t){this.dirty=this.dirty||this._y1!==t,this._y1=t}setP1(t,i){return this.x1=t,this.y1=i,this}updateData(){return this.pathData.length=0,this.pathData.push(this.x0,this.y0),this.pathData.push(this.x1,this.y1),this.pathData.push(this.x0,this.y0),super.updateData(),this}},lines:class extends R{constructor(){super(),this.builder=new $(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,i){return this.builder.startAt(t,i),this.dirty=!0,this}lineTo(t,i,s){return this.builder.lineTo(t,i,s),this.dirty=!0,this}verticalLineTo(t,i){return this.builder.verticalLineTo(t,i),this.dirty=!0,this}horizontalLineTo(t,i){return this.builder.horizontalLineTo(t,i),this.dirty=!0,this}ellipticalArc(t,i,s,e,h,a,r){return this.builder.ellipticalArc(t,i,s,e,h,a,r),this.dirty=!0,this}arc(t,i,s,e,h,a){return this.builder.arc(t,i,s,e,h,a),this.dirty=!0,this}quadraticBezierTo(t,i,s,e){return this.builder.quadraticBezierTo(t,i,s,e),this.dirty=!0,this}cubicBezierTo(t,i,s,e,h,a){return this.builder.cubicBezierTo(t,i,s,e,h,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,i,s){return this.builder.rotateAround(t,i,s),this.dirty=!0,this}scale(t,i,s,e){return this.builder.scale(t,i,s,e),this.dirty=!0,this}offset(t,i){return this.builder.offset(t,i),this.dirty=!0,this}toPolygon(t){return this.builder.toPolygon(t)}appendPathFrom(t,i,s){return this.builder.appendFromPathSegment(t.builder,i,s),this}copyPathFrom(t,i,s){return this.builder.clear().appendFromPathSegment(t.builder,i,s),this}setDisplayPathSegment(t,i){return this.builder.setDisplayPathSegment(t,i),this}},rectangle:it,roundRectangle:class extends R{constructor(t,i,s,e,h,a){void 0===t&&(t=0),void 0===i&&(i=0),void 0===s&&(s=0),void 0===e&&(e=s),void 0===h&&(h=0),void 0===a&&(a=6),super(),this.setTopLeftPosition(t,i),this.setSize(s,e),this.setRadius(h),this.setIterations(a),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=st(t,"tl",0),this.radiusTR=st(t,"tr",0),this.radiusBL=st(t,"bl",0),this.radiusBR=st(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,s=this.width,e=this.height,h=this.iterations+1;return(i=this.radiusTL)>0?this._convexTL?C(i,i,i,i,180,270,!1,h,t):C(0,0,i,i,90,0,!0,h,t):L(0,0,t),(i=this.radiusTR)>0?this._convexTR?C(s-i,i,i,i,270,360,!1,h,t):C(s,0,i,i,180,90,!0,h,t):L(s,0,t),(i=this.radiusBR)>0?this._convexBR?C(s-i,e-i,i,i,0,90,!1,h,t):C(s,e,i,i,270,180,!0,h,t):L(s,e,t),(i=this.radiusBL)>0?this._convexBL?C(i,e-i,i,i,90,180,!1,h,t):C(0,e,i,i,360,270,!0,h,t):L(0,e,t),t.push(t[0],t[1]),j(this.x,this.y,t),super.updateData(),this}},triangle:ht},rt=Phaser.Utils.Objects.GetValue,nt=Phaser.Utils.Objects.IsPlainObject,ot=function(){for(var t=this.getShapes(),i=0,s=t.length;i<s;i++)t[i].lineStyle().fillStyle()};var lt={createShape(t,i){var s=new(0,at[t]);return i&&s.setName(i),s},buildShapes(t){var i=rt(t,"create",void 0);if(nt(i)){var s=i;for(var e in s){var h=s[e];switch(typeof h){case"number":for(var a=0;a<h;a++)this.addShape(this.createShape(e));break;case"string":this.addShape(this.createShape(e,h));break;default:for(var r=h,n=(a=0,r.length);a<n;a++)this.addShape(this.createShape(e,r[a]))}}}else if(Array.isArray(i))for(a=0,n=(s=i).length;a<n;a++){var o=s[a];this.addShape(this.createShape(o.type,o.name))}else"function"==typeof i&&i.call(this);this.setUpdateShapesCallback(rt(t,"update"))},setUpdateShapesCallback(t){return void 0===t&&(t=ot),this.dirty=this.dirty||this.updateCallback!==t,this.updateCallback=t,this},updateShapes(){this.updateCallback.call(this)}};const ut=Phaser.GameObjects.Components.TransformMatrix,dt=Phaser.Math.TransformXY;var pt,ct,vt={};const gt=Phaser.Utils.Objects.GetValue,yt=Phaser.Utils.Objects.IsPlainObject;class ft extends r{constructor(t,i,s,e,h,a){yt(i)&&(i=gt(a=i,"x",0),s=gt(a,"y",0),e=gt(a,"width",2),h=gt(a,"height",2)),super(t,i,s,e,h),this.type=gt(a,"type","rexCustomShapes"),this.buildShapes(a)}get centerX(){return this.width/2}get centerY(){return this.height/2}worldToLocalXY(t,i,s,e){return"boolean"==typeof s&&(e=s,s=void 0),function(t,i,s,e,h){void 0===e&&(e=t.scene.cameras.main),void 0===h?h={}:!0===h&&(h=vt);var a=e.scrollX,r=e.scrollY,n=i+a*t.scrollFactorX-a,o=s+r*t.scrollFactorY-r;return t.parentContainer?(void 0===pt&&(pt=new ut,ct=new ut),t.getWorldTransformMatrix(pt,ct),pt.applyInverse(n,o,h)):dt(n,o,t.x,t.y,t.rotation,t.scaleX,t.scaleY,h),h.x+=t.displayOriginX,h.y+=t.displayOriginY,h}(this,t,i,s,e)}}return Object.assign(ft.prototype,lt),ft},"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).rexcustomshapes=i();