Add standalone Pokémon Legends: Arceus POC tracker (Hisui 242 Pokédex, Research Tasks & RL10 mode, Satchel MP & Save Mythicals toggles, Noble/story battles, saves/movesets), bundle local sprite packs across all three trackers into Git/Docker/Nginx with attribution credits, and update Hub landing page & unified server/tests.
213 lines
8.0 KiB
JavaScript
213 lines
8.0 KiB
JavaScript
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const ROOT_DIR = path.resolve(__dirname, '..');
|
|
|
|
async function existsNonEmpty(filePath) {
|
|
try {
|
|
const st = await fs.stat(filePath);
|
|
return st.isFile() && st.size > 0;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async function downloadFile(url, destPath) {
|
|
if (await existsNonEmpty(destPath)) return 'skipped';
|
|
const res = await fetch(url, { headers: { 'User-Agent': 'Professor-Oak-Tracker-Sprite-Downloader/1.0' } });
|
|
if (!res.ok) return `http-${res.status}`;
|
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
await fs.mkdir(path.dirname(destPath), { recursive: true });
|
|
await fs.writeFile(destPath, buf);
|
|
return 'downloaded';
|
|
}
|
|
|
|
async function collectOrasJobs() {
|
|
const { SPECIES_LIST } = await import('../oras/src/data/species.js');
|
|
const spritesMod = await import('../oras/src/ui/sprites.js');
|
|
const outRoot = path.join(ROOT_DIR, 'oras', 'assets', 'sprites');
|
|
const jobs = [];
|
|
|
|
for (const sp of SPECIES_LIST) {
|
|
for (const shiny of [false, true]) {
|
|
const { primary, fallback } = spritesMod.getPokemonSpriteUrls(sp.natId, { shiny });
|
|
const relPrimary = primary.replace(spritesMod.POKEAPI_SPRITES_CDN + '/', '');
|
|
const relFallback = fallback.replace(spritesMod.POKEAPI_SPRITES_CDN + '/', '');
|
|
jobs.push({
|
|
candidates: [
|
|
{ url: primary, dest: path.join(outRoot, relPrimary) },
|
|
{ url: fallback, dest: path.join(outRoot, relFallback) },
|
|
],
|
|
});
|
|
}
|
|
}
|
|
|
|
// Known ORAS evolution / held item icons
|
|
const itemSlugs = [
|
|
'water-stone', 'fire-stone', 'thunder-stone', 'leaf-stone', 'moon-stone', 'sun-stone',
|
|
'shiny-stone', 'dusk-stone', 'dawn-stone', 'oval-stone', 'kings-rock', 'metal-coat',
|
|
'dragon-scale', 'deep-sea-tooth', 'deep-sea-scale', 'protector', 'reaper-cloth',
|
|
'electirizer', 'magmarizer', 'up-grade', 'dubious-disc', 'prism-scale', 'sea-incense',
|
|
'rose-incense', 'pure-incense', 'luck-incense', 'lax-incense', 'wave-incense',
|
|
'helix-fossil', 'dome-fossil', 'old-amber', 'root-fossil', 'claw-fossil',
|
|
'skull-fossil', 'armor-fossil', 'cover-fossil', 'plume-fossil', 'poke-ball',
|
|
];
|
|
for (const slug of itemSlugs) {
|
|
const url = `${spritesMod.POKEAPI_SPRITES_CDN}/items/${slug}.png`;
|
|
jobs.push({ candidates: [{ url, dest: path.join(outRoot, 'items', `${slug}.png`) }] });
|
|
}
|
|
|
|
return { game: 'oras', outRoot, jobs };
|
|
}
|
|
|
|
async function collectLumiJobs() {
|
|
const { SPECIES_LIST } = await import('../luminescent-platinum/src/data/species.js');
|
|
const spritesMod = await import('../luminescent-platinum/src/ui/sprites.js');
|
|
const outRoot = path.join(ROOT_DIR, 'luminescent-platinum', 'assets', 'sprites');
|
|
const jobs = [];
|
|
|
|
for (const sp of SPECIES_LIST) {
|
|
for (const shiny of [false, true]) {
|
|
const { primary, fallback } = spritesMod.getPokemonSpriteUrls(sp, { shiny });
|
|
const relPrimary = primary.replace(spritesMod.LUMI_IMG_CDN + '/', '');
|
|
jobs.push({
|
|
candidates: [
|
|
{ url: primary, dest: path.join(outRoot, relPrimary) },
|
|
{ url: fallback, dest: path.join(outRoot, relPrimary) },
|
|
],
|
|
});
|
|
}
|
|
}
|
|
|
|
const lumiItems = [
|
|
'items/Item_Water_Stone.webp', 'items/Item_Fire_Stone.webp', 'items/Item_Thunder_Stone.webp',
|
|
'items/Item_Leaf_Stone.webp', 'items/Item_Moon_Stone.webp', 'items/Item_Sun_Stone.webp',
|
|
'items/Item_Shiny_Stone.webp', 'items/Item_Dusk_Stone.webp', 'items/Item_Dawn_Stone.webp',
|
|
'items/Item_Ice_Stone.webp', 'items/Item_Oval_Stone.webp', 'items/Item_Kings_Rock.webp',
|
|
'items/Item_Metal_Coat.webp', 'items/Item_Dragon_Scale.webp', 'items/Item_Deep_Sea_Tooth.webp',
|
|
'items/Item_Deep_Sea_Scale.webp', 'items/Item_Protector.webp', 'items/Item_Reaper_Cloth.webp',
|
|
'items/Item_Electirizer.webp', 'items/Item_Magmarizer.webp', 'items/Item_Upgrade.webp',
|
|
'items/Item_Dubious_Disc.webp', 'items/Item_Prism_Scale.webp', 'items/Item_Razor_Claw.webp',
|
|
'items/Item_Razor_Fang.webp', 'items/Item_Soothe_Bell.webp', 'Moss%20Rock.webp',
|
|
'Ice%20Rock.webp', 'Incense.webp', 'items/Item_Honey.webp',
|
|
];
|
|
for (const file of lumiItems) {
|
|
jobs.push({
|
|
candidates: [
|
|
{
|
|
url: `${spritesMod.LUMI_IMG_CDN}/${file}`,
|
|
dest: path.join(outRoot, decodeURIComponent(file)),
|
|
},
|
|
],
|
|
});
|
|
}
|
|
jobs.push({
|
|
candidates: [
|
|
{
|
|
url: `${spritesMod.POKEAPI_FALLBACK_CDN}/items/poke-ball.png`,
|
|
dest: path.join(outRoot, 'items', 'poke-ball.png'),
|
|
},
|
|
],
|
|
});
|
|
|
|
return { game: 'luminescent-platinum', outRoot, jobs };
|
|
}
|
|
|
|
async function collectPlaJobs() {
|
|
const { SPECIES_LIST } = await import('../legends-arceus/src/data/species.js');
|
|
const spritesMod = await import('../legends-arceus/src/ui/sprites.js');
|
|
const outRoot = path.join(ROOT_DIR, 'legends-arceus', 'assets', 'sprites');
|
|
const jobs = [];
|
|
|
|
for (const sp of SPECIES_LIST) {
|
|
for (const shiny of [false, true]) {
|
|
const { primary, fallback } = spritesMod.getPokemonSpriteUrls(sp, { shiny });
|
|
const relPrimary = primary.replace(spritesMod.POKEAPI_SPRITES_CDN + '/', '');
|
|
const relFallback = fallback.replace(spritesMod.POKEAPI_SPRITES_CDN + '/', '');
|
|
jobs.push({
|
|
candidates: [
|
|
{ url: primary, dest: path.join(outRoot, relPrimary) },
|
|
{ url: fallback, dest: path.join(outRoot, relFallback) },
|
|
],
|
|
});
|
|
}
|
|
}
|
|
|
|
for (const rule of spritesMod.ITEM_ICON_RULES) {
|
|
const url = `${spritesMod.POKEAPI_SPRITES_CDN}/items/${rule.slug}.png`;
|
|
jobs.push({ candidates: [{ url, dest: path.join(outRoot, 'items', `${rule.slug}.png`) }] });
|
|
}
|
|
|
|
return { game: 'legends-arceus', outRoot, jobs };
|
|
}
|
|
|
|
async function runPool(jobs, concurrency = 8) {
|
|
let idx = 0;
|
|
let downloaded = 0;
|
|
let skipped = 0;
|
|
const failed = [];
|
|
|
|
async function worker() {
|
|
while (idx < jobs.length) {
|
|
const job = jobs[idx++];
|
|
let ok = false;
|
|
for (const cand of job.candidates) {
|
|
const result = await downloadFile(cand.url, cand.dest).catch((e) => `err-${e.message}`);
|
|
if (result === 'downloaded') {
|
|
downloaded++;
|
|
ok = true;
|
|
break;
|
|
}
|
|
if (result === 'skipped') {
|
|
skipped++;
|
|
ok = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!ok) {
|
|
failed.push(job.candidates[0].url);
|
|
}
|
|
}
|
|
}
|
|
|
|
await Promise.all(Array.from({ length: concurrency }, () => worker()));
|
|
return { total: jobs.length, downloaded, skipped, failed };
|
|
}
|
|
|
|
const args = process.argv.slice(2);
|
|
const gameArgIdx = args.indexOf('--game');
|
|
const targetGame = gameArgIdx >= 0 && args[gameArgIdx + 1] ? args[gameArgIdx + 1] : 'all';
|
|
|
|
const collectors = [];
|
|
if (targetGame === 'all' || targetGame === 'oras') collectors.push(collectOrasJobs);
|
|
if (targetGame === 'all' || targetGame === 'luminescent-platinum') collectors.push(collectLumiJobs);
|
|
if (targetGame === 'all' || targetGame === 'legends-arceus') collectors.push(collectPlaJobs);
|
|
|
|
if (collectors.length === 0) {
|
|
console.error(`Unknown --game value "${targetGame}". Use all, oras, luminescent-platinum, or legends-arceus.`);
|
|
process.exit(1);
|
|
}
|
|
|
|
for (const collect of collectors) {
|
|
const { game, outRoot, jobs } = await collect();
|
|
console.log(`\nDownloading sprites for [${game}] (${jobs.length} files -> ${outRoot})...`);
|
|
const summary = await runPool(jobs, 8);
|
|
if (summary.downloaded > 0 || summary.skipped > 0) {
|
|
await fs.mkdir(outRoot, { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(outRoot, '.ready.json'),
|
|
JSON.stringify({ hasLocalSprites: true, updatedAt: new Date().toISOString() }, null, 2),
|
|
);
|
|
} else {
|
|
await fs.rm(path.join(outRoot, '.ready.json'), { force: true });
|
|
process.exitCode = 1;
|
|
}
|
|
console.log(` Done [${game}]: downloaded=${summary.downloaded}, skipped=${summary.skipped}, missing/optional=${summary.failed.length}`);
|
|
if (summary.failed.length > 0) {
|
|
console.log(' Sample skipped/missing URLs:', summary.failed.slice(0, 5));
|
|
}
|
|
}
|