Let the title-screen language buttons work before a game exists

The click dispatcher only lets a short list of actions through while there
is no game yet, so picking a language on a fresh title screen did nothing.
The test now clicks the button instead of calling the action.
This commit is contained in:
Danilo Carbonaro 2026-10-24 15:31:03 +02:00
parent 42711456e2
commit 42acec3f07
2 changed files with 7 additions and 1 deletions

View file

@ -3087,7 +3087,7 @@ let pressing=false;
document.addEventListener('pointerdown',e=>{if(e.target.closest('#panel,#left'))pressing=true;});
addEventListener('pointerup',()=>setTimeout(()=>pressing=false,0));
addEventListener('pointercancel',()=>{pressing=false;});addEventListener('blur',()=>{pressing=false;});
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','randomName','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);});
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','randomName','pickStart','cont','help','helpClose','newgame','mute','animSet','soundSet','langSet','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,animT=0;

View file

@ -79,6 +79,12 @@ test('every Italian entry keeps the placeholders and HTML tags of its English te
assert.deepEqual(brokenEntries(dict), []);
});
test('the language buttons on the title screen work before any game exists', () => {
const { ev } = load();
ev("[...document.querySelectorAll('#modalCard [data-act=langSet]')].find(b=>b.textContent==='Italiano').click()");
assert.equal(ev("localStorage.getItem('sot-lang')"), 'it');
});
test('picking a language saves the choice and the game, then reloads', () => {
const { ev } = load();
ev('ACT.start({});dayTick()');