13 lines
771 B
JavaScript
13 lines
771 B
JavaScript
/** WoW's twelve row-major 256px tiles are cropped to the client map's 1002x668 rectangle. */
|
|
export function stitchMap(tiles) {
|
|
if (tiles.length !== 12) throw new Error("A map requires all twelve tiles");
|
|
const width = 1002, height = 668, pixels = Buffer.alloc(width * height * 4);
|
|
tiles.forEach((tile, index) => {
|
|
if (tile.width !== 256 || tile.height !== 256) throw new Error("Unexpected map tile dimensions");
|
|
const x = (index % 4) * 256, y = Math.floor(index / 4) * 256;
|
|
const copyWidth = Math.min(256, width - x), copyHeight = Math.min(256, height - y);
|
|
for (let row = 0; row < copyHeight; row += 1) tile.pixels.copy(pixels, ((y + row) * width + x) * 4, row * 256 * 4, (row * 256 + copyWidth) * 4);
|
|
});
|
|
return { width, height, pixels };
|
|
}
|