UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 10.5 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).rexgridalignplugin=e();}(undefined,(function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(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,(r=n.key,o=void 0,"symbol"==typeof(o=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)}(r,"string"))?o:String(o)),n);}var r,o;}function i(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function o(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 function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function s(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,r=n(t);if(e){var s=n(this).constructor;i=Reflect.construct(r,arguments,s);}else i=r.apply(this,arguments);return o(this,i)}}var u=Math.sqrt(3),h=Math.sqrt(3),c=0,f=1,a=2,l=3,d=c,g=f,y=a,v=l,p={},b=c,x=f,w=a,k=l,O={},m={},P=c,_=f,W=a,T=l,X=4/3,Y=2/3,z={},j={},S=function(t,e,i){if(t&&"number"!=typeof t){if(t.hasOwnProperty(e))return t[e];if(-1!==e.indexOf(".")){for(var n=e.split("."),r=t,o=i,s=0;s<n.length;s++){if(!r.hasOwnProperty(n[s])){o=i;break}o=r[n[s]],r=r[n[s]];}return o}return i}return i},M=c,H=f,C=a,R=l,E=function(){function e(i){t(this,e),this.resetFromJSON(i);}return i(e,[{key:"resetFromJSON",value:function(t){this.setType(S(t,"staggeraxis",1),S(t,"staggerindex",1)),this.setDirectionMode(),this.setOriginPosition(S(t,"x",0),S(t,"y",0));var e=S(t,"size",void 0);void 0!==e?this.setCellRadius(e):this.setCellSize(S(t,"cellWidth",0),S(t,"cellHeight",0));}},{key:"setType",value:function(t,e){return "string"==typeof t&&(t=N[t]),"string"==typeof e&&(e=F[e]),this.staggeraxis=t,this.staggerindex=e,this.mode=0===t?0===e?R:C:0===e?H:M,this}},{key:"setDirectionMode",value:function(){return this.directions=6,this}},{key:"setOriginPosition",value:function(t,e){return this.x=t,this.y=e,this}},{key:"width",get:function(){return this._width},set:function(t){this._width=t,this._halfWidth=t/2;}},{key:"height",get:function(){return this._height},set:function(t){this._height=t,this._halfHeight=t/2;}},{key:"setCellSize",value:function(t,e){return this.width=t,this.height=e,this}},{key:"setCellRadius",value:function(t){this.size=t;var e={size:this.size,type:this.staggeraxis},i=function(t){return 0===t.type?2*t.size:u*t.size}(e),n=function(t){return 0===t.type?h*t.size:2*t.size}(e);return this.setCellSize(i,n),this}},{key:"cellWidth",get:function(){return this.width},set:function(t){this.width=t;}},{key:"cellHeight",get:function(){return this.height},set:function(t){this.height=t;}}]),e}(),D={getWorldXY:function(t,e,i){void 0===i?i={}:!0===i&&(i=p);var n=t*this.width,r=e*this.height;switch(this.mode){case d:1&e&&(n+=this._halfWidth),r*=.75;break;case g:1&e&&(n-=this._halfWidth),r*=.75;break;case y:n*=.75,1&t&&(r+=this._halfHeight);break;case v:n*=.75,1&t&&(r-=this._halfHeight);}return n+=this.x,r+=this.y,i.x=n,i.y=r,i},getWorldX:function(t,e){return this.getWorldXY(t,e,!0).x},getWorldY:function(t,e){return this.getWorldXY(t,e,!0).y},getTileXY:function(t,e,i){var n,r;switch(void 0===i?i={}:!0===i&&(i=j),t-=this.x,e-=this.y,this.mode){case P:case _:r=e*X/this.height,n=t/this.width-Y*(e/this.height);break;case W:case T:r=e/this.height-Y*(t/this.width),n=t*X/this.width;}var o=function(t,e,i){return void 0===i?i={}:!0===i&&(i=O),i.x=t,i.y=-t-e,i.z=e,i}(n,r,z);return function(t,e,i,n){"number"!=typeof t&&(t=(n=t).x,e=n.y,i=n.z),void 0===n?n={}:!0===n&&(n=O);var r=Math.round(t),o=Math.round(e),s=Math.round(i),u=Math.abs(r-t),h=Math.abs(o-e),c=Math.abs(s-i);u>h&&u>c?r=-o-s:h>c?o=-r-s:s=-r-o,n.x=r,n.y=o,n.z=s;}(o),function(t,e,i,n,r){switch(void 0===r?r={}:!0===r&&(r=m),t){case b:r.x=e+(n-(1&n))/2,r.y=n;break;case x:r.x=e+(n+(1&n))/2,r.y=n;break;case w:r.x=e,r.y=n+(e-(1&e))/2;break;case k:r.x=e,r.y=n+(e+(1&e))/2;}}(this.mode,o.x,o.y,o.z,i),i},getTileX:function(t,e){return this.getTileXY(t,e,!0).x},getTileY:function(t,e){return this.getTileXY(t,e,!0).y}};Object.assign(E.prototype,D);var N={y:0,x:1},F={even:0,odd:1},q=function(){},J=new Phaser.GameObjects.Zone({sys:{queueDepthSort:q,events:{once:q}}},0,0,1,1);J.setOrigin(0);var B=0,G=1,A=2,U=4,V=6,Z=8,I=10,K=12,L=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},Q=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height},$=function(t){var e=Q(t);return t.y+e-e*t.originY},tt=function(t){var e=L(t);return t.x-e*t.originX+.5*e},et=function(t,e){var i=Q(t);return t.y=e-i+i*t.originY,t},it=function(t,e){var i=L(t),n=i*t.originX;return t.x=e+n-.5*i,t},nt=function(t){var e=L(t);return t.x-e*t.originX},rt=function(t,e){var i=L(t);return t.x=e+i*t.originX,t},ot=function(t){var e=L(t);return t.x+e-e*t.originX},st=function(t,e){var i=L(t);return t.x=e-i+i*t.originX,t},ut=function(t,e){var i=Q(t),n=i*t.originY;return t.y=e+n-.5*i,t},ht=function(t){var e=Q(t);return t.y-e*t.originY+.5*e},ct=function(t){var e=Q(t);return t.y-e*t.originY},ft=function(t,e){var i=Q(t);return t.y=e+i*t.originY,t},at=[];at[11]=function(t,e,i,n){return void 0===i&&(i=0),void 0===n&&(n=0),it(t,tt(e)+i),et(t,$(e)+n),t},at[I]=function(t,e,i,n){return void 0===i&&(i=0),void 0===n&&(n=0),rt(t,nt(e)-i),et(t,$(e)+n),t},at[K]=function(t,e,i,n){return void 0===i&&(i=0),void 0===n&&(n=0),st(t,ot(e)+i),et(t,$(e)+n),t},at[V]=function(t,e,i,n){return void 0===i&&(i=0),void 0===n&&(n=0),function(t,e,i){it(t,e),ut(t,i);}(t,tt(e)+i,ht(e)+n),t},at[U]=function(t,e,i,n){return void 0===i&&(i=0),void 0===n&&(n=0),rt(t,nt(e)-i),ut(t,ht(e)+n),t},at[Z]=function(t,e,i,n){return void 0===i&&(i=0),void 0===n&&(n=0),st(t,ot(e)+i),ut(t,ht(e)+n),t},at[G]=function(t,e,i,n){return void 0===i&&(i=0),void 0===n&&(n=0),it(t,tt(e)+i),ft(t,ct(e)-n),t},at[B]=function(t,e,i,n){return void 0===i&&(i=0),void 0===n&&(n=0),rt(t,nt(e)-i),ft(t,ct(e)-n),t},at[A]=function(t,e,i,n){return void 0===i&&(i=0),void 0===n&&(n=0),st(t,ot(e)+i),ft(t,ct(e)-n),t};var lt=function(t,e,i,n,r){return at[i](t,e,n,r)},dt=Phaser.Utils.Objects.GetFastValue,gt=new E,yt={},vt={},pt=function(){function e(i){t(this,e),this.resetFromJSON(i);}return i(e,[{key:"resetFromJSON",value:function(t){this.setType(S(t,"type",0)),this.setDirectionMode(S(t,"dir",4)),this.setOriginPosition(S(t,"x",0),S(t,"y",0)),this.setCellSize(S(t,"cellWidth",0),S(t,"cellHeight",0));}},{key:"setType",value:function(t){return "string"==typeof t&&(t=xt[t]),this.mode=t,this}},{key:"setDirectionMode",value:function(t){return "string"==typeof t&&(t=wt[t]),this.directions=t,this}},{key:"setOriginPosition",value:function(t,e){return this.x=t,this.y=e,this}},{key:"width",get:function(){return this._width},set:function(t){this._width=t,this._halfWidth=t/2;}},{key:"height",get:function(){return this._height},set:function(t){this._height=t,this._halfHeight=t/2;}},{key:"setCellSize",value:function(t,e){return this.width=t,this.height=e,this}},{key:"cellWidth",get:function(){return this.width},set:function(t){this.width=t;}},{key:"cellHeight",get:function(){return this.height},set:function(t){this.height=t;}}]),e}(),bt={getWorldXY:function(t,e,i){var n,r;switch(void 0===i?i={}:!0===i&&(i=yt),this.mode){case 0:n=t*this.width,r=e*this.height;break;case 1:n=(t-e)*this._halfWidth,r=(t+e)*this._halfHeight;}return n+=this.x,r+=this.y,i.x=n,i.y=r,i},getWorldX:function(t,e){return this.getWorldXY(t,e,!0).x},getWorldY:function(t,e){return this.getWorldXY(t,e,!0).y},getTileXY:function(t,e,i){void 0===i?i={}:!0===i&&(i=vt),t-=this.x,e-=this.y;var n=t/this.width,r=e/this.height;switch(this.mode){case 0:i.x=Math.round(n),i.y=Math.round(r);break;case 1:i.x=Math.round(+n+r),i.y=Math.round(-n+r);}return i},getTileX:function(t,e){return this.getTileXY(t,e,!0).x},getTileY:function(t,e){return this.getTileXY(t,e,!0).y}};Object.assign(pt.prototype,bt);var xt={orthogonal:0,isometric:1,staggered:2},wt={"4dir":4,"8dir":8},kt=Phaser.Utils.Objects.GetFastValue,Ot=new pt;return function(e){!function(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&&r(t,e);}(o,Phaser.Plugins.BasePlugin);var n=s(o);function o(e){return t(this,o),n.call(this,e)}return i(o,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"hexagon",value:function(t,e){return function(t,e){void 0===e&&(e={});var i=dt(e,"width",-1),n=dt(e,"height",-1),r=dt(e,"cellWidth",1),o=dt(e,"cellHeight",r),s=dt(e,"staggeraxis",1),u=dt(e,"staggerindex",1),h=dt(e,"position",Phaser.Display.Align.CENTER),c=dt(e,"x",0),f=dt(e,"y",0);gt.setOriginPosition(c,f).setCellSize(r,o).setType(s,u),J.setSize(r,o);for(var a=n-1,l=i-1,d=0,g=0,y=0,v=t.length;y<v;y++)if(gt.getWorldXY(g,d,J),lt(t[y],J,h),-1===i)d++;else if(-1===n)g++;else if(g===l){if(d===a)break;g=0,d++;}else g++;return t}(t,e)}},{key:"quad",value:function(t,e){return function(t,e){void 0===e&&(e={});var i=kt(e,"width",-1),n=kt(e,"height",-1),r=kt(e,"cellWidth",1),o=kt(e,"cellHeight",r),s=kt(e,"type",0),u=kt(e,"position",Phaser.Display.Align.CENTER),h=kt(e,"x",0),c=kt(e,"y",0);Ot.setOriginPosition(h,c).setCellSize(r,o).setType(s),J.setSize(r,o);for(var f=n-1,a=i-1,l=0,d=0,g=0,y=t.length;g<y;g++)if(Ot.getWorldXY(d,l,J),lt(t[g],J,u),-1===i)l++;else if(-1===n)d++;else if(d===a){if(l===f)break;d=0,l++;}else d++;return t}(t,e)}}]),o}()}));