sendou.ink/scripts/replace-weapon-names.ts
Kalle d278a15504
Some checks failed
E2E Tests / e2e (push) Has been cancelled
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
10 star weapon pool (#3108)
2026-06-01 18:20:47 +03:00

99 lines
2.1 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { logger } from "~/utils/logger";
import weapons from "./dicts/WeaponInfoMain.json";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const DIR_PATH_1 = path.join(
__dirname,
"..",
"public",
"static-assets",
"img",
"main-weapons",
);
const DIR_PATH_2 = path.join(
__dirname,
"..",
"public",
"static-assets",
"img",
"main-weapons-outlined",
);
const DIR_PATH_3 = path.join(
__dirname,
"..",
"public",
"static-assets",
"img",
"main-weapons-outlined-2",
);
const DIR_PATH_4 = path.join(
__dirname,
"..",
"public",
"static-assets",
"img",
"main-weapons-outlined-3",
);
async function main() {
for (const [i, dir] of [
DIR_PATH_1,
DIR_PATH_2,
DIR_PATH_3,
DIR_PATH_4,
].entries()) {
const files = await fs.promises.readdir(dir);
for (const file of files) {
// skip if already replaced
if (file.length <= 8) continue;
const differentLevelBadge = (fileName: string) => {
if (i === 1 && fileName.includes("Lv01")) return true;
if (i === 2 && fileName.includes("Lv00")) return true;
if (i === 3 && fileName.includes("Lv00")) return true;
if (i === 3 && fileName.includes("Lv01")) return true;
// ver 10.0.0
if (fileName.includes("Lv02")) return true;
if (fileName.includes("Lv03")) return true;
if (fileName.includes("Lv04")) return true;
if (fileName.includes("Lv05")) return true;
if (i !== 3 && fileName.includes("Lv06")) return true;
return false;
};
if (file.includes(".webp") || differentLevelBadge(file)) {
await fs.promises.unlink(path.join(dir, file));
continue;
}
const weapon = (weapons as Array<{ __RowId: string; Id: number }>).find(
(weapon) =>
file.includes(`${weapon.__RowId}.`) ||
file.includes(`${weapon.__RowId}_`),
);
if (!weapon) {
await fs.promises.unlink(path.join(dir, file));
continue;
}
fs.renameSync(path.join(dir, file), path.join(dir, `${weapon.Id}.png`));
}
}
logger.info("done with all");
}
void main();