From cfb5fb5f8e73062a4be3e5e5ae52ce2c97eae11f Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Sun, 25 Oct 2026 17:34:48 +0100 Subject: [PATCH] Draw subsea cables when zoomed in (#49), release 1.26.1 The world layer only includes cables below zoom 1.7, but drawCables skipped its own lines whenever any cached layer existed, so zoomed in nobody drew them. The layer now records whether it holds the cables. --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- site/index.html | 6 ++++-- tests/issues.test.js | 12 ++++++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01fc7f3..92bc027 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +## [1.26.1] — 2026-10-25 + +- Subsea cables no longer disappear when you zoom in on the map (#49). + ## [1.26.0] — 2026-10-25 - Customer levels now go up to 13 instead of 4. Every new level asks for more peak traffic, POPs and continents, ending at 50 Tbps and 80 POPs on six continents, and each one unlocks new customers, gear or deals. Reaching level 13 earns a new legendary badge. diff --git a/package-lock.json b/package-lock.json index 3e658f2..98cf967 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "seriesoftubes", - "version": "1.26.0", + "version": "1.26.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "seriesoftubes", - "version": "1.26.0", + "version": "1.26.1", "devDependencies": { "jsdom": "24.1.3" }, diff --git a/package.json b/package.json index b46360b..b5d222e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "seriesoftubes", - "version": "1.26.0", + "version": "1.26.1", "description": "A cartoon browser game about building the internet.", "private": true, "license": "MIT", diff --git a/site/index.html b/site/index.html index e9c89cb..4bde91c 100644 --- a/site/index.html +++ b/site/index.html @@ -3661,7 +3661,9 @@ function besideLine(sp,d){const c=[0];for(let j=1;jv/L),t),a=polyAt(sp,c.map(v=>v/L),Math.max(0,t-.02)),b=polyAt(sp,c.map(v=>v/L),Math.min(1,t+.02)),dx=b[0]-a[0],dy=b[1]-a[1],n=Math.hypot(dx,dy)||1,f=d*Math.sin(Math.PI*t);out.push([q[0]+dy/n*f,q[1]-dx/n*f]);}return out;} function polyAt(sp,cum,t){let i=1;while(it0?(t-t0)/(t1-t0):0;return [sp[i-1][0]+(sp[i][0]-sp[i-1][0])*f,sp[i-1][1]+(sp[i][1]-sp[i-1][1])*f];} function segDist(x,y,a,b){const dx=b[0]-a[0],dy=b[1]-a[1],L=dx*dx+dy*dy||1;const t=clamp(((x-a[0])*dx+(y-a[1])*dy)/L,0,1);return Math.hypot(x-a[0]-t*dx,y-a[1]-t*dy);} -function drawCables(ks){const z=cam.z,selC=UI.drag&&UI.drag.mode==='link'?UI.drag.from:(UI.sel&&UI.sel.type==='city'?UI.sel.id:null),cached=!!(WL.cv&&WL.key); +// `cached`: the cables are already painted into the world layer. Zoomed in, the layer is painted without +// them (#49), so they are drawn here every frame instead. +function drawCables(ks){const z=cam.z,selC=UI.drag&&UI.drag.mode==='link'?UI.drag.from:(UI.sel&&UI.sel.type==='city'?UI.sel.id:null),cached=!!(WL.cv&&WL.key&&WL.cab); if(!selC&&z<1.7&&cached)return; ctx.font='800 10px Nunito, sans-serif';ctx.textAlign='center';ctx.textBaseline='middle'; for(const cp of CABLE_PAIRS){const C=CAB[cp.cid],hot=!!selC&&(cp.a===selC||cp.b===selC);if(!hot&&cached&&z<1.7)continue;const col=cableCol(C); @@ -3794,7 +3796,7 @@ function worldLayer(z){ const cv2=WL.cv||document.createElement('canvas');cv2.width=Math.ceil(w*sc)+2;cv2.height=Math.ceil(h*sc)+2; const c=cv2.getContext('2d',SOFT_CANVAS?{willReadFrequently:true}:undefined);if(!c)return null; const kk=full?0:Math.floor(cam.x/W)*W;c.setTransform(1,0,0,1,0,0);c.clearRect(0,0,cv2.width,cv2.height);c.setTransform(sc,0,0,sc,-(ox-kk)*sc,-oy*sc);paintWorld(c,z,z<1.7); - Object.assign(WL,{cv:cv2,key,sc,ox,oy,full});return WL; + Object.assign(WL,{cv:cv2,key,sc,ox,oy,full,cab:z<1.7});return WL; } // Draw the world image for map copy k (full layers repeat per copy; a crop already holds what is visible). function drawWorldLayer(wl,k,z,k0){if(!wl.full&&k!==k0)return;const f=z*DPR/wl.sc,ox=(wl.full?k*W:wl.ox); diff --git a/tests/issues.test.js b/tests/issues.test.js index 3861ca6..5558ae1 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -630,3 +630,15 @@ test('#67 a subsea cable can be laid between landing stations that also share a assert.ok(ev("S.links.some(l=>l.own&&l.sub&&l.a==='mrs'&&l.b==='sin')"), 'Marseille–Singapore cable ordered'); assert.deepEqual(errors, []); }); + +test('#49 subsea cables stay on the map when you zoom in', () => { + const { ev, errors } = load(); + ev("ACT.start({});UI.sel=null;cam.x=CITY.ams.x;cam.y=CITY.ams.y"); + const strokes = z => ev(`(()=>{cam.z=${z};WL.zAt=0;WL.key=null;const wl=worldLayer(${z});let n=0;const s=ctx.stroke;ctx.stroke=function(){n++;return s.apply(this,arguments);};drawCables([0]);ctx.stroke=s;return [!!wl,!!WL.cab,n];})()`); + const far = strokes(1.2), near = strokes(4); + assert.equal(far[1], true, 'zoomed out, the cables are painted into the world layer'); + assert.equal(near[0], true, 'zoomed in, a world layer is still used'); + assert.equal(near[1], false, 'but without cables in it'); + assert.ok(near[2] > 20, `so they are drawn live (${near[2]} strokes)`); + assert.deepEqual(errors, []); +});