phaser3-rex-plugins
Version:
29 lines • 157 kB
JavaScript
!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).rexboardplugin=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,p(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 s(t,e,i){return (e=p(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,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&&h(t,e);}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function h(t,e){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},h(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=o(t);if(e){var s=o(this).constructor;i=Reflect.construct(n,arguments,s);}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 l(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=o(t)););return t}function c(){return c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var n=l(t,e);if(n){var s=Object.getOwnPropertyDescriptor(n,e);return s.get?s.get.call(arguments.length<3?t:i):s.value}},c.apply(this,arguments)}function d(t,e,i,n){return d="undefined"!=typeof Reflect&&Reflect.set?Reflect.set:function(t,e,i,n){var r,o=l(t,e);if(o){if((r=Object.getOwnPropertyDescriptor(o,e)).set)return r.set.call(n,i),!0;if(!r.writable)return !1}if(r=Object.getOwnPropertyDescriptor(n,e)){if(!r.writable)return !1;r.value=i,Object.defineProperty(n,e,r);}else s(n,e,i);return !0},d(t,e,i,n)}function f(t,e,i,n,s){if(!d(t,e,i,n||t)&&s)throw new TypeError("failed to set property");return i}function v(t){return function(t){if(Array.isArray(t))return y(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return y(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return y(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function p(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 g=function(){function t(i){e(this,t),this.scene=i,this.displayList=i.sys.displayList,this.updateList=i.sys.updateList,i.sys.events.once("destroy",this.destroy,this);}return n(t,[{key:"destroy",value:function(){this.scene=null,this.displayList=null,this.updateList=null;}}],[{key:"register",value:function(e,i){t.prototype[e]=i;}}]),t}();function m(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var b={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,i="~";function n(){}function s(t,e,i){this.fn=t,this.context=e,this.once=i||!1;}function r(t,e,n,r,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var h=new s(n,r||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 n:delete t._events[e];}function h(){this._events=new n,this._eventsCount=0;}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(i=!1)),h.prototype.eventNames=function(){var t,n,s=[];if(0===this._eventsCount)return s;for(n in t=this._events)e.call(t,n)&&s.push(i?n.slice(1):n);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(t)):s},h.prototype.listeners=function(t){var e=i?i+t:t,n=this._events[e];if(!n)return [];if(n.fn)return [n.fn];for(var s=0,r=n.length,o=new Array(r);s<r;s++)o[s]=n[s].fn;return o},h.prototype.listenerCount=function(t){var e=i?i+t:t,n=this._events[e];return n?n.fn?1:n.length:0},h.prototype.emit=function(t,e,n,s,r,o){var h=i?i+t:t;if(!this._events[h])return !1;var a,u,l=this._events[h],c=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),c){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,n),!0;case 4:return l.fn.call(l.context,e,n,s),!0;case 5:return l.fn.call(l.context,e,n,s,r),!0;case 6:return l.fn.call(l.context,e,n,s,r,o),!0}for(u=1,a=new Array(c-1);u<c;u++)a[u-1]=arguments[u];l.fn.apply(l.context,a);}else {var d,f=l.length;for(u=0;u<f;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),c){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,e);break;case 3:l[u].fn.call(l[u].context,e,n);break;case 4:l[u].fn.call(l[u].context,e,n,s);break;default:if(!a)for(d=1,a=new Array(c-1);d<c;d++)a[d-1]=arguments[d];l[u].fn.apply(l[u].context,a);}}return !0},h.prototype.on=function(t,e,i){return r(this,t,e,i,!1)},h.prototype.once=function(t,e,i){return r(this,t,e,i,!0)},h.prototype.removeListener=function(t,e,n,s){var r=i?i+t:t;if(!this._events[r])return this;if(!e)return o(this,r),this;var h=this._events[r];if(h.fn)h.fn!==e||s&&!h.once||n&&h.context!==n||o(this,r);else {for(var a=0,u=[],l=h.length;a<l;a++)(h[a].fn!==e||s&&!h[a].once||n&&h[a].context!==n)&&u.push(h[a]);u.length?this._events[r]=1===u.length?u[0]:u:o(this,r);}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 n,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;}(b);var T=function(t){r(s,t);var i=u(s);function s(){return e(this,s),i.apply(this,arguments)}return n(s,[{key:"shutdown",value:function(){this.removeAllListeners();}},{key:"destroy",value:function(){this.removeAllListeners();}}]),s}(m(b.exports)),x=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("."),s=t,r=i,o=0;o<n.length;o++){if(!s.hasOwnProperty(n[o])){r=i;break}r=s[n[o]],s=s[n[o]];}return r}return i}return i},k=function(){function t(i){e(this,t),this.nextId=x(i,"start",1),this.uidKey=x(i,"uidKey","$uid"),this.autoRemove=x(i,"remove",!0),this.refs={},this.count=0;}return n(t,[{key:"add",value:function(t,e){var i=this.refs,n=this.uidKey;if(n&&null!=(e=t[n]))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++,n&&(t[n]=e),this.autoRemove&&t.on&&t.once("destroy",(function(){this.remove(e);}),this)),n?this:e}},{key:"addMultiple",value:function(t){for(var e=0,i=t.length;e<i;e++)this.add(t[e]);return this}},{key:"get",value:function(t){return this.refs[t]}},{key:"has",value:function(t){return this.refs.hasOwnProperty(t)}},{key:"remove",value:function(t){var e=this.refs;if(e.hasOwnProperty(t)){if(this.uidKey)e[t][this.uidKey]=void 0;delete e[t],this.count--;}return this}},{key:"forEach",value:function(t,e){var i,n=this.refs;for(var s in n)i=n[s],e?t.call(e,i,s):t(i,s);}},{key:"clear",value:function(){this.forEach((function(t){this.remove(t);}),this);}}]),t}(),w=new k({uidKey:"$uid",remove:!1}),C={setEventEmitter:function(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:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},Y=Phaser.Scene,X=function(t){return t instanceof Y},M=function(e){return null==e||"object"!==t(e)?null:X(e)?e:e.scene&&X(e.scene)?e.scene:e.parent&&e.parent.scene&&X(e.parent.scene)?e.parent.scene:null},P=Phaser.Game,S=function(t){return t instanceof P},D=function(e){return null==e||"object"!==t(e)?null:S(e)?e:S(e.game)?e.game:X(e)?e.sys.game:X(e.scene)?e.scene.sys.game:void 0},O=Phaser.Utils.Objects.GetValue,E=function(){function t(i,n){e(this,t),this.setParent(i),this.isShutdown=!1,this.setEventEmitter(O(n,"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));}return n(t,[{key:"shutdown",value:function(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);}},{key:"destroy",value:function(t){this.shutdown(t);}},{key:"onEnvDestroy",value:function(){this.destroy(!0);}},{key:"onParentDestroy",value:function(t,e){this.destroy(e);}},{key:"setParent",value:function(t){return this.parent=t,this.scene=M(t),this.game=D(t),this}}]),t}();Object.assign(E.prototype,C);var _={x:0,y:0},A=function(e){if("object"!==t(e)||e.nodeType||e===e.window)return !1;try{if(e.constructor&&!{}.hasOwnProperty.call(e.constructor.prototype,"isPrototypeOf"))return !1}catch(t){return !1}return !0},R=w.uidKey,B=function(t){r(s,t);var i=u(s);function s(t,n){var r;return e(this,s),r=i.call(this,t,{eventEmitter:!1}),w.add(a(r),n),r.board=null,r.blocker=!1,r}return n(s,[{key:"shutdown",value:function(t){this.isShutdown||(this.board&&this.board.removeChess(this[R]),w.remove(this[R]),this.board=null,c(o(s.prototype),"shutdown",this).call(this,t));}},{key:"setBoard",value:function(t){return this.board=t,this}},{key:"tileXYZ",get:function(){return null==this.board?null:this.board.chessToTileXYZ(this[R])}},{key:"setTileZ",value:function(t){return null==this.board||this.board.setChessTileZ(this.parent,t),this}},{key:"setBlocker",value:function(t){return void 0===t&&(t=!0),this.blocker=t,this}},{key:"setBlockEdge",value:function(t,e){!1===this.blocker&&(this.blocker={});var i=this.blocker;if(A(t)){var n=t;for(t in n)i[t]=n[t];}else void 0===e&&(e=!0),i[t]=e;return this}},{key:"getBlockEdge",value:function(t){var e=this.blocker;return !1!==e&&(!!e.hasOwnProperty(t)&&e[t])}}]),s}(E),N={getTileDirection:function(t,e){var i=this.board;return null===i?null:(_.x=t,_.y=e,i.getNeighborTileDirection(this.tileXYZ,_))}};Object.assign(B.prototype,N);var L=function(e){var i=t(e);return "number"===i||"string"===i},Z=function(t){return L(t)?w.get(t):(t.hasOwnProperty("rexChess")||(t.rexChess=new B(t)),t.rexChess)},I=w.uidKey,F=function(t){return L(t)?t:Z(t)[I]},j=function(t,e,i){return void 0===i&&(i=","),"".concat(t).concat(i).concat(e)},z={},U={},G=function(t,e,i,n){return Math.atan2(n-e,i-t)},W=function(t){return (t%=2*Math.PI)>=0?t:t+2*Math.PI},V=2*Math.PI,J={x:0,y:0},H=180/Math.PI,K=function(t){return t*H},q=function(t,e,i){if(t&&"number"!=typeof t){i=e;var n=this.chessToTileXYZ(t);t=n.x,e=n.y;}return this.grid.getGridPoints(t,e,i)};function $(e,i,n){var s=n?e[i]:Object.getOwnPropertyDescriptor(e,i);return !n&&s.value&&"object"===t(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 Q(e,i){var n=Object.getOwnPropertyDescriptor(e,i);return !!n&&(n.value&&"object"===t(n.value)&&(n=n.value),!1===n.configurable)}function tt(t,e,i,n){for(var s in e)if(e.hasOwnProperty(s)){var r=$(e,s,i);if(!1!==r){if(Q((n||t).prototype,s)){if(it.ignoreFinals)continue;throw new Error("cannot override final property '"+s+"', set Class.ignoreFinals = true to skip")}Object.defineProperty(t.prototype,s,r);}else t.prototype[s]=e[s];}}function et(t,e){if(e){Array.isArray(e)||(e=[e]);for(var i=0;i<e.length;i++)tt(t,e[i].prototype||e[i]);}}function it(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 n=t.Extends;e=function(){n.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 s=null;return t.Mixins&&(s=t.Mixins,delete t.Mixins),et(e,s),tt(e,t,!0,i),e}it.extend=tt,it.mixin=et,it.ignoreFinals=!1;
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var nt=function(t){return 2*(t.width+t.height)},st=new it({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}}),rt=function(t,e,i){if(void 0===i&&(i=new st),e<=0||e>=1)return i.x=t.x,i.y=t.y,i;var n=nt(t)*e;return e>.5?(n-=t.width+t.height)<=t.width?(i.x=t.right-n,i.y=t.bottom):(i.x=t.x,i.y=t.bottom-(n-t.width)):n<=t.width?(i.x=t.x+n,i.y=t.y):(i.x=t.right,i.y=t.y+(n-t.width)),i},ot=function(t,e,i,n){void 0===n&&(n=[]),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 s=t.x1,r=t.y1,o=t.x2,h=t.y2,a=0;a<e;a++){var u=a/e,l=s+(o-s)*u,c=r+(h-r)*u;n.push(new st(l,c));}return n},ht=new it({initialize:function(e,i){this.x=0,this.y=0,"object"===t(e)?(this.x=e.x||0,this.y=e.y||0):(void 0===i&&(i=e),this.x=e||0,this.y=i||0);},clone:function(){return new ht(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,n=this.y;return this.x=i+e*(t.x-i),this.y=n+e*(t.y-n),this},transformMat3:function(t){var e=this.x,i=this.y,n=t.val;return this.x=n[0]*e+n[3]*i+n[6],this.y=n[1]*e+n[4]*i+n[7],this},transformMat4:function(t){var e=this.x,i=this.y,n=t.val;return this.x=n[0]*e+n[4]*i+n[12],this.y=n[1]*e+n[5]*i+n[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}
*/ht.ZERO=new ht,ht.RIGHT=new ht(1,0),ht.LEFT=new ht(-1,0),ht.UP=new ht(0,-1),ht.DOWN=new ht(0,1),ht.ONE=new ht(1,1);
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var at,ut,lt,ct,dt=new it({initialize:function(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=0),this.x1=t,this.y1=e,this.x2=i,this.y2=n;},getPoint:function(t,e){return function(t,e,i){return void 0===i&&(i=new st),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 ot(this,t,e,i)},getRandomPoint:function(t){return function(t,e){void 0===e&&(e=new st);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,n){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=0),this.x1=t,this.y1=e,this.x2=i,this.y2=n,this},getPointA:function(t){return void 0===t&&(t=new ht),t.set(this.x1,this.y1),t},getPointB:function(t){return void 0===t&&(t=new ht),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;}}}),ft=new it({initialize:function(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=0),this.x=t,this.y=e,this.width=i,this.height=n;},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 rt(this,t,e)},getPoints:function(t,e,i){return function(t,e,i,n){void 0===n&&(n=[]),e||(e=nt(t)/i);for(var s=0;s<e;s++){var r=s/e;n.push(rt(t,r));}return n}(this,t,e,i)},getRandomPoint:function(t){return e=this,void 0===(i=t)&&(i=new st),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,n){return this.x=t,this.y=e,this.width=i,this.height=n,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 dt),t.setTo(this.x,this.y,this.right,this.y),t},getLineB:function(t){return void 0===t&&(t=new dt),t.setTo(this.right,this.y,this.right,this.bottom),t},getLineC:function(t){return void 0===t&&(t=new dt),t.setTo(this.right,this.bottom,this.x,this.bottom),t},getLineD:function(t){return void 0===t&&(t=new dt),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;}}}),vt=new ft,yt=function(t,e,i){return (e-t)*i+t},pt=function(t,e){return t&&e&&t.x===e.x&&t.y===e.y},gt=function(t,e,i,n,s){var r=t.tileXYToWorldXY(i,n,!0);if(e.contains(r.x,r.y))return !0;switch(s){case 1:var o=t.getGridBounds(i,n,!0);return mt(e,o);case 2:var h=t.getGridPoints(i,n,!0);return bt(e,h);default:return !1}},mt=function(t,e){var i=e.top,n=e.bottom,s=e.left,r=e.right;return !!t.contains(s,i)||(!!t.contains(s,n)||(!!t.contains(r,i)||!!t.contains(r,n)))},bt=function(t,e){for(var i=0,n=e.length;i<n;i++){var s=e[i];if(t.contains(s.x,s.y))return !0}return !1},Tt=function(t,e,i,n,s){if(!this.contains(e,i))return this;void 0===s&&(s=!0);var r=this.chessToTileXYZ(t);if(void 0===n&&(n=r?r.z:0),r&&r.x===e&&r.y===i&&r.z===n)return this;var o=this.tileXYZToChess(e,i,n);return o&&this.emit("kickout",t,o,r),this.removeChess(t),o&&this.removeChess(o,e,i,n),this.boardData.addUID(this.getChessUID(t),e,i,n),this.isBoard&&this.getChessData(t).setBoard(this),s&&this.gridAlign(t,e,i),this},xt=function(t,e,i){return Math.max(e,Math.min(i,t))},kt={x:0,y:0},wt=function(t,e,i){var n=i-e;return e+((t-e)%n+n)%n},Ct={},Yt={},Xt={},Mt={},Pt=function(t,e){return Math.floor(Math.random()*(e-t+1)+t)},St=function(t,e,i){void 0===e&&(e=0),void 0===i&&(i=t.length);var n=e+Math.floor(Math.random()*i);return void 0===t[n]?null:t[n]},Dt=[],Ot={},Et=[],_t=function(t){for(var e=t.length-1;e>0;e--){var i=Math.floor(Math.random()*(e+1)),n=t[e];t[e]=t[i],t[i]=n;}return t},At=[],Rt={},Bt=[],Nt=[],Lt=[],Zt=[],It=function(t){return "[object Array]"===Object.prototype.toString.call(t)},Ft=[],jt=function(t,e){return !1===t||!0===t?t:!0===t[e]},zt=[],Ut=function(t){return t?t.rexChess?t.rexChess.board:t.mainBoard?t.mainBoard:void 0:void 0},Gt=(ct={getChessData:Z,getChessUID:F,setBoardWidth:function(t){if(this.infinityMode)return this;if(void 0===this.width||this.width<=t)return this.width=t,this;var e,i,n;for(e=t;e<this.width;e++)for(i=0;i<this.height;i++)for(n in this.boardData.getUID(e,i))this.RemoveChess(!1,e,i,n);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,n;for(i=t;i<this.height;i++)for(e=0;e<this.width;e++)for(n in this.boardData.getUID(e,i))this.RemoveChess(!1,e,i,n);return this.height=t,this},tileXYZToKey:function(t,e,i,n){return void 0===n&&(n=","),"".concat(t).concat(n).concat(e).concat(n).concat(i)},tileXYToKey:j,keyToTileXYZ:function(t,e,i){void 0===e?e={}:!0===e&&(e=z),void 0===i&&(i=",");var n=t.split(i);return e.x=n[0],e.y=n[1],e.z=n[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 n=0,s=t.length;n<s;n++)i=t[n],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 n=this.worldXYToTileXY(t,e,!0);return this.tileXYToChessArray(n.x,n.y,i)},worldXYToChess:function(t,e,i){var n=this.worldXYToTileXY(t,e,!0);if(void 0!==i)return this.tileXYZToChess(n.x,n.y,i);var s=this.boardData.getUID(n.x,n.y);if(null==s)return null;for(var i in s)return this.uidToChess(s[i])},worldXYSnapToGrid:function(t,e,i){return void 0===i?i={}:!0===i&&(i=U),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),n=i.x,s=i.y,r=(i=this.tileXYToWorldXY(e.x,e.y,!0)).x,o=i.y;return G(n,s,r,o)},isAngleInCone:function(t,e,i,n){var s=this.chessToTileXYZ(t),r=this.chessToTileXYZ(e),o=this.angleBetween(s,r);o=W(o);var h=Math.abs(o-i);h=Math.min(h,V-h);var a,u,l,c=n/2;return a=h,u=c,void 0===l&&(l=1e-4),Math.abs(a-u)<l||h<c},angleToward:function(t,e){void 0===t&&(t=J);var i=this.wrapMode,n=this.infinityMode;this.wrapMode=!1,this.infinityMode=!0;var s=this.getNeighborTileXY(t,e,!0);return this.wrapMode=i,this.infinityMode=n,this.angleBetween(t,s)},angleSnapToDirection:function(t,e){e=K(e);for(var i,n,s,r=this.grid.allDirections,o=1/0,h=void 0,a=0,u=r.length;a<u;a++)i=K(this.angleToward(t,r[a])),(n=Math.abs((s=void 0,0===(s=i-e)?0:s-360*Math.floor((s- -180)/360))))<o&&(o=n,h=a);return h},isOverlappingPoint:function(t,e,i){if(this.infinityMode&&void 0===i)return !0;var n=this.worldXYToTileXY(t,e,!0);return this.contains(n.x,n.y,i)},gridAlign:function(t,e,i){if(void 0===t)for(var n=this.getAllChess(),s=0,r=n.length;s<r;s++)this.gridAlign(n[s]);else {if(L(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:q,getGridBounds:function(t,e,i){if(t&&"number"!=typeof t){i=e;var n=this.chessToTileXYZ(t);t=n.x,e=n.y;}return this.grid.getBounds(t,e,i)},getBoardBounds:function(t){void 0===t?t=new ft:!0===t&&(t=vt);var e=!0;return this.forEachTileXY((function(i,n){var s=n.getGridBounds(i.x,i.y,!0);e?(t.setTo(s.x,s.y,s.width,s.height),e=!1):t=function(t,e,i){void 0===i&&(i=new ft);var n=Math.min(t.x,e.x),s=Math.min(t.y,e.y),r=Math.max(t.right,e.right)-n,o=Math.max(t.bottom,e.bottom)-s;return i.setTo(n,s,r,o)}(t,s,t);})),t},lineToTileXYArray:function(t,e,i,n,s){if("number"!=typeof t){var r=t;s=e,t=r.x1,e=r.y1,i=r.x2,n=r.y2;}void 0===s&&(s=[]);for(var o,h,a,u,l,c,d,f=(o=t-i,h=e-n,Math.sqrt(o*o+h*h)),v=Math.min(this.grid.cellWidth,this.grid.cellHeight),y=Math.ceil(f/(v/4)),p=0;p<=y;p++)u=yt(t,i,a=p/y),l=yt(e,n,a),d=this.worldXYToTileXY(u,l),this.contains(d.x,d.y)&&(c&&pt(c,d)||(s.push(d),c=d));return s},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),at=function(t,e){void 0===e&&(e=new ft);for(var i,n=1/0,s=1/0,r=-n,o=-s,h=0;h<t.points.length;h++)i=t.points[h],n=Math.min(n,i.x),s=Math.min(s,i.y),r=Math.max(r,i.x),o=Math.max(o,i.y);return e.x=n,e.y=s,e.width=r-n,e.height=o-s,e}(t,at);var n={testMode:e,searchRectangle:at};return this.shapeToTileXYArray(t,n,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,n){var s=x(n,"testMode",0),r=x(n,"searchRectangle",t);x(n,"order",0),i&&(e=e.bind(i)),ut=this.worldXYToTileXY(r.left,r.top,ut),lt=this.worldXYToTileXY(r.right,r.bottom,lt);var o=ut.x-1,h=ut.y-1,a=lt.x+1,u=lt.y+1;return this.forEachTileXY((function(i,n){if(gt(n,t,i.x,i.y,s))return e(i,n)}),this,{left:o,right:a,top:h,bottom:u}),this},uidToChess:function(t){return null==t?null:this.boardData.exists(t)?w.get(t).parent:null},addChess:Tt,removeChess:function(t,e,i,n,s,r){if(void 0===s&&(s=!1),void 0===r&&(r=!1),t){var o=this.chessToTileXYZ(t);if(!o)return this;e=o.x,i=o.y,n=o.z;}else if(!(t=this.tileXYZToChess(e,i,n)))return this;return r||this.boardData.removeUID(e,i,n),this.isBoard&&this.getChessData(t).setBoard(null),s&&t.destroy&&t.destroy(),this},removeAllChess:function(t,e){for(var i=this.getAllChess(),n=0,s=i.length;n<s;n++)this.removeChess(i[n],void 0,void 0,void 0,t,e);return this},swapChess:function(t,e,i){void 0===i&&(i=!0);var n=this.chessToTileXYZ(t),s=this.chessToTileXYZ(e);return null==n||null==s||(this.removeChess(t),this.removeChess(e),this.addChess(t,s.x,s.y,s.z,i),this.addChess(e,n.x,n.y,n.z,i)),this},moveChess:Tt,setChessTileZ:function(t,e,i){void 0===i&&(i=!1);var n=this.chessToTileXYZ(t);return n&&this.moveChess(t,n.x,n.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 n;return (n=!!this.infinityMode||t>=0&&t<this.width&&e>=0&&e<this.height)&&void 0!==i&&(n=this.boardData.contains(t,e,i)),n},forEachTileXY:function(t,e,i){"number"==typeof i&&(i={order:i});var n=this.width-1,s=this.height-1,r=x(i,"order",0),o=x(i,"left",0),h=x(i,"right",n),a=x(i,"top",0),u=x(i,"bottom",s);switch(this.infinityMode||(o=xt(o,0,n),a=xt(a,0,s),h=xt(h,0,n),u=xt(u,0,s)),r){case 0:for(var l=a;l<=u;l++)for(var c=o;c<=h&&(kt.x=c,kt.y=l,!(e?t.call(e,kt,this):t(kt,this)));c++);break;case 1:for(l=a;l<=u;l++)for(c=h;c>=o&&(kt.x=c,kt.y=l,!(e?t.call(e,kt,this):t(kt,this)));c--);break;case 2:for(c=o;c<=h;c++)for(l=a;l<=u&&(kt.x=c,kt.y=l,!(e?t.call(e,kt,this):t(kt,this)));l++);break;case 3:for(c=o;c<=h;c++)for(l=u;l>=a&&(kt.x=c,kt.y=l,!(e?t.call(e,kt,this):t(kt,this)));l--);}return this},getWrapTileXY:function(t,e,i){return void 0===i?i={}:!0===i&&(i=Ct),this.wrapMode?t=wt(t,0,this.width):!this.infinityMode&&(t<0||t>=this.width)&&(t=null),this.wrapMode?e=wt(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 n=this.boardData.getUID(t,e,i);return this.uidToChess(n)},tileXYToChessArray:function(t,e,i){void 0===i&&(i=[]);var n=this.boardData.getUID(t,e);if(null==n)return i;for(var s in n)i.push(this.uidToChess(n[s]));return i},tileZToChessArray:function(t,e){void 0===e&&(e=[]);var i=this.boardData.UIDToXYZ;for(var n in i)i[n].z===t&&e.push(this.uidToChess(n));return e},tileXYArrayToChessArray:function(t,e,i){Array.isArray(e)&&(i=e,e=void 0),void 0===i&&(i=[]);for(var n,s=null!=e,r=0,o=t.length;r<o;r++)n=t[r],s?i.push(this.tileXYZToChess(n.x,n.y,e)):this.tileXYToChessArray(n.x,n.y,i);return i},chessToTileXYZ:function(t){if(!t)return null;if(L(t)||function(t){return !L(t)&&t&&!!t.rexChess}(t)){var e=F(t);return this.boardData.getXYZ(e)}return (i=t)&&(A(i)||i.isTileXYZ)?t:null;var i;},offset:function(t,e,i,n){return void 0===n?n={}:!0===n&&(n=Yt),0===e&&0===i?(n.x=t.x,n.y=t.y):this.grid.offset(t,e,i,n),n},mirror:function(t,e,i,n){return void 0===n?n={}:!0===n&&(n=Xt),void 0!==i?this.offset(t,-i.x,-i.y,n):(n.x=t.x,n.y=t.y),this.grid.mirror(n,e,n),void 0!==i&&this.offset(n,i.x,i.y,n),n},rotate:function(t,e,i,n){return void 0===n?n={}:!0===n&&(n=Mt),void 0!==i?this.offset(t,-i.x,-i.y,n):(n.x=t.x,n.y=t.y),this.grid.rotate(n,e,n),void 0!==i&&this.offset(n,i.x,i.y,n),n},getOppositeDirection:function(t,e,i){if(t&&"number"!=typeof t){i=e;var n=t,s=this.chessToTileXYZ(n);t=s.x,e=s.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 n=this.chessToTileXYZ(t),s=this.chessToTileXYZ(e);return this.grid.directionBetween(n,s,i)},isDirectionInCone:function(t,e,i,n){var s=this.chessToTileXYZ(t),r=this.chessToTileXYZ(e),o=this.grid.directions;this.grid.setDirectionMode(this.sides);var h=this.grid.directionBetween(s,r,!1);this.grid.setDirectionMode(o);var a=Math.abs(h-i);return (a=Math.min(a,this.grid.directions-a))<=n/2},fit:function(t){var e,i=1/0,n=1/0;for(var s in t)e=t[s],i=Math.min(i,e.x),n=Math.min(n,e.y);if(0!==i||0!==n)for(var s in t)e=t[s],this.offset(e,-i,-n,e);var r=-1/0,o=-1/0;for(var s in t)e=t[s],r=Math.max(r,e.x),o=Math.max(o,e.y);return this.setBoardWidth(r+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 n=0;n<this.width;n++)this.isEmptyTileXYZ(n,i,t)&&e.push({x:n,y:i});return e},getRandomEmptyTileXY:function(t,e){var i,n;void 0===t&&(t=0),void 0===e?e={}:!0===e&&(e=Ot);for(var s=!0,r=20;s&&r>0;)i=Pt(0,this.width-1),n=Pt(0,this.height-1),s=null!==this.tileXYZToChess(i,n,t),r--;if(s){if(0===(Dt=this.getEmptyTileXYArray(t,Dt)).length)return null;var o=St(Dt);return e.x=o.x,e.y=o.y,Dt.length=0,e}return e.x=i,e.y=n,e},getEmptyTileXYArrayInRange:function(t,e,i,n){var s;void 0===e&&(e=1),void 0===i&&(i=0),void 0===n&&(n=[]),t=this.chessToTileXYZ(t),this.grid.ringToTileXYArray(t,e,Et);for(var r=0,o=Et.length;r<o;r++)s=Et[r],this.isEmptyTileXYZ(s.x,s.y,i)&&n.push(s);return Et.length=0,n},getRandomEmptyTileXYInRange:function(t,e,i,n){var s;void 0===e&&(e=1),void 0===i&&(i=0),void 0===n?n={}:!0===n&&(n=Rt),t=this.chessToTileXYZ(t),this.grid.ringToTileXYArray(t,e,At),_t(At);for(var r=0,o=At.length;r<o;r++)if(s=At[r],this.isEmptyTileXYZ(s.x,s.y,i))return n.x=s.x,n.y=s.y,At.length=0,n;return At.length=0,null},getTileXYAtDirection:function(t,e,i,n){var s=this.chessToTileXYZ(t);if(!s)return null;"string"==typeof e&&(e=-1===e.indexOf(",")?parseInt(e):e.split(","));var r,o="number"==typeof e,h="number"==typeof i;if(o&&h)n=this.grid.getTileXYAtDirection(s.x,s.y,e,i,n),this.getWrapTileXY(n.x,n.y,n),null==n.x||null==n.y?n=null:n.direction=e;else if(void 0===n&&(n=[]),null==e&&(e=this.grid.allDirections),o)if(A(i)){var a=x(i,"end",1),u=x(i,"start",a>0?1:-1),l=x(i,"step",a>=u?1:-1);if(u===a)null!==(r=this.getTileXYAtDirection(s,e,a))&&n.push(r);else if(u<a)for(var c=u;c<=a;c+=l)null!==(r=this.getTileXYAtDirection(s,e,c))&&n.push(r);else for(c=u;c>=a;c+=l)null!==(r=this.getTileXYAtDirection(s,e,c))&&n.push(r);}else {c=0;for(var d=i.length;c<d;c++)null!==(r=this.getTileXYAtDirection(s,e,i[c]))&&n.push(r);}else for(c=0,d=e.length;c<d;c++)h?null!==(r=this.getTileXYAtDirection(s,e[c],i))&&n.push(r):this.getTileXYAtDirection(s,e[c],i,n);return n},getNeighborTileXY:function(t,e,i){return this.getTileXYAtDirection(t,e,1,i)},getNeighborTileXYAtAngle:function(t,e,i){var n=this.angleSnapToDirection(t,e);return this.getTileXYAtDirection(t,n,1,i)},getNeighborChess:function(e,i,n,s){if(null===(e=this.chessToTileXYZ(e)))return null;null==n&&(n=e.z);var r,o=t(i);if("number"===o||"string"===o&&-1===i.indexOf(",")){var h=i,a=this.getNeighborTileXY(e,h,!0);return null===a?null:this.tileXYZToChess(a.x,a.y,n)}void 0===s&&(s=[]),this.getNeighborTileXY(e,i,Bt);for(var u=0,l=Bt.length;u<l;u++)null!=(r=this.tileXYZToChess(Bt[u].x,Bt[u].y,n))&&s.push(r);return Bt.length=0,s},getNeighborTileDirection:function(t,e){if(null===t||null===e)return null;if(t=this.chessToTileXYZ(t),e=this.chessToTileXYZ(e),pt(t,e))return null;var i=this.grid.getNeighborTileDirection(t,e);if(this.wrapMode&&null===i){for(var n=0,s=(Nt=this.getNeighborTileXY(t,null,Nt)).length;n<s;n++)if(pt(e,Nt[n])){i=n;break}Nt.length=0;}return i},getNeighborChessDirection:function(t,e){var i=this.chessToTileXYZ(t),n=this.chessToTileXYZ(e);return this.getNeighborTileDirection(i,n)},areNeighbors:function(t,e){return null!==this.getNeighborChessDirection(t,e)},mapNeighbors:function(t,e,i,n){return "number"!=typeof e&&(n=i,i=e,e=1),this.getTileXYAtDirection(t,void 0,e).map(i,n)},ringToTileXYArray:function(t,e,i){var n;void 0===i&&(i=[]),t=this.chessToTileXYZ(t),this.grid.ringToTileXYArray(t,e,Lt);for(var s=0,r=Lt.length;s<r;s++)n=Lt[s],this.contains(n.x,n.y)&&i.push(n);return Lt.length=0,i},ringToChessArray:function(t,e,i,n){var s,r;Array.isArray(i)&&(n=i,i=void 0),void 0===n&&(n=[]),t=this.chessToTileXYZ(t),this.grid.ringToTileXYArray(t,e,Zt);for(var o=0,h=Zt.length;o<h;o++)s=Zt[o],(r=this.tileXYZToChess(s.x,s.y,i))&&n.push(r);return Zt.length=0,n},filledRingToTileXYArray:function(t,e,i,n){var s;It(i)&&(n=i,i=void 0),void 0===i&&(i=!0),void 0===n&&(n=[]),t=this.chessToTileXYZ(t);for(var r=0;r<=e;r++)s=i?r:e-r,this.ringToTileXYArray(t,s,n);return n},filledRingToChessArray:function(t,e,i,n,s){var r;It(n)&&(s=n,n=void 0),void 0===n&&(n=!0),void 0===s&&(s=[]),t=this.chessToTileXYZ(t);for(var o=0;o<=e;o++)r=n?o:e-o,this.ringToChessArray(t,r,i,s);return s},hasBlocker:function(t,e,i){if(t&&"number"!=typeof t){var n=this.chessToTileXYZ(t);t=n.x,e=n.y,i=n.z;}var s;if(void 0===i){for(var r=0,o=(s=this.tileXYToChessArray(t,e,Ft)).length;r<o;r++)if(!0===this.getChessData(s[r]).blocker)return Ft.length=0,!0;return Ft.length=0,!1}return null!==(s=this.tileXYZToChess(t,e,i))&&!0===this.getChessData(s).blocker},hasEdgeBlocker:function(t,e,i,n){var s;if(void 0===i){for(var r=0,o=(s=this.tileXYToChessArray(t,e,zt)).length;r<o;r++)if(jt(this.getChessData(s[r]).blocker))return zt.length=0,!0;return zt.length=0,!1}return null!==(s=this.tileXYZToChess(t,e,i))&&jt(this.getChessData(s).blocker)}},s(ct,"getGridPoints",q),s(ct,"chessToBoard",Ut),ct),Wt=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];return e},Vt=function(t){for(var e in t)return !1;return !0},Jt=function(){function t(){e(this,t),this.XYZToUID={},this.UIDToXYZ={},this.clear();}return n(t,[{key:"shutdown",value:function(t){return this.XYZToUID=void 0,this.UIDToXYZ=void 0,this}},{key:"destroy",value:function(t){return this.shutdown(t),this}},{key:"clear",value:function(){return Wt(this.UIDToXYZ),Wt(this.XYZToUID),this.chessCount=0,this.clearBounds(),this}},{key:"clearBounds",value:function(){return this._xMax=void 0,this._xMin=void 0,this._yMax=void 0,this._yMin=void 0,this}},{key:"addUID",value:function(t,e,i,n){this.XYZToUID.hasOwnProperty(e)||(this.XYZToUID[e]={});var s=this.XYZToUID[e];return s.hasOwnProperty(i)||(s[i]={}),s[i][n]=t,this.UIDToXYZ[t]={x:e,y:i,z:n},this.chessCount++,this.clearBounds(),this}},{key:"getUID",value:function(t,e,i){var n=this.XYZToUID[t];return n&&(n=n[e])&&void 0!==i&&(n=n[i]),n}},{key:"removeUID",value:function(t,e,i){if(!this.XYZToUID.hasOwnProperty(t))return this;var n=this.XYZToUID[t];if(!n.hasOwnProperty(e))return this;var s=n[e];if(!s.hasOwnProperty(i))return this;var r=s[i];return delete s[i],delete this.UIDToXYZ[r],Vt(s)&&delete n[e],Vt(n)&&delete this.XYZToUID[t],this.chessCount--,this.clearBounds(),this}},{key:"exists",value:function(t){return this.UIDToXYZ.hasOwnProperty(t)}},{key:"contains",value:function(t,e,i){return null!=this.getUID(t,e,i)}},{key:"getXYZ",value:function(t){return this.exists(t)?this.UIDToXYZ[t]:null}},{key:"xMax",get:function(){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}},{key:"xMin",get:function(){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}},{key:"yMax",get:function(){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}},{key:"yMin",get:function(){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}}]),t}(),Ht={},Kt={},qt=function(){function t(i){e(this,t),this.resetFromJSON(i);}return n(t,[{key:"resetFromJSON",value:function(t){this.setType(x(t,"type",0)),this.setDirectionMode(x(t,"dir",4)),this.setOriginPosition(x(t,"x",0),x(t,"y",0)),this.setCellSize(x(t,"cellWidth",0),x(t,"cellHeight",0));}},{key:"setType",value:function(t){return "string"==typeof t&&(t=Qt[t]),this.mode=t,this}},{key:"setDirectionMode",value:function(t){return "string"==typeof t&&(t=te[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;}}]),t}(),$t={getWorldXY:function(t,e,i){var n,s;switch(void 0===i?i={}:!0===i&&(i=Ht),this.mode){case 0:n=t*this.width,s=e*this.height;break;case 1:n=(t-e)*this._halfWidth,s=(t+e)*this._halfHeight;}return n+=this.x,s+=this.y,i.x=n,i.y=s,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=Kt),t-=this.x,e-=this.y;var n=t/this.width,s=e/this.height;switch(this.mode){case 0:i.x=Math.round(n),i.y=Math.round(s);break;case 1:i.x=Math.round(+n+s),i.y=Math.round(-n+s);}return i},getTileX:function(t,e){return this.getTileXY(t,e,!0).x},getTileY:function(t,e){return this.getTileXY(t,e,!0).y}};
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/Object.assign(qt.prototype,$t);var Qt={orthogonal:0,isometric:1,staggered:2},te={"4dir":4,"8dir":8},ee=function(){return this._savedOriginX=this.x,this._savedOriginY=this.y,this},ie=function(){return this.x=this._savedOriginX,this.y=this._savedOriginY,this},ne=[[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]],se=ne,re=function(t,e,i,n,s){var r,o;switch(void 0===s?s={}:!0===s&&(s=oe),this.mode){case 0:r=ne[i][0],o=ne[i][1];break;case 1:r=se[i][0],o=se[i][1];}return s.x=t+n*r,s.y=e+n*o,s},oe={},he=function(t){var e,i,n,s={};for(var r in t)i=(e=t[r])[0],n=e[1],s.hasOwnProperty(i)||(s[i]={}),s[i][n]=parseInt(r);return s}(ne),ae=he,ue={0:2,1:3,2:0,3:1,4:6,5:7,6:4,7:5},le=function(t,e,i,n){void 0===n?n={}:!0===n&&(n=ce);var s=t.x+e,r=t.y+i;return n.x=s,n.y=r,n},ce={},de={},fe={},ve=function(t){return wt(t,0,this.directions)},ye=function(t){for(var e=[],i=0;i<t;i++)e.push({x:0,y:0});return e},pe={},ge=ye(4),me=new ft,be=function(t){r(s,t);var i=u(s);function s(t){var n;return e(this,s),(n=i.call(this,t)).sides=4,n}return n(s,[{key:"allDirections",get:function(){return 4===this.directions?Te:xe}},{key:"halfDirections",get:function(){return 4===this.directions?ke:we}}]),s}(qt),Te=[0,1,2,3],xe=[0,1,2,3,4,5,6,7],ke=[0,1],we=[0,1,4,5],Ce={saveOrigin:ee,restoreOrigin:ie,getTileXYAtDirection:re,getNeighborTileXY:function(t,e,i,n){return re.call(this,t,e,i,1,n)},getNeighborTileDirection:function(t,e){var i;switch(this.mode){case 0:i=he;break;case 1:i=ae;}var n=e.x-t.x,s=e.y-t.y;if(i.hasOwnProperty(n)){var r=i[n];if(r.hasOwnProperty(s))return r[s]}return null},getOppositeDirection:function(t,e,i){return ue[i]},offset:le,mirror:function(t,e,i){return void 0===i?i={}:!0===i&&(i=de),i.x=1&e?-t.x:t.x,i.y=2&e?-t.y:t.y,i},rotate:function(t,e,i){var n,s;switch(void 0===i?i={}:!0===i&&(i=fe),e=wt(e,0,3)){case 1:n=-t.y,s=t.x;break;case 2:n=-t.x,s=-t.y;break;case 3:n=t.y,s=-t.x;break;default:n=t.x,s=t.y;}return i.x=n,i.y=s,i},getDistance:function(t,e,i){var n=e.x-t.x,s=e.y-t.y;return i?Math.abs(n)+Math.abs(s):Math.sqrt(n*n+s*s)},directionBetween:function(t,e,i){var n;switch(void 0===i&&(i=!0),this.mode){case 0:case 1:if(t.y===e.y)n=e.x>=t.x?0:2;else if(t.x===e.x)n=e.y>=t.y?1:3;else if(4===this.directions){(o=K(G(t.x,t.y,e.x,e.y)))<0&&(o+=360),n=o/90,i&&(n=Math.round(n));}else {var s=e.x-t.x,r=e.y-t.y;if(s===r)n=s>0?4:6;else if(s===-r)n=s>0?7:5;else {var o;(o=K(Math.atan2(r,s)))<0&&(o+=360);var h=o/45;i&&(h=Math.round(h)),n=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 n===this.directions&&(n=0),n},directionNormalize:ve,getGridPoints:function(t,e,i){void 0===i?i=ye(4):!0===i&&(i=ge),void 0===t?(pe.x=0,pe.y=0):this.getWorldXY(t,e,pe);var n=0===this.mode?0:1;return function(t,e,i,n,s,r){void 0===r&&(r=ye(4));var o=i/2,h=n/2;0===s?(r[0].x=t+o,r[0].y=e-h,r[1].x=t+o,r[1].y=e+h,r[2].x=t-o,r[2].y=e+h,r[3].x=t-o,r[3].y=e-h):(r[0].x=t+o,r[0].y=e,r[1].x=t,r[1].y=e+h,r[2].x=t-o,r[2].y=e,r[3].x=t,r[3].y=e-h);}(pe.x,pe.y,this.width,this.height,n,i),i},getBounds:function(t,e,i){void 0===i?i=new ft:!0===i&&(i=me);var n=this.getWorldXY(t,e,!0);return i.x=n.x-.5*this.width,i.y=n.y-.5*this.height,i.width=this.width,i.height=this.height,i},ringToTileXYArray:function(t,e,i){var n,s;for(void 0===i&&(i=[]),n=e,s=-e;s<=e;s++)i.push(le(t,n,s));for(s=e,n=e-1;n>=-e;n--)i.push(le(t,n,s));for(n=-e,s=e-1;s>=-e;s--)i.push(le(t,n,s));for(s=-e,n=1-e;n<=e-1;n++)i.push(le(t,n,s));return i}};Object.assign(be.prototype,Ce);var Ye=Math.sqrt(3),Xe=Math.sqrt(3),Me=0,Pe=1,Se=2,De=3,Oe=Me,Ee=Pe,_e=Se,Ae=De,Re={},Be=Me,Ne=Pe,Le=Se,Ze=De,Ie=function(t,e,i,n){switch(void 0===n?n={}:!0===n&&(n=je),t){case Be:n.x=e-(i-(1&i))/2,n.z=i;break;case Ne:n.x=e-(i+(1&i))/2,n.z=i;break;case Le:n.x=e,n.z=i-(e-(1&e))/2;break;case Ze:n.x=e,n.z=i-(e+(1&e))/2;}return n.y=-n.x-n.z,n},Fe=function(t,e,i,n,s){switch(void 0===s?s={}:!0===s&&(s=ze),t){case Be:s.x=e+(n-(1&n))/2,s.y=n;break;case Ne:s.x=e+(n+(1&n))/2,s.y=n;break;case Le:s.x=e,s.y=n+(e-(1&e))/2;break;case Ze:s.x=e,s.y=n+(e+(1&e))/2;}return s},je={},ze={},Ue=Me,Ge=Pe,We=Se,Ve=De,Je=4/3,He=2/3,Ke={},qe={},$e=Me,Qe=Pe,ti=Se,ei=De,ii=function(){function t(i){e(this,t),this.resetFromJSON(i);}return n(t,[{key:"resetFromJSON",value:function(t){this.setType(x(t,"staggeraxis",1),x(t,"staggerindex",1)),this.setDirectionMode(),this.setOriginPosition(x(t,"x",0),x(t,"y",0));var e=x(t,"size",void 0);void 0!==e?this.setCellRadius(e):this.setCellSize(x(t,"cellWidth",0),x(t,"cellHeight",0));}},{key:"setType",value:function(t,e){return "string"==typeof t&&(t=si[t]),"string"==typeof e&&(e=ri[e]),this.staggeraxis=t,this.staggerindex=e,this.mode=0===t?0===e?ei:ti:0===e?Qe:$e,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:Ye*t.size}(e),n=function(t){return 0===t.type?Xe*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;}}]),t}(),ni={getWorldXY:function(t,e,i){void 0===i?i={}:!0===i&&(i=Re);var n=t*this.width,s=e*this.height;switch(this.mode){case Oe:1&e&&(n+=this._halfWidth),s*=.75;break;case Ee:1&e&&(n-=this._halfWidth),s*=.75;break;case _e:n*=.75,1&t&&(s+=this._halfHeight);break;case Ae:n*=.75,1&t&&(s-=this._halfHeight);}return n+=this.x,s+=this.y,i.x=n,i.y=s,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,s;switch(void 0===i?i={}:!0===i&&(i=qe),t-=this.x,e-=this.y,this.mode){case Ue:case Ge:s=e*Je/this.height,n=t/this.width-He*(e/this.height);break;case We:case Ve:s=e/this.height-He*(t/this.width),n=t*Je/this.width;}var r=function(t,e,i){return void 0===i?i={}:!0===i&&(i=je),i.x=t,i.y=-t-e,i.z=e,i}(n,s,Ke);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=je);var s=Math.round(t),r=Math.round(e),o=Math.round(i),h=Math.abs(s-t),a=Math.abs(r-e),u=Math.abs(o-i);h>a&&h>u?s=-r-o:a>u?r=-s-o:o=-s-r,n.x=s,n.y=r,n.z=o;}(r),Fe(this.mode,r.x,r.y,r.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(ii.prototype,ni);var si={y:0,x:1},ri={even:0,odd:1},oi=[[[[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