38 lines
1.7 KiB
TypeScript
38 lines
1.7 KiB
TypeScript
// Takes the README pictures from a real two-player session: headless, muted, local game server only.
|
|
// Needs: bun tools/serve.ts web/dist <game dir> 8790 and bun server/main.ts on 8791.
|
|
import { chromium } from "playwright-core";
|
|
import { mkdirSync } from "node:fs";
|
|
const out = "docs/shots";
|
|
mkdirSync(out, { recursive: true });
|
|
const url = "http://127.0.0.1:8790/?mute=1&server=ws://127.0.0.1:8791/ws";
|
|
const b = await chromium.launch({ channel: "chrome", headless: true, args: ["--mute-audio"] });
|
|
async function player(name: string) {
|
|
const c = await b.newContext({ viewport: { width: 1280, height: 720 } });
|
|
await c.addInitScript((n) => { try { localStorage.setItem("vcNamed", "1"); localStorage.setItem("vcName", n); } catch (e) {} }, name);
|
|
const p = await c.newPage();
|
|
await p.goto(url);
|
|
await p.waitForFunction(() => (window as any).vcPlaying, null, { timeout: 240000, polling: 500 });
|
|
return p;
|
|
}
|
|
const wait = (s: number) => new Promise((r) => setTimeout(r, s * 1000));
|
|
const shot = (p: any, name: string) => p.screenshot({ path: `${out}/${name}.jpg`, type: "jpeg", quality: 82, timeout: 90000 });
|
|
const cmd = (p: any, c: string) => p.evaluate((x: string) => { const M = (window as any).Module; (M.vcCmds || (M.vcCmds = [])).push(x); }, c);
|
|
const a = await player("crt"), other = await player("tommy");
|
|
await wait(15);
|
|
await shot(a, "players");
|
|
await a.keyboard.press("b");
|
|
await wait(2);
|
|
await shot(a, "vehicles");
|
|
await a.keyboard.press("Escape");
|
|
await wait(1);
|
|
await a.keyboard.down("q");
|
|
await wait(2);
|
|
await shot(a, "wheel");
|
|
await a.keyboard.up("q");
|
|
await wait(1);
|
|
await cmd(other, "car infernus");
|
|
await cmd(a, "car cheetah");
|
|
await wait(8);
|
|
await shot(a, "cars");
|
|
await Promise.race([b.close(), wait(5)]);
|
|
process.exit(0);
|