UNPKG

gridboard

Version:

A Grid-Based Games Framework For TypeScript/JavaScript

2 lines (1 loc) 2.32 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).gridboard={})}(this,function(t){"use strict";var n=(e.prototype.getGridByRelativeCoordinate=function(t,e,i){var r,o;"number"!=typeof e&&(i=e,t=(r=t)[0],e=r[1]),"number"!=typeof t&&(t=(r=t)[0],e=r[1]),i&&("object"==typeof i?(t=(o=i.convertRelativeCoordinate(t,e))[0],e=o[1]):(t=(o=i(t,e))[0],e=o[1],i=void 0));t=this.x+t,e=this.y+e;return this.board.getGridByAbsoluteCoordinate(t,e,i)},e);function e(t,e,i){this.i=e*i.width+t,this.x=t,this.y=e,this.board=i}n.prototype.getGridTo=n.prototype.getGridByRelativeCoordinate;var i=(r.prototype.getGridByAbsoluteCoordinate=function(t,e,i){var r,o;if("number"!=typeof e&&(i=e,t=(r=t)[0],e=r[1]),"number"!=typeof t&&(t=(o=t)[0],e=o[1]),i&&(e="object"==typeof i?(t=(o=i.convertAbsoluteCoordinate(t,e))[0],o[1]):(t=(i=i(t,e))[0],i[1])),t<0||t>=this.width||e<0||e>=this.height)return null;t=e*this.width+t;return this.grids[t]},r);function r(t,e){this.grids=[],this.width=t,this.height=e;for(var i=0;i<t;i++)for(var r=0;r<e;r++){var o=new n(i,r,this);this.grids[o.i]=o}}i.prototype.getGridAt=i.prototype.getGridByAbsoluteCoordinate;var s=function(t){if("string"!=typeof t)return s(t[0]);if(t in s)return s[t];for(var e=0,i=0,r=0,o=t.split("");r<o.length;r++)switch(o[r]){case"F":i--;break;case"B":i++;break;case"L":e--;break;case"R":e++}return s[t]=[e,i]};(o=d=d||{})[o.FBLR=0]="FBLR",o[o.BFLR=1]="BFLR",o[o.FBRL=2]="FBRL",o[o.BFRL=3]="BFRL",o[o.LRFB=4]="LRFB",o[o.LRBF=5]="LRBF",o[o.RLFB=6]="RLFB",o[o.RLBF=7]="RLBF";var o=d,d=(a.prototype.convertAbsoluteCoordinate=function(t,e){var i;return this.isAxisNeedSwap&&(e=(i=[t,e])[0],t=i[1]),this.isXAxisOrderByDescending&&(t=this.board.width-1-t),this.isYAxisOrderByDescending&&(e=this.board.height-1-e),[t,e]},a.prototype.convertRelativeCoordinate=function(t,e){var i;return this.isAxisNeedSwap&&(e=(i=[t,e])[0],t=i[1]),this.isXAxisOrderByDescending&&(t=-t),this.isYAxisOrderByDescending&&(e=-e),[t,e]},a);function a(t,e){this.board=t,this.isAxisNeedSwap=0<(4&e),this.isXAxisOrderByDescending=0<(2&e),this.isYAxisOrderByDescending=0<(1&e)}t.Direction=s,t.Grid=n,t.GridBoard=i,t.Orientation=o,t.OrientationCoordinateConverter=d,Object.defineProperty(t,"__esModule",{value:!0})});