Files
2026-11-09 22:37:44 +05:00

319 lines
19 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Набор иконок HUD в стиле игры: плоские фигуры с объёмом (светлый верх, тёмный низ), тёмная обводка
// и золотой блик. Рисуется без внешних библиотек: свой растеризатор с 4× сглаживанием и PNG-кодировщик.
// node tools/icons/make-icons.js → assets/icons/<имя>.png (128×128) и assets/reference/icons_sheet.png
const fs = require('fs'), path = require('path'), zlib = require('zlib');
const ROOT = path.join(__dirname, '..', '..');
const OUT = path.join(ROOT, 'assets', 'icons');
fs.mkdirSync(OUT, { recursive: true });
const S = 128, SS = 4, N = S * SS; // итоговый размер, сглаживание
const OUTLINE = [40, 26, 18]; // тёмная обводка (тёмное дерево)
// ---------- PNG
function crc32(buf) {
let c, crc = 0xffffffff;
for (let n = 0; n < buf.length; n++) {
c = (crc ^ buf[n]) & 0xff;
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
crc = (crc >>> 8) ^ c;
}
return (crc ^ 0xffffffff) >>> 0;
}
function chunk(type, data) {
const len = Buffer.alloc(4); len.writeUInt32BE(data.length);
const td = Buffer.concat([Buffer.from(type, 'ascii'), data]);
const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(td));
return Buffer.concat([len, td, crc]);
}
function png(w, h, rgba) {
const raw = Buffer.alloc((w * 4 + 1) * h);
for (let y = 0; y < h; y++) { raw[y * (w * 4 + 1)] = 0; rgba.copy(raw, y * (w * 4 + 1) + 1, y * w * 4, (y + 1) * w * 4); }
const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 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', zlib.deflateSync(raw, { level: 9 })), chunk('IEND', Buffer.alloc(0))]);
}
// ---------- холст: фигуры в координатах 0..128 (как итоговая иконка), рисуются в 512×512
class Canvas {
constructor() { this.c = new Float32Array(N * N * 4); }
// заливка по функции inside(x, y) в координатах 0..128; color — [r,g,b]; shade — объём сверху вниз
fill(inside, color, opt = {}) {
const [x0, y0, x1, y1] = (opt.box || [0, 0, S, S]).map(v => Math.max(0, Math.min(N, Math.round(v * SS))));
const top = opt.top ?? 0, bot = opt.bot ?? 128, shade = opt.shade ?? 0.28, a = opt.alpha ?? 1;
for (let py = y0; py < y1; py++) for (let px = x0; px < x1; px++) {
const x = (px + 0.5) / SS, y = (py + 0.5) / SS;
if (!inside(x, y)) continue;
const t = Math.max(0, Math.min(1, (y - top) / Math.max(1, bot - top)));
const k = 1 + shade * (0.5 - t) * 2; // светлее сверху, темнее снизу
const i = (py * N + px) * 4;
for (let j = 0; j < 3; j++) this.c[i + j] = this.c[i + j] * (1 - a) + Math.min(255, color[j] * k) * a;
this.c[i + 3] = Math.max(this.c[i + 3], a);
}
}
// результат 128×128 с обводкой: под фигурами — тёмный силуэт, расширенный на w пикселей
render(w = 5) {
const R = w * SS, alpha = new Uint8Array(N * N);
for (let i = 0; i < N * N; i++) alpha[i] = this.c[i * 4 + 3] > 0.5 ? 1 : 0;
// расширение силуэта: сначала по X, потом по Y (квадратное, со скруглёнными углами через расстояние)
const dil = new Uint8Array(N * N);
const offs = [];
for (let dy = -R; dy <= R; dy++) for (let dx = -R; dx <= R; dx++) if (dx * dx + dy * dy <= R * R) offs.push([dx, dy]);
// быстрая версия: для каждой закрашенной точки края ставим диск (только по контуру)
for (let y = 0; y < N; y++) for (let x = 0; x < N; x++) {
if (!alpha[y * N + x]) continue;
const edge = x === 0 || y === 0 || x === N - 1 || y === N - 1 || !alpha[y * N + x - 1] || !alpha[y * N + x + 1] || !alpha[(y - 1) * N + x] || !alpha[(y + 1) * N + x];
dil[y * N + x] = 1;
if (!edge) continue;
for (const [dx, dy] of offs) { const X = x + dx, Y = y + dy; if (X >= 0 && Y >= 0 && X < N && Y < N) dil[Y * N + X] = 1; }
}
const out = Buffer.alloc(S * S * 4);
for (let y = 0; y < S; y++) for (let x = 0; x < S; x++) {
let r = 0, g = 0, b = 0, a = 0;
for (let sy = 0; sy < SS; sy++) for (let sx = 0; sx < SS; sx++) {
const i = (y * SS + sy) * N + (x * SS + sx);
if (this.c[i * 4 + 3] > 0) { const aa = this.c[i * 4 + 3]; r += this.c[i * 4] * aa + OUTLINE[0] * (1 - aa); g += this.c[i * 4 + 1] * aa + OUTLINE[1] * (1 - aa); b += this.c[i * 4 + 2] * aa + OUTLINE[2] * (1 - aa); a += 1; }
else if (dil[i]) { r += OUTLINE[0]; g += OUTLINE[1]; b += OUTLINE[2]; a += 1; }
}
const n = SS * SS, o = (y * S + x) * 4;
if (a) { out[o] = r / a; out[o + 1] = g / a; out[o + 2] = b / a; out[o + 3] = Math.round(255 * a / n); }
}
return out;
}
}
// ---------- примитивы (возвращают inside-функции)
const circle = (cx, cy, r) => (x, y) => (x - cx) ** 2 + (y - cy) ** 2 <= r * r;
const ellipse = (cx, cy, rx, ry, rot = 0) => (x, y) => {
const c = Math.cos(rot), s = Math.sin(rot), dx = x - cx, dy = y - cy;
const u = dx * c + dy * s, v = -dx * s + dy * c;
return (u / rx) ** 2 + (v / ry) ** 2 <= 1;
};
const rect = (x0, y0, x1, y1, r = 0) => (x, y) => {
if (x < x0 || x > x1 || y < y0 || y > y1) return false;
if (!r) return true;
const cx = Math.max(x0 + r, Math.min(x1 - r, x)), cy = Math.max(y0 + r, Math.min(y1 - r, y));
return (x - cx) ** 2 + (y - cy) ** 2 <= r * r;
};
const poly = pts => (x, y) => {
let inside = false;
for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {
const [xi, yi] = pts[i], [xj, yj] = pts[j];
if ((yi > y) !== (yj > y) && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;
}
return inside;
};
const line = (x0, y0, x1, y1, w) => (x, y) => {
const dx = x1 - x0, dy = y1 - y0, l2 = dx * dx + dy * dy;
const t = Math.max(0, Math.min(1, ((x - x0) * dx + (y - y0) * dy) / l2));
return (x - x0 - t * dx) ** 2 + (y - y0 - t * dy) ** 2 <= (w / 2) ** 2;
};
const ring = (cx, cy, r0, r1) => (x, y) => { const d = (x - cx) ** 2 + (y - cy) ** 2; return d <= r1 * r1 && d >= r0 * r0; };
const and = (a, b) => (x, y) => a(x, y) && b(x, y);
const not = a => (x, y) => !a(x, y);
const star = (cx, cy, r0, r1, n = 5, rot = -Math.PI / 2) => {
const pts = [];
for (let i = 0; i < n * 2; i++) { const r = i % 2 ? r0 : r1, a = rot + i * Math.PI / n; pts.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r]); }
return poly(pts);
};
// ---------- палитра игры
const C = {
wood: [122, 82, 50], woodD: [80, 52, 32], leather: [150, 92, 52], gold: [222, 172, 82], goldL: [255, 218, 120],
crimson: [170, 46, 40], forest: [70, 126, 66], leaf: [96, 170, 80], parch: [236, 220, 180], silver: [210, 216, 224],
steel: [150, 160, 172], pearl: [240, 232, 244], blue: [76, 146, 210], sky: [130, 196, 240], fish: [236, 152, 64],
fishB: [255, 196, 96], purple: [150, 96, 210], pink: [232, 120, 150], white: [250, 248, 240], grey: [150, 150, 158],
dark: [60, 56, 64], cloud: [226, 232, 240], yellow: [255, 206, 70], red: [214, 66, 56], teal: [70, 180, 170],
};
const shine = (cv, inside) => cv.fill(inside, [255, 255, 255], { alpha: 0.35, shade: 0 }); // белый блик
const ICONS = {
bag(cv) { // кожаная сумка с клапаном и пряжкой
cv.fill(rect(26, 46, 102, 112, 14), C.leather, { top: 46, bot: 112 });
cv.fill(ring(64, 46, 18, 26), C.woodD);
cv.fill(and(rect(24, 40, 104, 74, 12), (x, y) => y < 74), C.woodD, { top: 40, bot: 74 });
cv.fill(rect(55, 62, 73, 82, 4), C.gold, { top: 62, bot: 82 });
cv.fill(rect(60, 67, 68, 77, 2), C.woodD, { shade: 0 });
shine(cv, rect(32, 80, 40, 104, 4));
},
fish(cv) { // рыба с хвостом
cv.fill(poly([[86, 64], [116, 40], [110, 64], [116, 88]]), C.fish, { top: 40, bot: 88 });
cv.fill(ellipse(58, 64, 40, 24), C.fish, { top: 40, bot: 88 });
cv.fill(poly([[46, 42], [70, 30], [74, 46]]), C.fishB);
cv.fill(circle(34, 58, 6), C.white, { shade: 0 }); cv.fill(circle(35, 59, 3.2), C.dark, { shade: 0 });
cv.fill(line(54, 48, 54, 80, 3), C.woodD, { shade: 0 });
shine(cv, ellipse(50, 50, 18, 5, -0.15));
},
book(cv) { // коллекция: книга с закладкой
cv.fill(rect(22, 22, 106, 106, 8), C.crimson, { top: 22, bot: 106 });
cv.fill(rect(32, 22, 106, 98, 6), C.parch, { top: 22, bot: 98, shade: 0.12 });
cv.fill(rect(22, 22, 36, 106, 6), [130, 34, 30]);
cv.fill(poly([[84, 22], [96, 22], [96, 56], [90, 50], [84, 56]]), C.gold);
for (const y of [44, 58, 72]) cv.fill(rect(46, y, 78, y + 4, 2), [170, 150, 116], { shade: 0 });
},
map(cv) { // свёрнутая карта мира
cv.fill(poly([[18, 30], [48, 22], [80, 32], [110, 24], [110, 98], [80, 106], [48, 96], [18, 104]]), C.parch, { top: 22, bot: 106, shade: 0.15 });
cv.fill(poly([[48, 22], [80, 32], [80, 106], [48, 96]]), [214, 196, 152], { top: 22, bot: 106 });
cv.fill(ellipse(40, 62, 14, 18), C.leaf); cv.fill(ellipse(88, 56, 12, 10), C.leaf);
cv.fill(line(52, 84, 76, 70, 4), C.crimson, { shade: 0 });
cv.fill(line(84, 74, 96, 86, 5), C.crimson, { shade: 0 }); cv.fill(line(96, 74, 84, 86, 5), C.crimson, { shade: 0 });
},
scroll(cv) { // задания: свиток
cv.fill(rect(28, 26, 100, 102, 4), C.parch, { top: 26, bot: 102, shade: 0.15 });
cv.fill(rect(20, 18, 108, 34, 8), C.wood, { top: 18, bot: 34 });
cv.fill(rect(20, 94, 108, 110, 8), C.wood, { top: 94, bot: 110 });
for (const y of [46, 60, 74]) cv.fill(rect(40, y, 88, y + 5, 2), [150, 120, 84], { shade: 0 });
cv.fill(circle(84, 82, 10), C.crimson);
},
crystal(cv) { // донат: кристалл
cv.fill(poly([[64, 12], [104, 46], [64, 118], [24, 46]]), C.purple, { top: 12, bot: 118 });
cv.fill(poly([[64, 12], [104, 46], [64, 46]]), [196, 150, 250]);
cv.fill(poly([[64, 46], [104, 46], [64, 118]]), [116, 70, 176]);
cv.fill(poly([[44, 46], [64, 46], [64, 118]]), [176, 126, 236]);
shine(cv, poly([[44, 30], [56, 22], [50, 42]]));
},
horn(cv) { // звук: рог
cv.fill(poly([[24, 76], [96, 30], [108, 40], [112, 70], [104, 96], [40, 92]]), C.parch, { top: 30, bot: 96, shade: 0.2 });
cv.fill(ellipse(104, 64, 10, 34), C.gold, { top: 30, bot: 98 });
cv.fill(ellipse(104, 64, 5, 26), C.woodD, { shade: 0 });
cv.fill(rect(16, 70, 34, 96, 6), C.gold);
for (const x of [52, 74]) cv.fill(line(x, 50 + (74 - x) * 0.25, x + 4, 92, 6), C.woodD, { shade: 0 });
},
guild(cv) { // гильдия: щит и скрещённые мечи
cv.fill(line(24, 24, 104, 104, 9), C.silver); cv.fill(line(104, 24, 24, 104, 9), C.silver);
for (const [a, b] of [[[30, 98], [18, 110]], [[98, 98], [110, 110]]]) cv.fill(line(a[0], a[1], b[0], b[1], 10), C.woodD);
cv.fill(line(22, 92, 36, 106, 6), C.gold); cv.fill(line(106, 92, 92, 106, 6), C.gold);
cv.fill(poly([[64, 30], [96, 40], [92, 80], [64, 104], [36, 80], [32, 40]]), C.crimson, { top: 30, bot: 104 });
cv.fill(poly([[64, 40], [86, 47], [83, 76], [64, 93], [45, 76], [42, 47]]), C.gold, { top: 40, bot: 93 });
cv.fill(poly([[64, 48], [76, 60], [64, 84], [52, 60]]), C.crimson);
},
coin(cv) { // серебро
cv.fill(circle(64, 66, 46), [160, 168, 180]);
cv.fill(circle(64, 62, 46), C.silver, { top: 16, bot: 108 });
cv.fill(ring(64, 62, 30, 35), [176, 184, 196], { shade: 0 });
cv.fill(star(64, 62, 10, 22, 5), [176, 184, 196], { shade: 0 });
shine(cv, ellipse(46, 40, 14, 6, -0.6));
},
pearl(cv) { // жемчуг в раковине
cv.fill(poly([[16, 76], [64, 112], [112, 76], [100, 100], [28, 100]]), C.pink, { top: 76, bot: 112 });
cv.fill(ellipse(64, 84, 48, 22), [240, 170, 186], { top: 62, bot: 106 });
for (const x of [40, 64, 88]) cv.fill(line(64, 104, x, 66, 3), [210, 130, 150], { shade: 0 });
cv.fill(circle(64, 56, 26), C.pearl, { top: 30, bot: 82 });
shine(cv, circle(54, 46, 8));
},
seal(cv) { // печать гильдии: сургуч с лентами
cv.fill(poly([[48, 80], [36, 120], [52, 110], [60, 120], [64, 84]]), C.crimson);
cv.fill(poly([[80, 80], [92, 120], [76, 110], [68, 120], [64, 84]]), [140, 36, 32]);
const blob = [];
for (let i = 0; i < 24; i++) { const a = i / 24 * Math.PI * 2, r = 40 + (i % 2 ? 4 : 0); blob.push([64 + Math.cos(a) * r, 56 + Math.sin(a) * r]); }
cv.fill(poly(blob), C.crimson, { top: 14, bot: 98 });
cv.fill(ring(64, 56, 24, 28), [130, 30, 28], { shade: 0 });
cv.fill(poly([[64, 40], [74, 52], [70, 70], [58, 70], [54, 52]]), C.gold); // якорь-стрелка
},
clover(cv) { // удача
for (const [x, y] of [[44, 44], [84, 44], [44, 82], [84, 82]]) cv.fill(circle(x, y, 22), C.leaf, { top: y - 22, bot: y + 22 });
cv.fill(line(66, 66, 92, 116, 9), C.forest);
for (const [x, y] of [[40, 40], [80, 40], [40, 78], [80, 78]]) shine(cv, circle(x, y, 6));
},
xp(cv) { // опыт: звезда
cv.fill(star(64, 66, 22, 54), C.yellow, { top: 12, bot: 118 });
cv.fill(star(64, 66, 12, 30), C.goldL, { shade: 0 });
shine(cv, ellipse(48, 46, 8, 4, -0.5));
},
level(cv) { // уровень: ромб-значок
cv.fill(poly([[64, 10], [118, 64], [64, 118], [10, 64]]), C.gold, { top: 10, bot: 118 });
cv.fill(poly([[64, 26], [102, 64], [64, 102], [26, 64]]), [196, 140, 60], { top: 26, bot: 102 });
cv.fill(poly([[64, 40], [76, 64], [64, 88], [52, 64]]), C.goldL);
},
rod(cv) { // удочка с катушкой и поплавком
cv.fill(line(24, 112, 106, 18, 7), C.wood);
cv.fill(line(24, 112, 44, 88, 10), C.woodD);
cv.fill(circle(44, 92, 11), C.steel); cv.fill(circle(44, 92, 4), C.dark, { shade: 0 });
cv.fill(line(106, 18, 106, 84, 2), C.white, { shade: 0 });
cv.fill(circle(106, 92, 9), C.red); cv.fill(and(circle(106, 92, 9), (x, y) => y > 92), C.white);
},
worm(cv) { // наживка: червь
const pts = [[22, 92], [42, 70], [64, 84], [86, 64], [104, 46]];
for (let i = 0; i < pts.length - 1; i++) cv.fill(line(pts[i][0], pts[i][1], pts[i + 1][0], pts[i + 1][1], 20), [214, 120, 140], { top: 30, bot: 110 });
for (const [x, y] of [[36, 78], [54, 76], [74, 74], [92, 58]]) cv.fill(line(x - 5, y - 6, x + 5, y + 6, 3), [176, 86, 106], { shade: 0 });
cv.fill(circle(106, 42, 3), C.dark, { shade: 0 });
},
sun(cv) {
for (let i = 0; i < 8; i++) { const a = i * Math.PI / 4; cv.fill(line(64 + Math.cos(a) * 36, 64 + Math.sin(a) * 36, 64 + Math.cos(a) * 54, 64 + Math.sin(a) * 54, 9), C.yellow); }
cv.fill(circle(64, 64, 28), C.yellow, { top: 36, bot: 92 }); shine(cv, circle(54, 54, 8));
},
cloud(cv) {
for (const [x, y, r] of [[44, 74, 22], [70, 62, 28], [94, 76, 20]]) cv.fill(circle(x, y, r), C.cloud, { top: 34, bot: 98 });
cv.fill(rect(26, 74, 112, 96, 10), C.cloud, { top: 34, bot: 98 });
},
rain(cv) {
for (const [x, y] of [[44, 98], [66, 106], [88, 98]]) cv.fill(poly([[x, y - 12], [x + 6, y + 2], [x - 6, y + 2]]), C.blue), cv.fill(circle(x, y + 2, 6), C.blue);
for (const [x, y, r] of [[44, 56, 20], [68, 46, 26], [92, 58, 18]]) cv.fill(circle(x, y, r), [196, 206, 220], { top: 20, bot: 80 });
cv.fill(rect(26, 56, 108, 78, 10), [196, 206, 220], { top: 20, bot: 80 });
},
storm(cv) {
for (const [x, y, r] of [[44, 50, 20], [68, 40, 26], [92, 52, 18]]) cv.fill(circle(x, y, r), [130, 136, 156], { top: 14, bot: 74 });
cv.fill(rect(26, 50, 108, 72, 10), [130, 136, 156], { top: 14, bot: 74 });
cv.fill(poly([[70, 70], [52, 98], [64, 98], [54, 122], [82, 88], [68, 88], [80, 70]]), C.yellow);
},
fog(cv) {
for (const [y, x0, x1] of [[40, 26, 96], [62, 18, 110], [84, 32, 104], [104, 22, 90]]) cv.fill(rect(x0, y - 7, x1, y + 7, 7), C.cloud, { shade: 0.15 });
},
moon(cv) {
cv.fill(and(circle(62, 64, 44), not(circle(84, 52, 38))), [240, 226, 160], { top: 20, bot: 108 });
for (const [x, y] of [[96, 30], [104, 70], [86, 100]]) cv.fill(star(x, y, 3, 8, 4, 0), C.white, { shade: 0 });
},
lock(cv) {
cv.fill(ring(64, 54, 18, 28), C.steel, { top: 26, bot: 82 });
cv.fill(rect(30, 54, 98, 112, 10), C.gold, { top: 54, bot: 112 });
cv.fill(circle(64, 78, 9), C.woodD, { shade: 0 }); cv.fill(rect(60, 80, 68, 98, 2), C.woodD, { shade: 0 });
},
gift(cv) {
cv.fill(rect(22, 54, 106, 112, 6), C.crimson, { top: 54, bot: 112 });
cv.fill(rect(16, 40, 112, 60, 6), [196, 60, 52], { top: 40, bot: 60 });
cv.fill(rect(56, 40, 72, 112, 2), C.gold);
cv.fill(ellipse(48, 32, 16, 10, 0.4), C.gold); cv.fill(ellipse(80, 32, 16, 10, -0.4), C.gold);
},
chest(cv) { // сундук (ежедневная награда, донат-наборы)
cv.fill(rect(18, 56, 110, 110, 6), C.wood, { top: 56, bot: 110 });
cv.fill(rect(18, 30, 110, 62, 16), C.woodD, { top: 30, bot: 62 });
for (const x of [30, 92]) cv.fill(rect(x, 30, x + 8, 110, 2), C.gold);
cv.fill(rect(54, 54, 74, 76, 4), C.gold); cv.fill(circle(64, 64, 3.5), C.woodD, { shade: 0 });
},
trap(cv) { // ловушка-вентерь (плетёная корзина)
cv.fill(poly([[24, 40], [104, 40], [92, 110], [36, 110]]), [196, 150, 84], { top: 40, bot: 110 });
for (const y of [56, 74, 92]) cv.fill(rect(26, y, 102, y + 5, 2), [150, 108, 56], { shade: 0 });
for (const x of [46, 64, 82]) cv.fill(line(x, 40, x - (x - 64) * 0.2, 110, 4), [150, 108, 56], { shade: 0 });
cv.fill(ellipse(64, 40, 42, 10), [150, 108, 56]); cv.fill(ellipse(64, 40, 32, 6), C.woodD, { shade: 0 });
},
target(cv) { // цели
cv.fill(circle(64, 64, 48), C.parch, { top: 16, bot: 112 });
cv.fill(ring(64, 64, 28, 38), C.crimson, { shade: 0 }); cv.fill(circle(64, 64, 14), C.crimson);
cv.fill(line(64, 64, 110, 18, 6), C.wood); cv.fill(poly([[100, 14], [116, 12], [114, 28]]), C.gold);
},
gear(cv) { // настройки
const teeth = [];
for (let i = 0; i < 16; i++) { const a = i / 16 * Math.PI * 2, r = i % 2 ? 40 : 52; teeth.push([64 + Math.cos(a) * r, 64 + Math.sin(a) * r]); }
cv.fill(poly(teeth), C.steel, { top: 12, bot: 116 });
cv.fill(circle(64, 64, 16), C.woodD, { shade: 0 });
},
};
// ---------- запись иконок и превью-листа
const names = Object.keys(ICONS);
const sheetCols = 7, cell = 160, rows = Math.ceil(names.length / sheetCols);
const SW = sheetCols * cell, SH = rows * cell;
const sheet = Buffer.alloc(SW * SH * 4);
for (let i = 0; i < SW * SH; i++) { sheet[i * 4] = 52; sheet[i * 4 + 1] = 36; sheet[i * 4 + 2] = 24; sheet[i * 4 + 3] = 255; } // фон — тёмное дерево
names.forEach((name, k) => {
const cv = new Canvas();
ICONS[name](cv);
const img = cv.render();
fs.writeFileSync(path.join(OUT, name + '.png'), png(S, S, img));
const ox = (k % sheetCols) * cell + 16, oy = Math.floor(k / sheetCols) * cell + 16;
for (let y = 0; y < S; y++) for (let x = 0; x < S; x++) {
const s = (y * S + x) * 4, d = ((oy + y) * SW + ox + x) * 4, a = img[s + 3] / 255;
for (let j = 0; j < 3; j++) sheet[d + j] = sheet[d + j] * (1 - a) + img[s + j] * a;
}
});
fs.writeFileSync(path.join(ROOT, 'assets', 'reference', 'icons_sheet.png'), png(SW, SH, sheet));
console.log('icons:', names.length, names.join(' '));