@petkoneo/phaser3-rex-plugins
Version:
2 lines (1 loc) • 9.54 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 o=s.pipelines.set(r.pipeline),n=e(r,a,h),l=o.calcMatrix.copyFrom(n.calc),d=r._displayOriginX,u=r._displayOriginY,c=a.alpha*r.alpha;s.pipelines.preBatch(r),r.isFilled&&function(i,e,s,r,a,h){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],c=2*l[d+1],g=2*l[d+2],p=n[u+0]-a,v=n[u+1]-h,y=n[c+0]-a,f=n[c+1]-h,x=n[g+0]-a,R=n[g+1]-h,b=e.getX(p,v),m=e.getY(p,v),T=e.getX(y,f),_=e.getY(y,f),k=e.getX(x,R),P=e.getY(x,R);i.batchTri(s,b,m,T,_,k,P,0,0,1,1,o,o,o,2)}}(o,l,r,c,d,u),r.isStroked&&function(t,e,s,r,a){var h=t.strokeTint,o=i.getTintAppendFloatAlpha(e.strokeColor,e.strokeAlpha*s);h.TL=o,h.TR=o,h.BL=o,h.BR=o;var n=e.pathData,l=n.length-1,d=e.lineWidth,u=d/2,c=n[0]-r,g=n[1]-a;e.closePath||(l-=2);for(var p=2;p<l;p+=2){var v=n[p]-r,y=n[p+1]-a;t.batchLine(c,g,v,y,u,u,d,p-2,!!e.closePath&&p===l-1),c=v,g=y}}(o,r,c,d,u),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,o=i._displayOriginY,n=i.pathData,l=n.length-1,d=n[0]-h,u=n[1]-o;a.beginPath(),a.moveTo(d,u),i.closePath||(l-=2);for(var c=2;c<l;c+=2){var g=n[c]-h,p=n[c+1]-o;a.lineTo(g,p)}a.closePath(),i.isFilled&&(function(t,i,e,s){var r=e||i.fillColor,a=s||i.fillAlpha,h=(16711680&r)>>>16,o=(65280&r)>>>8,n=255&r;t.fillStyle="rgba("+h+","+o+","+n+","+a+")"}(a,i),a.fill()),i.isStroked&&(function(t,i,e,s){var r=e||i.strokeColor,a=s||i.strokeAlpha,h=(16711680&r)>>>16,o=(65280&r)>>>8,n=255&r;t.strokeStyle="rgba("+h+","+o+","+n+","+a+")",t.lineWidth=i.lineWidth}(a,i),a.stroke()),a.restore()}}};const a=Phaser.GameObjects.Shape;class h extends a{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(h.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)},c=function(t){return t.x>0&&t.y>0},g=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 p=Phaser.Math.DegToRad;var v=function(t,i,e,s,r,a,h,o,n){h&&a>r?a-=360:!h&&a<r&&(a+=360);var l=p(a-r)/o;r=p(r);for(var d=0;d<=o;d++){var u=r+l*d,c=t+e*Math.cos(u),v=i+s*Math.sin(u);g(c,v,n)}return n};const y=Phaser.Utils.Objects.IsPlainObject,f=Phaser.Utils.Objects.GetValue,x=Phaser.Geom.Polygon.Earcut;class R extends h{constructor(t,i,e,s,r,a,h,o){var l,d,u,c;if(y(i)){var g=i;i=g.x,e=g.y,s=g.width,r=g.height,a=g.radius,h=g.color,o=g.alpha,l=g.strokeColor,d=g.strokeAlpha,u=g.strokeWidth,c=g.shape}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===c&&(c=0);var p=new n;if(super(t,"rexRoundRectangleShape",p),this.setShapeType(c),0===this.shapeType){var v=f(a,"radius",a);p.setTo(0,0,s,r,v)}else v={x:s/2,y:r/2},p.setTo(0,0,s,r,v);this.setIteration(f(a,"iteration",void 0)),this.setPosition(i,e),this.setFillStyle(h,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,a=t.cornerRadius,h=this.iteration+1;if(e=a.tl,c(e))if(e.convex){var o=e.x,n=e.y;v(o,n,e.x,e.y,180,270,!1,h,i)}else v(o=0,n=0,e.x,e.y,90,0,!0,h,i);else g(0,0,i);return e=a.tr,c(e)?e.convex?(o=s-e.x,n=e.y,v(o,n,e.x,e.y,270,360,!1,h,i)):v(o=s,n=0,e.x,e.y,180,90,!0,h,i):g(s,0,i),e=a.br,c(e)?e.convex?(o=s-e.x,n=r-e.y,v(o,n,e.x,e.y,0,90,!1,h,i)):v(o=s,n=r,e.x,e.y,270,180,!0,h,i):g(s,r,i),e=a.bl,c(e)?e.convex?(o=e.x,n=r-e.y,v(o,n,e.x,e.y,90,180,!1,h,i)):v(o=0,n=r,e.x,e.y,360,270,!0,h,i):g(0,r,i),i.push(i[0],i[1]),this.pathIndexes=x(i),this}setShapeType(t){return"string"==typeof t&&(t=b[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}}const b={rectangle:0,circle:1};function m(t,i,e,s,r,a,h){var o=new R(this.scene,t,i,e,s,r,a,h);return this.scene.add.existing(o),o}const T=Phaser.Utils.Objects.GetAdvancedValue,_=Phaser.Utils.Objects.GetValue,k=Phaser.GameObjects.BuildGameObject;function P(t,i){void 0===t&&(t={}),void 0!==i&&(t.add=i);var e=T(t,"width",void 0),s=T(t,"height",e),r=_(t,"radius",void 0),a=T(t,"fillColor",void 0),h=T(t,"fillAlpha",void 0),o=new R(this.scene,0,0,e,s,r,a,h);return k(this.scene,o,t),o}var A=function(t){return null==t||""===t||0===t.length};class S extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexRoundRectangle",m,P)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,i,e,s){if(void 0===s&&(s="."),"object"==typeof t)if(A(i)){if(null==e)return;"object"==typeof e&&(t=e)}else{"string"==typeof i&&(i=i.split(s));var r=i.pop(),a=function(t,i,e){var s=t;if(A(i));else{var r;"string"==typeof i&&(i=i.split("."));for(var a=0,h=i.length;a<h;a++){var o;null!=s[r=i[a]]&&"object"==typeof s[r]||(o=a===h-1?void 0===e?{}:e:{},s[r]=o),s=s[r]}}return s}(t,i);a[r]=e}}(window,"RexPlugins.GameObjects.RoundRectangle",R),S},"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).rexroundrectangleplugin=i();