phaser3-rex-plugins-fix-chun
Version:
2 lines (1 loc) • 9.26 kB
JavaScript
var t,e;t=void 0,e=function(){const t=Phaser.GameObjects.Mesh;class e extends t{get tint(){return 0===this.vertices.length?16777215:this.vertices[0].color}forceUpdate(){return this.dirtyCache[10]=1,this}}function r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var i={exports:{}};!function(t){var e;!function(){var r=1/1048576;function i(t,e,i,s){var n,a,h,o,u,c,l,g,d,f,v=t[e][0],p=t[e][1],m=t[i][0],y=t[i][1],x=t[s][0],P=t[s][1],w=Math.abs(p-y),R=Math.abs(y-P);if(w<r&&R<r)throw new Error("Eek! Coincident points!");return w<r?a=(o=-(x-m)/(P-y))*((n=(m+v)/2)-(c=(m+x)/2))+(g=(y+P)/2):R<r?a=(h=-(m-v)/(y-p))*((n=(x+m)/2)-(u=(v+m)/2))+(l=(p+y)/2):(n=((h=-(m-v)/(y-p))*(u=(v+m)/2)-(o=-(x-m)/(P-y))*(c=(m+x)/2)+(g=(y+P)/2)-(l=(p+y)/2))/(h-o),a=w>R?h*(n-u)+l:o*(n-c)+g),{i:e,j:i,k:s,x:n,y:a,r:(d=m-n)*d+(f=y-a)*f}}function s(t){var e,r,i,s,n,a;for(r=t.length;r;)for(s=t[--r],i=t[--r],e=r;e;)if(a=t[--e],i===(n=t[--e])&&s===a||i===a&&s===n){t.splice(r,2),t.splice(e,2);break}}e={triangulate:function(t,e){var n,a,h,o,u,c,l,g,d,f,v,p,m=t.length;if(m<3)return[];if(t=t.slice(0),e)for(n=m;n--;)t[n]=t[n][e];for(h=new Array(m),n=m;n--;)h[n]=n;for(h.sort((function(e,r){return t[r][0]-t[e][0]})),o=function(t){var e,r,i,s,n,a,h=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;for(e=t.length;e--;)t[e][0]<h&&(h=t[e][0]),t[e][0]>u&&(u=t[e][0]),t[e][1]<o&&(o=t[e][1]),t[e][1]>c&&(c=t[e][1]);return i=c-o,[[(n=h+.5*(r=u-h))-20*(s=Math.max(r,i)),(a=o+.5*i)-s],[n,a+20*s],[n+20*s,a-s]]}(t),t.push(o[0],o[1],o[2]),u=[i(t,m+0,m+1,m+2)],c=[],l=[],n=h.length;n--;l.length=0){for(p=h[n],a=u.length;a--;)(g=t[p][0]-u[a].x)>0&&g*g>u[a].r?(c.push(u[a]),u.splice(a,1)):g*g+(d=t[p][1]-u[a].y)*d-u[a].r>r||(l.push(u[a].i,u[a].j,u[a].j,u[a].k,u[a].k,u[a].i),u.splice(a,1));for(s(l),a=l.length;a;)v=l[--a],f=l[--a],u.push(i(t,f,v,p))}for(n=u.length;n--;)c.push(u[n]);for(u.length=0,n=c.length;n--;)c[n].i<m&&c[n].j<m&&c[n].k<m&&u.push(c[n].i,c[n].j,c[n].k);return u},contains:function(t,e){if(e[0]<t[0][0]&&e[0]<t[1][0]&&e[0]<t[2][0]||e[0]>t[0][0]&&e[0]>t[1][0]&&e[0]>t[2][0]||e[1]<t[0][1]&&e[1]<t[1][1]&&e[1]<t[2][1]||e[1]>t[0][1]&&e[1]>t[1][1]&&e[1]>t[2][1])return null;var r=t[1][0]-t[0][0],i=t[2][0]-t[0][0],s=t[1][1]-t[0][1],n=t[2][1]-t[0][1],a=r*n-i*s;if(0===a)return null;var h=(n*(e[0]-t[0][0])-i*(e[1]-t[0][1]))/a,o=(r*(e[1]-t[0][1])-s*(e[0]-t[0][0]))/a;return h<0||o<0||h+o>1?null:[h,o]}},t.exports=e}()}(i);var s=r(i.exports);const n=Phaser.Geom.Triangle;var a=function(t,e){void 0===e&&(e=!0);var r=s.triangulate(t);if(e){for(var i=[],a=0,h=r.length;a<h;a+=3){var o=t[r[a+0]],u=t[r[a+1]],c=t[r[a+2]],l=new n(o[0],o[1],u[0],u[1],c[0],c[1]);i.push(l)}return i}return{vertices:t,indices:r}};const h=Phaser.Utils.Objects.GetValue,o=Phaser.Math.Clamp,u=[1/27,3/27,9/27];var c=function(t,e,r,i,s,n,a,h,o,u,c,l){var d=[];d.push([t,e]);for(var f=Math.min(r,i),v=0,p=s.length;v<p;v++)g(d,t,e,f*s[v],n,a,h,o,u,c,l);return f=2*Math.max(r,i),g(d,t,e,f,n,a,h,o,u,c,l),d};const l=2*Math.PI;var g=function(t,e,r,i,s,n,a,h,u,c,g){for(var f=0;f<s;f++){var v=f/s*l,p=e+Math.cos(v)*i*d(n,a),m=r+Math.sin(v)*i*d(n,a);p=o(p,h,u),m=o(m,c,g),t.push([p,m])}return t},d=function(t,e){return t===e?t:t+(e-t)*Math.random()};const f=Phaser.Geom.Mesh.Face,v=Phaser.Math.DegToRad,p=Phaser.Math.RadToDeg,m=Phaser.Geom.Mesh.RotateFace;class y extends f{constructor(t,e,r){super(t,e,r),this._rotation=0}get rotation(){return this._rotation}set rotation(t){m(this,t-this._rotation),this._rotation=t}setRotation(t){return this.rotation=t,this}get angle(){return p(this.rotation)}set angle(t){this.rotation=v(t)}setAngle(t){return this.angle=t,this}setAlpha(t){return this.alpha=t,this}get tint(){var t=this.vertex1.color,e=this.vertex2.color,r=this.vertex3.color;return(((255&t)+(255&e)+(255&r))/3|0)+(((t>>8&255)+(e>>8&255)+(r>>8&255))/3<<8)+(((t>>16&255)+(e>>16&255)+(r>>16&255))/3<<16)}set tint(t){this.vertex1.color=t,this.vertex2.color=t,this.vertex3.color=t}setTint(t){return this.tint=t,this}}const x=Phaser.Math.RotateAround;var P={x:0,y:0};const w=Phaser.Utils.Objects.IsPlainObject,R=Phaser.Utils.Objects.GetValue,b=Phaser.Geom.Mesh.GenerateGridVerts,O=Phaser.Geom.Mesh.Vertex,j=Phaser.Math.Distance.Squared,I=[1/27,3/27,9/27];class G extends e{constructor(t,e,r,i,s,n){w(e)&&(e=R(n=e,"x",0),r=R(n,"y",0),i=R(n,"key",null),s=R(n,"frame",null)),super(t,e,r,i,s),this.type="rexShatterImage",this.hideCCW=!1,this.resetImage(),this.shatterCenter={x:null,y:null},this.setRingRadiusList(R(n,"ringRadiusList",I)),this.setSamplesPerRing(R(n,"samplesPerRing",12)),this.setVariation(R(n,"variation",.25))}setRingRadiusList(t){return this.ringRadiusList=t,this}setSamplesPerRing(t){return this.samplesPerRing=t,this}setVariation(t){return this.variation=t,this}resetImage(){return this.setSizeToFrame(),this.clear(),this.dirtyCache[9]=-1,b({mesh:this,width:this.frame.cutWidth/this.height,height:this.frame.cutHeight/this.height}),this.setOrtho(this.width/this.height,1),this}shatter(t,e,r){if(w(t)&&(r=t,t=void 0,e=void 0),w(r)&&(r.hasOwnProperty("centerX")&&(t=r.centerX),r.hasOwnProperty("centerY")&&(e=r.centerY),r.hasOwnProperty("ringRadiusList")&&this.setRingRadiusList(r.ringRadiusList),r.hasOwnProperty("samplesPerRing")&&this.setSamplesPerRing(r.samplesPerRing),r.hasOwnProperty("variation")&&this.setVariation(r.variation)),void 0===t)t=this.width/2,e=this.height/2;else{var i=(n=t,l=e,g=(s=this).width/2,d=s.height/2,P.x=n-s.x,P.y=l-s.y,P.x/=s.scaleX,P.y/=s.scaleY,x(P,0,0,-s.rotation),P.x+=g,P.y+=d,P);t=i.x,e=i.y}var s,n,l,g,d;if(this.shatterCenter.x=t,this.shatterCenter.y=e,this.clear(),this.dirtyCache[9]=-1,0===this.width||0===this.height)return this;for(var f=function(t){var e,r,i,s,n,l,g=t.rectangle;g?(e=g.x,i=g.y,n=g.width,l=g.height):(e=0,i=0,n=t.width,l=t.height),r=e+n,s=i+l;var d,f,v=t.center;void 0===v?(d=(e+r)/2,f=(i+s)/2):(d=o(v.x,e,r),f=o(v.y,i,s));var p,m=h(t,"ringRadiusList",u),y=h(t,"samplesPerRing",12),x=h(t,"variation",.25),P=h(t,"triangleOutput",!0);(p=m)&&"function"==typeof p&&(m=m(n,l));for(var w=1-x,R=1+x,b=0;b<10;b++)try{var O=c(d,f,n,l,m,y,w,R,e,r,i,s);return a(O,P)}catch(t){}throw new Error("Generate triangles fail")}({width:this.width,height:this.height,center:this.shatterCenter,triangleOutput:!1,ringRadiusList:this.ringRadiusList,variation:this.variation,samplesPerRing:this.samplesPerRing}),v=f.vertices,p=f.indices,m=[],R=this.width,b=this.height,I=this.frame.cutWidth/b/2,G=this.frame.cutHeight/b/2,M=this.frame.u0,T=this.frame.u1,N=this.frame.v0,V=T-M,C=this.frame.v1-N,S=0,L=v.length;S<L;S++){var U=v[S],_=U[0],k=U[1];m.push({g:j(t,e,_,k),x:_/b-I,y:k/b-G,u:M+V*(_/R),v:N+C*(k/b)})}for(S=0,L=p.length;S<L;S+=3){var E=m[p[S+0]],A=m[p[S+1]],D=m[p[S+2]],F=new O(E.x,-E.y,0,E.u,E.v),Y=new O(A.x,-A.y,0,A.u,A.v),B=new O(D.x,-D.y,0,D.u,D.v),W=new y(F,Y,B);this.vertices.push(F,Y,B),this.faces.push(W),W.g=Math.min(E.g,A.g,D.g)}return this.faces.sort((function(t,e){return t.g-e.g})),this}startUpdate(){return this.ignoreDirtyCache=!0,this}stopUpdate(){return this.ignoreDirtyCache=!1,this}}function M(t,e,r,i,s){var n=new G(this.scene,t,e,r,i,s);return this.scene.add.existing(n),n}const T=Phaser.Utils.Objects.GetAdvancedValue,N=Phaser.GameObjects.BuildGameObject;function V(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var r=T(t,"key",null),i=T(t,"frame",null),s=new G(this.scene,0,0,r,i,t);return N(this.scene,s,t),s}const C=Phaser.Textures.DynamicTexture,S=Phaser.Utils.Objects.IsPlainObject,L=Phaser.Utils.Objects.GetValue;class U extends G{constructor(t,e,r,i,s,n){S(e)&&(e=L(n=e,"x",0),r=L(n,"y",0),i=L(n,"width",32),s=L(n,"height",32));var a=function(t,e,r){return void 0===e&&(e=2),void 0===r&&(r=2),new C(t.sys.textures,null,e,r)}(t,i,s);super(t,e,r,a,null,n),this.type="rexShatterRenderTexture",this.rt=this.texture}destroy(t){this.scene&&!this.ignoreDestroy&&(super.destroy(t),this.rt.destroy(),this.rt=null)}}function _(t,e,r,i,s){var n=new U(this.scene,t,e,r,i,s);return this.scene.add.existing(n),n}const k=Phaser.Utils.Objects.GetAdvancedValue,E=Phaser.GameObjects.BuildGameObject;function A(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var r=k(t,"width",32),i=k(t,"height",32),s=new U(this.scene,0,0,r,i,t);return E(this.scene,s,t),s}var D=function(t){return null==t||""===t||0===t.length},F=function(t,e,r,i){if(void 0===i&&(i="."),"object"==typeof t){if(D(e)){if(null==r)return;"object"==typeof r&&(t=r)}else{"string"==typeof e&&(e=e.split(i));var s=e.pop(),n=function(t,e,r){var i=t;if(D(e));else{var s;"string"==typeof e&&(e=e.split("."));for(var n=0,a=e.length;n<a;n++){var h;null!=i[s=e[n]]&&"object"==typeof i[s]||(h=n===a-1?void 0===r?{}:r:{},i[s]=h),i=i[s]}}return i}(t,e);n[s]=r}return t}};class Y extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexShatterImage",M,V),t.registerGameObject("rexShatterRenderTexture",_,A)}start(){this.game.events.on("destroy",this.destroy,this)}}return F(window,"RexPlugins.GameObjects.ShatterImage",G),F(window,"RexPlugins.GameObjects.ShatterRenderTexture",U),Y},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexshatterimageplugin=e();