Merge branch 'pr270b'
# Conflicts: # CHANGELOG.md # src/game/93-ui/82-keys.js
This commit is contained in:
commit
d1a2504104
13 changed files with 94 additions and 12 deletions
|
|
@ -9,7 +9,7 @@ All notable changes to this project are documented here. The project follows
|
|||
- You can pay to hurry the survey, permits and factory of your own subsea cable, 30 days at a time (#258). Money only goes so far: the cable still has to be made, about two months plus a day for every 80 km, before the lay ships sail.
|
||||
- Three new cities in northern Australia: Port Hedland, Townsville and Alice Springs (#255). Port Hedland lands a new cable up the coast to Darwin and a branch of Darwin's cable out to Singapore; Alice Springs has no sea at all. In the wet season, November to April, fiber cuts in the tropical north, Darwin included, take twice as long to reach.
|
||||
- Traceroute no longer shows an "embedded cache in your rack" hop on paths that leave over transit, an exchange or a PNI. Only traffic that really ends at one of your cache boxes shows it now.
|
||||
- New keyboard shortcuts: [ and ] step through your POPs, - and = zoom the map out and in, n opens the NOC dashboard, and ? lists every shortcut. A letter right after n opens one of the dashboard's tabs, such as n c for Connections, and Help links to the list too.
|
||||
- New keyboard shortcuts: the arrow keys and W A S D move the map, [ and ] step through your POPs, $ through the open offers, - and = zoom out and in, n opens the NOC dashboard, and ? lists every shortcut. A letter right after n opens one of the dashboard's tabs, such as n c for Connections, and Help links to the list too.
|
||||
|
||||
## [2.6.0] — 2026-11-03
|
||||
|
||||
|
|
|
|||
|
|
@ -546,10 +546,11 @@ const API_VIEW={
|
|||
linkCheck:{args:[['id','entityId']],doc:'Open the redundancy check for a link: what a single cut would drop, without changing anything.'},
|
||||
findOpen:{args:[],doc:'Open the city finder (the 🔍 in the top bar).'},
|
||||
findGo:{args:[['city','cityId']],doc:'Close the finder and jump to a city.'},
|
||||
routingOpen:{args:[],doc:'Open the Routing & DDoS window: backbone, Auto-TE and DDoS settings (the button at the top of the NOC tab).'},
|
||||
popStep:{args:[['d','step']],doc:'Select and centre the previous (-1) or next (1) of your POPs, in name order, wrapping around (the [ and ] keys).'},
|
||||
zoomStep:{args:[['d','step']],doc:'Zoom the map out (-1) or in (1) around its middle (the - and = keys).'},
|
||||
popStep:{args:[['d','integer']],doc:'Select and centre the previous (d<0) or next (d>0) of your POPs, by name: the [ and ] keys.'},
|
||||
offerStep:{args:[],doc:'Select the next open offer (soonest to expire first), centre its city and mark it under Offers here: the $ key.'},
|
||||
zoomStep:{args:[['d','integer']],doc:'Zoom the map out (d<0) or in (d>0) around its middle: the - and = keys.'},
|
||||
keys:{args:[],doc:'Open the list of keyboard shortcuts (the ? key).'},
|
||||
routingOpen:{args:[],doc:'Open the Routing & DDoS window: backbone, Auto-TE and DDoS settings (the button at the top of the NOC tab).'},
|
||||
opsOpen:{args:[],doc:'Open the Ops sheet: the NOC intern\'s mood, weekly shift report and standing orders.'},
|
||||
opsCity:{args:[['v','cityId',false]],doc:'Show one POP\'s standing-order exceptions in the Ops sheet.'},
|
||||
utilities:{args:[['city','cityId',false]],doc:'Open the utilities sheet: route servers, the redundancy kit, caches and bulk peering, for one city or the whole network.'},
|
||||
|
|
|
|||
|
|
@ -2383,6 +2383,8 @@
|
|||
"keys.esc":"Esc",
|
||||
"keys.game_speed":"Spielgeschwindigkeit: ½×, 1×, 2×, 4×, 8×",
|
||||
"keys.keyboard_shortcuts":"Tastenkürzel",
|
||||
"keys.move_around_the_map":"Karte verschieben",
|
||||
"keys.next_open_offer_soonest_to":"Nächstes offenes Angebot, das bald ablaufende zuerst",
|
||||
"keys.noc_dashboard_a_letter_right":"NOC-Dashboard. Ein Buchstabe direkt danach öffnet einen Tab:",
|
||||
"keys.pause_or_play":"Pause oder weiter",
|
||||
"keys.previous_or_next_of_your":"Vorheriger oder nächster deiner POPs",
|
||||
|
|
|
|||
|
|
@ -2381,6 +2381,8 @@
|
|||
"keys.esc":"Esc",
|
||||
"keys.game_speed":"Velocidad del juego: ½×, 1×, 2×, 4×, 8×",
|
||||
"keys.keyboard_shortcuts":"Atajos de teclado",
|
||||
"keys.move_around_the_map":"Mover el mapa",
|
||||
"keys.next_open_offer_soonest_to":"Siguiente oferta abierta, primero la que caduca antes",
|
||||
"keys.noc_dashboard_a_letter_right":"Panel del NOC. Una letra justo después abre una pestaña:",
|
||||
"keys.pause_or_play":"Pausar o reanudar",
|
||||
"keys.previous_or_next_of_your":"Tu POP anterior o siguiente",
|
||||
|
|
|
|||
|
|
@ -2381,6 +2381,8 @@
|
|||
"keys.esc":"Échap",
|
||||
"keys.game_speed":"Vitesse du jeu : ½×, 1×, 2×, 4×, 8×",
|
||||
"keys.keyboard_shortcuts":"Raccourcis clavier",
|
||||
"keys.move_around_the_map":"Déplacer la carte",
|
||||
"keys.next_open_offer_soonest_to":"Offre ouverte suivante, celle qui expire le plus tôt d’abord",
|
||||
"keys.noc_dashboard_a_letter_right":"Tableau de bord NOC. Une lettre juste après ouvre un onglet :",
|
||||
"keys.pause_or_play":"Pause ou reprise",
|
||||
"keys.previous_or_next_of_your":"Ton POP précédent ou suivant",
|
||||
|
|
|
|||
|
|
@ -2381,6 +2381,8 @@
|
|||
"keys.esc":"Esc",
|
||||
"keys.game_speed":"Velocità di gioco: ½×, 1×, 2×, 4×, 8×",
|
||||
"keys.keyboard_shortcuts":"Scorciatoie da tastiera",
|
||||
"keys.move_around_the_map":"Sposta la mappa",
|
||||
"keys.next_open_offer_soonest_to":"Prossima offerta aperta, prima quella che scade prima",
|
||||
"keys.noc_dashboard_a_letter_right":"Dashboard NOC. Una lettera subito dopo apre una scheda:",
|
||||
"keys.pause_or_play":"Pausa o riprendi",
|
||||
"keys.previous_or_next_of_your":"Il tuo POP precedente o successivo",
|
||||
|
|
|
|||
|
|
@ -2381,6 +2381,8 @@
|
|||
"keys.esc":"Esc",
|
||||
"keys.game_speed":"Velocidade do jogo: ½×, 1×, 2×, 4×, 8×",
|
||||
"keys.keyboard_shortcuts":"Atalhos de teclado",
|
||||
"keys.move_around_the_map":"Mover o mapa",
|
||||
"keys.next_open_offer_soonest_to":"Próxima oferta aberta, primeiro a que vence antes",
|
||||
"keys.noc_dashboard_a_letter_right":"Dashboard do NOC. Uma letra logo depois abre uma aba:",
|
||||
"keys.pause_or_play":"Pausar ou continuar",
|
||||
"keys.previous_or_next_of_your":"Seu POP anterior ou próximo",
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ const ACT={
|
|||
findGo:({city})=>{if(!isCity(city))return;closeModal();$('dash').hidden=true;ACT.focusCity({city});},
|
||||
focusCity:({city})=>{selectCity(city);const C=CITY[city];cam.x=C.x;cam.y=C.y;cam.z=Math.max(cam.z,1.2);if(innerWidth<760)UI.leftOpen=false;renderLeft();},
|
||||
popStep:({d})=>{const L=popOrder(),n=L.length;if(!n)return;const i=UI.sel&&UI.sel.type==='city'?L.indexOf(UI.sel.id):-1;$('dash').hidden=true;ACT.focusCity({city:L[i<0?(d>0?0:n-1):(i+(d>0?1:n-1))%n]});},
|
||||
// The offer stays marked in its city's Offers here until something else is selected, so two offers in one city each get a press.
|
||||
offerStep:()=>{const L=offerOrder(),n=L.length;if(!n){toast(tr('hud_and_panels.no_open_offers_right_now_businesses'));return;}
|
||||
const i=L.findIndex(o=>o.id===UI.offerAt),o=L[(i+1)%n];$('dash').hidden=true;ACT.focusCity({city:o.city});UI.offerAt=o.id;if(S.pops[o.city])UI.tab='cust';renderPanel();
|
||||
const r=document.querySelector('#panelBody .row.on');if(r&&r.scrollIntoView)r.scrollIntoView({block:'nearest'});},
|
||||
zoomStep:({d})=>zoomAt(CW/2,CH/2,d>0?1.25:0.8),
|
||||
keys:()=>showKeys(),
|
||||
selLink:({id})=>{selectLink(id);focusLink(id);},
|
||||
|
|
|
|||
|
|
@ -46,5 +46,5 @@ function focusLink(id){if(pzOn())return;const l=S.links.find(x=>x.id===id);if(!l
|
|||
// Phones leave a thin strip above the sheet: a fixed margin would eat most of it.
|
||||
const m=(a,b)=>Math.max(40,b-a-Math.min(100,(b-a)*0.3)),fw=m(fl,fr),fh=m(ft,fb),z=clamp(Math.min(fw/Math.max(1,x1-x0),fh/Math.max(1,y1-y0),Math.max(cam.z,1.2)),ZMIN,ZMAX);
|
||||
cam.z=z;cam.x=(x0+x1)/2-((fl+fr)/2-CW/2)/z;cam.y=(y0+y1)/2-((ft+fb)/2-CH/2)/z;wrapCam();}
|
||||
function selectCity(c){UI.sel={type:'city',id:c};UI.confirm=null;if(isTablet()||isPhone())UI.leftOpen=false;const P=$('panel');if(P)P.classList.remove('full');if(!S.pops[c])UI.tab='cust';renderPanel();}
|
||||
function selectCity(c){UI.sel={type:'city',id:c};UI.confirm=null;UI.offerAt=null;if(isTablet()||isPhone())UI.leftOpen=false;const P=$('panel');if(P)P.classList.remove('full');if(!S.pops[c])UI.tab='cust';renderPanel();}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ function dfPanel(l){
|
|||
}
|
||||
function offersHere(c){
|
||||
const os=S.offers.filter(o=>bCities(o).includes(c));if(!os.length)return '';
|
||||
return `<section><h3>${tr('common.offers_here')}</h3>${os.map(o=>`<div class="row"><div class="grow"><div class="nm">${esc(o.name)}</div><div class="meta">${esc(BIZ_T[o.type].l)}${o.city2?` ${CITY[o.city].name} ⇄ ${CITY[o.city2].name}`:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}</div>${spotWhy(o)}${R.reach<0.99&&!BIZ_T[o.type].l2?`<div class="why">${tr('link_panels.they_need_the_full_internet_your',{pct:pct(R.reach)})}</div>`:''}${o.type==='scrub'&&!hasScrub()?`<div class="why">${tr('link_panels.needs_your_own_scrubbing_center')}</div>`:''}${bRisk(o)}${reqList(o)}${bHas(o)?'':`<div class="why">${tr('link_panels.needs_a_pop_in_cities_too',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}</div>`}</div>${bHas(o)?btn(tr('common.accept'),'accept',{id:o.id},'green sm'):''}${btn(tr('common.no'),'decline',{id:o.id},'ghost sm')}</div>`).join('')}</section>`;
|
||||
return `<section><h3>${tr('common.offers_here')}</h3>${os.map(o=>`<div class="row${o.id===UI.offerAt?' on':''}"><div class="grow"><div class="nm">${esc(o.name)}</div><div class="meta">${esc(BIZ_T[o.type].l)}${o.city2?` ${CITY[o.city].name} ⇄ ${CITY[o.city2].name}`:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}</div>${spotWhy(o)}${R.reach<0.99&&!BIZ_T[o.type].l2?`<div class="why">${tr('link_panels.they_need_the_full_internet_your',{pct:pct(R.reach)})}</div>`:''}${o.type==='scrub'&&!hasScrub()?`<div class="why">${tr('link_panels.needs_your_own_scrubbing_center')}</div>`:''}${bRisk(o)}${reqList(o)}${bHas(o)?'':`<div class="why">${tr('link_panels.needs_a_pop_in_cities_too',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}</div>`}</div>${bHas(o)?btn(tr('common.accept'),'accept',{id:o.id},'green sm'):''}${btn(tr('common.no'),'decline',{id:o.id},'ghost sm')}</div>`).join('')}</section>`;
|
||||
}
|
||||
function linkPanel(id){
|
||||
const l=S.links.find(x=>x.id===id);if(!l){UI.sel=null;return '';}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,23 @@
|
|||
/* ---------- Keyboard shortcuts: [ ] step through your POPs, - = zoom, n (then a letter) the NOC, ? lists every key ----------
|
||||
/* ---------- Keyboard shortcuts: arrows/WASD move, [ ] step through your POPs, $ through the offers, - = zoom, n (then a letter) the NOC, ? lists every key ----------
|
||||
Space, 0–4 and Escape live with the map's input (96-map/90-input.js), / with Find a city. */
|
||||
// Your POPs in the order Find a city lists them, so [ and ] walk the same list.
|
||||
const popOrder=()=>S&&S.pops?Object.keys(S.pops).filter(isCity).sort((a,b)=>CITY[a].name.localeCompare(CITY[b].name)):[];
|
||||
// Open offers in the Deals list's order, soonest to expire first, so $ walks the same list.
|
||||
const offerOrder=()=>S&&S.offers?S.offers.filter(o=>isCity(o.city)).sort((a,b)=>a.exp-b.exp):[];
|
||||
// n opens the NOC dashboard, and a letter within KEY_LEAD ms of it picks a tab (n c: Connections). n never closes the
|
||||
// dashboard, so n c switches tabs without it flashing shut; Escape closes it.
|
||||
const DASH_KEYS={o:'overview',u:'cust',c:'conn',t:'traffic',r:'infra',l:'lease'},KEY_LEAD=1000;let keyLead=0;
|
||||
// Arrow keys and WASD move the map while held, at a steady speed on screen. Their own frame loop runs only while one is
|
||||
// down, so the game loop does no extra work; letting go, a window opening or leaving the browser window stops it.
|
||||
const PAN_KEYS={ArrowUp:[0,-1],w:[0,-1],ArrowDown:[0,1],s:[0,1],ArrowLeft:[-1,0],a:[-1,0],ArrowRight:[1,0],d:[1,0]},PAN_SPEED=700;
|
||||
const panHeld=new Set();let panAt=null;
|
||||
function panFrame(t){if(!panHeld.size||!$('modal').hidden||!$('dash').hidden){panHeld.clear();return;}
|
||||
// A slow frame (a busy day, a background tab) moves at most 50 ms worth, not a jump across the map.
|
||||
const dt=panAt==null?0:Math.min(0.05,(t-panAt)/1000);panAt=t;let dx=0,dy=0;for(const k of panHeld){dx+=PAN_KEYS[k][0];dy+=PAN_KEYS[k][1];}
|
||||
cam.x+=dx*PAN_SPEED*dt/cam.z;cam.y+=dy*PAN_SPEED*dt/cam.z;wrapCam();requestAnimationFrame(panFrame);}
|
||||
function showKeys(){const k=s=>`<span class="kbd">${s}</span>`,TN={overview:tr('common.overview'),cust:tr('common.customers'),conn:tr('common.connections'),traffic:tr('common.traffic'),infra:tr('common.links_routers'),lease:tr('common.leased_lines')};
|
||||
const tabs=Object.entries(DASH_KEYS).map(([l,t])=>`<span class="keytab">${k(l)} ${TN[t]}</span>`).join(' ');
|
||||
const rows=[[k(tr('keys.space')),tr('keys.pause_or_play')],[k('0')+' – '+k('4'),tr('keys.game_speed')],[k('/'),tr('find.find_a_city')],[k('[')+' '+k(']'),tr('keys.previous_or_next_of_your')],[k('-')+' '+k('='),tr('keys.zoom_the_map_out_or')],[k('n'),`${tr('keys.noc_dashboard_a_letter_right')}<br>${tabs}`],[k(tr('keys.esc')),tr('keys.close_a_window_or_deselect')],[k('?'),tr('keys.show_this_list')]];
|
||||
const rows=[[[...'←↑↓→'].map(k).join(' ')+'<br>'+[...'wasd'].map(k).join(' '),tr('keys.move_around_the_map')],[k(tr('keys.space')),tr('keys.pause_or_play')],[k('0')+' – '+k('4'),tr('keys.game_speed')],[k('/'),tr('find.find_a_city')],[k('[')+' '+k(']'),tr('keys.previous_or_next_of_your')],[k('$'),tr('keys.next_open_offer_soonest_to')],[k('-')+' '+k('='),tr('keys.zoom_the_map_out_or')],[k('n'),`${tr('keys.noc_dashboard_a_letter_right')}<br>${tabs}`],[k(tr('keys.esc')),tr('keys.close_a_window_or_deselect')],[k('?'),tr('keys.show_this_list')]];
|
||||
openModal(`<div style="display:flex;align-items:center"><h2 style="font-size:28px">⌨️ ${tr('keys.keyboard_shortcuts')}</h2><button class="x" data-act="helpClose" aria-label="${tr('common.close')}">×</button></div>
|
||||
<dl class="keylist">${rows.map(([a,b])=>`<dt>${a}</dt><dd>${b}</dd>`).join('')}</dl><div class="btns" style="margin-top:14px">${btn(UI.started?tr('common.back_to_the_map'):tr('common.got_it'),'helpClose',{},'big')}</div>`,'keys');}
|
||||
document.addEventListener('keydown',e=>{
|
||||
|
|
@ -18,5 +28,9 @@ document.addEventListener('keydown',e=>{
|
|||
if(lead&&DASH_KEYS[k]&&!$('dash').hidden){e.preventDefault();ACT.dashTab({k:DASH_KEYS[k]});return;}
|
||||
if(k==='n'){if(!S||!UI.started||!$('modal').hidden)return;e.preventDefault();if($('dash').hidden)ACT.dash();if(!$('dash').hidden)keyLead=Date.now();return;}
|
||||
if(k==='?'){if(e.repeat)return;if($('modal').hidden){if(S&&UI.started){e.preventDefault();ACT.keys();}}else if($('modal').className==='keys'){e.preventDefault();ACT.helpClose();}return;}
|
||||
if(!(step||zoom)||!S||!UI.started||!$('modal').hidden)return;
|
||||
e.preventDefault();if(step)ACT.popStep({d:step});else ACT.zoomStep({d:zoom});});
|
||||
// Alt with an arrow is the browser's Back and Forward.
|
||||
if(!e.altKey&&PAN_KEYS[k]){if(!S||!UI.started||!$('modal').hidden||!$('dash').hidden)return;e.preventDefault();if(!panHeld.size){panAt=null;requestAnimationFrame(panFrame);}panHeld.add(k);return;}
|
||||
if(!(step||zoom||k==='$')||!S||!UI.started||!$('modal').hidden)return;
|
||||
e.preventDefault();if(step)ACT.popStep({d:step});else if(zoom)ACT.zoomStep({d:zoom});else ACT.offerStep();});
|
||||
document.addEventListener('keyup',e=>panHeld.delete(e.key.length===1?e.key.toLowerCase():e.key));
|
||||
addEventListener('blur',()=>panHeld.clear());
|
||||
|
|
|
|||
|
|
@ -2382,6 +2382,8 @@
|
|||
"keys.esc":"Esc",
|
||||
"keys.game_speed":"Game speed: ½×, 1×, 2×, 4×, 8×",
|
||||
"keys.keyboard_shortcuts":"Keyboard shortcuts",
|
||||
"keys.move_around_the_map":"Move around the map",
|
||||
"keys.next_open_offer_soonest_to":"Next open offer, soonest to expire first",
|
||||
"keys.noc_dashboard_a_letter_right":"NOC dashboard. A letter right after it opens a tab:",
|
||||
"keys.pause_or_play":"Pause or play",
|
||||
"keys.previous_or_next_of_your":"Previous or next of your POPs",
|
||||
|
|
|
|||
|
|
@ -36,6 +36,28 @@ test('[ and ] step through your POPs in name order, wrap around, and move the ma
|
|||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('$ steps through the open offers, soonest to expire first, and marks each one in its city', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const doc = dom.window.document, key = keyer(dom);
|
||||
ev(start + ";S.offers=[];for(let i=0;i<60&&S.offers.length<3;i++)spawnOffer()");
|
||||
assert.equal(ev('S.offers.length'), 3);
|
||||
// Two offers in Frankfurt (a POP) and one in Tokyo (no POP), expiring Tokyo first, then both in Frankfurt.
|
||||
ev("(([a,b,c])=>{Object.assign(a,{city:'fra',city2:null,exp:S.day+30,name:'Alpha'});Object.assign(b,{city:'tok',city2:null,exp:S.day+10,name:'Bravo'});Object.assign(c,{city:'fra',city2:null,exp:S.day+20,name:'Charlie'});})(S.offers);UI.tab='up'");
|
||||
const sel = () => ev('UI.sel&&UI.sel.id'), marked = () => [...doc.querySelectorAll('#panelBody .row.on .nm')].map(e => e.textContent);
|
||||
key('$'); assert.equal(sel(), 'tok'); assert.deepEqual(marked(), ['Bravo'], 'the soonest to expire first, marked in its city');
|
||||
assert.equal(ev('cam.x'), ev('CITY.tok.x'), 'with the map on it');
|
||||
key('$'); assert.equal(sel(), 'fra'); assert.equal(ev('UI.tab'), 'cust', 'a POP opens on Customers, where its offers are');
|
||||
assert.deepEqual(marked(), ['Charlie']);
|
||||
key('$'); assert.equal(sel(), 'fra'); assert.deepEqual(marked(), ['Alpha'], 'a second offer in the same city gets its own press');
|
||||
key('$'); assert.deepEqual(marked(), ['Bravo'], 'and round again');
|
||||
ev("selectCity('ams')"); assert.equal(ev('UI.offerAt'), null, 'selecting something else clears the mark');
|
||||
key('$'); assert.deepEqual(marked(), ['Bravo'], 'so $ starts from the top');
|
||||
ev('ACT.decline({id:UI.offerAt})'); key('$'); assert.deepEqual(marked(), ['Charlie'], 'a declined offer drops out');
|
||||
ev('S.offers=[]'); key('$');
|
||||
assert.match(doc.getElementById('toasts').textContent, /No open offers right now/, 'no offers: it says so');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('- and = zoom the map out and in around its middle, within the zoom limits', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const key = keyer(dom);
|
||||
|
|
@ -51,6 +73,35 @@ test('- and = zoom the map out and in around its middle, within the zoom limits'
|
|||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the arrow keys and W A S D move the map while held, at the same speed on screen at any zoom', (t) => {
|
||||
const { ev, dom, errors } = load();
|
||||
// A key left held (a failed assertion) would keep the page's frame loop, and this test file, running.
|
||||
t.after(() => dom.window.dispatchEvent(new dom.window.Event('blur')));
|
||||
const doc = dom.window.document, key = keyer(dom);
|
||||
const up = k => doc.body.dispatchEvent(new dom.window.KeyboardEvent('keyup', { key: k, bubbles: true }));
|
||||
const at = () => [ev('cam.x'), ev('cam.y')].map(v => Math.round(v * 100) / 100);
|
||||
// Frames are driven by hand: panAt=null makes the first one a start, the next one 50 ms later moves.
|
||||
const frames = (a, b) => ev(`panAt=null;panFrame(${a});panFrame(${b})`);
|
||||
ev(start + ';cam.z=1;cam.x=1000;cam.y=500');
|
||||
key('ArrowRight'); frames(1000, 1050); assert.deepEqual(at(), [1035, 500], '700 px a second: 35 px in 50 ms');
|
||||
up('ArrowRight'); frames(1000, 1050); assert.deepEqual(at(), [1035, 500], 'letting go stops it');
|
||||
key('w'); key('a'); frames(0, 50); assert.deepEqual(at(), [1000, 465], 'W and A together: up and left');
|
||||
up('w'); up('A');
|
||||
assert.equal(ev('panHeld.size'), 0, 'a key let go with Shift held still counts');
|
||||
ev('cam.z=2'); key('s'); frames(0, 50); assert.deepEqual(at(), [1000, 482.5], 'zoomed in, the same 35 px on screen');
|
||||
frames(0, 2000); assert.deepEqual(at(), [1000, 500], 'a slow frame moves at most 50 ms worth');
|
||||
up('s');
|
||||
key('ArrowDown'); key('ArrowDown', null, { repeat: true }); assert.equal(ev('panHeld.size'), 1, 'key repeat is the same key');
|
||||
dom.window.dispatchEvent(new dom.window.Event('blur')); assert.equal(ev('panHeld.size'), 0, 'leaving the window lets go');
|
||||
key('d'); ev('ACT.keys()'); frames(0, 50); assert.deepEqual(at(), [1000, 500], 'a window opening stops it');
|
||||
assert.equal(ev('panHeld.size'), 0);
|
||||
ev('closeModal();ACT.dash()'); key('ArrowLeft'); assert.equal(ev('panHeld.size'), 0, 'arrows scroll the NOC dashboard instead');
|
||||
ev("$('dash').hidden=true;ACT.rename()"); key('a', doc.getElementById('rnIn')); key('a'); assert.equal(ev('panHeld.size'), 0, 'not while typing or behind a window');
|
||||
ev('closeModal()'); key('ArrowLeft', null, { altKey: true }); key('ArrowLeft', null, { metaKey: true });
|
||||
assert.equal(ev('panHeld.size'), 0, 'Alt or Cmd with an arrow is the browser\'s');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('n opens the NOC dashboard, and n followed by a letter opens one of its tabs', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
const key = keyer(dom), open = () => !ev("$('dash').hidden"), tab = () => ev("UI.dtab||'overview'");
|
||||
|
|
@ -79,9 +130,9 @@ test('? shows every keyboard shortcut and closes again; Help links to it on a co
|
|||
key('?');
|
||||
assert.equal(ev("$('modal').className"), 'keys', '? opens the list');
|
||||
const txt = doc.getElementById('modalCard').textContent;
|
||||
for (const s of ['Keyboard shortcuts', 'Space', 'Pause or play', 'Find a city', 'Previous or next of your POPs', 'Zoom the map out or in', 'NOC dashboard', 'Connections', 'Leased lines', 'Esc', 'Show this list'])
|
||||
for (const s of ['Keyboard shortcuts', 'Move around the map', 'Space', 'Pause or play', 'Find a city', 'Previous or next of your POPs', 'Next open offer, soonest to expire first', 'Zoom the map out or in', 'NOC dashboard', 'Connections', 'Leased lines', 'Esc', 'Show this list'])
|
||||
assert.ok(txt.includes(s), s);
|
||||
for (const k of ['[', ']', '-', '=', '/', '?', '0', '4', 'n', 'o', 'u', 'c', 't', 'r', 'l']) assert.ok([...doc.querySelectorAll('#modalCard .kbd')].some(e => e.textContent === k), k);
|
||||
for (const k of ['←', '↑', '↓', '→', 'w', 'a', 's', 'd', '[', ']', '$', '-', '=', '/', '?', '0', '4', 'n', 'o', 'u', 'c', 't', 'r', 'l']) assert.ok([...doc.querySelectorAll('#modalCard .kbd')].some(e => e.textContent === k), k);
|
||||
key('?', null, { repeat: true }); assert.equal(ev("$('modal').hidden"), false, 'holding ? does not flicker it');
|
||||
key('?'); assert.equal(ev("$('modal').hidden"), true, '? again closes it');
|
||||
key('?'); key('Escape'); assert.equal(ev("$('modal').hidden"), true, 'so does Escape');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue