phaser4-rex-plugins
Version:
2 lines (1 loc) • 11 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,o,n){r.dirty&&(r.updateData(),r.dirty=!1);var h=o.camera;h.addToRenderList(r);var l=e(r,h,n,!o.useCanvas).calc,d=r._displayOriginX,a=r._displayOriginY,g=r.alpha,u=r.customRenderNodes.Submitter||r.defaultRenderNodes.Submitter;r.isFilled&&function(i,e,s,r,o,n,h,l){var d,a,g,u,P,y=t.getTintAppendFloatAlpha(o.fillColor,o.fillAlpha*n),f=o.pathData,p=o.pathIndexes,c=f.length,S=Array(2*c),m=Array(c),v=0,b=0;for(d=0;d<c;d+=2)a=f[d]-h,g=f[d+1]-l,u=s.getX(a,g),P=s.getY(a,g),S[v++]=u,S[v++]=P,m[b++]=y;e.batch(i,p,S,m)}(o,u,l,0,r,g,d,a),r.isStroked&&function(t,e,s,r,o,n,h,l){var d=i.getTintAppendFloatAlpha(o.strokeColor,o.strokeAlpha*n),a=o.pathData,g=a.length-1,u=o.lineWidth,P=!o.closePath,y=r.customRenderNodes.StrokePath||r.defaultRenderNodes.StrokePath,f=[];P&&(g-=2);for(var p=0;p<g;p+=2){var c=a[p]-h,S=a[p+1]-l;p>0&&c===a[p-2]&&S===a[p-1]||f.push({x:c,y:S,width:u})}y.run(t,e,f,u,P,s,d,d,d,d)}(o,u,l,r,r,g,d,a)},renderCanvas:function(t,i,e,r){i.dirty&&(i.updateData(),i.dirty=!1),e.addToRenderList(i);var o=t.currentContext;if(s(t,o,i,e,r)){var n=i._displayOriginX,h=i._displayOriginY,l=i.pathData,d=l.length-1,a=l[0]-n,g=l[1]-h;o.beginPath(),o.moveTo(a,g),i.closePath||(d-=2);for(var u=2;u<d;u+=2){var P=l[u]-n,y=l[u+1]-h;o.lineTo(P,y)}o.closePath(),i.isFilled&&(function(t,i,e,s){var r=e||i.fillColor,o=s||i.fillAlpha,n=(16711680&r)>>>16,h=(65280&r)>>>8,l=255&r;t.fillStyle="rgba("+n+","+h+","+l+","+o+")"}(o,i),o.fill()),i.isStroked&&(function(t,i,e,s){var r=e||i.strokeColor,o=s||i.strokeAlpha,n=(16711680&r)>>>16,h=(65280&r)>>>8,l=255&r;t.strokeStyle="rgba("+n+","+h+","+l+","+o+")",t.lineWidth=i.lineWidth}(o,i),o.stroke()),o.restore()}}};const o=Phaser.GameObjects.Shape;class n extends o{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(n.prototype,r);var h=function(t,i,e){i&&!function(t,i){if(!t)return!1;if(t.hasOwnProperty(i))return!0;for(;t;){if(Object.getOwnPropertyDescriptor(t,i))return!0;t=t.__proto__}return!1}(t,`${i}X`)&&(Object.defineProperty(t,`${i}X`,{get:function(){return e.x},set:function(i){e.x=i,t.dirty=!0}}),Object.defineProperty(t,`${i}Y`,{get:function(){return e.y},set:function(i){e.y=i,t.dirty=!0}}),Object.defineProperty(t,`${i}T`,{get:function(){return e.t},set:function(i){e.t=i,t.dirty=!0}}))},l={setTLPosition(t,i){return this.geom.setTLPosition(t,i),this.dirty=!0,this},setTRPosition(t,i){return this.geom.setTRPosition(t,i),this.dirty=!0,this},setBLPosition(t,i){return this.geom.setBLPosition(t,i),this.dirty=!0,this},setBRPosition(t,i){return this.geom.setBRPosition(t,i),this.dirty=!0,this},resetCornerPosition(){return this.geom.resetCornerPosition(),this.dirty=!0,this},insertTopSidePoint(t,i,e,s){var r=this.geom.topSidePoints;if(Array.isArray(t))for(var o,n=0,l=(r=t).length;n<l;n++)o=r[n],this.geom.insertTopSidePoint(o.t,o.x,o.y),h(this,o.key,r[r.length-1]);else this.geom.insertTopSidePoint(t,i,e),h(this,s,r[r.length-1]);return this.dirty=!0,this},insertRightSidePoint(t,i,e,s){var r=this.geom.rightSidePoints;if(Array.isArray(t))for(var o,n=0,l=(r=t).length;n<l;n++)o=r[n],this.geom.insertRightSidePoint(o.t,o.x,o.y),h(this,o.key,r[r.length-1]);else this.geom.insertRightSidePoint(t,i,e),h(this,s,r[r.length-1]);return this.dirty=!0,this},insertBottomSidePoint(t,i,e,s){var r=this.geom.bottomSidePoints;if(Array.isArray(t))for(var o,n=0,l=(r=t).length;n<l;n++)o=r[n],this.geom.insertBottomSidePoint(o.t,o.x,o.y),h(this,o.key,r[r.length-1]);else this.geom.insertBottomSidePoint(t,i,e),h(this,s,r[r.length-1]);return this.dirty=!0,this},insertLeftSidePoint(t,i,e,s){var r=this.geom.leftSidePoints;if(Array.isArray(t))for(var o,n=0,l=(r=t).length;n<l;n++)o=r[n],this.geom.insertLeftSidePoint(o.t,o.x,o.y),h(this,o.key,r[r.length-1]);else this.geom.insertLeftSidePoint(t,i,e),h(this,s,r[r.length-1]);return this.dirty=!0,this},clearTopSidePoints(){return this.geom.clearTopSidePoints(),this.dirty=!0,this},clearRightSidePoints(){return this.geom.clearRightSidePoints(),this.dirty=!0,this},clearBottomSidePoints(){return this.geom.clearBottomSidePoints(),this.dirty=!0,this},clearLeftSidePoints(){return this.geom.clearLeftSidePoints(),this.dirty=!0,this},clearAllSidesPoints(){return this.geom.clearAllSidesPoints(),this.dirty=!0,this}};class d{constructor(t,i,e,s){void 0===t&&(t=0),void 0===i&&(i=t),void 0===e&&(e=0),void 0===s&&(s=0),this.setTo(t,i,e,s),this.tlx=0,this.tly=0,this.trx=0,this.try=0,this.blx=0,this.bly=0,this.brx=0,this.bry=0,this.topSidePoints=[],this.rightSidePoints=[],this.bottomSidePoints=[],this.leftSidePoints=[]}setTo(t,i,e,s){return this.setPosition(t,i),this.setSize(e,s),this}setPosition(t,i){return this.x=t,this.y=i,this}setSize(t,i){return this.width=t,this.height=i,this}setTLPosition(t,i){return this.tlx=t,this.tly=i,this}setTRPosition(t,i){return this.trx=t,this.try=i,this}setBLPosition(t,i){return this.blx=t,this.bly=i,this}setBRPosition(t,i){return this.brx=t,this.bry=i,this}resetCornerPosition(){return this.setTLPosition(0,0).setTRPosition(0,0).setBLPosition(0,0).setBRPosition(0,0),this}insertTopSidePoint(t,i,e){return a(this.topSidePoints,t,i,e),this}insertRightSidePoint(t,i,e){return a(this.rightSidePoints,t,i,e),this}insertBottomSidePoint(t,i,e){return a(this.bottomSidePoints,t,i,e),this}insertLeftSidePoint(t,i,e){return a(this.leftSidePoints,t,i,e),this}clearTopSidePoints(){return this.topSidePoints.length=0,this}clearRightSidePoints(){return this.rightSidePoints.length=0,this}clearBottomSidePoints(){return this.bottomSidePoints.length=0,this}clearLeftSidePoints(){return this.leftSidePoints.length=0,this}clearAllSidesPoints(){return this.clearTopSidePoints().clearRightSidePoints().clearBottomSidePoints().clearLeftSidePoints(),this}}var a=function(t,i,e,s){if("number"!=typeof i){var r=i;i=r.t,e=r.x,s=r.y}t.push({t:i,x:e,y:s})},g=function(t,i,e){var s=e.length;if(s>=2){var r=e[s-2],o=e[s-1];if(t===r&&i===o)return e}return e.push(t,i),e};const u=Phaser.Utils.Objects.IsPlainObject,P=Phaser.Utils.Objects.GetValue,y=Phaser.Math.Linear,f=Phaser.Geom.Polygon.Earcut;class p extends n{constructor(t,i,e,s,r,o,n){var h,l,a;if(u(i)){var g=i;i=g.x,e=g.y,s=g.width,r=g.height,o=g.color,n=g.alpha,h=g.strokeColor,l=g.strokeAlpha,a=g.strokeWidth}void 0===i&&(i=0),void 0===e&&(e=0),void 0===s&&(s=1),void 0===r&&(r=s);var y=new d;super(t,"rexQuadShape",y),y.setTo(0,0,s,r),this.setPosition(i,e),this.setFillStyle(o,n),void 0!==h&&void 0===a&&(a=2),this.setStrokeStyle(a,h,l),this.setTLPosition(P(g,"tlx",0),P(g,"tly",0)).setTRPosition(P(g,"trx",0),P(g,"try",0)).setBLPosition(P(g,"blx",0),P(g,"bly",0)).setBRPosition(P(g,"brx",0),P(g,"bry",0));var f=P(g,"leftSidePoints");f&&this.insertLeftSidePoint(f);var p=P(g,"topSidePoints");p&&this.insertTopSidePoint(p);var c=P(g,"rightSidePoints");c&&this.insertRightSidePoint(c);var S=P(g,"bottomSidePoints");S&&this.insertBottomSidePoint(S),this.updateDisplayOrigin(),this.dirty=!0}updateData(){var t=this.geom,i=this.pathData;i.length=0;var e=t.width,s=t.height,r=0+t.tlx,o=0+t.tly,n=e+t.trx,h=0+t.try,l=e+t.brx,d=s+t.bry,a=0+t.blx,u=s+t.bly,P=t.topSidePoints,p=t.rightSidePoints,S=t.bottomSidePoints,m=t.leftSidePoints;g(r,o,i),c(P);for(var v=0,b=P.length;v<b;v++){var x=P[v],A=y(r,n,x.t)+x.x,k=y(o,h,x.t)+x.y;g(A,k,i)}for(g(n,h,i),c(p),v=0,b=p.length;v<b;v++)x=p[v],A=y(n,l,x.t)+x.x,k=y(h,d,x.t)+x.y,g(A,k,i);for(g(l,d,i),c(S),v=S.length-1;v>=0;v--)x=S[v],A=y(a,l,x.t)+x.x,k=y(u,d,x.t)+x.y,g(A,k,i);for(g(a,u,i),c(m),v=m.length-1;v>=0;v--)x=m[v],A=y(r,a,x.t)+x.x,k=y(o,u,x.t)+x.y,g(A,k,i);return i.push(i[0],i[1]),this.pathIndexes=f(i),this}get tlx(){return this.geom.tlx}set tlx(t){this.geom.tlx=t,this.dirty=!0}get tly(){return this.geom.tly}set tly(t){this.geom.tly=t,this.dirty=!0}get trx(){return this.geom.trx}set trx(t){this.geom.trx=t,this.dirty=!0}get try(){return this.geom.try}set try(t){this.geom.try=t,this.dirty=!0}get blx(){return this.geom.blx}set blx(t){this.geom.blx=t,this.dirty=!0}get bly(){return this.geom.bly}set bly(t){this.geom.bly=t,this.dirty=!0}get brx(){return this.geom.brx}set brx(t){this.geom.brx=t,this.dirty=!0}get bry(){return this.geom.bry}set bry(t){this.geom.bry=t,this.dirty=!0}get leftSidePoints(){return this.geom.leftSidePoints}get topSidePoints(){return this.geom.topSidePoints}get bottomSidePoints(){return this.geom.bottomSidePoints}get rightSidePoints(){return this.geom.rightSidePoints}}var c=function(t){t.length<=1||t.sort((function(t,i){return t.t-i.t}))};function S(t,i,e,s,r,o){var n=new p(this.scene,t,i,e,s,r,o);return this.scene.add.existing(n),n}Object.assign(p.prototype,l);const m=Phaser.Utils.Objects.GetAdvancedValue,v=Phaser.GameObjects.BuildGameObject;function b(t,i){void 0===t&&(t={}),void 0!==i&&(t.add=i);var e=m(t,"width",void 0),s=m(t,"height",e),r=m(t,"fillColor",void 0),o=m(t,"fillAlpha",void 0),n=new p(this.scene,0,0,e,s,r,o);return v(this.scene,n,t),n}var x=function(t){return null==t||""===t||0===t.length};class A extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexQuadShape",S,b)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,i,e,s){if(void 0===s&&(s="."),"object"==typeof t)if(x(i)){if(null==e)return;"object"==typeof e&&(t=e)}else{"string"==typeof i&&(i=i.split(s));var r=i.pop(),o=function(t,i,e){var s=t;if(x(i));else{var r;"string"==typeof i&&(i=i.split("."));for(var o=0,n=i.length;o<n;o++){var h;null!=s[r=i[o]]&&"object"==typeof s[r]||(h=o===n-1?void 0===e?{}:e:{},s[r]=h),s=s[r]}}return s}(t,i);o[r]=e}}(window,"RexPlugins.GameObjects.QuadShape",p),A},"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).rexquadshapeplugin=i();