Examples > text-adventures 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.split('\n').map(esc).join('
')}

`).join('\n'); const head = entry.status ? `

${esc(entry.status)}

\n` : ''; const cmd = entry.cmd ? `

> ${esc(entry.cmd)}

\n` : ''; return `${head}${cmd}${paras}${note ? `\n

${esc(note)}

` : ''}`; } 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', }] }; Next: 18 Companion server.js (10/13)