UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 24.8 kB
var t,e;t=void 0,e=function(){const t=Phaser.GameObjects.GameObject;let e=class extends t{};const r=Phaser.GameObjects.Components;Phaser.Class.mixin(e,[r.AlphaSingle,r.BlendMode,r.Depth,r.Flip,r.Mask,r.Origin,r.RenderNodes,r.Size,r.Texture,r.Transform,r.Visible,r.ScrollFactor]);const s=Phaser.GameObjects.GetCalcMatrix;var i={multiTexturing:!1,smoothPixelArt:!1},a={renderWebGL:function(t,e,r,a){var n=r.camera;if(n.addToRenderList(e),!e.skipRender()){var h,o=s(e,n,a,!r.useCanvas).calc;e.dirty&&e.updateBuffers();var l=e.texture;h=l&&null!==l.smoothPixelArt?l.smoothPixelArt:e.scene.sys.game.config.smoothPixelArt,i.smoothPixelArt=h,(e.customRenderNodes.BatchHandler||e.defaultRenderNodes.BatchHandler).batchTriangles(r,e,o,e.texture.source[0].glTexture,e.vertexBuffer,e.uvBuffer,e.colorBuffer,e.alphaBuffer,e.alpha,e.tintFill,i,e.debugCallback)}},renderCanvas:function(t,e,r,s){},skipRender:function(){return 0===this.faces.length}};const n=Phaser.Math.RotateAround;var h=function(t,e,r,s){void 0===s?s={}:!0===s&&(s=o);var i=t.displayOriginX,a=t.displayOriginY;return s.x=e-t.x,s.y=r-t.y,s.x/=t.scaleX,s.y/=t.scaleY,n(s,0,0,-t.rotation),s.x+=i,s.y+=a,s},o={};const l=Phaser.Math.Linear,c=Phaser.Math.RotateAround;class u{constructor(){this.parent=void 0,this.name="",this.u=0,this.v=0,this.frameU=0,this.frameV=0,this.frameX=0,this.frameY=0,this._dx=0,this._dy=0,this.localX=0,this.localY=0,this.alpha=1,this.color=16777215}setParent(t){return this.parent=t,this}setName(t){return this.name=t,this}get frameU(){return this._frameU}set frameU(t){this._frameU!==t&&(this._frameU=t,this.parent&&this.parent.setUVDirtyFlag())}get frameV(){return this._frameV}set frameV(t){this._frameV!==t&&(this._frameV=t,this.parent&&this.parent.setUVDirtyFlag())}get frameX(){return this._frameX}set frameX(t){this._frameX!==t&&(this._frameX=t,this._localX=t+this._dx,this.parent&&this.parent.setVertexDirtyFlag())}get frameY(){return this._frameY}set frameY(t){this._frameY!==t&&(this._frameY=t,this._localY=t+this._dy,this.parent&&this.parent.setVertexDirtyFlag())}get localX(){return this._localX}set localX(t){this._localX!==t&&(this._localX=t,this._dx=t-this._frameX,this.parent&&this.parent.setVertexDirtyFlag())}get localY(){return this._localY}set localY(t){this._localY!==t&&(this._localY=t,this._dy=t-this._frameY,this.parent&&this.parent.setVertexDirtyFlag())}get alpha(){return this._alpha}set alpha(t){this._alpha!==t&&(this._alpha=t,this.parent&&this.parent.setAlphaDirtyFlag())}get color(){return this._color}set color(t){this._color!==t&&(this._color=t,this.parent&&this.parent.setColorDirtyFlag())}setUV(t,e){return this.u=t,this.v=e,this}setFrameUV(t,e,r,s){return this.frameU=l(t,r,this.u),this.frameV=l(e,s,this.v),this}setFrameSize(t,e){return this.frameX=this.u*t,this.frameY=this.v*e,this}resetPosition(){return this.localX=this.frameX,this.localY=this.frameY,this}setLocalPosition(t,e){return this.localX=t,this.localY=e,this}rotateAround(t,e,r){return f.x=this.localX,f.y=this.localY,c(f,t,e,r),this.localX=f.x,this.localY=f.y,this}setAlpha(t){return this.alpha=t,this}setColor(t){return this.color=t,this}getWorldXY(t){return this.parent?function(t,e,r,s){void 0===s?s={}:!0===s&&(s=o);var i=t.displayOriginX,a=t.displayOriginY;return s.x=e-i,s.y=r-a,n(s,0,0,t.rotation),s.x*=t.scaleX,s.y*=t.scaleY,s.x+=t.x,s.y+=t.y,s}(this.parent,this.localX,this.localY,t):null}setWorldXY(t,e){var r=h(this.parent,t,e,!0);return this.setLocalPosition(r.x,r.y),this}setPosition(t,e){return this.setWorldXY(t,e),this}get x(){return this.parent?this.getWorldXY(!0).x:null}set x(t){this.setWorldXY(t,this.y)}get y(){return this.parent?this.getWorldXY(!0).y:null}set y(t){this.setWorldXY(this.x,t)}}var f={};const d=Phaser.Geom.Triangle.InCenter;var v={},p={},g=new Phaser.Geom.Triangle;const m=Phaser.Math.RadToDeg,y=Phaser.Math.DegToRad;class x{constructor(t,e,r){void 0===t&&(t=new u),void 0===e&&(e=new u),void 0===r&&(r=new u),this.parent=void 0,this.name="",this.vertices=[t,e,r],this._localOffsetX=0,this._localOffsetY=0,this._rotation=0,this._alpha=1,this._color=16777215}setParent(t){return this.parent=t,this.vertices[0].setParent(t),this.vertices[1].setParent(t),this.vertices[2].setParent(t),this}setName(t){return this.name=t,this}get vertex0(){return this.vertices[0]}set vertex0(t){this.vertices[0]=t}get vertex1(){return this.vertices[1]}set vertex1(t){this.vertices[1]=t}get vertex2(){return this.vertices[2]}set vertex2(t){this.vertices[2]=t}get localOffsetX(){return this._localOffsetX}set localOffsetX(t){t!==this._localOffsetX&&(this._localOffsetX=t,this.updateVerticesPosition())}get localOffsetY(){return this._localOffsetY}set localOffsetY(t){t!==this._localOffsetY&&(this._localOffsetY=t,this.updateVerticesPosition())}get rotation(){return this._rotation}set rotation(t){if(t!==this._rotation){this._rotation=t;var e,r,s=(e=this,void 0===(r=!0)?r={}:!0===r&&(r=p),v.x1=e.vertices[0].localX,v.y1=e.vertices[0].localY,v.x2=e.vertices[1].localX,v.y2=e.vertices[1].localY,v.x3=e.vertices[2].localX,v.y3=e.vertices[2].localY,d(v,r)),i=s.x,a=s.y;this.vertices[0].rotateAround(i,a,t),this.vertices[1].rotateAround(i,a,t),this.vertices[2].rotateAround(i,a,t)}}get angle(){return m(this._rotation)}set angle(t){this.rotation=y(t)}get alpha(){return this._alpha}set alpha(t){this._alpha!==t&&(this._alpha=t,this.vertices[0].setAlpha(t),this.vertices[1].setAlpha(t),this.vertices[2].setAlpha(t))}get color(){return this._color}set color(t){this._color!==t&&(this._color=t,this.vertices[0].setColor(t),this.vertices[1].setColor(t),this.vertices[2].setColor(t))}get isPositionModified(){return 0!==this._localOffsetX||0!==this._localOffsetY||0!==this._rotation}setUV(t,e,r,s,i,a){return this.vertices[0].setUV(t,e),this.vertices[1].setUV(r,s),this.vertices[2].setUV(i,a),this}setFrameUV(t,e,r,s){return this.vertices[0].setFrameUV(t,e,r,s),this.vertices[1].setFrameUV(t,e,r,s),this.vertices[2].setFrameUV(t,e,r,s),this}setFrameSize(t,e){for(var r=0,s=this.vertices.length;r<s;r++)this.vertices[r].setFrameSize(t,e);return this.isPositionModified&&this.updateVerticesPosition(),this}setLocalOffset(t,e){return this.localOffsetX=t,this.localOffsetY=e,this}resetVerticesPosition(){for(var t=0,e=this.vertices.length;t<e;t++)this.vertices[t].resetPosition();return this.isPositionModified&&this.updateVerticesPosition(),this}updateVerticesPosition(){for(var t=this._localOffsetX,e=this._localOffsetY,r=this.vertices,s=0,i=r.length;s<i;s++){var a=r[s];a.setLocalPosition(a.frameX+t,a.frameY+e)}var n=this.rotation;return this._rotation=0,this.rotation=n,this}setRotation(t){return this.rotation=t,this}setAngle(t){return this.angle=t,this}setAlpha(t){return this.alpha=t,this}setColor(t){return this.color=t,this}contains(t,e){return r=t,s=e,i=this.vertices,a=i[0],n=i[1],h=i[2],g.setTo(a.localX,a.localY,n.localX,n.localY,h.localX,h.localY),g.contains(r,s);var r,s,i,a,n,h}}const F=Phaser.Utils.Array.GetFirst;var P={clear(){return this.faces.length=0,this.vertices.length=0,this.setFaceCountDirtyFlag(),this},createVertex(t,e){void 0===t&&(t=0),void 0===e&&(e=0);var r=new u;return r.setUV(t,e),r},createFace:(t,e,r)=>new x(t,e,r),addFace(t){if(this.faces.includes(t))return this;t.setParent(this),this.faces.push(t),this.setFaceCountDirtyFlag();var e=this.frame;t.setFrameSize(e.cutWidth,e.cutHeight).setFrameUV(e.u0,e.v0,e.u1,e.v1).resetVerticesPosition();var r=this.vertices;return t.vertices.forEach((function(t){r.includes(t)||r.push(t)})),this},addFaces(t){for(var e=0,r=t.length;e<r;e++)this.addFace(t[e]);return this},resetFaceSize(){for(var t=this.frame,e=t.realWidth,r=t.realHeight,s=this.faces,i=0,a=s.length;i<a;i++)s[i].setFrameSize(e,r);return this},addGridFaces(t,e,r){return function(t,e,r,s){if(function(t){if("object"!=typeof t||t.nodeType||t===t.window)return!1;try{if(t.constructor&&!{}.hasOwnProperty.call(t.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}return!0}(e)){var i=e;e=i.columns,r=i.rows,s=i.sharedVertexMode}void 0===e&&(e=1),void 0===r&&(r=1),void 0===s&&(s=!1);var a,n,h,o,l,c=[];if(s){a=[];for(var u=0;u<=r;u++)for(var f=0;f<=e;f++){var d=t.createVertex(f/e,u/r);a.push(d)}}for(u=0;u<r;u++)for(f=0;f<e;f++)if(s){var v=u*(e+1)+f,p=v+1,g=(u+1)*(e+1)+f,m=g+1,y=a[v],x=a[p],F=a[g],P=a[m];l=t.createFace(y,P,F),t.addFace(l),c.push(l),l=t.createFace(y,x,P),t.addFace(l),c.push(l)}else{var _=f/e,O=(f+1)/e,V=u/r,b=(u+1)/r;n=t.createVertex(_,V),h=t.createVertex(_,b),o=t.createVertex(O,b),l=t.createFace(n,h,o),t.addFace(l),c.push(l),n=t.createVertex(_,V),h=t.createVertex(O,b),o=t.createVertex(O,V),l=t.createFace(n,h,o),t.addFace(l),c.push(l)}s&&t.vertices.sort((function(t,e){return t.v===e.v?t.u-e.u:t.v-e.v}))}(this,t,e,r),this},getVertexByName(t){return F(this.vertices,"name",t)},getFaceByName(t){return F(this.faces,"name",t)},resetVerticesPosition(){for(var t=this.vertices,e=0,r=t.length;e<r;e++)t[e].resetPosition();return this}},_={clearDirtyFlag(){return this.dirtyFlags=0,this},setFaceCountDirtyFlag(){return this.dirtyFlags|=31,this},setUVDirtyFlag(){return this.dirtyFlags|=2,this},setVertexDirtyFlag(){return this.dirtyFlags|=4,this},setAlphaDirtyFlag(){return this.dirtyFlags|=8,this},setColorDirtyFlag(){return this.dirtyFlags|=16,this}},O={updateBuffers(){return this.dirty?(1&this.dirtyFlags&&this.resizeBuffers(),2&this.dirtyFlags&&this.updateUVBuffer(),4&this.dirtyFlags&&this.updateVertexBuffer(),8&this.dirtyFlags&&this.updateAlphaBuffer(),16&this.dirtyFlags&&this.updateColorBuffer(),this.clearDirtyFlag(),this):this},resizeBuffers(){var t=this.faces.length;return this.vertexBuffer=new Float32Array(6*t),this.uvBuffer=new Float32Array(6*t),this.colorBuffer=new Uint32Array(3*t),this.alphaBuffer=new Float32Array(3*t),this},updateUVBuffer(){for(var t,e,r=this.uvBuffer,s=this.faces,i=0,a=s.length;i<a;i++)e=s[i].vertices,r[t=6*i]=e[0].frameU,r[t+1]=e[0].frameV,r[t+2]=e[1].frameU,r[t+3]=e[1].frameV,r[t+4]=e[2].frameU,r[t+5]=e[2].frameV;return this},updateVertexBuffer(){for(var t,e,r=this.vertexBuffer,s=this.faces,i=0,a=s.length;i<a;i++)e=s[i].vertices,r[t=6*i]=e[0].localX,r[t+1]=e[0].localY,r[t+2]=e[1].localX,r[t+3]=e[1].localY,r[t+4]=e[2].localX,r[t+5]=e[2].localY;return this},updateAlphaBuffer(){for(var t,e,r=this.alphaBuffer,s=this.faces,i=0,a=s.length;i<a;i++)e=s[i].vertices,r[t=3*i]=e[0].alpha,r[t+1]=e[1].alpha,r[t+2]=e[2].alpha;return this},updateColorBuffer(){for(var t,e,r=this.colorBuffer,s=this.faces,i=0,a=s.length;i<a;i++)e=s[i].vertices,r[t=3*i]=e[0].color,r[t+1]=e[1].color,r[t+2]=e[2].color;return this}},V={setTintFill(t){return void 0===t&&(t=!1),this.tintFill=t,this},setTint(t){return this.tint=t,this},clearTint(){return this.setTint(16777215),this}},b={setDebug(t,e){return this.debugGraphic=t,this.debugCallback=t||e?e||this.renderDebugVerts:null,this},renderDebugVerts(t,e,r){for(var s=t.debugGraphic,i=0;i<e;i+=6){var a=r[i+0],n=r[i+1],h=r[i+2],o=r[i+3],l=r[i+4],c=r[i+5];s.lineBetween(a,n,h,o),s.lineBetween(h,o,l,c),s.lineBetween(l,c,a,n)}}};const Y=Phaser.GameObjects.Components.TransformMatrix,X=Phaser.Math.TransformXY;var R,w,A={},T={getFaceAt(t,e,r){for(var s=function(t,e,r,s,i){void 0===s&&(s=t.scene.cameras.main),void 0===i?i={}:!0===i&&(i=A);var a=s.scrollX,n=s.scrollY,h=e+a*t.scrollFactorX-a,o=r+n*t.scrollFactorY-n;return t.parentContainer?(void 0===R&&(R=new Y,w=new Y),t.getWorldTransformMatrix(R,w),R.applyInverse(h,o,i)):X(h,o,t.x,t.y,t.rotation,t.scaleX,t.scaleY,i),i.x+=t.displayOriginX,i.y+=t.displayOriginY,i}(this,t,e,r,!0),i=s.x,a=s.y,n=this.faces,h=0,o=n.length;h<o;h++){var l=n[h];if(l.contains(i,a))return l}return null},hasFaceAt(t,e,r){return!!this.getFaceAt(t,e,r)}},B=function(t,e,r,s){for(var i=s.faces,a=0,n=i.length;a<n;a++){var h=i[a];if(h.contains(e,r))return s.input.hitFace=h,!0}return s.input.hitFace=null,!1},U=function(t,e,r,s){var i=this.input.hitFace;this.emit("face.pointerdown",i,t,e,r,s)},C=function(t,e,r,s){var i=this.input.hitFace;this.emit("face.pointerup",i,t,e,r,s),this.input.hitFace=null},M=function(t,e,r,s){var i=this.input.hitFace,a=this.input.prevHitFace;i!==a?(a&&this.emit("face.pointerout",a,t,s),i&&this.emit("face.pointerover",i,t,s),this.input.prevHitFace=i):this.emit("face.pointermove",i,t,e,r,s)},j=function(t,e){var r=this.input.prevHitFace;r&&this.emit("face.pointerout",r,t,e),this.input.hitFace=null,this.input.prevHitFace=null},G={setFaceInteractive:function(t){if(!this.input)return void 0===t&&(t={}),t.hitArea={},t.hitAreaCallback=B,this.setInteractive(t).on("pointerdown",U,this).on("pointerup",C,this).on("pointermove",M,this).on("pointerover",M,this).on("pointerout",j,this),this}};Object.assign(G,P,_,O,V,b,T);const S=Phaser.Renderer.WebGL.Shaders.MultiFrag,I=Phaser.Renderer.WebGL.Shaders.MultiVert,D=Phaser.Renderer.WebGL.ShaderAdditionMakers,N=D.MakeApplyTint,L=D.MakeDefineTexCount,k=D.MakeGetTexCoordOut,W=D.MakeGetTexRes,E=D.MakeSmoothPixelArt,H=D.MakeGetTexture,z=Phaser.Renderer.WebGL.Utils,q=Phaser.Renderer.WebGL.RenderNodes.BatchHandlerQuad,Q=z.getTintAppendFloatAlpha;class J extends q{constructor(t,e){super(t,e),this.renderOptions.multiTexturing=!0}_generateElementIndices(t){for(var e=new ArrayBuffer(5*t*2),r=new Uint16Array(e),s=0,i=0;i<t;i++){var a=3*i;r[s++]=a,r[s++]=a,r[s++]=a+1,r[s++]=a+2,r[s++]=a+2}return e}batchTriangles(t,e,r,s,i,a,n,h,o,l,c,u){0===this.instanceCount&&this.manager.setCurrentBatchNode(this,t);var f=i.length/(2*this.verticesPerInstance);if(f>this.instancesPerBatch)throw new Error("rexBatchHandlerTriangle: Vertex count exceeds maximum per batch ("+this.maxVerticesPerBatch+")");this.instanceCount+f>this.instancesPerBatch&&this.run(t),this.updateRenderOptions(c),this._renderOptionsChanged&&(this.run(t),this.updateShaderConfig());var d,v=this.batchTextures(s),p=this.instanceCount*this.floatsPerInstance,g=this.vertexBufferLayout.buffer,m=g.viewF32,y=g.viewU32;u&&(d=[]);for(var x=r.a,F=r.b,P=r.c,_=r.d,O=r.e,V=r.f,b=-e.displayOriginX,Y=-e.displayOriginY,X=i.length,R=0;R<X;R+=6){for(var w=0;w<3;w++){var A=R+2*w,T=i[A],B=i[A+1],U=(T+=b)*x+(B+=Y)*P+O,C=T*F+B*_+V,M=R/2+w,j=Q(n[M],h[M]*o);m[p++]=U,m[p++]=C,m[p++]=a[A],m[p++]=a[A+1],m[p++]=v,m[p++]=l,y[p++]=j,d&&d.push(U,C)}this.instanceCount++,this.currentBatchEntry.count++}u&&u.call(e,e,X,d)}}J.prototype.defaultConfig={name:"rexBatchHandlerTriangle",verticesPerInstance:3,indicesPerInstance:5,shaderName:"REXTRI",vertexSource:I,fragmentSource:S,shaderAdditions:[k(),W(!0),E(!0),L(1),H(),N()],vertexBufferLayout:{usage:"DYNAMIC_DRAW",layout:[{name:"inPosition",size:2},{name:"inTexCoord",size:2},{name:"inTexDatum"},{name:"inTintEffect"},{name:"inTint",size:4,type:"UNSIGNED_BYTE",normalized:!0}]}};const K=Phaser.Game;var Z=function(t){return t instanceof K};const $=Phaser.Scene;var tt=function(t){return t instanceof $},et=function(t,e,r){var s,i=(s=t,null==s||"object"!=typeof s?null:Z(s)?s:Z(s.game)?s.game:tt(s)?s.sys.game:tt(s.scene)?s.scene.sys.game:void 0).renderer.renderNodes;i.hasNode(e,!0)||i.addNodeConstructor(e,r)};const rt=new Phaser.Structs.Map([["BatchHandler","rexBatchHandlerTriangles"]]);class st extends e{constructor(t,e,r,s,i){void 0===e&&(e=0),void 0===r&&(r=0),void 0===s&&(s="__DEFAULT"),super(t,"rexMeshImage"),this.dirtyFlags=0,this.vertices=[],this.faces=[],this.vertexBuffer=null,this.uvBuffer=null,this.alphaBuffer=null,this.colorBuffer=null,this.tintFill=!1,this.debugCallback=null,this.debugGraphic=null,this.setTexture(s,i),this.setPosition(e,r),this.setSizeToFrame(),this.setOriginFromFrame(),et(t,"rexBatchHandlerTriangles",J),this.initRenderNodes(this._defaultRenderNodesMap)}get _defaultRenderNodesMap(){return rt}get dirty(){return 0!==this.dirtyFlags}get frame(){return this._frame}set frame(t){if(this._frame!==t){this._frame=t;var e=this.faces;if(e){var r=t?t.u0:0,s=t?t.v0:0,i=t?t.u1:0,a=t?t.v1:0,n=t?t.cutWidth:0,h=t?t.cutHeight:0,o=this._frameWidthSave!==n||this._frameHeightSave!==h;this._frameWidthSave=n,this._frameHeightSave=h;for(var l=0,c=e.length;l<c;l++){var u=e[l];u.setFrameUV(r,s,i,a),o&&u.setFrameSize(n,h)}}}}get tint(){return this.faces.length>0?this.faces[0].color:16777215}set tint(t){for(var e=this.faces,r=0,s=e.length;r<s;r++)e[r].setColor(t)}addedToScene(){this.scene.sys.updateList.add(this)}removedFromScene(){this.scene.sys.updateList.remove(this)}}Object.assign(st.prototype,a,G);var it={play(t,e){return this.anims.play(t,e)},playReverse(t,e){return this.anims.playReverse(t,e)},playAfterDelay(t,e){return this.anims.playAfterDelay(t,e)},playAfterRepeat(t,e){return this.anims.playAfterRepeat(t,e)},chain(t){return this.anims.chain(t)},stop(){return this.anims.stop()},stopAfterDelay(t){return this.anims.stopAfterDelay(t)},stopAfterRepeat(t){return this.anims.stopAfterRepeat(t)},stopOnFrame(t){return this.anims.stopOnFrame(t)}},at={};Object.assign(at,it);const nt=Phaser.Animations.AnimationState;class ht extends st{constructor(t,e,r,s,i){super(t,e,r,s,i),this.type="rexMeshSprite",this.anims=new nt(this)}preUpdate(t,e){this.anims.update(t,e)}preDestroy(){this.anims.destroy(),this.anims=void 0}}Object.assign(ht.prototype,at);var ot={setRingRadiusList(t){return this.ringRadiusList=t,this},setSamplesPerRing(t){return this.samplesPerRing=t,this},setVariation(t){return this.variation=t,this}};function lt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ct={exports:{}};!function(t){var e;!function(){var r=1/1048576;function s(t,e,s,i){var a,n,h,o,l,c,u,f,d,v,p=t[e][0],g=t[e][1],m=t[s][0],y=t[s][1],x=t[i][0],F=t[i][1],P=Math.abs(g-y),_=Math.abs(y-F);if(P<r&&_<r)throw new Error("Eek! Coincident points!");return P<r?n=(o=-(x-m)/(F-y))*((a=(m+p)/2)-(c=(m+x)/2))+(f=(y+F)/2):_<r?n=(h=-(m-p)/(y-g))*((a=(x+m)/2)-(l=(p+m)/2))+(u=(g+y)/2):(a=((h=-(m-p)/(y-g))*(l=(p+m)/2)-(o=-(x-m)/(F-y))*(c=(m+x)/2)+(f=(y+F)/2)-(u=(g+y)/2))/(h-o),n=P>_?h*(a-l)+u:o*(a-c)+f),{i:e,j:s,k:i,x:a,y:n,r:(d=m-a)*d+(v=y-n)*v}}function i(t){var e,r,s,i,a,n;for(r=t.length;r;)for(i=t[--r],s=t[--r],e=r;e;)if(n=t[--e],s===(a=t[--e])&&i===n||s===n&&i===a){t.splice(r,2),t.splice(e,2);break}}e={triangulate:function(t,e){var a,n,h,o,l,c,u,f,d,v,p,g,m=t.length;if(m<3)return[];if(t=t.slice(0),e)for(a=m;a--;)t[a]=t[a][e];for(h=new Array(m),a=m;a--;)h[a]=a;for(h.sort((function(e,r){return t[r][0]-t[e][0]})),o=function(t){var e,r,s,i,a,n,h=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;for(e=t.length;e--;)t[e][0]<h&&(h=t[e][0]),t[e][0]>l&&(l=t[e][0]),t[e][1]<o&&(o=t[e][1]),t[e][1]>c&&(c=t[e][1]);return s=c-o,[[(a=h+.5*(r=l-h))-20*(i=Math.max(r,s)),(n=o+.5*s)-i],[a,n+20*i],[a+20*i,n-i]]}(t),t.push(o[0],o[1],o[2]),l=[s(t,m+0,m+1,m+2)],c=[],u=[],a=h.length;a--;u.length=0){for(g=h[a],n=l.length;n--;)(f=t[g][0]-l[n].x)>0&&f*f>l[n].r?(c.push(l[n]),l.splice(n,1)):f*f+(d=t[g][1]-l[n].y)*d-l[n].r>r||(u.push(l[n].i,l[n].j,l[n].j,l[n].k,l[n].k,l[n].i),l.splice(n,1));for(i(u),n=u.length;n;)p=u[--n],v=u[--n],l.push(s(t,v,p,g))}for(a=l.length;a--;)c.push(l[a]);for(l.length=0,a=c.length;a--;)c[a].i<m&&c[a].j<m&&c[a].k<m&&l.push(c[a].i,c[a].j,c[a].k);return l},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],s=t[2][0]-t[0][0],i=t[1][1]-t[0][1],a=t[2][1]-t[0][1],n=r*a-s*i;if(0===n)return null;var h=(a*(e[0]-t[0][0])-s*(e[1]-t[0][1]))/n,o=(r*(e[1]-t[0][1])-i*(e[0]-t[0][0]))/n;return h<0||o<0||h+o>1?null:[h,o]}},t.exports=e}()}(ct);var ut=lt(ct.exports);const ft=Phaser.Geom.Triangle;var dt=function(t,e){void 0===e&&(e=!0);var r=ut.triangulate(t);if(e){for(var s=[],i=0,a=r.length;i<a;i+=3){var n=t[r[i+0]],h=t[r[i+1]],o=t[r[i+2]],l=new ft(n[0],n[1],h[0],h[1],o[0],o[1]);s.push(l)}return s}return{vertices:t,indices:r}};const vt=Phaser.Utils.Objects.GetValue,pt=Phaser.Math.Clamp,gt=[1/27,3/27,9/27];var mt=function(t,e,r,s,i,a,n,h,o,l,c,u){var f=[];f.push([t,e]);for(var d=Math.min(r,s),v=0,p=i.length;v<p;v++)xt(f,t,e,d*i[v],a,n,h,o,l,c,u);return d=2*Math.max(r,s),xt(f,t,e,d,a,n,h,o,l,c,u),f};const yt=2*Math.PI;var xt=function(t,e,r,s,i,a,n,h,o,l,c){for(var u=0;u<i;u++){var f=u/i*yt,d=e+Math.cos(f)*s*Ft(a,n),v=r+Math.sin(f)*s*Ft(a,n);d=pt(d,h,o),v=pt(v,l,c),t.push([d,v])}return t},Ft=function(t,e){return t===e?t:t+(e-t)*Math.random()};const Pt=Phaser.Utils.Objects.IsPlainObject,_t=Phaser.Math.Distance.Squared;var Ot={resetImage:function(){return this.clear().addGridFaces(1,1),this},shatter:function(t,e,r){if(Pt(t)&&(r=t,t=void 0,e=void 0),Pt(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 s=h(this,t,e);t=s.x,e=s.y}if(this.shatterCenter.x=t,this.shatterCenter.y=e,this.clear(),0===this.width||0===this.height)return this;for(var i=function(t){var e,r,s,i,a,n,h=t.rectangle;h?(e=h.x,s=h.y,a=h.width,n=h.height):(e=0,s=0,a=t.width,n=t.height),r=e+a,i=s+n;var o,l,c=t.center;void 0===c?(o=(e+r)/2,l=(s+i)/2):(o=pt(c.x,e,r),l=pt(c.y,s,i));var u,f=vt(t,"ringRadiusList",gt),d=vt(t,"samplesPerRing",12),v=vt(t,"variation",.25),p=vt(t,"triangleOutput",!0);(u=f)&&"function"==typeof u&&(f=f(a,n));for(var g=1-v,m=1+v,y=0;y<10;y++)try{var x=mt(o,l,a,n,f,d,g,m,e,r,s,i);return dt(x,p)}catch(t){}throw new Error("Generate triangles fail")}({width:1,height:1,center:{x:t/=this.width,y:e/=this.height},triangleOutput:!1,ringRadiusList:this.ringRadiusList,variation:this.variation,samplesPerRing:this.samplesPerRing}),a=i.vertices,n=i.indices,o=[],l=0,c=a.length;l<c;l++){var u=a[l],f=u[0],d=u[1];o.push({g:_t(t,e,f,d),x:f,y:d})}for(l=0,c=n.length;l<c;l+=3){var v=o[n[l+0]],p=o[n[l+1]],g=o[n[l+2]],m=this.createVertex(v.x,v.y),y=this.createVertex(p.x,p.y),x=this.createVertex(g.x,g.y),F=this.createFace(m,y,x);this.addFace(F),F.g=Math.min(v.g,p.g,g.g)}return this.faces.sort((function(t,e){return t.g-e.g})),this}};Object.assign(Ot,ot);const Vt=Phaser.Utils.Objects.IsPlainObject,bt=Phaser.Utils.Objects.GetValue,Yt=[1/27,3/27,9/27];class Xt extends ht{constructor(t,e,r,s,i,a){Vt(e)&&(e=bt(a=e,"x",0),r=bt(a,"y",0),s=bt(a,"key",null),i=bt(a,"frame",null)),super(t,e,r,s,i),this.type="rexShatterImage",this.resetImage(),this.shatterCenter={x:null,y:null},this.setRingRadiusList(bt(a,"ringRadiusList",Yt)),this.setSamplesPerRing(bt(a,"samplesPerRing",12)),this.setVariation(bt(a,"variation",.25))}}function Rt(t,e,r,s,i){var a=new Xt(this.scene,t,e,r,s,i);return this.scene.add.existing(a),a}Object.assign(Xt.prototype,Ot);const wt=Phaser.Utils.Objects.GetAdvancedValue,At=Phaser.GameObjects.BuildGameObject;function Tt(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var r=wt(t,"key",null),s=wt(t,"frame",null),i=new Xt(this.scene,0,0,r,s,t);return At(this.scene,i,t),i}const Bt=Phaser.Textures.DynamicTexture,Ut=Phaser.Utils.Objects.IsPlainObject,Ct=Phaser.Utils.Objects.GetValue;class Mt extends Xt{constructor(t,e,r,s,i,a){Ut(e)&&(e=Ct(a=e,"x",0),r=Ct(a,"y",0),s=Ct(a,"width",32),i=Ct(a,"height",32));var n=function(t,e,r){return void 0===e&&(e=2),void 0===r&&(r=2),new Bt(t.sys.textures,null,e,r)}(t,s,i);super(t,e,r,n,null,a),this.type="rexShatterRenderTexture",this.rt=this.texture}destroy(t){this.scene&&!this.ignoreDestroy&&(super.destroy(t),this.rt.destroy(),this.rt=null)}}function jt(t,e,r,s,i){var a=new Mt(this.scene,t,e,r,s,i);return this.scene.add.existing(a),a}const Gt=Phaser.Utils.Objects.GetAdvancedValue,St=Phaser.GameObjects.BuildGameObject;function It(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var r=Gt(t,"width",32),s=Gt(t,"height",32),i=new Mt(this.scene,0,0,r,s,t);return St(this.scene,i,t),i}var Dt=function(t){return null==t||""===t||0===t.length},Nt=function(t,e,r,s){if(void 0===s&&(s="."),"object"==typeof t){if(Dt(e)){if(null==r)return;"object"==typeof r&&(t=r)}else{"string"==typeof e&&(e=e.split(s));var i=e.pop(),a=function(t,e,r){var s=t;if(Dt(e));else{var i;"string"==typeof e&&(e=e.split("."));for(var a=0,n=e.length;a<n;a++){var h;null!=s[i=e[a]]&&"object"==typeof s[i]||(h=a===n-1?void 0===r?{}:r:{},s[i]=h),s=s[i]}}return s}(t,e);a[i]=r}return t}};class Lt extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexShatterImage",Rt,Tt),t.registerGameObject("rexShatterRenderTexture",jt,It)}start(){this.game.events.on("destroy",this.destroy,this)}}return Nt(window,"RexPlugins.GameObjects.ShatterImage",Xt),Nt(window,"RexPlugins.GameObjects.ShatterRenderTexture",Mt),Lt},"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();