38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { decodeBlp2, encodePng } from "./blp.mjs";
|
|
import { stitchMap } from "./wow-map-image.mjs";
|
|
|
|
test("map tiles are row-major and cropped to the original client's 1002x668 area", () => {
|
|
const tiles = Array.from({ length: 12 }, (_, i) => ({ width: 256, height: 256, pixels: Buffer.alloc(256 * 256 * 4, i) }));
|
|
const image = stitchMap(tiles);
|
|
assert.deepEqual([image.width, image.height], [1002, 668]);
|
|
const pixel = (x, y) => image.pixels[(y * image.width + x) * 4];
|
|
assert.equal(pixel(0, 0), 0);
|
|
assert.equal(pixel(256, 0), 1);
|
|
assert.equal(pixel(1001, 0), 3);
|
|
assert.equal(pixel(0, 256), 4);
|
|
assert.equal(pixel(0, 667), 8);
|
|
assert.equal(pixel(1001, 667), 11);
|
|
const png = encodePng(image);
|
|
assert.equal(png.toString("ascii", 1, 4), "PNG");
|
|
assert.equal(png.readUInt32BE(16), 1002);
|
|
assert.equal(png.readUInt32BE(20), 668);
|
|
});
|
|
|
|
test("partial or unexpected-size tile sets cannot become a misleading map", () => {
|
|
assert.throws(() => stitchMap([]), /twelve/);
|
|
assert.throws(() => stitchMap(Array.from({ length: 12 }, () => ({ width: 128, height: 256 }))), /dimensions/);
|
|
});
|
|
|
|
test("BLP2 DXT1 map tiles decode RGB565 color correctly", () => {
|
|
const b = Buffer.alloc(156);
|
|
b.write("BLP2"); b.writeUInt32LE(1, 4); b[8] = 2;
|
|
b.writeUInt32LE(4, 12); b.writeUInt32LE(4, 16);
|
|
b.writeUInt32LE(148, 20); b.writeUInt32LE(8, 84);
|
|
b.writeUInt16LE(0xf800, 148);
|
|
const decoded = decodeBlp2(b, "red fixture");
|
|
assert.deepEqual([...decoded.pixels.subarray(0, 4)], [255, 0, 0, 255]);
|
|
assert.equal(decoded.pixels.length, 64);
|
|
});
|