UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 8.34 kB
var t,i;t=void 0,i=function(){var t=Phaser.Renderer.WebGL.Utils,i=Phaser.Renderer.WebGL.Utils;const e=Phaser.GameObjects.GetCalcMatrix,r=Phaser.Renderer.Canvas.SetTransform;var s={renderWebGL:function(r,s,h,a){s.dirty&&(s.updateData(),s.dirty=!1);var o=h.camera;o.addToRenderList(s);var n=e(s,o,a,!h.useCanvas).calc,d=s._displayOriginX,l=s._displayOriginY,u=s.alpha,g=s.customRenderNodes.Submitter||s.defaultRenderNodes.Submitter;s.isFilled&&function(i,e,r,s,h,a,o,n){var d,l,u,g,y,v=t.getTintAppendFloatAlpha(h.fillColor,h.fillAlpha*a),c=h.pathData,p=h.pathIndexes,x=c.length,f=Array(2*x),R=Array(x),m=0,b=0;for(d=0;d<x;d+=2)l=c[d]-o,u=c[d+1]-n,g=r.getX(l,u),y=r.getY(l,u),f[m++]=g,f[m++]=y,R[b++]=v;e.batch(i,p,f,R)}(h,g,n,0,s,u,d,l),s.isStroked&&function(t,e,r,s,h,a,o,n){var d=i.getTintAppendFloatAlpha(h.strokeColor,h.strokeAlpha*a),l=h.pathData,u=l.length-1,g=h.lineWidth,y=!h.closePath,v=s.customRenderNodes.StrokePath||s.defaultRenderNodes.StrokePath,c=[];y&&(u-=2);for(var p=0;p<u;p+=2){var x=l[p]-o,f=l[p+1]-n;p>0&&x===l[p-2]&&f===l[p-1]||c.push({x:x,y:f,width:g})}v.run(t,e,c,g,y,r,d,d,d,d)}(h,g,n,s,s,u,d,l)},renderCanvas:function(t,i,e,s){i.dirty&&(i.updateData(),i.dirty=!1),e.addToRenderList(i);var h=t.currentContext;if(r(t,h,i,e,s)){var a=i._displayOriginX,o=i._displayOriginY,n=i.pathData,d=n.length-1,l=n[0]-a,u=n[1]-o;h.beginPath(),h.moveTo(l,u),i.closePath||(d-=2);for(var g=2;g<d;g+=2){var y=n[g]-a,v=n[g+1]-o;h.lineTo(y,v)}h.closePath(),i.isFilled&&(function(t,i,e,r){var s=e||i.fillColor,h=r||i.fillAlpha,a=(16711680&s)>>>16,o=(65280&s)>>>8,n=255&s;t.fillStyle="rgba("+a+","+o+","+n+","+h+")"}(h,i),h.fill()),i.isStroked&&(function(t,i,e,r){var s=e||i.strokeColor,h=r||i.strokeAlpha,a=(16711680&s)>>>16,o=(65280&s)>>>8,n=255&s;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,s);const o=Phaser.Utils.Objects.GetValue;let n=class{constructor(t,i,e,r,s){void 0===t&&(t=0),void 0===i&&(i=t),void 0===e&&(e=0),void 0===r&&(r=0),void 0===s&&(s=0),this.cornerRadius={},this._width=0,this._height=0,this.setTo(t,i,e,r,s)}setTo(t,i,e,r,s){return this.setPosition(t,i),this.setRadius(s),this.setSize(e,r),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 r=this.cornerRadius;r.tl=d(o(t,"tl",void 0),i,e),r.tr=d(o(t,"tr",void 0),i,e),r.bl=d(o(t,"bl",void 0),i,e),r.br=d(o(t,"br",void 0),i,e)}get radiusTL(){var t=this.cornerRadius.tl;return Math.max(t.x,t.y)}set radiusTL(t){l(this.cornerRadius.tl,t)}get radiusTR(){var t=this.cornerRadius.tr;return Math.max(t.x,t.y)}set radiusTR(t){l(this.cornerRadius.tr,t)}get radiusBL(){var t=this.cornerRadius.bl;return Math.max(t.x,t.y)}set radiusBL(t){l(this.cornerRadius.bl,t)}get radiusBR(){var t=this.cornerRadius.br;return Math.max(t.x,t.y)}set radiusBR(t){l(this.cornerRadius.br,t)}};var d=function(t,i,e){return void 0===t?t={x:i,y:e}:"number"==typeof t&&(t={x:t,y:t}),u(t),t},l=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},y=function(t,i,e){var r=e.length;if(r>=2){var s=e[r-2],h=e[r-1];if(t===s&&i===h)return e}return e.push(t,i),e};const v=Phaser.Math.DegToRad;var c=function(t,i,e,r,s,h,a,o,n){a&&h>s?h-=360:!a&&h<s&&(h+=360);var d=v(h-s)/o;s=v(s);for(var l=0;l<=o;l++){var u=s+d*l,g=t+e*Math.cos(u),c=i+r*Math.sin(u);y(g,c,n)}return n};const p=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,r,s,h,a,o){var d,l,u,g;if(p(i)){var y=i;i=y.x,e=y.y,r=y.width,s=y.height,h=y.radius,a=y.color,o=y.alpha,d=y.strokeColor,l=y.strokeAlpha,u=y.strokeWidth,g=y.shape}void 0===i&&(i=0),void 0===e&&(e=0),void 0===r&&(r=1),void 0===s&&(s=r),void 0===h&&(h=0),void 0===g&&(g=0);var v=new n;if(super(t,"rexRoundRectangleShape",v),this.setShapeType(g),0===this.shapeType){var c=x(h,"radius",h);v.setTo(0,0,r,s,c)}else c={x:r/2,y:s/2},v.setTo(0,0,r,s,c);this.setIteration(x(h,"iteration",void 0)),this.setPosition(i,e),this.setFillStyle(a,o),void 0===u&&(u=2),this.setStrokeStyle(u,d,l),this.updateDisplayOrigin(),this.dirty=!0}updateData(){var t=this.geom,i=this.pathData;i.length=0;var e,r=t.width,s=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;c(o,n,e.x,e.y,180,270,!1,a,i)}else c(o=0,n=0,e.x,e.y,90,0,!0,a,i);else y(0,0,i);return e=h.tr,g(e)?e.convex?(o=r-e.x,n=e.y,c(o,n,e.x,e.y,270,360,!1,a,i)):c(o=r,n=0,e.x,e.y,180,90,!0,a,i):y(r,0,i),e=h.br,g(e)?e.convex?(o=r-e.x,n=s-e.y,c(o,n,e.x,e.y,0,90,!1,a,i)):c(o=r,n=s,e.x,e.y,270,180,!0,a,i):y(r,s,i),e=h.bl,g(e)?e.convex?(o=e.x,n=s-e.y,c(o,n,e.x,e.y,90,180,!1,a,i)):c(o=0,n=s,e.x,e.y,360,270,!0,a,i):y(0,s,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();