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=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 * @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 * @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;a0&&(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 * @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 * @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=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 * @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;e0;){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;i0;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=0&&t=0&&e=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;n0;)i=ft(0,this.width-1),s=ft(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;n0?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;d+=c)null!==(o=this.getTileXYAtDirection(r,e,d))&&s.push(o)}else{d=0;for(var v=i.length;d(e=(t=h[a]).x)&&(s=e),r(i=t.y)&&(n=i),ot&&(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._yMaxt&&(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.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 pe=0,fe=1,ge=2,ye=3;const me=pe,be=fe,Te=ge,xe=ye;var we={};const Ce=pe,Ye=fe,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=pe,Oe=fe,_e=ge,Ae=ye,Re=4/3,Be=2/3;var Le={},Ne={};const Fe=pe,Ie=fe,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=pe,He=fe,$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=pe,ri=fe,ni=ge,oi=ye;var hi={};const ai=pe,li=fe;var ui={},ci={},di={},vi={},pi={},fi={}; /** * @author Richard Davey * @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,pi),Pe(this.mode,e.x,e.y,fi);var r=fi.x-pi.x,n=fi.y-pi.y,o=fi.z-pi.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,p=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-p,r[1].x=t+c,r[1].y=e+p,r[2].x=t,r[2].y=e+v,r[3].x=t-c,r[3].y=e+p,r[4].x=t-c,r[4].y=e-p,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.width=this.width,i.height=this.height,i},ringToTileXYArray:function(t,e,i){void 0===i&&(i=[]);var s,r,n,o=Pe(this.mode,t.x,t.y,!0),h=o.x,a=(o.y,o.z);for(n=e,s=0;s>=-e;s--)r=-s-n,i.push(ke(this.mode,h+s,0,a+n));for(s=-e,r=1;r<=e;r++)n=-s-r,i.push(ke(this.mode,h+s,0,a+n));for(r=e,n=-1;n>=-e;n--)s=-r-n,i.push(ke(this.mode,h+s,0,a+n));for(n=-e,s=1;s<=e;s++)r=-s-n,i.push(ke(this.mode,h+s,0,a+n));for(s=e,r=-1;r>=-e;r--)n=-s-r,i.push(ke(this.mode,h+s,0,a+n));for(r=-e,n=1;n<=e-1;n++)s=-r-n,i.push(ke(this.mode,h+s,0,a+n));return i}};Object.assign(wi.prototype,Xi);var Mi={quadGrid:oe,hexagonGrid:wi};let Pi=class extends r{constructor(t,e){y(t)&&void 0===e&&(e=t,t=void 0),super(),this.isShutdown=!1,this.scene=t,this.boardData=new Rt,this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.isBoard=n(t,"isBoard",!0),this.setGrid(n(t,"grid",void 0)),this.setWrapMode(n(t,"wrap",!1)),this.setInfinityMode(n(t,"infinity",!1)),this.setBoardWidth(n(t,"width",0)),this.setBoardHeight(n(t,"height",0)),this}boot(){}shutdown(t){if(!this.isShutdown)return this.isBoard&&this.removeAllChess(!t,!0),super.shutdown(),this.boardData.shutdown(t),this.scene=void 0,this.boardData=void 0,this.isShutdown=!0,this}destroy(t){this.isShutdown||(this.emit("destroy",this,t),this.shutdown(t))}setGrid(t){if(y(t)){var e=t,i=n(e,"gridType","quadGrid");t=new Mi[i](e)}return this.grid=t,this}setWrapMode(t){return void 0===t&&(t=!0),this.wrapMode=t,this}setInfinityMode(t){return void 0===t&&(t=!0),this.infinityMode=t,this}setBoardSize(t,e){return this.setBoardWidth(t),this.setBoardHeight(e),this}exists(t){return this.boardData.exists(this.getChessUID(t))}get chessCount(){return this.boardData.chessCount}clear(t){return void 0===t&&(t=!0),this.removeAllChess(t,!0),this.boardData.clear(),this}static GetBoard(t){return Et(t)}};Object.assign(Pi.prototype,Ot);const ki=Phaser.GameObjects.Zone;class Si extends ki{constructor(t){super(t,0,0,1,1),t.add.existing(this),this.setScrollFactor(0),this.setInteractive({hitArea:{},hitAreaCallback:function(){return!0}})}}const Di=Phaser.GameObjects.GameObject.RENDER_MASK;var Ei=function(t){if(t.renderFlags!==Di)return!1;var e=!0,i=t.parentContainer;if(i)do{if(i.renderFlags!==Di){e=!1;break}i=i.parentContainer}while(i);return e},Oi=function(t,e,i,s,r,n){if(null!=s&&null!=r){for(var o,h="string"!=typeof t?t:void 0,a="string"!=typeof e?e:void 0,l=i.tileXYToChessArray(s,r,_i),u=0,c=l.length;u0),this.onDragStart())}onPointerUp(t){this.enable&&(!this.bounds||this.bounds.contains(t.x,t.y))&&this.pointer===t&&(this.pointer=void 0,this.pointerCamera=void 0,this.movedState=!1,this.tracerState=os,this.onDragEnd())}onPointerMove(t){if(this.enable&&t.isDown){var e=!this.bounds||this.bounds.contains(t.x,t.y),i=this.pointer===t;!i&&e||(i&&!e?this.onPointerUp(t):(this.movedState||(this.movedState=t.x!==t.downX||t.y!==t.downY),this.movedState&&this.onDrag()))}}dragCancel(){return this.tracerState===hs&&this.onDragEnd(),this.pointer=void 0,this.tracerState=os,this}onDragStart(){this.emit("dragstart",this)}onDragEnd(){this.emit("dragend",this)}onDrag(){this.emit("drag",this)}preUpdate(t,e){}postUpdate(t,e){}startTicking(){super.startTicking(),this.scene.sys.events.on("preupdate",this.preUpdate,this),this.scene.sys.events.on("postupdate",this.postUpdate,this)}stopTicking(){super.stopTicking(),this.scene&&(this.scene.sys.events.off("preupdate",this.preUpdate,this),this.scene.sys.events.off("postupdate",this.postUpdate,this))}setRecongizedStateObject(t){return this.recongizedState=t,this}get state(){return this.recongizedState.state}set state(t){this.recongizedState.state=t}cancel(){return this.state=as,this}isPointerInGameObject(t,e,i){var s=this.lastPointer;return!!s&&function(t,e,i,s){return ss(t,e,ts,i,s)}(t,s,e,i)}}const os=0,hs=1,as="IDLE";var ls={setEventEmitter(t,e){return void 0===e&&(e=r),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: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):[]}};const us=["next","exit","enter"];let cs=class{constructor(t){var e=n(t,"states",void 0);e&&this.addStates(e);var i=n(t,"extend",void 0);if(i)for(var s in i)this.hasOwnProperty(s)&&void 0!==this[s]||(this[s]=i[s]);var r=n(t,"eventEmitter",void 0),o=n(t,"EventEmitterClass",void 0);this.setEventEmitter(r,o),this._stateLock=!1,this.resetFromJSON(t)}shutdown(){this.destroyEventEmitter()}destroy(){this.shutdown()}resetFromJSON(t){this.setEnable(n(t,"enable",!0)),this.start(n(t,"start",void 0));var e=n(t,"init",void 0);return e&&e.call(this),this}toJSON(){return{curState:this.state,prevState:this.prevState,enable:this.enable,start:this._start}}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}toggleEnable(){return this.setEnable(!this.enable),this}set state(t){if(this.enable&&!this._stateLock&&this._state!==t){if(this._prevState=this._state,this._state=t,this._stateLock=!0,this.emit("statechange",this),null!=this._prevState){var e="exit_"+this._prevState,i=this[e];i&&i.call(this),this.emit(e,this)}if(this._stateLock=!1,null!=this._state){var s="enter_"+this._state,r=this[s];r&&r.call(this),this.emit(s,this)}}}get state(){return this._state}get prevState(){return this._prevState}start(t){return this._start=t,this._prevState=void 0,this._state=t,this}goto(t){return null!=t&&(this.state=t),this}next(){var t,e=this["next_"+this.state];return e&&(t="string"==typeof e?e:e.call(this)),this.goto(t),this}get stateProperties(){return us}addState(t,e){"string"!=typeof t&&(t=(e=t).name);for(var i=this.stateProperties,s=0,r=i.length;sthis.tapOffset&&(this.state=Ts,this.state=bs);break;case Ts:this.state=bs}}onDragEnd(){this.state===bs&&(this.tapsCount++,this.emit("tapping",this,this.gameObject,this.lastPointer),void 0!==this.maxTaps&&this.tapsCount===this.maxTaps&&(this.state=Ts))}onDrag(){this.state!==ms&&this.pointer.getDistance()>this.dragThreshold&&(this.state=ms)}preUpdate(t,e){if(this.isRunning&&this.enable&&this.state===bs){var i=this.lastPointer;i.isDown?t-i.downTime>this.holdTime&&(this.state=ms):t-i.upTime>this.tapInterval&&(void 0===this.minTaps||this.tapsCount>=this.minTaps?this.state=Ts:this.state=ms)}}postUpdate(t,e){this.isRunning&&this.enable&&this.state===Ts&&(this.state=ms)}get isTapping(){return this.state===Ts}get isTapped(){return this.isTapping}setHoldTime(t){return this.holdTime=t,this}setTapInterval(t){return this.tapInterval=t,this}setDragThreshold(t){return this.dragThreshold=t,this}setTapOffset(t){return this.tapOffset=t,this}setMaxTaps(t){return this.maxTaps=t,this}setMinTaps(t){return this.minTaps=t,this}setTaps(t,e){return void 0===e&&(e=t),this.setMinTaps(t).setMaxTaps(e),this}}const ms="IDLE",bs="BEGIN",Ts="RECOGNIZED";var xs=function(){var t=this.touchZone?this.touchZone:this.board.scene,e=new ys(t);return e.on("tap",ws,this),e},ws=function(t){var e=this.board,i=e.worldXYToTileXY(t.worldX,t.worldY),s=i.x,r=i.y;e.contains(s,r)&&(e.emit("tiletap",t,i),e.emit(`tile${t.tapsCount}tap`,t,i),Oi((function(i){e.emit("gameobjecttap",t,i),e.emit(`gameobject${t.tapsCount}tap`,t,i)}),(function(e){e.emit("board.tap",t),e.emit(`board.${t.tapsCount}tap`,t)}),e,s,r,t))};const Cs=Phaser.Utils.Objects.GetValue;class Ys extends ns{constructor(t,e){super(t,e);var i=this,s={states:{IDLE:{enter:function(){i.x=0,i.y=0,i.worldX=0,i.worldY=0,i.lastPointer=void 0},exit:function(){var t=i.lastPointer;i.x=t.x,i.y=t.y,i.worldX=t.worldX,i.worldY=t.worldY}},BEGIN:{enter:function(){i.start()},exit:function(){i.stop()}},RECOGNIZED:{enter:function(){i.emit("pressstart",i,i.gameObject,i.lastPointer)},exit:function(){i.emit("pressend",i,i.gameObject,i.lastPointer)}}},init:function(){this.state=Xs},eventEmitter:!1};this.setRecongizedStateObject(new ps(s))}resetFromJSON(t){return super.resetFromJSON(t),this.setDragThreshold(Cs(t,"threshold",9)),this.setHoldTime(Cs(t,"time",251)),this}onDragStart(){this.state=Ms,0===this.holdTime&&(this.state=Ps)}onDragEnd(){this.state=Xs}onDrag(){this.state!==Xs&&this.pointer.getDistance()>this.dragThreshold&&(this.state=Xs)}preUpdate(t,e){this.isRunning&&this.enable&&this.state===Ms&&t-this.pointer.downTime>=this.holdTime&&(this.state=Ps)}get isPressing(){return this.state===Ps}get isPressed(){return this.isPressing}setHoldTime(t){return this.holdTime=t,this}setDragThreshold(t){return this.dragThreshold=t,this}}const Xs="IDLE",Ms="BEGIN",Ps="RECOGNIZED";var ks=function(){var t=this.touchZone?this.touchZone:this.board.scene,e=new Ys(t);return e.on("pressstart",Ss,this).on("pressend",Ds,this),e},Ss=function(t){var e=this.board,i=e.worldXYToTileXY(t.worldX,t.worldY),s=i.x,r=i.y;e.contains(s,r)&&(e.emit("tilepressstart",t,i),Oi("gameobjectpressstart","board.pressstart",e,s,r,t))},Ds=function(t){var e=this.board,i=e.worldXYToTileXY(t.worldX,t.worldY),s=i.x,r=i.y;e.contains(s,r)&&(e.emit("tilepressend",t,i),Oi("gameobjectpressend","board.pressend",e,s,r,t))};const Es=Phaser.Math.Distance.Between,Os=Phaser.Math.Angle.Between;var _s={getDt:function(){var t;return t=this.scene,v(t).loop.delta},getVelocity:function(){var t=this.pointer.position,e=this.pointer.prevPosition;return Es(e.x,e.y,t.x,t.y)/(.001*this.getDt())},getVelocityX:function(){var t=this.pointer.position,e=this.pointer.prevPosition;return Math.abs(t.x-e.x)/(.001*this.getDt())},getVelocityY:function(){var t=this.pointer.position,e=this.pointer.prevPosition;return Math.abs(t.y-e.y)/(.001*this.getDt())},getVelocityAngle:function(){var t=this.pointer.position,e=this.pointer.prevPosition;return Os(e.x,e.y,t.x,t.y)}},As={"up&down":0,"left&right":1,"4dir":2,"8dir":3},Rs={};const Bs=Phaser.Utils.Objects.GetValue,Ls=Phaser.Math.RadToDeg;class Ns extends ns{constructor(t,e){super(t,e);var i=this,s={states:{IDLE:{enter:function(){i.x=0,i.y=0,i.worldX=0,i.worldY=0},exit:function(){var t=i.lastPointer;i.x=t.x,i.y=t.y,i.worldX=t.worldX,i.worldY=t.worldY}},BEGIN:{enter:function(){i.validDrag=!1}},RECOGNIZED:{enter:function(){i.start(),i.updateDirectionStates(),i.emit("swipe",i,i.gameObject,i.lastPointer)},exit:function(){i.stop(),i.clearDirectionStates()}}},init:function(){this.state=Fs},eventEmitter:!1};this.setRecongizedStateObject(new ps(s)),this.clearDirectionStates()}resetFromJSON(t){return super.resetFromJSON(t),this.setDragThreshold(Bs(t,"threshold",10)),this.setVelocityThreshold(Bs(t,"velocityThreshold",1e3)),this.setDirectionMode(Bs(t,"dir","8dir")),this}onDragStart(){this.state=Is}onDragEnd(){this.state=Fs}onDrag(){this.state===Is&&(this.validDrag||(this.validDrag=0===this.dragThreshold||this.pointer.getDistance()>=this.dragThreshold),this.validDrag&&this.dragVelocity>this.velocityThreshold&&(this.state=Zs))}postUpdate(t,e){this.isRunning&&this.enable&&this.state===Zs&&(this.state=Fs)}get isSwiping(){return this.state===Zs}get isSwiped(){return this.isSwiping}get dragVelocity(){var t;switch(this.dirMode){case 0:t=this.getVelocityY();break;case 1:t=this.getVelocityX();break;default:t=this.getVelocity()}return t}setDragThreshold(t){return this.dragThreshold=t,this}setVelocityThreshold(t){return this.velocityThreshold=t,this}setDirectionMode(t){return"string"==typeof t&&(t=As[t]),this.dirMode=t,this}updateDirectionStates(){return function(t,e,i){switch(void 0===i?i={}:!0===i&&(i=Rs),i.left=!1,i.right=!1,i.up=!1,i.down=!1,t=(t+360)%360,e){case 0:t<180?i.down=!0:i.up=!0;break;case 1:t>90&&t<=270?i.left=!0:i.right=!0;break;case 2:t>45&&t<=135?i.down=!0:t>135&&t<=225?i.left=!0:t>225&&t<=315?i.up=!0:i.right=!0;break;case 3:t>22.5&&t<=67.5?(i.down=!0,i.right=!0):t>67.5&&t<=112.5?i.down=!0:t>112.5&&t<=157.5?(i.down=!0,i.left=!0):t>157.5&&t<=202.5?i.left=!0:t>202.5&&t<=247.5?(i.left=!0,i.up=!0):t>247.5&&t<=292.5?i.up=!0:t>292.5&&t<=337.5?(i.up=!0,i.right=!0):i.right=!0}}(Ls(this.getVelocityAngle()),this.dirMode,this),this}clearDirectionStates(){return this.left=!1,this.right=!1,this.up=!1,this.down=!1,this}}Object.assign(Ns.prototype,_s);const Fs="IDLE",Is="BEGIN",Zs="RECOGNIZED";var js,zs=function(){var t=this.touchZone?this.touchZone:this.board.scene,e=new Ns(t);return e.on("swipe",Gs,this),e},Gs=function(t){var e=this.board,i=e.worldXYToTileXY(t.worldX,t.worldY),s=i.x,r=i.y;e.contains(s,r)&&(t.direction=e.angleSnapToDirection(i,t.getVelocityAngle()),e.emit("tileswipe",t,i),Oi("gameobjectswipe","board.swipe",e,s,r,t))};class Us{constructor(t,e){var i=n(e,"enable",!0),s=n(e,"useTouchZone",!0),r=t.scene;if(this.board=t,this.touchZone=void 0,this._enable=!0,this.pointer=null,this.tilePosition={x:void 0,y:void 0},this.prevTilePosition={x:void 0,y:void 0},s){var o=new Si(r);o.on("pointerdown",Ai,this),o.on("pointerup",Ri,this),o.on("pointermove",Bi,this),this.touchZone=o}else r.input.on("pointerdown",Ai,this),r.input.on("pointerup",Ri,this),r.input.on("pointermove",Bi,this);this.tap=xs.call(this),this.press=ks.call(this),this.swipe=zs.call(this),t.once("destroy",this.onBoardDestroy,this),this.setEnable(i)}destroy(t){if(this.tap.destroy(t),this.press.destroy(t),this.swipe.destroy(t),this.touchZone)this.touchZone.destroy(t),this.touchZone=void 0;else{var e=this.board.scene;e&&(e.input.off("pointerdown",Ai,this),e.input.off("pointerup",Ri,this),e.input.off("pointermove",Bi,this))}this.board=void 0}onBoardDestroy(t,e){this.destroy(e)}get enable(){return this._enable}set enable(t){this._enable!==t&&(t||(this.pointer=null),this._enable=t,this.touchZone&&(t?this.touchZone.setInteractive():this.touchZone.disableInteractive()),this.tap.setEnable(t),this.press.setEnable(t),this.swipe.setEnable(t))}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}}class Ws extends Pi{boot(){super.boot(),this.scene&&this.isBoard&&this.scene.sys.events.once("shutdown",this.destroy,this)}shutdown(t){if(!this.isShutdown)return this.scene&&this.isBoard&&this.scene.sys.events.off("shutdown",this.destroy,this),super.shutdown(t),this}get touchZone(){return this.input?this.input.touchZone:null}getTouchZone(){return this.touchZone}}var Vs={setInteractive:function(t){if(this.input){var e=!1!==t;this.input.setEnable(e)}else this.input=new Us(this,t);return this},forEachCullTileXY:function(t,e,i){"number"==typeof i&&(i={order:i}),void 0===i&&(i={});var s=n(i,"order",0),r=n(i,"camera",this.scene.cameras.main),o=n(i,"paddingX",1),h=n(i,"paddingY",1);return void 0===js&&(js=new W),js.width=(r.width+2*o)/r.zoomX,js.height=(r.height+2*h)/r.zoomY,js.centerX=r.centerX+r.scrollX,js.centerY=r.centerY+r.scrollY,this.forEachTileXYInShape(js,t,e,{order:s,testMode:1}),this}};Object.assign(Ws.prototype,Vs);var Js=function(t){return null==t||""===t||0===t.length},Hs=function(t,e,i,s){if(void 0===s&&(s="."),"object"==typeof t){if(Js(e)){if(null==i)return;"object"==typeof i&&(t=i)}else{"string"==typeof e&&(e=e.split(s));var r=e.pop(),n=function(t,e,i){var s=t;if(Js(e));else{var r;"string"==typeof e&&(e=e.split("."));for(var n=0,o=e.length;nr)return i?-1:1;if(s0;){var n=i.x,o=i.y,h=this.targetX,a=this.targetY,l=br(n,o,h,a);if(l<=1e-4){if(this.targets.length>0){var u=this.targets.shift();this.targetX=u.x,this.targetY=u.y;continue}return this.complete(),this}if(r0))return this.complete(),this;var p=this.targets.shift();this.targetX=p.x,this.targetY=p.y}return this}};var Cr=function(){var t=this.moveToTask.nextlines;return!!t&&0!==t.length&&(lr.apply(this,t[0]),t.length=0,!0)};let Yr=class extends nr{constructor(t,e){super(t,e),this.chessData=w(t),this.scene=t.scene,this.moveToTask=new wr(t,{tickingMode:0}),this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.isRunning=n(t,"isRunning",!1),this.setEnable(n(t,"enable",!0)),this.timeScale=n(t,"timeScale",1),this.setSpeed(n(t,"speed",400)),this.setRotateToTarget(n(t,"rotateToTarget",!1)),this.setOccupiedTest(n(t,"occupiedTest",!1)),this.setBlockerTest(n(t,"blockerTest",!1)),this.setEdgeBlockerTest(n(t,"edgeBlockerTest",!1)),this.setMoveableTestCallback(n(t,"moveableTest",void 0),n(t,"moveableTestScope",void 0)),this.setSneakEnable(n(t,"sneak",!1)),this.destinationTileX=n(t,"destinationTileX",null),this.destinationTileY=n(t,"destinationTileY",null),this.destinationDirection=n(t,"destinationDirection",null),this.lastMoveResult=n(t,"lastMoveResult",void 0),this}toJSON(){return{isRunning:this.isRunning,enable:this.enable,timeScale:this.timeScale,speed:this.speed,occupiedTest:this.occupiedTest,blockerTest:this.blockerTest,edgeBlockerTest:this.edgeBlockerTest,moveableTest:this.moveableTestCallback,moveableTestScope:this.moveableTestScope,rotateToTarget:this.rotateToTarget,destinationTileX:this.destinationTileX,destinationTileY:this.destinationTileY,destinationDirection:this.destinationDirection,lastMoveResult:this.lastMoveResult,tickingMode:this.tickingMode}}shutdown(t){this.moveToTask.shutdown(t),super.shutdown(t)}set enable(t){this.moveToTask.setEnable(t)}get enable(){return this.moveToTask.enable}setEnable(t){return null==t&&(t=!0),this.enable=t,this}get timeScale(){return this.moveToTask.timeScale}set timeScale(t){this.moveToTask.timeScale=t}set speed(t){this.moveToTask.setSpeed(t)}get speed(){return this.moveToTask.speed}setSpeed(t){return this.speed=t,this}set rotateToTarget(t){this.moveToTask.setRotateToTarget(t)}get rotateToTarget(){return this.moveToTask.rotateToTarget}setRotateToTarget(t){return void 0===t&&(t=!0),this.rotateToTarget=t,this}setOccupiedTest(t){return void 0===t&&(t=!0),this.occupiedTest=t,this}setBlockerTest(t){return void 0===t&&(t=!0),this.blockerTest=t,this}setEdgeBlockerTest(t){return void 0===t&&(t=!0),this.edgeBlockerTest=t,this}setMoveableTestCallback(t,e){return this.moveableTestCallback=t,this.moveableTestScope=e,this}setSneakEnable(t){return void 0===t&&(t=!0),this.sneakMode=t,this.tileZSave=void 0,this}update(t,e){if(!this.isRunning||!this.enable)return this;var i=this.moveToTask;return i.update(t,e),i.isRunning||Cr.call(this)||this.complete(),this}};Object.assign(Yr.prototype,yr);var Xr={x:0,y:0,z:0},Mr={x:0,y:0,z:0},Pr={},kr={},Sr=[];class Dr extends nr{constructor(t,e){super(t,e),this.moveToTask=new wr(t,{tickingMode:0}),this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.isRunning=n(t,"isRunning",!1),this.setEnable(n(t,"enable",!0)),this.timeScale=n(t,"timeScale",1),this.setSpeed(n(t,"speed",400)),this.destinationTileX=n(t,"destinationTileX",null),this.destinationTileY=n(t,"destinationTileY",null),this.destinationDirection=n(t,"destinationDirection",null),this.lastMoveResult=n(t,"lastMoveResult",void 0),this}toJSON(){return{isRunning:this.isRunning,enable:this.enable,timeScale:this.timeScale,speed:this.speed,moveableTest:this.moveableTestCallback,moveableTestScope:this.moveableTestScope,destinationTileX:this.destinationTileX,destinationTileY:this.destinationTileY,destinationDirection:this.destinationDirection,lastMoveResult:this.lastMoveResult,tickingMode:this.tickingMode}}shutdown(t){this.isShutdown||(this.moveToTask.shutdown(t),super.shutdown(t))}set enable(t){this.moveToTask.setEnable(t)}get enable(){return this.moveToTask.enable}setEnable(t){return null==t&&(t=!0),this.enable=t,this}get timeScale(){return this.moveToTask.timeScale}set timeScale(t){this.moveToTask.timeScale=t}set speed(t){this.moveToTask.setSpeed(t)}get speed(){return this.moveToTask.speed}setSpeed(t){return this.speed=t,this}update(t,e){if(!this.isRunning||!this.enable)return this;var i=this.moveToTask;return i.update(t,e),i.isRunning||this.complete(),this}}var Er={canMoveTo:function(t,e,i){var s=this.parent,r=s.mainBoard;if(null==r)return!1;if(Xr.x=s.tileX,Xr.y=s.tileY,Mr.x=t,Mr.y=e,Mr.x===Xr.x&&Mr.y===Xr.y)return!0;if(s.pullOutFromMainBoard(),!s.canPutOnMainBoard(r,Mr.x,Mr.y))return s.putBack(),!1;if(this.moveableTestCallback){if(void 0===i&&(i=r.getNeighborTileDirection(Xr,Mr)),this.moveableTestScope)var n=this.moveableTestCallback.call(this.moveableTestScope,Xr,Mr,i,r);else n=this.moveableTestCallback(Xr,Mr,i,r);if(!n)return s.putBack(),!1}return s.putBack(),!0},moveTo:function(t,e,i){var s=this.parent,r=s.mainBoard;if(null==r)return this.lastMoveResult=!1,this;if(null!=t&&"number"!=typeof t){var o=t;t=n(o,"x",void 0),e=n(o,"y",void 0),i=n(o,"direction",void 0)}if(Pr.x=s.tileX,Pr.y=s.tileY,(void 0!==i&&null==t||null==e)&&(null!==(h=r.getNeighborTileXY(Pr,i,!0))?(t=h.x,e=h.y):(t=null,e=null)),null==t||null==e)return this.lastMoveResult=!1,this;if(void 0===i&&(kr.x=t,kr.y=e,i=board.getNeighborTileDirection(Pr,kr)),!this.canMoveTo(t,e,i))return this.lastMoveResult=!1,this;this.destinationTileX=t,this.destinationTileY=e,this.destinationDirection=i;var h=r.tileXYToWorldXY(t,e,!0);return this.moveToTask.moveTo(h.x,h.y),s.putOnMainBoard(r,t,e,!1),this.isRunning=!0,this.lastMoveResult=!0,this},moveToward:function(t){return this.moveTo(void 0,void 0,t),this},moveToRandomNeighbor:function(){var t=this.parent.mainBoard;if(null==t)return this.lastMoveResult=!1,this;var e=t.grid.allDirections;Sr.length!==e.length&&vr(e,Sr),Tt(Sr);for(var i=0,s=Sr.length;i0?this.items.pop():null}push(t){return this.items.push(t),this}pushMultiple(t){return this.items.push.apply(this.items,t),t.length=0,this}clear(){return this.items.length=0,this}};class Ir{constructor(t){this.sn=0,this.pool=Fr,this.nodes={},this.pathFinder=t,this.closestNode=null}destroy(){return this.freeAllNodes(),this.pathFinder=null,this.pool=void 0,this}getNode(t,e,i){var s;switch(typeof t){case"number":s=X(t,e);break;case"string":s=t,i=e;break;default:var r=t;i=e,t=r.x,e=r.y,s=X(t,e)}if(void 0===i&&(i=!1),this.sn++,!this.nodes.hasOwnProperty(s)){if(!i)return null;var n=this.pool.pop();null===n&&(n=new Nr),n.reset(this),n.sn=this.sn,n.key=s,n.x=t,n.y=e,this.nodes[s]=n}return this.nodes[s]}freeAllNodes(){this.closestNode=null;var t,e=this.nodes,i=this.pool;for(var s in e)(t=e[s]).destroy(),i.push(t),delete e[s];return this.sn=0,this}getAllNodes(){return this.nodes}}var Zr={AREA_MODE:16,PATH_MODE:0,random:0,diagonal:1,straight:2,line:3,"A*":10,"A*-random":11,"A*-line":12,BLOCKER:null,INFINITY:void 0};const jr=Zr.PATH_MODE,zr=Zr["A*"],Gr=Zr["A*-line"],Ur=Zr["A*-random"],Wr=Zr.BLOCKER,Vr=Zr.INFINITY;var Jr=new class{constructor(t){this.content=[],this.scoreFunction=t}clear(){this.content.length=0}push(t){this.content.push(t),this.sinkDown(this.content.length-1)}pop(){var t=this.content[0],e=this.content.pop();return this.content.length>0&&(this.content[0]=e,this.bubbleUp(0)),t}remove(t){var e=this.content.indexOf(t),i=this.content.pop();e!==this.content.length-1&&(this.content[e]=i,this.scoreFunction(i)0;){var i=(t+1>>1)-1,s=this.content[i];if(!(this.scoreFunction(e)0;){var d=Jr.pop();if(n&&d===u){l=u;break}d.closed=!0;for(var v,p,f=d.getNeighborNodes(),g=0,y=f.length;gi||(!b||ms?1:i0;)switch(u.push(l),h=l.preNodes.length,i){case sn:case rn:case nn:l=o=l.preNodes[0];break;case qr:l=o=1===h?l.preNodes[0]:l.preNodes[ft(0,h-1)];break;case Qr:for(var c=0;c0&&null!==(i=this.getNextTile(n,this.preTileXY));)(s=i.cost)===kn&&(s=t),t>=s&&e.push(i),t-=s,this.preTileXY=n,n=i;for(var o=e.length-1;o>=0&&0===e[o].cost;o--)e.length=o;return e},getNextTile:function(t,e){for(var i,s,r,n=this.board,o=n.grid.allDirections,h=null,a=null,l=[],u=null,c=0,d=o.length;c=0;i--)(e=this.children[i]).parentContainer||e.displayList||e.destroy(t);this.clear(!t),super.destroy(t)}}contains(t){return-1!==this.children.indexOf(t)}add(t){var e=this;return Rn(this.children,t,0,(function(t){t.once("destroy",e.onChildDestroy,e)}),this),this}remove(t,e){var i=this;return Bn(this.children,t,(function(t){t.off("destroy",i.onChildDestroy,i),e&&t.destroy()})),this}onChildDestroy(t,e){this.remove(t,!1)}clear(t){for(var e,i=0,s=this.children.length;ijn(t),resetChildState(t){return this.resetChildPositionState(t).resetChildVisibleState(t).resetChildAlphaState(t).resetChildActiveState(t),this},resetChildrenState(t){for(var e=0,i=t.length;ejn(t).x,getChildLocalY:t=>jn(t).y};const ro=Phaser.Math.DegToRad;var no={updateChildRotation(t){var e=jn(t),i=e.parent;return e.syncRotation&&(t.rotation=i.rotation+e.rotation),this},syncRotation(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildRotation,this),this},resetChildRotationState(t){var e=jn(t),i=e.parent;return e.rotation=t.rotation-i.rotation,this},setChildRotation(t,e){return t.rotation=e,this.resetChildRotationState(t),this},setChildAngle(t,e){return t.angle=e,this.resetChildRotationState(t),this},setChildLocalRotation(t,e){return jn(t).rotation=e,this.updateChildRotation(t),this},setChildLocalAngle(t,e){return jn(t).rotation=ro(e),this.updateChildRotation(t),this},resetLocalRotationState(){var t=jn(this).parent;return t&&t.resetChildRotationState(this),this},getChildLocalRotation:t=>jn(t).rotation},oo={updateChildScale(t){var e=jn(t),i=e.parent;return e.syncScale&&(t.scaleX=i.scaleX*e.scaleX,t.scaleY=i.scaleY*e.scaleY),this},syncScale(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildScale,this),this},resetChildScaleState(t){var e=jn(t),i=e.parent;return e.scaleX=io(t.scaleX,i.scaleX),e.scaleY=io(t.scaleY,i.scaleY),this},setChildScale(t,e,i){return void 0===i&&(i=e),t.scaleX=e,t.scaleY=i,this.resetChildScaleState(t),this},setChildLocalScale(t,e,i){void 0===i&&(i=e);var s=jn(t);return s.scaleX=e,s.scaleY=i,this.updateChildScale(t),this},setChildDisplaySize(t,e,i){return t.setDisplaySize(e,i),this.resetChildScaleState(t),this},resetLocalScaleState(){var t=jn(this).parent;return t&&t.resetChildScaleState(this),this},getChildLocalScaleX:t=>jn(t).scaleX,getChildLocalScaleY:t=>jn(t).scaleY},ho={updateChildVisible(t){var e=jn(t),i=e.parent,s=!e.hasOwnProperty("maskVisible")||e.maskVisible,r=!i||i.visible;return t.visible=r&&e.visible&&s,this},syncVisible(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildVisible,this),this},resetChildVisibleState(t){var e=jn(t);return e.hasOwnProperty("maskVisible")&&delete e.maskVisible,e.visible=t.visible,this},setChildVisible(t,e){return this.setChildLocalVisible(t,e),this},setChildLocalVisible(t,e){return void 0===e&&(e=!0),jn(t).visible=e,this.updateChildVisible(t),this},setChildMaskVisible(t,e){return void 0===e&&(e=!0),jn(t).maskVisible=e,this.updateChildVisible(t),this},resetLocalVisibleState(){var t=jn(this).parent;return t&&t.resetChildVisibleState(this),this},getChildLocalVisible:t=>jn(t).visible},ao={updateChildAlpha(t){var e=jn(t),i=e.parent;return e.syncAlpha&&(t.alpha=i.alpha*e.alpha),this},syncAlpha(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildAlpha,this),this},resetChildAlphaState(t){var e=jn(t),i=e.parent;return e.alpha=io(t.alpha,i.alpha),this},setChildAlpha(t,e){return t.alpha=e,this.resetChildAlphaState(t),this},setChildLocalAlpha(t,e){return jn(t).alpha=e,this.updateChildAlpha(t),this},resetLocalAlphaState(){var t=jn(this).parent;return t&&t.resetChildAlphaState(this),this},getChildLocalAlpha:t=>jn(t).alpha},lo={updateChildActive(t){var e=jn(t),i=e.parent;return t.active=i.active&&e.active,this},syncActive(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildActive,this),this},resetChildActiveState(t){return jn(t).active=t.active,this},setChildActive(t,e){return t.active=e,this.resetChildActiveState(t),this},setChildLocalActive(t,e){return void 0===e&&(e=!0),jn(t).active=e,this.updateChildActive(t),this},resetLocalActiveState(){var t=jn(this).parent;return t&&t.resetChildActiveState(this),this},getChildLocalActive:t=>jn(t).active},uo={updateChildScrollFactor(t){var e=jn(t),i=e.parent;return e.syncScrollFactor&&(t.scrollFactorX=i.scrollFactorX,t.scrollFactorY=i.scrollFactorY),this},syncScrollFactor(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildScrollFactor,this),this}},co={updateCameraFilter(t){var e=jn(t),i=e.parent;return e.syncCameraFilter&&(t.cameraFilter=i.cameraFilter),this},syncCameraFilter(){return this.syncChildrenEnable&&this.children.forEach(this.updateCameraFilter,this),this}},vo={updateChildMask(t){return null==this.mask||(this.mask.hasOwnProperty("geometryMask")?this.mask.geometryMask:this.mask.bitmapMask)!==t&&(t.mask=this.mask),this},syncMask(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildMask,this),this},setMask(t){return this.mask=t,this},clearMask(t){void 0===t&&(t=!1);var e=this;return this._mask=null,this.setChildMaskVisible(this),this.children.forEach((function(t){t.clearMask&&t.clearMask(!1),t.hasOwnProperty("isRexContainerLite")||e.setChildMaskVisible(t)})),t&&this.mask&&this.mask.destroy(),this}},po=function(t,e){if(t.length<=1)return t;var i;void 0===e&&(e=!1);for(var s=0,r=t.length;s=0;r--){var n=e[r];s!==n&&(n!==this&&s.displayList!==n.displayList||(s.displayList.moveBelow(n,s),s=n))}return this}},yo=function(t,e){if(!e(t)&&t.isRexContainerLite)for(var i=t.children,s=0,r=i.length;s0;){var s=i.shift();!e(s)&&s.isRexContainerLite&&i.push(...s.children)}};const bo=Phaser.Utils.Array;var To={getChildren(t){if(t)for(var e=0,i=this.children.length;e0;return hh.length=0,s},hh=[],ah=function(t,e,i){var s,r;for(var n in void 0===t?t=1:"string"==typeof t&&(t=lh[t]),void 0===e&&(e=this.tileXYZMap),void 0===i&&(i={}),e)s=e[n],(r=this.board.mirror(s,t)).z=s.z,i[n]=r;return i};const lh={x:1,y:2,"x&y":3};var uh=function(t){var e;for(var i in this.removeAllChess(),t)e=t[i],i=parseInt(i),this.addChess(i,e.x,e.y,e.z,!1);return this},ch=function(t,e,i){var s,r;for(var n in void 0===t&&(t=0),void 0===e&&(e=this.tileXYZMap),void 0===i&&(i={}),e)s=e[n],(r=this.board.rotate(s,t)).z=s.z,i[n]=r;return i},dh=function(t,e,i,s){var r,n;for(var o in void 0===i&&(i=this.tileXYZMap),void 0===s&&(s={}),i)r=i[o],(n=this.board.offset(r,t,e)).z=r.z,s[o]=n;return s};const vh=Phaser.GameObjects.Components.Origin.setOrigin;var ph={addChess:function(t,e,i,s){var r=this.grid;return r.saveOrigin(),r.setOriginPosition(this.x,this.y),this.board.addChess(t,e,i,s,!0),x(t)&&(t=this.board.uidToChess(t)),this.add(t),r.restoreOrigin(),$o.call(this),this},removeChess:function(t,e,i,s,r){return this.board.removeChess(t,e,i,s,r),$o.call(this),this},removeAllChess:function(t){return this.board.removeAllChess(t),$o.call(this),this},getAllChess:function(t){return this.board.getAllChess(t)},worldXYToChess:function(t,e,i){var s=this.grid;s.saveOrigin(),s.setOriginPosition(this.x,this.y);var r=this.board.worldXYToTileXY(t,e,!0),n=r.x,o=r.y;return s.restoreOrigin(),this.board.tileXYToChessArray(n,o,i)},pullOutFromMainBoard:function(){var t=this.mainBoard;if(null===t)return this;var e=this.tileXYZMap;for(var i in e)t.removeChess(parseInt(i));return this.setMainBoard(null),this},canPutOnMainBoard:function(t,e,i,s){if(!t)return!1;var r,n,o;for(var h in void 0===s&&(s=this.tileXYZMap),s){if(r=s[h],n=t.offset(r,e,i,!0),!t.contains(n.x,n.y))return!1;if(this.putTestCallback){Ko.x=n.x,Ko.y=n.y,Ko.z=r.z;var a=this.board.uidToChess(h);o=this.putTestCallbackScpe?this.putTestCallback.call(this.putTestCallbackScpe,Ko,t,a):this.putTestCallback(Ko,t,a)}else o=t.contains(n.x,n.y,r.z);if(o)return!1}return!0},putOnMainBoard:function(t,e,i,s){if(!t)return this;if(void 0===e){var r=t.worldXYToTileXY(this.x,this.y,!0);e=r.x,i=r.y}if(void 0===s&&(s=!0),this.pullOutFromMainBoard(),!this.canPutOnMainBoard(t,e,i))return this;this.setMainBoard(t,e,i);var n,o,h=this.tileXYZMap;for(var a in h)n=h[a],a=parseInt(a),o=t.offset(n,e,i,!0),t.addChess(a,o.x,o.y,n.z,!1);return s&&this.alignToMainBoard(t,e,i),this},putBack:function(){var t=this.lastMainBoardRef.mainBoard,e=this.lastMainBoardRef.tileX,i=this.lastMainBoardRef.tileY;return this.putOnMainBoard(t,e,i,!1),this},isOverlapping:function(t,e){if(!t)return!1;var i;for(var s in this.tileXYZMap)if(i=this.board.uidToChess(s),t.isOverlappingPoint(i.x,i.y,e))return!0;return!1},alignToMainBoard:function(t,e,i){if(!t)return this;if(void 0===e){var s=t.worldXYToTileXY(this.x,this.y,!0);e=s.x,i=s.y}return t.gridAlign(this,e,i),this},setInteractive:function(t){return void 0===t&&(t={}),t.hitArea=new rh(0,0,this.width,this.height),t.hitAreaCallback=Qo,nh.call(this,t),th.call(this),sh.call(this),this},setDraggable:function(t){return void 0===t&&(t=!0),this.setInteractive({draggable:!0}),this.input.draggable=t,this},dragEnd:function(){if(this.dragPointer)return this.scene.input.setDragState(this.dragPointer,5),this},isInTouching:function(t){return!!this.visible&&ss(this,t,oh)},setMainBoard:function(t,e,i){return this.mainBoardRef.set(t,e,i),t&&this.lastMainBoardRef.set(t,e,i),this},canMirror:function(t){if(null===this.mainBoard)return!0;var e=ah.call(this,t);return this.canPutOnMainBoard(this.mainBoard,tileX,tileY,e)},mirror:function(t){var e=null!=this.mainBoard;e&&this.pullOutFromMainBoard();var i=ah.call(this,t);if(e){var s=this.lastMainBoardRef.mainBoard,r=this.lastMainBoardRef.tileX,n=this.lastMainBoardRef.tileY;this.lastTransferResult=this.canPutOnMainBoard(s,r,n,i),this.lastTransferResult&&uh.call(this,i),this.putBack()}else this.lastTransferResult=!0,uh.call(this,i);return this},canRotate:function(t){if(null===this.mainBoard)return!0;var e=ch.call(this,t);return this.canPutOnMainBoard(this.mainBoard,tileX,tileY,e)},rotate:function(t){if(0===t)return this;var e=null!=this.mainBoard;e&&this.pullOutFromMainBoard();var i=ch.call(this,t);if(e){var s=this.lastMainBoardRef.mainBoard,r=this.lastMainBoardRef.tileX,n=this.lastMainBoardRef.tileY;this.lastTransferResult=this.canPutOnMainBoard(s,r,n,i),this.lastTransferResult&&uh.call(this,i),this.putBack()}else this.lastTransferResult=!0,uh.call(this,i);return this.lastTransferResult&&this.setFace(this.face+t),this},canRotateTo:function(t){return t-=this.face,this.canRotate(t)},rotateTo:function(t){return t-=this.face,this.rotate(t),this},getBounds:function(t){var e=this.grid;return e.saveOrigin(),e.setOriginPosition(this.x,this.y),t=this.board.getBoardBounds(t),e.restoreOrigin(),t},setOrigin:function(t,e){switch(t){case"center":t=.5,e=.5;break;case"top-left":case"left-top":t=0,e=0}void 0===t&&(t=.5),void 0===e&&(e=t),vh.call(this,t,e);var i=this.getBounds(!0),s=-Math.floor(it(i.left,i.right,t)),r=-Math.floor(it(i.top,i.bottom,e));if(0!==s||0!==r){var n=dh.call(this,s,r);uh.call(this,n);var o=this.board.tileXYToWorldXY(s,r),h=this.board.tileXYToWorldXY(0,0);this.setPosition(this.x+(h.x-o.x),this.y+(h.y-o.y))}return this}};class fh{constructor(t){this.miniBoard=t,this.set(null)}set(t,e,i){t||(t=null,e=null,i=null),this.mainBoard=t,this.tileX=e,this.tileY=i}}class gh extends Vo{constructor(t,e,i,s){super(t,e,i,0,0),this.type="rexMiniBoard";var r={isBoard:!1,grid:n(s,"grid",void 0),infinity:!0,wrap:!1};this.board=new Pi(t,r),this.mainBoardRef=new fh,this.lastMainBoardRef=new fh,this.resetFromJSON(s)}resetFromJSON(t){this.setFace(n(t,"face",0));var e=n(t,"draggable",void 0);return void 0!==e&&this.setDraggable(e),this.setPutTestCallback(n(t,"putTestCallback",void 0),n(t,"putTestCallbackScpe",void 0)),this.lastTransferResult=n(t,"lastTransferResult",void 0),this}destroy(t){this.scene&&(this.clear(!t),this.board.shutdown(t),this.board=void 0,this.setPutTestCallback(void 0,void 0),super.destroy(t))}setFace(t){return this.face=this.board.grid.directionNormalize(t),this}get mainBoard(){return this.mainBoardRef.mainBoard}get tileX(){return this.mainBoardRef.tileX}get tileY(){return this.mainBoardRef.tileY}get grid(){return this.board.grid}get tileXYZMap(){return this.board.boardData.UIDToXYZ}setPutTestCallback(t,e){return this.putTestCallback=t,this.putTestCallbackScpe=e,this}}Object.assign(gh.prototype,ph),t.register("miniBoard",(function(t,e,i){var s=new gh(this.scene,t,e,i);return this.scene.add.existing(s),s})),Hs(window,"RexPlugins.Board.MiniBoard",gh);var yh={hexagon:function(t,e,i){void 0===i&&(i=[]);for(var s,r,n=t.grid.mode,o=-e;o<=e;o++){s=Math.max(-e,-o-e),r=Math.min(e,-o+e);for(var h=s;h<=r;h++)i.push(ke(n,o,0,-o-h))}return i},triangle:function(t,e,i,s){void 0===s&&(s=[]);for(var r,n,o=t.grid.mode,h=0;h<=i;h++){1===e?(r=i-h,n=i):(r=0,n=i-h);for(var a=r;a<=n;a++)s.push(ke(o,h,0,-h-a))}return s},parallelogram:function(t,e,i,s,r){void 0===r&&(r=[]);var n=t.grid.mode;switch(e){case 1:for(var o=0;o<=i;o++)for(var h=0;h<=s;h++)r.push(ke(n,h,0,o));break;case 2:for(var a=0;a<=i;a++)for(o=0;o<=s;o++)r.push(ke(n,-a-o,0,o));break;default:for(h=0;h<=i;h++)for(a=0;a<=s;a++)r.push(ke(n,h,0,-h-a))}return r}};const mh=Phaser.Utils.String.Pad;var bh,Th=function(t,e,i){if(null==t)return t;switch(typeof t){case"string":default:return t;case"number":return`#${mh(Math.floor(t).toString(16),6,"0",1)}`;case"function":return t(e,i);case"object":return t.hasOwnProperty("r")?t.hasOwnProperty("a")?`rgba(${t.r},${t.g},${t.b},${t.a})`:`rgb(${t.r},${t.g},${t.b})`:t.hasOwnProperty("h")?t.hasOwnProperty("a")?`hsla(${t.h},${t.s},${t.l},${t.a})`:`hsl(${t.h},${t.s},${t.l})`:t}},xh=function(t,e){void 0===e&&(e={});for(var i=1/0,s=1/0,r=-1/0,n=-1/0,o=0,h=t.length;oe?t-i:t},Yh=function(t,e,i){if(void 0===i&&(i=e),0===e&&0===i)return t;for(var s=0,r=t.length;s