// Builds public/og.jpg (1200x630) from real game screenshots: a desktop capture as backdrop, a phone capture in front, title on the left. // Needs dist/index.html (npm run dump) and playwright-core. import { chromium } from 'playwright-core' import { pathToFileURL } from 'node:url' import { resolve } from 'node:path' import { readFileSync, writeFileSync, mkdirSync } from 'node:fs' const url = pathToFileURL(resolve('dist/index.html')).href const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH || '/usr/bin/google-chrome' }) mkdirSync('dist/art', { recursive: true }) async function shot(opts, out, seed, hideUi) { const ctx = await browser.newContext(opts) const page = await ctx.newPage() await page.goto(url + `?seed=${seed}`) await page.waitForTimeout(300) await page.evaluate(() => window.__starsnake.scene()) await page.waitForTimeout(900) await page.evaluate(() => window.__starsnake.freeze()) if (hideUi) await page.addStyleTag({ content: '#hud,#buildBar{display:none!important}' }) await page.waitForTimeout(100) await page.screenshot({ path: out }) await ctx.close() } await shot({ viewport: { width: 1200, height: 630 } }, 'dist/art/bg.png', 5, true) await shot({ viewport: { width: 390, height: 780 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true }, 'dist/art/phone.png', 9) const b64 = (f) => readFileSync(f).toString('base64') const html = `
SNAKE × ASTEROIDS × TOWER DEFENSE

STARSNAKE

Grow a crystal tail. Build towers. Guard the core.
FLYCOLLECTBUILD
FREE · PLAY ON YOUR PHONE
` writeFileSync('dist/art/og.html', html) const page = await (await browser.newContext({ viewport: { width: 1200, height: 630 } })).newPage() await page.goto(pathToFileURL(resolve('dist/art/og.html')).href) await page.waitForTimeout(300) await page.screenshot({ path: 'public/og.jpg', type: 'jpeg', quality: 84 }) await browser.close() console.log('og ok')