From cc6d328511f184a97f9bb4cd1d60ad594dfa7cf6 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Sat, 24 Oct 2026 06:07:33 +0200 Subject: [PATCH] Freeze map animation while paused Packet dots, waves and clouds run on a clock that only advances while the game is playing. Closes #11 --- CHANGELOG.md | 2 ++ site/index.html | 5 +++-- tests/issues.test.js | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de793ae..e5a890c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Pausing now freezes the map too: packet dots, waves and clouds stop + moving until you press play again (#11). - Ports in both buildings: with a second site, any transit port, PNI or IX port can now be set to "Both". That splits it into a LAG with members in each building (adding a member if needed), so a dark building only takes diff --git a/site/index.html b/site/index.html index a262296..4509547 100644 --- a/site/index.html +++ b/site/index.html @@ -2824,14 +2824,15 @@ addEventListener('pointercancel',()=>{pressing=false;});addEventListener('blur', document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','pickStart','cont','help','helpClose','newgame','mute','animSet','soundSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','scenarios','startScn','startWeekly'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);}); /* ================= LOOP ================= */ -let last=performance.now(),acc=0,hudT=0; +let last=performance.now(),acc=0,hudT=0,animT=0; function frame(now){ const dt=Math.min(250,now-last);last=now; if(ANALYTICS.host&&S&&!S.lost&&UI.speed&&document.visibilityState==='visible'){UI.playMs=(UI.playMs||0)+dt;const m=UI.playMs/60000;for(const k of PLAY_MARKS)if(m>=k)track('play_'+k+'m',true);} if(S&&UI.started&&!S.lost&&now-(UI.lastSave||0)>5000)save(); if(S&&!S.lost&&$('modal').hidden&&UI.speed){acc+=dt*UI.speed;let n=0;while(acc>=DAY_MS&&n<4){acc-=DAY_MS;dayTick();n++;} if(n){renderHUD();if(!pressing){renderPanel();renderLeft();if(!$('dash').hidden)renderDash();renderBank();}renderHint();}} - draw(animOn()?now:0); + if(UI.speed&&!(S&&S.lost))animT+=dt; /* paused = frozen dots, waves and clouds */ + draw(animOn()?animT:0); if(!window.__TUBES_TEST__)requestAnimationFrame(frame); } function boot(data){ diff --git a/tests/issues.test.js b/tests/issues.test.js index 62c7c0c..9f3396e 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -179,3 +179,15 @@ test('#7 NOC legend, sortable network table and transit destinations', () => { assert.match(ev("document.getElementById('panelBody').textContent"), /Top destinations on this port/); assert.deepEqual(errors, []); }); + +test('#11 pausing freezes the dots on the links', () => { + const { ev, errors } = load(); + base(ev); + ev("ACT.animSet({v:'on'});UI.speed=1;last=1000;frame(1016)"); + const t0 = ev("animT"); + ev("UI.speed=0;frame(1100);frame(1400)"); + assert.equal(ev("animT"), t0, 'clock stands still while paused'); + ev("UI.speed=1;frame(1416)"); + assert.ok(ev("animT") > t0, 'and moves again on play'); + assert.deepEqual(errors, []); +});