LINE1 10 20 30 40 50 60 70 80 90123import { bus } from './bus.js';4import { FOOD_NAMES } from './food.js';5import { myId } from './net.js';67const LOG_LINES = 4;8const WANT_LABEL = { pending: '', eating: ' (eating)', done: ' (done)' };910export function startHud(root) {11 const round = root.querySelector('#round');12 const guests = root.querySelector('#guests');13 const hand = root.querySelector('#hand');14 const log = root.querySelector('#log');15 const lines = [];1617 const pushLine = (text, kind = 'log') => {18 lines.push({ text, kind });19 while (lines.length > LOG_LINES) lines.shift();20 log.replaceChildren(21 ...lines.map((l) => {22 const el = document.createElement('div');23 el.className = l.kind;24 el.textContent = l.text;25 return el;26 }),27 );28 };2930 const renderState = (s) => {31 const mins = Math.floor(s.round.time_left / 60);32 const secs = String(Math.floor(s.round.time_left % 60)).padStart(2, '0');33 const status = {34 playing: `${mins}:${secs} left`,35 won: 'Everyone has eaten.',36 lost: 'The food went cold.',37 }[s.round.state];38 round.textContent = `Dinner ${s.round.number} · ${status} · ${s.round.served} served`;3940 guests.replaceChildren(41 ...s.guests.map((g) => {42 const row = document.createElement('div');43 row.className = 'guest';44 const wants = g.wants45 .map((w) => `${FOOD_NAMES[w.food]}${WANT_LABEL[w.state]}`)46 .join(', ');47 row.innerHTML = `<b></b><span></span>`;48 row.firstChild.textContent = g.name;49 row.lastChild.textContent = wants;50 return row;51 }),52 );5354 const me = s.players.find((p) => p.id === myId());55 hand.textContent = me?.hand ? `Holding: ${FOOD_NAMES[me.hand]}` : 'Hands free';56 };5758 bus.addEventListener('state', (e) => renderState(e.detail));59 bus.addEventListener('log', (e) => pushLine(e.detail.text));60 bus.addEventListener('toast', (e) => pushLine(e.detail, 'toast'));61 bus.addEventListener('lost', () => {62 pushLine('You were away too long. Coming back in…', 'toast');63 setTimeout(() => location.reload(), 1500);64 });65}