Pitch installing the app to phone players before a new game

This commit is contained in:
Frederic Jung 2026-10-25 10:08:26 +01:00
parent cf3d333b81
commit 933d57228a
No known key found for this signature in database
3 changed files with 85 additions and 10 deletions

View file

@ -2024,9 +2024,6 @@
"Full screen, works offline, one tap from your home screen.":"A schermo intero, funziona offline, a un tocco dalla schermata Home.",
"Install":"Installa",
"Game":"Gioco",
"Play it like an app":"Giocalo come un’app",
"Add to your home screen":"Aggiungi alla schermata Home",
"On iPhone and iPad: tap the Share button in Safari, then “Add to Home Screen”. Series of Tubes then opens full screen, like an app, and keeps working offline.":"Su iPhone e iPad: tocca il pulsante Condividi in Safari, poi “Aggiungi alla schermata Home”. Series of Tubes si aprirà a schermo intero, come un’app, e funzionerà anche offline.",
"Speed":"Velocità",
"The North’s hub, with its own exchange and very damp air-conditioning intakes. Cables to Ireland and Denmark come ashore up the coast.":"Lo snodo del Nord, con il suo exchange e prese d’aria dei condizionatori molto umide. I cavi per l’Irlanda e la Danimarca arrivano sulla costa poco più su.",
"Scotland’s capital. North Sea cables to Norway and the Faroes land up the coast.":"La capitale della Scozia. I cavi del Mare del Nord verso la Norvegia e le Fær Øer approdano lungo la costa.",
@ -2101,4 +2098,28 @@
"{n} connection":"{n} connessione",
"{n} connections":"{n} connessioni",
"+{n} more":"+{n} altre",
"<b>Installed!</b><br>Open Series of Tubes from your home screen. Your saves come along.":"<b>Installato!</b><br>Apri Series of Tubes dalla schermata Home. I tuoi salvataggi vengono con te.",
"Best played as an app":"Meglio come app",
"Install it before you start: a game begun in Safari stays in Safari.":"Installala prima di iniziare: una partita cominciata in Safari resta in Safari.",
"Tap <b>Share</b> {icon} in the browser toolbar.":"Tocca <b>Condividi</b> {icon} nella barra del browser.",
"Tap <b>Add to Home Screen</b>. You may need to scroll down, or tap <b>More</b> first.":"Tocca <b>Aggiungi alla schermata Home</b>. Potrebbe servire scorrere in basso, o toccare prima <b>Altro</b>.",
"Open <b>Series of Tubes</b> from your home screen and start your network there.":"Apri <b>Series of Tubes</b> dalla schermata Home e avvia lì la tua rete.",
"Open your browser menu (⋮).":"Apri il menu del browser (⋮).",
"Tap <b>Install app</b> or <b>Add to Home screen</b>.":"Tocca <b>Installa app</b> o <b>Aggiungi a schermata Home</b>.",
"Open <b>Series of Tubes</b> from your home screen.":"Apri <b>Series of Tubes</b> dalla schermata Home.",
"Before you start":"Prima di iniziare",
"Play it as an app":"Giocalo come un’app",
"Series of Tubes is made for your home screen. It takes ten seconds, costs nothing, and it is a much better game there:":"Series of Tubes è fatto per la schermata Home. Ci vogliono dieci secondi, non costa nulla, e lì è un gioco molto migliore:",
"Full screen.":"Schermo intero.",
"No browser bars, a lot more map.":"Niente barre del browser, molta più mappa.",
"Works offline.":"Funziona offline.",
"Build your backbone on the train or on a plane.":"Costruisci la tua dorsale in treno o in aereo.",
"Your save stays safe.":"Il salvataggio resta al sicuro.",
"Safari can clear the data of websites you have not opened for a week. A home-screen app keeps its own.":"Safari può cancellare i dati dei siti che non apri da una settimana. Un’app sulla schermata Home tiene i suoi.",
"Install first.":"Prima installa.",
"On iPhone, a game started in Safari does not carry over to the home-screen app.":"Su iPhone, una partita iniziata in Safari non passa all’app sulla schermata Home.",
"One tap away.":"A un tocco di distanza.",
"It opens straight into your network, like any other app.":"Si apre direttamente sulla tua rete, come qualsiasi altra app.",
"Install the app":"Installa l’app",
"Play in the browser anyway":"Gioca comunque nel browser",
};

View file

