Keyboard shortcuts: the Help button works on the title screen; MCP knows the new actions

Before a game starts the click handler only runs allowlisted actions, so Help's
Keyboard shortcuts button did nothing on the title screen. Allow it, and close
the list with helpClose, so ? returns to the title instead of leaving an empty
map. popStep, zoomStep and keys are views for the MCP server.
This commit is contained in:
Frederic Jung 2026-11-03 11:32:12 +01:00
parent 9cf90d0ad0
commit 48ba0048da
No known key found for this signature in database
4 changed files with 18 additions and 2 deletions

View file

@ -547,6 +547,9 @@ const API_VIEW={
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).'},
keys:{args:[],doc:'Open the list of keyboard shortcuts (the ? key).'},
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.'},

View file

@ -17,6 +17,6 @@ document.addEventListener('keydown',e=>{
const lead=Date.now()-keyLead<KEY_LEAD;keyLead=0;
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();closeModal();}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});});

View file

@ -11,5 +11,5 @@ let PD={t:0,b:null};
document.addEventListener('pointerdown',e=>{PD={t:performance.now(),b:e.target.closest('[data-act]')};},true);
function tapOk(e,b){if(!e.isTrusted||!PD.t||e.detail===0)return true;const now=performance.now();if(now-PD.t>4000)return true;
if(PD.b!==b)return false;if((UI.layerAt||0)>PD.t)return false;const ts=b.closest('.toast');if(ts&&PD.t-(+ts.dataset.born||0)<500)return false;return true;}
document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;if(!$('modal').hidden&&!b.closest('#modal'))return;if(!tapOk(e,b))return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','randomName','pickStart','cont','help','helpClose','newgame','mute','animSet','soundSet','langSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','presetSet','chaosSet','puzzleDoor','puzzleMenu','pzStart','pzArStart','pzWeekly','scenarios','startScn','startWeekly','settings','settingsClose','prefSet','vpSet','install','pitchSkip','slotMenu','slotExport','slotDel','slotDelGo','slotBack','slotSwitch','slotTake','slotSpace','toTitle'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);});
document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;if(!$('modal').hidden&&!b.closest('#modal'))return;if(!tapOk(e,b))return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','keys','randomName','pickStart','cont','help','helpClose','newgame','mute','animSet','soundSet','langSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','presetSet','chaosSet','puzzleDoor','puzzleMenu','pzStart','pzArStart','pzWeekly','scenarios','startScn','startWeekly','settings','settingsClose','prefSet','vpSet','install','pitchSkip','slotMenu','slotExport','slotDel','slotDelGo','slotBack','slotSwitch','slotTake','slotSpace','toTitle'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);});

View file

@ -106,3 +106,16 @@ test('the shortcut list in German', () => {
assert.match(txt, /Leertaste/);
assert.deepEqual(errors, []);
});
test('on the title screen, Help opens the shortcut list and both ways out lead back to the title', () => {
const { ev, dom, errors } = load();
const doc = dom.window.document, key = keyer(dom), title = () => !ev("$('modal').hidden") && ev("$('modal').className") !== 'keys';
assert.ok(ev('!S'), 'no game yet');
ev('ACT.help()');
doc.querySelector('#modalCard [data-act="keys"]').click();
assert.equal(ev("$('modal').className"), 'keys', 'the button works before a game starts');
key('?'); assert.ok(title(), '? goes back to the title, not to an empty map');
ev('ACT.help()'); doc.querySelector('#modalCard [data-act="keys"]').click();
doc.querySelector('#modalCard .btns [data-act="helpClose"]').click(); assert.ok(title(), 'and so does its button');
assert.deepEqual(errors, []);
});