Puzzles on phones: fixed overlays that never scroll
A bar pinned at the top holds the puzzle's state (name, stars, money, undo, menu), the goal being worked on with Show me, and a chip per flow that opens its city. A city or a link opens a short card at the bottom, split into tabs (links, router, traffic; size, traffic, routing) that each fit on a 360 px phone, portrait or landscape. Architect runs get the same bar. Reset moves to the menu on phones. Desktop is unchanged. The old swipe-up sheet and its peek state are gone.
This commit is contained in:
parent
d7fb2a9617
commit
107b0b825a
10 changed files with 292 additions and 39 deletions
|
|
@ -439,6 +439,8 @@ const API_VIEW={
|
|||
bankClose:{args:[],doc:'Close the bank.'},
|
||||
closePanel:{args:[],doc:'Close the selection panel.'},
|
||||
tab:{args:[['t','string']],doc:'Switch the city panel\'s tab.'},
|
||||
pzCity:{args:[['c','cityId']],doc:'Puzzles on a phone: open a city\'s card from its flow chip.'},
|
||||
pzTab:{args:[['k','string'],['t','string']],doc:'Puzzles on a phone: switch the city (k:"city") or link (k:"link") card\'s tab.'},
|
||||
leftTab:{args:[['t','leftTab']],doc:'Switch the left drawer and open it.'},
|
||||
toggleLeft:{args:[],doc:'Open or close the left drawer.'},
|
||||
netFocus:{args:[['id','netId']],doc:'Focus one network in the left drawer.'},
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ Object.assign(ACT,{
|
|||
pzRetry:()=>{if(!pzOn())return;if(S.ar){arBegin(arRun());return;}pzBegin(S.pz.id==='weekly'?pzWkDef():pzDef(S.pz.id));},
|
||||
pzLeave:()=>{if(pzOn())pzLeave();},
|
||||
// The sheet's next-fix line: bring the city, or the link a cut hurts most, into view (the zoom stays).
|
||||
// Phones split a puzzle's city and link cards into tabs (97-puzzles-phone.js); the tab shown is kept per kind of card.
|
||||
pzTab:({k,t})=>{if(!pzOn()||!['city','link'].includes(k)||typeof t!=='string')return;UI.pzTab={...(UI.pzTab||{}),[k]:t};renderPanel();},
|
||||
// A flow chip on a phone: that city's card, with the city on screen.
|
||||
pzCity:({c})=>{if(!pzOn()||!isCity(c)||!pzKind(c))return;ACT.pzLook({c});selectCity(c);renderTabbar();},
|
||||
pzLook:({c,u})=>{if(!pzOn())return;let x,y;if(c&&isCity(c)){x=CITY[c].x;y=CITY[c].y;}else{const l=u&&S.links.find(q=>pzUnit(q)===u);if(!l)return;const A=CITY[l.a],B=CITY[l.b];x=A.x+wrapDx(A.x,B.x)/2;y=(A.y+B.y)/2;}
|
||||
const sh=isPhone()&&CW<=CH?($('pzBox').offsetHeight||0):0;cam.x=x;cam.y=y+sh/2/cam.z;wrapCam();haptic(8);},
|
||||
pzPop:({city})=>{if(!pzOn()||S.pops[city]||!['goal','via','off'].includes(pzKind(city)))return;pzSnap();S.pops[city]=pzNewPop(city);sfx('build');haptic(10);floater(CITY[city].x,CITY[city].y-30,tr('common.new_pop'),'#FF4F9A');pzAfter();},
|
||||
|
|
@ -49,7 +53,7 @@ Object.assign(ACT,{
|
|||
// A circuit follows the metrics (the IGP's shortest path) or takes the lowest-latency path, as customers can in the main game.
|
||||
pzRoute:({i,m})=>{const b=pzOn()&&S.biz.find(x=>x.id===pzFlowId(+i));if(!b||!['normal','fast'].includes(m)||b.route===m)return;pzSnap();b.route=m;sfx('click');pzAfter();},
|
||||
pzUndo:()=>{const h=UI.pzHist;if(!pzOn()||!h||!h.length)return;if(S.ar)arStop(true);const o=JSON.parse(h.pop());S.pops=o.p;S.links=o.l;S.pairMet=o.m||{};if(S.ar){S.ar.sunk=o.k||0;arDemand();}(o.r||[]).forEach((m,i)=>{if(S.biz[i])S.biz[i].route=m;});sfx('click');pzAfter();},
|
||||
pzReset:()=>{if(!pzOn())return;pzSnap();if(S.ar){arReset();sfx('click');pzAfter();return;}S.pops={};S.links=[];S.pairMet={};for(const b of S.biz)b.route='normal';UI.sel=null;sfx('click');pzAfter();},
|
||||
pzReset:()=>{if(!pzOn())return;if(!$('modal').hidden)closeModal();pzSnap();if(S.ar){arReset();sfx('click');pzAfter();return;}S.pops={};S.links=[];S.pairMet={};for(const b of S.biz)b.route='normal';UI.sel=null;sfx('click');pzAfter();},
|
||||
pzShare:()=>{if(!pzOn())return;const t=S.ar?arShareText(arStars(arSpend()),arSpend()):pzShareText(pzEval());
|
||||
const copied=()=>toast(tr('puzzles.copied_paste_it_anywhere',{t:esc(t)}),'good'),copy=()=>{try{navigator.clipboard.writeText(t).then(copied,()=>toast(esc(t),''));}catch(e){toast(esc(t),'');}};
|
||||
if(navigator.share&&isPhone()){navigator.share({text:t}).catch(()=>{});return;}copy();track('puzzle_share');},
|
||||
|
|
|
|||
|
|
@ -13,11 +13,10 @@ function renderTabbar(){const tb=$('tabbar');if(!tb||(pressing&&UI.ticking))retu
|
|||
function haptic(ms){if(UI.muted)return;try{navigator.vibrate&&navigator.vibrate(ms||12);}catch(e){}}
|
||||
// Bottom sheets: drag the handle up to expand, down to shrink or close; tap it to toggle.
|
||||
(function(){let g=null;
|
||||
document.addEventListener('pointerdown',e=>{const h=e.target.closest('[data-grab]');if(!h||!isPhone()||e.target.closest('button,select,input'))return;const el=h.dataset.grab==='pz'?$('pzBox'):h.parentElement;g={el,y:e.clientY,dy:0,id:e.pointerId,full:el.classList.contains('full')};try{h.setPointerCapture(e.pointerId);}catch(_){}el.style.transition='none';});
|
||||
document.addEventListener('pointerdown',e=>{const h=e.target.closest('[data-grab]');if(!h||!isPhone()||e.target.closest('button,select,input'))return;const el=h.parentElement;g={el,y:e.clientY,dy:0,id:e.pointerId,full:el.classList.contains('full')};try{h.setPointerCapture(e.pointerId);}catch(_){}el.style.transition='none';});
|
||||
document.addEventListener('pointermove',e=>{if(!g||e.pointerId!==g.id)return;g.dy=e.clientY-g.y;if(g.dy>0)g.el.style.transform=`translateY(${g.dy}px)`;});
|
||||
const end=e=>{if(!g||e.pointerId!==g.id)return;const {el,dy,full}=g;g=null;el.style.transition='';el.style.transform='';
|
||||
if(Math.abs(dy)<6){el.classList.toggle(el.id==='pzBox'?'mini':'full');return;}
|
||||
if(el.id==='pzBox'){el.classList.toggle('mini',dy>0);return;}
|
||||
if(Math.abs(dy)<6){el.classList.toggle('full');return;}
|
||||
if(dy<-40){el.classList.add('full');return;}
|
||||
if(dy>40){if(full){el.classList.remove('full');return;}if(el.id==='panel')ACT.closePanel();else{UI.leftOpen=false;renderLeft();}}};
|
||||
document.addEventListener('pointerup',end);document.addEventListener('pointercancel',end);})();
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ function pzGoalRow(g,i){const ic=g.done?'⭐':g.cur?'👉':`<i>${i+1}</i>`;
|
|||
+(g.cur&&g.hint?`<div class="pzgh">${g.hint}${g.look?' '+btn(tr('puzzles.show_me'),'pzLook',g.look,'sm pzshow'):''}</div>`:'')+`</div>`;}
|
||||
// A delivered eyeball flow is a chip; anything still short, a circuit or a latency cap keeps its full row.
|
||||
const pzChip=x=>`<span class="pzchip">👀 ${esc(CITY[x.f.a].name)} <b>${fmtG(x.f.g)}</b> ✓</span>`;
|
||||
function pzRender(){const el=$('pzBox');if(!pzOn()){el.hidden=true;return;}el.hidden=false;el.classList.toggle('ar',!!S.ar);if(S.ar){arRender(el);return;}
|
||||
function pzRender(){const el=$('pzBox');if(!pzOn()){el.hidden=true;return;}el.hidden=false;el.classList.toggle('ar',!!S.ar);UI._pzPhone=isPhone();if(S.ar){el.classList.toggle('dock',UI._pzPhone);(UI._pzPhone?arDock:arRender)(el);return;}
|
||||
const e=pzEval(),P=S.pz,d=pzDef(P.id),pk=d&&PZ_PACKS.find(x=>x.id===d.pack);
|
||||
// A phone held upright starts each puzzle with the sheet down to its status bar, so the map has the room (swipe it up for the rest).
|
||||
const pk2=P.id+'|'+(P.key||'');if(UI._pzPeek!==pk2){UI._pzPeek=pk2;el.classList.toggle('mini',isPhone()&&CW<=CH);}
|
||||
// A phone gets fixed overlays that never scroll (97-puzzles-phone.js).
|
||||
el.classList.toggle('dock',UI._pzPhone);if(UI._pzPhone){pzDock(el,e);return;}
|
||||
const sp=fmt$(e.spend);
|
||||
// The status bar stays at the top of the sheet, whatever scrolls: the puzzle, its stars, the money, undo and the menu.
|
||||
// The status bar stays at the top of the card, whatever scrolls: the puzzle, its stars, the money, undo and the menu.
|
||||
let h=`<div class="pztop" data-grab="pz"><div class="grab" aria-hidden="true"></div><div class="pzh"><div class="grow"><div class="eyebrow">${pk?esc(pk.n):P.theme&&own(PZ_WK_THEMES,P.theme)?`${PZ_WK_THEMES[P.theme].i} ${tr('puzzles.weekly_puzzle')} · ${tr(PZ_WK_THEMES[P.theme].t)}`:tr('puzzles.weekly_puzzle')}</div><h3>${esc(pzName(d||P))}</h3></div>`
|
||||
+`<button class="b ghost sm" data-act="pzUndo" data-args="{}" aria-label="${esc(tr('puzzles.undo'))}" title="${esc(tr('puzzles.undo'))}"${UI.pzHist&&UI.pzHist.length?'':' disabled'}>↶</button>${btn('☰','puzzleMenu',{},'ghost sm')}</div>`;
|
||||
const gs=pzGoals(e),cur=gs.find(g=>g.cur);UI.pzMark=!UI.pzMk&&cur&&cur.mark||null;
|
||||
|
|
@ -69,7 +69,7 @@ function pzPopSection(c){const p=S.pops[c],g=p.rgen||0,rt=p.routers||1,G=RG[g],c
|
|||
<h4 class="sub4">${tr('puzzles.router_model')}</h4>`;
|
||||
h+=PZ_RG.map(i=>{const M=RG[i],why=i===g?'':modelFits(c,i);return `<div class="row${i===g?' on':''}"><div class="grow"><div class="nm">${esc(M.n)}${i===g?` <span class="tag st on">${tr('puzzles.installed')}</span>`:''}</div><div class="meta">${tr('puzzles.model_facts',{cap:fmtG(M.cap),ports:M.ports,wave:LT[M.maxLT].n})}</div>${why?`<div class="why">${esc(why)}</div>`:''}</div>${i===g?'':btn(dl(pzRtCost(i,rt)-cur),'pzRtModel',{city:c,g:i},'ghost sm',!!why)}</div>`;}).join('');
|
||||
return h;}
|
||||
function pzPanel(sel){if(S.ar)return arPanel(sel);const head=(eb,name,facts)=>`<div class="ph"><div style="min-width:0"><div class="eyebrow">${eb}</div><h2>${name}</h2>${facts?`<div class="facts">${facts}</div>`:''}</div><button class="x" data-act="closePanel" aria-label="${tr('common.close')}">×</button></div>`;
|
||||
function pzPanel(sel){if(S.ar)return arPanel(sel);if(isPhone())return pzPanelPhone(sel);const head=(eb,name,facts)=>`<div class="ph"><div style="min-width:0"><div class="eyebrow">${eb}</div><h2>${name}</h2>${facts?`<div class="facts">${facts}</div>`:''}</div><button class="x" data-act="closePanel" aria-label="${tr('common.close')}">×</button></div>`;
|
||||
if(sel.type==='city'){const c=sel.id,k=pzKind(c),p=S.pops[c],C=CITY[c],P=S.pz;if(!k)return '';
|
||||
const eb=k==='goal'?tr('puzzles.goal_city'):k==='via'?tr('puzzles.stepping_stone_optional'):k==='off'?tr('puzzles.not_in_the_plan'):tr('puzzles.off_limits');
|
||||
let h=head(`${PZ_ICON[k]} ${eb}`,esc(C.name),p?`<span class="fact mine">${tr('common.your_pop')}</span>`:'')+'<div class="scroll">';
|
||||
|
|
@ -153,7 +153,7 @@ function pzMenu(){pzWkEnsure();const p=pzLoad(),tot=pzStarsTotal(p),max=PZ.lengt
|
|||
<p class="tagline">${tr('puzzles.no_clock_no_bills_real_traffic')}</p>`;
|
||||
// Once, after the puzzles got traffic: the old stars are kept on the wall, the new set starts at zero.
|
||||
if(p.old&&!p.noted){h+=`<div class="pznote">🖼️ ${tr('puzzles.puzzles_got_traffic_note',{n:p.old})}</div>`;p.noted=1;pzStore(p);}
|
||||
if(pzOn())h+=`<div class="btns" style="margin:8px 0">${(UI.pzTop||0)>0&&(UI.pzTop||0)<3?btn(tr('puzzles.finish_here'),'pzFinish',{},'sm'):''}${btn(UI.pzFrom==='game'?tr('puzzles.back_to_my_network'):tr('puzzles.back_to_the_title'),'pzLeave',{},'')}${btn(tr('puzzles.keep_building'),'closeModal',{},'ghost')}</div>`;
|
||||
if(pzOn())h+=`<div class="btns" style="margin:8px 0">${isPhone()&&!S.ar?btn(tr('puzzles.reset'),'pzReset',{},'ghost',!S.links.length&&!Object.keys(S.pops).length):''}${(UI.pzTop||0)>0&&(UI.pzTop||0)<3?btn(tr('puzzles.finish_here'),'pzFinish',{},'sm'):''}${btn(UI.pzFrom==='game'?tr('puzzles.back_to_my_network'):tr('puzzles.back_to_the_title'),'pzLeave',{},'')}${btn(tr('puzzles.keep_building'),'closeModal',{},'ghost')}</div>`;
|
||||
h+=arMenuRows();
|
||||
h+=pzWkRow();
|
||||
// The packs' own total, right above them: it is what unlocks the next pack (#231). Runs and weeklies count their own.
|
||||
|
|
|
|||
95
src/game/95-modals/97-puzzles-phone.js
Normal file
95
src/game/95-modals/97-puzzles-phone.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/* ---------- puzzles on a phone: fixed overlays that never scroll ----------
|
||||
A bar pinned at the top says how the puzzle stands (its name, the three stars, the money, undo and the menu), the one
|
||||
thing to do next and what each flow gets, as chips. A city or a link opens a card at the bottom whose content is
|
||||
split into tabs, so each tab fits on the screen. Desktop keeps the side card (pzRender, pzPanel). */
|
||||
// A rate in a few characters, for the chips: 30G, 2.5G, 1.2T.
|
||||
const pzG=g=>g>=1000?(g/1000).toFixed(g>=10000?0:1)+'T':g>=10||g===0?Math.round(g)+'G':g.toFixed(1)+'G';
|
||||
// One flow as a chip: what it is, how much of it arrives, a circuit's latency against its cap. Tapping it shows the city.
|
||||
function pzFlowChip(x){const f=x.f,ok=x.full&&x.fast,part=x.g>0&&!ok;
|
||||
const lat=f.ms?` · <span class="${x.fast?'':'bad'}">${x.ms==null?'—':x.ms.toFixed(1)}/${f.ms} ms</span>`:'';
|
||||
return `<button class="pzd-chip${ok?' ok':part?' part':' none'}" data-act="pzCity" data-args='${JSON.stringify({c:f.a})}'>${f.t==='l2'?'🔗':'👀'} ${esc(f.t==='l2'?pzFlowName(f):CITY[f.a].name)} <b>${pzG(x.g)}/${pzG(f.g)}</b>${lat}</button>`;}
|
||||
// The rules of this puzzle as chips: the content's home, the cities to avoid, no subsea cables, the ring.
|
||||
function pzRuleChips(e){const P=S.pz;let h='';
|
||||
if(P.src.length)h+=`<span class="pzd-chip rule">🗄️ ${P.src.map(c=>esc(CITY[c].name)).join(', ')}</span>`;
|
||||
for(const t of e.tw)h+=t.k==='avoid'?`<span class="pzd-chip rule">🚫 ${P.avoid.map(c=>esc(CITY[c].name)).join(', ')}</span>`:`<span class="pzd-chip ${t.ok?'ok':'none'}">${t.ok?'✓':'✗'} ${pzTwistTxt(t)}</span>`;
|
||||
return h;}
|
||||
function pzDock(el,e){const P=S.pz,d=pzDef(P.id),gs=pzGoals(e),cur=gs.find(g=>g.cur);UI.pzMark=!UI.pzMk&&cur&&cur.mark||null;
|
||||
const stars=gs.map((g,i)=>`<span class="pzd-st${g.done?' on':g.cur?' cur':''}" title="${esc(g.t)}">${g.done?'⭐':i+1}</span>`).join('');
|
||||
const bud=P.budget?`<span class="pzd-bud${e.goal&&!e.cheap?' bad':''}">${fmt$(e.spend)} / ${fmt$(P.budget)}</span>`:`<span class="pzd-bud">${tr('puzzles.free')}</span>`;
|
||||
let h=`<div class="pzd-bar"><b class="pzd-nm">${esc(pzName(d||P))}</b><span class="pzd-stars" aria-label="${tr('puzzles.your_stars_so_far')}">${stars}</span>${bud}`
|
||||
+`<button class="b ghost sm" data-act="pzUndo" data-args="{}" aria-label="${esc(tr('puzzles.undo'))}" title="${esc(tr('puzzles.undo'))}"${UI.pzHist&&UI.pzHist.length?'':' disabled'}>↶</button>${btn('☰','puzzleMenu',{},'ghost sm')}</div>`;
|
||||
// The one thing to do: the goal being worked on, what is wrong and Show me; the monkey once the traffic arrives.
|
||||
const act=UI.pzMk?btn('⏩ '+tr('puzzles.skip_the_monkey'),'pzMkSkip',{},'sm'):e.goal?btn('🐒 '+tr('puzzles.let_the_chaos_monkey_loose'),'pzMonkey',{},'ghost sm'):'';
|
||||
if(cur)h+=`<div class="pzd-goal"><span class="pzd-gi">👉</span><div class="pzd-gt"><b>${cur.t}</b>${cur.hint?` <span>${cur.hint}</span>`:''}</div><div class="pzd-ga">${cur.look?btn(tr('puzzles.show_me'),'pzLook',cur.look,'sm pzshow'):''}${act}</div></div>`;
|
||||
else h+=`<div class="pzd-goal done"><span class="pzd-gi">🛡</span><div class="pzd-gt"><b>${tr('puzzles.survives_any_single_cut_under_load')}</b></div><div class="pzd-ga">${act}</div></div>`;
|
||||
h+=`<div class="pzd-chips">${e.flows.map(pzFlowChip).join('')}${pzRuleChips(e)}</div>`;
|
||||
if(h!==UI._pzh){UI._pzh=h;morph(el,h);}}
|
||||
// The bar's height, for what must sit under it (toasts) or stop short of it (the card): it changes with its content and
|
||||
// when a card opens, so it is watched rather than measured after each render.
|
||||
try{new ResizeObserver(()=>{const H=$('pzBox').offsetHeight||0;document.documentElement.style.setProperty('--pzdock',H+'px');}).observe($('pzBox'));}catch(e){}
|
||||
// An architect run on a phone: the same bar. The brief, its sites and rules as chips, and the review with its one button.
|
||||
function arDock(el){const A=S.ar,run=arRun(),b=arBrief(),e=arEval(),sh=UI.arShow,f=UI.arFail,n=run.briefs.length,nm=c=>esc(CITY[c].name),T=e.tubes;
|
||||
let h=`<div class="pzd-bar"><b class="pzd-nm">🏗️ ${tr('architect.brief_n_of_m',{n:A.bi+1,m:n})}</b><span class="pzd-bud${e.cheap?'':' bad'}">${fmt$(e.spend)} / ${fmt$(e.budget)} ${e.cheap?'⭐':'☆'}</span>`
|
||||
+`<button class="b ghost sm" data-act="pzUndo" data-args="{}" aria-label="${esc(tr('puzzles.undo'))}" title="${esc(tr('puzzles.undo'))}"${!sh&&UI.pzHist&&UI.pzHist.length?'':' disabled'}>↶</button>${btn('☰','puzzleMenu',{},'ghost sm')}</div>`;
|
||||
h+=`<div class="arsteps">${run.briefs.map((x,i)=>`<i class="${i<A.bi||(i===A.bi&&e.passed)?'done':i===A.bi?'on':''}"></i>`).join('')}</div><p class="arbrief">${esc(b.t)}</p>`;
|
||||
let ch=e.sites.map(s=>`<span class="arsite${s.ok&&s.full?' ok':''}${s.ok&&!s.full?' thin':''}${s.gold?' gold':''}">${s.hq?'🏠':s.gold?'🚨':s.ok?'✓':'○'} ${nm(s.c)}${s.hq?'':` <small>${s.ok&&!s.full?arG(s.got)+'/':''}${arG(s.dem)}</small>`}</span>`).join('');
|
||||
for(const r of e.rings)ch+=`<span class="pzd-chip ${r.ok?'ok':'none'}">💍 ${r.cs.map(nm).join(' · ')}</span>`;
|
||||
if(e.lat)ch+=`<span class="pzd-chip ${e.lat.ok?'ok':'none'}">⏱ ${e.lat.ms==null?'—':e.lat.ms.toFixed(1)}/${e.lat.cap} ms</span>`;
|
||||
for(const c of S.pz.avoid)ch+=`<span class="pzd-chip ${S.pops[c]?'none':'rule'}">🚫 ${nm(c)}</span>`;
|
||||
if(T.max!=null)ch+=`<span class="pzd-chip${T.over?' part':' rule'}">${tr('architect.tubes_this_brief')} <b>${T.u}/${T.max}</b></span>`;
|
||||
h+=`<div class="pzd-chips">${ch}</div>`;
|
||||
const rev=sh?`🐒 ${tr('architect.cut_n_of_m',{n:sh.i+1,m:sh.units.length})}${sh.dark.length?' · '+sh.dark.map(nm).join(', '):''}`:f?`💥 ${f.gold.length?tr('architect.cut_on_x_cuts_off_y',{x:pzUnitName(f.u),y:f.gold.map(nm).join(', ')}):tr('architect.cut_on_x_no_room',{x:pzUnitName(f.u),y:f.short.map(nm).join(', ')})}`
|
||||
:e.passed?`✅ ${tr('architect.review_passed')}`:!e.ready?esc(e.why):A.gold.length?tr('architect.ready_send_the_backhoe'):tr('architect.ready_no_gold_yet');
|
||||
const main=sh?btn('⏩ '+tr('architect.skip'),'pzArSkip',{},'sm'):e.passed?btn(arLast()?tr('architect.finish_the_run')+' 🎉':tr('architect.next_brief')+' →','pzArNext',{},'pink sm'):btn('▶ '+tr('architect.send_the_backhoe'),'pzArGo',{},'pink sm',!e.ready);
|
||||
h+=`<div class="pzd-goal${sh?'':f?' bad':e.passed?' done':''}"><div class="pzd-gt">${rev}${A.gold.length&&!sh&&!f&&!e.passed?`<br><small>🚨 ${tr('architect.gold_must_survive',{list:A.gold.map(nm).join(', ')})}</small>`:''}</div><div class="pzd-ga">${main}</div></div>`;
|
||||
if(h!==UI._pzh){UI._pzh=h;morph(el,h);}}
|
||||
// The tabs of a card; the one shown is kept per kind of card (city or link) while the puzzle runs.
|
||||
const pzTabs=(kind,tabs,cur)=>`<nav class="pzd-tabs" role="tablist">${tabs.map(([k,l])=>`<button role="tab" aria-selected="${k===cur}" class="${k===cur?'on':''}" data-act="pzTab" data-args='${JSON.stringify({k:kind,t:k})}'>${l}</button>`).join('')}</nav>`;
|
||||
const pzTabOf=(kind,tabs,def)=>{const t=(UI.pzTab||{})[kind];return tabs.some(([k])=>k===t)?t:def;};
|
||||
// The card's head in two short lines: what it is (and whether it is yours) above the name, the facts beside the name.
|
||||
const pzHead=(eb,name,facts)=>`<div class="ph pzd-ph"><div class="grow"><div class="eyebrow">${eb}</div><h2>${name}${facts?` <small>${facts}</small>`:''}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('common.close')}">×</button></div>`;
|
||||
function pzPanelPhone(sel){
|
||||
if(sel.type==='city'){const c=sel.id,k=pzKind(c),p=S.pops[c],C=CITY[c],P=S.pz;if(!k)return '';
|
||||
const eb=k==='goal'?tr('puzzles.goal_city'):k==='via'?tr('puzzles.stepping_stone_optional'):k==='off'?tr('puzzles.not_in_the_plan'):tr('puzzles.off_limits');
|
||||
let h=pzHead(`${PZ_ICON[k]} ${eb}${p?` · <span class="mine">${tr('common.your_pop')}</span>`:''}`,esc(C.name),'')+'<div class="pzd-body">';
|
||||
if(k==='avoid')return h+`<p class="lead">${tr('puzzles.not_this_one_find_a_way_around')}</p></div>`;
|
||||
const ev=pzEval(),fl=ev.flows.filter(x=>x.f.a===c||x.f.b===c);
|
||||
const chips=fl.length||P.src.includes(c)?`<div class="pzd-chips">${P.src.includes(c)?`<span class="pzd-chip rule">🗄️ ${tr('puzzles.the_content_origin_lives_here')}</span>`:''}${fl.map(pzFlowChip).join('')}</div>`:'';
|
||||
if(!p)return h+chips+(k==='off'?`<p class="note">${tr('puzzles.no_traffic_starts_or_ends_here')}</p>`:'')+`<div class="btns">${btn(tr('puzzles.open_a_pop_cost',{cost:fmt$(pzPopCost(c))}),'pzPop',{city:c},'pink big')}</div><p class="note">${tr('puzzles.a_pop_costs_setup_plus_a_year',{setup:fmt$(popCost(c)),mo:fmt$(popMo(c))})}</p></div>`;
|
||||
const nb=[...new Set(S.links.filter(l=>l.a===c||l.b===c).map(l=>l.a===c?l.b:l.a))];
|
||||
const tabs=[['links',tr('common.links')],['router',tr('puzzles.router_model')]];if(fl.length)tabs.push(['traffic',tr('puzzles.carrying')]);
|
||||
const t=pzTabOf('city',tabs,'links');h+=pzTabs('city',tabs,t);
|
||||
if(t==='links'){
|
||||
if(!nb.length)h+=`<p class="note">${tr('puzzles.drag_from_this_pop_onto_another')}</p>`;
|
||||
for(const x of nb){const ls=pairLinks(c,x),ld=ls.reduce((a,l)=>a+(R.load[l.id]||0),0),cp=ls.filter(l=>!linkDown(l)).reduce((a,l)=>a+capOf(l),0);
|
||||
h+=`<div class="pzd-row"><div class="grow"><b>→ ${esc(CITY[x].name)}</b> <span class="meta">${groupLabel(ls,ls)} · ${pzG(ld)}/${pzG(cp)}</span></div>${btn(tr('common.open'),'selLink',{id:ls[0].id},'ghost sm')}</div>`;}
|
||||
const others=[...P.cities,...P.via].filter(x=>x!==c);
|
||||
h+=`<h4 class="sub4">${tr('puzzles.lease_a_wave_to')}</h4><div class="seg pzd-to">${others.map(x=>btn(esc(CITY[x].name),'pzLinkTo',{a:c,b:x},S.pops[x]?'':'ghost')).join('')}</div>`;
|
||||
h+=`<div class="btns pzd-foot">${btn(tr('puzzles.remove_this_pop'),'pzRmPop',{city:c},'red sm')}</div>`;}
|
||||
else if(t==='router'){const g=p.rgen||0,rt=p.routers||1,G=RG[g],cap=nodeCap(c),ld=R.nodeLoad[c]||0,u=cap?ld/cap:0,cur=pzRtCost(g,rt),dl=v=>(v>=0?'+':'−')+fmt$(Math.abs(v));
|
||||
h+=`<div class="kv"><span>${rt>1?rt+' × ':''}${esc(G.n)} · ${tr('puzzles.u_of_m_used',{u:fmtPorts(portsUsed(c)),m:portsMax(c)})}</span><b>${pzG(ld)}/${pzG(cap)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100).toFixed(1)}%"></i></div>`;
|
||||
h+=`<div class="btns pzd-rt">${btn(tr('puzzles.add_a_router_cost',{cost:dl(pzRtCost(g,rt+1)-cur)}),'pzRtAdd',{city:c},'sm',rt>=RMAX)}${rt>1?btn(tr('puzzles.remove_a_router'),'pzRtRm',{city:c},'ghost sm'):''}</div>`;
|
||||
// Every model at once, two to a row: what it can do, or why it does not fit; its price against the installed one.
|
||||
h+=`<div class="pzd-models">${PZ_RG.map(i=>{const M=RG[i],why=i===g?'':modelFits(c,i);
|
||||
return `<button class="pzd-model${i===g?' on':''}" data-act="pzRtModel" data-args='${JSON.stringify({city:c,g:i})}'${i===g||why?' disabled':''}><span class="pzd-mh"><b>${esc(M.n)}</b><span>${i===g?'✓':dl(pzRtCost(i,rt)-cur)}</span></span><small>${why?esc(why):`${pzG(M.cap)} · 🔌${M.ports} · ≤${LT[M.maxLT].n}`}</small></button>`;}).join('')}</div>`;}
|
||||
else{if(P.src.includes(c))h+=`<p class="note">🗄️ ${tr('puzzles.the_content_origin_lives_here')}</p>`;h+=`<div class="pzfl">${fl.map(x=>pzFlowRow(x)).join('')}</div>`;}
|
||||
return h+'</div>';}
|
||||
const l=S.links.find(x=>x.id===sel.id);if(!l)return '';const pl=pairLinks(l.a,l.b);
|
||||
let h=pzHead(l.cable?esc(CAB[l.cable].name):tr('common.overland'),`${esc(CITY[l.a].name)} ⇄ ${esc(CITY[l.b].name)}`,`${capName(l)} · ${l.km.toLocaleString()} km · ${linkLat(l).toFixed(1)} ms · ${tr('puzzles.price_per_year',{price:fmt$(l.mo*PZ_YEAR)})}`)+'<div class="pzd-body">';
|
||||
const u=capOf(l)?(R.load[l.id]||0)/capOf(l):0;
|
||||
h+=`<div class="kv"><span>${tr('puzzles.this_link')}</span><b>${pzLoadTxt(l)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100).toFixed(1)}%"></i></div>`;
|
||||
const tabs=[['size',tr('puzzles.size')],['traffic',tr('puzzles.carrying')],['routing',tr('common.routing_metric')]],t=pzTabOf('link',tabs,'size');h+=pzTabs('link',tabs,t);
|
||||
if(t==='size'){
|
||||
h+=`<div class="pzd-tiers">${PZ_TIERS.map(i=>{const r={km:l.km,sub:l.sub,f:l.mult||1},why=pzWaveWhy(l.a,l.b,i,r);return btn(`${LT[i].n} <small>${why?esc(why):tr('puzzles.price_per_year',{price:fmt$(pzMo(r,i,false)*PZ_YEAR)})}</small>`,'pzTier',{id:l.id,tier:i},l.tier===i?'pink':'ghost',!!why||l.tier===i);}).join('')}</div>`;
|
||||
h+=`<h4 class="sub4">${tr('puzzles.add_another_link_here')}</h4><div class="btns">${btn(l.cable?tr('puzzles.another_wave_on_this_cable'):tr('puzzles.same_trench_cheaper'),'pzAddPar',{id:l.id,div:0},'sm')}${btn(l.cable?tr('puzzles.a_different_route'):tr('puzzles.a_diverse_route'),'pzAddPar',{id:l.id,div:1},'pink sm')}</div>`;
|
||||
h+=`<div class="btns pzd-foot">${btn(tr('puzzles.remove_this_link'),'pzRmLink',{id:l.id},'red sm')}</div>`;}
|
||||
else if(t==='traffic'){const rec=R.ef[edgeKey(l)],rows=[];
|
||||
if(rec){S.pz.dem.forEach((f,i)=>{const v=rec.eg['l2:'+pzFlowId(i)];if(v>0.01)rows.push([pzFlowName(f),v]);});
|
||||
const byc={};for(const k in rec.dst)byc[k]=rec.dst[k];S.pz.dem.forEach((f,i)=>{const v=rec.eg['l2:'+pzFlowId(i)];if(v>0.01)byc[f.b]=(byc[f.b]||0)-v;});
|
||||
for(const k in byc)if(byc[k]>0.01)rows.push([tr('puzzles.flow_eyeballs_in_city',{city:CITY[k].name}),byc[k]]);}
|
||||
h+=rows.length?rows.map(([n,v])=>`<div class="kv"><span>${esc(n)}</span><b>${fmtG(v)}</b></div>`).join(''):`<p class="note">—</p>`;
|
||||
if(pl.length>1)h+=`<h4 class="sub4">${tr('puzzles.n_links_on_this_pair',{n:pl.length,what:groupLabel(pl,pl)})}</h4>`+pl.map(x=>`<div class="pzd-row${x===l?' on':''}"><div class="grow meta">${capName(x)} · ${pzTrench(x)}${x.standby?' · '+tr('common.standby'):''} · ${pzLoadTxt(x)}</div>${x===l?'':btn(tr('common.open'),'selLink',{id:x.id},'ghost sm')}</div>`).join('');}
|
||||
else h+=`<div class="pzd-routing">${metricSection(l)}${linkCheckControl(l)}</div>`;
|
||||
return h+'</div>';}
|
||||
// A phone turned or a window resized can switch between the two layouts: draw the puzzle again in the one that fits.
|
||||
addEventListener('resize',()=>{if(!S||!pzOn())return;const ph=isPhone();if(ph===UI._pzPhone)return;UI._pzh=null;UI._ph=null;pzRender();renderPanel();});
|
||||
|
|
@ -47,27 +47,64 @@ body.pz #hud .chip:not(.brand):not(.speed),body.pz #hud .speed button:not(#muteB
|
|||
.pzconf i{position:absolute;top:-12px;left:var(--x);width:8px;height:12px;background:var(--c);border:1.5px solid var(--ink);border-radius:2px;animation:pzfall var(--t) ease-in var(--dl) both}
|
||||
@keyframes pzfall{0%{transform:translateY(0) rotate(0);opacity:1}100%{transform:translateY(420px) rotate(var(--r));opacity:0}}
|
||||
@media (max-width:760px),(max-height:500px) and (pointer:coarse){
|
||||
#pzBox{top:auto;left:0;right:0;width:auto;bottom:0;max-height:min(46%,330px);border-radius:20px 20px 0 0;border-bottom:0;box-shadow:0 -3px 0 var(--ink);padding:0 12px calc(10px + env(safe-area-inset-bottom,0px))}
|
||||
#pzBox .grab{display:block}
|
||||
#pzBox .btns .b,#pzBox .pzh .b{min-height:40px;min-width:40px;padding:4px 12px}
|
||||
/* Long languages make the sheet scroll: Undo, Reset and Back stay pinned at its foot. */
|
||||
#pzBox>.btns{position:sticky;bottom:0;background:var(--paper);margin:6px -12px 0;padding:6px 12px 0;box-shadow:0 -6px 6px -6px rgba(30,38,64,.25)}
|
||||
#pzBox .pztop{top:0;margin:0 -12px;padding:0 12px 2px}
|
||||
/* Peek: only the status bar, so the map keeps the screen while you build; tap or swipe it up for the rest. */
|
||||
#pzBox.mini{max-height:none}#pzBox.mini>:not(.pztop){display:none}
|
||||
#pzBox .pzh .eyebrow{display:none}#pzBox h3{font-size:17px}
|
||||
#pzBox .pzgl{font-size:14.5px}#pzBox .pzgh{font-size:13.5px}#pzBox .pzgh .pzshow{min-height:32px}
|
||||
body.pz:has(#pzBox.mini) #hint{bottom:calc(150px + env(safe-area-inset-bottom,0px)) !important}
|
||||
body.pz.sheet-open #pzBox{display:none}
|
||||
body.pz #panel{bottom:0 !important}
|
||||
body.pz #hint{bottom:calc(min(46%,330px) + 8px) !important}
|
||||
.pzbig{font-size:40px}
|
||||
}
|
||||
/* Phones (97-puzzles-phone.js): nothing scrolls. A bar pinned at the top holds the puzzle's state and the next thing to
|
||||
do; a city or a link opens a card at the bottom, split into tabs that each fit. --pzdock is the bar's height. */
|
||||
@media (max-width:760px),(max-height:500px) and (pointer:coarse){
|
||||
body.pz #hud{display:none}
|
||||
#pzBox.dock{top:calc(env(safe-area-inset-top,0px) + 6px);bottom:auto;left:max(6px,env(safe-area-inset-left,0px));right:max(6px,env(safe-area-inset-right,0px));width:auto;max-height:none;overflow:visible;border-radius:16px;border:3px solid var(--ink);box-shadow:3px 3px 0 var(--ink);padding:6px 8px 7px}
|
||||
body.pz.sheet-open #pzBox.dock{display:block}
|
||||
body.pz.sheet-open #pzBox.dock .pzd-goal,body.pz.sheet-open #pzBox.dock .pzd-chips{display:none}
|
||||
.pzd-bar{display:flex;align-items:center;gap:6px;min-width:0}
|
||||
.pzd-nm{flex:1 1 auto;min-width:0;font:800 15px/1.2 var(--display);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.pzd-stars{display:flex;gap:2px;flex:none}
|
||||
.pzd-st{display:inline-grid;place-items:center;width:22px;height:22px;border:2px solid var(--line);border-radius:50%;font:900 11px var(--body);color:var(--ink2);box-sizing:border-box}
|
||||
.pzd-st.on{border:0;font-size:17px}.pzd-st.cur{border-color:var(--warn);background:#FFF4D6;color:var(--ink)}
|
||||
.pzd-bud{flex:none;font-weight:900;font-size:12.5px;font-variant-numeric:tabular-nums;white-space:nowrap}.pzd-bud.bad{color:var(--bad)}
|
||||
#pzBox.dock .pzd-bar .b.sm{min-width:36px;min-height:36px;padding:2px 8px;font-size:16px}
|
||||
.pzd-goal{display:flex;align-items:center;gap:8px;margin-top:6px;padding:5px 8px;background:#FFF4D6;border:2px solid var(--warn);border-radius:12px}
|
||||
.pzd-goal.done{background:#DFFBEA;border-color:var(--ok)}.pzd-goal.bad{background:#FFE6E9;border-color:var(--bad)}
|
||||
#pzBox.dock .arsteps{margin:6px 0 4px}#pzBox.dock .arsteps i{height:6px}#pzBox.dock .arbrief{font-size:13px;margin:0 0 2px}
|
||||
#pzBox.dock .arsites{display:contents}#pzBox.dock .arsite{font-size:12px;padding:2px 8px}
|
||||
body.pz.sheet-open #pzBox.dock .arbrief,body.pz.sheet-open #pzBox.dock .arsteps{display:none}
|
||||
.pzd-goal{flex-wrap:wrap}.pzd-gi{flex:none;font-size:16px}.pzd-gt{flex:1 1 170px;min-width:0;font-size:13px;line-height:1.3}.pzd-gt b{font-weight:800}
|
||||
.pzd-ga{flex:none;display:flex;flex-direction:column;gap:4px}#pzBox.dock .pzd-ga{margin-left:auto}#pzBox.dock .pzd-ga .b{min-height:32px;padding:2px 10px;font-size:13px;white-space:nowrap}
|
||||
.pzd-chips{display:flex;flex-wrap:wrap;gap:4px;margin-top:6px}
|
||||
.pzd-chip{font:800 12px/1.2 var(--body);color:var(--ink);background:#fff;border:2px solid var(--line);border-radius:999px;padding:3px 8px;white-space:nowrap;max-width:100%;overflow:hidden;text-overflow:ellipsis;cursor:pointer}
|
||||
.pzd-chip b{font-weight:900;font-variant-numeric:tabular-nums}.pzd-chip .bad{color:var(--bad)}
|
||||
.pzd-chip.ok{border-color:var(--ok);background:#DFFBEA}.pzd-chip.part{border-color:var(--warn);background:#FFF4D6}.pzd-chip.none{border-color:var(--bad);background:#FFE6E9}
|
||||
.pzd-chip.rule{cursor:default;color:var(--ink2)}
|
||||
/* The card: as tall as its tab, under the bar at most; tabs keep each part short enough to need no scrolling. */
|
||||
body.pz #panel{max-height:calc(100% - var(--pzdock,60px) - 18px - env(safe-area-inset-top,0px)) !important}
|
||||
body.pz #panel>.grab{display:none}
|
||||
body.pz #panel .pzd-ph{padding:10px 12px 6px;align-items:center}body.pz #panel .pzd-ph .grow{min-width:0}
|
||||
body.pz #panel .pzd-ph h2{font-size:20px;line-height:1.15}body.pz #panel .pzd-ph h2 small{font:700 12px var(--body);color:var(--ink2);white-space:normal}
|
||||
body.pz #panel .pzd-ph .eyebrow .mine{color:var(--me)}
|
||||
.pzd-body{padding:0 14px calc(10px + env(safe-area-inset-bottom,0px))}
|
||||
.pzd-tabs{display:flex;gap:4px;margin:6px 0 8px;border-bottom:2px solid var(--line)}
|
||||
.pzd-tabs button{flex:1;font:800 13px var(--body);color:var(--ink2);background:none;border:0;border-bottom:3px solid transparent;margin-bottom:-2px;padding:6px 2px;min-height:36px}
|
||||
.pzd-tabs button.on{color:var(--ink);border-bottom-color:var(--me)}
|
||||
.pzd-row{display:flex;align-items:center;gap:8px;padding:4px 0;border-bottom:1.5px dashed var(--line);font-size:13px}.pzd-row .grow{min-width:0}.pzd-row.on{background:#FFE3F0;border-radius:8px}
|
||||
.pzd-to{flex-wrap:wrap}.pzd-foot{justify-content:flex-end}
|
||||
.pzd-models{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:5px;margin-top:6px}
|
||||
.pzd-model{display:flex;flex-direction:column;align-items:flex-start;gap:0;text-align:left;font:inherit;color:var(--ink);background:#fff;border:2px solid var(--ink);border-radius:10px;padding:3px 7px;min-width:0;cursor:pointer}
|
||||
.pzd-mh{display:flex;gap:6px;width:100%;align-items:baseline}.pzd-mh b{flex:1 1 auto;min-width:0;font-size:12.5px;font-weight:900;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.pzd-mh span{flex:none;font-weight:900;font-size:12.5px}
|
||||
.pzd-model small{font-size:11px;color:var(--ink2);line-height:1.25;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.pzd-model.on{background:#FFE3F0;border-color:var(--me)}.pzd-model:disabled:not(.on){opacity:.45;border-color:var(--line)}
|
||||
.pzd-rt{margin:6px 0 0}.pzd-rt .b{min-height:34px}
|
||||
.pzd-tiers{display:grid;grid-template-columns:1fr 1fr;gap:6px}.pzd-tiers .b{margin:0;display:flex;flex-direction:column;align-items:center;gap:0;white-space:normal;line-height:1.15;padding:4px 6px}.pzd-tiers .b small{font-size:11px}
|
||||
/* What a routing metric does, and the redundancy check's question, are on the desktop card; here the buttons speak. */
|
||||
.pzd-routing section{margin:0}.pzd-routing h3{font-size:15px;margin:4px 0}.pzd-routing .note,.pzd-routing .lead{display:none}.pzd-routing .btns{margin:4px 0 8px}
|
||||
body.pz #hint{bottom:calc(env(safe-area-inset-bottom,0px) + 12px) !important}
|
||||
body.pz #toasts{top:calc(env(safe-area-inset-top,0px) + var(--pzdock,60px) + 14px) !important;bottom:auto !important}
|
||||
}
|
||||
@media (orientation:landscape) and (max-height:500px) and (pointer:coarse),(orientation:landscape) and (max-width:760px) and (max-height:500px){
|
||||
#pzBox{left:auto;right:0;width:min(360px,52%);top:calc(env(safe-area-inset-top,0px) + 50px);max-height:calc(100% - 50px - env(safe-area-inset-top,0px));overscroll-behavior:contain;border-radius:20px 0 0 0;border-right:0}
|
||||
#pzBox .pzj{display:none}#pzBox .pzs span{font-size:16px;padding:1px 0}
|
||||
body.pz #hint{bottom:12px !important;left:30% !important}
|
||||
body.pz #toasts{left:8px !important;transform:none !important;width:calc(48% - 16px) !important}
|
||||
#pzBox.dock{right:auto;width:min(380px,46%)}
|
||||
body.pz #toasts{top:auto !important;bottom:12px !important;left:8px !important;transform:none !important;width:calc(46% - 16px) !important}
|
||||
/* The bar sits on the left here, so the card on the right can have the whole height. */
|
||||
body.pz #panel{top:calc(env(safe-area-inset-top,0px) + 6px) !important;max-height:calc(100% - 6px - env(safe-area-inset-top,0px)) !important}
|
||||
}
|
||||
/* The weekly puzzle: a badge on the Puzzles door and in the list while this week's puzzle is unplayed. */
|
||||
.pznew{display:inline-block;font:900 10.5px/1.2 var(--body);font-style:normal;text-transform:uppercase;letter-spacing:.04em;background:var(--me);color:#fff;border:2px solid var(--ink);border-radius:999px;padding:1px 7px;white-space:nowrap;vertical-align:1px}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue