diff --git a/tools/gen-thumbnails.js b/tools/gen-thumbnails.js new file mode 100644 index 0000000..3b86be7 --- /dev/null +++ b/tools/gen-thumbnails.js @@ -0,0 +1,225 @@ +// Generate 8-bit style thumbnails for each game (attract-mode look). +// Self-contained: all code inlined into a single page, no cross-scope issues. +const puppeteer = require('puppeteer'); +const path = require('path'); +const fs = require('fs'); + +const OUT = path.join(__dirname, '..', 'public', 'img'); +fs.mkdirSync(OUT, { recursive: true }); + +const W = 640, H = 480; + +const PAGE = `
+ + + + +`; + +const NAMES = ['asteroid', 'breakout', 'snake', 'spaceinvaders']; + +(async () => { + const browser = await puppeteer.launch({ + headless: 'new', + args: ['--no-sandbox','--disable-setuid-sandbox','--disable-gpu', + '--use-gl=swiftshader','--enable-unsafe-swiftshader'], + }); + const page = await browser.newPage(); + await page.setViewport({ width: W, height: H }); + await page.setContent(PAGE, { waitUntil: 'networkidle0' }); + await page.evaluate(() => document.fonts.load('28px "Press Start 2P"')); + await page.evaluate(() => document.fonts.ready); + + for (const name of NAMES) { + await page.evaluate((n) => drawScene(n), name); + const d = await page.$eval('#c', c => c.toDataURL('image/png')); + const b64 = d.replace(/^data:image\/png;base64,/, ''); + const buf = Buffer.from(b64, 'base64'); + fs.writeFileSync(path.join(OUT, name + '.png'), buf); + console.log(`wrote ${name}.png (${buf.length} bytes)`); + } + await browser.close(); + console.log('thumbnails done'); +})().catch(e => { console.error(e); process.exit(1); }); \ No newline at end of file