diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b57d0..fe14d8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] -- New keyboard shortcuts: [ and ] step through your POPs, - and = zoom the map out and in, and ? lists every shortcut. Help links to the list too. +- 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. ## [2.6.0] — 2026-11-03 diff --git a/site/i18n/de.js b/site/i18n/de.js index 1b14f23..149fc64 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -2374,6 +2374,7 @@ "keys.esc":"Esc", "keys.game_speed":"Spielgeschwindigkeit: ½×, 1×, 2×, 4×, 8×", "keys.keyboard_shortcuts":"Tastenkürzel", +"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", "keys.show_this_list":"Diese Liste zeigen", diff --git a/site/i18n/es.js b/site/i18n/es.js index 95fdda8..c6d55a7 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -2372,6 +2372,7 @@ "keys.esc":"Esc", "keys.game_speed":"Velocidad del juego: ½×, 1×, 2×, 4×, 8×", "keys.keyboard_shortcuts":"Atajos de teclado", +"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", "keys.show_this_list":"Mostrar esta lista", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index e52dc95..43d5054 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -2372,6 +2372,7 @@ "keys.esc":"Échap", "keys.game_speed":"Vitesse du jeu : ½×, 1×, 2×, 4×, 8×", "keys.keyboard_shortcuts":"Raccourcis clavier", +"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", "keys.show_this_list":"Afficher cette liste", diff --git a/site/i18n/it.js b/site/i18n/it.js index e2df221..0ac558c 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2372,6 +2372,7 @@ "keys.esc":"Esc", "keys.game_speed":"Velocità di gioco: ½×, 1×, 2×, 4×, 8×", "keys.keyboard_shortcuts":"Scorciatoie da tastiera", +"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", "keys.show_this_list":"Mostra questo elenco", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index c68808b..422017c 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -2372,6 +2372,7 @@ "keys.esc":"Esc", "keys.game_speed":"Velocidade do jogo: ½×, 1×, 2×, 4×, 8×", "keys.keyboard_shortcuts":"Atalhos de teclado", +"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", "keys.show_this_list":"Mostrar esta lista", diff --git a/src/game/93-ui/82-keys.js b/src/game/93-ui/82-keys.js index aef2c06..334a05c 100644 --- a/src/game/93-ui/82-keys.js +++ b/src/game/93-ui/82-keys.js @@ -1,15 +1,22 @@ -/* ---------- Keyboard shortcuts: [ ] step through your POPs, - = zoom, ? lists every key ---------- +/* ---------- Keyboard shortcuts: [ ] step through your POPs, - = 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)):[]; -function showKeys(){const k=s=>`${s}`; - 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(tr('keys.esc')),tr('keys.close_a_window_or_deselect')],[k('?'),tr('keys.show_this_list')]]; +// 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; +function showKeys(){const k=s=>`${s}`,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])=>`${k(l)} ${TN[t]}`).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')}
${tabs}`],[k(tr('keys.esc')),tr('keys.close_a_window_or_deselect')],[k('?'),tr('keys.show_this_list')]]; openModal(`

⌨️ ${tr('keys.keyboard_shortcuts')}

${rows.map(([a,b])=>`
${a}
${b}
`).join('')}
${btn(UI.started?tr('common.back_to_the_map'):tr('common.got_it'),'helpClose',{},'big')}
`,'keys');} document.addEventListener('keydown',e=>{ // Many layouts type [ and ] with Option or AltGr held, so Alt alone is fine; Ctrl or Cmd belongs to the browser. - if(e.metaKey||(e.ctrlKey&&!e.altKey)||(e.target.closest&&e.target.closest('input,textarea,select,[contenteditable]')))return; - const k=e.key,step={'[':-1,']':1}[k],zoom={'-':-1,'_':-1,'=':1,'+':1}[k]; + if(e.key==='Shift'||e.metaKey||(e.ctrlKey&&!e.altKey)||(e.target.closest&&e.target.closest('input,textarea,select,[contenteditable]')))return; + const k=e.key.length===1?e.key.toLowerCase():e.key,step={'[':-1,']':1}[k],zoom={'-':-1,'_':-1,'=':1,'+':1}[k]; + const lead=Date.now()-keyLead { + const { ev, dom, errors } = load(); + const key = keyer(dom), open = () => !ev("$('dash').hidden"), tab = () => ev("UI.dtab||'overview'"); + ev(start); + key('n'); assert.ok(open(), 'n opens it'); + assert.equal(tab(), 'overview'); + key('c'); assert.equal(tab(), 'conn', 'n c: Connections'); + key('n'); assert.ok(open(), 'n does not close it, so n c can switch tabs without a flash'); + key('u'); assert.equal(tab(), 'cust'); + for (const [l, t] of [['o', 'overview'], ['t', 'traffic'], ['r', 'infra'], ['l', 'lease'], ['c', 'conn']]) { key('n'); key(l); assert.equal(tab(), t, 'n ' + l); } + key('o'); assert.equal(tab(), 'conn', 'a letter on its own does nothing'); + key('n'); key('Shift'); key('T'); assert.equal(tab(), 'traffic', 'Shift on the way does not cancel it'); + key('n'); ev('keyLead=Date.now()-KEY_LEAD-1'); key('c'); assert.equal(tab(), 'traffic', 'too late: the letter stands alone'); + key('n'); key('x'); key('c'); assert.equal(tab(), 'traffic', 'another key in between ends the wait'); + key('Escape'); assert.ok(!open(), 'Escape closes it'); + key('n'); key('c', null, { ctrlKey: true }); assert.equal(tab(), 'traffic', 'not with Ctrl'); + ev("$('dash').hidden=true;ACT.rename()"); key('n', dom.window.document.getElementById('rnIn')); key('n'); + assert.ok(!open(), 'not while typing or behind a window'); + assert.deepEqual(errors, []); +}); + test('? shows every keyboard shortcut and closes again; Help links to it on a computer, not on a phone', () => { const { ev, dom, errors } = load(); const doc = dom.window.document, key = keyer(dom); @@ -58,9 +79,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', 'Esc', 'Show this list']) + 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']) assert.ok(txt.includes(s), s); - for (const k of ['[', ']', '-', '=', '/', '?', '0', '4']) assert.ok([...doc.querySelectorAll('#modalCard .kbd')].some(e => e.textContent === k), k); + 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); 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');