From 29a5859354789a48825a67bda0eb692f989922f9 Mon Sep 17 00:00:00 2001 From: Dennis Dryden Date: Thu, 29 Oct 2026 16:21:23 +0000 Subject: [PATCH 1/4] Inspecting a link moves the map to it Inspect on a congested or busy link (NOC list, dashboard, link toasts and log entries) now frames the whole drawn line in the part of the map the panel leaves free: left of the side panel, above a phone's bottom sheet. --- CHANGELOG.md | 1 + src/game/90-actions/10-interface.js | 4 +- src/game/90-actions/90-action-helpers.js | 10 +++++ tests/focus-link.test.js | 51 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 tests/focus-link.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d94892..7b33e4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project are documented here. The project follows - Waves between Philippine islands now cost more than waves out of the country: Manila to Cebu costs about twice Manila to Hong Kong. - Manila, Cebu and Davao have more people online, in line with their real populations. - Cable names on the map no longer pile on top of each other when you zoom in. Where short cables crowd together, a name that would cover another is left out, and selecting a city shows the names of all its cables. +- Inspecting a congested or busy link now moves the map to it, zoomed so the whole line fits beside the open panel. ## [2.2.0] — 2026-10-31 diff --git a/src/game/90-actions/10-interface.js b/src/game/90-actions/10-interface.js index 696ad90..e1ed9bc 100644 --- a/src/game/90-actions/10-interface.js +++ b/src/game/90-actions/10-interface.js @@ -20,7 +20,7 @@ const ACT={ if(UI.confirm!==id){UI.confirm=id;renderBank();return;}UI.confirm=null;if(!spend(cost)){renderBank();return;}S.loans=S.loans.filter(x=>x!==l);track('loan_repaid'); toast(B.equity?tr('interface.you_bought_out_bank_they_flew',{bank:esc(B.name)}):tr('interface.loan_from_bank_repaid_early',{bank:esc(B.name)}),'good');after();renderBank();}, leaseSwap:({a,b,src})=>{if(!S.pops[a]||!S.pops[b]||a===b)return;$('dash').hidden=true;UI.lmode='df';UI.dfSrc=['lease','build','cable'].includes(src)?src:isSub(a,b)?'cable':'build';UI.dfSys=lvl()>=3?'roadm':'lite';openLinkModal(a,b);}, - dashLink:({id})=>{$('dash').hidden=true;selectLink(id);}, + dashLink:({id})=>{$('dash').hidden=true;selectLink(id);focusLink(id);}, animSet:({v})=>{if(!['auto','on','off'].includes(v))return;UI.anim=v;try{localStorage.setItem('sot-anim',v);}catch(e){}applyAnim();refreshSettings();}, soundSet:({v})=>{UI.muted=v==='off';try{localStorage.setItem('sot-mute',UI.muted?'1':'0');}catch(e){}renderHUD();refreshSettings();}, langSet:({v})=>{if(!Object.hasOwn(LANGS,v)||v===LANG)return;try{localStorage.setItem('sot-lang',v);}catch(e){}save(true);location.reload();}, @@ -48,5 +48,5 @@ const ACT={ findOpen:()=>findOpen(), findGo:({city})=>{if(!isCity(city))return;closeModal();$('dash').hidden=true;ACT.focusCity({city});}, focusCity:({city})=>{selectCity(city);const C=CITY[city];cam.x=C.x;cam.y=C.y;cam.z=Math.max(cam.z,1.2);if(innerWidth<760)UI.leftOpen=false;renderLeft();}, - selLink:({id})=>selectLink(id), + selLink:({id})=>{selectLink(id);focusLink(id);}, }; diff --git a/src/game/90-actions/90-action-helpers.js b/src/game/90-actions/90-action-helpers.js index 4571f3d..96f1222 100644 --- a/src/game/90-actions/90-action-helpers.js +++ b/src/game/90-actions/90-action-helpers.js @@ -27,5 +27,15 @@ function bbCost(c){return 15000+CITY[c].P*20;} function after(){if(pzOn()){pzAfter();return;}if(S)purgeInc();compute();checkGoals();renderAll();if(S&&!$('dash').hidden)renderDash();save();} const isTablet=()=>innerWidth>760&&innerWidth<=1200; function selectLink(id){UI.sel={type:'link',id};UI.confirm=null;if(isTablet()||isPhone())UI.leftOpen=false;$('panel').classList.remove('full');renderPanel();renderLeft();} +// Frame the whole drawn line (cables bend far from the straight one) in the part of the map the panel leaves free: +// above a phone's bottom sheet, left of the side panel. Long links zoom out to fit; short ones zoom in like a city. +// A puzzle keeps its own framing beside the puzzle card (pzCam). +function focusLink(id){if(pzOn())return;const l=S.links.find(x=>x.id===id);if(!l||!CITY[l.a]||!CITY[l.b])return;const pts=linkGeom(l).pts; + let x0=Infinity,x1=-Infinity,y0=Infinity,y1=-Infinity;for(const [x,y] of pts){if(xx1)x1=x;if(yy1)y1=y;} + const P=$('panel'),r=P&&!P.hidden&&P.getBoundingClientRect();let fl=0,fr=CW,ft=70,fb=CH; + if(r&&r.width>0){if(r.width>CW*0.6)fb=Math.min(fb,r.top);else fr=Math.min(fr,r.left);} + // Phones leave a thin strip above the sheet: a fixed margin would eat most of it. + const m=(a,b)=>Math.max(40,b-a-Math.min(100,(b-a)*0.3)),fw=m(fl,fr),fh=m(ft,fb),z=clamp(Math.min(fw/Math.max(1,x1-x0),fh/Math.max(1,y1-y0),Math.max(cam.z,1.2)),ZMIN,ZMAX); + cam.z=z;cam.x=(x0+x1)/2-((fl+fr)/2-CW/2)/z;cam.y=(y0+y1)/2-((ft+fb)/2-CH/2)/z;wrapCam();} function selectCity(c){UI.sel={type:'city',id:c};UI.confirm=null;if(isTablet()||isPhone())UI.leftOpen=false;const P=$('panel');if(P)P.classList.remove('full');if(!S.pops[c])UI.tab='cust';renderPanel();} diff --git a/tests/focus-link.test.js b/tests/focus-link.test.js new file mode 100644 index 0000000..758a886 --- /dev/null +++ b/tests/focus-link.test.js @@ -0,0 +1,51 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +const start = "ACT.start({});S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'})"; +// Where a world point lands on screen, in whichever wrapped copy of the map is nearest the middle. +const onScreen = (ev, x, y) => JSON.parse(ev(`JSON.stringify([-1,0,1].map(k=>toS(${x},${y},k)).sort((p,q)=>Math.abs(p[0]-CW/2)-Math.abs(q[0]-CW/2))[0])`)); +const ends = (ev, id) => JSON.parse(ev(`JSON.stringify((()=>{const l=S.links.find(x=>x.id==='${id}');return [CITY[l.a],CITY[l.b]].map(c=>[c.x,c.y]);})())`)); +const inBox = (p, b, why) => assert.ok(p[0] >= b[0] && p[0] <= b[2] && p[1] >= b[1] && p[1] <= b[3], `${why}: ${p} not in ${b}`); + +test('Inspect on a congested link moves the map to that link', () => { + const { ev, errors, dom } = load(); + ev(start); + ev("S.links.push({id:'hot',a:'fra',b:'ams',kind:'wave',tier:0,km:400,mo:100,cut:0});R.load.hot=capOf(S.links.find(l=>l.id==='hot'))*0.95"); + ev("const C=CITY.syd;cam.x=C.x;cam.y=C.y;cam.z=0.8;UI.left='noc';UI.leftOpen=true;renderLeft()"); + ev("document.querySelector('#leftBody [data-act=selLink][data-args*=hot]').click()"); + assert.equal(ev('UI.sel.id'), 'hot'); + assert.ok(ev('cam.z') >= 1.2, 'a short link zooms in like a city does'); + const box = [0, 0, ev('CW'), ev('CH')]; + for (const [x, y] of ends(ev, 'hot')) inBox(onScreen(ev, x, y), box, 'both cities are on screen'); + assert.deepEqual(errors, []); + dom.window.close(); +}); + +test('a long link zooms out to fit, and stays clear of a bottom sheet', () => { + const { ev, errors, dom } = load(); + ev(start); + ev("S.links.push({id:'far',a:'fra',b:'sin',kind:'wave',tier:0,km:10000,mo:100,cut:0})"); + // jsdom lays nothing out, so stand in for a phone's bottom sheet covering the lower 60% of the map. + ev("$('panel').getBoundingClientRect=()=>({left:0,top:CH*0.4,width:CW,height:CH*0.6,right:CW,bottom:CH});cam.z=3"); + ev("ACT.selLink({id:'far'})"); + assert.ok(ev('cam.z') < 1.2, 'zoomed out for a long link'); + const box = [0, 0, ev('CW'), ev('CH*0.4')]; + for (const [x, y] of ends(ev, 'far')) inBox(onScreen(ev, x, y), box, 'both cities are above the sheet'); + // The drawn line, not just its ends, fits. + for (const [x, y] of JSON.parse(ev("JSON.stringify(linkGeom(S.links.find(l=>l.id==='far')).pts)"))) inBox(onScreen(ev, x, y), box, 'the whole line is above the sheet'); + assert.deepEqual(errors, []); + dom.window.close(); +}); + +test('a puzzle keeps its own framing when a link is opened', () => { + const { ev, errors, dom } = load(); + ev("ACT.pzStart({id:'hello'})"); + ev("S.links.push({id:'pz',a:'nyc',b:'lon',kind:'wave',tier:0,km:5600,mo:100,cut:0})"); + const before = ev('JSON.stringify(cam)'); + ev("ACT.selLink({id:'pz'})"); + assert.equal(ev('UI.sel.id'), 'pz'); + assert.equal(ev('JSON.stringify(cam)'), before, 'the camera stays on the whole puzzle'); + assert.deepEqual(errors, []); + dom.window.close(); +}); From f0d0675bad819120b5aca5435532c7de91925597 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Sat, 31 Oct 2026 15:57:46 +0100 Subject: [PATCH 2/4] Free caches scale with demand: more boxes once one per site is not enough (closes #248) --- CHANGELOG.md | 1 + src/game/70-rules/95-utilities.js | 10 +++++++--- tests/utilities-caches.test.js | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d94892..05c2e6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- The intern's Accept free caches order, and the Request caches button, now add more cache boxes as demand to a network outgrows the ones you have (#248). Before, they stopped at one box per site. - Manila gets real exchanges: GotchaFIX Manila, the free community Bayanihan-IX and In-Vitro-IX, run by PLDTea Time. Diverge, Smarty Pants, Ditto and RISE & Shine join as Philippine networks, and PLDTea Time and Globe-Trotter Telecom now sell transit. - Cebu joins the map on its own island, with GotchaFIX Cebu and two domestic cables from Manila: the Pan de Sal Cable Network and the Philippines Long Distance Relationship. PLDTea Time, Globe-Trotter Telecom, Diverge and RISE & Shine reach Cebu, and typhoons can hit it too. - Davao joins the map on Mindanao, with GotchaFIX Davao. Bi-Frosted and SEA-US Later now land in Davao, as the real cables do, instead of Manila; a link you already run on their old Manila landings keeps working as a plain subsea link. Three domestic cables reach Davao from Cebu: the Pan de Sal Cable Network, the Philippines Long Distance Relationship and the new Diverge VisMin Express. RISE & Shine peers at GotchaFIX Davao. The Pan de Sal Cable Network also runs straight from Manila to Davao. diff --git a/src/game/70-rules/95-utilities.js b/src/game/70-rules/95-utilities.js index 5d759b7..65385b3 100644 --- a/src/game/70-rules/95-utilities.js +++ b/src/game/70-rules/95-utilities.js @@ -10,9 +10,13 @@ function utilityCacheMoves(city){if(!S||!S.pops[city])return [];const groups=new const from=diff>0?'a':'b',to=from==='a'?'b':'a';let left=Math.floor(Math.abs(diff)/2); for(const g of groups.values())if(left&&g[from].length>g[to].length){move(g,from,1);left--;} return moves;} -function utilityCaches(city){const p=S&&S.pops[city];if(!p)return null;const sites=p.site2?['a','b']:['a'],add=[],have=new Set(); - for(const c of S.caches)if(c.city===city)have.add(c.net+'@'+(c.site==='b'?'b':'a')); - for(const n of NETS)if(n.cache&&(R.demTo[n.id]||0)>=n.cache.min)for(const site of sites)if(!have.has(n.id+'@'+site))add.push({net:n.id,site}); +// One box per site first; then more boxes while this city's demand to the network outgrows them (100G each, #248). +function utilityCaches(city){const p=S&&S.pops[city];if(!p)return null;const sites=p.site2?['a','b']:['a'],add=[],have={}; + for(const c of S.caches)if(c.city===city){const k=c.net+'@'+(c.site==='b'?'b':'a');have[k]=(have[k]||0)+1;} + for(const n of NETS)if(n.cache&&(R.demTo[n.id]||0)>=n.cache.min){const box=sites.map(st=>have[n.id+'@'+st]||0); + sites.forEach((site,i)=>{if(!box[i]){add.push({net:n.id,site});box[i]=1;}}); + const need=Math.ceil(((R.cityDem&&R.cityDem[city])||0)*(NSH[n.id]||0)/CACHE_CAP-1e-9); + for(let t=box.reduce((a,b)=>a+b,0);tc.net+'@'+c.site).join(','),mo:add.length*CACHE_MO,free:Math.max(0,portsMax(city)-portsUsed(city))};} function utilityKit(city){const p=S&&S.pops[city];if(!p)return null; const gen=!p.gen,site=!p.site2,router=(p.routers||1)<2,g=p.rgen||0; diff --git a/tests/utilities-caches.test.js b/tests/utilities-caches.test.js index 1543587..f81aa65 100644 --- a/tests/utilities-caches.test.js +++ b/tests/utilities-caches.test.js @@ -118,3 +118,17 @@ test('balanced caches keep serving when either site fails', t => { } assert.deepEqual(errors, []); }); + +test('more boxes while demand outgrows them, balanced across sites (#248)', t => { + const { ev, errors } = setup(t); + ev("Object.assign(S.pops.fra,{site2:true,routers:2});S.caches=[{id:'a1',city:'fra',net:'cfl',site:'a'},{id:'b1',city:'fra',net:'cfl',site:'b'}];compute();R.demTo={cfl:NET.cfl.cache.min};R.cityDem.fra=450/NSH.cfl"); + const add = JSON.parse(ev("JSON.stringify(utilityCaches('fra').add)")); + assert.deepEqual(add.map(x => x.net + '@' + x.site), ['cfl@a', 'cfl@b', 'cfl@a'], '450G needs five 100G boxes: three more, spread over both sites'); + ev("R.cityDem.fra=150/NSH.cfl"); + assert.equal(ev("utilityCaches('fra').add.length"), 0, 'two boxes already carry 150G'); + // Requesting them adds just what is missing. + ev("R.cityDem.fra=350/NSH.cfl"); + ev("ACT.utilityCaches({city:'fra',quote:utilityCaches('fra').key})"); + assert.equal(ev("S.caches.filter(c=>c.net==='cfl').length"), 4); + assert.deepEqual(errors, []); +}); From c3b253925d7bc217b8a7cc6beaac82588381d8e4 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Sat, 31 Oct 2026 16:31:33 +0100 Subject: [PATCH 3/4] City panel opens again with the transit order on Already connected (closes #249) --- CHANGELOG.md | 1 + src/game/60-features/95-standing-orders.js | 3 ++- tests/standing-orders.test.js | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05c2e6b..61521c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Clicking a city without a POP works again while the intern's transit order is set to Already connected (#249). Before, the city panel failed to open and the map stuck to the mouse. - The intern's Accept free caches order, and the Request caches button, now add more cache boxes as demand to a network outgrows the ones you have (#248). Before, they stopped at one box per site. - Manila gets real exchanges: GotchaFIX Manila, the free community Bayanihan-IX and In-Vitro-IX, run by PLDTea Time. Diverge, Smarty Pants, Ditto and RISE & Shine join as Philippine networks, and PLDTea Time and Globe-Trotter Telecom now sell transit. - Cebu joins the map on its own island, with GotchaFIX Cebu and two domestic cables from Manila: the Pan de Sal Cable Network and the Philippines Long Distance Relationship. PLDTea Time, Globe-Trotter Telecom, Diverge and RISE & Shine reach Cebu, and typhoons can hit it too. diff --git a/src/game/60-features/95-standing-orders.js b/src/game/60-features/95-standing-orders.js index eabd0b1..81336ec 100644 --- a/src/game/60-features/95-standing-orders.js +++ b/src/game/60-features/95-standing-orders.js @@ -114,7 +114,8 @@ function opsTransitOk(n,c){if(n.id==='cog'&&(scnRule('spat')||S.ev.depeer>S.day) const chk=()=>bz.map(b=>b.reqs.every(k=>!OPS_TREQ.includes(k)||REQS[k].ok(b))).concat(ls.map(l=>COVS.nocog.ok(l))); const was=chk(),all=S.transit;S.transit=all.concat({net:n.id,city:c});try{const now=chk();return was.every((v,i)=>!v||now[i]);}finally{S.transit=all;}} const cheapestTransit=c=>NETS.filter(n=>sellsAt(n,c)&&opsTransitOk(n,c)).sort((a,b)=>transitPerG(a,c,premOnlyAt(a,c))-transitPerG(b,c,premOnlyAt(b,c)))[0]; -const opsProv=c=>{const pv=opsP('transit','prov');return pv!=='cheap'&&sellsAt(NET[pv],c)&&opsTransitOk(NET[pv],c)?NET[pv]:cheapestTransit(c);}; +// 'cheap' and 'have' (Already connected) name no network: quote the cheapest seller (#249). +const opsProv=c=>{const pv=opsP('transit','prov'),n=isNet(pv)?NET[pv]:null;return n&&sellsAt(n,c)&&opsTransitOk(n,c)?n:cheapestTransit(c);}; // The orders. Each takes the shift and does its jobs through the player's own actions. const OPS_RUN={ repair(X){purgeInc();for(const i of S.inc.slice())if(i.type!=='ddos'&&i.until>S.day&&i.cost>0&&!(i.slow&&i.rushed)&&X.can('repair',i.cost)&&X.pay('repair',()=>ACT.fixInc({id:i.id})))X.did('repair');}, diff --git a/tests/standing-orders.test.js b/tests/standing-orders.test.js index e2c5bbf..3a262c6 100644 --- a/tests/standing-orders.test.js +++ b/tests/standing-orders.test.js @@ -635,3 +635,12 @@ test('#244 the PNI order counts the traffic the PNI list shows at that POP, not assert.equal(ev("S.pni.some(p=>p.city==='ham'&&p.net==='nfx')"), true, 'ordered once the traffic is really there'); assert.deepEqual(errors, []); }); + +test('#249 a city without a POP opens while the transit order is set to Already connected', t => { + const { ev, dom, errors } = game(t, ''); + hire(ev); on(ev, 'transit', { x: 1.5, prov: 'have' }); + ev("selectCity('lon')"); + assert.match(dom.window.document.getElementById('panelBody').textContent, /London/); + assert.equal(ev("opsProv('lon')&&opsProv('lon').id"), ev("cheapestTransit('lon')&&cheapestTransit('lon').id"), 'the quote uses the cheapest seller'); + assert.deepEqual(errors, []); +}); From b9183f1178bff126be9180824059d6bf45ad04e3 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Sat, 31 Oct 2026 16:31:50 +0100 Subject: [PATCH 4/4] City panel fix, caches that scale, Manila, Cebu and Davao (2.3.0) --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61521c7..9b59e4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +## [2.3.0] — 2026-10-31 + - Clicking a city without a POP works again while the intern's transit order is set to Already connected (#249). Before, the city panel failed to open and the map stuck to the mouse. - The intern's Accept free caches order, and the Request caches button, now add more cache boxes as demand to a network outgrows the ones you have (#248). Before, they stopped at one box per site. - Manila gets real exchanges: GotchaFIX Manila, the free community Bayanihan-IX and In-Vitro-IX, run by PLDTea Time. Diverge, Smarty Pants, Ditto and RISE & Shine join as Philippine networks, and PLDTea Time and Globe-Trotter Telecom now sell transit. diff --git a/package-lock.json b/package-lock.json index 5a52b2a..27ac0d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "seriesoftubes", - "version": "2.2.0", + "version": "2.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "seriesoftubes", - "version": "2.2.0", + "version": "2.3.0", "license": "MIT", "devDependencies": { "jsdom": "24.1.3", diff --git a/package.json b/package.json index 07e924e..de5c794 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "seriesoftubes", - "version": "2.2.0", + "version": "2.3.0", "description": "A cartoon browser game about building the internet.", "private": true, "license": "MIT",