mirror of
https://github.com/smogon/sprites.git
synced 2026-12-04 22:18:12 -06:00
DeployCtx read/list/hash return promises (copy and write stay sync: they only queue ops), the stamped copy helpers and buildfile deploy blocks await them, ActionQueue materialization and packing use fs/promises, and the CLI, config loaders, spritesheet writer, and trim tool follow. Declaration-time globbing and the module-init data reads stay sync: rules exist by the end of the import. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
|
|
import {parseArgs} from 'node:util';
|
|
|
|
import * as image from './image.ts';
|
|
|
|
let {values: opts, positionals: files} = parseArgs({
|
|
options: {
|
|
check: {type: 'boolean', short: 'c'},
|
|
verbose: {type: 'boolean', short: 'v'},
|
|
force: {type: 'boolean', short: 'f'},
|
|
},
|
|
allowPositionals: true,
|
|
});
|
|
|
|
let retVal = 0;
|
|
|
|
for (let file of files) {
|
|
let dims = await image.getDims(file);
|
|
let alreadyCropped = (dims.left === 0 || dims.right === 0) &&
|
|
(dims.top === 0 || dims.bottom === 0);
|
|
|
|
if (opts.verbose) {
|
|
let msg = `${file}: ${dims.width}x${dims.height}, `;
|
|
if (alreadyCropped) {
|
|
msg += `displacement horiz ${dims.left - dims.right}, vert ${dims.top - dims.bottom}`;
|
|
} else {
|
|
msg += `padding left ${dims.left}, top ${dims.top}, right ${dims.right}, bottom ${dims.bottom}`;
|
|
}
|
|
console.log(msg);
|
|
}
|
|
|
|
if (opts.check && !alreadyCropped) {
|
|
retVal = 1;
|
|
if (!opts.verbose) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!opts.check && (!alreadyCropped || opts.force)) {
|
|
let trimDims = image.losslessTrim(dims);
|
|
await image.crop(file, trimDims, file);
|
|
}
|
|
}
|
|
|
|
process.exit(retVal);
|