UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 17.6 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexquadimageplugin=e();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,c(n.key),n);}}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e);}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function u(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return !1}}();return function(){var i,n=s(t);if(e){var r=s(this).constructor;i=Reflect.construct(n,arguments,r);}else i=n.apply(this,arguments);return function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return a(t)}(this,i)}}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}(t,e);if(n){var r=Object.getOwnPropertyDescriptor(n,e);return r.get?r.get.call(arguments.length<3?t:i):r.value}},h.apply(this,arguments)}function c(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(t,"string");return "symbol"==typeof e?e:String(e)}var l=function(t){r(s,t);var i=u(s);function s(){return e(this,s),i.apply(this,arguments)}return n(s,[{key:"tint",get:function(){return 0===this.vertices.length?16777215:this.vertices[0].color}},{key:"setInteractive",value:function(){var t=function(t,e,i){for(var n=this.faces,r=0;r<n.length;r++){if(n[r].contains(e,i))return !0}return !1}.bind(this);return this.scene.sys.input.enable(this,t),this}},{key:"forceUpdate",value:function(){return this.dirtyCache[10]=1,this}}]),s}(Phaser.GameObjects.Mesh),f=Phaser.Math.RotateAround,d=function(t,e,i){var n=t.width/2,r=t.height/2;return y.x=e-n,y.y=i-r,f(y,0,0,t.rotation),y.x*=t.scaleX,y.y*=t.scaleY,y.x+=t.x,y.y+=t.y,y},y={x:0,y:0},v=function(){function t(i,n){e(this,t),this.parent=i,this.vertex=n,this._localX=void 0,this._localY=void 0;}return n(t,[{key:"destroy",value:function(){this.parent=void 0,this.vertex=void 0;}},{key:"updateVertexPosition",value:function(t,e){var i=this.parent,n=i.height,r=t/n-i.frame.cutWidth/n/2,s=e/n-i.frame.cutHeight/n/2,o=this.vertex;return o.x=r,o.y=-s,i.forceUpdate(),this}},{key:"localX",get:function(){return this._localX},set:function(t){this.setLocalXY(t,this._localY);}},{key:"localY",get:function(){return this._localY},set:function(t){this.setLocalXY(this._localX,t);}},{key:"localXOrigin",get:function(){return this._localXOrigin}},{key:"localYOrigin",get:function(){return this._localYOrigin}},{key:"resetLocalXY",value:function(t,e){return this._localXOrigin=t,this._localYOrigin=e,this._localX=t,this._localY=e,this}},{key:"setLocalXY",value:function(t,e,i){return this._localX===t&&this._localY===e||(this._localX=t,this._localY=e,i||this.updateVertexPosition(t,e)),this}},{key:"setWorldXY",value:function(t,e){if(this._worldX===t&&this._worldY===e)return this;var i,n,r,s,o,a=(i=this.parent,n=t,r=e,s=i.width/2,o=i.height/2,y.x=n-i.x,y.y=r-i.y,y.x/=i.scaleX,y.y/=i.scaleY,f(y,0,0,-i.rotation),y.x+=s,y.y+=o,y);return this.setLocalXY(a.x,a.y),this}},{key:"setPosition",value:function(t,e){return this.setWorldXY(t,e),this}},{key:"getWorldXY",value:function(){return d(this.parent,this._localX,this._localY)}},{key:"x",get:function(){return d(this.parent,this._localX,this._localY).x},set:function(t){this.setWorldXY(t,this.y);}},{key:"y",get:function(){return d(this.parent,this._localX,this._localY).y},set:function(t){this.setWorldXY(this.x,t);}}]),t}(),g=Phaser.Geom.Mesh.Vertex,p=Phaser.Geom.Mesh.Face,x=[0,2,3,0,3,1],w=[1,3,2,1,2,0],b=[0,3,4,0,4,1,1,4,2,4,5,2,3,6,4,6,7,4,4,7,8,4,8,5],m=Phaser.Utils.Objects.IsPlainObject,k=Phaser.Utils.Objects.GetValue,P=function(t){r(o,t);var i=u(o);function o(t,n,r,s,u,h){var c;return e(this,o),m(n)&&(n=k(h=n,"x",0),r=k(h,"y",0),s=k(h,"key",null),u=k(h,"frame",null)),(c=i.call(this,t,n,r,s,u)).type="rexQuadImage",c.isNinePointMode=k(h,"ninePointMode",!1),c.fourPointsModeRTL=k(h,"rtl",!1),c.controlPoints=[],function(t){for(var e,i=t.isNinePointMode,n=i?9:4,r=t.vertices,s=t.faces,o=t.controlPoints,a=0;a<n;a++){var u=new g;r.push(u),o.push(new v(t,u));}a=0;for(var h=(e=i?b:t.fourPointsModeRTL?w:x).length;a<h;a+=3){var c=r[e[a+0]],l=r[e[a+1]],f=r[e[a+2]];s.push(new p(c,l,f));}i?(t.topLeft=o[0],t.topCenter=o[1],t.topRight=o[2],t.centerLeft=o[3],t.center=o[4],t.centerRight=o[5],t.bottomLeft=o[6],t.bottomCenter=o[7],t.bottomRight=o[8]):(t.topLeft=o[0],t.topRight=o[1],t.bottomLeft=o[2],t.bottomRight=o[3]);}(a(c)),c.hideCCW=!1,c.syncSize(),c}return n(o,[{key:"destroy",value:function(t){if(this.scene&&!this.ignoreDestroy){h(s(o.prototype),"destroy",this).call(this,t);for(var e=0,i=this.controlPoints.length;e<i;e++)this.controlPoints[e].destroy();this.controlPoints=void 0;}}},{key:"resetVerts",value:function(){this.dirtyCache[9]=-1;for(var t=function(t){var e,i=t.height,n=t.width;if(t.isNinePointMode){var r=(0+n)/2,s=(0+i)/2;e=[0,0,r,0,n,0,0,s,r,s,n,s,0,i,r,i,n,i];}else e=[0,0,n,0,0,i,n,i];return e}(this),e=this.width,i=this.height,n=this.frame.cutWidth/i/2,r=this.frame.cutHeight/i/2,s=this.frame.u0,o=this.frame.u1,a=this.frame.v0,u=o-s,h=this.frame.v1-a,c=this.controlPoints,l=0,f=t.length;l<f;l+=2){var d=t[l+0],y=t[l+1],v=l/2,g=d/i-n,p=y/i-r,x=s+u*(d/e),w=a+h*(y/i);this.vertices[v].set(g,-p,0).setUVs(x,w),c[v].resetLocalXY(d,y);}return this}},{key:"syncSize",value:function(){return this.setSizeToFrame(),this.setOrtho(this.width/this.height,1),this.resetVerts(),this}}]),o}(l);function O(t,e,i,n,r){var s=new P(this.scene,t,e,i,n,r);return this.scene.add.existing(s),s}var j=Phaser.Utils.Objects.GetAdvancedValue,X=Phaser.GameObjects.BuildGameObject;function Y(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=j(t,"key",null),n=j(t,"frame",null),r=new P(this.scene,0,0,i,n,t);return X(this.scene,r,t),r}var _,R=Phaser.Textures.DynamicTexture,S=function(t,e,i){return void 0===e&&(e=2),void 0===i&&(i=2),new R(t.sys.textures,null,e,i)},T=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},G=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height},M=Phaser.Geom.Rectangle,V=Phaser.Math.Vector2,C=Phaser.Math.RotateAround,U=function(t,e){if(void 0===e?e=new M:!0===e&&(void 0===D&&(D=new M),e=D),t.getBounds)return t.getBounds(e);var i,n,r,s,o,a,u,h;if(t.parentContainer){var c=t.parentContainer.getBoundsTransformMatrix();L(t,e),c.transformPoint(e.x,e.y,e),i=e.x,n=e.y,B(t,e),c.transformPoint(e.x,e.y,e),r=e.x,s=e.y,W(t,e),c.transformPoint(e.x,e.y,e),o=e.x,a=e.y,A(t,e),c.transformPoint(e.x,e.y,e),u=e.x,h=e.y;}else L(t,e),i=e.x,n=e.y,B(t,e),r=e.x,s=e.y,W(t,e),o=e.x,a=e.y,A(t,e),u=e.x,h=e.y;return e.x=Math.min(i,r,o,u),e.y=Math.min(n,s,a,h),e.width=Math.max(i,r,o,u)-e.x,e.height=Math.max(n,s,a,h)-e.y,e},D=void 0,L=function(t,e,i){return void 0===e?e=new V:!0===e&&(void 0===I&&(I=new V),e=I),t.getTopLeft?t.getTopLeft(e):(e.x=t.x-T(t)*t.originX,e.y=t.y-G(t)*t.originY,z(t,e,i))},B=function(t,e,i){return void 0===e?e=new V:!0===e&&(void 0===I&&(I=new V),e=I),t.getTopRight?t.getTopRight(e):(e.x=t.x-T(t)*t.originX+T(t),e.y=t.y-G(t)*t.originY,z(t,e,i))},W=function(t,e,i){return void 0===e?e=new V:!0===e&&(void 0===I&&(I=new V),e=I),t.getBottomLeft?t.getBottomLeft(e):(e.x=t.x-T(t)*t.originX,e.y=t.y-G(t)*t.originY+G(t),z(t,e,i))},A=function(t,e,i){return void 0===e?e=new V:!0===e&&(void 0===I&&(I=new V),e=I),t.getBottomRight?t.getBottomRight(e):(e.x=t.x-T(t)*t.originX+T(t),e.y=t.y-G(t)*t.originY+G(t),z(t,e,i))},I=void 0,z=function(t,e,i){(void 0===i&&(i=!1),0!==t.rotation&&C(e,t.x,t.y,t.rotation),i&&t.parentContainer)&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e);return e},H=Phaser.Geom.Rectangle,Q=Phaser.Geom.Rectangle.Union,E=function(e,i){var n=Array.isArray(e);if(void 0===i?i=n?[]:{}:function(e){if("object"!==t(e)||null===e)return e;if(Array.isArray(e))e.length=0;else for(var i in e)delete e[i];}(i),n){i.length=e.length;for(var r=0,s=e.length;r<s;r++)i[r]=e[r];}else for(var o in e)i[o]=e[o];return i},N=Phaser.GameObjects.GameObject,F=Phaser.Utils.Objects.GetValue,q=Phaser.Textures.DynamicTexture,J=Phaser.Utils.String.UUID,K=function(t){if(t){var e,i,n=t.gameObjects,r=t.renderTexture,s=F(t,"x",void 0),o=F(t,"y",void 0),a=F(t,"width",void 0),u=F(t,"height",void 0),h=F(t,"originX",0),c=F(t,"originY",0),l=F(t,"padding",0);if(void 0===a||void 0===u||void 0===s||void 0===o){var f=function(t,e){var i;void 0===e?e=new H:!0===e&&(void 0===_&&(_=new H),e=_),e.setTo(0,0,0,0);for(var n=!0,r=0,s=t.length;r<s;r++)if((i=t[r]).getBounds){var o=U(i,!0);n?(e.setTo(o.x,o.y,o.width,o.height),n=!1):Q(o,e,e);}return e}(n,!0);void 0!==s&&void 0!==o?(a=2*Math.max(s-f.left,f.right-s),u=2*Math.max(o-f.top,f.bottom-o),h=.5,c=.5):(s=f.x,o=f.y,a=f.width,u=f.height,h=0,c=0),e=f.x,i=f.y;}else e=s+(0-h)*a,i=o+(0-c)*u;e-=l,i-=l,a+=2*l,u+=2*l;var d=n[0].scene;y&&!r&&(r=new q(d.sys.textures,J(),a,u)),r||(r=d.add.renderTexture(0,0,a,u)),r.setPosition&&r.setPosition(s,o),r.width===a&&r.height===u||r.setSize(a,u),r.setOrigin&&r.setOrigin(h,c),r.camera.setScroll(e,i),n=function(t,e){if(t.length<=1)return t;var i;void 0===e&&(e=!1);var n=t[0];return (i=n.displayList?n.displayList:n.parentContainer?n.parentContainer.list:n.scene.sys.displayList).depthSort&&(i.depthSort(),i=i.list),e?t.sort((function(t,e){return i.indexOf(e)-i.indexOf(t)})):t.sort((function(t,e){return i.indexOf(t)-i.indexOf(e)})),t}(E(n)),r.draw(n);var y=t.saveTexture;if(y)if(r instanceof N)r.saveTexture(y);else {var v=r,g=v.manager;g.exists(v.key)?g.renameTexture(v.key,key):(v.key=key,g.list[key]=v,g.emit("addtexture",key,v),g.emit("addtexture-".concat(key),v));}return r}},Z=Phaser.Utils.Objects.IsPlainObject,$=Phaser.Utils.Objects.GetValue,tt=function(t){r(o,t);var i=u(o);function o(t,n,r,s,a,u){var h;e(this,o),Z(n)&&(n=$(u=n,"x",0),r=$(u,"y",0),s=$(u,"width",32),a=$(u,"height",32));var c=S(t,s,a);return (h=i.call(this,t,n,r,c,null,u)).type="rexQuadRenderTexture",h.rt=h.texture,h}return n(o,[{key:"destroy",value:function(t){this.scene&&!this.ignoreDestroy&&(h(s(o.prototype),"destroy",this).call(this,t),this.rt.destroy(),this.rt=null);}},{key:"snapshot",value:function(t,e){return void 0===e&&(e={}),e.gameObjects=t,e.renderTexture=this.rt,K(e),this.width===this.frame.realWidth&&this.height===this.frame.realHeight||this.syncSize(),this}}]),o}(P);function et(t,e,i,n,r){var s=new tt(this.scene,t,e,i,n,r);return this.scene.add.existing(s),s}var it=Phaser.Utils.Objects.GetAdvancedValue,nt=Phaser.GameObjects.BuildGameObject;function rt(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=it(t,"x",0),n=it(t,"y",0),r=it(t,"width",32),s=it(t,"height",32),o=new tt(this.scene,i,n,r,s,t);return nt(this.scene,o,t),o}var st=function(t,e,i){void 0===e&&(e=0),void 0===i&&(i=0);for(var n=.5*t.width,r=.5*t.height,s=Math.tan(e)*r,o=Math.tan(i)*n,a=t.controlPoints,u=0,h=a.length;u<h;u++){var c=a[u],l=c.localXOrigin,f=c.localYOrigin;c.localX=l+(f>r?s:-s),c.localY=f+(l>n?o:-o);}},ot=Phaser.Utils.Objects.IsPlainObject,at=Phaser.Utils.Objects.GetValue,ut=Phaser.Math.DegToRad,ht=Phaser.Math.RadToDeg,ct=function(t){r(s,t);var i=u(s);function s(t,n,r,o,a){var u;if(e(this,s),ot(n)){var h=n;n=at(h,"x",0),r=at(h,"y",0),o=at(h,"key",null),a=at(h,"frame",null);}return (u=i.call(this,t,n,r,o,a)).type="rexSkewmage",u._skewX=0,u._skewY=0,u}return n(s,[{key:"skewX",get:function(){return this._skewX},set:function(t){this._skewX=t,st(this,this._skewX,this._skewY);}},{key:"skewXDeg",get:function(){return ht(this._skewX)},set:function(t){this.skewX=ut(t);}},{key:"skewY",get:function(){return this._skewY},set:function(t){this._skewY=t,st(this,this._skewX,this._skewY);}},{key:"skewYDeg",get:function(){return ht(this._skewY)},set:function(t){this.skewY=ut(t);}},{key:"setSkewX",value:function(t){return this.skewX=t,this}},{key:"setSkewY",value:function(t){return this.skewY=t,this}},{key:"setSkew",value:function(t,e){return void 0===e&&(e=t),this.skewX=t,this.skewY=e,this}},{key:"setSkewXDeg",value:function(t){return this.skewXDeg=t,this}},{key:"setSkewYDeg",value:function(t){return this.skewYDeg=t,this}},{key:"setSkewDeg",value:function(t,e){return void 0===e&&(e=t),this.skewXDeg=t,this.skewYDeg=e,this}}]),s}(P);function lt(t,e,i,n){var r=new ct(this.scene,t,e,i,n);return this.scene.add.existing(r),r}var ft=Phaser.Utils.Objects.GetAdvancedValue,dt=Phaser.GameObjects.BuildGameObject;function yt(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=ft(t,"key",null),n=ft(t,"frame",null),r=new ct(this.scene,0,0,i,n);return dt(this.scene,r,t),r}var vt=Phaser.Utils.Objects.IsPlainObject,gt=Phaser.Utils.Objects.GetValue,pt=function(t){r(o,t);var i=u(o);function o(t,n,r,s,a){var u;if(e(this,o),vt(n)){var h=n;n=gt(h,"x",0),r=gt(h,"y",0),s=gt(h,"width",32),a=gt(h,"height",32);}var c=S(t,s,a);return (u=i.call(this,t,n,r,c,null)).type="rexSkewRenderTexture",u.rt=u.texture,u}return n(o,[{key:"destroy",value:function(t){this.scene&&!this.ignoreDestroy&&(h(s(o.prototype),"destroy",this).call(this,t),this.rt.destroy(),this.rt=null);}}]),o}(ct);function xt(t,e,i,n){var r=new pt(this.scene,t,e,i,n);return this.scene.add.existing(r),r}var wt=Phaser.Utils.Objects.GetAdvancedValue,bt=Phaser.GameObjects.BuildGameObject;function mt(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=wt(t,"x",0),n=wt(t,"y",0),r=wt(t,"width",32),s=wt(t,"height",32),o=new pt(this.scene,i,n,r,s);return bt(this.scene,o,t),o}var kt=Phaser.Utils.Objects.GetValue,Pt=function(t,e){if(!t)return !1;for(var i=e.visibleSibling,n=0,r=i.length;n<r;n++)t.setChildVisible(i[n],!0);return i.length=0,t.setChildVisible(e,!1),e.isRunning=!1,!0},Ot=function(t){r(s,t);var i=u(s);function s(){return e(this,s),i.apply(this,arguments)}return n(s,[{key:"skewState",get:function(){return this.isRunning}}]),s}(function(t){r(o,t);var i=u(o);function o(t,n){var r;e(this,o);var s=t.scene;return r=i.call(this,s,0,0,1,1,n),s.add.existing(a(r)),function(t,e,i){e.visibleSibling=[],e.isRunning=!1,e.useParentBounds=kt(i,"useParentBounds",!1),e.setPosition(t.x,t.y).setVisible(!1),t.pin(e);}(t,a(r),n),r}return n(o,[{key:"destroy",value:function(t){this.scene&&!this.ignoreDestroy&&(this.exit(),h(s(o.prototype),"destroy",this).call(this,t));}},{key:"enter",value:function(){return function(t,e){if(!t)return !1;Pt(t,e);var i=e.useParentBounds;K({gameObjects:t.getAllVisibleChildren(),renderTexture:e.rt,x:e.x,y:e.y,width:i?t.displayWidth:void 0,height:i?t.displayHeighth:void 0,originX:i?t.originX:void 0,originY:i?t.originY:void 0}),t.setChildVisible(e,!0);for(var n=e.visibleSibling,r=t.children,s=0,o=r.length;s<o;s++){var a=r[s];a.visible&&a!==e&&(t.setChildVisible(a,!1),n.push(a));}return e.isRunning=!0,!0}(this.rexContainer.parent,this)&&this.syncSize(),this}},{key:"exit",value:function(){return Pt(this.rexContainer.parent,this),this}}]),o}(pt)),jt=function(t){return null==t||""===t||0===t.length},Xt=function(e,i,n,r){if(void 0===r&&(r="."),"object"===t(e)){if(jt(i)){if(null==n)return;"object"===t(n)&&(e=n);}else {"string"==typeof i&&(i=i.split(r));var s=i.pop(),o=function(e,i,n){var r=e;if(jt(i));else {var s;"string"==typeof i&&(i=i.split("."));for(var o=0,a=i.length;o<a;o++){var u;null!=r[s=i[o]]&&"object"===t(r[s])||(u=o===a-1?void 0===n?{}:n:{},r[s]=u),r=r[s];}}return r}(e,i);o[s]=n;}return e}},Yt=function(t){r(s,Phaser.Plugins.BasePlugin);var i=u(s);function s(t){var n;return e(this,s),n=i.call(this,t),t.registerGameObject("rexQuadImage",O,Y),t.registerGameObject("rexQuadRenderTexture",et,rt),t.registerGameObject("rexSkewImage",lt,yt),t.registerGameObject("rexSkewRenderTexture",xt,mt),n}return n(s,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"addContainerSkew",value:function(t,e){return new Ot(t,e)}}]),s}();return Xt(window,"RexPlugins.GameObjects.QuadImage",P),Xt(window,"RexPlugins.GameObjects.QuadRenderTexture",tt),Xt(window,"RexPlugins.GameObjects.SkewImage",ct),Xt(window,"RexPlugins.GameObjects.SkewRenderTexture",pt),Xt(window,"RexPlugins.GameObjects.ContainerSkew",Ot),Yt}));