mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-14 13:55:20 +01:00
* Add license information * Add reuse lint workflow * Add snippets for spdx * fix: minor wording adjustments and typo fixes Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * chore: add FileContributor attributions for Bertie Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com> * begin licensing some audio assets * Add pokemon reborn sound affect attribution * Annotate Leavannite's section * Add more licensing info * Add license info to license files ._. * Move ps1 files out of public * Add license for animation jsons * Add license for bat scripts in public * Update licensing in scripts * Fix typo in license ref * Fix AGPL-3.0-or-later * Add license info to typedoc.config.js * Add MIT license for snippets * chore: update license info for files in scripts * chore: update license info * chore: update license info * chore: update license info * Remove licenses used only by public before linting with reuse * Add license info to new files added by docker PR * chore: apply biome * fix: add back linting workflow lost during merge * Add attribution based on Hanniel's information * Add attribution based on Officer Porkchop and Green Ninja's information * add attribution to unicorn_power for reshiram/zekrom/kyurem epic variant * Fixup minor typo * Adjust sprite test to not think REUSE.toml is a sprite json * Add missing continue-on-error to workflow * fix: address kev's comments from code review * docs: minor touchups --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
86 lines
2.5 KiB
JavaScript
86 lines
2.5 KiB
JavaScript
/*
|
|
* SPDX-FileCopyrightText: 2025 Pagefault Games
|
|
* SPDX-FileContributor: Bertie690
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import chalk from "chalk";
|
|
|
|
/**
|
|
* A single line of the inputted CSV.
|
|
* @typedef {[speciesName: string, move1: string, move2: string, move3: string, move4: string]}
|
|
* CSVLine
|
|
*/
|
|
|
|
/**
|
|
* Regex to determine if a string follows the required CSV format.
|
|
*/
|
|
const csvRegex = /^((?:[^,]+?,){4}(?:\w|\s)+?,?\n?)+$/g;
|
|
|
|
/**
|
|
* Given a CSV string, parse it and return a structured table ready to be inputted into code.
|
|
* @param {string} csv - The formatted CSV string.
|
|
* @returns {string} The fully formatted table.
|
|
*/
|
|
export function parseEggMoves(csv) {
|
|
console.log(chalk.grey("⚙️ Parsing egg moves..."));
|
|
if (!csvRegex.test(csv)) {
|
|
console.error(chalk.redBright("! Input was not proper CSV!"));
|
|
process.exitCode = 1;
|
|
return "";
|
|
}
|
|
|
|
let output = "{\n";
|
|
|
|
const lines = csv.split(/\n/g);
|
|
|
|
for (const line of lines) {
|
|
/**
|
|
* The individual CSV column for this species.
|
|
*/
|
|
const cols =
|
|
/** @type {CSVLine} */
|
|
(line.split(",").slice(0, 5));
|
|
const speciesName = toUpperSnakeCase(cols[0]);
|
|
|
|
const eggMoves =
|
|
/** @type {string[]} */
|
|
([]);
|
|
|
|
for (let m = 1; m < 5; m++) {
|
|
const moveName = cols[m].trim();
|
|
if (!moveName || moveName === "N/A") {
|
|
console.warn(`Species ${speciesName} missing ${m}th egg move!`);
|
|
eggMoves.push("MoveId.NONE");
|
|
continue;
|
|
}
|
|
|
|
// Remove (N) and (P) from the ends of move names before UPPER_SNAKE_CASE-ing them
|
|
const moveNameTitle = toUpperSnakeCase(moveName.replace(/ \([A-Z]\)$/, ""));
|
|
eggMoves.push("MoveId." + moveNameTitle);
|
|
}
|
|
|
|
if (eggMoves.every(move => move === "MoveId.NONE")) {
|
|
console.warn(`Species ${speciesName} could not be parsed, excluding from output...`);
|
|
output += ` // [SpeciesId.${speciesName}]: [ MoveId.NONE, MoveId.NONE, MoveId.NONE, MoveId.NONE ],\n`;
|
|
} else {
|
|
output += ` [SpeciesId.${speciesName}]: [ ${eggMoves.join(", ")} ],\n`;
|
|
}
|
|
}
|
|
|
|
// NB: We omit the semicolon as it is contained in the template string itself
|
|
return output + "} satisfies Partial<Record<SpeciesId, [MoveId, MoveId, MoveId, MoveId]>>";
|
|
}
|
|
|
|
/**
|
|
* Helper method to convert a string into `UPPER_SNAKE_CASE`.
|
|
* @param {string} str - The string being converted
|
|
* @returns {string} The result of converting `str` into upper snake case.
|
|
*/
|
|
function toUpperSnakeCase(str) {
|
|
return str
|
|
.split(/[_ -]+/g)
|
|
.map(word => word.toUpperCase())
|
|
.join("_");
|
|
}
|