phaser3-rex-plugins
Version:
2 lines (1 loc) • 11.5 kB
JavaScript
var t,i;t=void 0,i=function(){var t=Phaser.Renderer.WebGL.Utils,i=Phaser.Renderer.WebGL.Utils;const e=Phaser.GameObjects.GetCalcMatrix,s=Phaser.Renderer.Canvas.SetTransform;var r={renderWebGL:function(s,r,a,h){r.dirty&&(r.updateData(),r.dirty=!1),a.addToRenderList(r);var n=s.pipelines.set(r.pipeline),o=e(r,a,h),l=n.calcMatrix.copyFrom(o.calc),u=r._displayOriginX,d=r._displayOriginY,v=a.alpha*r.alpha;s.pipelines.preBatch(r),r.isFilled&&function(i,e,s,r,a,h){for(var n=t.getTintAppendFloatAlpha(s.fillColor,s.fillAlpha*r),o=s.pathData,l=s.pathIndexes,u=0;u<l.length;u+=3){var d=2*l[u],v=2*l[u+1],f=2*l[u+2],c=o[d+0]-a,g=o[d+1]-h,p=o[v+0]-a,y=o[v+1]-h,x=o[f+0]-a,P=o[f+1]-h,k=e.getX(c,g),R=e.getY(c,g),m=e.getX(p,y),b=e.getY(p,y),T=e.getX(x,P),D=e.getY(x,P);i.batchTri(s,k,R,m,b,T,D,0,0,1,1,n,n,n,2)}}(n,l,r,v,u,d),r.isStroked&&function(t,e,s,r,a){var h=t.strokeTint,n=i.getTintAppendFloatAlpha(e.strokeColor,e.strokeAlpha*s);h.TL=n,h.TR=n,h.BL=n,h.BR=n;var o,l,u=e.isDashed&&!!e.strokePathData,d=u?e.strokePathData:e.pathData,v=d.length-1,f=e.lineWidth,c=f/2,g=d[0]-r,p=d[1]-a;if(e.closePath||(v-=2),u){var y=e.strokePathMask,x=0,P=0;for(k=2;k<v;k+=2)o=d[k]-r,l=d[k+1]-a,y[x]?(t.batchLine(g,p,o,l,c,c,f,P,!1),P++):P=0,g=o,p=l,x++}else for(var k=2;k<v;k+=2)o=d[k]-r,l=d[k+1]-a,t.batchLine(g,p,o,l,c,c,f,k-2,!!e.closePath&&k===v-1),g=o,p=l}(n,r,v,u,d),s.pipelines.postBatch(r)},renderCanvas:function(t,i,e,r){i.dirty&&(i.updateData(),i.dirty=!1),e.addToRenderList(i);var a=t.currentContext;if(s(t,a,i,e,r)){var h=i._displayOriginX,n=i._displayOriginY;i.isFilled&&function(t,i,e,s){var r=i.pathData;if(r&&!(r.length<4)){var a=r.length-1,h=r[0]-e,n=r[1]-s;t.beginPath(),t.moveTo(h,n),i.closePath||(a-=2);for(var o=2;o<a;o+=2){var l=r[o]-e,u=r[o+1]-s;t.lineTo(l,u)}i.closePath&&t.closePath(),function(t,i,e,s){var r=i.fillColor,a=s||i.fillAlpha,h=(16711680&r)>>>16,n=(65280&r)>>>8,o=255&r;t.fillStyle="rgba("+h+","+n+","+o+","+a+")"}(t,i),t.fill()}}(a,i,h,n),i.isStroked&&function(t,i,e,s){var r=i.isDashed&&!!i.strokePathData,a=r?i.strokePathData:i.pathData;if(a&&!(a.length<4)){var h=a.length-1,n=a[0]-e,o=a[1]-s;if(function(t,i,e,s){var r=i.strokeColor,a=s||i.strokeAlpha,h=(16711680&r)>>>16,n=(65280&r)>>>8,o=255&r;t.strokeStyle="rgba("+h+","+n+","+o+","+a+")",t.lineWidth=i.lineWidth}(t,i),t.beginPath(),i.closePath||(h-=2),r){var l=i.strokePathMask,u=0;for(d=2;d<h;d+=2)v=a[d]-e,f=a[d+1]-s,l[u]&&(t.moveTo(n,o),t.lineTo(v,f)),n=v,o=f,u++}else{t.moveTo(n,o);for(var d=2;d<h;d+=2){var v=a[d]-e,f=a[d+1]-s;t.lineTo(v,f)}i.closePath&&t.closePath()}t.stroke()}}(a,i,h,n),a.restore()}}};const a=1e-6,h=10,n=.5;var o=function(t,i){return function(t){if(!Array.isArray(t))return null;for(var i=[],e=0,s=t.length;e<s;e++){var r=Number(t[e]);isFinite(r)&&r>0&&i.push(r)}return i.length>0?i:null}(t)||function(t,i){var{segments:e=h,drawRatio:s=n}=t;if(e=Math.round(e),!isFinite(e)||e<=0)return null;if(!(i>a))return null;var r=i/e;if(!(r>a))return null;if((s=Math.max(0,Math.min(1,s)))>=.999999)return null;var o=r*s;o<=a&&(o=a);var l=r-o;return l<=a?null:[o,l]}(t,i)},l=function(t,i,e){if(t&&!(t.length<4)){var s=t.length-1;if(i||(s-=2),!(s<2))for(var r=t[0],a=t[1],h=2;h<s;h+=2){var n=t[h],o=t[h+1];e(r,a,n,o),r=n,a=o}}},u=function(t,i,e){void 0===i&&(i={}),void 0===e&&(e={});var{closePath:s=!1,dashPattern:r,dashOffset:h=0}=i,n=function(t,i){var e=0;return l(t,i,(function(t,i,s,r){var a=s-t,h=r-i;e+=Math.sqrt(a*a+h*h)})),e}(t,s);if(null===(r=o(r,n)))return null;for(var u=[],d=[],v=0,f=0,c=r.length;f<c;f++)v+=r[f];if(v<=a)return e.strokePathData=t?t.slice():[],e.strokePathMask=void 0,e;for(var g=0,p=!0,y=r[g],x=function(){g=(g+1)%r.length,p=!p,y=r[g]},P=function(t,i){return isFinite(t)||(t=0),(t%=i)<0&&(t+=i),t}(h,v);P>a;)P<y-a?(y-=P,P=0):(P-=y,x());var k=function(t,i,e,s,r){if(0===u.length)u.push(t,i);else{var a=u[u.length-2],h=u[u.length-1];a===t&&h===i||u.push(t,i)}u.push(e,s),d.push(r?1:0)};return l(t,s,(function(t,i,e,s){var r=e-t,h=s-i,n=Math.sqrt(r*r+h*h);if(!(n<=a))for(var o=0;o<n-a;){var l=Math.min(y,n-o);if(l<=a)x();else{var u=o/n,d=(o+l)/n;k(t+r*u,i+h*u,t+r*d,i+h*d,p),o+=l,(y-=l)<=a&&x()}}})),!s&&u.length>=2&&u.push(u[u.length-2],u[u.length-1]),e.strokePathData=u,e.strokePathMask=d,e},d={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}},v={buildStrokePath:function(){if(this.isDashed){var t=u(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(v,d);const f=Phaser.GameObjects.Shape;class c extends f{init(){this.isDashed=!1,this.strokePathData=void 0,this.strokePathMask=void 0,this.dashPattern=void 0,this.dashOffset=0}get fillColor(){return this._fillColor}set fillColor(t){this._fillColor=t,this.isFilled=null!=t&&this._fillAlpha>0}get fillAlpha(){return this._fillAlpha}set fillAlpha(t){this._fillAlpha=t,this.isFilled=t>0&&null!=this._fillColor}setFillStyle(t,i){return void 0===i&&(i=1),this.fillColor=t,this.fillAlpha=i,this}get strokeColor(){return this._strokeColor}set strokeColor(t){this._strokeColor=t,this.isStroked=null!=t&&this._strokeAlpha>0&&this._lineWidth>0}get strokeAlpha(){return this._strokeAlpha}set strokeAlpha(t){this._strokeAlpha=t,this.isStroked=t>0&&null!=this._strokeColor&&this._lineWidth>0}get lineWidth(){return this._lineWidth}set lineWidth(t){this._lineWidth=t,this.isStroked=t>0&&null!=this._strokeColor}setStrokeStyle(t,i,e){return void 0===e&&(e=1),this.lineWidth=t,this.strokeColor=i,this.strokeAlpha=e,this}updateData(){return this.buildStrokePath(),this}get width(){return this.geom.width}set width(t){this.resize(t,this.height)}get height(){return this.geom.height}set height(t){this.resize(this.width,t)}setSize(t,i){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}}Object.assign(c.prototype,v,r);const g=Phaser.Utils.Objects.GetValue;let p=class{constructor(t,i,e,s,r){void 0===t&&(t=0),void 0===i&&(i=t),void 0===e&&(e=0),void 0===s&&(s=0),void 0===r&&(r=0),this.cornerRadius={},this._width=0,this._height=0,this.setTo(t,i,e,s,r)}setTo(t,i,e,s,r){return this.setPosition(t,i),this.setRadius(r),this.setSize(e,s),this}setPosition(t,i){return this.x=t,this.y=i,this}setRadius(t){return void 0===t&&(t=0),this.radius=t,this}setSize(t,i){return this.width=t,this.height=i,this}get minWidth(){var t=this.cornerRadius;return Math.max(t.tl.x+t.tr.x,t.bl.x+t.br.x)}get minHeight(){var t=this.cornerRadius;return Math.max(t.tl.y+t.bl.y,t.tr.y+t.br.y)}get width(){return this._width}set width(t){null==t&&(t=0),this._width=Math.max(t,this.minWidth)}get height(){return this._height}set height(t){null==t&&(t=0),this._height=Math.max(t,this.minHeight)}get radius(){var t=this.cornerRadius;return Math.max(t.tl.x,t.tl.y,t.tr.x,t.tr.y,t.bl.x,t.bl.y,t.br.x,t.br.y)}set radius(t){var i,e;"number"==typeof t?(i=t,e=t):(i=g(t,"x",0),e=g(t,"y",0));var s=this.cornerRadius;s.tl=y(g(t,"tl",void 0),i,e),s.tr=y(g(t,"tr",void 0),i,e),s.bl=y(g(t,"bl",void 0),i,e),s.br=y(g(t,"br",void 0),i,e)}get radiusTL(){var t=this.cornerRadius.tl;return Math.max(t.x,t.y)}set radiusTL(t){x(this.cornerRadius.tl,t)}get radiusTR(){var t=this.cornerRadius.tr;return Math.max(t.x,t.y)}set radiusTR(t){x(this.cornerRadius.tr,t)}get radiusBL(){var t=this.cornerRadius.bl;return Math.max(t.x,t.y)}set radiusBL(t){x(this.cornerRadius.bl,t)}get radiusBR(){var t=this.cornerRadius.br;return Math.max(t.x,t.y)}set radiusBR(t){x(this.cornerRadius.br,t)}};var y=function(t,i,e){return void 0===t?t={x:i,y:e}:"number"==typeof t&&(t={x:t,y:t}),P(t),t},x=function(t,i){"number"==typeof i?(t.x=i,t.y=i):(t.x=g(i,"x",0),t.y=g(i,"y",0)),P(t)},P=function(t){t.convex=t.x>=0||t.y>=0,t.x=Math.abs(t.x),t.y=Math.abs(t.y)},k=function(t){return t.x>0&&t.y>0},R=function(t,i,e){var s=e.length;if(s>=2){var r=e[s-2],a=e[s-1];if(t===r&&i===a)return e}return e.push(t,i),e};const m=Phaser.Math.DegToRad;var b=function(t,i,e,s,r,a,h,n,o){h&&a>r?a-=360:!h&&a<r&&(a+=360);var l=m(a-r)/n;r=m(r);for(var u=0;u<=n;u++){var d=r+l*u,v=t+e*Math.cos(d),f=i+s*Math.sin(d);R(v,f,o)}return o};const T=Phaser.Utils.Objects.IsPlainObject,D=Phaser.Utils.Objects.GetValue,_=Phaser.Geom.Polygon.Earcut,M={rectangle:0,circle:1};return class extends c{constructor(t,i,e,s,r,a,h,n){var o,l,u,d,v,f;if(T(i)){var c=i;i=c.x,e=c.y,s=c.width,r=c.height,a=c.radius,h=c.color,n=c.alpha,o=c.strokeColor,l=c.strokeAlpha,u=c.strokeWidth,d=c.shape,v=c.dashPattern,f=c.dashOffset}void 0===i&&(i=0),void 0===e&&(e=0),void 0===s&&(s=1),void 0===r&&(r=s),void 0===a&&(a=0),void 0===d&&(d=0);var g=new p;if(super(t,"rexRoundRectangleShape",g),this.init(),this.setShapeType(d),0===this.shapeType){var y=D(a,"radius",a);g.setTo(0,0,s,r,y)}else y={x:s/2,y:r/2},g.setTo(0,0,s,r,y);this.setIteration(D(a,"iteration",void 0)),this.setPosition(i,e),this.setFillStyle(h,n),void 0===u&&(u=2),this.setStrokeStyle(u,o,l),v&&this.setDashPattern(v,f),this.updateDisplayOrigin(),this.dirty=!0}updateData(){var t=this.geom,i=this.pathData;i.length=0;var e,s=t.width,r=t.height,a=t.cornerRadius,h=this.iteration+1;if(e=a.tl,k(e))if(e.convex){var n=e.x,o=e.y;b(n,o,e.x,e.y,180,270,!1,h,i)}else b(n=0,o=0,e.x,e.y,90,0,!0,h,i);else R(0,0,i);return e=a.tr,k(e)?e.convex?(n=s-e.x,o=e.y,b(n,o,e.x,e.y,270,360,!1,h,i)):b(n=s,o=0,e.x,e.y,180,90,!0,h,i):R(s,0,i),e=a.br,k(e)?e.convex?(n=s-e.x,o=r-e.y,b(n,o,e.x,e.y,0,90,!1,h,i)):b(n=s,o=r,e.x,e.y,270,180,!0,h,i):R(s,r,i),e=a.bl,k(e)?e.convex?(n=e.x,o=r-e.y,b(n,o,e.x,e.y,90,180,!1,h,i)):b(n=0,o=r,e.x,e.y,360,270,!0,h,i):R(0,r,i),i.push(i[0],i[1]),this.pathIndexes=_(i),super.updateData(),this}setShapeType(t){return"string"==typeof t&&(t=M[t]),this.shapeType=t,this}setSize(t,i){return void 0===i&&(i=t),this.geom.width===t&&this.geom.height===i||(this.geom.setSize(t,i),1===this.shapeType&&this.setRadius({x:t/2,y:i/2}),this.updateDisplayOrigin(),this.dirty=!0,super.setSize(t,i)),this}get radius(){return this.geom.radius}set radius(t){this.geom.setRadius(t),this.updateDisplayOrigin(),this.dirty=!0}get radiusTL(){return this.geom.radiusTL}set radiusTL(t){this.geom.radiusTL=t,this.dirty=!0}get radiusTR(){return this.geom.radiusTR}set radiusTR(t){this.geom.radiusTR=t,this.dirty=!0}get radiusBL(){return this.geom.radiusBL}set radiusBL(t){this.geom.radiusBL=t,this.dirty=!0}get radiusBR(){return this.geom.radiusBR}set radiusBR(t){this.geom.radiusBR=t,this.dirty=!0}setRadius(t){return void 0===t&&(t=0),this.radius=t,this}setRadiusTL(t){return void 0===t&&(t=0),this.radiusTL=t,this}setRadiusTR(t){return void 0===t&&(t=0),this.radiusTR=t,this}setRadiusBL(t){return void 0===t&&(t=0),this.radiusBL=t,this}setRadiusBR(t){return void 0===t&&(t=0),this.radiusBR=t,this}get cornerRadius(){return this.geom.cornerRadius}set cornerRadius(t){this.radius=t}setCornerRadius(t){return this.setRadius(t)}get iteration(){return this._iteration}set iteration(t){void 0!==this._iteration?this._iteration!==t&&(this._iteration=t,this.dirty=!0):this._iteration=t}setIteration(t){return void 0===t&&(t=6),this.iteration=t,this}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).rexroundrectangle=i();