seriesoftubes/src/game/93-ui/59-build-standard.js
jvanvik d1e127da67 Server-run play, part 1: game prerequisites and shared contracts
Groundwork for running multiplayer games on the session server; nothing
of it is switched on yet, and the plain build is unchanged.

- A new network in two halves (beginState/beginShow), the coach split into
  tutAdvance/coachDom, toastPop split out of toast, bootNotes() for the
  once-per-load toasts, the five text actions take their text as an
  argument, and srvOn() with its two checks in the loop.
- Live state is what a reload makes of it (migrate() is a no-op on it):
  new POPs, ports, PNIs, customers, attacks, dark fiber and the intern's
  notes are written in their saved shape; a 365-day test proves it.
- pniAll and bstdApply check the quote the sheet showed (bstdApply by its
  plan, within 1% for the daily hardware drift; utilityKit too).
- assemble({mp}) leaves src/game/98-server-play/ and its CSS out of every
  page but a multiplayer build's, which also gets a SIM_ID build id.
- Contracts for the server, protocol and browser parts: the action tables
  and envelope check (scripts/lib/mp-sim-acts.js), event fixtures, a shape
  checker, a fake engine, and load({mp:true}) in the test harness.
- route-fuzz judges both pages with one migrate(), so reload repairs of
  the base no longer count as divergences.
2026-11-07 10:26:06 +01:00

40 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* The build standard sheet: every target as a list (two to a row on a phone), grouped POP / ports and peering / fiber;
what is below the standard and what bringing it up costs, priced without changing anything; one tap to do it now;
and the intern's order that keeps it there. A bottom sheet on phones, like the Ops sheet it sits next to. */
const BSTD_GRP=[['pop',N_('common.pops')],['port',N_('bstd.g_port')],['fiber',N_('bstd.g_fiber')]];
// Every value a target can take, in the order its list shows them; the current one is always on the list.
function bstdOpts(k){const L=BSTDK[k].v(),cur=bstd()[k];if(!L.includes(cur))L.push(cur);return L;}
function bstdVal(k,v){if(v===BSTDK[k].d&&k!=='rt')return tr('bstd.keep');
switch(k){case 'g':return RG[v].n+(rgOpen(v)?'':' '+tr('bstd.from_level',{lv:RG[v].lvl}));
case 'rt':return v>1?tr('bstd.at_least_n',{n:v}):tr('bstd.keep');
case 'site2':case 'gen':return tr('bstd.at_every_pop');
case 'lag':return tr('bstd.at_least_n',{n:v});
case 'split':return tr('bstd.both_buildings');
case 'ix':return tr('bstd.every_exchange');
case 'pni':return tr('bstd.in_n_cities',{n:v});
case 'sys':return tr('bstd.or_better',{x:DF_SYS[v].n});
case 'opt':return tr('bstd.fastest');
case 'wv':return tr('bstd.or_better',{x:LT[v].n});}
return String(v);}
const bstdShown=()=>!!$('modal')&&!$('modal').hidden&&!!$('modalCard').querySelector('[data-sheet="bstd"]');
// msg: why the sheet is shown again (the quote changed).
function bstdModal(msg){if(!S||pzOn())return;const D=bstd(),q=bstdQuote(false),hired=opsHired(),on=hired&&S.ops.on.std;
let h=`<div data-sheet="bstd" style="display:flex;align-items:center"><div><div class="eyebrow">${tr('ops.ops')}</div><h2 style="font-size:26px">${tr('bstd.title')}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div>
<p class="tagline">${tr('bstd.tagline')}</p>${typeof msg==='string'&&msg?`<p class="why">${esc(msg)}</p>`:''}`;
for(const [g,lab] of BSTD_GRP)h+=`<section><h3>${tr(lab)}</h3><div class="ops-p">${BSTD.filter(x=>x.grp===g).map(x=>opsSel(tr(x.l),'bstdSet',{k:x.k},bstdOpts(x.k),D[x.k],v=>bstdVal(x.k,v))).join('')}</div>
<p class="note">${g==='pop'?tr('bstd.new_pops_note'):g==='port'?tr('bstd.port_note'):tr('bstd.fiber_note_two')}</p></section>`;
// What is below it today, and what bringing it all up costs: a quote, nothing changes until the button. A fiber whose
// line system has to wait is below it too, but not on the bill.
const n={pop:q.pops,port:q.ports,fiber:q.links},w=q.held.length;
h+=`<section><h3>${tr('bstd.below')}</h3>${q.n||w?BSTD_GRP.map(([g,lab])=>`<div class="kv"><span>${tr(lab)}</span><b>${n[g]}</b></div>`).join('')
+`<div class="kv"><span>${tr('bstd.cost_now')}</span><b>${fmt$(q.cost)}</b></div><div class="kv"><span>${tr('bstd.cost_mo')}</span><b>${tr('common.price_mo',{price:opsMo$(q.mo)})}</b></div>`
+(w?`<p class="meta">${trn('bstd.held',w)}</p>`:'')
:`<p class="meta">${S.popStd?tr('bstd.all_up'):tr('bstd.none_set')}</p>`}</section>`;
// The intern keeps it there: the order's switch and budget, or a word on hiring one.
h+=`<section><h3>${tr('ops.o_std')}</h3>${hired?`<div class="ops-o${on?' on':''}"><div class="ops-h"><span class="ops-i" aria-hidden="true">${INTERNS[S.ops.intern].i}</span><div class="grow"><div class="nm">${esc(tr('bstd.intern_keeps',{name:opsName()}))}</div><div class="meta">${tr('ops.o_std_around_d')}</div></div>
<button class="b sm ${on?'green':'ghost'}" data-act="opsToggle" data-args='{"k":"std"}' aria-pressed="${on}" aria-label="${esc(tr('ops.o_std'))}">${on?tr('common.on'):tr('ops.paused')}</button></div>
${on?`<div class="ops-p">${opsSel(tr('ops.budget'),'opsCap',{k:'std'},opsCaps('std'),opsCap('std'),v=>opsCapName('std',v))}</div>`:''}</div>`
:`<p class="meta">${tr('bstd.hire_note')}</p><div class="btns">${btn(tr('ops.hire_an_intern'),'opsOpen',{},'ghost sm',!opsCanHire()||!rule('clock'))}</div>`}</section>`;
// The button carries the plan it shows and its total (bstdApply checks both again).
h+=`<div class="btns cta">${btn(q.n?tr('bstd.apply_now',{cost:fmt$(q.cost)}):w?tr('bstd.apply_wait'):tr('bstd.apply_nothing'),'bstdApply',{quote:bstdPlanKey(bstdPlan(false)),q:q.cost},'pink',!q.n)}</div>`;
openModal(h,'ops');}