Back to Faultline
SOURCE / PINNED RELEASE

Made of little things.

Faultline

Release
da1ffaa5624c…
Author-recorded commit
60f5f03189db…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-6932b12c78c

Archive hash verified: 5a2e0492417ec4e7…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

tests/controller-match.mjs
// Physical input is replaced only at the Gamepad API boundary of the local soyLI player.
// App navigation, field edits, combat and room operations use controller samples.
export default async ({ players: [host, guest], check }) => {
  async function attach(p) {
    await p.frame.evaluate(() => {
      const pad = {
        index: 0,
        id: 'Test pad',
        mapping: 'standard',
        connected: true,
        axes: [0, 0, 0, 0],
        buttons: Array.from({ length: 17 }, () => ({ value: 0, pressed: false, touched: false })),
      };
      Object.defineProperty(navigator, 'getGamepads', {
        configurable: true,
        value: () => [window.testPad.connected ? pad : null],
      });
      window.testPad = pad;
      window.focus();
    });
    await p.frame.waitForFunction(() => document.hasFocus());
    await p.page.waitForTimeout(120);
    const set = (n, down) =>
      p.frame.evaluate(
        ([i, d]) => {
          window.testPad.buttons[i] = { value: +d, pressed: d, touched: d };
        },
        [n, down],
      );
    const frames = () =>
      p.frame.evaluate(
        () =>
          new Promise((resolve) =>
            requestAnimationFrame(() => requestAnimationFrame(() => resolve(true))),
          ),
      );
    const tap = async (n) => {
      await set(n, true);
      await frames();
      await set(n, false);
      await frames();
    };
    const focus = async (find, next = 13) => {
      for (let i = 0; i < 65; i++) {
        if (await p.frame.evaluate((selector) => document.activeElement.matches(selector), find))
          return;
        await tap(next);
      }
      throw new Error(
        'Controller focus missed ' +
          find +
          ' at ' +
          (await p.frame.evaluate(() => document.activeElement.outerHTML.slice(0, 220))),
      );
    };
    const pick = async (locator, next = 13) => {
      await locator.first().waitFor({ timeout: 25000 });
      for (let i = 0; i < 65; i++) {
        if (await locator.first().evaluate((el) => el === document.activeElement)) {
          await tap(0);
          return;
        }
        await tap(next);
      }
      throw new Error(
        'Controller could not select ' +
          locator +
          '; focus ' +
          (await p.frame.evaluate(() => document.activeElement.outerHTML.slice(0, 180))),
      );
    };
    const button = (name) => p.frame.getByRole('button', { name, exact: true });
    return { set, frames, tap, focus, pick, choose: (name) => pick(button(name)), button };
  }
  const h = await attach(host),
    g = await attach(guest);
  await g.choose('Settings');
  await g.focus('#alias-name');
  await g.tap(0);
  await g.pick(guest.frame.locator('.pad-editor [data-key="f"]'), 15);
  await g.pick(guest.frame.locator('.pad-editor button').filter({ hasText: /^Done$/ }), 14);
  await g.focus('#crouch-mode');
  await g.tap(15);
  check(
    'settings and callsign can be edited by controller',
    (await guest.frame.locator('#crouch-mode').inputValue()) === 'hold' &&
      (await guest.frame.locator('#alias-name').inputValue()).endsWith('f'),
  );
  await g.choose('Done');
  await h.choose('Controls');
  await host.frame.getByRole('heading', { name: 'Controller', exact: true }).waitFor();
  await h.tap(1);
  await h.choose('Create room');
  await h.choose('Open lobby');
  const code = (await host.frame.getByText(/^Room code:/).innerText()).slice('Room code: '.length);
  await g.choose('Browse rooms');
  await g.pick(guest.frame.locator('.room-item'));
  await guest.frame.getByText('Waiting for the host to start.').waitFor({ timeout: 50000 });
  await g.choose('Leave room');
  await host.frame.getByText(/1 \/ 8 players/).waitFor();
  check('guest can join from the room browser and leave using only the pad', true);
  await g.choose('Browse rooms');
  await g.choose('Enter room code');
  await g.focus('[aria-label="Room code"]');
  await g.tap(0);
  for (const char of code.replaceAll('-', ''))
    await g.pick(guest.frame.locator('.pad-editor [data-key="' + char + '"]'), 15);
  await g.pick(guest.frame.locator('.pad-editor button').filter({ hasText: /^Done$/ }), 15);
  check(
    'controller keyboard enters a complete invitation code',
    (await guest.frame.getByLabel('Room code').inputValue()) === code,
  );
  await g.choose('Join room');
  await guest.frame.getByText('Waiting for the host to start.').waitFor({ timeout: 50000 });
  // Advance only the regulation clock through fixed host simulation steps.
  await host.frame.evaluate(() => {
    const now = performance.now.bind(performance),
      interval = window.setInterval.bind(window);
    let simulated;
    Object.defineProperty(performance, 'now', { value: () => simulated ?? now() });
    window.setInterval = (fn, delay, ...args) => {
      if (delay !== 1000 / 60) return interval(fn, delay, ...args);
      const start = now();
      return interval(() => {
        simulated = start + (now() - start) * 6;
        try {
          fn(...args);
        } finally {
          simulated = undefined;
        }
      }, delay);
    };
  });
  await h.choose('Start match');
  for (const p of [guest, host])
    await p.frame.waitForFunction(
      () => document.querySelector('#scene').dataset.remote?.length > 0,
    );
  const scene = guest.frame.locator('#scene');
  const aim = await scene.getAttribute('data-aim'),
    pos = await scene.getAttribute('data-position');
  await guest.frame.evaluate(() => {
    window.testPad.axes = [0, -1, 0.8, 0];
  });
  await g.set(7, true);
  await guest.frame.waitForFunction(
    ([aim, pos]) => {
      const d = document.querySelector('#scene').dataset;
      return d.aim !== aim && d.position !== pos && Number(d.shots) > 0;
    },
    [aim, pos],
  );
  await g.set(7, false);
  await guest.frame.evaluate(() => {
    window.testPad.axes = [0, 0, 0, 0];
  });
  await g.set(1, true);
  await guest.frame.waitForFunction(
    () => document.querySelector('#scene').dataset.crouch === 'true',
  );
  await g.set(1, false);
  const gun = await guest.frame.locator('#gun-label').innerText();
  await g.tap(3);
  await guest.frame.waitForFunction(
    (old) => document.querySelector('#gun-label').textContent !== old,
    gun,
  );
  await g.set(8, true);
  await guest.frame.locator('#scoreboard:not([hidden])').waitFor();
  await g.set(8, false);
  check('guest moves, aims, fires, crouches, swaps weapons and reads live scores', true);
  await guest.frame.evaluate(() => {
    window.testPad.connected = false;
  });
  await guest.frame.getByRole('heading', { name: 'Match menu' }).waitFor();
  await g.set(0, true);
  await guest.frame.evaluate(() => {
    window.testPad.connected = true;
  });
  await g.frames();
  check(
    'a held button on reconnect leaves the match menu open',
    await g.button('Resume').isVisible(),
  );
  await g.set(0, false);
  await g.frames();
  await g.choose('Resume');
  await g.tap(9);
  await g.choose('Player settings');
  await g.tap(1);
  await guest.frame.getByRole('heading', { name: 'Match menu' }).waitFor();
  await g.tap(1);
  await guest.frame.locator('#dialog').waitFor({ state: 'hidden' });
  check('pause, change settings and resume in a live match', true);
  await host.frame
    .locator('#dialog')
    .getByText(/Up next/)
    .waitFor({ timeout: 150000 });
  await h.choose('Return to lobby');
  await host.frame.getByRole('button', { name: 'Start match' }).waitFor();
  await h.choose('Leave room');
  check('two controller players complete regulation and return to the lobby', true);
};