/** * Temporary 16×16 status-effect icons (replace with final art later). */ import { mkdirSync, writeFileSync } from "node:fs"; import { deflateSync } from "node:zlib"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; import { STATUS_EFFECT_DISPLAY } from "../../shared/statusEffects/display.js"; const SIZE = 16; const OUT = join(dirname(fileURLToPath(import.meta.url)), "../assets/status-effects"); const PALETTE = { "health-regen": [80, 200, 100], "stamina-regen": [90, 200, 170], "strength-bonus": [220, 100, 60], "mind-bonus": [140, 120, 230], "stamina-drain": [180, 60, 90], glow: [240, 220, 90], shrink: [180, 140, 210], blind: [40, 40, 50] }; function crcTable () { const table = new Uint32Array(256); for (let n = 0; n < 256; n++) { let c = n; for (let k = 0; k < 8; k++) { c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); } table[n] = c >>> 0; } return table; } const CRC_TABLE = crcTable(); function crc32 (buf) { let c = 0xffffffff; for (let i = 0; i < buf.length; i++) { c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); } return (c ^ 0xffffffff) >>> 0; } function chunk (type, data) { const len = Buffer.alloc(4); len.writeUInt32BE(data.length); const typeBuf = Buffer.from(type, "ascii"); const crcBuf = Buffer.alloc(4); crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data]))); return Buffer.concat([len, typeBuf, data, crcBuf]); } function encodePng (rgba) { const raw = Buffer.alloc((SIZE * 4 + 1) * SIZE); for (let y = 0; y < SIZE; y++) { const row = y * (SIZE * 4 + 1); raw[row] = 0; for (let x = 0; x < SIZE; x++) { const i = (y * SIZE + x) * 4; const o = row + 1 + x * 4; raw[o] = rgba[i]; raw[o + 1] = rgba[i + 1]; raw[o + 2] = rgba[i + 2]; raw[o + 3] = rgba[i + 3]; } } const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(SIZE, 0); ihdr.writeUInt32BE(SIZE, 4); ihdr[8] = 8; ihdr[9] = 6; return Buffer.concat([ Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", ihdr), chunk("IDAT", deflateSync(raw, { level: 9 })), chunk("IEND", Buffer.alloc(0)) ]); } function setPx (rgba, x, y, rgb) { if (x < 0 || y < 0 || x >= SIZE || y >= SIZE) { return; } const i = (y * SIZE + x) * 4; rgba[i] = rgb[0]; rgba[i + 1] = rgb[1]; rgba[i + 2] = rgb[2]; rgba[i + 3] = 255; } function drawIcon (rgb) { const rgba = new Uint8Array(SIZE * SIZE * 4); const rim = [Math.max(0, rgb[0] - 50), Math.max(0, rgb[1] - 50), Math.max(0, rgb[2] - 50)]; for (let y = 2; y < 14; y++) { for (let x = 2; x < 14; x++) { const edge = x === 2 || x === 13 || y === 2 || y === 13; setPx(rgba, x, y, edge ? rim : rgb); } } // Simple glyph: plus / diamond / bar for (let i = 5; i < 11; i++) { setPx(rgba, i, 7, [255, 255, 255]); setPx(rgba, 7, i, [255, 255, 255]); } return rgba; } mkdirSync(OUT, { recursive: true }); for (const display of Object.values(STATUS_EFFECT_DISPLAY)) { const rgb = PALETTE[display.iconKey] ?? [160, 160, 160]; writeFileSync(join(OUT, `${display.iconKey}.png`), encodePng(drawIcon(rgb))); console.log(`wrote ${display.iconKey}.png`); }