@ -373,6 +373,9 @@ input.t{width:100%;box-sizing:border-box;border:3px solid var(--ink);border-radi
A decluttered, app-like layout: a one-row status strip at the top, a tab bar at the bottom
(play, speed, goals, deals, NOC, networks), and bottom sheets you drag up, down or away. */
html,body{overscroll-behavior:none}
.pitch{list-style:none;padding:0;margin:10px 0}.pitch li{margin:7px 0;line-height:1.38;font-size:14px}.pitch li.warn{background:#FFF4D6;border:2px solid var(--ink);border-radius:10px;padding:6px 8px}
.isteps{padding-left:22px;margin:8px 0 4px}.isteps li{margin:5px 0;line-height:1.38;font-size:14px}.isteps svg{vertical-align:-3px}
.icard{margin:8px 0 10px;border:2.5px solid var(--ink);border-radius:14px;padding:8px 10px;background:#FFF4D6}
/* iPhone home-screen app with a viewport shorter than the screen: the page box takes the real screen height
and becomes the containing block for everything fixed, so bottom-anchored UI reaches the bottom. */
html.iosfix,html.iosfix body{height:var(--app-h)}
@ -1275,7 +1278,7 @@ const WEEK_MODS=[{id:'pricey',n:tr('Transit costs 30% more')},{id:'chaos',n:tr('
function weekly(){const {y,w}=isoWeek(new Date());let r=(y*100+w)*2654435761>>>0;const nx=()=>{r=(r*1103515245+12345)>>>0;return r/4294967296;};const city=WEEK_CITIES[Math.floor(nx()*WEEK_CITIES.length)];const mods=[];while(mods.length<2){const m=WEEK_MODS[Math.floor(nx()*WEEK_MODS.length)];if(!mods.includes(m))mods.push(m);}return {id:'weekly',key:`${y}-W${String(w).padStart(2,'0')}`,seed:y*100+w,city,mods,days:365};}
const scnRule=k=>!!(S&&S.scn&&S.scn.rules&&S.scn.rules[k]);
function scnHof(){try{return JSON.parse(localStorage.getItem('sot-scn')||'{}')||{};}catch(e){return {};}}
function beginGame(nm,city,o={}){newGame(nm,city);S.mode=o.mode||'normal';
function beginGame(nm,city,o={}){if(needPitch()&&!UI.pitched){UI.pendGame=[nm,city,o];openModal(pitchHtml(true));return;}newGame(nm,city);S.mode=o.mode||'normal';
if(S.mode==='sandbox'){S.cash=1e9;S.lvl=4;S.nextFail=1e9;S.nextEvent=1e9;}
if(o.scn){const sc=o.scn;S.scn={id:sc.id,rules:sc.rules||{},days:sc.days,name:sc.n||tr('Weekly challenge {key}',{key:sc.key}),key:sc.key||null,mods:(sc.mods||[]).map(m=>m.id)};S.rng=(o.seed||hstr(sc.id))|0;S.mode='scenario';S.asn=200000+Math.floor(Math.random()*15000);
if(sc.cash)S.cash=sc.cash;if(sc.setup)sc.setup();
@ -2416,7 +2419,8 @@ const ACT={
phonePlay:()=>{haptic(10);if(UI.speed){UI.lastSpeed=UI.speed;UI.speed=0;}else UI.speed=UI.lastSpeed||1;renderHUD();},
phoneSpeed:()=>{haptic(8);const cur=UI.speed||UI.lastSpeed||1,i=SPEEDS.indexOf(cur),n=SPEEDS[(i+1)%SPEEDS.length];UI.speed=n;UI.lastSpeed=n;renderHUD();},
install:()=>{if(installEvt){installEvt.prompt();installEvt.userChoice.finally(()=>{installEvt=null;});return;}
openModal(`<div style="display:flex;align-items:center"><h2 style="font-size:24px">${tr('Add to your home screen')}</h2><button class="x" data-act="closeModal" aria-label="${tr('Close')}">×</button></div><p class="lead" style="margin-top:8px">${tr('On iPhone and iPad: tap the Share button in Safari, then “Add to Home Screen”. Series of Tubes then opens full screen, like an app, and keeps working offline.')}</p><div class="btns">${btn(tr('Got it'),'closeModal',{},'pink')}</div>`);},
openModal(pitchHtml(false));},
pitchSkip:()=>{const p=UI.pendGame;UI.pendGame=null;UI.pitched=true;if(p)beginGame(...p);else closeModal();},
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();},
selLink:({id})=>{UI.sel={type:'link',id};UI.confirm=null;renderPanel();},
buildPop:({city})=>{if(S.pops[city])return;if(cnCity(city)&&!cnOk()){toast(tr('<b>You need a license first.</b><br>Foreign networks need a joint venture to build in mainland China.'),'bad');sfx('err');return;}if(!spend(popCost(city)))return;S.pops[city]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};floater(CITY[city].x,CITY[city].y-30,tr('New POP!'),'#FF4F9A');UI.tab='cust';after();},
@ -2586,7 +2590,7 @@ const ACT={
importPick:()=>{let f=$('importIn');if(!f){f=document.createElement('input');f.type='file';f.accept='.json,application/json';f.id='importIn';f.hidden=true;document.body.appendChild(f);f.addEventListener('change',()=>{importFile(f.files[0]);f.value='';});}f.click();},
importGo:()=>{const s0=UI.importing;if(!s0)return;UI.importing=null;const prev=S;try{S=migrate(JSON.parse(JSON.stringify(s0)));compute();checkGoals();renderAll();}catch(e){S=prev;if(S)compute();renderAll();toast(tr('<b>Import failed.</b><br>That save is damaged and could not be loaded. Your current game is untouched.'),'bad');sfx('err');return;}UI.confirm=null;$('bankBox').hidden=true;$('dash').hidden=true;UI.started=true;UI.sel=null;UI.speed=S.uiSpeed===undefined?1:S.uiSpeed;if(S.cam&&isFinite(S.cam.x))Object.assign(cam,S.cam);else{const h=CITY[S.home];if(h){cam.x=h.x;cam.y=h.y;}}closeModal();$('modal').hidden=true;compute();renderAll();save();toast(tr('<b>Welcome back, {name}.</b><br>Imported and saved on this device.',{name:esc(S.name)}),'good');sfx('coin');track('game_import');},
menu:()=>{if(!S||!UI.started){showTitle();return;}openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">AS${S.asn} · ${esc(dateStr(S.day))} · ${tierLabel()}</div><h2 style="font-size:28px">${esc(S.name)}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('Close')}">×</button></div>
<p class="tagline">${tr('Your game saves itself every few seconds on this device.')}</p>
<p class="tagline">${tr('Your game saves itself every few seconds on this device.')}</p>${isPhone()?installRow():''}
<div class="menu-list">
${btn(tr('Back to the map'),'closeModal',{},'pink big')}
${btn(tr('Export save <small>download a file</small>'),'exportSave',{},'')}
@ -2685,11 +2689,25 @@ document.addEventListener('click',e=>{const t=e.target.closest('.toast');if(t&&!
/* ================= INSTALL (PWA) ================= */
let installEvt=null;
addEventListener('beforeinstallprompt',e=>{e.preventDefault();installEvt=e;});
addEventListener('appinstalled',()=>{installEvt=null;track('pwa_installed',true);});
const isStandalone=()=>{try{return matchMedia('(display-mode: standalone)').matches||navigator.standalone===true;}catch(e){return false;}};
addEventListener('appinstalled',()=>{installEvt=null;track('pwa_installed',true);if(UI.pendGame){const p=UI.pendGame;UI.pendGame=null;UI.pitched=true;beginGame(...p);}toast(tr('<b>Installed!</b><br>Open Series of Tubes from your home screen. Your saves come along.'),'good');});
const isStandalone=()=>{try{return navigator.standalone===true||!!(window.matchMedia&&matchMedia('(display-mode: standalone)').matches);}catch(e){return false;}};
const isIOS=()=>/iPad|iPhone|iPod/.test(navigator.userAgent)||(navigator.platform==='MacIntel'&&navigator.maxTouchPoints>1);
function installRow(){if(isStandalone())return '';if(!installEvt&&!isIOS())return '';
return `<div class="row" style="margin-top:8px"><div class="grow"><div class="nm">${tr('Play it like an app')}</div><div class="meta">${tr('Full screen, works offline, one tap from your home screen.')}</div></div>${btn(tr('Install'),'install',{},'pink sm')}</div>`;}
function installRow(){if(isStandalone())return '';
return `<div class="row icard"><div class="grow"><div class="nm">📲 ${tr('Best played as an app')}</div><div class="meta">${tr('Full screen, works offline, one tap from your home screen.')}${isIOS()?' '+tr('Install it before you start: a game begun in Safari stays in Safari.'):''}</div></div>${btn(tr('Install'),'install',{},'pink sm')}</div>`;}
/* Phones get a real pitch before a new game: an installed app is full screen, works offline, and on iPhone
keeps its save away from Safari's clean-ups. Storage is separate on iOS, so installing first matters. */
const SHARE_SVG='<svg width="16" height="18" viewBox="0 0 16 18" aria-hidden="true"><path d="M8 1v10M4.5 4.5 8 1l3.5 3.5M5 7H2.5v9.5h11V7H11" fill="none" stroke="#1E2640" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>';
const needPitch=()=>isPhone()&&!isStandalone();
function installSteps(){
if(isIOS())return `<ol class="isteps"><li>${tr('Tap <b>Share</b> {icon} in the browser toolbar.',{icon:SHARE_SVG})}</li><li>${tr('Tap <b>Add to Home Screen</b>. You may need to scroll down, or tap <b>More</b> first.')}</li><li>${tr('Open <b>Series of Tubes</b> from your home screen and start your network there.')}</li></ol>`;
if(installEvt)return '';
return `<ol class="isteps"><li>${tr('Open your browser menu (⋮).')}</li><li>${tr('Tap <b>Install app</b> or <b>Add to Home screen</b>.')}</li><li>${tr('Open <b>Series of Tubes</b> from your home screen.')}</li></ol>`;}
function pitchHtml(starting){const ios=isIOS();
return `<div style="display:flex;align-items:center"><div>${starting?`<div class="eyebrow">${tr('Before you start')}</div>`:''}<h2 style="font-size:26px">📲 ${tr('Play it as an app')}</h2></div><button class="x" data-act="${starting?'pitchSkip':'closeModal'}" aria-label="${tr('Close')}">×</button></div>
<p class="lead" style="margin-top:6px">${tr('Series of Tubes is made for your home screen. It takes ten seconds, costs nothing, and it is a much better game there:')}</p>
<ul class="pitch"><li>🗺️ <b>${tr('Full screen.')}</b> ${tr('No browser bars, a lot more map.')}</li><li>📶 <b>${tr('Works offline.')}</b> ${tr('Build your backbone on the train or on a plane.')}</li>${ios?`<li>💾 <b>${tr('Your save stays safe.')}</b> ${tr('Safari can clear the data of websites you have not opened for a week. A home-screen app keeps its own.')}</li><li class="warn">⚠️ <b>${tr('Install first.')}</b> ${tr('On iPhone, a game started in Safari does not carry over to the home-screen app.')}</li>`:`<li>⚡ <b>${tr('One tap away.')}</b> ${tr('It opens straight into your network, like any other app.')}</li>`}</ul>
${installSteps()}
<div class="btns cta" style="margin-top:12px">${installEvt?btn(tr('Install the app'),'install',{},'pink big'):''}${starting?btn(tr('Play in the browser anyway'),'pitchSkip',{},installEvt?'ghost':'ghost big'):btn(tr('Got it'),'closeModal',{},installEvt?'ghost':'pink')}</div>`;}
if('serviceWorker' in navigator&&location.protocol==='https:'&&!IS_DEV)addEventListener('load',()=>{navigator.serviceWorker.register('/sw.js').catch(()=>{});});
function fitHud(){const h=$('hud');if(!h)return;h.classList.remove('fit1','fit2','fit3');if(innerWidth<=760)return;
const row=()=>{let m=0;for(const c of h.children)if(c.offsetParent)m=Math.max(m,c.offsetHeight);return m;};

View file

@ -214,3 +214,39 @@ test('iPhone home-screen app fills the screen when iOS reports a short viewport'
assert.equal(ev('CH'), 700);
assert.deepEqual(errors, []);
});
test('phones in the browser get the install pitch before a new game, then can still play', () => {
const { ev, dom, errors } = load();
const w = dom.window;
const set = (o, k, v) => Object.defineProperty(o, k, { value: v, configurable: true });
set(w.navigator, 'userAgent', 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Mobile/15E148 Safari/604.1');
set(w, 'innerWidth', 390); set(w, 'innerHeight', 760);
ev('showTitle()');
assert.match(ev("document.getElementById('modal').textContent"), /Best played as an app/, 'title screen card');
ev('ACT.start({})');
const modal = () => ev("document.getElementById('modal').textContent");
assert.equal(ev('!!S&&UI.started'), false, 'the game waits for the pitch');
assert.match(modal(), /Play it as an app/);
assert.match(modal(), /does not carry over/, 'iPhone players learn to install first');
assert.match(modal(), /Add to Home Screen/);
ev('ACT.pitchSkip()');
assert.equal(ev('UI.started&&!!S.pops[S.home]'), true, 'playing in the browser still works');
// only once per session
ev('ACT.newgame();ACT.start({})');
assert.equal(ev('UI.started'), true);
assert.deepEqual(errors, []);
});
test('the installed app and desktop browsers start straight away', () => {
for (const [w0, sa] of [[390, true], [1280, false]]) {
const { ev, dom, errors } = load();
const w = dom.window;
const set = (o, k, v) => Object.defineProperty(o, k, { value: v, configurable: true });
set(w.navigator, 'userAgent', 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_6 like Mac OS X) AppleWebKit/605.1.15');
set(w.navigator, 'standalone', sa);
set(w, 'innerWidth', w0); set(w, 'innerHeight', 760);
ev('ACT.start({})');
assert.equal(ev('UI.started'), true, `width ${w0}, standalone ${sa}`);
assert.deepEqual(errors, []);
}
});