UNPKG

@petkoneo/phaser3-rex-plugins

Version:
2 lines (1 loc) 13.3 kB
var e,t;e=void 0,t=function(){const e=Phaser.GameObjects.Mesh;class t extends e{get tint(){return 0===this.vertices.length?16777215:this.vertices[0].color}forceUpdate(){return this.dirtyCache[10]=1,this}}const i=Phaser.Math.RotateAround;var s=function(e,t,s){var n=e.width/2,o=e.height/2;return r.x=t-n,r.y=s-o,i(r,0,0,e.rotation),r.x*=e.scaleX,r.y*=e.scaleY,r.x+=e.x,r.y+=e.y,r},r={x:0,y:0};class n{constructor(e,t){this.parent=e,this.vertex=t,this._localX=void 0,this._localY=void 0}destroy(){this.parent=void 0,this.vertex=void 0}updateVertexPosition(e,t){var i=this.parent,s=i.height,r=e/s-i.frame.cutWidth/s/2,n=t/s-i.frame.cutHeight/s/2,o=this.vertex;return o.x=r,o.y=-n,i.forceUpdate(),this}get localX(){return this._localX}set localX(e){this.setLocalXY(e,this._localY)}get localY(){return this._localY}set localY(e){this.setLocalXY(this._localX,e)}get localXOrigin(){return this._localXOrigin}get localYOrigin(){return this._localYOrigin}resetLocalXY(e,t){return this._localXOrigin=e,this._localYOrigin=t,this._localX=e,this._localY=t,this}setLocalXY(e,t,i){return this._localX===e&&this._localY===t||(this._localX=e,this._localY=t,i||this.updateVertexPosition(e,t)),this}setWorldXY(e,t){if(this._worldX===e&&this._worldY===t)return this;var s,n,o,a,h,l=(s=this.parent,n=e,o=t,a=s.width/2,h=s.height/2,r.x=n-s.x,r.y=o-s.y,r.x/=s.scaleX,r.y/=s.scaleY,i(r,0,0,-s.rotation),r.x+=a,r.y+=h,r);return this.setLocalXY(l.x,l.y),this}setPosition(e,t){return this.setWorldXY(e,t),this}getWorldXY(){return s(this.parent,this._localX,this._localY)}get x(){return s(this.parent,this._localX,this._localY).x}set x(e){this.setWorldXY(e,this.y)}get y(){return s(this.parent,this._localX,this._localY).y}set y(e){this.setWorldXY(this.x,e)}}const o=Phaser.Geom.Mesh.Vertex,a=Phaser.Geom.Mesh.Face,h=[0,2,3,0,3,1],l=[1,3,2,1,2,0],c=[0,3,4,0,4,1,1,4,2,4,5,2,3,6,4,6,7,4,4,7,8,4,8,5],d=Phaser.Utils.Objects.IsPlainObject,u=Phaser.Utils.Objects.GetValue;class g extends t{constructor(e,t,i,s,r,g){d(t)&&(t=u(g=t,"x",0),i=u(g,"y",0),s=u(g,"key",null),r=u(g,"frame",null)),super(e,t,i,s,r),this.type="rexQuadImage",this.isNinePointMode=u(g,"ninePointMode",!1),this.fourPointsModeRTL=u(g,"rtl",!1),this.controlPoints=[],function(e){for(var t,i=e.isNinePointMode,s=i?9:4,r=e.vertices,d=e.faces,u=e.controlPoints,g=0;g<s;g++){var v=new o;r.push(v),u.push(new n(e,v))}g=0;for(var f=(t=i?c:e.fourPointsModeRTL?l:h).length;g<f;g+=3){var x=r[t[g+0]],y=r[t[g+1]],w=r[t[g+2]];d.push(new a(x,y,w))}i?(e.topLeft=u[0],e.topCenter=u[1],e.topRight=u[2],e.centerLeft=u[3],e.center=u[4],e.centerRight=u[5],e.bottomLeft=u[6],e.bottomCenter=u[7],e.bottomRight=u[8]):(e.topLeft=u[0],e.topRight=u[1],e.bottomLeft=u[2],e.bottomRight=u[3])}(this),this.hideCCW=!1,this.syncSize()}destroy(e){if(this.scene&&!this.ignoreDestroy){super.destroy(e);for(var t=0,i=this.controlPoints.length;t<i;t++)this.controlPoints[t].destroy();this.controlPoints=void 0}}resetVerts(){this.dirtyCache[9]=-1;for(var e=function(e){var t,i=e.height,s=e.width;if(e.isNinePointMode){var r=(0+s)/2,n=(0+i)/2;t=[0,0,r,0,s,0,0,n,r,n,s,n,0,i,r,i,s,i]}else t=[0,0,s,0,0,i,s,i];return t}(this),t=this.width,i=this.height,s=this.frame.cutWidth/i/2,r=this.frame.cutHeight/i/2,n=this.frame.u0,o=this.frame.u1,a=this.frame.v0,h=o-n,l=this.frame.v1-a,c=this.controlPoints,d=0,u=e.length;d<u;d+=2){var g=e[d+0],v=e[d+1],f=d/2,x=g/i-s,y=v/i-r,w=n+h*(g/t),m=a+l*(v/i);this.vertices[f].set(x,-y,0).setUVs(w,m),c[f].resetLocalXY(g,v)}return this}syncSize(){return this.setSizeToFrame(),this.setOrtho(this.width/this.height,1),this.resetVerts(),this}}function v(e,t,i,s,r){var n=new g(this.scene,e,t,i,s,r);return this.scene.add.existing(n),n}const f=Phaser.Utils.Objects.GetAdvancedValue,x=Phaser.GameObjects.BuildGameObject;function y(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var i=f(e,"key",null),s=f(e,"frame",null),r=new g(this.scene,0,0,i,s,e);return x(this.scene,r,e),r}const w=Phaser.Textures.DynamicTexture;var m=function(e,t,i){return void 0===t&&(t=2),void 0===i&&(i=2),new w(e.sys.textures,null,t,i)},p=function(e){return void 0!==e.displayWidth?e.displayWidth:e.width},P=function(e){return void 0!==e.displayHeight?e.displayHeight:e.height};const b=Phaser.Geom.Rectangle,O=Phaser.Math.Vector2,X=Phaser.Math.RotateAround,Y=Phaser.GameObjects.Container;var k=function(e,t){if(void 0===t?t=new b:!0===t&&(void 0===j&&(j=new b),t=j),e.getBounds&&!(e instanceof Y))return e.getBounds(t);var i,s,r,n,o,a,h,l;if(e.parentContainer){var c=e.parentContainer.getBoundsTransformMatrix();G(e,t),c.transformPoint(t.x,t.y,t),i=t.x,s=t.y,_(e,t),c.transformPoint(t.x,t.y,t),r=t.x,n=t.y,R(e,t),c.transformPoint(t.x,t.y,t),o=t.x,a=t.y,T(e,t),c.transformPoint(t.x,t.y,t),h=t.x,l=t.y}else G(e,t),i=t.x,s=t.y,_(e,t),r=t.x,n=t.y,R(e,t),o=t.x,a=t.y,T(e,t),h=t.x,l=t.y;return t.x=Math.min(i,r,o,h),t.y=Math.min(s,n,a,l),t.width=Math.max(i,r,o,h)-t.x,t.height=Math.max(s,n,a,l)-t.y,t},j=void 0,G=function(e,t,i){return void 0===t?t=new O:!0===t&&(void 0===S&&(S=new O),t=S),e.getTopLeft?e.getTopLeft(t):(t.x=e.x-p(e)*e.originX,t.y=e.y-P(e)*e.originY,M(e,t,i))},_=function(e,t,i){return void 0===t?t=new O:!0===t&&(void 0===S&&(S=new O),t=S),e.getTopRight?e.getTopRight(t):(t.x=e.x-p(e)*e.originX+p(e),t.y=e.y-P(e)*e.originY,M(e,t,i))},R=function(e,t,i){return void 0===t?t=new O:!0===t&&(void 0===S&&(S=new O),t=S),e.getBottomLeft?e.getBottomLeft(t):(t.x=e.x-p(e)*e.originX,t.y=e.y-P(e)*e.originY+P(e),M(e,t,i))},T=function(e,t,i){return void 0===t?t=new O:!0===t&&(void 0===S&&(S=new O),t=S),e.getBottomRight?e.getBottomRight(t):(t.x=e.x-p(e)*e.originX+p(e),t.y=e.y-P(e)*e.originY+P(e),M(e,t,i))},S=void 0,M=function(e,t,i){return void 0===i&&(i=!1),0!==e.rotation&&X(t,e.x,e.y,e.rotation),i&&e.parentContainer&&e.parentContainer.getBoundsTransformMatrix().transformPoint(t.x,t.y,t),t};const V=Phaser.Geom.Rectangle,C=Phaser.Geom.Rectangle.Union;var L,D=function(e,t){var i=Array.isArray(e);if(void 0===t?t=i?[]:{}: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),i){t.length=e.length;for(var s=0,r=e.length;s<r;s++)t[s]=e[s]}else for(var n in e)t[n]=e[n];return t};const U=Phaser.GameObjects.GameObject,B=Phaser.GameObjects.Layer;var W=Phaser.Utils.Objects.GetValue,A=function(e){if(e){var t,i,s=e.gameObjects,r=e.renderTexture,n=e.saveTexture,o=W(e,"x",void 0),a=W(e,"y",void 0),h=W(e,"width",void 0),l=W(e,"height",void 0),c=W(e,"originX",0),d=W(e,"originY",0),u=W(e,"padding",0);if(void 0===h||void 0===l||void 0===o||void 0===a){var g=function(e,t){var i;void 0===t?t=new V:!0===t&&(void 0===L&&(L=new V),t=L),t.setTo(0,0,0,0);for(var s=!0,r=0,n=e.length;r<n;r++)if((i=e[r]).getBounds){var o=k(i,!0);s?(t.setTo(o.x,o.y,o.width,o.height),s=!1):C(o,t,t)}return t}(s,!0);void 0!==o&&void 0!==a?(h=2*Math.max(o-g.left,g.right-o),l=2*Math.max(a-g.top,g.bottom-a),c=.5,d=.5):(o=g.x,a=g.y,h=g.width,l=g.height,c=0,d=0),t=g.x,i=g.y}else t=o+(0-c)*h,i=a+(0-d)*l;t-=u,i-=u,h+=2*u,l+=2*u;var v,f=s[0].scene,x=f.sys.textures;return n&&!r&&(r=x.addDynamicTexture(n,h,l)),r||(r=f.add.renderTexture(0,0,h,l)),r.setPosition&&r.setPosition(o,a),r.width===h&&r.height===l||r.setSize(h,l),r.setOrigin&&r.setOrigin(c,d),r.camera.setScroll(t,i),s=function(e,t){if(e.length<=1)return e;var i;void 0===t&&(t=!1);for(var s=0,r=e.length;s<r;s++){var n=e[s];if(n.displayList?i=n.displayList:n.parentContainer&&(i=n.parentContainer.list),i)break}return i||(i=n.scene.sys.displayList),i.depthSort&&(i.depthSort(),i=i.list),t?e.sort((function(e,t){return i.indexOf(t)-i.indexOf(e)})):e.sort((function(e,t){return i.indexOf(e)-i.indexOf(t)})),e}(D(s)),r.draw(s),n&&((v=r)instanceof U||v instanceof B?r.saveTexture(n):r.key!==n&&x.renameTexture(r.key,key)),r}};const I=Phaser.Utils.Objects.IsPlainObject,z=Phaser.Utils.Objects.GetValue;class H extends g{constructor(e,t,i,s,r,n){I(t)&&(t=z(n=t,"x",0),i=z(n,"y",0),s=z(n,"width",32),r=z(n,"height",32)),super(e,t,i,m(e,s,r),null,n),this.type="rexQuadRenderTexture",this.rt=this.texture}destroy(e){this.scene&&!this.ignoreDestroy&&(super.destroy(e),this.rt.destroy(),this.rt=null)}snapshot(e,t){return void 0===t&&(t={}),t.gameObjects=e,t.renderTexture=this.rt,A(t),this.width===this.frame.realWidth&&this.height===this.frame.realHeight||this.syncSize(),this}}function Q(e,t,i,s,r){var n=new H(this.scene,e,t,i,s,r);return this.scene.add.existing(n),n}const N=Phaser.Utils.Objects.GetAdvancedValue,F=Phaser.GameObjects.BuildGameObject;function q(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var i=N(e,"width",32),s=N(e,"height",32),r=new H(this.scene,0,0,i,s,e);return F(this.scene,r,e),r}var E=function(e,t,i){void 0===t&&(t=0),void 0===i&&(i=0);for(var s=.5*e.width,r=.5*e.height,n=Math.tan(t)*r,o=Math.tan(i)*s,a=e.controlPoints,h=0,l=a.length;h<l;h++){var c=a[h],d=c.localXOrigin,u=c.localYOrigin;c.localX=d+(u>r?n:-n),c.localY=u+(d>s?o:-o)}};const J=Phaser.Utils.Objects.IsPlainObject,K=Phaser.Utils.Objects.GetValue,Z=Phaser.Math.DegToRad,$=Phaser.Math.RadToDeg;class ee extends g{constructor(e,t,i,s,r){if(J(t)){var n=t;t=K(n,"x",0),i=K(n,"y",0),s=K(n,"key",null),r=K(n,"frame",null)}super(e,t,i,s,r),this.type="rexSkewmage",this._skewX=0,this._skewY=0}get skewX(){return this._skewX}set skewX(e){this._skewX=e,E(this,this._skewX,this._skewY)}get skewXDeg(){return $(this._skewX)}set skewXDeg(e){this.skewX=Z(e)}get skewY(){return this._skewY}set skewY(e){this._skewY=e,E(this,this._skewX,this._skewY)}get skewYDeg(){return $(this._skewY)}set skewYDeg(e){this.skewY=Z(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 te(e,t,i,s){var r=new ee(this.scene,e,t,i,s);return this.scene.add.existing(r),r}const ie=Phaser.Utils.Objects.GetAdvancedValue,se=Phaser.GameObjects.BuildGameObject;function re(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var i=ie(e,"key",null),s=ie(e,"frame",null),r=new ee(this.scene,0,0,i,s);return se(this.scene,r,e),r}const ne=Phaser.Utils.Objects.IsPlainObject,oe=Phaser.Utils.Objects.GetValue;class ae extends ee{constructor(e,t,i,s,r){if(ne(t)){var n=t;t=oe(n,"x",0),i=oe(n,"y",0),s=oe(n,"width",32),r=oe(n,"height",32)}super(e,t,i,m(e,s,r),null),this.type="rexSkewRenderTexture",this.rt=this.texture}destroy(e){this.scene&&!this.ignoreDestroy&&(super.destroy(e),this.rt.destroy(),this.rt=null)}}function he(e,t,i,s){var r=new ae(this.scene,e,t,i,s);return this.scene.add.existing(r),r}const le=Phaser.Utils.Objects.GetAdvancedValue,ce=Phaser.GameObjects.BuildGameObject;function de(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var i=le(e,"width",32),s=le(e,"height",32),r=new ae(this.scene,0,0,i,s);return ce(this.scene,r,e),r}const ue=Phaser.Utils.Objects.GetValue;var ge=function(e,t){if(!e)return!1;for(var i=t.visibleSibling,s=0,r=i.length;s<r;s++)e.setChildVisible(i[s],!0);return i.length=0,e.setChildVisible(t,!1),t.isRunning=!1,!0},ve=function(e){return class extends e{constructor(e,t){var i=e.scene;super(i,0,0,1,1,t),i.add.existing(this),function(e,t,i){t.visibleSibling=[],t.isRunning=!1,t.useParentBounds=ue(i,"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;ge(e,t);var i=t.useParentBounds;A({gameObjects:e.getAllVisibleChildren(),renderTexture:t.rt,x:t.x,y:t.y,width:i?e.displayWidth:void 0,height:i?e.displayHeighth:void 0,originX:i?e.originX:void 0,originY:i?e.originY:void 0}),e.setChildVisible(t,!0);for(var s=t.visibleSibling,r=e.children,n=0,o=r.length;n<o;n++){var a=r[n];a.visible&&a!==t&&(e.setChildVisible(a,!1),s.push(a))}return t.isRunning=!0,!0}(this.rexContainer.parent,this)&&this.syncSize(),this}exit(){return ge(this.rexContainer.parent,this),this}}};class fe extends(ve(ae)){get skewState(){return this.isRunning}}var xe=function(e){return null==e||""===e||0===e.length},ye=function(e,t,i,s){if(void 0===s&&(s="."),"object"==typeof e){if(xe(t)){if(null==i)return;"object"==typeof i&&(e=i)}else{"string"==typeof t&&(t=t.split(s));var r=t.pop(),n=function(e,t,i){var s=e;if(xe(t));else{var r;"string"==typeof t&&(t=t.split("."));for(var n=0,o=t.length;n<o;n++){var a;null!=s[r=t[n]]&&"object"==typeof s[r]||(a=n===o-1?void 0===i?{}:i:{},s[r]=a),s=s[r]}}return s}(e,t);n[r]=i}return e}};class we extends Phaser.Plugins.BasePlugin{constructor(e){super(e),e.registerGameObject("rexQuadImage",v,y),e.registerGameObject("rexQuadRenderTexture",Q,q),e.registerGameObject("rexSkewImage",te,re),e.registerGameObject("rexSkewRenderTexture",he,de)}start(){this.game.events.on("destroy",this.destroy,this)}addContainerSkew(e,t){return new fe(e,t)}}return ye(window,"RexPlugins.GameObjects.QuadImage",g),ye(window,"RexPlugins.GameObjects.QuadRenderTexture",H),ye(window,"RexPlugins.GameObjects.SkewImage",ee),ye(window,"RexPlugins.GameObjects.SkewRenderTexture",ae),ye(window,"RexPlugins.GameObjects.ContainerSkew",fe),we},"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();