Freeze map animation while paused
Packet dots, waves and clouds run on a clock that only advances while the game is playing. Closes #11
This commit is contained in:
parent
23b72dcb92
commit
cc6d328511
3 changed files with 17 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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, []);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue