Some of the links, particularly the one to the code, are broken now. Here's a TypeScript example:
JavaScript:
import { z } from "zod" ;
import { genderNames } from "../enums" ;
import { gens } from "../gens" ;
import { writeJunctionJsonToCsv } from "../path" ;
import { toID } from "@pkmn/data" ;
const eventSchema = z.object ({
gen : z.number (),
pokemonPsId : z.string (),
eventIndex : z.number (),
level : z.number ().optional (),
shinyChance : z.enum (["ALWAYS" , "SOMETIMES" , "NEVER" ]),
gender : z.enum (genderNames).optional (),
nature : z.string ().optional (),
guaranteedIvs : z
.object ({
hp : z.number ().optional (),
atk : z.number ().optional (),
def : z.number ().optional (),
spa : z.number ().optional (),
spd : z.number ().optional (),
spe : z.number ().optional (),
})
.optional (),
numberPerfectIvs : z.number ().optional (),
hiddenAbilityChance : z.enum (["ALWAYS" , "NEVER" ]).optional (),
abilityPsIds : z.array (z.string ()).optional (),
movePsIds : z.array (z.string ()).optional (),
pokeball : z.string ().optional (),
japanOnly : z.boolean ().optional (),
});
const learnsMoveSchema = z.object ({
gen : z.number (),
pokemonPsId : z.string (),
movePsId : z.string (),
learnMethods : z.string (),
});
export async function writeLearnsetAndEventCsv ( ) {
const eventRows : z.infer <typeof eventSchema>[] = [];
const learnsMoveRows : z.infer <typeof learnsMoveSchema>[] = [];
const learnMethodByPokemonPsId_MovePsId = new Map <string, Set <string>>();
for (const gen of gens) {
const learnsets = gen.learnsets ;
const genString = gen.num .toString ();
for (const specie of gen.species ) {
for await (const learnset of learnsets.all (specie)) {
const { learnset : learnData, eventData } = learnset;
if (eventData) {
eventData.forEach ((eventInfo, index ) => {
eventRows.push (
eventSchema.parse ({
gen : gen.num ,
pokemonPsId : specie.id ,
eventIndex : index,
level : eventInfo.level ,
shinyChance :
eventInfo.shiny === 1
? "SOMETIMES"
: eventInfo.shiny
? "ALWAYS"
: "NEVER" ,
gender : eventInfo.gender ,
nature : toID (eventInfo.nature ),
guaranteedIvs : eventInfo.ivs ,
numberPerfectIvs : eventInfo.perfectIVs ,
hiddenAbilityChance : eventInfo.isHidden ? "ALWAYS" : "NEVER" ,
abilityPsIds : eventInfo.abilities ,
movePsIds : eventInfo.moves ,
pokeball : eventInfo.pokeball ,
japanOnly : eventInfo.japan ,
})
);
});
}
if (learnData) {
for (const [movePsId, learnMethods] of Object .entries (learnData)) {
for (let learnMethod of learnMethods) {
if (learnMethod.indexOf (genString) !== 0 ) {
continue ;
}
else if (learnMethod.includes ("C" )) {
continue ;
}
learnMethod = learnMethod.replace (genString, "" );
const pokemonPsId = specie.id ;
const key = [genString, pokemonPsId, movePsId].join ("_" );
if (learnMethodByPokemonPsId_MovePsId.has (key)) {
learnMethodByPokemonPsId_MovePsId.get (key)?.add (learnMethod);
} else {
learnMethodByPokemonPsId_MovePsId.set (
key,
new Set ([learnMethod])
);
}
}
}
}
}
}
for (let [key, value] of learnMethodByPokemonPsId_MovePsId.entries ()) {
const [genString, pokemonId, moveId] = key.split ("_" );
if (!genString || !pokemonId || !moveId) {
continue ;
}
learnsMoveRows.push ({
gen : +genString,
pokemonPsId : pokemonId,
movePsId : moveId,
learnMethods : [...value].join (";" ),
});
}
}
writeJunctionJsonToCsv ("pokemon" , "event" , eventRows);
writeJunctionJsonToCsv ("pokemon" , "learnsMove" , learnsMoveRows);
}