phaser3-rex-plugins
Version:
2 lines (1 loc) • 11.3 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexroundrectangle=e();}(undefined,(function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var i=0;i<e.length;i++){var r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(n=r.key,o=void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var r=i.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(n,"string"))?o:String(o)),r);}var n,o;}function i(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function n(t,e){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},n(t,e)}function o(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function s(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return !1}}();return function(){var i,n=r(t);if(e){var s=r(this).constructor;i=Reflect.construct(n,arguments,s);}else i=n.apply(this,arguments);return o(this,i)}}var a=Phaser.Utils.Objects.GetValue,u=function(){function e(i,r,n,o,s){t(this,e),void 0===i&&(i=0),void 0===r&&(r=i),void 0===n&&(n=0),void 0===o&&(o=0),void 0===s&&(s=0),this.cornerRadius={},this._width=0,this._height=0,this.setTo(i,r,n,o,s);}return i(e,[{key:"setTo",value:function(t,e,i,r,n){return this.setPosition(t,e),this.setRadius(n),this.setSize(i,r),this}},{key:"setPosition",value:function(t,e){return this.x=t,this.y=e,this}},{key:"setRadius",value:function(t){return void 0===t&&(t=0),this.radius=t,this}},{key:"setSize",value:function(t,e){return this.width=t,this.height=e,this}},{key:"minWidth",get:function(){var t=this.cornerRadius;return Math.max(t.tl.x+t.tr.x,t.bl.x+t.br.x)}},{key:"minHeight",get:function(){var t=this.cornerRadius;return Math.max(t.tl.y+t.bl.y,t.tr.y+t.br.y)}},{key:"width",get:function(){return this._width},set:function(t){null==t&&(t=0),this._width=Math.max(t,this.minWidth);}},{key:"height",get:function(){return this._height},set:function(t){null==t&&(t=0),this._height=Math.max(t,this.minHeight);}},{key:"radius",get:function(){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:function(t){var e,i;"number"==typeof t?(e=t,i=t):(e=a(t,"x",0),i=a(t,"y",0));var r=this.cornerRadius;r.tl=h(a(t,"tl",void 0),e,i),r.tr=h(a(t,"tr",void 0),e,i),r.bl=h(a(t,"bl",void 0),e,i),r.br=h(a(t,"br",void 0),e,i);}},{key:"radiusTL",get:function(){var t=this.cornerRadius.tl;return Math.max(t.x,t.y)},set:function(t){l(this.cornerRadius.tl,t);}},{key:"radiusTR",get:function(){var t=this.cornerRadius.tr;return Math.max(t.x,t.y)},set:function(t){l(this.cornerRadius.tr,t);}},{key:"radiusBL",get:function(){var t=this.cornerRadius.bl;return Math.max(t.x,t.y)},set:function(t){l(this.cornerRadius.bl,t);}},{key:"radiusBR",get:function(){var t=this.cornerRadius.br;return Math.max(t.x,t.y)},set:function(t){l(this.cornerRadius.br,t);}}]),e}(),h=function(t,e,i){return void 0===t?t={x:e,y:i}:"number"==typeof t&&(t={x:t,y:t}),c(t),t},l=function(t,e){"number"==typeof e?(t.x=e,t.y=e):(t.x=a(e,"x",0),t.y=a(e,"y",0)),c(t);},c=function(t){t.convex=t.x>=0||t.y>=0,t.x=Math.abs(t.x),t.y=Math.abs(t.y);},f=function(t,e,i){var r=i.length;if(r>=2){var n=i[r-2],o=i[r-1];if(t===n&&e===o)return i}return i.push(t,e),i},d=Phaser.Math.DegToRad,y=function(t,e,i,r,n,o,s,a,u){s&&o>n?o-=360:!s&&o<n&&(o+=360);var h=d(o-n)/a;n=d(n);for(var l=0;l<=a;l++){var c=n+h*l,y=t+i*Math.cos(c),p=e+r*Math.sin(c);f(y,p,u);}return u},p=Phaser.Renderer.WebGL.Utils,v=Phaser.Renderer.WebGL.Utils,g=Phaser.GameObjects.GetCalcMatrix,b=Phaser.Renderer.Canvas.SetTransform,k={renderWebGL:function(t,e,i,r){e.dirty&&(e.updateData(),e.dirty=!1),i.addToRenderList(e);var n=t.pipelines.set(e.pipeline),o=g(e,i,r),s=n.calcMatrix.copyFrom(o.calc),a=e._displayOriginX,u=e._displayOriginY,h=i.alpha*e.alpha;t.pipelines.preBatch(e),e.isFilled&&function(t,e,i,r,n,o){for(var s=p.getTintAppendFloatAlpha(i.fillColor,i.fillAlpha*r),a=i.pathData,u=i.pathIndexes,h=0;h<u.length;h+=3){var l=2*u[h],c=2*u[h+1],f=2*u[h+2],d=a[l+0]-n,y=a[l+1]-o,v=a[c+0]-n,g=a[c+1]-o,b=a[f+0]-n,k=a[f+1]-o,x=e.getX(d,y),m=e.getY(d,y),R=e.getX(v,g),_=e.getY(v,g),T=e.getX(b,k),P=e.getY(b,k);t.batchTri(i,x,m,R,_,T,P,0,0,1,1,s,s,s,2);}}(n,s,e,h,a,u),e.isStroked&&function(t,e,i,r,n){var o=t.strokeTint,s=v.getTintAppendFloatAlpha(e.strokeColor,e.strokeAlpha*i);o.TL=s,o.TR=s,o.BL=s,o.BR=s;var a=e.pathData,u=a.length-1,h=e.lineWidth,l=h/2,c=a[0]-r,f=a[1]-n;e.closePath||(u-=2);for(var d=2;d<u;d+=2){var y=a[d]-r,p=a[d+1]-n;t.batchLine(c,f,y,p,l,l,h,d-2,!!e.closePath&&d===u-1),c=y,f=p;}}(n,e,h,a,u),t.pipelines.postBatch(e);},renderCanvas:function(t,e,i,r){e.dirty&&(e.updateData(),e.dirty=!1),i.addToRenderList(e);var n=t.currentContext;if(b(t,n,e,i,r)){var o=e._displayOriginX,s=e._displayOriginY,a=e.pathData,u=a.length-1,h=a[0]-o,l=a[1]-s;n.beginPath(),n.moveTo(h,l),e.closePath||(u-=2);for(var c=2;c<u;c+=2){var f=a[c]-o,d=a[c+1]-s;n.lineTo(f,d);}n.closePath(),e.isFilled&&(!function(t,e,i,r){var n=i||e.fillColor,o=r||e.fillAlpha,s=(16711680&n)>>>16,a=(65280&n)>>>8,u=255&n;t.fillStyle="rgba("+s+","+a+","+u+","+o+")";}(n,e),n.fill()),e.isStroked&&(!function(t,e,i,r){var n=i||e.strokeColor,o=r||e.strokeAlpha,s=(16711680&n)>>>16,a=(65280&n)>>>8,u=255&n;t.strokeStyle="rgba("+s+","+a+","+u+","+o+")",t.lineWidth=e.lineWidth;}(n,e),n.stroke()),n.restore();}}},x=Phaser.GameObjects.Shape,m=Phaser.Utils.Objects.IsPlainObject,R=Phaser.Utils.Objects.GetValue,_=Phaser.Geom.Polygon.Earcut,T=function(e){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&n(t,e);}(o,e);var r=s(o);function o(e,i,n,s,a,h,l,c){var f,d,y,p,v;if(t(this,o),m(i)){var g=i;i=g.x,n=g.y,s=g.width,a=g.height,h=g.radius,l=g.color,c=g.alpha,d=g.strokeColor,y=g.strokeAlpha,p=g.strokeWidth,v=g.shape;}void 0===i&&(i=0),void 0===n&&(n=0),void 0===s&&(s=1),void 0===a&&(a=s),void 0===h&&(h=0),void 0===v&&(v=0);var b=new u;if((f=r.call(this,e,"rexRoundRectangleShape",b)).setShapeType(v),0===f.shapeType){var k=R(h,"radius",h);b.setTo(0,0,s,a,k);}else {k={x:s/2,y:a/2};b.setTo(0,0,s,a,k);}var x=R(h,"iteration",void 0);return f.setIteration(x),f.setPosition(i,n),f.setFillStyle(l,c),void 0!==d&&void 0===p&&(p=2),f.setStrokeStyle(p,d,y),f.updateDisplayOrigin(),f.dirty=!0,f}return i(o,[{key:"fillColor",get:function(){return this._fillColor},set:function(t){this._fillColor=t,this.isFilled=null!=t&&this._fillAlpha>0;}},{key:"fillAlpha",get:function(){return this._fillAlpha},set:function(t){this._fillAlpha=t,this.isFilled=t>0&&null!=this._fillColor;}},{key:"setFillStyle",value:function(t,e){return void 0===e&&(e=1),this.fillColor=t,this.fillAlpha=e,this}},{key:"strokeColor",get:function(){return this._strokeColor},set:function(t){this._strokeColor=t,this.isStroked=null!=t&&this._strokeAlpha>0&&this._lineWidth>0;}},{key:"strokeAlpha",get:function(){return this._strokeAlpha},set:function(t){this._strokeAlpha=t,this.isStroked=t>0&&null!=this._strokeColor&&this._lineWidth>0;}},{key:"lineWidth",get:function(){return this._lineWidth},set:function(t){this._lineWidth=t,this.isStroked=t>0&&null!=this._strokeColor;}},{key:"setStrokeStyle",value:function(t,e,i){return void 0===i&&(i=1),this.lineWidth=t,this.strokeColor=e,this.strokeAlpha=i,this}},{key:"updateData",value:function(){var t=this.geom,e=this.pathData;e.length=0;var i,r=t.width,n=t.height,o=t.cornerRadius,s=this.iteration+1;if(i=o.tl,P(i))if(i.convex){var a=i.x,u=i.y;y(a,u,i.x,i.y,180,270,!1,s,e);}else {y(a=0,u=0,i.x,i.y,90,0,!0,s,e);}else f(0,0,e);if(i=o.tr,P(i))if(i.convex){a=r-i.x,u=i.y;y(a,u,i.x,i.y,270,360,!1,s,e);}else {y(a=r,u=0,i.x,i.y,180,90,!0,s,e);}else f(r,0,e);if(i=o.br,P(i))if(i.convex){a=r-i.x,u=n-i.y;y(a,u,i.x,i.y,0,90,!1,s,e);}else {y(a=r,u=n,i.x,i.y,270,180,!0,s,e);}else f(r,n,e);if(i=o.bl,P(i))if(i.convex){a=i.x,u=n-i.y;y(a,u,i.x,i.y,90,180,!1,s,e);}else {y(a=0,u=n,i.x,i.y,360,270,!0,s,e);}else f(0,n,e);return e.push(e[0],e[1]),this.pathIndexes=_(e),this}},{key:"setShapeType",value:function(t){return "string"==typeof t&&(t=O[t]),this.shapeType=t,this}},{key:"width",get:function(){return this.geom.width},set:function(t){this.resize(t,this.height);}},{key:"height",get:function(){return this.geom.height},set:function(t){this.resize(this.width,t);}},{key:"setSize",value:function(t,e){if(void 0===e&&(e=t),this.geom.width===t&&this.geom.height===e)return this;this.geom.setSize(t,e),1===this.shapeType&&this.setRadius({x:t/2,y:e/2}),this.updateDisplayOrigin(),this.dirty=!0;var i=this.input;return i&&!i.customHitArea&&(i.hitArea.width=t,i.hitArea.height=e),this}},{key:"resize",value:function(t,e){return this.setSize(t,e),this}},{key:"radius",get:function(){return this.geom.radius},set:function(t){this.geom.setRadius(t),this.updateDisplayOrigin(),this.dirty=!0;}},{key:"radiusTL",get:function(){return this.geom.radiusTL},set:function(t){this.geom.radiusTL=t,this.dirty=!0;}},{key:"radiusTR",get:function(){return this.geom.radiusTR},set:function(t){this.geom.radiusTR=t,this.dirty=!0;}},{key:"radiusBL",get:function(){return this.geom.radiusBL},set:function(t){this.geom.radiusBL=t,this.dirty=!0;}},{key:"radiusBR",get:function(){return this.geom.radiusBR},set:function(t){this.geom.radiusBR=t,this.dirty=!0;}},{key:"setRadius",value:function(t){return void 0===t&&(t=0),this.radius=t,this}},{key:"setRadiusTL",value:function(t){return void 0===t&&(t=0),this.radiusTL=t,this}},{key:"setRadiusTR",value:function(t){return void 0===t&&(t=0),this.radiusTR=t,this}},{key:"setRadiusBL",value:function(t){return void 0===t&&(t=0),this.radiusBL=t,this}},{key:"setRadiusBR",value:function(t){return void 0===t&&(t=0),this.radiusBR=t,this}},{key:"cornerRadius",get:function(){return this.geom.cornerRadius},set:function(t){this.radius=t;}},{key:"setCornerRadius",value:function(t){return this.setRadius(t)}},{key:"iteration",get:function(){return this._iteration},set:function(t){void 0!==this._iteration?this._iteration!==t&&(this._iteration=t,this.dirty=!0):this._iteration=t;}},{key:"setIteration",value:function(t){return void 0===t&&(t=6),this.iteration=t,this}}]),o}(x),P=function(t){return t.x>0&&t.y>0},O={rectangle:0,circle:1};return Object.assign(T.prototype,k),T}));