From 13a9f257bbb2f5df8863a9e609ff5f3f876f2950 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Wed, 14 Sep 2022 13:43:08 +0300 Subject: [PATCH] Update replace img names script --- scripts/create-analyzer-json.ts | 6 +---- scripts/create-gear-json.ts | 8 +++++- scripts/replace-img-names.ts | 43 +++++++++------------------------ 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/scripts/create-analyzer-json.ts b/scripts/create-analyzer-json.ts index e8ec29c90..90ff95d83 100644 --- a/scripts/create-analyzer-json.ts +++ b/scripts/create-analyzer-json.ts @@ -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"; diff --git a/scripts/create-gear-json.ts b/scripts/create-gear-json.ts index 2dfca6c0a..02b8e6e32 100644 --- a/scripts/create-gear-json.ts +++ b/scripts/create-gear-json.ts @@ -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; } diff --git a/scripts/replace-img-names.ts b/scripts/replace-img-names.ts index 60c38d9dd..1f6e6bb8c 100644 --- a/scripts/replace-img-names.ts +++ b/scripts/replace-img-names.ts @@ -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),