mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-21 18:44:51 -05:00
Gear ids and translations
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
This folder has scripts that can be used run time for admin only actions or to prepare some data.
|
||||
|
||||
#### `create-weapon-json.ts`
|
||||
#### `create-weapon-json.ts` & `create-gear-json.ts`
|
||||
|
||||
Before using this script you need to copy some files from another repository.
|
||||
|
||||
1. Move .json files matching wanted languages from https://github.com/Leanny/leanny.github.io/tree/master/splat3/data/language to /scripts/dicts/langs
|
||||
2. Move WeaponInfoMain.json from https://github.com/Leanny/leanny.github.io/blob/master/splat3/data/mush/099/WeaponInfoMain.json to /scripts/dicts
|
||||
1. Copy all .json files from https://github.com/Leanny/leanny.github.io/tree/master/splat3/data/language to /scripts/dicts/langs
|
||||
2. Move `WeaponInfoMain.json`, `GearInfoClothes.json`, `GearInfoShoes.json` & `GearInfoHead.json` from https://github.com/Leanny/leanny.github.io/blob/master/splat3/data/mush/099 to /scripts/dicts
|
||||
|
||||
(note: the path is likely to change to .../mush/latest in future)
|
||||
|
||||
96
scripts/create-gear-json.ts
Normal file
96
scripts/create-gear-json.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import head from "./dicts/GearInfoHead.json";
|
||||
import clothes from "./dicts/GearInfoClothes.json";
|
||||
import shoes from "./dicts/GearInfoShoes.json";
|
||||
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import invariant from "tiny-invariant";
|
||||
import { loadLangDicts } from "./utils";
|
||||
|
||||
const CURRENT_SEASON = 0;
|
||||
const OUTPUT_DIR_PATH = path.join(__dirname, "output");
|
||||
const LANG_JSONS_TO_CREATE = ["EUen"];
|
||||
|
||||
async function main() {
|
||||
const allGear: Array<{
|
||||
id: number;
|
||||
internalName: string;
|
||||
type: string;
|
||||
translations: Array<{ language: string; name: string }>;
|
||||
}> = [];
|
||||
const langDicts = await loadLangDicts();
|
||||
|
||||
for (const gear of [...head, ...clothes, ...shoes]) {
|
||||
if (gear.Season > CURRENT_SEASON || gear.HowToGet !== "Shop") {
|
||||
continue;
|
||||
}
|
||||
|
||||
const [type, internalName] = gear.__RowId.split("_");
|
||||
invariant(type);
|
||||
invariant(internalName);
|
||||
|
||||
allGear.push({
|
||||
id: gear.Id,
|
||||
type,
|
||||
internalName,
|
||||
translations: langDicts.map(([langCode, translations]) => {
|
||||
const name = translations[internalName];
|
||||
invariant(name, `Missing translation for ${internalName}`);
|
||||
|
||||
return {
|
||||
language: langCode,
|
||||
name,
|
||||
};
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
allGear.sort((a, b) => a.id - b.id);
|
||||
|
||||
const headGear = allGear.filter((g) => g.type === "Hed");
|
||||
const clothesGear = allGear.filter((g) => g.type === "Clt");
|
||||
const shoesGear = allGear.filter((g) => g.type === "Shs");
|
||||
invariant(headGear.length);
|
||||
invariant(clothesGear.length);
|
||||
invariant(shoesGear.length);
|
||||
|
||||
const headIds = headGear.map((w) => w.id);
|
||||
const clothesIds = clothesGear.map((w) => w.id);
|
||||
const shoesIds = shoesGear.map((w) => w.id);
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(OUTPUT_DIR_PATH, "head-ids.json"),
|
||||
JSON.stringify(headIds, null, 2)
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(OUTPUT_DIR_PATH, "clothes-ids.json"),
|
||||
JSON.stringify(clothesIds, null, 2)
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(OUTPUT_DIR_PATH, "shoes-ids.json"),
|
||||
JSON.stringify(shoesIds, null, 2)
|
||||
);
|
||||
|
||||
for (const langCode of LANG_JSONS_TO_CREATE) {
|
||||
const translationsMap = Object.fromEntries(
|
||||
allGear.map((gear) => {
|
||||
const translation = gear.translations.find(
|
||||
(t) => t.language === langCode
|
||||
)?.name;
|
||||
invariant(
|
||||
translation,
|
||||
`No translation for ${gear.internalName} in ${langCode}`
|
||||
);
|
||||
|
||||
return [`${gear.type.charAt(0).toUpperCase()}_${gear.id}`, translation];
|
||||
})
|
||||
);
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(OUTPUT_DIR_PATH, `gear-${langCode}.json`),
|
||||
JSON.stringify(translationsMap, null, 2)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main();
|
||||
23
scripts/utils.ts
Normal file
23
scripts/utils.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
const LANG_DICTS_PATH = path.join(__dirname, "dicts", "langs");
|
||||
|
||||
export async function loadLangDicts() {
|
||||
const result: Array<
|
||||
[langCode: string, translations: Record<string, string>]
|
||||
> = [];
|
||||
|
||||
const files = await fs.promises.readdir(LANG_DICTS_PATH);
|
||||
for (const file of files) {
|
||||
if (file === ".gitkeep") continue;
|
||||
|
||||
const translations = JSON.parse(
|
||||
fs.readFileSync(path.join(LANG_DICTS_PATH, file), "utf8")
|
||||
);
|
||||
|
||||
result.push([file.replace(".json", ""), translations]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user