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:
Frederic Jung 2026-10-27 10:05:56 +01:00
parent 295e68cc46
commit 67a40942b4
No known key found for this signature in database
113 changed files with 5584 additions and 5195 deletions

View file

@ -0,0 +1,12 @@
function scnTick(d){const sc=S.scn;if(!sc||sc.done||sc.failed)return;
if(sc.id==='weekly'){if(d>=sc.days){sc.done=d;const score=Math.round(S.stats.peak||0);sc.score=score;let best=null;try{const wk=JSON.parse(localStorage.getItem('sot-weekly')||'{}');best=wk[sc.key];if(!best||score>best){wk[sc.key]=score;localStorage.setItem('sot-weekly',JSON.stringify(wk));}}catch(e){}
const h=scnHof();h.weekly=h.weekly||{d:new Date().toISOString().slice(0,10)};try{localStorage.setItem('sot-scn',JSON.stringify(h));}catch(e){}
openModal(`<div class="eyebrow">${tr('Weekly challenge {key}',{key:esc(sc.key)})}</div><h2 style="font-size:30px">${tr('Your score: {score}',{score:fmtG(score)})}</h2><p class="tagline">${best&&best>score?tr('Peak traffic served in one year. Your best this week is {best}.',{best:fmtG(best)}):best?tr('Peak traffic served in one year. A new personal best for this week!.'):tr('Peak traffic served in one year.')}</p><div class="btns">${btn(tr('Share my result'),'share',{},'pink big')}${btn(tr('Keep playing'),'closeModal',{},'ghost big')}</div>`);track('weekly_done');}return;}
const def=SCN.find(x=>x.id===sc.id);if(!def)return;let ok=false;try{ok=def.ok();}catch(e){}
if(ok){sc.done=d;const h=scnHof();if(!h[sc.id]||h[sc.id].days>d)h[sc.id]={d:new Date().toISOString().slice(0,10),days:d};try{localStorage.setItem('sot-scn',JSON.stringify(h));}catch(e){}track('scenario_'+sc.id);
openModal(`<div class="eyebrow">${tr('Scenario complete')}</div><h2 style="font-size:30px">${tr('{name}: done in {d} days',{name:esc(def.n),d})}</h2><p class="tagline">${esc(def.goal)}. ${d<def.days/2?tr('With time to spare.'):tr('Just in time.')}</p><div class="btns">${btn(tr('Share my result'),'share',{},'pink big')}${btn(tr('Keep playing'),'closeModal',{},'ghost big')}${btn(tr('More scenarios'),'scenarios',{},'ghost')}</div>`);sfx('coin');}
else if(d>=def.days){sc.failed=d;openModal(`<div class="eyebrow">${tr('Scenario over')}</div><h2 style="font-size:30px">${tr("Time's up")}</h2><p class="tagline">${tr('{goal} was not reached in {d} days. Keep playing this network as free play, or try again.',{goal:esc(def.goal),d:def.days})}</p><div class="btns">${btn(tr('Try again'),'startScn',{id:def.id},'pink big')}${btn(tr('Keep playing'),'closeModal',{},'ghost big')}</div>`);}}
function scenarioModal(){const wk=weekly(),h=scnHof();let best=null;try{best=JSON.parse(localStorage.getItem('sot-weekly')||'{}')[wk.key];}catch(e){}
openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">${tr('Scenarios')}</div><h2 style="font-size:28px">${tr('Pick a challenge')}</h2></div><button class="x" data-act="${UI.started?'closeModal':'helpClose'}" aria-label="${tr('Close')}">×</button></div>
<div class="scn wk"><div class="grow"><div class="nm">${tr('Weekly challenge {key}',{key:esc(wk.key)})}</div><div class="meta">${tr('Start in {city} · {mods} · one year, score = peak traffic. The same world for everyone this week.',{city:esc(CITY[wk.city].name),mods:wk.mods.map(m=>esc(m.n)).join(' · ')})}${best?' '+tr('Your best: {best}.',{best:fmtG(best)}):''}</div></div>${btn(tr('Play'),'startWeekly',{},'pink')}</div>
${SCN.map(x=>`<div class="scn"><div class="grow"><div class="nm">${esc(x.n)} ${h[x.id]?`<span class="tag open">${tr('done in {d} days',{d:h[x.id].days})}</span>`:''}</div><div class="meta">${esc(x.d)}</div><div class="meta">${tr('<b>Goal:</b> {goal} · <b>Time:</b> {d} days · start in {city}',{goal:esc(x.goal),d:x.days,city:esc(CITY[x.city].name)})}</div></div>${btn(tr('Play'),'startScn',{id:x.id},'')}</div>`).join('')}`);}