sendou.ink/scripts/generate-weapon-csv.js
William Lam 02516e26bd
Add script that generates a CSV containing basic attribute information on each Main Weapon (#1148)
* Added a script that generates a CSV containing basic attribute information on each Main Weapon

* Improved some names & console info

* More comments

* Renamed file & fixed Prettier error

* Shortened the default string a weapon attribute if it doesn't exist
2022-11-22 17:48:43 +02:00

56 lines
1.7 KiB
JavaScript

/* eslint-disable */
// @ts-nocheck
// This script generates a CSV file for main weapons and some of their attributes.
// To run the script, run "node scripts/generate-weapon-csv.js" from the root of the repository folder
const weaponParams = require("../app/modules/analyzer/weapon-params.json");
const weaponsJsonEn = require("../public/locales/en/weapons.json");
const fs = require("fs");
const outFilePath = "output/main-weapon-table.csv";
function main() {
// Create data structure where we can search by weaponId as the key
const mainWeaponsJson = Object.keys(weaponsJsonEn)
.filter((key) => key.includes("MAIN"))
.reduce((obj, key) => {
weaponId = key.replace("MAIN_", "");
obj[weaponId] = weaponsJsonEn[key];
return obj;
}, {});
const mainWeaponsParams = weaponParams.mainWeapons;
const columnNames = [
"Weapon Name",
"Special Points Required",
"Weapon Speed Type",
"Move Speed",
];
const columnNamesForCsv = columnNames.join(",") + "\r\n";
fs.writeFileSync(outFilePath, columnNamesForCsv);
const columnAttributes = ["SpecialPoint", "WeaponSpeedType", "MoveSpeed"];
// Construct each row data string for each main weapon, then append them to the CSV file
Object.entries(mainWeaponsParams).forEach((mainWeapon) => {
const [weaponId, weaponAttributes] = mainWeapon;
const weaponName = mainWeaponsJson[weaponId];
let rowData = weaponName + ",";
for (const attrKey of columnAttributes) {
const attribute = weaponAttributes[attrKey] ?? "";
rowData += attribute + ",";
}
rowData += "\r\n";
fs.appendFileSync(outFilePath, rowData, (err) => {
if (err) throw err;
});
});
console.log(`Table was generated in file '${outFilePath}'`);
}
void main();