phaser3-rex-plugins
Version:
2 lines (1 loc) • 35.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(),s.addToRenderList(e);var r=i.pipelines.set(e.pipeline),a=t(e,s,h),n=r.calcMatrix.copyFrom(a.calc),o=e._displayOriginX,l=e._displayOriginY,u=s.alpha*e.alpha;i.pipelines.preBatch(e);for(var d,p=e.geom,c=0,v=p.length;c<v;c++)(d=p[c]).visible&&d.webglRender(r,n,u,o,l);i.pipelines.postBatch(e)},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={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}},o=function(t,i,e){for(var s=t,h=e,r=0,a=i.length;r<a;r++){var n=i[r];if(!s||"object"!=typeof s&&"function"!=typeof s||!(n in s))return l.found=!1,l;s=h=s[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 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),r=s&&("object"==typeof s||"function"==typeof s);if(!h&&!r)return e;var a=String(i);if(h&&a in t)return t[a];if(r&&a in s)return s[a];if(-1===a.indexOf("."))return e;var n=a.split(".");if(h){var l=o(t,n,e);if(l.found)return l.value}if(r){var u=o(s,n,e);if(u.found)return u.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 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,e,s,h){}canvasRender(t,i,e){}updateData(){this.dirty=!1}}Object.assign(d.prototype,n,u);var p=Phaser.Renderer.WebGL.Utils,c=function(t,i,e,s,h,r){for(var a=p.getTintAppendFloatAlpha(e.fillColor,e.fillAlpha*s),n=e.pathData,o=e.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]-r,y=n[d+0]-h,f=n[d+1]-r,D=n[c+0]-h,m=n[c+1]-r,P=i.getX(v,g),b=i.getY(v,g),k=i.getX(y,f),_=i.getY(y,f),S=i.getX(D,m),T=i.getY(D,m);t.batchTri(e,P,b,k,_,S,T,0,0,1,1,a,a,a,2)}},v=Phaser.Renderer.WebGL.Utils,g=function(t,i,e,s,h){var r=t.strokeTint,a=v.getTintAppendFloatAlpha(i.strokeColor,i.strokeAlpha*e);r.TL=a,r.TR=a,r.BL=a,r.BR=a;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]-s,y=u[1]-h;if(i.closePath||(d-=2),l){var f=i.strokePathMask,D=0,m=0;for(P=2;P<d;P+=2)n=u[P]-s,o=u[P+1]-h,f[D]?(t.batchLine(g,y,n,o,c,c,p,m,!1),m++):m=0,g=n,y=o,D++}else for(var P=2;P<d;P+=2)n=u[P]-s,o=u[P+1]-h,t.batchLine(g,y,n,o,c,c,p,P-2,!!i.closePath&&P===d-1),g=n,y=o},y=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+")"},f=function(t,i,e,s){var h=i.pathData;if(h&&!(h.length<4)){var r=h.length-1,a=h[0]-e,n=h[1]-s;t.beginPath(),t.moveTo(a,n),i.closePath||(r-=2);for(var o=2;o<r;o+=2){var l=h[o]-e,u=h[o+1]-s;t.lineTo(l,u)}i.closePath&&t.closePath(),y(t,i),t.fill()}},D=function(t,i,e,s){var h=i.isDashed&&!!i.strokePathData,r=h?i.strokePathData:i.pathData;if(r&&!(r.length<4)){var a=r.length-1,n=r[0]-e,o=r[1]-s;if(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,i),t.beginPath(),i.closePath||(a-=2),h){var l=i.strokePathMask,u=0;for(d=2;d<a;d+=2)p=r[d]-e,c=r[d+1]-s,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<a;d+=2){var p=r[d]-e,c=r[d+1]-s;t.lineTo(p,c)}i.closePath&&t.closePath()}t.stroke()}};const m=1e-6,P=10,b=.5;var k=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=P,drawRatio:s=b}=t;if(e=Math.round(e),!isFinite(e)||e<=0)return null;if(!(i>m))return null;var h=i/e;if(!(h>m))return null;if((s=Math.max(0,Math.min(1,s)))>=.999999)return null;var r=h*s;r<=m&&(r=m);var a=h-r;return a<=m?null:[r,a]}(t,i)},_=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],r=t[1],a=2;a<s;a+=2){var n=t[a],o=t[a+1];e(h,r,n,o),h=n,r=o}}},S=function(t,i,e){void 0===i&&(i={}),void 0===e&&(e={});var{closePath:s=!1,dashPattern:h,dashOffset:r=0}=i,a=function(t,i){var e=0;return _(t,i,(function(t,i,s,h){var r=s-t,a=h-i;e+=Math.sqrt(r*r+a*a)})),e}(t,s);if(null===(h=k(h,a)))return null;for(var n=[],o=[],l=0,u=0,d=h.length;u<d;u++)l+=h[u];if(l<=m)return e.strokePathData=t?t.slice():[],e.strokePathMask=void 0,e;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}(r,l);y>m;)y<v-m?(v-=y,y=0):(y-=v,g());var f=function(t,i,e,s,h){if(0===n.length)n.push(t,i);else{var r=n[n.length-2],a=n[n.length-1];r===t&&a===i||n.push(t,i)}n.push(e,s),o.push(h?1:0)};return _(t,s,(function(t,i,e,s){var h=e-t,r=s-i,a=Math.sqrt(h*h+r*r);if(!(a<=m))for(var n=0;n<a-m;){var o=Math.min(v,a-n);if(o<=m)g();else{var l=n/a,u=(n+o)/a;f(t+h*l,i+r*l,t+h*u,i+r*u,c),n+=o,(v-=o)<=m&&g()}}})),!s&&n.length>=2&&n.push(n[n.length-2],n[n.length-1]),e.strokePathData=n,e.strokePathMask=o,e},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}},x={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(x,T);const w=Phaser.Geom.Polygon.Earcut;class E 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=w(this.pathData),super.updateData(),this.buildStrokePath(),this}webglRender(t,i,e,s,h){this.isFilled&&c(t,i,this,e,s,h),this.isStroked&&g(t,this,e,s,h)}canvasRender(t,i,e){this.isFilled&&f(t,this,i,e),this.isStroked&&D(t,this,i,e)}}Object.assign(E.prototype,x);var R=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 A=Phaser.Math.DegToRad;Phaser.Math.DegToRad;const O=Phaser.Math.Interpolation.QuadraticBezier,C=Phaser.Math.Interpolation.CubicBezier,M=Phaser.Math.Interpolation.CatmullRom;var L=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},j={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,r,a){return void 0===a&&(a=!1),function(t,i,e,s,h,r,a,n,o){a&&r>h?r-=360:!a&&r<h&&(r+=360);var l=A(r-h)/n;h=A(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);R(p,c,o)}}(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(O(d,n,t,e),O(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(C(c,l,t,e,h),C(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(M(h,l),M(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 L(this.pathData),this}};const F=Phaser.Math.RotateAround,X=Phaser.Math.DegToRad;Phaser.Math.RotateAround;var Y={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],F(h,t,i,e),s[r]=h.x,s[r+1]=h.y}(t,i,e=X(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 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}},z={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 G=Phaser.Math.Distance.Between,W=Phaser.Math.Wrap,B=Phaser.Math.Linear;var N=function(t,i,e,s,h){if(void 0===s&&(s=e,e=0),(e=U(e))!==(s=U(s))){var r=i[i.length-1],a=r*e,n=r*s;e<s?V(t,i,a,n,h):(V(t,i,a,r,h),V(t,i,0,n,h)),L(h)}},V=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(I(t,o-2,o,u)),h.push(I(t,o-1,o+1,u)),r=!1}}if(!(l<=s)){u=1-(l-s)/(l-i[a-1]),h.push(I(t,o-2,o,u)),h.push(I(t,o-1,o+1,u));break}if(h.push(t[o]),h.push(t[o+1]),l===s)break}},I=function(t,i,e,s){var h=t[i],r=t[e];return B(h,r,s)},U=function(t){return 0===t?0:t%1==0?1:W(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:G(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,N(this.pathDataSave,this.accumulationLengths,t,i,this.pathData),this},appendFromPathSegment(t,i,e){return void 0===i?this.pathData.push(...t.pathData):(t.updateAccumulationLengths(),N(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}},q={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 K=Phaser.Geom.Polygon;class H{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 K),i.setTo(t),i}(this.pathData,t)}}Object.assign(H.prototype,j,Y,z,J,q);class Q extends E{constructor(){super(),this.builder=new H(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,r,a){return this.builder.ellipticalArc(t,i,e,s,h,r,a),this.dirty=!0,this}arc(t,i,e,s,h,r){return this.builder.arc(t,i,e,s,h,r),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,r){return this.builder.cubicBezierTo(t,i,e,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,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 Z=Phaser.Renderer.WebGL.Utils.getTintAppendFloatAlpha;Object.assign(class extends d{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 r=t.fillTint,a=Z(this.fillColor,this.fillAlpha*e);r.TL=a,r.TR=a,r.BL=a,r.BR=a,t.batchFillRect(-s+this.x,-h+this.y,this.width,this.height)}this.isStroked&&g(t,this,e,s,h)}canvasRender(t,i,e){this.isFilled&&(y(t,this),t.fillRect(-i,-e,this.width,this.height)),this.isStroked&&D(t,this,i,e)}}.prototype,x),Phaser.Utils.Objects.GetValue;const $=Phaser.Geom.Polygon.Earcut;Object.assign(class extends d{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=0),void 0===h&&(h=0),void 0===r&&(r=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,r)}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=$(this.pathData),super.updateData(),this.buildStrokePath(),this}webglRender(t,i,e,s,h){this.isFilled&&c(t,i,this,e,s,h),this.isStroked&&g(t,this,e,s,h)}canvasRender(t,i,e){this.isFilled&&f(t,this,i,e),this.isStroked&&D(t,this,i,e)}}.prototype,x),Phaser.Math.Wrap;const tt=Phaser.Math.Linear;var it=function(){var t,i,e,s,h,r,a=this.getShape("triangle"),n=this.padding,o=this.width-n.right,l=0+n.left,u=this.height-n.bottom,d=0+n.top,p=(l+o)/2,c=(d+u)/2,v={0:{a:{x:l,y:d},b:{x:o,y:c},c:{x:l,y:u}},1:{a:{x:l,y:d},b:{x:p,y:u},c:{x:o,y:d}},2:{a:{x:o,y:d},b:{x:l,y:c},c:{x:o,y:u}},3:{a:{x:l,y:u},b:{x:p,y:d},c:{x:o,y:u}}};if(void 0===this.previousDirection){var g=v[this.direction],y=g.a,f=g.b,D=g.c;t=y.x,i=y.y,e=f.x,s=f.y,h=D.x,r=D.y}else{var m=v[this.previousDirection],P=v[this.direction],b=this.easeDirectionProgress;t=tt(m.a.x,P.a.x,b),i=tt(m.a.y,P.a.y,b),e=tt(m.b.x,P.b.x,b),s=tt(m.b.y,P.b.y,b),h=tt(m.c.x,P.c.x,b),r=tt(m.c.y,P.c.y,b)}a.startAt(t,i).lineTo(e,s).lineTo(h,r),this.arrowOnly?a.end():a.close()};const et=(0,Phaser.Math.DegToRad)(120);var st=function(t){t=this.getShape("triangle");var i=this.width/2,e=this.height/2,s=Math.min(i,e)*this.radius,h=this.verticeRotation;t.startAt(i+s*Math.cos(h+et),e+s*Math.sin(h+et)).lineTo(i+s*Math.cos(h),e+s*Math.sin(h)).lineTo(i+s*Math.cos(h-et),e+s*Math.sin(h-et)),this.arrowOnly?t.end():t.close()},ht={buildShapes(){this.addShape((new Q).setName("triangle"))},updateShapes(){var t=this.getShape("triangle");this.arrowOnly?t.fillStyle().lineStyle(this.lineWidth,this.strokeColor,this.strokeAlpha):t.fillStyle(this.fillColor,this.fillAlpha).lineStyle(this.lineWidth,this.strokeColor,this.strokeAlpha),0===this.shapeMode?it.call(this):st.call(this)}},rt={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 at=Phaser.Scene;var nt=function(t){return t instanceof at};const ot=Phaser.Game;var lt=function(t){return t instanceof ot};const ut=Phaser.Utils.Objects.GetValue;class dt{constructor(t,i){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(ut(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:nt(i)?i:i.scene&&nt(i.scene)?i.scene:i.parent&&i.parent.scene&&nt(i.parent.scene)?i.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:lt(t)?t:lt(t.game)?t.game:nt(t)?t.sys.game:nt(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(dt.prototype,rt);const pt=Phaser.Utils.Objects.GetValue;class ct extends dt{constructor(t,i){super(t,i),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(pt(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=vt[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 vt={no:0,lazy:1,always:2},gt=Phaser.Utils.Objects.GetValue;class yt extends ct{constructor(t,i){super(t,i);var e=this.scene?"update":"step";this.tickEventName=gt(i,"tickEventName",e),this.isSceneTicker=!ft(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 ft=function(t){return"step"===t||"poststep"===t};const Dt=Phaser.Utils.Objects.GetValue,mt=Phaser.Math.Clamp;class Pt{constructor(t){this.resetFromJSON(t)}resetFromJSON(t){this.state=Dt(t,"state",bt),this.timeScale=Dt(t,"timeScale",1),this.delay=Dt(t,"delay",0),this.repeat=Dt(t,"repeat",0),this.repeatCounter=Dt(t,"repeatCounter",0),this.repeatDelay=Dt(t,"repeatDelay",0),this.duration=Dt(t,"duration",0),this.nowTime=Dt(t,"nowTime",0),this.justRestart=Dt(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?_t:kt,this.repeatCounter=0,this}stop(){return this.state=bt,this}update(t,i){this.state!==bt&&this.state!==Tt&&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=St)):(this.nowTime=this.duration,this.state=Tt):this.nowTime>=0&&(this.state=_t))}get t(){var t;switch(this.state){case bt:case kt:case St:t=0;break;case _t:t=this.nowTime/this.duration;break;case Tt:t=1}return mt(t,0,1)}set t(t){(t=mt(t,-1,1))<0?(this.state=kt,this.nowTime=-this.delay*t):(this.state=_t,this.nowTime=this.duration*t,1===t&&0!==this.repeat&&this.repeatCounter++)}setT(t){return this.t=t,this}get isIdle(){return this.state===bt}get isDelay(){return this.state===kt}get isCountDown(){return this.state===_t}get isRunning(){return this.state===kt||this.state===_t}get isDone(){return this.state===Tt}get isOddIteration(){return!(1&~this.repeatCounter)}get isEvenIteration(){return!(1&this.repeatCounter)}}const bt=0,kt=1,_t=2,St=3,Tt=-1;class xt extends yt{constructor(t,i){super(t,i),this.timer=new Pt}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 wt=Phaser.Utils.Objects.GetValue,Et=Phaser.Utils.Objects.GetAdvancedValue,Rt=Phaser.Tweens.Builders.GetEaseFunction;class At extends xt{resetFromJSON(t){return this.timer.resetFromJSON(wt(t,"timer")),this.setEnable(wt(t,"enable",!0)),this.setTarget(wt(t,"target",this.parent)),this.setDelay(Et(t,"delay",0)),this.setDuration(Et(t,"duration",1e3)),this.setEase(wt(t,"ease","Linear")),this.setRepeat(wt(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=Rt(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 Ot=Phaser.Utils.Objects.GetValue,Ct=Phaser.Math.Linear;class Mt extends At{constructor(t,i){super(t,i),this.resetFromJSON(),this.boot()}start(t){if(this.timer.isRunning)return this;var i=this.target;this.propertyKey=Ot(t,"key","value");var e=i[this.propertyKey];return this.fromValue=Ot(t,"from",e),this.toValue=Ot(t,"to",e),this.setEase(Ot(t,"ease",this.ease)),this.setDuration(Ot(t,"duration",this.duration)),this.setRepeat(Ot(t,"repeat",0)),this.setDelay(Ot(t,"delay",0)),this.setRepeatDelay(Ot(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]=Ct(this.fromValue,this.toValue,e)}}var Lt={setEaseDuration(t){return void 0===t&&(t=0),this.easeDuration=t,this},playEaseDirectionation(){return void 0===this.easeDirectionProgressTask&&(this.easeDirectionProgressTask=new Mt(this,{eventEmitter:null})),this.easeDirectionProgressTask.restart({key:"easeDirectionProgress",from:0,to:1,duration:this.easeDuration}),this},stopEaseDirection(){return void 0===this.easeDirectionProgressTask||this.easeDirectionProgressTask.stop(),this}};const jt=Phaser.Utils.Objects.GetValue,Ft=Phaser.Utils.Objects.IsPlainObject,Xt=Phaser.Math.DegToRad,Yt=Phaser.Math.RadToDeg;class zt extends a{constructor(t,i,e,s,h,r,a){var n,o,l,u,d,p,c,v;if(Ft(i)){var g=i;i=g.x,e=g.y,s=g.width,h=g.height,r=g.color,a=g.alpha,n=g.strokeColor,o=g.strokeAlpha,l=g.strokeWidth,u=g.arrowOnly,d=g.direction,p=g.easeDuration,c=g.padding,v=g.radius}void 0===i&&(i=0),void 0===e&&(e=0),void 0===s&&(s=1),void 0===h&&(h=s),void 0===u&&(u=!1),void 0===d&&(d=0),void 0===p&&(p=0),void 0===c&&(c=0),void 0===v&&(v=void 0),super(t,i,e,s,h),this.type="rexTriangle",this.setFillStyle(r,a),void 0!==n&&void 0===l&&(l=2),this.setStrokeStyle(l,n,o),this.setArrowOnly(u),this.setDirection(d,p),this.setPadding(c),this.setRadius(v),this.buildShapes()}get arrowOnly(){return this._arrowOnly}set arrowOnly(t){this.dirty=this.dirty||this._arrowOnly!=t,this._arrowOnly=t}setArrowOnly(t){return void 0===t&&(t=!0),this.arrowOnly=t,this}get direction(){return this._direction}set direction(t){t=Wt(t),this._direction!==t&&(this.easeDuration>0&&void 0!==this._direction?this.previousDirection=this._direction:this.previousDirection=void 0,this._direction=t,this.verticeAngle=90*t,this.dirty=!0,void 0!==this.previousDirection?this.playEaseDirectionation():this.stopEaseDirection())}setDirection(t,i){return void 0!==i&&this.setEaseDuration(i),this.direction=t,this}toggleDirection(t){return this.setDirection(this.direction+2,t),this}get easeDirectionProgress(){return this._easeDirectionProgress}set easeDirectionProgress(t){this._easeDirectionProgress!==t&&(this._easeDirectionProgress=t,this.dirty=!0)}setPadding(t,i,e,s){if("object"==typeof t){var h=t,r=jt(h,"x",null);null!==r?(t=r,e=r):(t=jt(h,"left",0),e=jt(h,"right",t));var a=jt(h,"y",null);null!==a?(i=a,s=a):(i=jt(h,"top",0),s=jt(h,"bottom",i))}else void 0===t&&(t=0),void 0===i&&(i=t),void 0===e&&(e=t),void 0===s&&(s=i);return void 0===this.padding&&(this.padding={}),this.dirty=this.dirty||this.padding.left!=t||this.padding.top!=i||this.padding.right!=e||this.padding.bottom!=s,this.padding.left=t,this.padding.top=i,this.padding.right=e,this.padding.bottom=s,this.setRadius(),this}get radius(){return this._radius}set radius(t){this.dirty=this.dirty||this._radius!=t,this._radius=t}setRadius(t){return this.radius=t,this.shapeMode=null==t?0:1,this}get verticeRotation(){return this._verticeRotation}set verticeRotation(t){this.dirty=this.dirty||this._verticeRotation!=t,this._verticeRotation=t}setVerticeRotation(t){return this.verticeRotation=t,this}get verticeAngle(){return Yt(this.verticeRotation)}set verticeAngle(t){this.verticeRotation=Xt(t)}setVerticeAngle(t){return this.verticeAngle=t,this}}const Gt={right:0,down:1,left:2,up:3};var Wt=function(t){return"string"==typeof t&&(t=Gt[t]),t%=4};function Bt(t,i,e,s,h,r){var a=new zt(this.scene,t,i,e,s,h,r);return this.scene.add.existing(a),a}Object.assign(zt.prototype,ht,Lt);const Nt=Phaser.GameObjects.BuildGameObject;function Vt(t,i){void 0===t&&(t={}),void 0!==i&&(t.add=i);var e=new zt(this.scene,t);return Nt(this.scene,e,t),e}var It=function(t){return null!==t&&"object"==typeof t};class Ut extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexTriangle",Bt,Vt)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,i,e,s="."){if(!It(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 r=t,a=h.length,n=0;n<a-1;n++){var o=h[n],l=r[o];It(l)||(r[o]={}),r=r[o]}r[h[a-1]]=e}(window,"RexPlugins.GameObjects.Triangle",zt),Ut},"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).rextriangleplugin=i();