Add function to categorize gamemaster data into Pokémon, forms, and moves

This commit is contained in:
2026-01-28 19:07:35 +00:00
parent 5785985419
commit 0a7b920bb5
2 changed files with 73 additions and 8 deletions

View File

@@ -85,6 +85,73 @@ function loadFile(filename) {
return JSON.parse(content);
}
/**
* Break up gamemaster into separate categories
* @param {Array} gamemaster - Full gamemaster data
* @returns {Object} Separated data {pokemon, pokemonAllForms, moves}
*/
function breakUpGamemaster(gamemaster) {
const regionCheck = ['alola', 'galarian', 'hisuian', 'paldea'];
const result = gamemaster.reduce(
(acc, item) => {
const templateId = item.templateId;
// POKEMON FILTER
if (
templateId.startsWith('V') &&
templateId.toLowerCase().includes('pokemon')
) {
const pokemonSettings = item.data?.pokemonSettings;
const pokemonId = pokemonSettings?.pokemonId;
acc.pokemonAllForms.push(item);
const form = pokemonSettings?.form;
const isRegionalForm =
form && typeof form === 'string'
? regionCheck.includes(form.split('_')[1]?.toLowerCase())
: false;
if (
!acc.pokemonSeen.has(pokemonId) ||
(acc.pokemonSeen.has(pokemonId) && isRegionalForm)
) {
acc.pokemonSeen.add(pokemonId);
acc.pokemon.push(item);
}
}
// POKEMON MOVE FILTER
if (
templateId.startsWith('V') &&
templateId.toLowerCase().includes('move')
) {
const moveSettings = item.data?.moveSettings;
const moveId = moveSettings?.movementId;
if (!acc.moveSeen.has(moveId)) {
acc.moveSeen.add(moveId);
acc.moves.push(item);
}
}
return acc;
},
{
pokemon: [],
pokemonAllForms: [],
moves: [],
pokemonSeen: new Set(),
moveSeen: new Set()
}
);
delete result.pokemonSeen;
delete result.moveSeen;
return result;
}
// ============================================================================
// ROUTES
// ============================================================================