sprites/tools/sheet/index.ts
2020-09-13 22:22:43 -04:00

34 lines
812 B
TypeScript

import 'make-promises-safe';
import cp from 'child_process';
import path from 'path';
const sheetjs = process.argv[2];
const dest = process.argv[3];
if (!sheetjs || !dest) {
throw new Error(`node tools/sheet <file.sheet.js> <dest>`);
}
const {default: sheet} = await import(path.join(process.cwd(), sheetjs));
for (let i = 0; i < sheet.entries.length; i++) {
if (sheet.entries[i] === undefined)
throw new Error(`gap: ${i}`);
if (sheet.entries[i] === null) {
// ImageMagick blank entry
sheet.entries[i] = "xc:transparent";
}
}
cp.execFileSync("magick", [
"montage",
...sheet.entries,
"-background", "transparent",
"-geometry", `${sheet.width}x${sheet.height}>`,
"-gravity", "center",
"-tile", `${sheet.tile}x`,
"-depth", "8",
dest
]);