UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 9.48 kB
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);var o=a.camera;o.addToRenderList(r);var n=i(r,o,h,!a.useCanvas).calc,d=r._displayOriginX,l=r._displayOriginY,u=r.alpha,c=r.customRenderNodes.Submitter||r.defaultRenderNodes.Submitter;r.isFilled&&function(e,i,s,r,a,h,o,n){var d,l,u,c,g,v=t.getTintAppendFloatAlpha(a.fillColor,a.fillAlpha*h),p=a.pathData,y=a.pathIndexes,f=p.length,x=Array(2*f),R=Array(f),m=0,b=0;for(d=0;d<f;d+=2)l=p[d]-o,u=p[d+1]-n,c=s.getX(l,u),g=s.getY(l,u),x[m++]=c,x[m++]=g,R[b++]=v;i.batch(e,y,x,R)}(a,c,n,0,r,u,d,l),r.isStroked&&function(t,i,s,r,a,h,o,n){var d=e.getTintAppendFloatAlpha(a.strokeColor,a.strokeAlpha*h),l=a.pathData,u=l.length-1,c=a.lineWidth,g=!a.closePath,v=r.customRenderNodes.StrokePath||r.defaultRenderNodes.StrokePath,p=[];g&&(u-=2);for(var y=0;y<u;y+=2){var f=l[y]-o,x=l[y+1]-n;y>0&&f===l[y-2]&&x===l[y-1]||p.push({x:f,y:x,width:c})}v.run(t,i,p,c,g,s,d,d,d,d)}(a,c,n,r,r,u,d,l)},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,o=e._displayOriginY,n=e.pathData,d=n.length-1,l=n[0]-h,u=n[1]-o;a.beginPath(),a.moveTo(l,u),e.closePath||(d-=2);for(var c=2;c<d;c+=2){var g=n[c]-h,v=n[c+1]-o;a.lineTo(g,v)}a.closePath(),e.isFilled&&(function(t,e,i,s){var r=i||e.fillColor,a=s||e.fillAlpha,h=(16711680&r)>>>16,o=(65280&r)>>>8,n=255&r;t.fillStyle="rgba("+h+","+o+","+n+","+a+")"}(a,e),a.fill()),e.isStroked&&(function(t,e,i,s){var r=i||e.strokeColor,a=s||e.strokeAlpha,h=(16711680&r)>>>16,o=(65280&r)>>>8,n=255&r;t.strokeStyle="rgba("+h+","+o+","+n+","+a+")",t.lineWidth=e.lineWidth}(a,e),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,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}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(h.prototype,r);const o=Phaser.Utils.Objects.GetValue;let n=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=o(t,"x",0),i=o(t,"y",0));var s=this.cornerRadius;s.tl=d(o(t,"tl",void 0),e,i),s.tr=d(o(t,"tr",void 0),e,i),s.bl=d(o(t,"bl",void 0),e,i),s.br=d(o(t,"br",void 0),e,i)}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,e,i){return void 0===t?t={x:e,y:i}:"number"==typeof t&&(t={x:t,y:t}),u(t),t},l=function(t,e){"number"==typeof e?(t.x=e,t.y=e):(t.x=o(e,"x",0),t.y=o(e,"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,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 v=Phaser.Math.DegToRad;var p=function(t,e,i,s,r,a,h,o,n){h&&a>r?a-=360:!h&&a<r&&(a+=360);var d=v(a-r)/o;r=v(r);for(var l=0;l<=o;l++){var u=r+d*l,c=t+i*Math.cos(u),p=e+s*Math.sin(u);g(c,p,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,e,i,s,r,a,h,o){var d,l,u,c;if(y(e)){var g=e;e=g.x,i=g.y,s=g.width,r=g.height,a=g.radius,h=g.color,o=g.alpha,d=g.strokeColor,l=g.strokeAlpha,u=g.strokeWidth,c=g.shape}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===c&&(c=0);var v=new n;if(super(t,"rexRoundRectangleShape",v),this.setShapeType(c),0===this.shapeType){var p=f(a,"radius",a);v.setTo(0,0,s,r,p)}else p={x:s/2,y:r/2},v.setTo(0,0,s,r,p);this.setIteration(f(a,"iteration",void 0)),this.setPosition(e,i),this.setFillStyle(h,o),void 0===u&&(u=2),this.setStrokeStyle(u,d,l),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,c(i))if(i.convex){var o=i.x,n=i.y;p(o,n,i.x,i.y,180,270,!1,h,e)}else p(o=0,n=0,i.x,i.y,90,0,!0,h,e);else g(0,0,e);return i=a.tr,c(i)?i.convex?(o=s-i.x,n=i.y,p(o,n,i.x,i.y,270,360,!1,h,e)):p(o=s,n=0,i.x,i.y,180,90,!0,h,e):g(s,0,e),i=a.br,c(i)?i.convex?(o=s-i.x,n=r-i.y,p(o,n,i.x,i.y,0,90,!1,h,e)):p(o=s,n=r,i.x,i.y,270,180,!0,h,e):g(s,r,e),i=a.bl,c(i)?i.convex?(o=i.x,n=r-i.y,p(o,n,i.x,i.y,90,180,!1,h,e)):p(o=0,n=r,i.x,i.y,360,270,!0,h,e):g(0,r,e),e.push(e[0],e[1]),this.pathIndexes=x(e),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 b(t,e,i,s,r,a,h){var o=new R(this.scene,t,e,i,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 S(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=T(t,"width",void 0),s=T(t,"height",i),r=_(t,"radius",void 0),a=T(t,"fillColor",void 0),h=T(t,"fillAlpha",void 0),o=new R(this.scene,0,0,i,s,r,a,h);return k(this.scene,o,t),o}var A=function(t){return null==t||""===t||0===t.length};class P extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexRoundRectangle",b,S)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,e,i,s){if(void 0===s&&(s="."),"object"==typeof t)if(A(e)){if(null==i)return;"object"==typeof i&&(t=i)}else{"string"==typeof e&&(e=e.split(s));var r=e.pop(),a=function(t,e,i){var s=t;if(A(e));else{var r;"string"==typeof e&&(e=e.split("."));for(var a=0,h=e.length;a<h;a++){var o;null!=s[r=e[a]]&&"object"==typeof s[r]||(o=a===h-1?void 0===i?{}:i:{},s[r]=o),s=s[r]}}return s}(t,e);a[r]=i}}(window,"RexPlugins.GameObjects.RoundRectangle",R),P},"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();