mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
create-weapon-json.ts script initial
This commit is contained in:
parent
2b378f69f8
commit
7d016598a0
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -12,4 +12,10 @@ dump
|
|||
/cypress/screenshots
|
||||
|
||||
.DS_Store
|
||||
.excalidraw
|
||||
.excalidraw
|
||||
|
||||
/scripts/output/*
|
||||
!/scripts/output/.gitkeep
|
||||
|
||||
/scripts/dicts/*.json
|
||||
/scripts/dicts/langs/*.json
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
"migrate:cypress": "cross-env DB_PATH=db-cypress.sqlite3 ley",
|
||||
"migrate:reset": "node scripts/delete-db-files.mjs && npm run migrate && npm run seed",
|
||||
"add-badge": "node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register scripts/add-badge.ts",
|
||||
"create-weapon-json": "node --experimental-specifier-resolution=node --loader ts-node/esm -r tsconfig-paths/register scripts/create-weapon-json.ts",
|
||||
"lint:ts": "eslint . --ext .ts,.tsx",
|
||||
"lint:styles": "stylelint \"app/styles/**/*.css\"",
|
||||
"prettier:check": "prettier --check .",
|
||||
|
|
|
|||
8
scripts/README.md
Normal file
8
scripts/README.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
This folder has scripts that can be used run time for admin only actions or to prepare some data.
|
||||
|
||||
#### `create-weapon-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
|
||||
63
scripts/create-weapon-json.ts
Normal file
63
scripts/create-weapon-json.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import weapons from "./dicts/WeaponInfoMain.json";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
const INTERNAL_NAMES_TO_IGNORE: readonly string[] = ["Free"] as const;
|
||||
const LANG_DICTS_PATH = path.join(__dirname, "dicts", "langs");
|
||||
const OUTPUT_PATH = path.join(__dirname, "output", "weapons.json");
|
||||
|
||||
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) {
|
||||
const translations = JSON.parse(
|
||||
fs.readFileSync(path.join(LANG_DICTS_PATH, file), "utf8")
|
||||
);
|
||||
|
||||
result.push([file.replace(".json", ""), translations]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const result: Array<{
|
||||
id: number;
|
||||
internalName: string;
|
||||
translations: Array<{ language: string; name: string }>;
|
||||
}> = [];
|
||||
const langDicts = await loadLangDicts();
|
||||
|
||||
for (const weapon of weapons) {
|
||||
if (
|
||||
weapon.Type === "Coop" ||
|
||||
INTERNAL_NAMES_TO_IGNORE.includes(weapon.__RowId)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push({
|
||||
id: weapon.Id,
|
||||
internalName: weapon.__RowId,
|
||||
translations: langDicts.map(([langCode, translations]) => {
|
||||
const name = translations[weapon.__RowId];
|
||||
invariant(name);
|
||||
|
||||
return {
|
||||
language: langCode,
|
||||
name,
|
||||
};
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
result.sort((a, b) => a.id - b.id);
|
||||
|
||||
fs.writeFileSync(OUTPUT_PATH, JSON.stringify(result, null, 2));
|
||||
}
|
||||
|
||||
void main();
|
||||
0
scripts/dicts/.gitkeep
Normal file
0
scripts/dicts/.gitkeep
Normal file
0
scripts/dicts/langs/.gitkeep
Normal file
0
scripts/dicts/langs/.gitkeep
Normal file
0
scripts/output/.gitkeep
Normal file
0
scripts/output/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user