phaser4-rex-plugins
Version:
2 lines (1 loc) • 28.3 kB
JavaScript
var e,t;e=void 0,t=function(){const e=Phaser.GameObjects.GameObject;let t=class extends e{};const r=Phaser.GameObjects.Components;Phaser.Class.mixin(t,[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(e,t,r,a){var n=r.camera;if(n.addToRenderList(t),!t.skipRender()){var o,h=s(t,n,a,!r.useCanvas).calc;t.dirty&&t.updateBuffers();var l=t.texture;o=l&&null!==l.smoothPixelArt?l.smoothPixelArt:t.scene.sys.game.config.smoothPixelArt,i.smoothPixelArt=o,(t.customRenderNodes.BatchHandler||t.defaultRenderNodes.BatchHandler).batchTriangles(r,t,h,t.texture.source[0].glTexture,t.vertexBuffer,t.uvBuffer,t.colorBuffer,t.alphaBuffer,t.alpha,t.tintFill,i,t.debugCallback)}},renderCanvas:function(e,t,r,s){},skipRender:function(){return 0===this.faces.length}};const n=Phaser.Math.RotateAround;var o={};const h=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(e){return this.parent=e,this}setName(e){return this.name=e,this}get frameU(){return this._frameU}set frameU(e){this._frameU!==e&&(this._frameU=e,this.parent&&this.parent.setUVDirtyFlag())}get frameV(){return this._frameV}set frameV(e){this._frameV!==e&&(this._frameV=e,this.parent&&this.parent.setUVDirtyFlag())}get frameX(){return this._frameX}set frameX(e){this._frameX!==e&&(this._frameX=e,this._localX=e+this._dx,this.parent&&this.parent.setVertexDirtyFlag())}get frameY(){return this._frameY}set frameY(e){this._frameY!==e&&(this._frameY=e,this._localY=e+this._dy,this.parent&&this.parent.setVertexDirtyFlag())}get localX(){return this._localX}set localX(e){this._localX!==e&&(this._localX=e,this._dx=e-this._frameX,this.parent&&this.parent.setVertexDirtyFlag())}get localY(){return this._localY}set localY(e){this._localY!==e&&(this._localY=e,this._dy=e-this._frameY,this.parent&&this.parent.setVertexDirtyFlag())}get alpha(){return this._alpha}set alpha(e){this._alpha!==e&&(this._alpha=e,this.parent&&this.parent.setAlphaDirtyFlag())}get color(){return this._color}set color(e){this._color!==e&&(this._color=e,this.parent&&this.parent.setColorDirtyFlag())}setUV(e,t){return this.u=e,this.v=t,this}setFrameUV(e,t,r,s){return this.frameU=h(e,r,this.u),this.frameV=h(t,s,this.v),this}setFrameSize(e,t){return this.frameX=this.u*e,this.frameY=this.v*t,this}resetPosition(){return this.localX=this.frameX,this.localY=this.frameY,this}setLocalPosition(e,t){return this.localX=e,this.localY=t,this}rotateAround(e,t,r){return u.x=this.localX,u.y=this.localY,l(u,e,t,r),this.localX=u.x,this.localY=u.y,this}setAlpha(e){return this.alpha=e,this}setColor(e){return this.color=e,this}getWorldXY(e){return this.parent?function(e,t,r,s){void 0===s?s={}:!0===s&&(s=o);var i=e.displayOriginX,a=e.displayOriginY;return s.x=t-i,s.y=r-a,n(s,0,0,e.rotation),s.x*=e.scaleX,s.y*=e.scaleY,s.x+=e.x,s.y+=e.y,s}(this.parent,this.localX,this.localY,e):null}setWorldXY(e,t){var r=function(e,t,r,s){void 0===s?s={}:!0===s&&(s=o);var i=e.displayOriginX,a=e.displayOriginY;return s.x=t-e.x,s.y=r-e.y,s.x/=e.scaleX,s.y/=e.scaleY,n(s,0,0,-e.rotation),s.x+=i,s.y+=a,s}(this.parent,e,t,!0);return this.setLocalPosition(r.x,r.y),this}setPosition(e,t){return this.setWorldXY(e,t),this}get x(){return this.parent?this.getWorldXY(!0).x:null}set x(e){this.setWorldXY(e,this.y)}get y(){return this.parent?this.getWorldXY(!0).y:null}set y(e){this.setWorldXY(this.x,e)}}var u={};const d=Phaser.Geom.Triangle.InCenter;var f={},v={},g=new Phaser.Geom.Triangle;const p=Phaser.Math.RadToDeg,m=Phaser.Math.DegToRad;class y{constructor(e,t,r){void 0===e&&(e=new c),void 0===t&&(t=new c),void 0===r&&(r=new c),this.parent=void 0,this.name="",this.vertices=[e,t,r],this._localOffsetX=0,this._localOffsetY=0,this._rotation=0,this._alpha=1,this._color=16777215}setParent(e){return this.parent=e,this.vertices[0].setParent(e),this.vertices[1].setParent(e),this.vertices[2].setParent(e),this}setName(e){return this.name=e,this}get vertex0(){return this.vertices[0]}set vertex0(e){this.vertices[0]=e}get vertex1(){return this.vertices[1]}set vertex1(e){this.vertices[1]=e}get vertex2(){return this.vertices[2]}set vertex2(e){this.vertices[2]=e}get localOffsetX(){return this._localOffsetX}set localOffsetX(e){e!==this._localOffsetX&&(this._localOffsetX=e,this.updateVerticesPosition())}get localOffsetY(){return this._localOffsetY}set localOffsetY(e){e!==this._localOffsetY&&(this._localOffsetY=e,this.updateVerticesPosition())}get rotation(){return this._rotation}set rotation(e){if(e!==this._rotation){this._rotation=e;var t,r,s=(t=this,void 0===(r=!0)?r={}:!0===r&&(r=v),f.x1=t.vertices[0].localX,f.y1=t.vertices[0].localY,f.x2=t.vertices[1].localX,f.y2=t.vertices[1].localY,f.x3=t.vertices[2].localX,f.y3=t.vertices[2].localY,d(f,r)),i=s.x,a=s.y;this.vertices[0].rotateAround(i,a,e),this.vertices[1].rotateAround(i,a,e),this.vertices[2].rotateAround(i,a,e)}}get angle(){return p(this._rotation)}set angle(e){this.rotation=m(e)}get alpha(){return this._alpha}set alpha(e){this._alpha!==e&&(this._alpha=e,this.vertices[0].setAlpha(e),this.vertices[1].setAlpha(e),this.vertices[2].setAlpha(e))}get color(){return this._color}set color(e){this._color!==e&&(this._color=e,this.vertices[0].setColor(e),this.vertices[1].setColor(e),this.vertices[2].setColor(e))}get isPositionModified(){return 0!==this._localOffsetX||0!==this._localOffsetY||0!==this._rotation}setUV(e,t,r,s,i,a){return this.vertices[0].setUV(e,t),this.vertices[1].setUV(r,s),this.vertices[2].setUV(i,a),this}setFrameUV(e,t,r,s){return this.vertices[0].setFrameUV(e,t,r,s),this.vertices[1].setFrameUV(e,t,r,s),this.vertices[2].setFrameUV(e,t,r,s),this}setFrameSize(e,t){for(var r=0,s=this.vertices.length;r<s;r++)this.vertices[r].setFrameSize(e,t);return this.isPositionModified&&this.updateVerticesPosition(),this}setLocalOffset(e,t){return this.localOffsetX=e,this.localOffsetY=t,this}resetVerticesPosition(){for(var e=0,t=this.vertices.length;e<t;e++)this.vertices[e].resetPosition();return this.isPositionModified&&this.updateVerticesPosition(),this}updateVerticesPosition(){for(var e=this._localOffsetX,t=this._localOffsetY,r=this.vertices,s=0,i=r.length;s<i;s++){var a=r[s];a.setLocalPosition(a.frameX+e,a.frameY+t)}var n=this.rotation;return this._rotation=0,this.rotation=n,this}setRotation(e){return this.rotation=e,this}setAngle(e){return this.angle=e,this}setAlpha(e){return this.alpha=e,this}setColor(e){return this.color=e,this}contains(e,t){return r=e,s=t,i=this.vertices,a=i[0],n=i[1],o=i[2],g.setTo(a.localX,a.localY,n.localX,n.localY,o.localX,o.localY),g.contains(r,s);var r,s,i,a,n,o}}const x=Phaser.Utils.Array.GetFirst;var P={clear(){return this.faces.length=0,this.vertices.length=0,this.setFaceCountDirtyFlag(),this},createVertex(e,t){void 0===e&&(e=0),void 0===t&&(t=0);var r=new c;return r.setUV(e,t),r},createFace:(e,t,r)=>new y(e,t,r),addFace(e){if(this.faces.includes(e))return this;e.setParent(this),this.faces.push(e),this.setFaceCountDirtyFlag();var t=this.frame;e.setFrameSize(t.cutWidth,t.cutHeight).setFrameUV(t.u0,t.v0,t.u1,t.v1).resetVerticesPosition();var r=this.vertices;return e.vertices.forEach((function(e){r.includes(e)||r.push(e)})),this},addFaces(e){for(var t=0,r=e.length;t<r;t++)this.addFace(e[t]);return this},resetFaceSize(){for(var e=this.frame,t=e.realWidth,r=e.realHeight,s=this.faces,i=0,a=s.length;i<a;i++)s[i].setFrameSize(t,r);return this},addGridFaces(e,t,r){return function(e,t,r,s){if(function(e){if("object"!=typeof e||e.nodeType||e===e.window)return!1;try{if(e.constructor&&!{}.hasOwnProperty.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(e){return!1}return!0}(t)){var i=t;t=i.columns,r=i.rows,s=i.sharedVertexMode}void 0===t&&(t=1),void 0===r&&(r=1),void 0===s&&(s=!1);var a,n,o,h,l,c=[];if(s){a=[];for(var u=0;u<=r;u++)for(var d=0;d<=t;d++){var f=e.createVertex(d/t,u/r);a.push(f)}}for(u=0;u<r;u++)for(d=0;d<t;d++)if(s){var v=u*(t+1)+d,g=v+1,p=(u+1)*(t+1)+d,m=p+1,y=a[v],x=a[g],P=a[p],w=a[m];l=e.createFace(y,w,P),e.addFace(l),c.push(l),l=e.createFace(y,x,w),e.addFace(l),c.push(l)}else{var F=d/t,b=(d+1)/t,O=u/r,_=(u+1)/r;n=e.createVertex(F,O),o=e.createVertex(F,_),h=e.createVertex(b,_),l=e.createFace(n,o,h),e.addFace(l),c.push(l),n=e.createVertex(F,O),o=e.createVertex(b,_),h=e.createVertex(b,O),l=e.createFace(n,o,h),e.addFace(l),c.push(l)}s&&e.vertices.sort((function(e,t){return e.v===t.v?e.u-t.u:e.v-t.v}))}(this,e,t,r),this},getVertexByName(e){return x(this.vertices,"name",e)},getFaceByName(e){return x(this.faces,"name",e)},resetVerticesPosition(){for(var e=this.vertices,t=0,r=e.length;t<r;t++)e[t].resetPosition();return this}},w={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}},F={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 e=this.faces.length;return this.vertexBuffer=new Float32Array(6*e),this.uvBuffer=new Float32Array(6*e),this.colorBuffer=new Uint32Array(3*e),this.alphaBuffer=new Float32Array(3*e),this},updateUVBuffer(){for(var e,t,r=this.uvBuffer,s=this.faces,i=0,a=s.length;i<a;i++)t=s[i].vertices,r[e=6*i]=t[0].frameU,r[e+1]=t[0].frameV,r[e+2]=t[1].frameU,r[e+3]=t[1].frameV,r[e+4]=t[2].frameU,r[e+5]=t[2].frameV;return this},updateVertexBuffer(){for(var e,t,r=this.vertexBuffer,s=this.faces,i=0,a=s.length;i<a;i++)t=s[i].vertices,r[e=6*i]=t[0].localX,r[e+1]=t[0].localY,r[e+2]=t[1].localX,r[e+3]=t[1].localY,r[e+4]=t[2].localX,r[e+5]=t[2].localY;return this},updateAlphaBuffer(){for(var e,t,r=this.alphaBuffer,s=this.faces,i=0,a=s.length;i<a;i++)t=s[i].vertices,r[e=3*i]=t[0].alpha,r[e+1]=t[1].alpha,r[e+2]=t[2].alpha;return this},updateColorBuffer(){for(var e,t,r=this.colorBuffer,s=this.faces,i=0,a=s.length;i<a;i++)t=s[i].vertices,r[e=3*i]=t[0].color,r[e+1]=t[1].color,r[e+2]=t[2].color;return this}},b={setTintFill(e){return void 0===e&&(e=!1),this.tintFill=e,this},setTint(e){return this.tint=e,this},clearTint(){return this.setTint(16777215),this}},O={setDebug(e,t){return this.debugGraphic=e,this.debugCallback=e||t?t||this.renderDebugVerts:null,this},renderDebugVerts(e,t,r){for(var s=e.debugGraphic,i=0;i<t;i+=6){var a=r[i+0],n=r[i+1],o=r[i+2],h=r[i+3],l=r[i+4],c=r[i+5];s.lineBetween(a,n,o,h),s.lineBetween(o,h,l,c),s.lineBetween(l,c,a,n)}}};const _=Phaser.GameObjects.Components.TransformMatrix,Y=Phaser.Math.TransformXY;var X,T,V={},B={getFaceAt(e,t,r){for(var s=function(e,t,r,s,i){void 0===s&&(s=e.scene.cameras.main),void 0===i?i={}:!0===i&&(i=V);var a=s.scrollX,n=s.scrollY,o=t+a*e.scrollFactorX-a,h=r+n*e.scrollFactorY-n;return e.parentContainer?(void 0===X&&(X=new _,T=new _),e.getWorldTransformMatrix(X,T),X.applyInverse(o,h,i)):Y(o,h,e.x,e.y,e.rotation,e.scaleX,e.scaleY,i),i.x+=e.displayOriginX,i.y+=e.displayOriginY,i}(this,e,t,r,!0),i=s.x,a=s.y,n=this.faces,o=0,h=n.length;o<h;o++){var l=n[o];if(l.contains(i,a))return l}return null},hasFaceAt(e,t,r){return!!this.getFaceAt(e,t,r)}},k=function(e,t,r,s){for(var i=s.faces,a=0,n=i.length;a<n;a++){var o=i[a];if(o.contains(t,r))return s.input.hitFace=o,!0}return s.input.hitFace=null,!1},A=function(e,t,r,s){var i=this.input.hitFace;this.emit("face.pointerdown",i,e,t,r,s)},R=function(e,t,r,s){var i=this.input.hitFace;this.emit("face.pointerup",i,e,t,r,s),this.input.hitFace=null},S=function(e,t,r,s){var i=this.input.hitFace,a=this.input.prevHitFace;i!==a?(a&&this.emit("face.pointerout",a,e,s),i&&this.emit("face.pointerover",i,e,s),this.input.prevHitFace=i):this.emit("face.pointermove",i,e,t,r,s)},j=function(e,t){var r=this.input.prevHitFace;r&&this.emit("face.pointerout",r,e,t),this.input.hitFace=null,this.input.prevHitFace=null},G={setFaceInteractive:function(e){if(!this.input)return void 0===e&&(e={}),e.hitArea={},e.hitAreaCallback=k,this.setInteractive(e).on("pointerdown",A,this).on("pointerup",R,this).on("pointermove",S,this).on("pointerover",S,this).on("pointerout",j,this),this}};Object.assign(G,P,w,F,b,O,B);const C=Phaser.Renderer.WebGL.Shaders.MultiFrag,D=Phaser.Renderer.WebGL.Shaders.MultiVert,U=Phaser.Renderer.WebGL.ShaderAdditionMakers,M=U.MakeApplyTint,L=U.MakeDefineTexCount,z=U.MakeGetTexCoordOut,W=U.MakeGetTexRes,I=U.MakeSmoothPixelArt,N=U.MakeGetTexture,H=Phaser.Renderer.WebGL.Utils,E=Phaser.Renderer.WebGL.RenderNodes.BatchHandlerQuad,Q=H.getTintAppendFloatAlpha;class q extends E{constructor(e,t){super(e,t),this.renderOptions.multiTexturing=!0}_generateElementIndices(e){for(var t=new ArrayBuffer(5*e*2),r=new Uint16Array(t),s=0,i=0;i<e;i++){var a=3*i;r[s++]=a,r[s++]=a,r[s++]=a+1,r[s++]=a+2,r[s++]=a+2}return t}batchTriangles(e,t,r,s,i,a,n,o,h,l,c,u){0===this.instanceCount&&this.manager.setCurrentBatchNode(this,e);var d=i.length/(2*this.verticesPerInstance);if(d>this.instancesPerBatch)throw new Error("rexBatchHandlerTriangle: Vertex count exceeds maximum per batch ("+this.maxVerticesPerBatch+")");this.instanceCount+d>this.instancesPerBatch&&this.run(e),this.updateRenderOptions(c),this._renderOptionsChanged&&(this.run(e),this.updateShaderConfig());var f,v=this.batchTextures(s),g=this.instanceCount*this.floatsPerInstance,p=this.vertexBufferLayout.buffer,m=p.viewF32,y=p.viewU32;u&&(f=[]);for(var x=r.a,P=r.b,w=r.c,F=r.d,b=r.e,O=r.f,_=-t.displayOriginX,Y=-t.displayOriginY,X=i.length,T=0;T<X;T+=6){for(var V=0;V<3;V++){var B=T+2*V,k=i[B],A=i[B+1],R=(k+=_)*x+(A+=Y)*w+b,S=k*P+A*F+O,j=T/2+V,G=Q(n[j],o[j]*h);m[g++]=R,m[g++]=S,m[g++]=a[B],m[g++]=a[B+1],m[g++]=v,m[g++]=l,y[g++]=G,f&&f.push(R,S)}this.instanceCount++,this.currentBatchEntry.count++}u&&u.call(t,t,X,f)}}q.prototype.defaultConfig={name:"rexBatchHandlerTriangle",verticesPerInstance:3,indicesPerInstance:5,shaderName:"REXTRI",vertexSource:D,fragmentSource:C,shaderAdditions:[z(),W(!0),I(!0),L(1),N(),M()],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(e){return e instanceof J};const Z=Phaser.Scene;var $=function(e){return e instanceof Z},ee=function(e,t,r){var s,i=(s=e,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(t,!0)||i.addNodeConstructor(t,r)};const te=new Phaser.Structs.Map([["BatchHandler","rexBatchHandlerTriangles"]]);let re=class extends t{constructor(e,t,r,s,i){void 0===t&&(t=0),void 0===r&&(r=0),void 0===s&&(s="__DEFAULT"),super(e,"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(t,r),this.setSizeToFrame(),this.setOriginFromFrame(),ee(e,"rexBatchHandlerTriangles",q),this.initRenderNodes(this._defaultRenderNodesMap)}get _defaultRenderNodesMap(){return te}get dirty(){return 0!==this.dirtyFlags}get frame(){return this._frame}set frame(e){if(this._frame!==e){this._frame=e;var t=this.faces;if(t){var r=e?e.u0:0,s=e?e.v0:0,i=e?e.u1:0,a=e?e.v1:0,n=e?e.cutWidth:0,o=e?e.cutHeight:0,h=this._frameWidthSave!==n||this._frameHeightSave!==o;this._frameWidthSave=n,this._frameHeightSave=o;for(var l=0,c=t.length;l<c;l++){var u=t[l];u.setFrameUV(r,s,i,a),h&&u.setFrameSize(n,o)}}}}get tint(){return this.faces.length>0?this.faces[0].color:16777215}set tint(e){for(var t=this.faces,r=0,s=t.length;r<s;r++)t[r].setColor(e)}addedToScene(){this.scene.sys.updateList.add(this)}removedFromScene(){this.scene.sys.updateList.remove(this)}};Object.assign(re.prototype,a,G);var se={play(e,t){return this.anims.play(e,t)},playReverse(e,t){return this.anims.playReverse(e,t)},playAfterDelay(e,t){return this.anims.playAfterDelay(e,t)},playAfterRepeat(e,t){return this.anims.playAfterRepeat(e,t)},chain(e){return this.anims.chain(e)},stop(){return this.anims.stop()},stopAfterDelay(e){return this.anims.stopAfterDelay(e)},stopAfterRepeat(e){return this.anims.stopAfterRepeat(e)},stopOnFrame(e){return this.anims.stopOnFrame(e)}},ie={};Object.assign(ie,se);const ae=Phaser.Animations.AnimationState;class ne extends re{constructor(e,t,r,s,i){super(e,t,r,s,i),this.type="rexMeshSprite",this.anims=new ae(this)}preUpdate(e,t){this.anims.update(e,t)}preDestroy(){this.anims.destroy(),this.anims=void 0}}Object.assign(ne.prototype,ie);const oe=[0,2,3,0,3,1],he=[1,3,2,1,2,0],le=[0,3,4,0,4,1,1,4,2,4,5,2,3,6,4,6,7,4,4,7,8,4,8,5],ce=Phaser.Utils.Objects.IsPlainObject,ue=Phaser.Utils.Objects.GetValue;class de extends ne{constructor(e,t,r,s,i,a){ce(t)&&(t=ue(a=t,"x",0),r=ue(a,"y",0),s=ue(a,"key",null),i=ue(a,"frame",null)),super(e,t,r,s,i),this.type="rexQuadImage",this.isNinePointMode=ue(a,"ninePointMode",!1),this.fourPointsModeRTL=ue(a,"rtl",!1),function(e){for(var t,r=e.isNinePointMode,s=r?3:2,i=[],a=0;a<s;a++)for(var n=0;n<s;n++){var o=n/(s-1),h=a/(s-1),l=e.createVertex(o,h);i.push(l)}for(var c=0,u=(t=r?le:e.fourPointsModeRTL?he:oe).length;c<u;c+=3){var d=i[t[c+0]],f=i[t[c+1]],v=i[t[c+2]],g=e.createFace(d,f,v);e.addFace(g)}e.vertices.sort((function(e,t){return e.v===t.v?e.u-t.u:e.v-t.v})),r?(e.topLeft=i[0],e.topCenter=i[1],e.topRight=i[2],e.centerLeft=i[3],e.center=i[4],e.centerRight=i[5],e.bottomLeft=i[6],e.bottomCenter=i[7],e.bottomRight=i[8]):(e.topLeft=i[0],e.topRight=i[1],e.bottomLeft=i[2],e.bottomRight=i[3])}(this)}destroy(e){this.scene&&!this.ignoreDestroy&&super.destroy(e)}}function fe(e,t,r,s,i){var a=new de(this.scene,e,t,r,s,i);return this.scene.add.existing(a),a}const ve=Phaser.Utils.Objects.GetAdvancedValue,ge=Phaser.GameObjects.BuildGameObject;function pe(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var r=ve(e,"key",null),s=ve(e,"frame",null),i=new de(this.scene,0,0,r,s,e);return ge(this.scene,i,e),i}const me=Phaser.Textures.DynamicTexture;var ye=function(e,t,r){return void 0===t&&(t=2),void 0===r&&(r=2),new me(e.sys.textures,null,t,r)},xe=function(e){return void 0!==e.displayWidth?e.displayWidth:e.width},Pe=function(e){return void 0!==e.displayHeight?e.displayHeight:e.height};const we=Phaser.Geom.Rectangle,Fe=Phaser.Math.Vector2,be=Phaser.Math.RotateAround,Oe=Phaser.GameObjects.Container;var _e=function(e,t){if(void 0===t?t=new we:!0===t&&(void 0===Ye&&(Ye=new we),t=Ye),e.getBounds&&!(e instanceof Oe))return e.getBounds(t);var r,s,i,a,n,o,h,l;if(e.parentContainer){var c=e.parentContainer.getBoundsTransformMatrix();Xe(e,t),c.transformPoint(t.x,t.y,t),r=t.x,s=t.y,Te(e,t),c.transformPoint(t.x,t.y,t),i=t.x,a=t.y,Ve(e,t),c.transformPoint(t.x,t.y,t),n=t.x,o=t.y,Be(e,t),c.transformPoint(t.x,t.y,t),h=t.x,l=t.y}else Xe(e,t),r=t.x,s=t.y,Te(e,t),i=t.x,a=t.y,Ve(e,t),n=t.x,o=t.y,Be(e,t),h=t.x,l=t.y;return t.x=Math.min(r,i,n,h),t.y=Math.min(s,a,o,l),t.width=Math.max(r,i,n,h)-t.x,t.height=Math.max(s,a,o,l)-t.y,t},Ye=void 0,Xe=function(e,t,r){return void 0===t?t=new Fe:!0===t&&(void 0===ke&&(ke=new Fe),t=ke),e.getTopLeft?e.getTopLeft(t,r):(t.x=e.x-xe(e)*e.originX,t.y=e.y-Pe(e)*e.originY,Ae(e,t,r))},Te=function(e,t,r){return void 0===t?t=new Fe:!0===t&&(void 0===ke&&(ke=new Fe),t=ke),e.getTopRight?e.getTopRight(t,r):(t.x=e.x-xe(e)*e.originX+xe(e),t.y=e.y-Pe(e)*e.originY,Ae(e,t,r))},Ve=function(e,t,r){return void 0===t?t=new Fe:!0===t&&(void 0===ke&&(ke=new Fe),t=ke),e.getBottomLeft?e.getBottomLeft(t,r):(t.x=e.x-xe(e)*e.originX,t.y=e.y-Pe(e)*e.originY+Pe(e),Ae(e,t,r))},Be=function(e,t,r){return void 0===t?t=new Fe:!0===t&&(void 0===ke&&(ke=new Fe),t=ke),e.getBottomRight?e.getBottomRight(t,r):(t.x=e.x-xe(e)*e.originX+xe(e),t.y=e.y-Pe(e)*e.originY+Pe(e),Ae(e,t,r))},ke=void 0,Ae=function(e,t,r){return void 0===r&&(r=!1),0!==e.rotation&&be(t,e.x,e.y,e.rotation),r&&e.parentContainer&&e.parentContainer.getBoundsTransformMatrix().transformPoint(t.x,t.y,t),t};const Re=Phaser.Geom.Rectangle,Se=Phaser.Geom.Rectangle.Union;var je,Ge=function(e,t){var r=Array.isArray(e);if(void 0===t?t=r?[]:{}:function(e){if("object"!=typeof e||null===e)return e;if(Array.isArray(e))e.length=0;else for(var t in e)delete e[t]}(t),r){t.length=e.length;for(var s=0,i=e.length;s<i;s++)t[s]=e[s]}else for(var a in e)t[a]=e[a];return t};const Ce=Phaser.GameObjects.GameObject,De=Phaser.GameObjects.Layer;var Ue=Phaser.Utils.Objects.GetValue,Me=function(e){if(e){var t=e.gameObjects;Array.isArray(t)||(t=[t]);var r,s,i=e.renderTexture,a=e.saveTexture,n=Ue(e,"x",void 0),o=Ue(e,"y",void 0),h=Ue(e,"width",void 0),l=Ue(e,"height",void 0),c=Ue(e,"originX",0),u=Ue(e,"originY",0),d=Ue(e,"padding",0);if(void 0===h||void 0===l||void 0===n||void 0===o){var f=function(e,t){var r;void 0===t?t=new Re:!0===t&&(void 0===je&&(je=new Re),t=je),t.setTo(0,0,0,0);for(var s=!0,i=0,a=e.length;i<a;i++)if((r=e[i]).getBounds){var n=_e(r,!0);s?(t.setTo(n.x,n.y,n.width,n.height),s=!1):Se(n,t,t)}return t}(t,!0);void 0!==n&&void 0!==o?(h=2*Math.max(n-f.left,f.right-n),l=2*Math.max(o-f.top,f.bottom-o),c=.5,u=.5):(n=f.x,o=f.y,h=f.width,l=f.height,c=0,u=0),r=f.x,s=f.y}else r=n+(0-c)*h,s=o+(0-u)*l;r-=d,s-=d,h+=2*d,l+=2*d;var v,g=t[0].scene,p=g.sys.textures;return a&&!i&&(i=p.addDynamicTexture(a,h,l)),i||(i=g.add.renderTexture(0,0,h,l)),i.setPosition&&i.setPosition(n,o),i.width===h&&i.height===l||i.setSize(h,l),i.setOrigin&&i.setOrigin(c,u),i.camera.setScroll(r,s),t=function(e,t){if(e.length<=1)return e;var r;void 0===t&&(t=!1);for(var s=0,i=e.length;s<i;s++){var a=e[s];if(a.displayList?r=a.displayList:a.parentContainer&&(r=a.parentContainer.list),r)break}return r||(r=a.scene.sys.displayList),r.depthSort&&(r.depthSort(),r=r.list),t?e.sort((function(e,t){return r.indexOf(t)-r.indexOf(e)})):e.sort((function(e,t){return r.indexOf(e)-r.indexOf(t)})),e}(Ge(t)),i.draw(t).render(),a&&((v=i)instanceof Ce||v instanceof De?i.saveTexture(a):i.key!==a&&p.renameTexture(i.key,key)),i}};const Le=Phaser.Utils.Objects.IsPlainObject,ze=Phaser.Utils.Objects.GetValue;class We extends de{constructor(e,t,r,s,i,a){Le(t)&&(t=ze(a=t,"x",0),r=ze(a,"y",0),s=ze(a,"width",32),i=ze(a,"height",32)),super(e,t,r,ye(e,s,i),null,a),this.type="rexQuadRenderTexture",this.rt=this.texture}destroy(e){this.scene&&!this.ignoreDestroy&&(super.destroy(e),this.rt.destroy(),this.rt=null)}setSizeToFrame(e){return super.setSizeToFrame(e),this.updateDisplayOrigin(),this.resetFaceSize(),this}snapshot(e,t){return void 0===t&&(t={}),t.gameObjects=e,t.renderTexture=this.rt,Me(t),this.setSizeToFrame(),this}}function Ie(e,t,r,s,i){var a=new We(this.scene,e,t,r,s,i);return this.scene.add.existing(a),a}const Ne=Phaser.Utils.Objects.GetAdvancedValue,He=Phaser.GameObjects.BuildGameObject;function Ee(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var r=Ne(e,"width",32),s=Ne(e,"height",32),i=new We(this.scene,0,0,r,s,e);return He(this.scene,i,e),i}var Qe=function(e,t,r){void 0===t&&(t=0),void 0===r&&(r=0);for(var s=e.displayOriginX,i=e.displayOriginY,a=Math.tan(t)*i,n=Math.tan(r)*s,o=e.vertices,h=0,l=o.length;h<l;h++){var c=o[h],u=c.frameX,d=c.frameY;d>i?c.localX=u+a:d<i&&(c.localX=u-a),u>s?c.localY=d+n:u<s&&(c.localY=d-n)}};const qe=Phaser.Utils.Objects.IsPlainObject,Je=Phaser.Utils.Objects.GetValue,Ke=Phaser.Math.DegToRad,Ze=Phaser.Math.RadToDeg;class $e extends de{constructor(e,t,r,s,i){if(qe(t)){var a=t;t=Je(a,"x",0),r=Je(a,"y",0),s=Je(a,"key",null),i=Je(a,"frame",null)}super(e,t,r,s,i),this.type="rexSkewmage",this._skewX=0,this._skewY=0}get skewX(){return this._skewX}set skewX(e){this._skewX=e,Qe(this,this._skewX,this._skewY)}get skewXDeg(){return Ze(this._skewX)}set skewXDeg(e){this.skewX=Ke(e)}get skewY(){return this._skewY}set skewY(e){this._skewY=e,Qe(this,this._skewX,this._skewY)}get skewYDeg(){return Ze(this._skewY)}set skewYDeg(e){this.skewY=Ke(e)}setSkewX(e){return this.skewX=e,this}setSkewY(e){return this.skewY=e,this}setSkew(e,t){return void 0===t&&(t=e),this.skewX=e,this.skewY=t,this}setSkewXDeg(e){return this.skewXDeg=e,this}setSkewYDeg(e){return this.skewYDeg=e,this}setSkewDeg(e,t){return void 0===t&&(t=e),this.skewXDeg=e,this.skewYDeg=t,this}}function et(e,t,r,s){var i=new $e(this.scene,e,t,r,s);return this.scene.add.existing(i),i}const tt=Phaser.Utils.Objects.GetAdvancedValue,rt=Phaser.GameObjects.BuildGameObject;function st(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var r=tt(e,"key",null),s=tt(e,"frame",null),i=new $e(this.scene,0,0,r,s);return rt(this.scene,i,e),i}const it=Phaser.Utils.Objects.IsPlainObject,at=Phaser.Utils.Objects.GetValue;class nt extends $e{constructor(e,t,r,s,i){if(it(t)){var a=t;t=at(a,"x",0),r=at(a,"y",0),s=at(a,"width",32),i=at(a,"height",32)}super(e,t,r,ye(e,s,i),null),this.type="rexSkewRenderTexture",this.rt=this.texture}destroy(e){this.scene&&!this.ignoreDestroy&&(super.destroy(e),this.rt.destroy(),this.rt=null)}setSizeToFrame(e){return super.setSizeToFrame(e),this.updateDisplayOrigin(),this.resetFaceSize(),this}snapshot(e,t){return void 0===t&&(t={}),t.gameObjects=e,t.renderTexture=this.rt,Me(t),this.setSizeToFrame(),this}}function ot(e,t,r,s){var i=new nt(this.scene,e,t,r,s);return this.scene.add.existing(i),i}const ht=Phaser.Utils.Objects.GetAdvancedValue,lt=Phaser.GameObjects.BuildGameObject;function ct(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var r=ht(e,"width",32),s=ht(e,"height",32),i=new nt(this.scene,0,0,r,s);return lt(this.scene,i,e),i}const ut=Phaser.Utils.Objects.GetValue;var dt=function(e,t){if(!e)return!1;for(var r=t.visibleSibling,s=0,i=r.length;s<i;s++)e.setChildVisible(r[s],!0);return r.length=0,e.setChildVisible(t,!1),t.isRunning=!1,!0},ft=function(e){return class extends e{constructor(e,t){var r=e.scene;super(r,0,0,1,1,t),r.add.existing(this),function(e,t,r){t.visibleSibling=[],t.isRunning=!1,t.useParentBounds=ut(r,"useParentBounds",!1),t.setPosition(e.x,e.y).setVisible(!1),e.pin(t)}(e,this,t)}destroy(e){this.scene&&!this.ignoreDestroy&&(this.exit(),super.destroy(e))}enter(){return function(e,t){if(!e)return!1;dt(e,t);var r=t.useParentBounds;Me({gameObjects:e.getAllVisibleChildren(),renderTexture:t.rt,x:t.x,y:t.y,width:r?e.displayWidth:void 0,height:r?e.displayHeighth:void 0,originX:r?e.originX:void 0,originY:r?e.originY:void 0}),e.setChildVisible(t,!0);for(var s=t.visibleSibling,i=e.children,a=0,n=i.length;a<n;a++){var o=i[a];o.visible&&o!==t&&(e.setChildVisible(o,!1),s.push(o))}return t.isRunning=!0,!0}(this.rexContainer.parent,this)&&this.setSizeToFrame(),this}exit(){return dt(this.rexContainer.parent,this),this}}};class vt extends(ft(nt)){get skewState(){return this.isRunning}}var gt=function(e){return null==e||""===e||0===e.length},pt=function(e,t,r,s){if(void 0===s&&(s="."),"object"==typeof e){if(gt(t)){if(null==r)return;"object"==typeof r&&(e=r)}else{"string"==typeof t&&(t=t.split(s));var i=t.pop(),a=function(e,t,r){var s=e;if(gt(t));else{var i;"string"==typeof t&&(t=t.split("."));for(var a=0,n=t.length;a<n;a++){var o;null!=s[i=t[a]]&&"object"==typeof s[i]||(o=a===n-1?void 0===r?{}:r:{},s[i]=o),s=s[i]}}return s}(e,t);a[i]=r}return e}};class mt extends Phaser.Plugins.BasePlugin{constructor(e){super(e),e.registerGameObject("rexQuadImage",fe,pe),e.registerGameObject("rexQuadRenderTexture",Ie,Ee),e.registerGameObject("rexSkewImage",et,st),e.registerGameObject("rexSkewRenderTexture",ot,ct)}start(){this.game.events.on("destroy",this.destroy,this)}addContainerSkew(e,t){return new vt(e,t)}}return pt(window,"RexPlugins.GameObjects.QuadImage",de),pt(window,"RexPlugins.GameObjects.QuadRenderTexture",We),pt(window,"RexPlugins.GameObjects.SkewImage",$e),pt(window,"RexPlugins.GameObjects.SkewRenderTexture",nt),pt(window,"RexPlugins.GameObjects.ContainerSkew",vt),mt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexquadimageplugin=t();