UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 23.3 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={};const o=Phaser.Math.Linear,l=Phaser.Math.RotateAround;class c{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=o(t,r,this.u),this.frameV=o(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 u.x=this.localX,u.y=this.localY,l(u,t,e,r),this.localX=u.x,this.localY=u.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=h);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=function(t,e,r,s){void 0===s?s={}:!0===s&&(s=h);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}(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 u={};const f=Phaser.Geom.Triangle.InCenter;var d={},v={},p=new Phaser.Geom.Triangle;const g=Phaser.Math.RadToDeg,m=Phaser.Math.DegToRad;class y{constructor(t,e,r){void 0===t&&(t=new c),void 0===e&&(e=new c),void 0===r&&(r=new c),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=v),d.x1=e.vertices[0].localX,d.y1=e.vertices[0].localY,d.x2=e.vertices[1].localX,d.y2=e.vertices[1].localY,d.x3=e.vertices[2].localX,d.y3=e.vertices[2].localY,f(d,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 g(this._rotation)}set angle(t){this.rotation=m(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],p.setTo(a.localX,a.localY,n.localX,n.localY,h.localX,h.localY),p.contains(r,s);var r,s,i,a,n,h}}const x=Phaser.Utils.Array.GetFirst;var F={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 c;return r.setUV(t,e),r},createFace:(t,e,r)=>new y(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,b=u/r,V=(u+1)/r;n=t.createVertex(_,b),h=t.createVertex(_,V),o=t.createVertex(O,V),l=t.createFace(n,h,o),t.addFace(l),c.push(l),n=t.createVertex(_,b),h=t.createVertex(O,V),o=t.createVertex(O,b),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 x(this.vertices,"name",t)},getFaceByName(t){return x(this.faces,"name",t)},resetVerticesPosition(){for(var t=this.vertices,e=0,r=t.length;e<r;e++)t[e].resetPosition();return this}},P={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}},_={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}},O={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 V=Phaser.GameObjects.Components.TransformMatrix,T=Phaser.Math.TransformXY;var Y,A,X={},B={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=X);var a=s.scrollX,n=s.scrollY,h=e+a*t.scrollFactorX-a,o=r+n*t.scrollFactorY-n;return t.parentContainer?(void 0===Y&&(Y=new V,A=new V),t.getWorldTransformMatrix(Y,A),Y.applyInverse(h,o,i)):T(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)}},w=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},C=function(t,e,r,s){var i=this.input.hitFace;this.emit("face.pointerdown",i,t,e,r,s)},U=function(t,e,r,s){var i=this.input.hitFace;this.emit("face.pointerup",i,t,e,r,s),this.input.hitFace=null},D=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)},G=function(t,e){var r=this.input.prevHitFace;r&&this.emit("face.pointerout",r,t,e),this.input.hitFace=null,this.input.prevHitFace=null},j={setFaceInteractive:function(t){if(!this.input)return void 0===t&&(t={}),t.hitArea={},t.hitAreaCallback=w,this.setInteractive(t).on("pointerdown",C,this).on("pointerup",U,this).on("pointermove",D,this).on("pointerover",D,this).on("pointerout",G,this),this}};Object.assign(j,F,P,_,O,b,B);const I=Phaser.Renderer.WebGL.Shaders.MultiFrag,R=Phaser.Renderer.WebGL.Shaders.MultiVert,M=Phaser.Renderer.WebGL.ShaderAdditionMakers,N=M.MakeApplyTint,S=M.MakeDefineTexCount,k=M.MakeGetTexCoordOut,W=M.MakeGetTexRes,E=M.MakeSmoothPixelArt,H=M.MakeGetTexture,L=Phaser.Renderer.WebGL.Utils,z=Phaser.Renderer.WebGL.RenderNodes.BatchHandlerQuad,Q=L.getTintAppendFloatAlpha;class q extends z{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,b=r.f,V=-e.displayOriginX,T=-e.displayOriginY,Y=i.length,A=0;A<Y;A+=6){for(var X=0;X<3;X++){var B=A+2*X,w=i[B],C=i[B+1],U=(w+=V)*x+(C+=T)*P+O,D=w*F+C*_+b,G=A/2+X,j=Q(n[G],h[G]*o);m[p++]=U,m[p++]=D,m[p++]=a[B],m[p++]=a[B+1],m[p++]=v,m[p++]=l,y[p++]=j,d&&d.push(U,D)}this.instanceCount++,this.currentBatchEntry.count++}u&&u.call(e,e,Y,d)}}q.prototype.defaultConfig={name:"rexBatchHandlerTriangle",verticesPerInstance:3,indicesPerInstance:5,shaderName:"REXTRI",vertexSource:R,fragmentSource:I,shaderAdditions:[k(),W(!0),E(!0),S(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 J=Phaser.Game;var K=function(t){return t instanceof J};const Z=Phaser.Scene;var $=function(t){return t instanceof Z},tt=function(t,e,r){var s,i=(s=t,null==s||"object"!=typeof s?null:K(s)?s:K(s.game)?s.game:$(s)?s.sys.game:$(s.scene)?s.scene.sys.game:void 0).renderer.renderNodes;i.hasNode(e,!0)||i.addNodeConstructor(e,r)};const et=new Phaser.Structs.Map([["BatchHandler","rexBatchHandlerTriangles"]]);class rt 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(),tt(t,"rexBatchHandlerTriangles",q),this.initRenderNodes(this._defaultRenderNodesMap)}get _defaultRenderNodesMap(){return et}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(rt.prototype,a,j);var st={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)}},it={};Object.assign(it,st);const at=Phaser.Animations.AnimationState;class nt extends rt{constructor(t,e,r,s,i){super(t,e,r,s,i),this.type="rexMeshSprite",this.anims=new at(this)}preUpdate(t,e){this.anims.update(t,e)}preDestroy(){this.anims.destroy(),this.anims=void 0}}Object.assign(nt.prototype,it);var ht={setTriangleCount(t){return this.triangleCount=t,this}};function ot(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var lt={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}()}(lt);var ct=ot(lt.exports);const ut=Phaser.Geom.Triangle,ft=Phaser.Utils.Objects.GetValue,dt=Phaser.Geom.Rectangle;var vt=function(t){var e=t.rectangle;e||(e=new dt(0,0,t.width,t.height));var r=ft(t,"amount",10),s=ft(t,"triangleOutput",!0),i=Math.ceil(r/2)+3,a=Phaser.Geom.Rectangle.Decompose(e),n=e.width,h=e.height;pt.setTo(e.x+.05*n,e.y+.05*h,.9*n,.9*h);for(var o=0,l=i-a.length;o<l;o++)a.push(pt.getRandomPoint());var c=[];for(o=0,l=a.length;o<l;o++){var u=a[o];c.push([u.x,u.y])}return function(t,e){void 0===e&&(e=!0);var r=ct.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 ut(n[0],n[1],h[0],h[1],o[0],o[1]);s.push(l)}return s}return{vertices:t,indices:r}}(c,s)},pt=new dt;const gt=Phaser.Utils.Objects.IsPlainObject;var mt={resetImage:function(){return this.clear().addGridFaces(1,1),this},reTriangulate:function(t){if(gt(t)&&t.hasOwnProperty("triangleCount")&&this.setTriangleCount(t.triangleCount),this.clear(),0===this.width||0===this.height)return this;for(var e=vt({width:1,height:1,amount:this.triangleCount,triangleOutput:!1}),r=e.vertices,s=e.indices,i=0,a=s.length;i<a;i+=3){var n=r[s[i+0]],h=r[s[i+1]],o=r[s[i+2]],l=this.createVertex(n[0],n[1]),c=this.createVertex(h[0],h[1]),u=this.createVertex(o[0],o[1]),f=this.createFace(l,c,u);this.addFace(f)}return this}};Object.assign(mt,ht);const yt=Phaser.Utils.Objects.IsPlainObject,xt=Phaser.Utils.Objects.GetValue;class Ft extends nt{constructor(t,e,r,s,i,a){yt(e)&&(e=xt(a=e,"x",0),r=xt(a,"y",0),s=xt(a,"key",null),i=xt(a,"frame",null)),super(t,e,r,s,i),this.type="rexDelaunayImage",this.resetImage(),this.setTriangleCount(xt(a,"triangleCount",8))}}function Pt(t,e,r,s,i){var a=new Ft(this.scene,t,e,r,s,i);return this.scene.add.existing(a),a}Object.assign(Ft.prototype,mt);const _t=Phaser.Utils.Objects.GetAdvancedValue,Ot=Phaser.GameObjects.BuildGameObject;function bt(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var r=_t(t,"key",null),s=_t(t,"frame",null),i=new Ft(this.scene,0,0,r,s,t);return Ot(this.scene,i,t),i}const Vt=Phaser.Textures.DynamicTexture,Tt=Phaser.Utils.Objects.IsPlainObject,Yt=Phaser.Utils.Objects.GetValue;class At extends Ft{constructor(t,e,r,s,i,a){Tt(e)&&(e=Yt(a=e,"x",0),r=Yt(a,"y",0),s=Yt(a,"width",32),i=Yt(a,"height",32));var n=function(t,e,r){return void 0===e&&(e=2),void 0===r&&(r=2),new Vt(t.sys.textures,null,e,r)}(t,s,i);super(t,e,r,n,null,a),this.type="rexDelaunayRenderTexture",this.rt=this.texture}destroy(t){this.scene&&!this.ignoreDestroy&&(super.destroy(t),this.rt.destroy(),this.rt=null)}}function Xt(t,e,r,s,i){var a=new At(this.scene,t,e,r,s,i);return this.scene.add.existing(a),a}const Bt=Phaser.Utils.Objects.GetAdvancedValue,wt=Phaser.GameObjects.BuildGameObject;function Ct(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var r=Bt(t,"width",32),s=Bt(t,"height",32),i=new At(this.scene,0,0,r,s,t);return wt(this.scene,i,t),i}var Ut=function(t){return null==t||""===t||0===t.length},Dt=function(t,e,r,s){if(void 0===s&&(s="."),"object"==typeof t){if(Ut(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(Ut(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 Gt extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexDelaunayImage",Pt,bt),t.registerGameObject("rexDelaunayRenderTexture",Xt,Ct)}start(){this.game.events.on("destroy",this.destroy,this)}}return Dt(window,"RexPlugins.GameObjects.DelaunayImage",Ft),Dt(window,"RexPlugins.GameObjects.DelaunayRenderTexture",At),Gt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexdelaunayimageplugin=e();