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
30
src/game/94-dashboard/70-bank.js
Normal file
30
src/game/94-dashboard/70-bank.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
function loanSummary(o){return o.model==='transit'?tr('You pay {pct} of your transit bill until {price} is repaid.',{pct:pct(o.cut||0.3),price:fmt$(o.owe||o.amount)}):o.model==='balloon'?tr('Nothing to pay for {n} months. Then everything.',{n:o.term}):tr('{pay}/mo for {n} months.',{pay:fmt$(o.pay),n:o.term})+(o.share?' '+tr('Plus {pct} of your revenue until it is repaid.',{pct:pct(o.share)}):'');}
|
||||
function loanLine(l){const sh=l.share?' · '+tr('plus {pct} of revenue',{pct:pct(l.share)}):'',fee=loanFees(l)?' · '+tr('{price}/mo in extras',{price:fmt$(loanFees(l))}):'';
|
||||
if(l.model==='transit')return tr('{pct} of your transit bill · {n} months left · the rest is due at the end',{pct:pct(l.cut||0.3),n:l.left})+sh+fee;
|
||||
if(l.model==='balloon')return tr('Nothing to pay until the end · {n} months left · growing at {apr}% a year',{n:l.left,apr:(l.apr*100).toFixed(1)})+sh+fee;
|
||||
return tr('{pay}/mo · {n} months left · {apr}% APR',{pay:fmt$(l.pay),n:l.left,apr:(l.apr*100).toFixed(1)})+(l.model==='storm'?' · '+tr('+2% per open incident'):l.model==='astro'?' · '+tr('rate set by the stars each month'):'')+sh+fee;}
|
||||
function renderBank(){
|
||||
if(!S||$('bankBox').hidden)return;const rt=rating(),net=R.revMo-R.costMo;
|
||||
const terms=(o)=>{const B=BANKS[o.bank],sh=o.share&&!B.equity?`<span class="tag selective">${tr('plus {pct} of revenue until repaid',{pct:pct(o.share)})}</span>`:'';
|
||||
if(o.model==='transit')return `<span class="tag st on">${tr('{pct} of your transit bill',{pct:pct(o.cut||0.3)})}</span><span class="tag st">${tr('{price} to repay',{price:fmt$(o.owe||o.amount)})}</span><span class="tag st">${tr('{n} months',{n:o.term})}</span><span class="tag selective">${tr('the rest is due at the end')}</span>${sh}`;
|
||||
if(o.model==='balloon')return `<span class="tag st on">${tr('Nothing to pay until the end')}</span><span class="tag st">${tr('{apr}% APR',{apr:(o.apr*100).toFixed(1)})}</span><span class="tag st">${tr('{n} months',{n:o.term})}</span><span class="tag selective">${tr('then about {price} at once',{price:fmt$(o.amount*Math.pow(1+o.apr/12,o.term))})}</span>${sh}`;
|
||||
const extra=o.model==='storm'?`<span class="tag selective">${tr('+2% per open incident')}</span>`:o.model==='astro'?`<span class="tag selective">${tr('rate set by the stars each month')}</span>`:'';
|
||||
return (B.equity?`<span class="tag st on">${tr('No repayments')}</span><span class="tag st">${tr('{pct} of revenue, forever',{pct:pct(o.share)})}</span><span class="tag st">${tr('Buy-out {price}',{price:fmt$(o.amount*3)})}</span>`:`<span class="tag st on">${tr('{apr}% APR',{apr:(o.apr*100).toFixed(1)})}</span><span class="tag st">${tr('{n} months',{n:o.term})}</span><span class="tag st">${tr('{price}/mo',{price:fmt$(o.pay)})}</span>${B.crypto?'<span class="tag selective">'+tr('Paid in TubeCoin')+'</span>':''}`)+extra+sh;};
|
||||
const covList=(l)=>l.covs.length?l.covs.map(c=>{const ok=COVS[c].ok(l);return `<div class="meta"><b style="color:${ok?'var(--eye)':'var(--bad)'}">${ok?'✓':'✗'}</b> ${esc(covLabel(c))}</div>`;}).join(''):'<div class="meta">'+tr('No conditions. That is the scary part.')+'</div>';
|
||||
let h=`<div style="display:flex;align-items:center;gap:12px"><div><div class="eyebrow">AS${S.asn} · ${esc(S.name)}</div><h2 style="font-size:28px">${tr('Bank')}</h2></div><button class="x" data-act="bankClose" aria-label="${tr('Close')}">×</button></div>
|
||||
<div class="dgrid"><div class="tile"><div class="lbl">${tr('Cash')}</div><div class="val" style="color:${S.cash<0?'var(--bad)':'inherit'}">${fmt$(S.cash)}</div><div class="sub">${S.cash<0?tr('Bankrupt at −$100k'):tr('in the vault')}</div></div>
|
||||
<div class="tile"><div class="lbl">${tr('Monthly P&L')}</div><div class="val" style="color:${net>=0?'var(--eye)':'var(--bad)'}">${net>=0?'+':''}${fmt$(net)}</div><div class="sub">${tr('after loan payments')}</div></div>
|
||||
<div class="tile"><div class="lbl">${tr('Credit rating')}</div><div class="val">${rt}</div><div class="sub">${rIdx(rt)>=5?tr('Bankers return your calls'):rIdx(rt)>=3?tr('Bankers return your emails'):tr('Bankers pretend to be out')}</div></div>
|
||||
<div class="tile"><div class="lbl">${tr('Debt')}</div><div class="val">${fmt$(S.loans.reduce((a,l)=>a+(BANKS[l.bank].equity?0:l.bal),0))}</div><div class="sub">${trn('{n} loan','{n} loans',S.loans.length)}</div></div></div>`;
|
||||
h+=`<h3 style="font-size:18px;margin-top:6px">${tr('Offers')}</h3>`;
|
||||
if(!S.loanOffers.length)h+=`<p class="empty">${tr('No offers right now. Banks get in touch now and then, and much faster when you are in trouble. A better credit rating brings better banks.')}</p>`;
|
||||
for(const o of S.loanOffers){const B=BANKS[o.bank];h+=`<div class="loan"><span class="logo" style="--c:${B.col}">${initials(B)}</span><div class="grow"><div class="nm">${tr('{bank} offers <b>{amount}</b>',{bank:esc(B.name),amount:fmt$(o.amount)})}</div><div class="meta">${esc(B.blurb)} · ${tr('offer ends in {n}d',{n:o.exp-S.day})}</div><div class="terms">${terms(o)}</div>${covList({covs:o.covs,start:S.day,base:{sub:S.links.filter(x=>x.sub).length}})}<div class="btns" style="margin-top:6px">${btn(tr('Take the money'),'takeLoan',{id:o.id},'pink')}${btn(tr('No thanks'),'declineLoan',{id:o.id},'ghost sm')}</div></div></div>`;}
|
||||
h+=`<h3 style="font-size:18px;margin-top:14px">${tr('Your loans')}</h3>`;
|
||||
if(!S.loans.length)h+=`<p class="empty">${tr('Debt-free. Your accountant is suspicious.')}</p>`;
|
||||
for(const l of S.loans){const B=BANKS[l.bank];const cost=repayCost(l,B);
|
||||
h+=`<div class="loan"><span class="logo" style="--c:${B.col}">${initials(B)}</span><div class="grow"><div class="nm">${esc(B.name)} · ${fmt$(l.amount)}</div>
|
||||
${B.equity?`<div class="meta">${tr('Taking {pct} of your revenue every month.',{pct:pct(l.share)})}</div>`:`<div class="kv"><span>${tr('Still owed')}</span><b>${fmt$(l.bal)}</b></div><div class="bar me"><i style="width:${Math.min(100,(1-l.bal/l.amount)*100)}%"></i></div><div class="meta">${loanLine(l)}</div>`}
|
||||
${covList(l)}${l.breach>=1?`<div class="why">${trn('Condition broken for {n} day.','Condition broken for {n} days.',l.breach)} ${l.breach<10?tr('Penalty in {n} days.',{n:10-l.breach}):tr('Penalties are running.')}</div>`:''}
|
||||
<div class="btns" style="margin-top:6px">${btn(UI.confirm===l.id?tr('Really pay {price}?',{price:fmt$(cost)}):B.equity?tr('Buy them out <small>{price}</small>',{price:fmt$(cost)}):tr('Repay early <small>{price} incl. 2% fee</small>',{price:fmt$(cost)}),'repayLoan',{id:l.id},UI.confirm===l.id?'red sm':'sm',S.cash<cost)}</div></div></div>`;}
|
||||
if(h!==UI._bh){UI._bh=h;$('bankCard').innerHTML=h;}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue