phaser3-rex-plugins
Version:
2 lines (1 loc) • 29.8 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(),s.addToRenderList(e);var a=i.pipelines.set(e.pipeline),r=t(e,s,h),n=a.calcMatrix.copyFrom(r.calc),o=e._displayOriginX,l=e._displayOriginY,d=s.alpha*e.alpha;i.pipelines.preBatch(e);for(var u,p=e.geom,c=0,v=p.length;c<v;c++)(u=p[c]).visible&&u.webglRender(a,n,d,o,l);i.pipelines.postBatch(e)},renderCanvas:function(t,e,s,h){e.updateData(),s.addToRenderList(e);var a=t.currentContext;if(i(t,a,e,s,h)){for(var r,n=e._displayOriginX,o=e._displayOriginY,l=e.geom,d=0,u=l.length;d<u;d++)(r=l[d]).visible&&r.canvasRender(a,n,o);a.restore()}}},s=function(t){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))t.length=0;else for(var 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,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],a(this.geom,i)),this}}Object.assign(r.prototype,e);const n={bezier:0,spline:1,polyline:2,poly:2,straightline:3,straight:3},o={none:0,triangle:1,dot:2,box:3,diamond:4};var l={setHeadShape(t){return"string"==typeof t&&(t=o[t.toLowerCase()]),this.headShape=t,this},setHeadSize(t){return this.headSize=t,this},setHeadFillStyle(t,i){return void 0===i&&(i=1),this.headColor=t,this.headAlpha=i,this},setHeadStrokeStyle(t,i,e){return void 0===e&&(e=1),this.headStrokeWidth=t,this.headStrokeColor=i,this.headStrokeAlpha=e,this},setTailShape(t){return"string"==typeof t&&(t=o[t.toLowerCase()]),this.tailShape=t,this},setTailSize(t){return this.tailSize=t,this},setTailFillStyle(t,i){return void 0===i&&(i=1),this.tailColor=t,this.tailAlpha=i,this},setTailStrokeStyle(t,i,e){return void 0===e&&(e=1),this.tailStrokeWidth=t,this.tailStrokeColor=i,this.tailStrokeAlpha=e,this}},d={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}},u=function(t,i,e){for(var s=t,h=e,a=0,r=i.length;a<r;a++){var n=i[a];if(!s||"object"!=typeof s&&"function"!=typeof s||!(n in s))return p.found=!1,p;s=h=s[n]}return p.found=!0,p.value=h,p},p={},c={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,s){var h=t&&("object"==typeof t||"function"==typeof t),a=s&&("object"==typeof s||"function"==typeof s);if(!h&&!a)return e;var r=String(i);if(h&&r in t)return t[r];if(a&&r in s)return s[r];if(-1===r.indexOf("."))return e;var n=r.split(".");if(h){var o=u(t,n,e);if(o.found)return o.value}if(a){var l=u(s,n,e);if(l.found)return l.value}return e}(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 v{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){}canvasRender(t,i,e){}updateData(){this.dirty=!1}}Object.assign(v.prototype,d,c);var f=Phaser.Renderer.WebGL.Utils,y=function(t,i,e,s,h,a){for(var r=f.getTintAppendFloatAlpha(e.fillColor,e.fillAlpha*s),n=e.pathData,o=e.pathIndexes,l=0;l<o.length;l+=3){var d=2*o[l],u=2*o[l+1],p=2*o[l+2],c=n[d+0]-h,v=n[d+1]-a,y=n[u+0]-h,g=n[u+1]-a,S=n[p+0]-h,P=n[p+1]-a,D=i.getX(c,v),k=i.getY(c,v),b=i.getX(y,g),_=i.getY(y,g),A=i.getX(S,P),m=i.getY(S,P);t.batchTri(e,D,k,b,_,A,m,0,0,1,1,r,r,r,2)}},g=Phaser.Renderer.WebGL.Utils,S=function(t,i,e,s,h){var a=t.strokeTint,r=g.getTintAppendFloatAlpha(i.strokeColor,i.strokeAlpha*e);a.TL=r,a.TR=r,a.BL=r,a.BR=r;var n,o,l=i.isDashed&&!!i.strokePathData,d=l?i.strokePathData:i.pathData,u=d.length-1,p=i.lineWidth,c=p/2,v=d[0]-s,f=d[1]-h;if(i.closePath||(u-=2),l){var y=i.strokePathMask,S=0,P=0;for(D=2;D<u;D+=2)n=d[D]-s,o=d[D+1]-h,y[S]?(t.batchLine(v,f,n,o,c,c,p,P,!1),P++):P=0,v=n,f=o,S++}else for(var D=2;D<u;D+=2)n=d[D]-s,o=d[D+1]-h,t.batchLine(v,f,n,o,c,c,p,D-2,!!i.closePath&&D===u-1),v=n,f=o},P=function(t,i,e,s){var h=e||i.fillColor,a=s||i.fillAlpha,r=(16711680&h)>>>16,n=(65280&h)>>>8,o=255&h;t.fillStyle="rgba("+r+","+n+","+o+","+a+")"},D=function(t,i,e,s){var h=i.pathData;if(h&&!(h.length<4)){var a=h.length-1,r=h[0]-e,n=h[1]-s;t.beginPath(),t.moveTo(r,n),i.closePath||(a-=2);for(var o=2;o<a;o+=2){var l=h[o]-e,d=h[o+1]-s;t.lineTo(l,d)}i.closePath&&t.closePath(),P(t,i),t.fill()}},k=function(t,i,e,s){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]-e,o=a[1]-s;if(function(t,i,e,s){var h=e||i.strokeColor,a=s||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,d=0;for(u=2;u<r;u+=2)p=a[u]-e,c=a[u+1]-s,l[d]&&(t.moveTo(n,o),t.lineTo(p,c)),n=p,o=c,d++}else{t.moveTo(n,o);for(var u=2;u<r;u+=2){var p=a[u]-e,c=a[u+1]-s;t.lineTo(p,c)}i.closePath&&t.closePath()}t.stroke()}};const b=1e-6,_=10,A=.5;var m=function(t,i){return function(t){if(!Array.isArray(t))return null;for(var i=[],e=0,s=t.length;e<s;e++){var h=Number(t[e]);isFinite(h)&&h>0&&i.push(h)}return i.length>0?i:null}(t)||function(t,i){var{segments:e=_,drawRatio:s=A}=t;if(e=Math.round(e),!isFinite(e)||e<=0)return null;if(!(i>b))return null;var h=i/e;if(!(h>b))return null;if((s=Math.max(0,Math.min(1,s)))>=.999999)return null;var a=h*s;a<=b&&(a=b);var r=h-a;return r<=b?null:[a,r]}(t,i)},x=function(t,i,e){if(t&&!(t.length<4)){var s=t.length-1;if(i||(s-=2),!(s<2))for(var h=t[0],a=t[1],r=2;r<s;r+=2){var n=t[r],o=t[r+1];e(h,a,n,o),h=n,a=o}}},T=function(t,i,e){void 0===i&&(i={}),void 0===e&&(e={});var{closePath:s=!1,dashPattern:h,dashOffset:a=0}=i,r=function(t,i){var e=0;return x(t,i,(function(t,i,s,h){var a=s-t,r=h-i;e+=Math.sqrt(a*a+r*r)})),e}(t,s);if(null===(h=m(h,r)))return null;for(var n=[],o=[],l=0,d=0,u=h.length;d<u;d++)l+=h[d];if(l<=b)return e.strokePathData=t?t.slice():[],e.strokePathMask=void 0,e;for(var p=0,c=!0,v=h[p],f=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>b;)y<v-b?(v-=y,y=0):(y-=v,f());var g=function(t,i,e,s,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(e,s),o.push(h?1:0)};return x(t,s,(function(t,i,e,s){var h=e-t,a=s-i,r=Math.sqrt(h*h+a*a);if(!(r<=b))for(var n=0;n<r-b;){var o=Math.min(v,r-n);if(o<=b)f();else{var l=n/r,d=(n+o)/r;g(t+h*l,i+a*l,t+h*d,i+a*d,c),n+=o,(v-=o)<=b&&f()}}})),!s&&n.length>=2&&n.push(n[n.length-2],n[n.length-1]),e.strokePathData=n,e.strokePathMask=o,e},C={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}},w={buildStrokePath:function(){if(this.isDashed){var t=T(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(w,C);const z=Phaser.Geom.Polygon.Earcut;class L extends v{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=z(this.pathData),super.updateData(),this.buildStrokePath(),this}webglRender(t,i,e,s,h){this.isFilled&&y(t,i,this,e,s,h),this.isStroked&&S(t,this,e,s,h)}canvasRender(t,i,e){this.isFilled&&D(t,this,i,e),this.isStroked&&k(t,this,i,e)}}Object.assign(L.prototype,w);var R=function(t,i,e){var s=e.length;if(s>=2){var h=e[s-2],a=e[s-1];if(t===h&&i===a)return e}return e.push(t,i),e};const O=Phaser.Math.DegToRad;Phaser.Math.DegToRad;const W=Phaser.Math.Interpolation.QuadraticBezier,M=Phaser.Math.Interpolation.CubicBezier,F=Phaser.Math.Interpolation.CatmullRom;var j=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},X={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),R(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,a,r){return void 0===r&&(r=!1),function(t,i,e,s,h,a,r,n,o){r&&a>h?a-=360:!r&&a<h&&(a+=360);var l=O(a-h)/n;h=O(h);for(var d=0;d<=n;d++){var u=h+l*d,p=t+e*Math.cos(u),c=i+s*Math.sin(u);R(p,c,o)}}(t,i,e,s,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,e,s,h,a){return this.ellipticalArc(t,i,e,e,s,h,a),this},quadraticBezierTo(t,i,e,s){return function(t,i,e,s,h,a){for(var r=a.length,n=a[r-2],o=a[r-1],l=1,d=h-1;l<=d;l++){var u=l/d;a.push(W(u,n,t,e),W(u,o,i,s))}}(t,i,e,s,this.iterations,this.pathData),this.lastPointX=e,this.lastPointY=s,this},cubicBezierTo(t,i,e,s,h,a){return function(t,i,e,s,h,a,r,n){for(var o=n.length,l=n[o-2],d=n[o-1],u=1,p=r-1;u<=p;u++){var c=u/p;n.push(M(c,l,t,e,h),M(c,d,i,s,a))}}(t,i,e,s,h,a,this.iterations,this.pathData),this.lastPointX=h,this.lastPointY=a,this},catmullRomTo(...t){return function(t,i,e){for(var s=e.length,h=[e[s-2]],a=[e[s-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;e.push(F(h,l),F(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 j(this.pathData),this}};const Y=Phaser.Math.RotateAround,G=Phaser.Math.DegToRad;Phaser.Math.RotateAround;var B={rotateAround(t,i,e){if(0===this.pathData.length)return this;!function(t,i,e,s){for(var h={x:0,y:0},a=0,r=s.length-1;a<r;a+=2)h.x=s[a],h.y=s[a+1],Y(h,t,i,e),s[a]=h.x,s[a+1]=h.y}(t,i,e=G(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 a=0,r=h.length-1;a<r;a+=2){var n=h[a]-t,o=h[a+1]-i;n*=e,o*=s,h[a]=n+t,h[a+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 function(t,i,e){for(var s=0,h=e.length-1;s<h;s+=2)e[s]+=t,e[s+1]+=i}(t,i,this.pathData),this}},I={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,a=t.length;h<a;h++)t[h]=i[h+e]}(this.pathData,this.pathDataSave),this.pathDataSave=void 0,this.pathDataSaved=!1,this):this}};const H=Phaser.Math.Distance.Between,V=Phaser.Math.Wrap,U=Phaser.Math.Linear;var q=function(t,i,e,s,h){if(void 0===s&&(s=e,e=0),(e=Q(e))!==(s=Q(s))){var a=i[i.length-1],r=a*e,n=a*s;e<s?N(t,i,r,n,h):(N(t,i,r,a,h),N(t,i,0,n,h)),j(h)}},N=function(t,i,e,s,h){for(var a=e>0,r=0,n=i.length;r<n;r++){var o=2*r,l=i[r];if(a){if(l<e)continue;if(l==e)a=!1;else{var d=1-(l-e)/(l-i[r-1]);h.push(E(t,o-2,o,d)),h.push(E(t,o-1,o+1,d)),a=!1}}if(!(l<=s)){d=1-(l-s)/(l-i[r-1]),h.push(E(t,o-2,o,d)),h.push(E(t,o-1,o+1,d));break}if(h.push(t[o]),h.push(t[o+1]),l===s)break}},E=function(t,i,e,s){var h=t[i],a=t[e];return U(h,a,s)},Q=function(t){return 0===t?0:t%1==0?1:V(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,a=this.pathData,r=0,n=0,o=a.length;n<o;n+=2)e=a[n],s=a[n+1],r+=void 0===t?0:H(t,i,e,s),h.push(r),t=e,i=s;return this.totalPathLength=r,this},setDisplayPathSegment(t,i){return this.pathDataSaved||(this.updateAccumulationLengths(),this.savePathData()),this.pathData.length=0,q(this.pathDataSave,this.accumulationLengths,t,i,this.pathData),this},appendFromPathSegment(t,i,e){return void 0===i?this.pathData.push(...t.pathData):(t.updateAccumulationLengths(),q(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}},K={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;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)}}Object.assign($.prototype,X,B,I,J,K);class tt extends L{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,e){return this.builder.lineTo(t,i,e),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,e,s,h,a,r){return this.builder.ellipticalArc(t,i,e,s,h,a,r),this.dirty=!0,this}arc(t,i,e,s,h,a){return this.builder.arc(t,i,e,s,h,a),this.dirty=!0,this}quadraticBezierTo(t,i,e,s){return this.builder.quadraticBezierTo(t,i,e,s),this.dirty=!0,this}cubicBezierTo(t,i,e,s,h,a){return this.builder.cubicBezierTo(t,i,e,s,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,e){return this.builder.rotateAround(t,i,e),this.dirty=!0,this}scale(t,i,e,s){return this.builder.scale(t,i,e,s),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,e){return this.builder.appendFromPathSegment(t.builder,i,e),this}copyPathFrom(t,i,e){return this.builder.clear().appendFromPathSegment(t.builder,i,e),this}setDisplayPathSegment(t,i){return this.builder.setDisplayPathSegment(t,i),this}}const it=Phaser.Renderer.WebGL.Utils.getTintAppendFloatAlpha;Object.assign(class extends v{constructor(t,i,e,s){void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=0),void 0===s&&(s=e),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(e,s)}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,e=this.y,s=e+this.height;return this.pathData.push(t,e),this.pathData.push(i,e),this.pathData.push(i,s),this.pathData.push(t,s),this.pathData.push(t,e),super.updateData(),this.buildStrokePath(),this}webglRender(t,i,e,s,h){if(this.isFilled){var a=t.fillTint,r=it(this.fillColor,this.fillAlpha*e);a.TL=r,a.TR=r,a.BL=r,a.BR=r,t.batchFillRect(-s+this.x,-h+this.y,this.width,this.height)}this.isStroked&&S(t,this,e,s,h)}canvasRender(t,i,e){this.isFilled&&(P(t,this),t.fillRect(-i,-e,this.width,this.height)),this.isStroked&&k(t,this,i,e)}}.prototype,w),Phaser.Utils.Objects.GetValue;const et=Phaser.Geom.Polygon.Earcut;Object.assign(class extends v{constructor(t,i,e,s,h,a){void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=0),void 0===s&&(s=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(e,s),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,e,s,h){this.isFilled&&y(t,i,this,e,s,h),this.isStroked&&S(t,this,e,s,h)}canvasRender(t,i,e){this.isFilled&&D(t,this,i,e),this.isStroked&&k(t,this,i,e)}}.prototype,w);var st=function(t){var i=this.points,e=i[1],s=i[2];t.startAt(0,0).quadraticBezierTo(e.x,e.y,s.x,s.y).end()},ht=function(t){var i=this.points,e=i[1],s=i[2],h=i[3];t.startAt(0,0).cubicBezierTo(e.x,e.y,s.x,s.y,h.x,h.y).end()},at=function(t){for(var i=this.points,e=[],s=1,h=i.length;s<h;s++){var a=i[s];e.push(a.x),e.push(a.y)}t.startAt(0,0).catmullRomTo(...e).end()},rt=function(t){var i=this.points,e=i[i.length-1];t.startAt(0,0).lineTo(e.x,e.y).end()},nt=function(t){var i=this.points;t.startAt(0,0);for(var e=1,s=i.length;e<s;e++){var h=i[e];t.lineTo(h.x,h.y)}t.end()};const ot=Phaser.Geom.Rectangle;var lt=function(t,i){switch(void 0===i?i=new ot:!0===i&&(i=dt),t.length){case 0:i.setTo(0,0,0,0);break;case 2:i.setTo(t[0],t[1],0,0);break;default:for(var e=1/0,s=1/0,h=-e,a=-s,r=0,n=t.length;r<n;r+=2){var o=t[r],l=t[r+1];e=Math.min(e,o),s=Math.min(s,l),h=Math.max(h,o),a=Math.max(a,l)}i.setTo(e,s,h-e,a-s)}return i},dt=new ot,ut=function(t,i,e,s,h,a,r){var n=a/2;switch(r){case 1:var o,l;if(i===s&&e===h)o=1,l=0;else{o=i-s,l=e-h;var d=Math.hypot(o,l);o/=d,l/=d}var u=-l,p=i-o*a,c=e-l*a,v=a/2,f=p+u*v,y=c+o*v,g=p-u*v,S=c-o*v;t.startAt(i,e).lineTo(f,y).lineTo(g,S).close();break;case 2:default:t.start().arc(i,e,n,0,360).close();break;case 3:t.startAt(i-n,e-n).lineTo(a,0,!0).lineTo(0,a,!0).lineTo(-a,0,!0).lineTo(0,-a,!0).close();break;case 4:t.startAt(i,e-n).lineTo(i+n,e).lineTo(i,e+n).lineTo(i-n,e).close()}},pt=function(){var t=this.bounds,i=this.pointRadius,e=t.x-i,s=t.y-i,h=t.width+2*i,a=t.height+2*i;this.setSize(h,a),this.setOrigin(-e/h,-s/a);for(var r=this.getShapes(),n=0,o=r.length;n<o;n++){var l=r[n];l.visible&&l.offset(-e,-s)}},ct={buildShapes(){var t=(new tt).setName("body"),i=(new tt).setName("head"),e=(new tt).setName("tail");this.addShape(t).addShape(i).addShape(e)},updateShapes(){var t=this.points.length,i=t>=2,e=this.getShape("body").setVisible(i);i&&(e.lineStyle(this.lineWidth,this.strokeColor,this.strokeAlpha),3===this.lineType||2==t?rt.call(this,e):0===this.lineType&&3===t?st.call(this,e):0===this.lineType&&4===t?ht.call(this,e):2===this.lineType?nt.call(this,e):at.call(this,e));var s=t>=1,h=s&&0!==this.headShape,a=s&&0!==this.tailShape,r=this.getShape("head").setVisible(h),n=this.getShape("tail").setVisible(a);if(h){r.fillStyle(this.headColor,this.headAlpha).lineStyle(this.headStrokeWidth,this.headStrokeColor,this.headStrokeAlpha);var o=this.points[0];l=t>=2?3===this.lineType?this.points[t-1]:this.points[1]:o,ut(r,o.x,o.y,l.x,l.y,this.headSize,this.headShape)}if(a){n.fillStyle(this.tailColor,this.tailAlpha).lineStyle(this.tailStrokeWidth,this.tailStrokeColor,this.tailStrokeAlpha);var l,d=this.points[t-1];l=3===this.lineType?this.points[0]:this.points[t-2],ut(n,d.x,d.y,l.x,l.y,this.tailSize,this.tailShape)}this.bounds=lt.call(this,e.pathData,!0),pt.call(this),i&&e.setDashPattern(this.dashPattern,this.dashOffset)}};const vt=Phaser.Geom.Intersects.LineToCircle,ft=new Phaser.Geom.Line,yt=Phaser.Geom.Rectangle,gt=Phaser.Geom.Rectangle.Contains,St=Phaser.GameObjects.GameObject.prototype.setInteractive,Pt=new Phaser.Geom.Circle;var Dt=function(t,i,e,s){return!!gt(t,i,e)&&(Pt.setTo(i,e,s.pointRadius),function(t,i){ft.x1=t[0],ft.y1=t[1];for(var e=2,s=t.length;e<s;e+=2){if(ft.x2=t[e],ft.y2=t[e+1],vt(ft,i))return!0;ft.x1=ft.x2,ft.y1=ft.y2}return!1}(s.getShapes()[0].pathData,Pt))},kt={setPointRadius(t){return this.pointRadius=t,this},setInteractive(t){return void 0===t&&(t={}),t.hitArea=new yt(0,0,this.width,this.height),t.hitAreaCallback=Dt,St.call(this,t),this}},bt={};Object.assign(bt,l,ct,kt,C);class _t extends r{constructor(t,i,e,s,h,a){var r,n,o,l,d,u,p,c,v,f,y,g,S,P,D,k,b,_;void 0!==i&&("number"==typeof i?(r=h,h=s,s=e,e=i,i=[]):Array.isArray(i)||(i=(a=i).points,e=a.lineWidth,s=a.color,h=a.alpha)),void 0===a&&(a={}),r=a.lineType,n=a.pointRadius,o=a.headShape,l=a.headSize,d=a.headColor,u=a.headAlpha,p=a.headStrokeWidth,c=a.headStrokeColor,v=a.headStrokeAlpha,f=a.tailShape,y=a.tailSize,g=a.tailColor,S=a.tailAlpha,P=a.tailStrokeWidth,D=a.tailStrokeColor,k=a.tailStrokeAlpha,b=a.dashPattern,_=a.dashOffset,void 0===i&&(i=[]),void 0===e&&(e=2),void 0===s&&(s=16777215),void 0===h&&(h=1),void 0===r&&(r=0),void 0===n&&(n=10),void 0===o&&(o=0),void 0===l&&(l=4*e),void 0===d&&(d=s),void 0===p&&(p=1),void 0===f&&(f=0),void 0===y&&(y=l),void 0===g&&(g=s),void 0===P&&(P=1),super(t),this.type="rexLine",this.points=[],this.padding={},this.bounds=void 0,this.setPointRadius(n),this.setLine(i,r),this.setStrokeStyle(e,s,h),this.setHeadShape(o),this.setHeadSize(l),this.setHeadFillStyle(d,u),this.setHeadStrokeStyle(p,c,v),this.setTailShape(f),this.setTailSize(y),this.setTailFillStyle(g,S),this.setTailStrokeStyle(P,D,k),this.setDashPattern(b,_),this.buildShapes(),this.updateData()}setLine(t,i){void 0===t&&(t=[]),void 0!==i&&("string"==typeof i&&(i=n[i.toLocaleLowerCase()]),this.lineType=i),this.points.length=0;var e=0,s=0;t.length>0&&(e=t[0].x,s=t[0].y),this.x=e,this.y=s;for(var h=0,a=t.length;h<a;h++){var r=t[h];this.points.push({x:r.x-e,y:r.y-s})}return this.dirty=!0,this.geom.length>0&&this.updateData(),this}setLineType(t){return"string"==typeof t&&(t=n[t.toLocaleLowerCase()]),this.lineType===t||(this.lineType=t,this.dirty=!0,this.geom.length>0&&this.updateData()),this}getPoints(t){void 0===t&&(t=[]);for(var i=this.x,e=this.y,s=this.points,h=0,a=s.length;h<a;h++){var r=s[h];t.push({x:r.x+i,y:r.y+e})}return t}get headShape(){return this._headShape}set headShape(t){this.dirty=this.dirty||this._headShape!=t,this._headShape=t}get headSize(){return this._headSize}set headSize(t){this.dirty=this.dirty||this._headSize!=t,this._headSize=t}get headColor(){return this._headColor}set headColor(t){this.dirty=this.dirty||this._headColor!=t,this._headColor=t}get headAlpha(){return this._headAlpha}set headAlpha(t){this.dirty=this.dirty||this._headAlpha!=t,this._headAlpha=t}get headStokeWidth(){return this._headStokeWidth}set headStokeWidth(t){this.dirty=this.dirty||this._headStokeWidth!=t,this._headStokeWidth=t}get headStokeColor(){return this._headStokeColor}set headStokeColor(t){this.dirty=this.dirty||this._headStokeColor!=t,this._headStokeColor=t}get headStokeAlpha(){return this._headStokeAlpha}set headStokeAlpha(t){this.dirty=this.dirty||this._headStokeAlpha!=t,this._headStokeAlpha=t}get tailShape(){return this._tailShape}set tailShape(t){this.dirty=this.dirty||this._tailShape!=t,this._tailShape=t}get tailSize(){return this._tailSize}set tailSize(t){this.dirty=this.dirty||this._tailSize!=t,this._tailSize=t}get tailColor(){return this._tailColor}set tailColor(t){this.dirty=this.dirty||this._tailColor!=t,this._tailColor=t}get tailAlpha(){return this._tailAlpha}set tailAlpha(t){this.dirty=this.dirty||this._tailAlpha!=t,this._tailAlpha=t}get tailStokeWidth(){return this._tailStokeWidth}set tailStokeWidth(t){this.dirty=this.dirty||this._tailStokeWidth!=t,this._tailStokeWidth=t}get tailStokeColor(){return this._tailStokeColor}set tailStokeColor(t){this.dirty=this.dirty||this._tailStokeColor!=t,this._tailStokeColor=t}get tailStokeAlpha(){return this._tailStokeAlpha}set tailStokeAlpha(t){this.dirty=this.dirty||this._tailStokeAlpha!=t,this._tailStokeAlpha=t}}function At(t,i,e,s,h){var a=new _t(this.scene,t,i,e,s,h);return this.scene.add.existing(a),a}Object.assign(_t.prototype,bt);const mt=Phaser.Utils.Objects.GetAdvancedValue,xt=Phaser.Utils.Objects.GetValue,Tt=Phaser.GameObjects.BuildGameObject;function Ct(t,i){void 0===t&&(t={}),void 0!==i&&(t.add=i);var e=xt(t,"points",void 0),s=mt(t,"lineWidth",2),h=mt(t,"color",16777215),a=mt(t,"alpha",1),r=mt(t,"lineType",0),n=new _t(this.scene,e,s,h,a,r);return Tt(this.scene,n,t),n}var wt=function(t){return null!==t&&"object"==typeof t};class zt extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexLineShape",At,Ct)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,i,e,s="."){if(!wt(t))return t;if(function(t){return null==t}(i)||""===i||Array.isArray(i)&&0===i.length)return t;if("string"==typeof i&&-1===i.indexOf(s)||"number"==typeof i)return t[i]=e,t;var h=function(t,i){return Array.isArray(t)||(t="string"!=typeof t||""===t.trim()?[]:t.split(i).filter(Boolean)),t}(i,s);if(0===h.length)return t;for(var a=t,r=h.length,n=0;n<r-1;n++){var o=h[n],l=a[o];wt(l)||(a[o]={}),a=a[o]}a[h[r-1]]=e}(window,"RexPlugins.GameObjects.LineShape",_t),zt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).rexlineshapeplugin=i();