✨ Add function to categorize gamemaster data into Pokémon, forms, and moves
This commit is contained in:
@@ -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
|
||||
// ============================================================================
|
||||
|
||||
@@ -257,17 +257,12 @@ async function saveToServer() {
|
||||
error.value = null;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/gamemaster/save', {
|
||||
// Call the server endpoint to fetch and process on the server
|
||||
const response = await fetch('/api/gamemaster/process', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
pokemon: processedData.value.pokemon,
|
||||
pokemonAllForms: processedData.value.pokemonAllForms,
|
||||
moves: processedData.value.moves,
|
||||
raw: rawGamemaster.value
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -275,7 +270,10 @@ async function saveToServer() {
|
||||
throw new Error(err.error || 'Failed to save to server');
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
saveSuccess.value = true;
|
||||
console.log('✅ Files saved to server:', result);
|
||||
|
||||
// Reload server status
|
||||
await loadServerStatus();
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user