File size: 1,954 Bytes
33d96a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const puppeteer = require('puppeteer');
const path = require('path');
(async () => {
  const browser = await puppeteer.launch({ headless: 'new',
    args: ['--no-sandbox','--use-gl=swiftshader','--enable-unsafe-swiftshader'] });
  const page = await browser.newPage();
  await page.setViewport({ width: 1280, height: 720 });
  const errors = [];
  page.on('pageerror', e => errors.push(e.message));
  await page.goto('file://' + path.resolve(__dirname, 'index.html'), { waitUntil: 'domcontentloaded', timeout: 60000 });
  await page.waitForFunction('typeof THREE !== "undefined" && typeof G !== "undefined"', { timeout: 20000 });
  await new Promise(r => setTimeout(r, 1200));

  await page.evaluate(() => startRace());
  await new Promise(r => setTimeout(r, 4200)); // let countdown finish -> race

  // 1) force physics directly (bypass input): call updatePlayer manually
  let r1 = await page.evaluate(() => {
    const p = G.player;
    const inp = { left:0, right:0, gas:1, brake:0, nitro:0, drift:0 };
    for (let i = 0; i < 60; i++) updatePlayer(1/60, inp);
    return { v: +(Math.hypot(p.vx,p.vz)).toFixed(1), x:+p.x.toFixed(1), z:+p.z.toFixed(1), s:Math.round(p.s) };
  });
  console.log('MANUAL PHYSICS 1s:', JSON.stringify(r1), '(expect ~15 m/s)');

  // 2) now test keyboard input: check keys object after keydown
  await page.keyboard.down('ArrowUp');

  const kState = await page.evaluate(() => ({
    arrowUp: !!keys.ArrowUp,
    readGas: readInput().gas,
  }));
  console.log('KEYBOARD STATE:', JSON.stringify(kState));
  await new Promise(r => setTimeout(r, 2000));
  const r3 = await page.evaluate(() => {
    const p = G.player;
    return { v: +(Math.hypot(p.vx,p.vz)*3.6).toFixed(0) + ' km/h', keysUp: !!keys.ArrowUp, gas: readInput().gas, state: G.state };
  });
  console.log('AFTER 2s REAL TIME w/ KEY:', JSON.stringify(r3));
  await page.keyboard.up('ArrowUp');

  console.log('ERRORS:', errors);
  await browser.close();
})();