Language is a dropdown on the title screen and in Settings
This commit is contained in:
parent
3b8bd4e534
commit
87fac683f0
7 changed files with 54 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
- Language is now a dropdown on the title screen and in Settings, with each language named in itself. On phones it opens the system picker.
|
||||||
- Every new network starts at ½ speed, so you can find your feet before the bills arrive (#186). Saved games still continue at the speed you left them.
|
- Every new network starts at ½ speed, so you can find your feet before the bills arrive (#186). Saved games still continue at the speed you left them.
|
||||||
- You can put a link on standby, so one of two links between the same cities sits idle as a backup (#122). It carries traffic only when the other links are full or down, so its capacity is never wasted, and the map draws it dashed while it waits. The routing metric still applies to every link between the two cities.
|
- You can put a link on standby, so one of two links between the same cities sits idle as a backup (#122). It carries traffic only when the other links are full or down, so its capacity is never wasted, and the map draws it dashed while it waits. The routing metric still applies to every link between the two cities.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ function showTitle(){
|
||||||
<label class="f" for="nmIn">${tr('title.name_your_network')}</label><div class="network-name"><input class="t" id="nmIn" maxlength="24" value="${esc(UI.nm)}" autocomplete="off">${btn(tr('common.another_one'),'randomName',{},'ghost sm')}</div>
|
<label class="f" for="nmIn">${tr('title.name_your_network')}</label><div class="network-name"><input class="t" id="nmIn" maxlength="24" value="${esc(UI.nm)}" autocomplete="off">${btn(tr('common.another_one'),'randomName',{},'ghost sm')}</div>
|
||||||
<label class="f">${tr('title.pick_your_home_city')}</label><div class="starts">${starts.map(([c,d])=>`<button class="start ${UI.startCity===c?'on':''}" data-city="${c}" data-act="pickStart" data-args='{"city":"${c}"}'><b>${CITY[c].name}</b><span>${d}</span></button>`).join('')}</div>
|
<label class="f">${tr('title.pick_your_home_city')}</label><div class="starts">${starts.map(([c,d])=>`<button class="start ${UI.startCity===c?'on':''}" data-city="${c}" data-act="pickStart" data-args='{"city":"${c}"}'><b>${CITY[c].name}</b><span>${d}</span></button>`).join('')}</div>
|
||||||
<label class="f">${tr('common.mode')}</label><div class="btns">${[['normal',tr('common.normal')],['sandbox',tr('common.sandbox')]].map(([m,l])=>`<button class="b sm modeb ${(UI.mode||'normal')===m?'pink':'ghost'}" data-m="${m}" data-act="modeSet" data-args='{"m":"${m}"}'>${l}</button>`).join('')}${btn(tr('title.scenarios_amp_weekly_challenge'),'scenarios',{},'sm')}</div>
|
<label class="f">${tr('common.mode')}</label><div class="btns">${[['normal',tr('common.normal')],['sandbox',tr('common.sandbox')]].map(([m,l])=>`<button class="b sm modeb ${(UI.mode||'normal')===m?'pink':'ghost'}" data-m="${m}" data-act="modeSet" data-args='{"m":"${m}"}'>${l}</button>`).join('')}${btn(tr('title.scenarios_amp_weekly_challenge'),'scenarios',{},'sm')}</div>
|
||||||
<label class="f">${tr('common.language')}</label><div class="btns">${segBtns('langSet',LANG,Object.entries(LANGS))}</div>
|
<label class="f" for="langTitle">${tr('common.language')}</label>${langPick('langTitle')}
|
||||||
<div class="btns cta" style="margin-top:16px;justify-content:space-between;align-items:center">${btn(sv?tr('common.start_a_new_network'):tr('common.start_building'),'start',{},'big')}${btn(tr('common.how_to_play'),'help',{},'ghost')}${btn(tr('common.import_a_save'),'importPick',{},'ghost sm')}${btn(tr('common.settings'),'settings',{},'ghost sm')}</div><p class="ver">v${APP_VERSION} · <a href="https://github.com/fjaeckel/seriesoftubes" target="_blank" rel="noopener">${tr('title.source_on_github')}</a> · <a href="${SIGNAL}" target="_blank" rel="noopener">${tr('title.chat_on_signal')}</a> · ${tr('title.cookieless_stats_no_tracking')}</p>`);
|
<div class="btns cta" style="margin-top:16px;justify-content:space-between;align-items:center">${btn(sv?tr('common.start_a_new_network'):tr('common.start_building'),'start',{},'big')}${btn(tr('common.how_to_play'),'help',{},'ghost')}${btn(tr('common.import_a_save'),'importPick',{},'ghost sm')}${btn(tr('common.settings'),'settings',{},'ghost sm')}</div><p class="ver">v${APP_VERSION} · <a href="https://github.com/fjaeckel/seriesoftubes" target="_blank" rel="noopener">${tr('title.source_on_github')}</a> · <a href="${SIGNAL}" target="_blank" rel="noopener">${tr('title.chat_on_signal')}</a> · ${tr('title.cookieless_stats_no_tracking')}</p>`);
|
||||||
$('nmIn').addEventListener('input',e=>{UI.nm=e.target.value;});
|
$('nmIn').addEventListener('input',e=>{UI.nm=e.target.value;});
|
||||||
if(sv){S=migrate(sv);compute();}
|
if(sv){S=migrate(sv);compute();}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
function i18nDom(){if(LANG==='en')return;for(const el of document.querySelectorAll('[data-i18n]'))el.textContent=tr(el.dataset.i18n);
|
function i18nDom(){if(LANG==='en')return;for(const el of document.querySelectorAll('[data-i18n]'))el.textContent=tr(el.dataset.i18n);
|
||||||
for(const a of ['aria-label','title'])for(const el of document.querySelectorAll(`[data-i18n-${a}]`))el.setAttribute(a,tr(el.getAttribute('data-i18n-'+a)));}
|
for(const a of ['aria-label','title'])for(const el of document.querySelectorAll(`[data-i18n-${a}]`))el.setAttribute(a,tr(el.getAttribute('data-i18n-'+a)));}
|
||||||
// One button per [value,label] option; the current one is highlighted.
|
// One button per [value,label] option; the current one is highlighted.
|
||||||
|
// One dropdown instead of a button per language: the list keeps growing, and on phones the system picker opens.
|
||||||
|
// Each language is named in itself (lang= lets screen readers say it right).
|
||||||
|
const langPick=id=>`<select class="pick" id="${id}" data-chg="langSet" aria-label="${tr('common.language')}">${Object.entries(LANGS).map(([v,l])=>`<option value="${v}" lang="${v}"${v===LANG?' selected':''}>${esc(l)}</option>`).join('')}</select>`;
|
||||||
function segBtns(act,cur,opts){return opts.map(([v,l])=>btn(l,act,{v},cur===v?'pink sm':'ghost sm')).join('');}
|
function segBtns(act,cur,opts){return opts.map(([v,l])=>btn(l,act,{v},cur===v?'pink sm':'ghost sm')).join('');}
|
||||||
/* Animation setting: auto follows the system's reduced-motion preference, or force it on or off. */
|
/* Animation setting: auto follows the system's reduced-motion preference, or force it on or off. */
|
||||||
/* Settings are per device (localStorage), not part of the save: they are about how you like to play. */
|
/* Settings are per device (localStorage), not part of the save: they are about how you like to play. */
|
||||||
|
|
@ -23,7 +26,7 @@ function settingsHtml(){const seg=(lab,act,cur,opts,note)=>`<div class="setline"
|
||||||
<h3 class="sub4">${tr('settings.display_and_sound')}</h3>
|
<h3 class="sub4">${tr('settings.display_and_sound')}</h3>
|
||||||
${seg(tr('common.animations'),'animSet',UI.anim||'auto',[['auto',tr('common.auto')],['on',tr('common.on')],['off',tr('common.off')]],tr('settings.auto_follows_your_device_s_reduce'))}
|
${seg(tr('common.animations'),'animSet',UI.anim||'auto',[['auto',tr('common.auto')],['on',tr('common.on')],['off',tr('common.off')]],tr('settings.auto_follows_your_device_s_reduce'))}
|
||||||
${seg(tr('common.sound'),'soundSet',UI.muted?'off':'on',[['on',tr('common.on')],['off',tr('common.off')]])}
|
${seg(tr('common.sound'),'soundSet',UI.muted?'off':'on',[['on',tr('common.on')],['off',tr('common.off')]])}
|
||||||
${seg(tr('common.language'),'langSet',LANG,Object.entries(LANGS))}
|
<div class="setline"><label for="langSel">${tr('common.language')}</label>${langPick('langSel')}</div>
|
||||||
${seg(tr('common.viewport_info'),'vpSet',VP_T?'on':'off',[['on',tr('common.on')],['off',tr('common.off')]],tr('settings.for_reporting_layout_bugs_shows_what'))}
|
${seg(tr('common.viewport_info'),'vpSet',VP_T?'on':'off',[['on',tr('common.on')],['off',tr('common.off')]],tr('settings.for_reporting_layout_bugs_shows_what'))}
|
||||||
${installRow()}<div class="btns" style="margin-top:12px">${btn(tr('common.done_8dd3'),'settingsClose',{},'pink')}</div>`;}
|
${installRow()}<div class="btns" style="margin-top:12px">${btn(tr('common.done_8dd3'),'settingsClose',{},'pink')}</div>`;}
|
||||||
const refreshSettings=()=>{if(UI.setOpen)openModal(settingsHtml());};
|
const refreshSettings=()=>{if(UI.setOpen)openModal(settingsHtml());};
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ let pressing=false;
|
||||||
document.addEventListener('pointerdown',e=>{if(e.target.closest('#panel,#left,#dash,#bankBox,#modal,#tabbar,#toasts'))pressing=true;});
|
document.addEventListener('pointerdown',e=>{if(e.target.closest('#panel,#left,#dash,#bankBox,#modal,#tabbar,#toasts'))pressing=true;});
|
||||||
addEventListener('pointerup',()=>setTimeout(()=>pressing=false,0));
|
addEventListener('pointerup',()=>setTimeout(()=>pressing=false,0));
|
||||||
addEventListener('pointercancel',()=>{pressing=false;});addEventListener('blur',()=>{pressing=false;});
|
addEventListener('pointercancel',()=>{pressing=false;});addEventListener('blur',()=>{pressing=false;});
|
||||||
document.addEventListener('change',e=>{const el=e.target.closest('[data-chg]');if(!el||!S)return;const fn=ACT[el.dataset.chg];if(fn)fn({v:el.value});});
|
document.addEventListener('change',e=>{const el=e.target.closest('[data-chg]');if(!el||(!S&&el.dataset.chg!=='langSet'))return;const fn=ACT[el.dataset.chg];if(fn)fn({v:el.value});});
|
||||||
/* Taps that land on the wrong thing (#44): a real tap only fires the button it went down on, never something that
|
/* Taps that land on the wrong thing (#44): a real tap only fires the button it went down on, never something that
|
||||||
appeared or moved under the finger, nothing behind a menu that opened or closed mid-tap, and no toast button in
|
appeared or moved under the finger, nothing behind a menu that opened or closed mid-tap, and no toast button in
|
||||||
the first half second after the toast popped up. Synthetic clicks (keyboard, tests) are not affected. */
|
the first half second after the toast popped up. Synthetic clicks (keyboard, tests) are not affected. */
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,11 @@
|
||||||
@media (prefers-reduced-motion:reduce){:root:not(.anim-force) .coach-glow{animation:none;outline:3px solid #FF4F9A}}
|
@media (prefers-reduced-motion:reduce){:root:not(.anim-force) .coach-glow{animation:none;outline:3px solid #FF4F9A}}
|
||||||
:root.no-anim .coach-glow{outline:3px solid #FF4F9A}
|
:root.no-anim .coach-glow{outline:3px solid #FF4F9A}
|
||||||
.setline{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:4px 0}
|
.setline{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:4px 0}
|
||||||
.setline>span{font-weight:800}
|
.setline>span,.setline>label{font-weight:800}
|
||||||
|
/* Dropdowns that look like the game's buttons. 16px text: iOS zooms into anything smaller when it is tapped. */
|
||||||
|
select.pick{-webkit-appearance:none;appearance:none;font:800 16px var(--display);color:var(--ink);background:var(--soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%231E2640' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;border:3px solid var(--ink);border-radius:12px;padding:6px 36px 6px 12px;min-height:44px;cursor:pointer;box-shadow:0 3px 0 var(--ink)}
|
||||||
|
select.pick:focus-visible{outline:3px solid #FF4F9A;outline-offset:2px}
|
||||||
|
label.f+select.pick{width:100%}
|
||||||
.thb{font:inherit;font-weight:900;background:none;border:0;padding:0;cursor:pointer;color:inherit}
|
.thb{font:inherit;font-weight:900;background:none;border:0;padding:0;cursor:pointer;color:inherit}
|
||||||
.ttop{margin:4px 0;padding:4px 8px;border-left:3px solid #FF8A3D;background:#FFF6EC;border-radius:6px}
|
.ttop{margin:4px 0;padding:4px 8px;border-left:3px solid #FF8A3D;background:#FFF6EC;border-radius:6px}
|
||||||
.ibx{border:2px solid var(--line,#DDE3EE);border-radius:12px;padding:8px 10px;margin:8px 0;background:#fff}.ibx .nm{font-weight:800}.ibx.mp{border-color:#FF5A5F;background:#FFF1F1}.ibx.ai{border-color:#8E5CF7;background:#F7F2FF}.ibx .term{font-size:11.5px;white-space:pre-wrap;max-height:180px;overflow:auto}.ibx .cnt{display:inline-block;min-width:18px;padding:0 5px;border-radius:9px;background:var(--me);color:#fff;font-size:11px;text-align:center}.ibx .cnt.red{background:#FF5A5F}
|
.ibx{border:2px solid var(--line,#DDE3EE);border-radius:12px;padding:8px 10px;margin:8px 0;background:#fff}.ibx .nm{font-weight:800}.ibx.mp{border-color:#FF5A5F;background:#FFF1F1}.ibx.ai{border-color:#8E5CF7;background:#F7F2FF}.ibx .term{font-size:11.5px;white-space:pre-wrap;max-height:180px;overflow:auto}.ibx .cnt{display:inline-block;min-width:18px;padding:0 5px;border-radius:9px;background:var(--me);color:#fff;font-size:11px;text-align:center}.ibx .cnt.red{background:#FF5A5F}
|
||||||
|
|
|
||||||
|
|
@ -108,9 +108,10 @@ test('the static markup is translated by label', () => {
|
||||||
assert.equal(ev("document.querySelector('[data-act=help]').getAttribute('aria-label')"), ev("tr('common.how_to_play')"));
|
assert.equal(ev("document.querySelector('[data-act=help]').getAttribute('aria-label')"), ev("tr('common.how_to_play')"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('the language buttons on the title screen work before any game exists', () => {
|
test('the language dropdown on the title screen works before any game exists', () => {
|
||||||
const { ev } = load();
|
const { ev } = load();
|
||||||
ev("[...document.querySelectorAll('#modalCard [data-act=langSet]')].find(b=>b.textContent==='Italiano').click()");
|
assert.equal(ev('S'), null);
|
||||||
|
ev("const s=document.querySelector('#modalCard select#langTitle');s.value='it';s.dispatchEvent(new Event('change',{bubbles:true}))");
|
||||||
assert.equal(ev("localStorage.getItem('sot-lang')"), 'it');
|
assert.equal(ev("localStorage.getItem('sot-lang')"), 'it');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
39
tests/language-picker.test.js
Normal file
39
tests/language-picker.test.js
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const { load } = require('./harness');
|
||||||
|
|
||||||
|
const pick = (ev, id) => JSON.parse(ev(`(()=>{const s=document.getElementById('${id}');return JSON.stringify(s&&{tag:s.tagName,value:s.value,chg:s.dataset.chg,
|
||||||
|
opts:[...s.options].map(o=>[o.value,o.textContent,o.lang]),label:(document.querySelector('label[for=${id}]')||{}).textContent});})()`));
|
||||||
|
|
||||||
|
test('language is one dropdown on the title screen and in Settings, in every language, with the current one selected', () => {
|
||||||
|
for (const lang of ['en', 'it', 'pt', 'fr', 'es']) {
|
||||||
|
const { ev, errors } = load(lang === 'en' ? {} : { lang });
|
||||||
|
const langs = JSON.parse(ev('JSON.stringify(Object.entries(LANGS))'));
|
||||||
|
const title = pick(ev, 'langTitle');
|
||||||
|
assert.equal(title.tag, 'SELECT', `${lang}: title screen`);
|
||||||
|
assert.equal(title.value, lang);
|
||||||
|
assert.deepEqual(title.opts, langs.map(([v, l]) => [v, l, v]), `${lang}: every language, named in itself`);
|
||||||
|
assert.equal(title.label, ev("tr('common.language')"), `${lang}: labelled`);
|
||||||
|
assert.equal(ev("document.querySelectorAll('#modalCard [data-act=langSet]').length"), 0, `${lang}: no language buttons left`);
|
||||||
|
ev("ACT.start({});ACT.settings()");
|
||||||
|
const set = pick(ev, 'langSel');
|
||||||
|
assert.equal(set.value, lang, `${lang}: settings`);
|
||||||
|
assert.equal(set.label, ev("tr('common.language')"));
|
||||||
|
assert.deepEqual(errors, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changing the dropdown in Settings switches language and keeps the game', () => {
|
||||||
|
const { ev, errors } = load();
|
||||||
|
ev("ACT.start({});dayTick();ACT.settings();const s=document.getElementById('langSel');s.value='fr';s.dispatchEvent(new Event('change',{bubbles:true}))");
|
||||||
|
assert.equal(ev("localStorage.getItem('sot-lang')"), 'fr');
|
||||||
|
assert.ok(ev("localStorage.getItem('sot-save-v1')"), 'saved before reloading');
|
||||||
|
assert.deepEqual(errors, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the dropdown fits a phone', () => {
|
||||||
|
const { ev, errors } = load();
|
||||||
|
ev('window.innerWidth=360;showTitle()');
|
||||||
|
assert.ok(ev("document.getElementById('langTitle').classList.contains('pick')"));
|
||||||
|
assert.deepEqual(errors, []);
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue