17 Companion server.js (9/13)

  if (state.quit) {
    cmdRow('Start over', '#restart');
  } else if (state.waiting === 'key') {
    cmdRow('Continue (press Enter)', '#key');
    for (const k of ['y', 'n', 'q']) cmdRow(`Press "${k}"`, k);
  } else {
    const { exits, objects } = survey(game, state);
    const dirs = exits.length ? exits : DIRECTIONS.slice(0, 4);
    for (const d of dirs) cmdRow(`> ${d}`, d);
    cmdRow('> look', 'look');
    cmdRow('> inventory', 'inventory');
    for (const o of objects) cmdRow(`> examine ${o}`, `examine ${o}`);
    cmdRow('> wait', 'wait');
    cmdRow('> again', 'again');
    cmdRow('> undo', 'undo');
    if (!exits.length) for (const d of DIRECTIONS.slice(4)) cmdRow(`> ${d}`, d);
    cmdRow('Start over', '#restart');
  }
  return { rows };
}

function entryHtml(game, entry, note) {
  let text = entry.output || '(no text)';
  if (text.length > DETAILS_MAX) text = '...' + text.slice(-DETAILS_MAX);
  const paras = text.split(/\n{2,}/).map((p) => `<p>${p.split('\n').map(esc).join('<br/>')}</p>`).join('\n');
  const head = entry.status ? `<p><i>${esc(entry.status)}</i></p>\n` : '';
  const cmd = entry.cmd ? `<p><b>&gt; ${esc(entry.cmd)}</b></p>\n` : '';
  return `<html><body>${head}${cmd}${paras}${note ? `\n<p><i>${esc(note)}</i></p>` : ''}</body></html>`;
}

const NOT_SET_UP = { rows: [{
  title: 'Not set up yet',
  sub: 'Open the Plugins page in the reader\'s web UI, enter this server\'s address and press Save.',
  id: 'setup',
}] };
‹ PreviousReader file (.txt)Next ›