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.
This commit is contained in:
Frederic Jung 2026-10-25 17:34:48 +01:00
parent c181065d9f
commit cfb5fb5f8e
No known key found for this signature in database
5 changed files with 23 additions and 5 deletions

View file

@ -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.

4
package-lock.json generated
View file

@ -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"
},

View file

@ -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",

View file

@ -3661,7 +3661,9 @@ function besideLine(sp,d){const c=[0];for(let j=1;j<sp.length;j++)c.push(c[j-1]+
for(let j=0;j<=N;j++){const t=j/N,q=polyAt(sp,c.map(v=>v/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(i<cum.length-1&&cum[i]<t)i++;const t0=cum[i-1],t1=cum[i],f=t1>t0?(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);

View file

@ -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, []);
});