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
22
src/game/10-catalog/40-ports.js
Normal file
22
src/game/10-catalog/40-ports.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* Ports are finite. Every transit, IX, PNI and cache port, every wave and every fibre channel
|
||||
takes a router port. 10G ports ride a breakout cable, four to a port. */
|
||||
const PORT_SLOT=i=>i===0?0.25:1;
|
||||
function portsUsed(c){let u=0;
|
||||
for(const l of S.links){if(l.a!==c&&l.b!==c||l.kind==='vxc')continue;u+=l.kind==='df'?(l.ch||[]).length:1;}
|
||||
for(const t of S.transit)if(t.city===c)u+=PORT_SLOT(t.tier)*(t.n||1);
|
||||
for(const x of S.pni)if(x.city===c)u+=PORT_SLOT(x.tier)*(x.n||1);
|
||||
for(const x of ixIdsIn(c))if(S.ixp[x]!==undefined&&!S.myIx[x])u+=PORT_SLOT(S.ixp[x])*((S.ixn||{})[x]||1);
|
||||
if(S.myIx[c])u+=1;
|
||||
u+=S.caches.filter(x=>x.city===c).length+(S.nni||[]).filter(x=>x.city===c).length;
|
||||
return u;}
|
||||
function portsMax(c,g,rt){const p=S.pops[c];if(!p)return 0;return RG[g===undefined?(p.rgen||0):g].ports*(rt||p.routers||1);}
|
||||
function portGate(c,add){if(!S.pops[c]||add<=0)return true;const u=portsUsed(c),m=portsMax(c);if(u+add<=m+1e-9)return true;
|
||||
toast(tr('<b>No free router ports in {city}.</b><br>{u} of {m} in use. Add a router, or swap to a model with more ports (Infra tab).',{city:esc(CITY[c].name),u:fmtPorts(u),m}),'bad');sfx('err');return false;}
|
||||
// Nothing depends on this POP yet: no broadband, nothing plugged in, no customer. Work here bothers nobody (#105).
|
||||
const popIdle=c=>{const p=S.pops[c];return !!p&&!p.bb&&portsUsed(c)===0&&!S.biz.some(b=>b.city===c||b.city2===c||(b.sites||[]).includes(c));};
|
||||
const fmtPorts=u=>Number.isInteger(u)?String(u):u.toFixed(2).replace(/0+$/,'');
|
||||
function modelFits(c,g){const G=RG[g],p=S.pops[c];if(!p)return '';
|
||||
if(S.links.some(l=>(l.a===c||l.b===c)&&l.kind==='wave'&&l.tier>G.maxLT))return tr('A wave here is faster than {pn}.',{pn:G.pn});
|
||||
if([...S.transit,...S.pni].some(t=>t.city===c&&t.tier>G.maxP)||ixIdsIn(c).some(x=>S.ixp[x]!==undefined&&!S.myIx[x]&&S.ixp[x]>G.maxP))return tr('A port here is bigger than {pn}.',{pn:G.pn});
|
||||
if(S.links.some(l=>(l.a===c||l.b===c)&&l.kind==='df'&&(l.ch||[]).some(o=>OPT[o]&&OPT[o].rg>G.cls)))return tr('A fibre here uses optics this model cannot take.');
|
||||
if(portsUsed(c)>portsMax(c,g))return tr('You use {u} ports here and {r} × {model} only has {max}.',{u:fmtPorts(portsUsed(c)),r:p.routers||1,model:G.n,max:portsMax(c,g)});return '';}
|
||||
Loading…
Add table
Add a link
Reference in a new issue