@petkoneo/phaser3-rex-plugins
Version:
2 lines (1 loc) • 8.4 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,h,a){r.dirty&&(r.updateData(),r.dirty=!1),h.addToRenderList(r);var o=s.pipelines.set(r.pipeline),n=e(r,h,a),l=o.calcMatrix.copyFrom(n.calc),d=r._displayOriginX,u=r._displayOriginY,g=h.alpha*r.alpha;s.pipelines.preBatch(r),r.isFilled&&function(i,e,s,r,h,a){for(var o=t.getTintAppendFloatAlpha(s.fillColor,s.fillAlpha*r),n=s.pathData,l=s.pathIndexes,d=0;d<l.length;d+=3){var u=2*l[d],g=2*l[d+1],p=2*l[d+2],c=n[u+0]-h,y=n[u+1]-a,v=n[g+0]-h,x=n[g+1]-a,f=n[p+0]-h,R=n[p+1]-a,m=e.getX(c,y),b=e.getY(c,y),T=e.getX(v,x),_=e.getY(v,x),k=e.getX(f,R),S=e.getY(f,R);i.batchTri(s,m,b,T,_,k,S,0,0,1,1,o,o,o,2)}}(o,l,r,g,d,u),r.isStroked&&function(t,e,s,r,h){var a=t.strokeTint,o=i.getTintAppendFloatAlpha(e.strokeColor,e.strokeAlpha*s);a.TL=o,a.TR=o,a.BL=o,a.BR=o;var n=e.pathData,l=n.length-1,d=e.lineWidth,u=d/2,g=n[0]-r,p=n[1]-h;e.closePath||(l-=2);for(var c=2;c<l;c+=2){var y=n[c]-r,v=n[c+1]-h;t.batchLine(g,p,y,v,u,u,d,c-2,!!e.closePath&&c===l-1),g=y,p=v}}(o,r,g,d,u),s.pipelines.postBatch(r)},renderCanvas:function(t,i,e,r){i.dirty&&(i.updateData(),i.dirty=!1),e.addToRenderList(i);var h=t.currentContext;if(s(t,h,i,e,r)){var a=i._displayOriginX,o=i._displayOriginY,n=i.pathData,l=n.length-1,d=n[0]-a,u=n[1]-o;h.beginPath(),h.moveTo(d,u),i.closePath||(l-=2);for(var g=2;g<l;g+=2){var p=n[g]-a,c=n[g+1]-o;h.lineTo(p,c)}h.closePath(),i.isFilled&&(function(t,i,e,s){var r=e||i.fillColor,h=s||i.fillAlpha,a=(16711680&r)>>>16,o=(65280&r)>>>8,n=255&r;t.fillStyle="rgba("+a+","+o+","+n+","+h+")"}(h,i),h.fill()),i.isStroked&&(function(t,i,e,s){var r=e||i.strokeColor,h=s||i.strokeAlpha,a=(16711680&r)>>>16,o=(65280&r)>>>8,n=255&r;t.strokeStyle="rgba("+a+","+o+","+n+","+h+")",t.lineWidth=i.lineWidth}(h,i),h.stroke()),h.restore()}}};const h=Phaser.GameObjects.Shape;class a extends h{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}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(a.prototype,r);const o=Phaser.Utils.Objects.GetValue;let n=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=o(t,"x",0),e=o(t,"y",0));var s=this.cornerRadius;s.tl=l(o(t,"tl",void 0),i,e),s.tr=l(o(t,"tr",void 0),i,e),s.bl=l(o(t,"bl",void 0),i,e),s.br=l(o(t,"br",void 0),i,e)}get radiusTL(){var t=this.cornerRadius.tl;return Math.max(t.x,t.y)}set radiusTL(t){d(this.cornerRadius.tl,t)}get radiusTR(){var t=this.cornerRadius.tr;return Math.max(t.x,t.y)}set radiusTR(t){d(this.cornerRadius.tr,t)}get radiusBL(){var t=this.cornerRadius.bl;return Math.max(t.x,t.y)}set radiusBL(t){d(this.cornerRadius.bl,t)}get radiusBR(){var t=this.cornerRadius.br;return Math.max(t.x,t.y)}set radiusBR(t){d(this.cornerRadius.br,t)}};var l=function(t,i,e){return void 0===t?t={x:i,y:e}:"number"==typeof t&&(t={x:t,y:t}),u(t),t},d=function(t,i){"number"==typeof i?(t.x=i,t.y=i):(t.x=o(i,"x",0),t.y=o(i,"y",0)),u(t)},u=function(t){t.convex=t.x>=0||t.y>=0,t.x=Math.abs(t.x),t.y=Math.abs(t.y)},g=function(t){return t.x>0&&t.y>0},p=function(t,i,e){var s=e.length;if(s>=2){var r=e[s-2],h=e[s-1];if(t===r&&i===h)return e}return e.push(t,i),e};const c=Phaser.Math.DegToRad;var y=function(t,i,e,s,r,h,a,o,n){a&&h>r?h-=360:!a&&h<r&&(h+=360);var l=c(h-r)/o;r=c(r);for(var d=0;d<=o;d++){var u=r+l*d,g=t+e*Math.cos(u),y=i+s*Math.sin(u);p(g,y,n)}return n};const v=Phaser.Utils.Objects.IsPlainObject,x=Phaser.Utils.Objects.GetValue,f=Phaser.Geom.Polygon.Earcut,R={rectangle:0,circle:1};return class extends a{constructor(t,i,e,s,r,h,a,o){var l,d,u,g;if(v(i)){var p=i;i=p.x,e=p.y,s=p.width,r=p.height,h=p.radius,a=p.color,o=p.alpha,l=p.strokeColor,d=p.strokeAlpha,u=p.strokeWidth,g=p.shape}void 0===i&&(i=0),void 0===e&&(e=0),void 0===s&&(s=1),void 0===r&&(r=s),void 0===h&&(h=0),void 0===g&&(g=0);var c=new n;if(super(t,"rexRoundRectangleShape",c),this.setShapeType(g),0===this.shapeType){var y=x(h,"radius",h);c.setTo(0,0,s,r,y)}else y={x:s/2,y:r/2},c.setTo(0,0,s,r,y);this.setIteration(x(h,"iteration",void 0)),this.setPosition(i,e),this.setFillStyle(a,o),void 0===u&&(u=2),this.setStrokeStyle(u,l,d),this.updateDisplayOrigin(),this.dirty=!0}updateData(){var t=this.geom,i=this.pathData;i.length=0;var e,s=t.width,r=t.height,h=t.cornerRadius,a=this.iteration+1;if(e=h.tl,g(e))if(e.convex){var o=e.x,n=e.y;y(o,n,e.x,e.y,180,270,!1,a,i)}else y(o=0,n=0,e.x,e.y,90,0,!0,a,i);else p(0,0,i);return e=h.tr,g(e)?e.convex?(o=s-e.x,n=e.y,y(o,n,e.x,e.y,270,360,!1,a,i)):y(o=s,n=0,e.x,e.y,180,90,!0,a,i):p(s,0,i),e=h.br,g(e)?e.convex?(o=s-e.x,n=r-e.y,y(o,n,e.x,e.y,0,90,!1,a,i)):y(o=s,n=r,e.x,e.y,270,180,!0,a,i):p(s,r,i),e=h.bl,g(e)?e.convex?(o=e.x,n=r-e.y,y(o,n,e.x,e.y,90,180,!1,a,i)):y(o=0,n=r,e.x,e.y,360,270,!0,a,i):p(0,r,i),i.push(i[0],i[1]),this.pathIndexes=f(i),this}setShapeType(t){return"string"==typeof t&&(t=R[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();