export default class Tile { constructor(x, y, name) { this.x = x; this.y = y; this.name = name; } } function realNames(base, override = {}) { return { topLeft: override.topLeft || base+"-top-l", top: override.top || base+"-top", topRight: override.topRight || base+"-top-r", topBoth: override.topBoth || base+"-top-lr", left: override.left || base+"-l", mid: override.mid || base, right: override.right || base+"-r", both: override.both || base+"-lr", bottomLeft: override.bottomLeft || base+"-bottom-l", bottom: override.bottom || base+"-bottom", bottomRight: override.bottomRight || base+"-bottom-r", bottomBoth: override.bottomBoth || base+"-bottom-lr", }; } function getName(x, y, size, names) { let name = null; if (size.x <= 1) { if (y === 0) name = names.topBoth; else if (y === size.y - 1) name = names.bottomBoth; else name = names.both; } else { if (y === 0) { if (x === 0) name = names.topLeft; else if (x === size.x - 1) name = names.topRight; else name = names.top; } else if (y === size.y - 1) { if (x === 0) name = names.bottomLeft; else if (x === size.x - 1) name = names.bottomRight; else name = names.bottom; } else { if (x === 0) name = names.left; else if (x === size.x - 1) name = names.right; else name = names.mid; } } if (!name) name = "--invalid-"+x+"-"+y+"--"; return name; } Tile.createBox = function(pos, size, base, names) { names = realNames(base, names); let arr = []; for (let x = 0; x < size.x; ++x) { for (let y = 0; y < size.y; ++y) { arr.push(new Tile( pos.x + x, pos.y + y, getName(x, y, size, names))); } } return arr; } function getNameLine(x, width, names) { if (width === 1) return names.both; else if (x === 0) return names.left; else if (x === width - 1) return names.right; else return names.mid; } Tile.createLine = function(pos, width, base, names) { names = realNames(base, names); let arr = []; for (let x = 0; x < width; ++x) { arr.push(new Tile( pos.x + x, pos.y, getNameLine(x, width, names))); } return arr; }