From 23eeddf44f19946c2b92853cbed48244d7214c1d Mon Sep 17 00:00:00 2001 From: Charlie Allom Date: Tue, 3 Nov 2026 10:08:29 +0000 Subject: [PATCH 1/2] Keyboard shortcuts: [ ] step through your POPs, - = zoom, ? lists every key [ and ] select the previous or next of your POPs, in the order Find a city lists them, and move the map there. - and = (also _ and +) zoom around the middle of the map. ? opens a list of every shortcut, and Help links to it on a computer. Keys are ignored while typing, with Ctrl or Cmd held, or behind an open window. --- CHANGELOG.md | 2 + site/i18n/de.js | 9 +++ site/i18n/es.js | 9 +++ site/i18n/fr.js | 9 +++ site/i18n/it.js | 9 +++ site/i18n/pt.js | 9 +++ src/game/90-actions/10-interface.js | 3 + src/game/93-ui/82-keys.js | 15 +++++ src/game/95-modals/60-help.js | 2 +- src/i18n/en.js | 9 +++ src/styles/40-modal.css | 3 + tests/keyboard-shortcuts.test.js | 87 +++++++++++++++++++++++++++++ 12 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 src/game/93-ui/82-keys.js create mode 100644 tests/keyboard-shortcuts.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 086c892..14b57d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ 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. + ## [2.6.0] — 2026-11-03 - New Best Effort mode, the gentlest way to play: rare outages, no DDoS, no chaos monkey, no conferences and no cable ships, with sea cuts that mend on their own. PNIs are up the moment you order them, customers are more patient, a rescue loan from the Ministry of Tubes replaces game over, builds take days and prices never spike. A new Quiet notifications setting, on by default in Best Effort and available in every mode, only pops up trouble and milestones; everything else goes into the NOC log. diff --git a/site/i18n/de.js b/site/i18n/de.js index b0830a1..1b14f23 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -2370,6 +2370,15 @@ "interface.tubecoin_moved_down_p_on_the":"TubeCoin ist auf dem Weg zu deinem Konto um {p} % gefallen.", "interface.tubecoin_moved_up_p_on_the":"TubeCoin ist auf dem Weg zu deinem Konto um {p} % gestiegen.", "interface.you_bought_out_bank_they_flew":"Du hast {bank} ausbezahlt.
Sie sind weitergeflogen, um ein anderes Startup zu finden.", +"keys.close_a_window_or_deselect":"Fenster schließen oder Stadt bzw. Link abwählen", +"keys.esc":"Esc", +"keys.game_speed":"Spielgeschwindigkeit: ½×, 1×, 2×, 4×, 8×", +"keys.keyboard_shortcuts":"Tastenkürzel", +"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", +"keys.space":"Leertaste", +"keys.zoom_the_map_out_or":"Karte heraus- oder hineinzoomen", "lease_swaps.cap_fabric_circuit":"{cap}-Fabric-Verbindung", "lease_swaps.cap_on_a_dark_fiber_iru":"{cap} auf einer Dark-Fiber-IRU", "lease_swaps.cap_wave":"{cap}-Wave", diff --git a/site/i18n/es.js b/site/i18n/es.js index 45a48e2..95fdda8 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -2368,6 +2368,15 @@ "interface.tubecoin_moved_down_p_on_the":"TubeCoin bajó un {p} % de camino a tu cuenta.", "interface.tubecoin_moved_up_p_on_the":"TubeCoin subió un {p} % de camino a tu cuenta.", "interface.you_bought_out_bank_they_flew":"Compraste {bank}.
Se fueron volando a buscar otra startup.", +"keys.close_a_window_or_deselect":"Cerrar una ventana, o deseleccionar una ciudad o un enlace", +"keys.esc":"Esc", +"keys.game_speed":"Velocidad del juego: ½×, 1×, 2×, 4×, 8×", +"keys.keyboard_shortcuts":"Atajos de teclado", +"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", +"keys.space":"Espacio", +"keys.zoom_the_map_out_or":"Alejar o acercar el mapa", "lease_swaps.cap_fabric_circuit":"Circuito de fabric de {cap}", "lease_swaps.cap_on_a_dark_fiber_iru":"{cap} en una IRU de fibra oscura", "lease_swaps.cap_wave":"Onda de {cap}", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 51cc12c..e52dc95 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -2368,6 +2368,15 @@ "interface.tubecoin_moved_down_p_on_the":"Le TubeCoin a perdu {p} % en route vers ton compte.", "interface.tubecoin_moved_up_p_on_the":"Le TubeCoin a pris {p} % en route vers ton compte.", "interface.you_bought_out_bank_they_flew":"Tu as racheté la part de {bank}.
Ils se sont envolés à la recherche d’une autre startup.", +"keys.close_a_window_or_deselect":"Fermer une fenêtre, ou désélectionner une ville ou un lien", +"keys.esc":"Échap", +"keys.game_speed":"Vitesse du jeu : ½×, 1×, 2×, 4×, 8×", +"keys.keyboard_shortcuts":"Raccourcis clavier", +"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", +"keys.space":"Espace", +"keys.zoom_the_map_out_or":"Dézoomer ou zoomer la carte", "lease_swaps.cap_fabric_circuit":"circuit fabric {cap}", "lease_swaps.cap_on_a_dark_fiber_iru":"{cap} sur un IRU de fibre noire", "lease_swaps.cap_wave":"longueur d’onde {cap}", diff --git a/site/i18n/it.js b/site/i18n/it.js index e01b0e5..e2df221 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2368,6 +2368,15 @@ "interface.tubecoin_moved_down_p_on_the":"TubeCoin è sceso del {p}% mentre arrivava sul tuo conto.", "interface.tubecoin_moved_up_p_on_the":"TubeCoin è salito del {p}% mentre arrivava sul tuo conto.", "interface.you_bought_out_bank_they_flew":"Hai liquidato {bank}.
Sono volati via in cerca di un’altra startup.", +"keys.close_a_window_or_deselect":"Chiudi una finestra, o deseleziona una città o un link", +"keys.esc":"Esc", +"keys.game_speed":"Velocità di gioco: ½×, 1×, 2×, 4×, 8×", +"keys.keyboard_shortcuts":"Scorciatoie da tastiera", +"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", +"keys.space":"Spazio", +"keys.zoom_the_map_out_or":"Zoom indietro o avanti sulla mappa", "lease_swaps.cap_fabric_circuit":"circuito fabric da {cap}", "lease_swaps.cap_on_a_dark_fiber_iru":"{cap} su una dark fiber IRU", "lease_swaps.cap_wave":"wave da {cap}", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index d05bfb2..c68808b 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -2368,6 +2368,15 @@ "interface.tubecoin_moved_down_p_on_the":"A TubeCoin caiu {p}% no caminho até sua conta.", "interface.tubecoin_moved_up_p_on_the":"A TubeCoin subiu {p}% no caminho até sua conta.", "interface.you_bought_out_bank_they_flew":"Você comprou a parte de {bank}.
Eles voaram em busca de outra startup.", +"keys.close_a_window_or_deselect":"Fechar uma janela, ou desmarcar uma cidade ou link", +"keys.esc":"Esc", +"keys.game_speed":"Velocidade do jogo: ½×, 1×, 2×, 4×, 8×", +"keys.keyboard_shortcuts":"Atalhos de teclado", +"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", +"keys.space":"Espaço", +"keys.zoom_the_map_out_or":"Afastar ou aproximar o mapa", "lease_swaps.cap_fabric_circuit":"circuito de fabric de {cap}", "lease_swaps.cap_on_a_dark_fiber_iru":"{cap} numa IRU de dark fiber", "lease_swaps.cap_wave":"wave de {cap}", diff --git a/src/game/90-actions/10-interface.js b/src/game/90-actions/10-interface.js index e1ed9bc..ef3e4fa 100644 --- a/src/game/90-actions/10-interface.js +++ b/src/game/90-actions/10-interface.js @@ -48,5 +48,8 @@ const ACT={ findOpen:()=>findOpen(), 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]});}, + zoomStep:({d})=>zoomAt(CW/2,CH/2,d>0?1.25:0.8), + keys:()=>showKeys(), selLink:({id})=>{selectLink(id);focusLink(id);}, }; diff --git a/src/game/93-ui/82-keys.js b/src/game/93-ui/82-keys.js new file mode 100644 index 0000000..aef2c06 --- /dev/null +++ b/src/game/93-ui/82-keys.js @@ -0,0 +1,15 @@ +/* ---------- Keyboard shortcuts: [ ] step through your POPs, - = zoom, ? 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')]]; + 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(k==='?'){if(e.repeat)return;if($('modal').hidden){if(S&&UI.started){e.preventDefault();ACT.keys();}}else if($('modal').className==='keys'){e.preventDefault();closeModal();}return;} + if(!(step||zoom)||!S||!UI.started||!$('modal').hidden)return; + e.preventDefault();if(step)ACT.popStep({d:step});else ACT.zoomStep({d:zoom});}); diff --git a/src/game/95-modals/60-help.js b/src/game/95-modals/60-help.js index 58cb71d..e3fd9c2 100644 --- a/src/game/95-modals/60-help.js +++ b/src/game/95-modals/60-help.js @@ -18,7 +18,7 @@ function showHelp(){
${tr('common.waves')}
${tr('help.your_fiber_links_are_leased_waves')}
${tr('common.95th_percentile')}
${tr('help.transit_bills_sample_your_usage')}
${tr('common.routers')}
${tr('help.each_pop_s_router_model_caps')}
${tr('common.dark_fiber')}
${tr('help.lease_an_iru_or_build_your')}
${tr('common.subsea_cables')}
${tr('help.subsea_waves_can_only_follow_cable')}
${tr('common.latency')}
${tr('help.every_link_has_latency_high')}
${tr('common.noc_dashboard')}
${tr('help.the_chart_button_at_the_top')}
${tr('common.asia')}
${tr('help.a_weird_underserved_market_transit')}
${tr('common.russia')}
${tr('help.moscow_needs_a_mandatory_government')}
${tr('help.events_chains_and_wholesale')}
${tr('help.event_networks_a_final_a_festival')}
${tr('common.bank')}
${tr('help.tap_your_cash_to_open_the')}
${tr('common.lags')}
${tr('help.out_of_port_speed_bundle_up')}
${tr('common.traffic_engineering')}
${tr('help.tap_a_link_to_see_which')}
${tr('common.china')}
${tr('help.mainland_china_needs_a_license_and')}
${tr('common.weird_requirements')}
${tr('help.some_customers_come_with_conditions')}
${tr('common.customer_levels')}
${tr('help.as_your_peak_traffic_and_footprint')}
${tr('help.l2vpn_ddos_protection')}
${tr('help.businesses_may_want_a_private')}
${tr('common.ddos_attack')}
${tr('help.ddos_a_flood_comes_from')}
${tr('common.scrubbing_centers')}
${tr('help.scrubbing_a_center_pulls_floods')}
${tr('common.nni_fabrics')}
${tr('help.megapork_pocketfabric_and')}
${tr('common.conferences')}
${tr('help.nanog_ripe_denog_and_friends_come')}
${tr('common.modes')}
${tr('help.one_game_four_doors_and_the')}
${tr('common.traceroute')}
${tr('help.tap_traceroute_on_any_of_your')}
${tr('common.badges')}
${tr('help.below_your_goals_sits_a_wall')}
${tr('common.the_giants')}
${tr('help.at_customer_level_3_and_4')}
RouteScript
${tr('help.once_auto_te_is_installed_you')}
Auto-TE
${tr('help.traffic_follows_the_shortest_path_by')}
${tr('common.metro_diversity')}
${tr('help.a_pop_is_one_building_until')}
${tr('common.wave_markets')}
${tr('help.what_a_wave_costs_depends_on')}
${tr('common.regional_quirks')}
${tr('help.in_the_gulf_saudi_pops_need')}
${tr('common.boot_times')}
${tr('help.some_routers_take_forever_to_boot')}
${tr('common.failures')}
${tr('help.things_break_all_the_time_fiber')}
RouteScript
${tr('help.rules_for_your_auto_te_controller')}
-

