From 673b5159b089cd7eb5b344714395c8d98cb397e2 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Mon, 26 Oct 2026 20:42:01 +0100 Subject: [PATCH] Zoom in further, and pick short links between close cities (#126) Porto Alegre and Florianopolis are 65 px apart at the old maximum zoom, and each city grabbed taps within 38 px, so the link between them could not be selected at all. The maximum zoom goes from 6x to 16x (city icons stop growing at 1.35x, so dense regions spread out), and a city now wins a tap outright only on its icon; in the rest of its tap circle a link right under the pointer wins. The hover cursor follows the same rule. Dragging from a POP still draws a new link. --- CHANGELOG.md | 1 + site/index.html | 10 +++++++--- tests/issues.test.js | 20 ++++++++++++++++++++ tests/modes.test.js | 3 ++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 648e743..1f7889d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- You can zoom in much further on the map, and a short link between two close cities can now be picked (#126). Dense regions like southern Brazil spread out properly when you zoom in, and tapping right on a link next to a city opens the link instead of the city. ## [1.31.0] — 2026-10-26 - Series of Tubes now speaks French. The game follows your browser's language the first time, and you can switch to Français under Settings or on the title screen. diff --git a/site/index.html b/site/index.html index 9334e32..d0da411 100644 --- a/site/index.html +++ b/site/index.html @@ -4475,6 +4475,9 @@ function drawCity(C,sx,sy,sc,now,lyOverride){ /* ---------- hit tests & input ---------- */ function hitCity(x,y,r=28){let best=null,bd=r*iconScale();const KS=visibleKs();for(const C of CITIES)for(const k of KS){const [sx,sy]=toS(C.x,C.y,k);const d=Math.hypot(sx-x,sy+4-y);if(d{audioInit();cv.setPointerCapture(e.pointer cv.addEventListener('pointermove',e=>{ if(ptrs.has(e.pointerId))ptrs.set(e.pointerId,{x:e.clientX,y:e.clientY}); const d=UI.drag; - if(!d){const h=S&&hitCity(e.clientX,e.clientY);UI.hover=h?h.id:null;cv.style.cursor=h?(S.pops[h.id]?'crosshair':'pointer'):(hitLink(e.clientX,e.clientY)?'pointer':'grab');return;} + if(!d){const h=S&&pickCity(e.clientX,e.clientY);UI.hover=h?h.id:null;cv.style.cursor=h?(S.pops[h.id]?'crosshair':'pointer'):(hitLink(e.clientX,e.clientY)?'pointer':'grab');return;} if(d.mode==='pinch'){if(ptrs.size>=2){const [a,b]=[...ptrs.values()];const mx=(a.x+b.x)/2,my=(a.y+b.y)/2;zoomAt(mx,my,clamp(d.z0*Math.hypot(a.x-b.x,a.y-b.y)/d.d0,ZMIN,ZMAX)/cam.z);}return;} const dx=e.clientX-d.sx,dy=e.clientY-d.sy;if(Math.hypot(dx,dy)>6)d.moved=true; if(d.mode==='maybeLink'&&d.moved){d.mode='link';cv.classList.add('linking');} @@ -4498,7 +4501,7 @@ function endPtr(e){ ptrs.delete(e.pointerId);const d=UI.drag;if(!d)return; if(d.mode==='pinch'){if(ptrs.size===0){UI.drag=null;UI.snap=null;cv.classList.remove('linking');}return;} if(d.mode==='link'){if(UI.snap&&UI.snap.id!==d.from){openLinkModal(d.from,UI.snap.id);sfx('click');}} - else if(!d.moved&&S){const h=hitCity(e.clientX,e.clientY); + else if(!d.moved&&S){const h=pickCity(e.clientX,e.clientY); if(h){selectCity(h.id);renderLeft();sfx('click');} else{const l=hitLink(e.clientX,e.clientY);if(l){selectLink(l);sfx('click');}else{UI.sel=null;renderPanel();renderLeft();}}} UI.drag=null;UI.snap=null;cv.classList.remove('linking');cv.style.cursor='grab';renderHint(); @@ -4506,7 +4509,8 @@ function endPtr(e){ // A cancelled pointer (scroll takeover, palm rejection, system gesture) is not a tap or a drop. function cancelPtr(e){ptrs.delete(e.pointerId);if(ptrs.size)return;UI.drag=null;UI.snap=null;cv.classList.remove('linking');cv.style.cursor='grab';renderHint();} cv.addEventListener('pointerup',endPtr);cv.addEventListener('pointercancel',cancelPtr); -const ZMIN=0.35,ZMAX=6; +// Dense regions (southern Brazil, the Benelux) need a close look: cities stop growing past 1.35×, so zooming spreads them out (#126). +const ZMIN=0.35,ZMAX=16; function zoomAt(mx,my,f){const wx=cam.x+(mx-CW/2)/cam.z,wy=cam.y+(my-CH/2)/cam.z;cam.z=clamp(cam.z*f,ZMIN,ZMAX);cam.x=wx-(mx-CW/2)/cam.z;cam.y=wy-(my-CH/2)/cam.z;wrapCam();} cv.addEventListener('wheel',e=>{e.preventDefault();zoomAt(e.clientX,e.clientY,Math.exp(-e.deltaY*0.0015));},{passive:false}); addEventListener('keydown',e=>{if(e.target.closest&&e.target.closest('input,textarea,select,[contenteditable]'))return;if(e.ctrlKey||e.metaKey||e.altKey)return;if(e.code==='Space'&&e.target.closest&&e.target.closest('button,a'))return;if(e.code==='Space'){e.preventDefault();UI.speed=UI.speed?0:1;renderHUD();}if(e.key==='0')ACT.speed({v:0.5});if(e.key==='1')ACT.speed({v:1});if(e.key==='2')ACT.speed({v:2});if(e.key==='3')ACT.speed({v:4});if(e.key==='4')ACT.speed({v:8});if(e.key==='Escape'&&!$('bankBox').hidden){$('bankBox').hidden=true;return;}if(e.key==='Escape'&&!$('dash').hidden){$('dash').hidden=true;return;}if(e.key==='Escape'){if(!$('modal').hidden){if(S&&UI.started&&!S.lost)closeModal();}else{UI.sel=null;renderPanel();}}}); diff --git a/tests/issues.test.js b/tests/issues.test.js index 1aee2f8..c611a03 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -1275,3 +1275,23 @@ test('#51 a dark fiber shows what is rented out, and spare capacity can be liste assert.equal(ev('S.offers[0].broker'), true); assert.deepEqual(errors, []); }); + +test('#126 you can zoom in far enough, and pick a short link between two close cities', () => { + const { ev, errors } = load(); + ev("ACT.start({city:'sao'});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;for(const c of ['poa','fln'])ACT.buildPop({city:c});UI.pending=null;UI.via=null;UI.lmode='wave';UI.route='main';openLinkModal('poa','fln');ACT.buildLink({tier:1});closeModal()"); + assert.ok(ev('ZMAX') >= 16); + const id = ev("S.links.find(l=>l.a==='poa'||l.b==='poa').id"); + // the middle of the drawn link, on screen, fully zoomed in on it + const at = (z) => JSON.parse(ev(`(()=>{const l=S.links.find(x=>x.id==='${id}'),g=linkGeom(l,pairIdx().get(edgeKey(l))),p=g.pts[Math.floor(g.pts.length/2)]; + cam.x=p[0];cam.y=p[1];cam.z=1;zoomAt(CW/2,CH/2,${z});const [sx,sy]=toS(p[0],p[1],visibleKs()[0]);const c=toS(CITY.poa.x,CITY.poa.y,visibleKs()[0]);return JSON.stringify({sx,sy,cx:c[0],cy:c[1],z:cam.z});})()`)); + const m = at(100); + assert.equal(m.z, ev('ZMAX'), 'zoom stops at the new maximum'); + assert.equal(ev(`pickCity(${m.sx},${m.sy})`), null, 'the middle of the link is not grabbed by a city'); + assert.equal(ev(`hitLink(${m.sx},${m.sy})`), id); + assert.equal(ev(`pickCity(${m.cx},${m.cy-4}).id`), 'poa', 'tapping the city icon still picks the city'); + // even at the old maximum, a click on the link now picks the link where it is not under a city icon + const o = at(6); + assert.ok(Math.abs(o.z - 6) < 1e-9); + assert.equal(ev(`pickCity(${o.sx},${o.sy})`), null); + assert.deepEqual(errors, []); +}); diff --git a/tests/modes.test.js b/tests/modes.test.js index f8155b8..78d1f42 100644 --- a/tests/modes.test.js +++ b/tests/modes.test.js @@ -132,7 +132,8 @@ test('half speed and deeper zoom', () => { ev("ACT.speed({v:7})"); assert.equal(ev("UI.speed"), 0.5, 'bogus speeds are ignored'); ev("cam.z=1;for(let i=0;i<40;i++)zoomAt(100,100,1.2)"); - assert.equal(ev("cam.z"), 6); + assert.equal(ev("cam.z"), ev("ZMAX"), 'zooming in stops at the maximum'); + assert.ok(ev("ZMAX") >= 16, 'deep enough for dense regions (#126)'); assert.deepEqual(errors, []); });