mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-07 19:55:46 -05:00
Update replace img names script
This commit is contained in:
@@ -8,11 +8,7 @@
|
||||
// xxx: finish merging with create-weapon-json
|
||||
|
||||
import type { SpecialWeaponId } from "~/modules/in-game-lists";
|
||||
import {
|
||||
type SubWeaponId,
|
||||
subWeaponIds,
|
||||
mainWeaponIds,
|
||||
} from "~/modules/in-game-lists";
|
||||
import { type SubWeaponId, subWeaponIds } from "~/modules/in-game-lists";
|
||||
import weapons from "./dicts/WeaponInfoMain.json";
|
||||
// xxx: for example suction missing ink consume level, ink saver lvl... we are not considering default?
|
||||
import subWeapons from "./dicts/WeaponInfoSub.json";
|
||||
|
||||
@@ -14,6 +14,8 @@ const LEAN_HEAD_CODE = "Hed";
|
||||
const LEAN_CLOTHES_CODE = "Clt";
|
||||
const LEAN_SHOES_CODE = "Shs";
|
||||
|
||||
const AVAILABLE_SR_GEAR = [21010];
|
||||
|
||||
async function main() {
|
||||
const allGear: Array<{
|
||||
id: number;
|
||||
@@ -24,7 +26,11 @@ async function main() {
|
||||
const langDicts = await loadLangDicts();
|
||||
|
||||
for (const gear of [...head, ...clothes, ...shoes]) {
|
||||
if (gear.Season > CURRENT_SEASON || gear.HowToGet !== "Shop") {
|
||||
if (gear.Season > CURRENT_SEASON || gear.HowToGet === "Impossible") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gear.__RowId.includes("COP") && !AVAILABLE_SR_GEAR.includes(gear.Id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,6 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
const WEAPON_IMAGES_PATH = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"public",
|
||||
"img",
|
||||
"weapons"
|
||||
);
|
||||
const GEAR_IMAGES_DIR_PATH = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
@@ -17,33 +10,9 @@ const GEAR_IMAGES_DIR_PATH = path.join(
|
||||
"img",
|
||||
"gear"
|
||||
);
|
||||
const WEAPONS_JSON_PATH = path.join(__dirname, "output", "weapons.json");
|
||||
const GEAR_JSON_PATH = path.join(__dirname, "output", "gear.json");
|
||||
|
||||
async function main() {
|
||||
const weapons = JSON.parse(fs.readFileSync(WEAPONS_JSON_PATH, "utf8"));
|
||||
const files = await fs.promises.readdir(WEAPON_IMAGES_PATH);
|
||||
|
||||
// weapons
|
||||
for (const file of files) {
|
||||
if (!file.startsWith("Path_Wst")) continue;
|
||||
|
||||
const weaponInternalName = file
|
||||
.replace(".png", "")
|
||||
.replace("Path_Wst_", "");
|
||||
|
||||
const weaponId = weapons.find(
|
||||
(w: any) => w.internalName === weaponInternalName
|
||||
).id;
|
||||
invariant(typeof weaponId === "number", weaponInternalName + " has no id");
|
||||
|
||||
fs.renameSync(
|
||||
path.join(WEAPON_IMAGES_PATH, file),
|
||||
path.join(WEAPON_IMAGES_PATH, `${weaponId}.png`)
|
||||
);
|
||||
}
|
||||
|
||||
// gear
|
||||
const gear = JSON.parse(fs.readFileSync(GEAR_JSON_PATH, "utf8"));
|
||||
for (const gearSlot of ["head", "clothes", "shoes"] as const) {
|
||||
const gearSlotDirPath = path.join(GEAR_IMAGES_DIR_PATH, gearSlot);
|
||||
@@ -53,6 +22,7 @@ async function main() {
|
||||
gearSlot === "head" ? "Hed" : gearSlot === "shoes" ? "Shs" : "Clt";
|
||||
|
||||
for (const file of files) {
|
||||
// did we already replace the name
|
||||
if (
|
||||
!file.startsWith("Shs") &&
|
||||
!file.startsWith("Clt") &&
|
||||
@@ -61,13 +31,22 @@ async function main() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file.endsWith(".webp")) {
|
||||
fs.unlinkSync(path.join(gearSlotDirPath, file));
|
||||
continue;
|
||||
}
|
||||
|
||||
const internalName = file.replace(".png", "").split("_")[1];
|
||||
invariant(internalName);
|
||||
|
||||
const gearId = gear.find(
|
||||
(g: any) => g.internalName === internalName && g.type === type
|
||||
)?.id;
|
||||
invariant(typeof gearId === "number", internalName + " has no id");
|
||||
|
||||
if (typeof gearId !== "number") {
|
||||
fs.unlinkSync(path.join(gearSlotDirPath, file));
|
||||
continue;
|
||||
}
|
||||
|
||||
fs.renameSync(
|
||||
path.join(gearSlotDirPath, file),
|
||||
|
||||
Reference in New Issue
Block a user