Split the game page into partials under src/, assembled into one index.html at build
site/index.html (900 KB of HTML, CSS and JS in one file) becomes src/: a shell (src/index.html), styles/ and game/, concatenated in path order by scripts/lib/page.js. The assembled page is byte-identical to the old file, so load time and in-game performance are unchanged. - scripts/build.js replaces build.sh (same env vars, same output) - npm run dev: a zero-dependency dev server that assembles on every request - tests assemble the page in memory; npm test runs every tests/*.test.js - perf-bench takes --base-ref to build a git ref's page - scripts/legacy/split-index-html.js is the splitter, kept for older branches
This commit is contained in:
parent
295e68cc46
commit
67a40942b4
113 changed files with 5584 additions and 5195 deletions
34
src/game/94-dashboard/30-customers.js
Normal file
34
src/game/94-dashboard/30-customers.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ---------- customers overview (#13, #14, #15) ---------- */
|
||||
const bizMo=b=>{const T=BIZ_T[b.type];return T.event?0:T.fiber?b.rate:b.bw*b.rate;};
|
||||
// Why a customer is unhappy, in the same terms the daily mood update uses.
|
||||
function bizWhy(b){const T=BIZ_T[b.type],out=[];if(T.event&&!eventLive(b))return out;
|
||||
const sf=bizSf(b);if(sf<0.95)out.push(T.fiber?tr('their fiber is down'):tr('getting only {p} of the bandwidth they pay for',{p:pct(sf)}));
|
||||
if(!(T.l2||T.fiber)&&R.reach<=0.99&&!scnRule('local'))out.push(tr('you cannot reach the whole internet ({p})',{p:pct(R.reach)}));
|
||||
if(b.type==='scrub'&&!hasScrub())out.push(tr('needs a scrubbing center'));
|
||||
{const q=b.type==='scrub'&&scrubFar(b.city);if(q)out.push(tr('attacks on {city} are hauled to {to} for scrubbing: +{ms} ms',{city:CITY[b.city].name,to:CITY[q.to].name,ms:Math.round(q.ms)}));}
|
||||
for(const k of b.reqs||[])if(REQS[k]&&!REQS[k].ok(b))out.push(typeof REQS[k].l==='function'?REQS[k].l(b):REQS[k].l);
|
||||
return out;}
|
||||
const moodCls=m=>m<30?'bad':m<60?'warn':'';
|
||||
const custStats=()=>{const bz=S.biz.filter(b=>!BIZ_T[b.type].event),mo=bz.reduce((a,b)=>a+bizMo(b),0);
|
||||
return {n:bz.length,unhappy:bz.filter(b=>b.mood<60).length,furious:bz.filter(b=>b.mood<30).length,avg:bz.length?(mo>0?bz.reduce((a,b)=>a+b.mood*bizMo(b),0)/mo:bz.reduce((a,b)=>a+b.mood,0)/bz.length):100,risk:bz.filter(b=>b.mood<60).reduce((a,b)=>a+bizMo(b),0)};};
|
||||
// Long lists show their first rows and grow on request: a thousand rows of buttons take the browser a long time to
|
||||
// lay out again every day, worst of all on a phone. Filters, sorting and totals still cover every row.
|
||||
const LIST_PAGE=100,listN=k=>(UI.listN&&UI.listN[k])||LIST_PAGE,listReset=k=>{if(UI.listN)delete UI.listN[k];};
|
||||
const listMore=(k,n,lab)=>n>listN(k)?`<div class="btns" style="margin-top:6px">${btn(lab(Math.min(LIST_PAGE,n-listN(k))),'listMore',{k},'ghost sm')}</div>`:'';
|
||||
function custSection(){const F=UI.kf||{};let h=`<div class="panel2" id="custSec" style="margin-top:12px"><h3>${tr('Customers')}</h3>`;
|
||||
if(!S.biz.length)return h+`<p class="empty">${tr('No customers yet. Offers show up in the Deals tab.')}</p></div>`;
|
||||
const st=custStats();
|
||||
h+=`<p class="note" style="margin-top:0">${tr('Everyone who pays you, happiest last. Below 60% they start to grumble, below 30% they are furious, and at 0% they cancel.')}</p>`;
|
||||
h+=`<div class="dgrid" style="margin:0 0 8px"><div class="tile"><div class="lbl">${tr('Happiness')}</div><div class="val" style="color:${st.avg<60?'var(--bad)':'inherit'}">${Math.round(st.avg)}%</div><div class="sub">${tr('weighted by what they pay')}</div></div><div class="tile"><div class="lbl">${tr('Unhappy')}</div><div class="val" style="color:${st.unhappy?'var(--bad)':'inherit'}">${st.unhappy}</div><div class="sub">${trn('{n} furious','{n} furious',st.furious)}</div></div><div class="tile"><div class="lbl">${tr('At risk')}</div><div class="val">${tr('{price}/mo',{price:fmt$(st.risk)})}</div><div class="sub">${tr('from unhappy customers')}</div></div></div>`;
|
||||
const cities=[...new Set(S.biz.map(b=>b.city))].sort((a,b)=>CITY[a].name.localeCompare(CITY[b].name));
|
||||
h+=`<div class="trsel" style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:6px"><div class="seg">${btn(tr('All ({n})',{n:S.biz.length}),'custF',{v:''},!F.f?'pink sm':'ghost sm')}${btn(tr('Unhappy ({n})',{n:S.biz.filter(b=>b.mood<60).length}),'custF',{v:'sad'},F.f==='sad'?'pink sm':'ghost sm')}</div><label>${tr('City')} <select data-chg="custCity"><option value="">${tr('All cities')}</option>${cities.map(c=>`<option value="${c}"${F.city===c?' selected':''}>${esc(CITY[c].name)}</option>`).join('')}</select></label></div>`;
|
||||
const rows=S.biz.filter(b=>(!F.f||b.mood<60)&&(!F.city||b.city===F.city||b.city2===F.city||(b.sites||[]).includes(F.city)));
|
||||
const sk=UI.custSort||'mood',dir=UI.custDir||1,val=b=>sk==='name'?b.name.toLowerCase():sk==='city'?CITY[b.city].name:sk==='mo'?bizMo(b):b.mood;
|
||||
rows.sort((a,b)=>{const A=val(a),B=val(b);return (A<B?-1:A>B?1:0)*dir||a.mood-b.mood;});
|
||||
if(!rows.length)return h+`<p class="empty">${F.f?tr('Nobody is unhappy. Enjoy it while it lasts.'):tr('No customers here.')}</p></div>`;
|
||||
const where=b=>b.sites?b.sites.map(c=>CITY[c].name).join(', '):b.city2?`${CITY[b.city].name} ⇄ ${CITY[b.city2].name}`:CITY[b.city].name;
|
||||
const trend=b=>b.pm===undefined||Math.abs(b.mood-b.pm)<0.05?'':b.mood>b.pm?' <span style="color:var(--eye)">▲</span>':' <span style="color:var(--bad)">▼</span>';
|
||||
const sorts=[['mood',tr('Happiness')],['mo',tr('Per month')],['name',tr('Name')],['city',tr('Where')]];
|
||||
h+=`<div class="seg" style="margin-bottom:4px">${sorts.map(([k,l])=>btn(l+(sk===k?(dir>0?' ▲':' ▼'):''),'custSort',{k},sk===k?'pink sm':'ghost sm')).join('')}</div>`;
|
||||
h+=rows.slice(0,listN('cust')).map(b=>{const why=bizWhy(b),grace=S.day-(b.since||0)<15;return `<div class="row"><div class="grow"><div class="nm">${esc(b.name)} <span class="meta">${esc(BIZ_T[b.type].l)}</span></div><div class="meta">${esc(where(b))} · ${BIZ_T[b.type].event?esc(bTerms(b)):tr('{price}/mo',{price:fmt$(bizMo(b))})}${grace?` · ${tr('provisioning, {n}d grace',{n:15-(S.day-(b.since||0))})}`:''}</div>${why.length?`<div class="why">${why.map(esc).join(' · ')}</div>`:''}<div class="bar ${moodCls(b.mood)}"><i style="width:${b.mood}%"></i></div><div class="meta">${tr('Happiness {p}%',{p:Math.round(b.mood)})}${trend(b)}</div></div>${btn(tr('Open'),'custGo',{id:b.id},'ghost sm')}</div>`;}).join('');
|
||||
return h+listMore('cust',rows.length,n=>trn('+{n} more customer','+{n} more customers',n))+`</div>`;}
|
||||
Loading…
Add table
Add a link
Reference in a new issue