Start anywhere: pick any city with transit as your home
This commit is contained in:
parent
87fac683f0
commit
8b8bfadbaa
11 changed files with 78 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
- Start anywhere: besides the five suggested home cities, the new game screen now lets you pick any city on the map that sells transit, grouped by continent.
|
||||
- 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.
|
||||
- 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.
|
||||
|
|
|
|||
|
|
@ -3012,11 +3012,13 @@
|
|||
"supply_chain.until_date_at_p":"hasta {date}, a +{p}",
|
||||
"supply_chain.what_p_n_days_left":"{what} +{p} · quedan {n} días",
|
||||
"supply_chain.your_price_lock_covers_you_until":"Tu precio fijo te cubre hasta {date}.",
|
||||
"title.anywhere_else":"En otro lugar",
|
||||
"title.asia_hub_great_peering_far_from":"Hub de Asia. Gran peering, lejos de casa.",
|
||||
"title.back_to_my_network":"Volver a mi red",
|
||||
"title.big_hungry_market_few_providers":"Mercado enorme y hambriento, pocos proveedores.",
|
||||
"title.build_an_internet_lay_fiber_between":"Construye un internet. Tiende fibra entre ciudades, compra tránsito, haz peering en intercambios, firma con empresas y mantén contentos a los eyeballs mientras retroexcavadoras, tiburones y fugas de rutas hacen lo posible por detenerte.",
|
||||
"title.chat_on_signal":"Chatea en Signal",
|
||||
"title.choose_a_city":"Elige una ciudad…",
|
||||
"title.continue_name_date":"Continuar {name} · {date}",
|
||||
"title.cookieless_stats_no_tracking":"Estadísticas sin cookies, sin rastreo",
|
||||
"title.crossroads_of_europe_de_kicks_ix":"La encrucijada de Europa. DE-KICKS IX, tránsito barato.",
|
||||
|
|
|
|||
|
|
@ -3012,11 +3012,13 @@
|
|||
"supply_chain.until_date_at_p":"jusqu’au {date}, à +{p}",
|
||||
"supply_chain.what_p_n_days_left":"{what} +{p} · encore {n} jours",
|
||||
"supply_chain.your_price_lock_covers_you_until":"Votre blocage des prix vous couvre jusqu’au {date}.",
|
||||
"title.anywhere_else":"Ailleurs",
|
||||
"title.asia_hub_great_peering_far_from":"Hub de l’Asie. Super peering, loin de chez soi.",
|
||||
"title.back_to_my_network":"Retour à mon réseau",
|
||||
"title.big_hungry_market_few_providers":"Gros marché affamé, peu d’opérateurs.",
|
||||
"title.build_an_internet_lay_fiber_between":"Construis un Internet. Pose de la fibre entre les villes, achète du transit, fais du peering aux IX, signe des entreprises et garde les eyeballs contents pendant que pelleteuses, requins et fuites de routes font tout pour t’arrêter.",
|
||||
"title.chat_on_signal":"Discuter sur Signal",
|
||||
"title.choose_a_city":"Choisis une ville…",
|
||||
"title.continue_name_date":"Continuer {name} · {date}",
|
||||
"title.cookieless_stats_no_tracking":"Stats sans cookies, sans pistage",
|
||||
"title.crossroads_of_europe_de_kicks_ix":"Carrefour de l’Europe. IX DE-KICKS, transit pas cher.",
|
||||
|
|
|
|||
|
|
@ -3012,11 +3012,13 @@
|
|||
"supply_chain.until_date_at_p":"fino al {date}, a +{p}",
|
||||
"supply_chain.what_p_n_days_left":"{what} +{p} · {n} giorni rimasti",
|
||||
"supply_chain.your_price_lock_covers_you_until":"Il tuo blocco dei prezzi ti copre fino al {date}.",
|
||||
"title.anywhere_else":"Altrove",
|
||||
"title.asia_hub_great_peering_far_from":"Hub dell’Asia. Ottimo peering, lontano da casa.",
|
||||
"title.back_to_my_network":"Torna alla mia rete",
|
||||
"title.big_hungry_market_few_providers":"Mercato grande e affamato, pochi provider.",
|
||||
"title.build_an_internet_lay_fiber_between":"Costruisci un internet. Posa fibra tra le città, compra transit, fai peering agli exchange, metti sotto contratto le aziende e tieni contenti gli eyeball, mentre ruspe, squali e route leak fanno di tutto per fermarti.",
|
||||
"title.chat_on_signal":"Chat su Signal",
|
||||
"title.choose_a_city":"Scegli una città…",
|
||||
"title.continue_name_date":"Continua {name} · {date}",
|
||||
"title.cookieless_stats_no_tracking":"Statistiche senza cookie, nessun tracciamento",
|
||||
"title.crossroads_of_europe_de_kicks_ix":"Crocevia d’Europa. IX DE-KICKS, transit economico.",
|
||||
|
|
|
|||
|
|
@ -3012,11 +3012,13 @@
|
|||
"supply_chain.until_date_at_p":"até {date}, a +{p}",
|
||||
"supply_chain.what_p_n_days_left":"{what} +{p} · faltam {n} dias",
|
||||
"supply_chain.your_price_lock_covers_you_until":"Seu congelamento de preços te cobre até {date}.",
|
||||
"title.anywhere_else":"Outro lugar",
|
||||
"title.asia_hub_great_peering_far_from":"Hub da Ásia. Ótimo peering, longe de casa.",
|
||||
"title.back_to_my_network":"Voltar para minha rede",
|
||||
"title.big_hungry_market_few_providers":"Mercado grande e faminto, poucos provedores.",
|
||||
"title.build_an_internet_lay_fiber_between":"Construa uma internet. Lance fibra entre cidades, compre transit, faça peering nos exchanges, feche contratos com empresas e mantenha os eyeballs felizes enquanto retroescavadeiras, tubarões e route leaks fazem de tudo para te parar.",
|
||||
"title.chat_on_signal":"Chat no Signal",
|
||||
"title.choose_a_city":"Escolha uma cidade…",
|
||||
"title.continue_name_date":"Continuar {name} · {date}",
|
||||
"title.cookieless_stats_no_tracking":"Estatísticas sem cookies, sem rastreamento",
|
||||
"title.crossroads_of_europe_de_kicks_ix":"Encruzilhada da Europa. IX DE-KICKS, transit barato.",
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
Object.assign(ACT,{
|
||||
randomName:()=>{const input=$('nmIn');if(input)input.value=UI.nm=randomNetworkName(input.value);},
|
||||
start:()=>{const nm=(($('nmIn')&&$('nmIn').value)||randomNetworkName()).slice(0,24);beginGame(nm,UI.startCity,{mode:UI.mode==='sandbox'?'sandbox':'normal'});},
|
||||
start:()=>{const nm=(($('nmIn')&&$('nmIn').value)||randomNetworkName()).slice(0,24);beginGame(nm,homeOk(UI.startCity)?UI.startCity:'fra',{mode:UI.mode==='sandbox'?'sandbox':'normal'});},
|
||||
modeSet:({m})=>{UI.mode=m;document.querySelectorAll('.modeb').forEach(b=>b.classList.toggle('pink',b.dataset.m===m));document.querySelectorAll('.modeb').forEach(b=>b.classList.toggle('ghost',b.dataset.m!==m));},
|
||||
scenarios:()=>{UI.nm=(($('nmIn')&&$('nmIn').value)||UI.nm||(S&&S.name)||randomNetworkName()).slice(0,24);scenarioModal();},
|
||||
startScn:({id,sure})=>{const sc=SCN.find(x=>x.id===id);if(!sc)return;if(!sure&&S&&UI.started&&!S.lost&&!(S.scn&&(S.scn.done||S.scn.failed))){openModal(`<h2 style="font-size:26px">${tr('game_and_settings.start_name',{name:esc(sc.n)})}</h2><p class="tagline">${tr('game_and_settings.name_will_be_replaced_export_it',{name:esc(S.name)})}</p><div class="btns">${btn(tr('game_and_settings.start_the_scenario'),'startScn',{id,sure:1},'pink big')}${btn(tr('common.keep_playing'),'closeModal',{},'ghost big')}</div>`);return;}beginGame(UI.nm||(S&&S.name)||randomNetworkName(),sc.city,{scn:sc});},
|
||||
startWeekly:({sure}={})=>{if(!sure&&S&&UI.started&&!S.lost&&!(S.scn&&(S.scn.done||S.scn.failed))){openModal(`<h2 style="font-size:26px">${tr('game_and_settings.start_the_weekly_challenge')}</h2><p class="tagline">${tr('game_and_settings.name_will_be_replaced_export_it',{name:esc(S.name)})}</p><div class="btns">${btn(tr('game_and_settings.start_the_challenge'),'startWeekly',{sure:1},'pink big')}${btn(tr('common.keep_playing'),'closeModal',{},'ghost big')}</div>`);return;}const wk=weekly();beginGame(UI.nm||(S&&S.name)||randomNetworkName(),wk.city,{scn:wk,seed:wk.seed});},
|
||||
pickStart:({city})=>{UI.startCity=city;document.querySelectorAll('.start').forEach(b=>b.classList.toggle('on',b.dataset.city===city));},
|
||||
pickStart:({city})=>{if(!homeOk(city))return;UI.startCity=city;document.querySelectorAll('.start').forEach(b=>b.classList.toggle('on',b.dataset.city===city||(b.classList.contains('own')&&!START5.includes(city))));const s=$('homeSel');if(s&&START5.includes(city))s.value='';},
|
||||
pickHome:({v})=>{if(v)ACT.pickStart({city:v});else ACT.pickStart({city:'fra'});},
|
||||
cont:()=>{migrate(S);track('game_continue',true);UI.started=true;closeModal();renderAll();},
|
||||
newgame:()=>{try{localStorage.removeItem('sot-save-v1');}catch(e){}S=null;UI.started=false;UI.sel=null;UI.nm=null;$('dash').hidden=true;$('bankBox').hidden=true;renderAll();showTitle();},
|
||||
keepPlaying:()=>{closeModal();},
|
||||
|
|
|
|||
|
|
@ -1,3 +1,10 @@
|
|||
// Five suggested homes, or any city with someone selling transit there. Hidden cities and China (which needs
|
||||
// a license first) can't be a home, and neither can a city where nobody sells transit: you'd start cut off.
|
||||
const homeOk=c=>own(CITY,c)&&!CITY[c].off&&!CITY[c].cn&&NETS.some(n=>sellsAt(n,c));
|
||||
const START5=['fra','nyc','sin','sao','syd'];
|
||||
function homePick(){const cs=Object.keys(CITY).filter(homeOk),cur=START5.includes(UI.startCity)?'':UI.startCity;
|
||||
return `<select class="pick" id="homeSel" data-chg="pickHome" aria-label="${tr('title.anywhere_else')}"><option value="">${tr('title.choose_a_city')}</option>${Object.keys(REG).map(r=>{const g=cs.filter(c=>CITY[c].reg===r).sort((a,b)=>CITY[a].name.localeCompare(CITY[b].name));
|
||||
return g.length?`<optgroup label="${esc(REG[r])}">${g.map(c=>`<option value="${c}"${c===cur?' selected':''}>${esc(CITY[c].name)}</option>`).join('')}</optgroup>`:'';}).join('')}</select>`;}
|
||||
function showTitle(){
|
||||
const sv=loadSave();
|
||||
if(UI.nm==null)UI.nm=randomNetworkName();
|
||||
|
|
@ -7,7 +14,7 @@ function showTitle(){
|
|||
<p class="tagline">${tr('title.build_an_internet_lay_fiber_between')}</p>${plugHtml(false)}${isPhone()?installRow():''}
|
||||
${sv?`<div class="btns" style="margin-bottom:6px">${btn(tr('title.continue_name_date',{name:esc(sv.name),date:dateStr(sv.day)}),'cont',{},'pink big')}</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('')}<label class="start own ${START5.includes(UI.startCity)?'':'on'}" for="homeSel"><b>${tr('title.anywhere_else')}</b>${homePick()}</label></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" 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>`);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ let pressing=false;
|
|||
document.addEventListener('pointerdown',e=>{if(e.target.closest('#panel,#left,#dash,#bankBox,#modal,#tabbar,#toasts'))pressing=true;});
|
||||
addEventListener('pointerup',()=>setTimeout(()=>pressing=false,0));
|
||||
addEventListener('pointercancel',()=>{pressing=false;});addEventListener('blur',()=>{pressing=false;});
|
||||
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});});
|
||||
document.addEventListener('change',e=>{const el=e.target.closest('[data-chg]');if(!el||(!S&&!['langSet','pickHome'].includes(el.dataset.chg)))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
|
||||
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. */
|
||||
|
|
|
|||
|
|
@ -3013,11 +3013,13 @@
|
|||
"supply_chain.until_date_at_p":"until {date}, at +{p}",
|
||||
"supply_chain.what_p_n_days_left":"{what} +{p} · {n} days left",
|
||||
"supply_chain.your_price_lock_covers_you_until":"Your price lock covers you until {date}.",
|
||||
"title.anywhere_else":"Anywhere else",
|
||||
"title.asia_hub_great_peering_far_from":"Asia hub. Great peering, far from home.",
|
||||
"title.back_to_my_network":"Back to my network",
|
||||
"title.big_hungry_market_few_providers":"Big hungry market, few providers.",
|
||||
"title.build_an_internet_lay_fiber_between":"Build an internet. Lay fiber between cities, buy transit, peer at exchanges, sign up businesses, and keep the eyeballs happy while backhoes, sharks and route leaks do their best to stop you.",
|
||||
"title.chat_on_signal":"Chat on Signal",
|
||||
"title.choose_a_city":"Choose a city…",
|
||||
"title.continue_name_date":"Continue {name} · {date}",
|
||||
"title.cookieless_stats_no_tracking":"Cookieless stats, no tracking",
|
||||
"title.crossroads_of_europe_de_kicks_ix":"Crossroads of Europe. DE-KICKS IX, cheap transit.",
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ input.t{width:100%;box-sizing:border-box;border:3px solid var(--ink);border-radi
|
|||
.start.on{background:#FFE3F0;border-color:var(--me);box-shadow:0 3px 0 var(--me)}
|
||||
.start b{font-family:var(--display);font-size:17px;display:block}
|
||||
.start span{font-size:12px;color:var(--ink2);line-height:1.3;display:block}
|
||||
.start.own select.pick{width:100%;margin-top:4px;min-height:40px;font-size:16px;box-shadow:none;border-width:2px}
|
||||
.tiers{display:grid;gap:7px;margin-top:10px}
|
||||
.tierbtn{display:flex;align-items:center;gap:10px;border:3px solid var(--ink);border-radius:13px;padding:8px 12px;background:var(--paper);cursor:pointer;box-shadow:0 3px 0 var(--ink);text-align:left}
|
||||
.tierbtn:hover{background:#FFF6CF}
|
||||
|
|
|
|||
54
tests/any-home-city.test.js
Normal file
54
tests/any-home-city.test.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const choose = (ev, v) => ev(`(()=>{const s=document.getElementById('homeSel');s.value=${JSON.stringify(v)};s.dispatchEvent(new Event('change',{bubbles:true}));})()`);
|
||||
const onTiles = ev => JSON.parse(ev("JSON.stringify([...document.querySelectorAll('.starts .start.on')].map(b=>b.dataset.city||'own'))"));
|
||||
|
||||
test('the title screen offers five homes and a sixth tile for any city, grouped by continent', () => {
|
||||
const { ev, errors } = load();
|
||||
assert.equal(ev('S'), null, 'before any game exists');
|
||||
assert.equal(ev("document.querySelectorAll('.starts .start').length"), 6);
|
||||
const opts = JSON.parse(ev("JSON.stringify([...document.querySelectorAll('#homeSel option')].map(o=>o.value).filter(Boolean))"));
|
||||
assert.ok(opts.length > 150, `lots of cities (${opts.length})`);
|
||||
assert.ok(opts.every(c => ev(`homeOk('${c}')`)), 'only cities that work as a home');
|
||||
assert.ok(!opts.some(c => ev(`!!CITY['${c}'].cn||!!CITY['${c}'].off`)), 'no hidden or Chinese cities');
|
||||
assert.ok(!opts.includes('stg'), 'no city without transit to buy');
|
||||
assert.ok(ev("document.querySelectorAll('#homeSel optgroup').length") >= 5, 'grouped by continent');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('picking any city starts the network there, and the tiles follow the choice', () => {
|
||||
const { ev, errors } = load();
|
||||
choose(ev, 'lis');
|
||||
assert.equal(ev('UI.startCity'), 'lis');
|
||||
assert.deepEqual(onTiles(ev), ['own'], 'the sixth tile lights up');
|
||||
ev("document.querySelector('.start[data-city=nyc]').click()");
|
||||
assert.deepEqual(onTiles(ev), ['nyc'], 'a suggested tile takes over again');
|
||||
assert.equal(ev("document.getElementById('homeSel').value"), '', 'and the dropdown resets');
|
||||
choose(ev, 'akl');
|
||||
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip()");
|
||||
assert.equal(ev('S.home'), 'akl');
|
||||
assert.ok(ev("!!S.pops.akl"), 'the first POP is in Auckland');
|
||||
assert.ok(ev("NETS.some(n=>sellsAt(n,'akl'))"), 'with transit to buy');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a home that cannot work is refused, and the game falls back to Frankfurt', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.pickStart({city:'stg'});ACT.pickStart({city:'pek'});ACT.pickStart({city:'nowhere'})");
|
||||
assert.equal(ev('UI.startCity'), 'fra');
|
||||
ev("UI.startCity='pek';ACT.start({})");
|
||||
assert.equal(ev('S.home'), 'fra');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the sixth tile works on a phone and in every language', () => {
|
||||
for (const lang of ['en', 'it', 'pt', 'fr', 'es']) {
|
||||
const { ev, errors } = load(lang === 'en' ? {} : { lang });
|
||||
ev('window.innerWidth=360;showTitle()');
|
||||
assert.equal(ev("document.querySelector('label.start.own b').textContent"), ev("tr('title.anywhere_else')"), lang);
|
||||
if (lang !== 'en') assert.notEqual(ev("tr('title.anywhere_else')"), 'Anywhere else', `${lang}: translated`);
|
||||
assert.deepEqual(errors, []);
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue