import { readdirSync, readFileSync } from "node:fs"; import { extname, join } from "node:path"; import { fileURLToPath } from "node:url"; import test from "node:test"; import assert from "node:assert/strict"; const ASSET_ROOT = join(fileURLToPath(new URL("..", import.meta.url)), "assets"); const SPRITE_FOLDERS = ["grounds", "blocks", "characters", "items", "equipment", "mobs"]; function pngSize (buffer) { if (buffer.length < 24 || buffer.toString("ascii", 1, 4) !== "PNG") { throw new Error("Not a PNG"); } return { width: buffer.readUInt32BE(16), height: buffer.readUInt32BE(20) }; } function listPngs (dir) { const files = []; for (const entry of readdirSync(dir, { withFileTypes: true })) { const path = join(dir, entry.name); if (entry.isDirectory()) { files.push(...listPngs(path)); } else if (extname(entry.name).toLowerCase() === ".png") { files.push(path); } } return files; } test("world sprite PNGs load with a positive size", () => { const offenders = []; for (const folder of SPRITE_FOLDERS) { const dir = join(ASSET_ROOT, folder); let files = []; try { files = listPngs(dir); } catch (error) { if (error.code === "ENOENT") { continue; } throw error; } for (const file of files) { const { width, height } = pngSize(readFileSync(file)); if (width < 1 || height < 1) { offenders.push(`${file} is ${width}×${height}`); } } } assert.equal(offenders.length, 0, offenders.join("\n")); });