tools/ps-sheet -> tools/sheet, take js sheet spec as arg

This commit is contained in:
Christopher Monsanto 2020-05-09 06:04:47 -04:00
parent 9f3ccad640
commit 39eec46241
5 changed files with 47 additions and 32 deletions

View File

@ -26,9 +26,9 @@ rule{
rule{
display="ps trainers sheet",
input={},
input={"ps-trainers.sheet.mjs"},
command={
"node tools/ps-sheet trainers src/canonical/trainers %o",
"node tools/sheet %f %o",
compresspng{config="SPRITESHEET"}
},
output={"build/ps/trainers-sheet.png"}

View File

@ -1,6 +1,11 @@
import fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Derived from pokemon-showdown-client/src/battle-dex-data.ts
export default {
const BattleAvatarNumbers = {
1: 'lucas',
2: 'dawn',
3: 'youngster-gen4',
@ -297,3 +302,17 @@ export default {
// Not in the existing trainer sheet...
// 294: 'ash',
}
const entries = [];
for (const [num, id] of Object.entries(BattleAvatarNumbers)) {
entries[num - 1] = path.join(__dirname, "src/canonical/trainers", id + ".png");
}
export default {
width: 80,
height: 80,
tile: 16,
entries
};

View File

@ -1,29 +0,0 @@
import cp from 'child_process';
import path from 'path';
import BattleAvatarNumbers from './data-trainers.js';
const type = process.argv[2];
const dir = process.argv[3];
const dest = process.argv[4];
if (!dir || !dest) {
throw new Error(`node tools/ps-sheet <type> <dir> <dest>`);
}
if (type === 'trainers') {
// Guaranteed to be in the right order by V8, but iirc not by other JS engines.
const trainers = Object.values(BattleAvatarNumbers).map(t => path.join(dir, t) + ".png");
cp.execFileSync("montage", [
...trainers,
"-background", "transparent",
"-geometry", "80x80>",
"-gravity", "center",
"-tile", "16x",
"-depth", "8",
dest
]);
} else {
throw new Error(`unknown type: ${type}`);
}

25
tools/sheet/index.js Normal file
View File

@ -0,0 +1,25 @@
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/ps-sheet <file.sheet.js> <dest>`);
}
// Top-level await?
(async() => {
const {default: sheet} = await import(path.join(process.cwd(), sheetjs));
cp.execFileSync("montage", [
...sheet.entries,
"-background", "transparent",
"-geometry", `${sheet.width}x${sheet.height}>`,
"-gravity", "center",
"-tile", `${sheet.tile}x`,
"-depth", "8",
dest
]);
})();