pokemon-showdown-client/build-tools/build-minidex
Guangcong Luo a10821ab8b
Some checks are pending
Node.js CI / build (22.x) (push) Waiting to run
Update to ESLint 9 (#2326)
This finally removes the tslint dependency and switches to eslint.

There are a lot of other changes here, too, to bring the codebase up to
server standards. TSLint never had much in the way of indentation
enforcement.

Not very happy about eslint splitting itself up over 6 dependencies,
or its documentation over three websites, nor how poorly documented the
new flat config is, but I mean, eslint's gonna eslint. Customizing
would be even harder if we tried to use Biome or something. They mostly
seem to go full Prettier.

Also here are some changes to our style rules. In particular:

- Curly brackets (for objects etc) now have spaces inside them. Sorry
  for the huge change. ESLint doesn't support our old style, and most
  projects use Prettier style, so we might as well match them in this way.
  See https://github.com/eslint-stylistic/eslint-stylistic/issues/415

- String + number concatenation is no longer allowed (except in ES3
  code). We otherwise now consistently use template strings for this.
2025-02-25 20:05:32 -08:00

104 lines
2.8 KiB
JavaScript
Executable File

#!/usr/bin/env node
'use strict';
const fs = require("fs");
const path = require("path");
process.chdir(path.resolve(__dirname, '../play.pokemonshowdown.com'));
const imageSize = require('image-size');
const Dex = require('./../caches/pokemon-showdown/dist/sim/dex').Dex;
const toID = Dex.toID;
process.stdout.write("Updating animated sprite dimensions... ");
let buf = `/*
DO NOT EDIT
THIS FILE IS AUTOGENERATED BY ./build-tools/build-minidex
*/
exports.BattlePokemonSprites = {
substitute:{exists:false, front:{w:34, h:39}, back:{w:37, h:38}},
`;
let g5buf = `/*
DO NOT EDIT
THIS FILE IS AUTOGENERATED BY ./build-tools/build-minidex
*/
exports.BattlePokemonSpritesBW = {
`;
function sizeObj(objPath) {
try {
const size = imageSize(objPath);
return {
w: size.width,
h: size.height,
};
} catch {}
}
function updateSizes() {
for (const baseid in Dex.data.Pokedex) {
const species = Dex.species.get(baseid);
for (const formeName of [''].concat(species.cosmeticFormes || [])) {
let spriteid = species.spriteid;
if (formeName) spriteid += '-' + toID(formeName).slice(species.id.length);
const id = toID(spriteid);
{
const row = { num: species.num };
const frontSize = sizeObj('sprites/ani/' + spriteid + '.gif');
if (frontSize) row.front = frontSize;
const frontSizeF = sizeObj('sprites/ani/' + spriteid + '-f.gif');
if (frontSizeF) row.frontf = frontSizeF;
const backSize = sizeObj('sprites/ani-back/' + spriteid + '.gif');
if (backSize) row.back = backSize;
const backSizeF = sizeObj('sprites/ani-back/' + spriteid + '-f.gif');
if (backSizeF) row.backf = backSizeF;
if (row.front || row.back || !row.forme) {
buf += `\t${id}:` + JSON.stringify(row).replace(/"/g, '') + `,\n`;
}
}
{
const g5row = { num: species.num };
const frontSize = sizeObj('sprites/gen5ani/' + spriteid + '.gif');
if (frontSize) g5row.front = frontSize;
const frontSizeF = sizeObj('sprites/gen5ani/' + spriteid + '-f.gif');
if (frontSizeF) g5row.frontf = frontSizeF;
const backSize = sizeObj('sprites/gen5ani-back/' + spriteid + '.gif');
if (backSize) g5row.back = backSize;
const backSizeF = sizeObj('sprites/gen5ani-back/' + spriteid + '-f.gif');
if (backSizeF) g5row.backf = backSizeF;
if (g5row.front || g5row.back || !g5row.forme) {
g5buf += `\t${id}:` + JSON.stringify(g5row).replace(/"/g, '') + `,\n`;
}
}
}
}
buf = buf.slice(0, -2) + `
};
`;
g5buf = g5buf.slice(0, -2) + `
};
`;
fs.writeFileSync('data/pokedex-mini.js', buf);
fs.writeFileSync('data/pokedex-mini-bw.js', g5buf);
}
if (fs.existsSync('sprites/ani/')) {
updateSizes();
console.log('DONE');
} else {
try {
fs.unlinkSync('data/pokedex-mini.js');
fs.unlinkSync('data/pokedex-mini-bw.js');
} catch {}
console.log('SKIPPED');
}