${tr('help.want_to_know_how_it_really')}

${plugHtml(true)}${chatHtml()}${issueHtml()}
${btn(UI.started?tr('common.back_to_the_map'):tr('common.got_it'),'helpClose',{},'big')}${RELEASE_NOTES.length?btn(tr('common.what_s_new_in_v',{v:esc(APP_VERSION)}),'whatsNewShow',{},'ghost'):''}${UI.started&&S&&!S.lost?btn(tr('common.start_a_new_network'),'resetAsk',{},'ghost sm'):''}
${UI.started&&S&&!S.lost?btn(tr('common.export_save'),'exportSave',{},'ghost sm'):''}${btn(tr('common.import_a_save'),'importPick',{},'ghost sm')}${btn(tr('common.settings'),'settings',{},'ghost sm')}
`); +

${tr('help.want_to_know_how_it_really')}

${plugHtml(true)}${chatHtml()}${issueHtml()}
${btn(UI.started?tr('common.back_to_the_map'):tr('common.got_it'),'helpClose',{},'big')}${RELEASE_NOTES.length?btn(tr('common.what_s_new_in_v',{v:esc(APP_VERSION)}),'whatsNewShow',{},'ghost'):''}${UI.started&&S&&!S.lost?btn(tr('common.start_a_new_network'),'resetAsk',{},'ghost sm'):''}
${UI.started&&S&&!S.lost?btn(tr('common.export_save'),'exportSave',{},'ghost sm'):''}${btn(tr('common.import_a_save'),'importPick',{},'ghost sm')}${btn(tr('common.settings'),'settings',{},'ghost sm')}${isPhone()?'':btn(tr('keys.keyboard_shortcuts'),'keys',{},'ghost sm')}
`); } function showWin(){setTimeout(()=>{const m=$('modalCard');if(m&&!m.querySelector('[data-act=share]'))m.insertAdjacentHTML('beforeend',`
${btn(tr('help.share_my_network'),'share',{},'pink')}

${tr('help.you_built_a_cartoon_internet_now')}

${plugHtml(true)}`);},0);openModal(`

${tr('help.you_re_a_tier_1')}

${tr('help.name_as_asn_is_transit_free',{name:esc(S.name),asn:S.asn,days:S.day,n:S.stats.incidents})}

${btn(tr('common.keep_building'),'keepPlaying',{},'pink big')}`);sfx('coin');} function showLose(){openModal(`

${tr('common.bankrupt')}

${tr('help.the_bank_repossessed_your_routers',{name:esc(S.name),days:S.day,peak:fmtG(S.stats.peak)})}

${btn(tr('common.try_again'),'newgame',{},'pink big')}`);if(UI.slot){const id=UI.slot;slotDrop(id);slotFree(id);}} diff --git a/src/i18n/en.js b/src/i18n/en.js index 4f4386e..356faa5 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -2369,6 +2369,15 @@ "interface.tubecoin_moved_down_p_on_the":"TubeCoin moved down {p}% on the way to your account.", "interface.tubecoin_moved_up_p_on_the":"TubeCoin moved up {p}% on the way to your account.", "interface.you_bought_out_bank_they_flew":"You bought out {bank}.
They flew off to find another startup.", +"keys.close_a_window_or_deselect":"Close a window, or deselect a city or link", +"keys.esc":"Esc", +"keys.game_speed":"Game speed: ½×, 1×, 2×, 4×, 8×", +"keys.keyboard_shortcuts":"Keyboard shortcuts", +"keys.pause_or_play":"Pause or play", +"keys.previous_or_next_of_your":"Previous or next of your POPs", +"keys.show_this_list":"Show this list", +"keys.space":"Space", +"keys.zoom_the_map_out_or":"Zoom the map out or in", "lease_swaps.cap_fabric_circuit":"{cap} fabric circuit", "lease_swaps.cap_on_a_dark_fiber_iru":"{cap} on a dark fiber IRU", "lease_swaps.cap_wave":"{cap} wave", diff --git a/src/styles/40-modal.css b/src/styles/40-modal.css index ab9b0d6..7e1f964 100644 --- a/src/styles/40-modal.css +++ b/src/styles/40-modal.css @@ -160,6 +160,9 @@ input.t{width:100%;box-sizing:border-box;border:3px solid var(--ink);border-radi .gl dt{font-family:var(--display);font-weight:800;font-size:16px;margin-top:10px} .gl dd{margin:2px 0 0;color:var(--ink2);line-height:1.45;font-size:13px} .kbd{display:inline-block;border:2px solid var(--ink);border-radius:6px;padding:0 5px;font-weight:900;font-size:11px;background:var(--soft)} +.keylist{display:grid;grid-template-columns:auto 1fr;gap:10px 16px;align-items:center;margin:14px 0 0} +.keylist dt{margin:0;white-space:nowrap}.keylist dd{margin:0;color:var(--ink2);font-size:14px} +.keylist .kbd{font-size:13px;padding:1px 7px;min-width:12px;text-align:center} /* "Your networks" on the title screen: one big tap target per network, a small ⋯ for export and delete. */ .slots{display:flex;flex-direction:column;gap:7px;margin-bottom:6px;max-height:min(46vh,330px);overflow:auto;padding:2px 2px 5px} diff --git a/tests/keyboard-shortcuts.test.js b/tests/keyboard-shortcuts.test.js new file mode 100644 index 0000000..42b2372 --- /dev/null +++ b/tests/keyboard-shortcuts.test.js @@ -0,0 +1,87 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +const start = "ACT.start({});S.nextFail=1e9;S.nextEvent=1e9;S.cash=1e9"; +const keyer = dom => (k, t, o) => (t || dom.window.document.body).dispatchEvent(new dom.window.KeyboardEvent('keydown', { key: k, bubbles: true, ...o })); + +test('[ and ] step through your POPs in name order, wrap around, and move the map there', () => { + const { ev, dom, errors } = load(); + const key = keyer(dom); + ev(start + ";for(const c of ['par','lon','ams'])ACT.buildPop({city:c})"); + assert.equal(ev("popOrder().join()"), 'ams,fra,lon,par', 'Amsterdam, Frankfurt, London, Paris'); + const sel = () => ev('UI.sel&&UI.sel.type==="city"?UI.sel.id:null'); + assert.equal(sel(), 'fra', 'the game starts on the home POP'); + key(']'); assert.equal(sel(), 'lon'); + assert.equal(ev('cam.x'), ev('CITY.lon.x'), 'with the map on it'); + key(']'); assert.equal(sel(), 'par'); + key(']'); assert.equal(sel(), 'ams', '] wraps to the first'); + key('['); assert.equal(sel(), 'par', '[ wraps to the last'); + key('['); assert.equal(sel(), 'lon'); + // Nothing selected, or a city without a POP: ] starts at the first POP, [ at the last. + ev('UI.sel=null'); key(']'); assert.equal(sel(), 'ams'); + ev('UI.sel=null'); key('['); assert.equal(sel(), 'par'); + ev("selectCity('tok')"); key(']'); assert.equal(sel(), 'ams'); + // The NOC dashboard steps aside so the POP can be seen. + ev("ACT.dash()"); assert.equal(ev("$('dash').hidden"), false); + key(']'); assert.equal(sel(), 'fra'); assert.equal(ev("$('dash').hidden"), true); + // Not while typing, not with Ctrl or Cmd, not behind an open window. + key(']', null, { ctrlKey: true }); key(']', null, { metaKey: true }); assert.equal(sel(), 'fra'); + key(']', null, { altKey: true }); assert.equal(sel(), 'lon', 'Option or AltGr types [ ] on many layouts'); + ev("ACT.rename()"); + key(']', dom.window.document.getElementById('rnIn')); + key(']'); + assert.equal(sel(), 'lon'); + assert.equal(ev("$('modal').hidden"), false); + 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); + ev(start + ';cam.z=1'); + const x = ev('cam.x'), z = () => ev('cam.z'); + key('='); assert.ok(Math.abs(z() - 1.25) < 1e-9); + key('+'); assert.ok(Math.abs(z() - 1.5625) < 1e-9, '+ zooms in too'); + key('-'); key('_'); assert.ok(Math.abs(z() - 1) < 1e-9, '- and _ zoom out'); + assert.ok(Math.abs(ev('cam.x') - x) < 1e-6, 'the middle of the map stays put'); + ev('cam.z=ZMAX'); key('='); assert.equal(z(), ev('ZMAX')); + ev('cam.z=ZMIN'); key('-'); assert.equal(z(), ev('ZMIN')); + ev("cam.z=1;ACT.rename()"); key('=', dom.window.document.getElementById('rnIn')); key('='); assert.equal(z(), 1, 'not while a window is open'); + 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); + ev(start); + 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']) + assert.ok(txt.includes(s), s); + for (const k of ['[', ']', '-', '=', '/', '?', '0', '4']) 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'); + // Another window stays as it is, and ? in a text field is just a question mark. + ev("ACT.findOpen()"); key('?'); assert.equal(ev("$('modal').className"), 'find'); + key('?', doc.getElementById('findIn')); assert.equal(ev("$('modal').className"), 'find'); + ev('closeModal();ACT.help()'); + const link = doc.querySelector('#modalCard [data-act="keys"]'); + assert.ok(link, 'Help has a Keyboard shortcuts button'); + link.click(); assert.equal(ev("$('modal').className"), 'keys'); + ev("closeModal();window.innerWidth=360;ACT.help()"); + assert.equal(doc.querySelector('#modalCard [data-act="keys"]'), null, 'not on a phone, which has no keys'); + assert.deepEqual(errors, []); +}); + +test('the shortcut list in German', () => { + const { ev, dom, errors } = load({ lang: 'de' }); + ev(start + ';if(ACT.pitchSkip)ACT.pitchSkip()'); + keyer(dom)('?'); + const txt = dom.window.document.getElementById('modalCard').textContent; + assert.match(txt, /Tastenkürzel/); + assert.match(txt, /Leertaste/); + assert.deepEqual(errors, []); +}); From d88684d86ea0bc7a478fceab88555eeea38c2ff3 Mon Sep 17 00:00:00 2001 From: Charlie Allom Date: Tue, 3 Nov 2026 10:20:15 +0000 Subject: [PATCH 2/2] n opens the NOC dashboard, and a letter right after it opens a tab n then o, u, c, t, r or l, within a second, opens Overview, Customers, Connections, Traffic, Links & routers or Leased lines. n never closes the dashboard, so n c switches tabs without it flashing shut; Escape closes it. Shift on the way does not cancel the wait, any other key does. The ? list shows the letters. --- CHANGELOG.md | 2 +- site/i18n/de.js | 1 + site/i18n/es.js | 1 + site/i18n/fr.js | 1 + site/i18n/it.js | 1 + site/i18n/pt.js | 1 + src/game/93-ui/82-keys.js | 17 ++++++++++++----- src/i18n/en.js | 1 + src/styles/40-modal.css | 1 + tests/keyboard-shortcuts.test.js | 25 +++++++++++++++++++++++-- 10 files changed, 43 insertions(+), 8 deletions(-) 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');