phaser4-rex-plugins
Version:
35 lines • 146 kB
JavaScript
var t,e;t=void 0,e=function(){class t{constructor(t){this.scene=t,t.sys.events.once("destroy",this.destroy,this)}destroy(){this.scene=null}static register(e,i){t.prototype[e]=i}}function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var i={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,i="~";function s(){}function r(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function n(t,e,s,n,o){if("function"!=typeof s)throw new TypeError("The listener must be a function");var h=new r(s,n||t,o),a=i?i+e:e;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],h]:t._events[a].push(h):(t._events[a]=h,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function h(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),h.prototype.eventNames=function(){var t,s,r=[];if(0===this._eventsCount)return r;for(s in t=this._events)e.call(t,s)&&r.push(i?s.slice(1):s);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},h.prototype.listeners=function(t){var e=i?i+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var r=0,n=s.length,o=new Array(n);r<n;r++)o[r]=s[r].fn;return o},h.prototype.listenerCount=function(t){var e=i?i+t:t,s=this._events[e];return s?s.fn?1:s.length:0},h.prototype.emit=function(t,e,s,r,n,o){var h=i?i+t:t;if(!this._events[h])return!1;var a,l,u=this._events[h],c=arguments.length;if(u.fn){switch(u.once&&this.removeListener(t,u.fn,void 0,!0),c){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,e),!0;case 3:return u.fn.call(u.context,e,s),!0;case 4:return u.fn.call(u.context,e,s,r),!0;case 5:return u.fn.call(u.context,e,s,r,n),!0;case 6:return u.fn.call(u.context,e,s,r,n,o),!0}for(l=1,a=new Array(c-1);l<c;l++)a[l-1]=arguments[l];u.fn.apply(u.context,a)}else{var d,v=u.length;for(l=0;l<v;l++)switch(u[l].once&&this.removeListener(t,u[l].fn,void 0,!0),c){case 1:u[l].fn.call(u[l].context);break;case 2:u[l].fn.call(u[l].context,e);break;case 3:u[l].fn.call(u[l].context,e,s);break;case 4:u[l].fn.call(u[l].context,e,s,r);break;default:if(!a)for(d=1,a=new Array(c-1);d<c;d++)a[d-1]=arguments[d];u[l].fn.apply(u[l].context,a)}}return!0},h.prototype.on=function(t,e,i){return n(this,t,e,i,!1)},h.prototype.once=function(t,e,i){return n(this,t,e,i,!0)},h.prototype.removeListener=function(t,e,s,r){var n=i?i+t:t;if(!this._events[n])return this;if(!e)return o(this,n),this;var h=this._events[n];if(h.fn)h.fn!==e||r&&!h.once||s&&h.context!==s||o(this,n);else{for(var a=0,l=[],u=h.length;a<u;a++)(h[a].fn!==e||r&&!h[a].once||s&&h[a].context!==s)&&l.push(h[a]);l.length?this._events[n]=1===l.length?l[0]:l:o(this,n)}return this},h.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&o(this,e)):(this._events=new s,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=i,h.EventEmitter=h,t.exports=h}(i);var s=e(i.exports);class r extends s{shutdown(){this.removeAllListeners()}destroy(){this.removeAllListeners()}}var n=function(t,e,i){if(!t||"number"==typeof t)return i;if("string"==typeof e){if(t.hasOwnProperty(e))return t[e];if(-1===e.indexOf("."))return i;e=e.split(".")}for(var s=e,r=t,n=i,o=0;o<s.length;o++){if(e=s[o],!r.hasOwnProperty(e)){n=i;break}r=n=r[e]}return n},o=new class{constructor(t){this.nextId=n(t,"start",1),this.uidKey=n(t,"uidKey","$uid"),this.autoRemove=n(t,"remove",!0),this.refs={},this.count=0}add(t,e){var i=this.refs,s=this.uidKey;if(s&&t.hasOwnProperty("uidKey")&&null!=t[s])return this;if(null==e)do{e=this.nextId,this.nextId++}while(i.hasOwnProperty(e));return i.hasOwnProperty(e)?e=null:(i[e]=t,this.count++,s&&(t[s]=e),this.autoRemove&&t.on&&t.once("destroy",(function(){this.remove(e)}),this)),s?this:e}addMultiple(t){for(var e=0,i=t.length;e<i;e++)this.add(t[e]);return this}get(t){return this.refs[t]}has(t){return this.refs.hasOwnProperty(t)}remove(t){var e=this.refs;return e.hasOwnProperty(t)&&(this.uidKey&&(e[t][this.uidKey]=void 0),delete e[t],this.count--),this}forEach(t,e){var i,s=this.refs;for(var r in s)i=s[r],e?t.call(e,i,r):t(i,r)}clear(){this.forEach((function(t){this.remove(t)}),this)}}({uidKey:"$uid",remove:!1}),h={setEventEmitter(t,e){return void 0===e&&(e=Phaser.Events.EventEmitter),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter(){return this._eventEmitter},on(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}};const a=Phaser.Scene;var l=function(t){return t instanceof a},u=function(t){return null==t||"object"!=typeof t?null:l(t)?t:t.scene&&l(t.scene)?t.scene:t.parent&&t.parent.scene&&l(t.parent.scene)?t.parent.scene:null};const c=Phaser.Game;var d=function(t){return t instanceof c},v=function(t){return null==t||"object"!=typeof t?null:d(t)?t:d(t.game)?t.game:l(t)?t.sys.game:l(t.scene)?t.scene.sys.game:void 0};const f=Phaser.Utils.Objects.GetValue;class p{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(f(e,"eventEmitter",!0)),this.parent&&(this.parent===this.scene?this.scene.sys.events.once("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.once("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.once("destroy",this.onParentDestroy,this))}shutdown(t){this.isShutdown||(this.parent&&(this.parent===this.scene?this.scene.sys.events.off("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.off("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.off("destroy",this.onParentDestroy,this)),this.destroyEventEmitter(),this.parent=void 0,this.scene=void 0,this.game=void 0,this.isShutdown=!0)}destroy(t){this.shutdown(t)}onEnvDestroy(){this.destroy(!0)}onParentDestroy(t,e){this.destroy(e)}setParent(t){return this.parent=t,this.scene=u(t),this.game=v(t),this}}Object.assign(p.prototype,h);var g={x:0,y:0},y=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};const m=o.uidKey;class b extends p{constructor(t,e){super(t,{eventEmitter:!1}),o.add(this,e),this.board=null,this.blocker=!1}shutdown(t){this.isShutdown||(this.board&&this.board.removeChess(this[m]),o.remove(this[m]),this.board=null,super.shutdown(t))}setBoard(t){return this.board=t,this}get tileXYZ(){return null==this.board?null:this.board.chessToTileXYZ(this[m])}setTileZ(t){return null==this.board||this.board.setChessTileZ(this.parent,t),this}setBlocker(t){return void 0===t&&(t=!0),this.blocker=t,this}setBlockEdge(t,e){!1===this.blocker&&(this.blocker={});var i=this.blocker;if(y(t)){var s=t;for(t in s)i[t]=s[t]}else void 0===e&&(e=!0),i[t]=e;return this}getBlockEdge(t){var e=this.blocker;return!1!==e&&!!e.hasOwnProperty(t)&&e[t]}}var T={getTileDirection:function(t,e){var i=this.board;return null===i?null:(g.x=t,g.y=e,i.getNeighborTileDirection(this.tileXYZ,g))}};Object.assign(b.prototype,T);var x=function(t){var e=typeof t;return"number"===e||"string"===e},w=function(t){return x(t)?o.get(t):(t.hasOwnProperty("rexChess")&&t.rexChess||(t.rexChess=new b(t)),t.rexChess)};const C=o.uidKey;var Y=function(t){return x(t)?t:w(t)[C]},X=function(t,e,i){return void 0===i&&(i=","),`${t}${i}${e}`},M={},P={},k=function(t,e,i,s){return Math.atan2(s-e,i-t)},S=function(t){return(t%=2*Math.PI)>=0?t:t+2*Math.PI};const D=2*Math.PI;var E={x:0,y:0},O=180/Math.PI,_=function(t){return t*O},A=function(t,e,i){if(t&&"number"!=typeof t){i=e;var s=this.chessToTileXYZ(t);t=s.x,e=s.y}return this.grid.getGridPoints(t,e,i)};function R(t,e,i){var s=i?t[e]:Object.getOwnPropertyDescriptor(t,e);return!i&&s.value&&"object"==typeof s.value&&(s=s.value),!(!s||!
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
function(t){return!!t.get&&"function"==typeof t.get||!!t.set&&"function"==typeof t.set}(s))&&(void 0===s.enumerable&&(s.enumerable=!0),void 0===s.configurable&&(s.configurable=!0),s)}function B(t,e){var i=Object.getOwnPropertyDescriptor(t,e);return!!i&&(i.value&&"object"==typeof i.value&&(i=i.value),!1===i.configurable)}function L(t,e,i,s){for(var r in e)if(e.hasOwnProperty(r)){var n=R(e,r,i);if(!1!==n){if(B((s||t).prototype,r)){if(F.ignoreFinals)continue;throw new Error("cannot override final property '"+r+"', set Class.ignoreFinals = true to skip")}Object.defineProperty(t.prototype,r,n)}else t.prototype[r]=e[r]}}function N(t,e){if(e){Array.isArray(e)||(e=[e]);for(var i=0;i<e.length;i++)L(t,e[i].prototype||e[i])}}function F(t){var e,i;if(t||(t={}),t.initialize){if("function"!=typeof t.initialize)throw new Error("initialize must be a function");e=t.initialize,delete t.initialize}else if(t.Extends){var s=t.Extends;e=function(){s.apply(this,arguments)}}else e=function(){};t.Extends?(e.prototype=Object.create(t.Extends.prototype),e.prototype.constructor=e,i=t.Extends,delete t.Extends):e.prototype.constructor=e;var r=null;return t.Mixins&&(r=t.Mixins,delete t.Mixins),N(e,r),L(e,t,!0,i),e}F.extend=L,F.mixin=N,F.ignoreFinals=!1;
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var I=function(t){return 2*(t.width+t.height)},Z=new F({initialize:function(t,e){void 0===t&&(t=0),void 0===e&&(e=t),this.x=t,this.y=e},setTo:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.x=t,this.y=e,this}}),j=function(t,e,i){if(void 0===i&&(i=new Z),e<=0||e>=1)return i.x=t.x,i.y=t.y,i;var s=I(t)*e;return e>.5?(s-=t.width+t.height)<=t.width?(i.x=t.right-s,i.y=t.bottom):(i.x=t.x,i.y=t.bottom-(s-t.width)):s<=t.width?(i.x=t.x+s,i.y=t.y):(i.x=t.right,i.y=t.y+(s-t.width)),i},z=function(t,e,i,s){void 0===s&&(s=[]),e||(e=function(t){return Math.sqrt((t.x2-t.x1)*(t.x2-t.x1)+(t.y2-t.y1)*(t.y2-t.y1))}(t)/i);for(var r=t.x1,n=t.y1,o=t.x2,h=t.y2,a=0;a<e;a++){var l=a/e,u=r+(o-r)*l,c=n+(h-n)*l;s.push(new Z(u,c))}return s},G=new F({initialize:function(t,e){this.x=0,this.y=0,"object"==typeof t?(this.x=t.x||0,this.y=t.y||0):(void 0===e&&(e=t),this.x=t||0,this.y=e||0)},clone:function(){return new G(this.x,this.y)},copy:function(t){return this.x=t.x||0,this.y=t.y||0,this},setFromObject:function(t){return this.x=t.x||0,this.y=t.y||0,this},set:function(t,e){return void 0===e&&(e=t),this.x=t,this.y=e,this},setTo:function(t,e){return this.set(t,e)},setToPolar:function(t,e){return null==e&&(e=1),this.x=Math.cos(t)*e,this.y=Math.sin(t)*e,this},equals:function(t){return this.x===t.x&&this.y===t.y},angle:function(){var t=Math.atan2(this.y,this.x);return t<0&&(t+=2*Math.PI),t},add:function(t){return this.x+=t.x,this.y+=t.y,this},subtract:function(t){return this.x-=t.x,this.y-=t.y,this},multiply:function(t){return this.x*=t.x,this.y*=t.y,this},scale:function(t){return isFinite(t)?(this.x*=t,this.y*=t):(this.x=0,this.y=0),this},divide:function(t){return this.x/=t.x,this.y/=t.y,this},negate:function(){return this.x=-this.x,this.y=-this.y,this},distance:function(t){var e=t.x-this.x,i=t.y-this.y;return Math.sqrt(e*e+i*i)},distanceSq:function(t){var e=t.x-this.x,i=t.y-this.y;return e*e+i*i},length:function(){var t=this.x,e=this.y;return Math.sqrt(t*t+e*e)},lengthSq:function(){var t=this.x,e=this.y;return t*t+e*e},normalize:function(){var t=this.x,e=this.y,i=t*t+e*e;return i>0&&(i=1/Math.sqrt(i),this.x=t*i,this.y=e*i),this},normalizeRightHand:function(){var t=this.x;return this.x=-1*this.y,this.y=t,this},dot:function(t){return this.x*t.x+this.y*t.y},cross:function(t){return this.x*t.y-this.y*t.x},lerp:function(t,e){void 0===e&&(e=0);var i=this.x,s=this.y;return this.x=i+e*(t.x-i),this.y=s+e*(t.y-s),this},transformMat3:function(t){var e=this.x,i=this.y,s=t.val;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[7],this},transformMat4:function(t){var e=this.x,i=this.y,s=t.val;return this.x=s[0]*e+s[4]*i+s[12],this.y=s[1]*e+s[5]*i+s[13],this},reset:function(){return this.x=0,this.y=0,this}});
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/G.ZERO=new G,G.RIGHT=new G(1,0),G.LEFT=new G(-1,0),G.UP=new G(0,-1),G.DOWN=new G(0,1),G.ONE=new G(1,1);
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var U=new F({initialize:function(t,e,i,s){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=0),this.x1=t,this.y1=e,this.x2=i,this.y2=s},getPoint:function(t,e){return function(t,e,i){return void 0===i&&(i=new Z),i.x=t.x1+(t.x2-t.x1)*e,i.y=t.y1+(t.y2-t.y1)*e,i}(this,t,e)},getPoints:function(t,e,i){return z(this,t,e,i)},getRandomPoint:function(t){return function(t,e){void 0===e&&(e=new Z);var i=Math.random();return e.x=t.x1+i*(t.x2-t.x1),e.y=t.y1+i*(t.y2-t.y1),e}(this,t)},setTo:function(t,e,i,s){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=0),this.x1=t,this.y1=e,this.x2=i,this.y2=s,this},getPointA:function(t){return void 0===t&&(t=new G),t.set(this.x1,this.y1),t},getPointB:function(t){return void 0===t&&(t=new G),t.set(this.x2,this.y2),t},left:{get:function(){return Math.min(this.x1,this.x2)},set:function(t){this.x1<=this.x2?this.x1=t:this.x2=t}},right:{get:function(){return Math.max(this.x1,this.x2)},set:function(t){this.x1>this.x2?this.x1=t:this.x2=t}},top:{get:function(){return Math.min(this.y1,this.y2)},set:function(t){this.y1<=this.y2?this.y1=t:this.y2=t}},bottom:{get:function(){return Math.max(this.y1,this.y2)},set:function(t){this.y1>this.y2?this.y1=t:this.y2=t}}}),W=new F({initialize:function(t,e,i,s){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=0),this.x=t,this.y=e,this.width=i,this.height=s},contains:function(t,e){return function(t,e,i){return!(t.width<=0||t.height<=0)&&t.x<=e&&t.x+t.width>=e&&t.y<=i&&t.y+t.height>=i}(this,t,e)},getPoint:function(t,e){return j(this,t,e)},getPoints:function(t,e,i){return function(t,e,i,s){void 0===s&&(s=[]),e||(e=I(t)/i);for(var r=0;r<e;r++){var n=r/e;s.push(j(t,n))}return s}(this,t,e,i)},getRandomPoint:function(t){return e=this,void 0===(i=t)&&(i=new Z),i.x=e.x+Math.random()*e.width,i.y=e.y+Math.random()*e.height,i;var e,i},setTo:function(t,e,i,s){return this.x=t,this.y=e,this.width=i,this.height=s,this},setEmpty:function(){return this.setTo(0,0,0,0)},setPosition:function(t,e){return void 0===e&&(e=t),this.x=t,this.y=e,this},setSize:function(t,e){return void 0===e&&(e=t),this.width=t,this.height=e,this},isEmpty:function(){return this.width<=0||this.height<=0},getLineA:function(t){return void 0===t&&(t=new U),t.setTo(this.x,this.y,this.right,this.y),t},getLineB:function(t){return void 0===t&&(t=new U),t.setTo(this.right,this.y,this.right,this.bottom),t},getLineC:function(t){return void 0===t&&(t=new U),t.setTo(this.right,this.bottom,this.x,this.bottom),t},getLineD:function(t){return void 0===t&&(t=new U),t.setTo(this.x,this.bottom,this.x,this.y),t},left:{get:function(){return this.x},set:function(t){t>=this.right?this.width=0:this.width=this.right-t,this.x=t}},right:{get:function(){return this.x+this.width},set:function(t){t<=this.x?this.width=0:this.width=t-this.x}},top:{get:function(){return this.y},set:function(t){t>=this.bottom?this.height=0:this.height=this.bottom-t,this.y=t}},bottom:{get:function(){return this.y+this.height},set:function(t){t<=this.y?this.height=0:this.height=t-this.y}},centerX:{get:function(){return this.x+this.width/2},set:function(t){this.x=t-this.width/2}},centerY:{get:function(){return this.y+this.height/2},set:function(t){this.y=t-this.height/2}}}),V=new W,J=function(t){for(var e=[],i=0,s=t.length;i<s;i++)e.push(H(t[i],t[(i+1)%s]));return e},H=function(t,e){var i=[t,e];return i=i.sort((function(t,e){return t.x===e.x?t.y-e.y:t.x-e.x}))};
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/class ${constructor(){this.nodes=new Map}addEdges(t){for(var e=0,i=t.length;e<i;e++)this.addEdge(t[e]);return this}addEdge(t){var e=this.nodes,[i,s]=t,r=tt(i),n=tt(s);return e.has(r)||e.set(r,[]),e.get(r).push(n),e.has(n)||e.set(n,[]),e.get(n).push(r),this}findCycle(t){"string"!=typeof t&&(t=tt(t));for(var e=this.nodes,i=[t],s=new Set,r=[{current:t,nextIndex:0}];r.length>0;){var n=r[r.length-1],o=n.current,h=e.get(o);if(n.nextIndex>=h.length)i.pop(),r.pop();else{var a=h[n.nextIndex];n.nextIndex+=1;var l=[o,a].sort().join("->");if(!s.has(l)){if(a===t&&i.length>2)return i.map(et);i.includes(a)||(s.add(l),r.push({current:a,nextIndex:0}),i.push(a))}}}return[]}}var K,q,Q,tt=function(t){return`${t.x},${t.y}`},et=function(t){var[e,i]=t.split(",").map(Number);return{x:e,y:i}},it=function(t,e,i){return(e-t)*i+t},st=function(t,e){return t&&e&&t.x===e.x&&t.y===e.y},rt=function(t,e,i,s,r){var n=t.tileXYToWorldXY(i,s,!0);if(e.contains(n.x,n.y))return!0;switch(r){case 1:var o=t.getGridBounds(i,s,!0);return nt(e,o);case 2:var h=t.getGridPoints(i,s,!0);return ot(e,h);default:return!1}},nt=function(t,e){var i=e.top,s=e.bottom,r=e.left,n=e.right;return!!(t.contains(r,i)||t.contains(r,s)||t.contains(n,i)||t.contains(n,s))},ot=function(t,e){for(var i=0,s=e.length;i<s;i++){var r=e[i];if(t.contains(r.x,r.y))return!0}return!1},ht=function(t,e,i,s,r){if(!this.contains(e,i))return this;void 0===r&&(r=!0);var n=this.chessToTileXYZ(t);if(void 0===s&&(s=n?n.z:0),n&&n.x===e&&n.y===i&&n.z===s)return this;var o=this.tileXYZToChess(e,i,s);return o&&this.emit("kickout",t,o,n),this.removeChess(t),o&&this.removeChess(o,e,i,s),this.boardData.addUID(this.getChessUID(t),e,i,s),this.isBoard&&this.getChessData(t).setBoard(this),r&&this.gridAlign(t,e,i),this},at=function(t,e,i){return Math.max(e,Math.min(i,t))},lt={x:0,y:0},ut=function(t,e,i){var s=i-e;return e+((t-e)%s+s)%s},ct={},dt={},vt={},ft={},pt=function(t,e){return Math.floor(Math.random()*(e-t+1)+t)},gt=function(t,e,i){void 0===e&&(e=0),void 0===i&&(i=t.length);var s=e+Math.floor(Math.random()*i);return void 0===t[s]?null:t[s]},yt=[],mt={},bt=[],Tt=function(t){for(var e=t.length-1;e>0;e--){var i=Math.floor(Math.random()*(e+1)),s=t[e];t[e]=t[i],t[i]=s}return t},xt=[],wt={},Ct=[],Yt=[],Xt=[],Mt=[],Pt=function(t){return"[object Array]"===Object.prototype.toString.call(t)},kt=[],St=function(t,e){return!1===t||!0===t?t:!0===t[e]},Dt=[],Et=function(t){return t?t.rexChess?t.rexChess.board:t.mainBoard?t.mainBoard:void 0:void 0},Ot={getChessData:w,getChessUID:Y,setBoardWidth:function(t){if(this.infinityMode)return this;if(void 0===this.width||this.width<=t)return this.width=t,this;var e,i,s;for(e=t;e<this.width;e++)for(i=0;i<this.height;i++)for(s in this.boardData.getUID(e,i))this.RemoveChess(!1,e,i,s);return this.width=t,this},setBoardHeight:function(t){if(this.infinityMode)return this;if(void 0===this.height||this.height<=t)return this.height=t,this;var e,i,s;for(i=t;i<this.height;i++)for(e=0;e<this.width;e++)for(s in this.boardData.getUID(e,i))this.RemoveChess(!1,e,i,s);return this.height=t,this},tileXYZToKey:function(t,e,i,s){return void 0===s&&(s=","),`${t}${s}${e}${s}${i}`},tileXYToKey:X,keyToTileXYZ:function(t,e,i){void 0===e?e={}:!0===e&&(e=M),void 0===i&&(i=",");var s=t.split(i);return e.x=s[0],e.y=s[1],e.z=s[2],e},tileXYToWorldX:function(t,e){return this.tileXYToWorldXY(t,e,!0).x},tileXYToWorldY:function(t,e){return this.tileXYToWorldXY(t,e,!0).y},tileXYToWorldXY:function(t,e,i){return this.grid.getWorldXY(t,e,i)},tileXYArrayToWorldXYArray:function(t,e){var i;void 0===e&&(e=[]);for(var s=0,r=t.length;s<r;s++)i=t[s],e.push(this.tileXYToWorldXY(i.x,i.y));return e},worldXYToTileX:function(t,e){return this.worldXYToTileXY(t,e,!0).x},worldXYToTileY:function(t,e){return this.worldXYToTileXY(t,e,!0).y},worldXYToTileXY:function(t,e,i){return this.grid.getTileXY(t,e,i)},worldXYToChessArray:function(t,e,i){var s=this.worldXYToTileXY(t,e,!0);return this.tileXYToChessArray(s.x,s.y,i)},worldXYToChess:function(t,e,i){var s=this.worldXYToTileXY(t,e,!0);if(void 0!==i)return this.tileXYZToChess(s.x,s.y,i);var r=this.boardData.getUID(s.x,s.y);if(null==r)return null;for(var i in r)return this.uidToChess(r[i])},worldXYSnapToGrid:function(t,e,i){return void 0===i?i={}:!0===i&&(i=P),this.worldXYToTileXY(t,e,i),this.tileXYToWorldXY(i.x,i.y,i),i},angleBetween:function(t,e){t=this.chessToTileXYZ(t),e=this.chessToTileXYZ(e);var i=this.tileXYToWorldXY(t.x,t.y,!0),s=i.x,r=i.y,n=(i=this.tileXYToWorldXY(e.x,e.y,!0)).x,o=i.y;return k(s,r,n,o)},isAngleInCone:function(t,e,i,s){var r=this.chessToTileXYZ(t),n=this.chessToTileXYZ(e),o=this.angleBetween(r,n);o=S(o);var h=Math.abs(o-i);h=Math.min(h,D-h);var a,l,u,c=s/2;return a=h,l=c,void 0===u&&(u=1e-4),Math.abs(a-l)<u||h<c},angleToward:function(t,e){void 0===t&&(t=E);var i=this.wrapMode,s=this.infinityMode;this.wrapMode=!1,this.infinityMode=!0;var r=this.getNeighborTileXY(t,e,!0);return this.wrapMode=i,this.infinityMode=s,this.angleBetween(t,r)},angleSnapToDirection:function(t,e){e=_(e);for(var i,s,r,n=this.grid.allDirections,o=1/0,h=void 0,a=0,l=n.length;a<l;a++)i=_(this.angleToward(t,n[a])),(s=Math.abs((r=void 0,0==(r=i-e)?0:r-360*Math.floor((r- -180)/360))))<o&&(o=s,h=a);return h},isOverlappingPoint:function(t,e,i){if(this.infinityMode&&void 0===i)return!0;var s=this.worldXYToTileXY(t,e,!0);return this.contains(s.x,s.y,i)},gridAlign:function(t,e,i){if(void 0===t)for(var s=this.getAllChess(),r=0,n=s.length;r<n;r++)this.gridAlign(s[r]);else{if(x(t)&&(t=this.uidToChess(t)),void 0===e){var o=this.chessToTileXYZ(t);e=o.x,i=o.y}this.tileXYToWorldXY(e,i,t)}return this},getGridPoints:A,getGridBounds:function(t,e,i){if(t&&"number"!=typeof t){i=e;var s=this.chessToTileXYZ(t);t=s.x,e=s.y}return this.grid.getBounds(t,e,i)},getBoardBounds:function(t){void 0===t?t=new W:!0===t&&(t=V);var e=!0;return this.forEachTileXY((function(i,s){var r=s.getGridBounds(i.x,i.y,!0);e?(t.setTo(r.x,r.y,r.width,r.height),e=!1):t=function(t,e,i){void 0===i&&(i=new W);var s=Math.min(t.x,e.x),r=Math.min(t.y,e.y),n=Math.max(t.right,e.right)-s,o=Math.max(t.bottom,e.bottom)-r;return i.setTo(s,r,n,o)}(t,r,t)})),t},getBoundaryPoints:function(t,e){var i=function(t,e){var i=[];if(void 0===e)t.forEachTileXY((function(t,e){i.push({x:t.x,y:t.y})}));else{if("number"==typeof e){var s=e;e=t.tileZToChessArray(s)}for(var r=0,n=e.length;r<n;r++)i.push(t.chessToTileXYZ(e[r]))}return i}(this,t),s=function(t,e){var i=new Map;return e.forEach((function(e){var s=t.getGridPoints(e.x,e.y,!0);J(s).forEach((function(t){var e=JSON.stringify(t);i.set(e,(i.get(e)||0)+1)}))})),Array.from(i.entries()).filter((function(t){return 1===t[1]})).map((function(t){return JSON.parse(t[0])}))}(this,i);return e=function(t,e){void 0===e&&(e=[]);var i=new Map;t.forEach((function(t){i.set(JSON.stringify(t),t)}));var s=new $;for(s.addEdges(t);t.length;){var r=t[0],n=s.findCycle(r[0]);e.push(n),J(n).forEach((function(t){i.delete(JSON.stringify(t))})),t=[...i.values()]}return e}(s,e),e},lineToTileXYArray:function(t,e,i,s,r){if("number"!=typeof t){var n=t;r=e,t=n.x1,e=n.y1,i=n.x2,s=n.y2}void 0===r&&(r=[]);for(var o,h,a,l,u,c,d,v=(o=t-i,h=e-s,Math.sqrt(o*o+h*h)),f=Math.min(this.grid.cellWidth,this.grid.cellHeight),p=Math.ceil(v/(f/4)),g=0;g<=p;g++)l=it(t,i,a=g/p),u=it(e,s,a),d=this.worldXYToTileXY(l,u),this.contains(d.x,d.y)&&(c&&st(c,d)||(r.push(d),c=d));return r},circleToTileXYArray:function(t,e,i){return this.shapeToTileXYArray(t,e,i)},ellipseToTileXYArray:function(t,e,i){return this.shapeToTileXYArray(t,e,i)},polygonToTileXYArray:function(t,e,i){Array.isArray(e)&&(i=e,e=void 0),K=function(t,e){void 0===e&&(e=new W);for(var i,s=1/0,r=1/0,n=-s,o=-r,h=0;h<t.points.length;h++)i=t.points[h],s=Math.min(s,i.x),r=Math.min(r,i.y),n=Math.max(n,i.x),o=Math.max(o,i.y);return e.x=s,e.y=r,e.width=n-s,e.height=o-r,e}(t,K);var s={testMode:e,searchRectangle:K};return this.shapeToTileXYArray(t,s,i)},rectangleToTileXYArray:function(t,e,i){return this.shapeToTileXYArray(t,e,i)},triangleToTileXYArray:function(t,e,i){return this.shapeToTileXYArray(t,e,i)},shapeToTileXYArray:function(t,e,i){return"number"==typeof e&&(e={testMode:e}),Array.isArray(e)&&(i=e,e=void 0),void 0===i&&(i=[]),this.forEachTileXYInShape(t,(function(t){i.push({x:t.x,y:t.y})}),void 0,e),i},forEachTileXYInShape:function(t,e,i,s){var r=n(s,"testMode",0),o=n(s,"searchRectangle",t);n(s,"order",0),i&&(e=e.bind(i)),q=this.worldXYToTileXY(o.left,o.top,q),Q=this.worldXYToTileXY(o.right,o.bottom,Q);var h=q.x-1,a=q.y-1,l=Q.x+1,u=Q.y+1;return this.forEachTileXY((function(i,s){if(rt(s,t,i.x,i.y,r))return e(i,s)}),this,{left:h,right:l,top:a,bottom:u}),this},uidToChess:function(t){return null==t?null:this.boardData.exists(t)?o.get(t).parent:null},addChess:ht,removeChess:function(t,e,i,s,r,n){if(void 0===r&&(r=!1),void 0===n&&(n=!1),t){var o=this.chessToTileXYZ(t);if(!o)return this;e=o.x,i=o.y,s=o.z}else if(!(t=this.tileXYZToChess(e,i,s)))return this;return n||this.boardData.removeUID(e,i,s),this.isBoard&&this.getChessData(t).setBoard(null),r&&t.destroy&&t.destroy(),this},removeAllChess:function(t,e){for(var i=this.getAllChess(),s=0,r=i.length;s<r;s++)this.removeChess(i[s],void 0,void 0,void 0,t,e);return this},swapChess:function(t,e,i){void 0===i&&(i=!0);var s=this.chessToTileXYZ(t),r=this.chessToTileXYZ(e);return null==s||null==r||(this.removeChess(t),this.removeChess(e),this.addChess(t,r.x,r.y,r.z,i),this.addChess(e,s.x,s.y,s.z,i)),this},moveChess:ht,setChessTileZ:function(t,e,i){void 0===i&&(i=!1);var s=this.chessToTileXYZ(t);return s&&this.moveChess(t,s.x,s.y,e,i),this},getAllChess:function(t){void 0===t&&(t=[]);var e=this.boardData.UIDToXYZ;for(var i in e)t.push(this.uidToChess(i));return t},contains:function(t,e,i){var s;return(s=!!this.infinityMode||t>=0&&t<this.width&&e>=0&&e<this.height)&&void 0!==i&&(s=this.boardData.contains(t,e,i)),s},forEachTileXY:function(t,e,i){"number"==typeof i&&(i={order:i});var s,r,o,h,a=n(i,"order",0);if(this.infinityMode&&void 0===this.width){var l=this.boardData.getBounds();o=l.left,h=l.right,s=l.top,r=l.bottom}else{var u=this.width-1,c=this.height-1;o=at(n(i,"left",0),0,u),h=at(n(i,"right",u),0,u),s=at(n(i,"top",0),0,c),r=at(n(i,"bottom",c),0,c)}switch(a){case 0:for(var d=s;d<=r;d++)for(var v=o;v<=h&&(lt.x=v,lt.y=d,!(e?t.call(e,lt,this):t(lt,this)));v++);break;case 1:for(d=s;d<=r;d++)for(v=h;v>=o&&(lt.x=v,lt.y=d,!(e?t.call(e,lt,this):t(lt,this)));v--);break;case 2:for(v=o;v<=h;v++)for(d=s;d<=r&&(lt.x=v,lt.y=d,!(e?t.call(e,lt,this):t(lt,this)));d++);break;case 3:for(v=o;v<=h;v++)for(d=r;d>=s&&(lt.x=v,lt.y=d,!(e?t.call(e,lt,this):t(lt,this)));d--);}return this},getWrapTileXY:function(t,e,i){return void 0===i?i={}:!0===i&&(i=ct),this.wrapMode?t=ut(t,0,this.width):!this.infinityMode&&(t<0||t>=this.width)&&(t=null),this.wrapMode?e=ut(e,0,this.height):!this.infinityMode&&(e<0||e>=this.height)&&(e=null),i.x=t,i.y=e,i},tileXYZToChess:function(t,e,i){var s=this.boardData.getUID(t,e,i);return this.uidToChess(s)},tileXYToChessArray:function(t,e,i){void 0===i&&(i=[]);var s=this.boardData.getUID(t,e);if(null==s)return i;for(var r in s)i.push(this.uidToChess(s[r]));return i},tileZToChessArray:function(t,e){void 0===e&&(e=[]);var i=this.boardData.UIDToXYZ;for(var s in i)i[s].z===t&&e.push(this.uidToChess(s));return e},tileXYArrayToChessArray:function(t,e,i){Array.isArray(e)&&(i=e,e=void 0),void 0===i&&(i=[]);for(var s,r=null!=e,n=0,o=t.length;n<o;n++)s=t[n],r?i.push(this.tileXYZToChess(s.x,s.y,e)):this.tileXYToChessArray(s.x,s.y,i);return i},chessToTileXYZ:function(t){if(!t)return null;if(x(t)||function(t){return!x(t)&&t&&!!t.rexChess}(t)){var e=Y(t);return this.boardData.getXYZ(e)}return(i=t)&&(y(i)||i.isTileXYZ)?t:null;var i},offset:function(t,e,i,s){return void 0===s?s={}:!0===s&&(s=dt),0===e&&0===i?(s.x=t.x,s.y=t.y):this.grid.offset(t,e,i,s),s},mirror:function(t,e,i,s){return void 0===s?s={}:!0===s&&(s=vt),void 0!==i?this.offset(t,-i.x,-i.y,s):(s.x=t.x,s.y=t.y),this.grid.mirror(s,e,s),void 0!==i&&this.offset(s,i.x,i.y,s),s},rotate:function(t,e,i,s){return void 0===s?s={}:!0===s&&(s=ft),void 0!==i?this.offset(t,-i.x,-i.y,s):(s.x=t.x,s.y=t.y),this.grid.rotate(s,e,s),void 0!==i&&this.offset(s,i.x,i.y,s),s},getOppositeDirection:function(t,e,i){if(t&&"number"!=typeof t){i=e;var s=t,r=this.chessToTileXYZ(s);t=r.x,e=r.y}return this.grid.getOppositeDirection(t,e,i)},getDistance:function(t,e,i){return t=this.chessToTileXYZ(t),e=this.chessToTileXYZ(e),this.grid.getDistance(t,e,i)},directionBetween:function(t,e,i){void 0===i&&(i=!0);var s=this.chessToTileXYZ(t),r=this.chessToTileXYZ(e);return this.grid.directionBetween(s,r,i)},isDirectionInCone:function(t,e,i,s){var r=this.chessToTileXYZ(t),n=this.chessToTileXYZ(e),o=this.grid.directions;this.grid.setDirectionMode(this.sides);var h=this.grid.directionBetween(r,n,!1);this.grid.setDirectionMode(o);var a=Math.abs(h-i);return(a=Math.min(a,this.grid.directions-a))<=s/2},fit:function(t){var e,i=1/0,s=1/0;for(var r in t)e=t[r],i=Math.min(i,e.x),s=Math.min(s,e.y);if(0!==i||0!==s)for(var r in t)e=t[r],this.offset(e,-i,-s,e);var n=-1/0,o=-1/0;for(var r in t)e=t[r],n=Math.max(n,e.x),o=Math.max(o,e.y);return this.setBoardWidth(n+1),this.setBoardHeight(o+1),t},isEmptyTileXYZ:function(t,e,i){return this.contains(t,e)&&!this.contains(t,e,i)},getEmptyTileXYArray:function(t,e){void 0===t&&(t=0),void 0===e&&(e=[]);for(var i=0;i<this.height;i++)for(var s=0;s<this.width;s++)this.isEmptyTileXYZ(s,i,t)&&e.push({x:s,y:i});return e},getRandomEmptyTileXY:function(t,e){var i,s;void 0===t&&(t=0),void 0===e?e={}:!0===e&&(e=mt);for(var r=!0,n=20;r&&n>0;)i=pt(0,this.width-1),s=pt(0,this.height-1),r=null!==this.tileXYZToChess(i,s,t),n--;if(r){if(0===(yt=this.getEmptyTileXYArray(t,yt)).length)return null;var o=gt(yt);return e.x=o.x,e.y=o.y,yt.length=0,e}return e.x=i,e.y=s,e},getEmptyTileXYArrayInRange:function(t,e,i,s){var r;void 0===e&&(e=1),void 0===i&&(i=0),void 0===s&&(s=[]),t=this.chessToTileXYZ(t),this.grid.ringToTileXYArray(t,e,bt);for(var n=0,o=bt.length;n<o;n++)r=bt[n],this.isEmptyTileXYZ(r.x,r.y,i)&&s.push(r);return bt.length=0,s},getRandomEmptyTileXYInRange:function(t,e,i,s){var r;void 0===e&&(e=1),void 0===i&&(i=0),void 0===s?s={}:!0===s&&(s=wt),t=this.chessToTileXYZ(t),this.grid.ringToTileXYArray(t,e,xt),Tt(xt);for(var n=0,o=xt.length;n<o;n++)if(r=xt[n],this.isEmptyTileXYZ(r.x,r.y,i))return s.x=r.x,s.y=r.y,xt.length=0,s;return xt.length=0,null},getTileXYAtDirection:function(t,e,i,s){var r=this.chessToTileXYZ(t);if(!r)return null;"string"==typeof e&&(e=-1===e.indexOf(",")?parseInt(e):e.split(","));var o,h="number"==typeof e,a="number"==typeof i;if(h&&a)s=this.grid.getTileXYAtDirection(r.x,r.y,e,i,s),this.getWrapTileXY(s.x,s.y,s),null==s.x||null==s.y?s=null:s.direction=e;else if(void 0===s&&(s=[]),null==e&&(e=this.grid.allDirections),h)if(y(i)){var l=n(i,"end",1),u=n(i,"start",l>0?1:-1),c=n(i,"step",l>=u?1:-1);if(u===l)null!==(o=this.getTileXYAtDirection(r,e,l))&&s.push(o);else if(u<l)for(var d=u;d<=l;d+=c)null!==(o=this.getTileXYAtDirection(r,e,d))&&s.push(o);else for(d=u;d>=l;d+=c)null!==(o=this.getTileXYAtDirection(r,e,d))&&s.push(o)}else{d=0;for(var v=i.length;d<v;d++)null!==(o=this.getTileXYAtDirection(r,e,i[d]))&&s.push(o)}else for(d=0,v=e.length;d<v;d++)a?null!==(o=this.getTileXYAtDirection(r,e[d],i))&&s.push(o):this.getTileXYAtDirection(r,e[d],i,s);return s},getNeighborTileXY:function(t,e,i){return this.getTileXYAtDirection(t,e,1,i)},getNeighborTileXYAtAngle:function(t,e,i){var s=this.angleSnapToDirection(t,e);return this.getTileXYAtDirection(t,s,1,i)},getNeighborChess:function(t,e,i,s){if(null===(t=this.chessToTileXYZ(t)))return null;null==i&&(i=t.z);var r,n=typeof e;if("number"===n||"string"===n&&-1===e.indexOf(",")){var o=e,h=this.getNeighborTileXY(t,o,!0);return null===h?null:this.tileXYZToChess(h.x,h.y,i)}void 0===s&&(s=[]),this.getNeighborTileXY(t,e,Ct);for(var a=0,l=Ct.length;a<l;a++)null!=(r=this.tileXYZToChess(Ct[a].x,Ct[a].y,i))&&s.push(r);return Ct.length=0,s},getNeighborTileDirection:function(t,e){if(null===t||null===e)return null;if(t=this.chessToTileXYZ(t),e=this.chessToTileXYZ(e),st(t,e))return null;var i=this.grid.getNeighborTileDirection(t,e);if(this.wrapMode&&null===i){for(var s=0,r=(Yt=this.getNeighborTileXY(t,null,Yt)).length;s<r;s++)if(st(e,Yt[s])){i=s;break}Yt.length=0}return i},getNeighborChessDirection:function(t,e){var i=this.chessToTileXYZ(t),s=this.chessToTileXYZ(e);return this.getNeighborTileDirection(i,s)},areNeighbors:function(t,e){return null!==this.getNeighborChessDirection(t,e)},mapNeighbors:function(t,e,i,s){return"number"!=typeof e&&(s=i,i=e,e=1),this.getTileXYAtDirection(t,void 0,e).map(i,s)},ringToTileXYArray:function(t,e,i){var s;void 0===i&&(i=[]),t=this.chessToTileXYZ(t),this.grid.ringToTileXYArray(t,e,Xt);for(var r=0,n=Xt.length;r<n;r++)s=Xt[r],this.contains(s.x,s.y)&&i.push(s);return Xt.length=0,i},ringToChessArray:function(t,e,i,s){var r,n;Array.isArray(i)&&(s=i,i=void 0),void 0===s&&(s=[]),t=this.chessToTileXYZ(t),this.grid.ringToTileXYArray(t,e,Mt);for(var o=0,h=Mt.length;o<h;o++)r=Mt[o],(n=this.tileXYZToChess(r.x,r.y,i))&&s.push(n);return Mt.length=0,s},filledRingToTileXYArray:function(t,e,i,s){var r;Pt(i)&&(s=i,i=void 0),void 0===i&&(i=!0),void 0===s&&(s=[]),t=this.chessToTileXYZ(t);for(var n=0;n<=e;n++)r=i?n:e-n,this.ringToTileXYArray(t,r,s);return s},filledRingToChessArray:function(t,e,i,s,r){var n;Pt(s)&&(r=s,s=void 0),void 0===s&&(s=!0),void 0===r&&(r=[]),t=this.chessToTileXYZ(t);for(var o=0;o<=e;o++)n=s?o:e-o,this.ringToChessArray(t,n,i,r);return r},hasBlocker:function(t,e,i){if(t&&"number"!=typeof t){var s=this.chessToTileXYZ(t);t=s.x,e=s.y,i=s.z}var r;if(void 0===i){for(var n=0,o=(r=this.tileXYToChessArray(t,e,kt)).length;n<o;n++)if(!0===this.getChessData(r[n]).blocker)return kt.length=0,!0;return kt.length=0,!1}return null!==(r=this.tileXYZToChess(t,e,i))&&!0===this.getChessData(r).blocker},hasEdgeBlocker:function(t,e,i,s){var r;if(void 0===i){for(var n=0,o=(r=this.tileXYToChessArray(t,e,Dt)).length;n<o;n++)if(St(this.getChessData(r[n]).blocker))return Dt.length=0,!0;return Dt.length=0,!1}return null!==(r=this.tileXYZToChess(t,e,i))&&St(this.getChessData(r).blocker)},getGridPoints:A,chessToBoard:Et},_t=function(t){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))t.length=0;else for(var e in t)delete t[e];return t},At=function(t){for(var e in t)return!1;return!0};class Rt{constructor(){this.XYZToUID={},this.UIDToXYZ={},this.clear()}shutdown(t){return this.XYZToUID=void 0,this.UIDToXYZ=void 0,this}destroy(t){return this.shutdown(t),this}clear(){return _t(this.UIDToXYZ),_t(this.XYZToUID),this.chessCount=0,this.clearBounds(),this}clearBounds(){return this._xMax=void 0,this._xMin=void 0,this._yMax=void 0,this._yMin=void 0,this}getBounds(){var t,e,i,s=1/0,r=-1/0,n=1/0,o=-1/0,h=this.UIDToXYZ;for(var a in h)s>(e=(t=h[a]).x)&&(s=e),r<e&&(r=e),n>(i=t.y)&&(n=i),o<i&&(o=i);return{left:s,right:r,top:n,bottom:o}}addUID(t,e,i,s){this.XYZToUID.hasOwnProperty(e)||(this.XYZToUID[e]={});var r=this.XYZToUID[e];return r.hasOwnProperty(i)||(r[i]={}),r[i][s]=t,this.UIDToXYZ[t]={x:e,y:i,z:s},this.chessCount++,this.clearBounds(),this}getUID(t,e,i){var s=this.XYZToUID[t];return s&&(s=s[e])&&void 0!==i&&(s=s[i]),s}removeUID(t,e,i){if(!this.XYZToUID.hasOwnProperty(t))return this;var s=this.XYZToUID[t];if(!s.hasOwnProperty(e))return this;var r=s[e];if(!r.hasOwnProperty(i))return this;var n=r[i];return delete r[i],delete this.UIDToXYZ[n],At(r)&&delete s[e],At(s)&&delete this.XYZToUID[t],this.chessCount--,this.clearBounds(),this}exists(t){return this.UIDToXYZ.hasOwnProperty(t)}contains(t,e,i){return null!=this.getUID(t,e,i)}getXYZ(t){return this.exists(t)?this.UIDToXYZ[t]:null}get xMax(){if(void 0===this._xMax){this._xMax=-1/0;var t,e=this.UIDToXYZ;for(var i in e)t=e[i].x,this._xMax<t&&(this._xMax=t)}return this._xMax}get xMin(){if(void 0===this._xMin){this._xMin=1/0;var t,e=this.UIDToXYZ;for(var i in e)t=e[i].x,this._xMin>t&&(this._xMin=t)}return this._xMin}get yMax(){if(void 0===this._yMax){this._yMax=-1/0;var t,e=this.UIDToXYZ;for(var i in e)t=e[i].y,this._yMax<t&&(this._yMax=t)}return this._yMax}get yMin(){if(void 0===this._yMin){this._yMin=1/0;var t,e=this.UIDToXYZ;for(var i in e)t=e[i].y,this._yMin>t&&(this._yMin=t)}return this._yMin}}var Bt={},Lt={};class Nt{constructor(t){this.resetFromJSON(t)}resetFromJSON(t){this.setType(n(t,"type",0)),this.setDirectionMode(n(t,"dir",4)),this.setOriginPosition(n(t,"x",0),n(t,"y",0)),this.setCellSize(n(t,"cellWidth",0),n(t,"cellHeight",0))}setType(t){return"string"==typeof t&&(t=It[t]),this.mode=t,this}setDirectionMode(t){return"string"==typeof t&&(t=Zt[t]),this.directions=t,this}setOriginPosition(t,e){return this.x=t,this.y=e,this}get width(){return this._width}set width(t){this._width=t,this._halfWidth=t/2}get height(){return this._height}set height(t){this._height=t,this._halfHeight=t/2}setCellSize(t,e){return this.width=t,this.height=e,this}get cellWidth(){return this.width}set cellWidth(t){this.width=t}get cellHeight(){return this.height}set cellHeight(t){this.height=t}}var Ft={getWorldXY:function(t,e,i){var s,r;switch(void 0===i?i={}:!0===i&&(i=Bt),this.mode){case 0:s=t*this.width,r=e*this.height;break;case 1:s=(t-e)*this._halfWidth,r=(t+e)*this._halfHeight}return s+=this.x,r+=this.y,i.x=s,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=Lt),t-=this.x,e-=this.y;var s=t/this.width,r=e/this.height;switch(this.mode){case 0:i.x=Math.round(s),i.y=Math.round(r);break;case 1:i.x=Math.round(+s+r),i.y=Math.round(-s+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(Nt.prototype,Ft);const It={orthogonal:0,isometric:1,staggered:2},Zt={"4dir":4,"8dir":8};var jt=function(){return this._savedOriginX=this.x,this._savedOriginY=this.y,this},zt=function(){return this.x=this._savedOriginX,this.y=this._savedOriginY,this};const Gt=[[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]],Ut=Gt;var Wt=function(t,e,i,s,r){var n,o;switch(void 0===r?r={}:!0===r&&(r=Vt),this.mode){case 0:n=Gt[i][0],o=Gt[i][1];break;case 1:n=Ut[i][0],o=Ut[i][1]}return r.x=t+s*n,r.y=e+s*o,r},Vt={};const Jt=function(t){var e,i,s,r={};for(var n in t)i=(e=t[n])[0],s=e[1],r.hasOwnProperty(i)||(r[i]={}),r[i][s]=parseInt(n);return r}(Gt),Ht=Jt,$t={0:2,1:3,2:0,3:1,4:6,5:7,6:4,7:5};var Kt=function(t,e,i,s){void 0===s?s={}:!0===s&&(s=qt);var r=t.x+e,n=t.y+i;return s.x=r,s.y=n,s},qt={},Qt={},te={},ee=function(t){return ut(t,0,this.directions)},ie=function(t){for(var e=[],i=0;i<t;i++)e.push({x:0,y:0});return e},se={},re=ie(4),ne=new W;class oe extends Nt{constructor(t){super(t),this.sides=4}get allDirections(){return 4===this.directions?he:ae}get halfDirections(){return 4===this.directions?le:ue}}const he=[0,1,2,3],ae=[0,1,2,3,4,5,6,7],le=[0,1],ue=[0,1,4,5];var ce={saveOrigin:jt,restoreOrigin:zt,getTileXYAtDirection:Wt,getNeighborTileXY:function(t,e,i,s){return Wt.call(this,t,e,i,1,s)},getNeighborTileDirection:function(t,e){var i;switch(this.mode){case 0:i=Jt;break;case 1:i=Ht}var s=e.x-t.x,r=e.y-t.y;if(i.hasOwnProperty(s)){var n=i[s];if(n.hasOwnProperty(r))return n[r]}return null},getOppositeDirection:function(t,e,i){return $t[i]},offset:Kt,mirror:function(t,e,i){return void 0===i?i={}:!0===i&&(i=Qt),i.x=1&e?-t.x:t.x,i.y=2&e?-t.y:t.y,i},rotate:function(t,e,i){var s,r;switch(void 0===i?i={}:!0===i&&(i=te),e=ut(e,0,3)){case 1:s=-t.y,r=t.x;break;case 2:s=-t.x,r=-t.y;break;case 3:s=t.y,r=-t.x;break;default:s=t.x,r=t.y}return i.x=s,i.y=r,i},getDistance:function(t,e,i){var s=e.x-t.x,r=e.y-t.y;return i?Math.abs(s)+Math.abs(r):Math.sqrt(s*s+r*r)},directionBetween:function(t,e,i){var s;switch(void 0===i&&(i=!0),this.mode){case 0:case 1:if(t.y===e.y)s=e.x>=t.x?0:2;else if(t.x===e.x)s=e.y>=t.y?1:3;else if(4===this.directions)(o=_(k(t.x,t.y,e.x,e.y)))<0&&(o+=360),s=o/90,i&&(s=Math.round(s));else{var r=e.x-t.x,n=e.y-t.y;if(r===n)s=r>0?4:6;else if(r===-n)s=r>0?7:5;else{var o;(o=_(Math.atan2(n,r)))<0&&(o+=360);var h=o/45;i&&(h=Math.round(h)),s=h>=0&&h<1?h:h>=1&&h<2?h+3:h>=2&&h<3?h-1:h>=3&&h<4?h+2:h>=4&&h<5?h-2:h>=5&&h<6?h+1:h>=6&&h<7?h-3:h}}}return s===this.directions&&(s=0),s},directionNormalize:ee,getGridPoints:function(t,e,i){void 0===i?i=ie(4):!0===i&&(i=re),void 0===t?(se.x=0,se.y=0):this.getWorldXY(t,e,se);var s=0===this.mode?0:1;return function(t,e,i,s,r,n){void 0===n&&(n=ie(4));var o=i/2,h=s/2;0===r?(n[0].x=t+o,n[0].y=e-h,n[1].x=t+o,n[1].y=e+h,n[2].x=t-o,n[2].y=e+h,n[3].x=t-o,n[3].y=e-h):(n[0].x=t+o,n[0].y=e,n[1].x=t,n[1].y=e+h,n[2].x=t-o,n[2].y=e,n[3].x=t,n[3].y=e-h)}(se.x,se.y,this.width,this.height,s,i),i},getBounds:function(t,e,i){void 0===i?i=new W:!0===i&&(i=ne);var s=this.getWorldXY(t,e,!0);return i.x=s.x-.5*this.width,i.y=s.y-.5*this.height,i.width=this.width,i.height=this.height,i},ringToTileXYArray:function(t,e,i){var s,r;for(void 0===i&&(i=[]),s=e,r=-e;r<=e;r++)i.push(Kt(t,s,r));for(r=e,s=e-1;s>=-e;s--)i.push(Kt(t,s,r));for(s=-e,r=e-1;r>=-e;r--)i.push(Kt(t,s,r));for(r=-e,s=1-e;s<=e-1;s++)i.push(Kt(t,s,r));return i}};Object.assign(oe.prototype,ce);const de=Math.sqrt(3),ve=Math.sqrt(3);var fe=0,pe=1,ge=2,ye=3;const me=fe,be=pe,Te=ge,xe=ye;var we={};const Ce=fe,Ye=pe,Xe=ge,Me=ye;var Pe=function(t,e,i,s){switch(void 0===s?s={}:!0===s&&(s=Se),t){case Ce:s.x=e-(i-(1&i))/2,s.z=i;break;case Ye:s.x=e-(i+(1&i))/2,s.z=i;break;case Xe:s.x=e,s.z=i-(e-(1&e))/2;break;case Me:s.x=e,s.z=i-(e+(1&e))/2}return s.y=-s.x-s.z,s},ke=function(t,e,i,s,r){switch(void 0===r?r={}:!0===r&&(r=De),t){case Ce:r.x=e+(s-(1&s))/2,r.y=s;break;case Ye:r.x=e+(s+(1&s))/2,r.y=s;break;case Xe:r.x=e,r.y=s+(e-(1&e))/2;break;case Me:r.x=e,r.y=s+(e+(1&e))/2}return r},Se={},De={};const Ee=fe,Oe=pe,_e=ge,Ae=ye,Re=4/3,Be=2/3;var Le={},Ne={};const Fe=fe,Ie=pe,Ze=ge,je=ye;class ze{constructor(t){this.resetFromJSON(t)}resetFromJSON(t){this.setType(n(t,"staggeraxis",1),n(t,"staggerindex",1)),this.setDirectionMode(),this.setOriginPosition(n(t,"x",0),n(t,"y",0));var e=n(t,"size",void 0);void 0!==e?this.setCellRadius(e):this.setCellSize(n(t,"cellWidth",0),n(t,"cellHeight",0))}setType(t,e){return"string"==typeof t&&(t=Ue[t]),"string"==typeof e&&(e=We[e]),this.staggeraxis=t,this.staggerindex=e,this.mode=0===t?0===e?je:Ze:0===e?Ie:Fe,this}setDirectionMode(){return this.directions=6,this}setOriginPosition(t,e){return this.x=t,this.y=e,this}get width(){return this._width}set width(t){this._width=t,this._halfWidth=t/2}get height(){return this._height}set height(t){this._height=t,this._halfHeight=t/2}setCellSize(t,e){return this.width=t,this.height=e,this}setCellRadius(t){this.size=t;var e={size:this.size,type:this.staggeraxis},i=function(t){return 0===t.type?2*t.size:de*t.size}(e),s=function(t){return 0===t.type?ve*t.size:2*t.size}(e);return this.setCellSize(i,s),this}get cellWidth(){return this.width}set cellWidth(t){this.width=t}get cellHeight(){return this.height}set cellHeight(t){this.height=t}}var Ge={getWorldXY:function(t,e,i){void 0===i?i={}:!0===i&&(i=we);var s=t*this.width,r=e*this.height;switch(this.mode){case me:1&e&&(s+=this._halfWidth),r*=.75;break;case be:1&e&&(s-=this._halfWidth),r*=.75;break;case Te:s*=.75,1&t&&(r+=this._halfHeight);break;case xe:s*=.75,1&t&&(r-=this._halfHeight)}return s+=this.x,r+=this.y,i.x=s,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 s,r;switch(void 0===i?i={}:!0===i&&(i=Ne),t-=this.x,e-=this.y,this.mode){case Ee:case Oe:r=e*Re/this.height,s=t/this.width-Be*(e/this.height);break;case _e:case Ae:r=e/this.height-Be*(t/this.width),s=t*Re/this.width}var n=function(t,e,i){return void 0===i?i={}:!0===i&&(i=Se),i.x=t,i.y=-t-e,i.z=e,i}(s,r,Le);return function(t,e,i,s){"number"!=typeof t&&(t=(s=t).x,e=s.y,i=s.z),void 0===s?s={}:!0===s&&(s=Se);var r=Math.round(t),n=Math.round(e),o=Math.round(i),h=Math.abs(r-t),a=Math.abs(n-e),l=Math.abs(o-i);h>a&&h>l?r=-n-o:a>l?n=-r-o:o=-r-n,s.x=r,s.y=n,s.z=o}(n),ke(this.mode,n.x,n.y,n.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(ze.prototype,Ge);const Ue={y:0,x:1},We={even:0,odd:1},Ve=[[[[1,0],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1]],[[1,0],[1,1],[0,1],[-1,0],[0,-1],[1,-1]]],[[[1,0],[1,1],[0,1],[-1,0],[0,-1],[1,-1]],[[1,0],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1]]],[[[1,0],[0,1],[-1,0],[-1,-1],[0,-1],[1,-1]],[[1,1],[0,1],[-1,1],[-1,0],[0,-1],[1,0]]],[[[1,1],[0,1],[-1,1],[-1,0],[0,-1],[1,0]],[[1,0],[0,1],[-1,0],[-1,-1],[0,-1],[1,-1]]]],Je=fe,He=pe,$e=ge,Ke=ye;var qe=function(t,e,i){var s;switch(t){case Je:case He:s=1&i;break;case $e:case Ke:s=1&e}return s},Qe=function(t,e,i,s,r){if(void 0===r?r={}:!0===r&&(r=ti),1===s){var n=qe(this.mode,t,e);r.x=t+Ve[this.mode][n][i][0],r.y=e+Ve[this.mode][n][i][1]}else if(0===s)r.x=t,r.y=e;else{var o,h,a=Pe(this.mode,t,e,!0);switch(i){case 1:o=a.x,a.y,h=a.z+s;break;case 2:o=a.x-s,a.y,h=a.z+s;break;case 3:o=a.x-s,a.y,h=a.z;break;case 4:o=a.x,a.y,h=a.z-s;break;case 5:o=a.x+s,a.y,h=a.z-s;break;default:o=a.x+s,a.y,h=a.z}ke(this.mode,o,0,h,r)}return r},ti={},ei=function(t){var e,i,s,r={};for(var n in t)i=(e=t[n])[0],s=e[1],r.hasOwnProperty(i)||(r[i]={}),r[i][s]=parseInt(n);return r};const ii=[[ei(Ve[0][0]),ei(Ve[0][1])],[ei(Ve[1][0]),ei(Ve[1][1])],[ei(Ve[2][0]),ei(Ve[2][1])],[ei(Ve[3][0]),ei(Ve[3][1])]],si=fe,ri=pe,ni=ge,oi=ye;var hi={};const ai=fe,li=pe;var ui={},ci={},di={},vi={},fi={},pi={};
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
const gi=Math.PI/180;var yi=function(t){return t*gi},mi=ie(6),bi={},Ti={},xi=new W;class wi extends ze{constructor(t){super(t),this.sides=6}get allDirections(){return Ci}get halfDirections(){return Yi}}const Ci=[0,1,2,3,4,5],Yi=[0,1,2];var Xi={saveOrigin:jt,restoreOrigin:zt,getTileXYAtDirection:Qe,getNeighborTileXY:function(t,e,i,s){return Qe.call(this,t,e,i,1,s)},getNeighborTileDirection:function(t,e){var i=qe(this.mode,t.x,t.y),s=ii[this.mode][i],r=e.x-t.x,n=e.y-t.y;if(s.hasOwnProperty(r)){var o=s[r];if(o.hasOwnProperty(n))return o[n]}return null},getOppositeDirection:function(t,e,i){return(i+3)%6},offset:function(t,e,i,s){void 0===s?s={}:!0===s&&(s=hi);var r=t.x+e,n=t.y+i;switch(this.mode){case si:1&i&&(1&n||(r+=1));break;case ri:1&i&&(1&n||(r-=1));break;case ni:1&e&&(1&r||(n+=1));break;case oi:1&e&&(1&r||(n-=1))}return s.x=r,s.y=n,s},mirror:function(t,e,i){void 0===i?i={}:!0===i&&(i=ui);var s,r,n,o=Pe(this.mode,t.x,t.y,!0),h=this.mode===ai||this.mode===li;return 1&e&&(h?(s=o.y,r=o.x,n=o.z):(s=-o.x,r=-o.z,n=-o.y),o.x=s,o.y=r,o.z=n),2&e&&(h?(s=-o.y,r=-o.x,n=-o.z):(s=o.x,r=o.z,n=o.y)),ke(this.mode,s,0,n,i),i},rotate:function(t,e,i){void 0===i?i={}:!0===i&&(i=ci),e=ut(e,0,5);var s,r,n=Pe(this.mode,t.x,t.y,!0);switch(e){case 1:s=-n.z,n.x,r=-n.y;break;case 2:s=n.y,n.z,r=n.x;break;case 3:s=-n.x,n.y,r=-n.z;break;case 4:s=n.z,n.x,r=n.y;break;case 5:s=-n.y,n.z,r=-n.x;break;default:s=n.x,n.y,r=n.z}return ke(this.mode,s,0,r,i),i},getDistance:function(t,e,i){Pe(this.mode,t.x,t.y,di),Pe(this.mode,e.x,e.y,vi);var s=vi.x-di.x,r=vi.y-di.y,n=vi.z-di.z;return(Math.abs(s)+Math.abs(r)+Math.abs(n))/2},directionBetween:function(t,e,i){var s;void 0===i&&(i=!0),Pe(this.mode,t.x,t.y,fi),Pe(this.mode,e.x,e.y,pi);var r=pi.x-fi.x,n=pi.y-fi.y,o=pi.z-fi.z;return s=0===o?r>0?0:3:0===r?o>0?1:4:0===n?o>0?2:5:r>0&&n<0&&o>0?0+o/-n:r<0&&n<0&&o>0?1+-n/o:r<0&&n>0&&o>0?2+n/-r:r<0&&n>0&&o<0?3+-o/n:r>0&&n>0&&o<0?4+r/-o:5+-n/r,i&&(s=Math.round(s)),s},directionNormalize:ee,getGridPoints:function(t,e,i){var s;return void 0===i?i=ie(6):!0===i&&(i=mi),void 0===t?(bi.x=0,bi.y=0):this.getWorldXY(t,e,bi),void 0!==this.size?s=this.size:((s=Ti).width=this.width,s.height=this.height),function(t,e,i,s,r){if(void 0===r&&(r=ie(6)),void 0===i);else if("number"==typeof i)for(var n,o=0===s?0:-30,h=0;h<6;h++)n=yi(60*h+o),r[h].x=t+i*Math.cos(n),r[h].y=e+i*Math.sin(n);else{var a=i,l=a.width,u=a.height,c=l/2,d=l/4,v=u/2,f=u/4;0===s?(r[0].x=t+c,r[0].y=e,r[1].x=t+d,r[1].y=e+v,r[2].x=t-d,r[2].y=e+v,r[3].x=t-c,r[3].y=e,r[4].x=t-d,r[4].y=e-v,r[5].x=t+d,r[5].y=e-v):(r[0].x=t+c,r[0].y=e-f,r[1].x=t+c,r[1].y=e+f,r[2].x=t,r[2].y=e+v,r[3].x=t-c,r[3].y=e+f,r[4].x=t-c,r[4].y=e-f,r[5].x=t,r[5].y=e-v)}}(bi.x,bi.y,s,this.staggeraxis,i),i},getBounds:function(t,e,i){void 0===i?i=new W:!0===i&&(i=xi);var s=this.getWorldXY(t,e,!0);return i.x=s.x-.5*this.width,i.y=s.y-.5*this.height,i.