phaser3-rex-plugins
Version:
2 lines (1 loc) • 12.6 kB
JavaScript
var t,e;t=void 0,e=function(){var t=Phaser.Renderer.WebGL.Utils,e=Phaser.Renderer.WebGL.Utils;const i=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=i(r,a,h),l=n.calcMatrix.copyFrom(o.calc),u=r._displayOriginX,d=r._displayOriginY,c=a.alpha*r.alpha;s.pipelines.preBatch(r),r.isFilled&&function(e,i,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],c=2*l[u+1],f=2*l[u+2],v=o[d+0]-a,g=o[d+1]-h,p=o[c+0]-a,y=o[c+1]-h,x=o[f+0]-a,P=o[f+1]-h,R=i.getX(v,g),m=i.getY(v,g),b=i.getX(p,y),k=i.getY(p,y),T=i.getX(x,P),D=i.getY(x,P);e.batchTri(s,R,m,b,k,T,D,0,0,1,1,n,n,n,2)}}(n,l,r,c,u,d),r.isStroked&&function(t,i,s,r,a){var h=t.strokeTint,n=e.getTintAppendFloatAlpha(i.strokeColor,i.strokeAlpha*s);h.TL=n,h.TR=n,h.BL=n,h.BR=n;var o,l,u=i.isDashed&&!!i.strokePathData,d=u?i.strokePathData:i.pathData,c=d.length-1,f=i.lineWidth,v=f/2,g=d[0]-r,p=d[1]-a;if(i.closePath||(c-=2),u){var y=i.strokePathMask,x=0,P=0;for(R=2;R<c;R+=2)o=d[R]-r,l=d[R+1]-a,y[x]?(t.batchLine(g,p,o,l,v,v,f,P,!1),P++):P=0,g=o,p=l,x++}else for(var R=2;R<c;R+=2)o=d[R]-r,l=d[R+1]-a,t.batchLine(g,p,o,l,v,v,f,R-2,!!i.closePath&&R===c-1),g=o,p=l}(n,r,c,u,d),s.pipelines.postBatch(r)},renderCanvas:function(t,e,i,r){e.dirty&&(e.updateData(),e.dirty=!1),i.addToRenderList(e);var a=t.currentContext;if(s(t,a,e,i,r)){var h=e._displayOriginX,n=e._displayOriginY;e.isFilled&&function(t,e,i,s){var r=e.pathData;if(r&&!(r.length<4)){var a=r.length-1,h=r[0]-i,n=r[1]-s;t.beginPath(),t.moveTo(h,n),e.closePath||(a-=2);for(var o=2;o<a;o+=2){var l=r[o]-i,u=r[o+1]-s;t.lineTo(l,u)}e.closePath&&t.closePath(),function(t,e,i,s){var r=e.fillColor,a=s||e.fillAlpha,h=(16711680&r)>>>16,n=(65280&r)>>>8,o=255&r;t.fillStyle="rgba("+h+","+n+","+o+","+a+")"}(t,e),t.fill()}}(a,e,h,n),e.isStroked&&function(t,e,i,s){var r=e.isDashed&&!!e.strokePathData,a=r?e.strokePathData:e.pathData;if(a&&!(a.length<4)){var h=a.length-1,n=a[0]-i,o=a[1]-s;if(function(t,e,i,s){var r=e.strokeColor,a=s||e.strokeAlpha,h=(16711680&r)>>>16,n=(65280&r)>>>8,o=255&r;t.strokeStyle="rgba("+h+","+n+","+o+","+a+")",t.lineWidth=e.lineWidth}(t,e),t.beginPath(),e.closePath||(h-=2),r){var l=e.strokePathMask,u=0;for(d=2;d<h;d+=2)c=a[d]-i,f=a[d+1]-s,l[u]&&(t.moveTo(n,o),t.lineTo(c,f)),n=c,o=f,u++}else{t.moveTo(n,o);for(var d=2;d<h;d+=2){var c=a[d]-i,f=a[d+1]-s;t.lineTo(c,f)}e.closePath&&t.closePath()}t.stroke()}}(a,e,h,n),a.restore()}}};const a=1e-6,h=10,n=.5;var o=function(t,e){return function(t){if(!Array.isArray(t))return null;for(var e=[],i=0,s=t.length;i<s;i++){var r=Number(t[i]);isFinite(r)&&r>0&&e.push(r)}return e.length>0?e:null}(t)||function(t,e){var{segments:i=h,drawRatio:s=n}=t;if(i=Math.round(i),!isFinite(i)||i<=0)return null;if(!(e>a))return null;var r=e/i;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,e)},l=function(t,e,i){if(t&&!(t.length<4)){var s=t.length-1;if(e||(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];i(r,a,n,o),r=n,a=o}}},u=function(t,e,i){void 0===e&&(e={}),void 0===i&&(i={});var{closePath:s=!1,dashPattern:r,dashOffset:h=0}=e,n=function(t,e){var i=0;return l(t,e,(function(t,e,s,r){var a=s-t,h=r-e;i+=Math.sqrt(a*a+h*h)})),i}(t,s);if(null===(r=o(r,n)))return null;for(var u=[],d=[],c=0,f=0,v=r.length;f<v;f++)c+=r[f];if(c<=a)return i.strokePathData=t?t.slice():[],i.strokePathMask=void 0,i;for(var g=0,p=!0,y=r[g],x=function(){g=(g+1)%r.length,p=!p,y=r[g]},P=function(t,e){return isFinite(t)||(t=0),(t%=e)<0&&(t+=e),t}(h,c);P>a;)P<y-a?(y-=P,P=0):(P-=y,x());var R=function(t,e,i,s,r){if(0===u.length)u.push(t,e);else{var a=u[u.length-2],h=u[u.length-1];a===t&&h===e||u.push(t,e)}u.push(i,s),d.push(r?1:0)};return l(t,s,(function(t,e,i,s){var r=i-t,h=s-e,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;R(t+r*u,e+h*u,t+r*d,e+h*d,p),o+=l,(y-=l)<=a&&x()}}})),!s&&u.length>=2&&u.push(u[u.length-2],u[u.length-1]),i.strokePathData=u,i.strokePathMask=d,i},d={setDashPattern:function(t,e){return this.dashPattern=t,this.dashOffset=e||0,this.isDashed=!!t,this},clearDashPattern:function(){return this.setDashPattern(),this},setDashed:function(t){return void 0===t&&(t=!0),this.isDashed=t,this}},c={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(c,d);const f=Phaser.GameObjects.Shape;class v 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,e){return void 0===e&&(e=1),this.fillColor=t,this.fillAlpha=e,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,e,i){return void 0===i&&(i=1),this.lineWidth=t,this.strokeColor=e,this.strokeAlpha=i,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,e){var i=this.input;return i&&!i.customHitArea&&(i.hitArea.width=t,i.hitArea.height=e),this}resize(t,e){return this.setSize(t,e),this}}Object.assign(v.prototype,c,r);const g=Phaser.Utils.Objects.GetValue;let p=class{constructor(t,e,i,s,r){void 0===t&&(t=0),void 0===e&&(e=t),void 0===i&&(i=0),void 0===s&&(s=0),void 0===r&&(r=0),this.cornerRadius={},this._width=0,this._height=0,this.setTo(t,e,i,s,r)}setTo(t,e,i,s,r){return this.setPosition(t,e),this.setRadius(r),this.setSize(i,s),this}setPosition(t,e){return this.x=t,this.y=e,this}setRadius(t){return void 0===t&&(t=0),this.radius=t,this}setSize(t,e){return this.width=t,this.height=e,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 e,i;"number"==typeof t?(e=t,i=t):(e=g(t,"x",0),i=g(t,"y",0));var s=this.cornerRadius;s.tl=y(g(t,"tl",void 0),e,i),s.tr=y(g(t,"tr",void 0),e,i),s.bl=y(g(t,"bl",void 0),e,i),s.br=y(g(t,"br",void 0),e,i)}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,e,i){return void 0===t?t={x:e,y:i}:"number"==typeof t&&(t={x:t,y:t}),P(t),t},x=function(t,e){"number"==typeof e?(t.x=e,t.y=e):(t.x=g(e,"x",0),t.y=g(e,"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)},R=function(t){return t.x>0&&t.y>0},m=function(t,e,i){var s=i.length;if(s>=2){var r=i[s-2],a=i[s-1];if(t===r&&e===a)return i}return i.push(t,e),i};const b=Phaser.Math.DegToRad;var k=function(t,e,i,s,r,a,h,n,o){h&&a>r?a-=360:!h&&a<r&&(a+=360);var l=b(a-r)/n;r=b(r);for(var u=0;u<=n;u++){var d=r+l*u,c=t+i*Math.cos(d),f=e+s*Math.sin(d);m(c,f,o)}return o};const T=Phaser.Utils.Objects.IsPlainObject,D=Phaser.Utils.Objects.GetValue,A=Phaser.Geom.Polygon.Earcut;class _ extends v{constructor(t,e,i,s,r,a,h,n){var o,l,u,d,c,f;if(T(e)){var v=e;e=v.x,i=v.y,s=v.width,r=v.height,a=v.radius,h=v.color,n=v.alpha,o=v.strokeColor,l=v.strokeAlpha,u=v.strokeWidth,d=v.shape,c=v.dashPattern,f=v.dashOffset}void 0===e&&(e=0),void 0===i&&(i=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(e,i),this.setFillStyle(h,n),void 0===u&&(u=2),this.setStrokeStyle(u,o,l),c&&this.setDashPattern(c,f),this.updateDisplayOrigin(),this.dirty=!0}updateData(){var t=this.geom,e=this.pathData;e.length=0;var i,s=t.width,r=t.height,a=t.cornerRadius,h=this.iteration+1;if(i=a.tl,R(i))if(i.convex){var n=i.x,o=i.y;k(n,o,i.x,i.y,180,270,!1,h,e)}else k(n=0,o=0,i.x,i.y,90,0,!0,h,e);else m(0,0,e);return i=a.tr,R(i)?i.convex?(n=s-i.x,o=i.y,k(n,o,i.x,i.y,270,360,!1,h,e)):k(n=s,o=0,i.x,i.y,180,90,!0,h,e):m(s,0,e),i=a.br,R(i)?i.convex?(n=s-i.x,o=r-i.y,k(n,o,i.x,i.y,0,90,!1,h,e)):k(n=s,o=r,i.x,i.y,270,180,!0,h,e):m(s,r,e),i=a.bl,R(i)?i.convex?(n=i.x,o=r-i.y,k(n,o,i.x,i.y,90,180,!1,h,e)):k(n=0,o=r,i.x,i.y,360,270,!0,h,e):m(0,r,e),e.push(e[0],e[1]),this.pathIndexes=A(e),super.updateData(),this}setShapeType(t){return"string"==typeof t&&(t=M[t]),this.shapeType=t,this}setSize(t,e){return void 0===e&&(e=t),this.geom.width===t&&this.geom.height===e||(this.geom.setSize(t,e),1===this.shapeType&&this.setRadius({x:t/2,y:e/2}),this.updateDisplayOrigin(),this.dirty=!0,super.setSize(t,e)),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}}const M={rectangle:0,circle:1};function O(t,e,i,s,r,a,h){var n=new _(this.scene,t,e,i,s,r,a,h);return this.scene.add.existing(n),n}const S=Phaser.Utils.Objects.GetAdvancedValue,L=Phaser.Utils.Objects.GetValue,C=Phaser.GameObjects.BuildGameObject;function B(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=S(t,"width",void 0),s=S(t,"height",i),r=L(t,"radius",void 0),a=S(t,"fillColor",void 0),h=S(t,"fillAlpha",void 0),n=new _(this.scene,0,0,i,s,r,a,h);return C(this.scene,n,t),n}var w=function(t){return null!==t&&"object"==typeof t};class j extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexRoundRectangle",O,B)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,e,i,s="."){if(!w(t))return t;if(function(t){return null==t}(e)||""===e||Array.isArray(e)&&0===e.length)return t;if("string"==typeof e&&-1===e.indexOf(s)||"number"==typeof e)return t[e]=i,t;var r=function(t,e){return Array.isArray(t)||(t="string"!=typeof t||""===t.trim()?[]:t.split(e).filter(Boolean)),t}(e,s);if(0===r.length)return t;for(var a=t,h=r.length,n=0;n<h-1;n++){var o=r[n],l=a[o];w(l)||(a[o]={}),a=a[o]}a[r[h-1]]=i}(window,"RexPlugins.GameObjects.RoundRectangle",_),j},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexroundrectangleplugin=e();