Puzzles keep going until three stars: a cheer for each new star, results at three or on Finish
This commit is contained in:
parent
2eb22d1df3
commit
f24abe8fc7
10 changed files with 26 additions and 6 deletions
|
|
@ -2948,6 +2948,7 @@
|
|||
"puzzles.every_star_in_this_pack_is":"Alle Sterne in diesem Paket gehören dir.",
|
||||
"puzzles.everything_at_once_across_oceans":"Alles auf einmal, über Ozeane. Knappe Budgets.",
|
||||
"puzzles.fat_pipes":"Dicke Rohre",
|
||||
"puzzles.finish_here":"Hier aufhören",
|
||||
"puzzles.fjord_focus":"Fjord im Fokus",
|
||||
"puzzles.flash_boys":"Flash Boys",
|
||||
"puzzles.flow_circuit_a_b":"Leitung {a} ⇄ {b}",
|
||||
|
|
@ -3066,6 +3067,7 @@
|
|||
"puzzles.your_pop":"Dein POP",
|
||||
"puzzles.your_routers_pick_the_path":"Deine Router wählen den Weg. Sag ihnen welchen: Metriken, niedrigste Latenz, Best Effort.",
|
||||
"puzzles.your_stars":"Deine Sterne",
|
||||
"puzzles.your_stars_so_far":"Deine Sterne bisher",
|
||||
"puzzles_weekly.detour":"Umleitung",
|
||||
"puzzles_weekly.island_hopping":"Inselhüpfen",
|
||||
"puzzles_weekly.joke_a_ring_survives_one_cut":"Ein Ring übersteht jeden einzelnen Schnitt. Genau dafür ist er ein Ring.",
|
||||
|
|
|
|||
|
|
@ -2946,6 +2946,7 @@
|
|||
"puzzles.every_star_in_this_pack_is":"Todas las estrellas de este paquete son tuyas.",
|
||||
"puzzles.everything_at_once_across_oceans":"Todo a la vez, cruzando océanos. Presupuestos ajustados.",
|
||||
"puzzles.fat_pipes":"Tubos gordos",
|
||||
"puzzles.finish_here":"Terminar aquí",
|
||||
"puzzles.fjord_focus":"Rumbo al fiordo",
|
||||
"puzzles.flash_boys":"Flash Boys",
|
||||
"puzzles.flow_circuit_a_b":"Circuito {a} ⇄ {b}",
|
||||
|
|
@ -3064,6 +3065,7 @@
|
|||
"puzzles.your_pop":"Tu POP",
|
||||
"puzzles.your_routers_pick_the_path":"Tus routers eligen el camino. Diles cuál: métricas, menor latencia, best effort.",
|
||||
"puzzles.your_stars":"Tus estrellas",
|
||||
"puzzles.your_stars_so_far":"Tus estrellas hasta ahora",
|
||||
"puzzles_weekly.detour":"Desvío",
|
||||
"puzzles_weekly.island_hopping":"De isla en isla",
|
||||
"puzzles_weekly.joke_a_ring_survives_one_cut":"Un anillo sobrevive a cualquier corte. Para eso es un anillo.",
|
||||
|
|
|
|||
|
|
@ -2946,6 +2946,7 @@
|
|||
"puzzles.every_star_in_this_pack_is":"Toutes les étoiles de ce pack sont à toi.",
|
||||
"puzzles.everything_at_once_across_oceans":"Tout à la fois, par-delà les océans. Budgets serrés.",
|
||||
"puzzles.fat_pipes":"Gros tuyaux",
|
||||
"puzzles.finish_here":"Terminer ici",
|
||||
"puzzles.fjord_focus":"Cap sur le fjord",
|
||||
"puzzles.flash_boys":"Flash Boys",
|
||||
"puzzles.flow_circuit_a_b":"Circuit {a} ⇄ {b}",
|
||||
|
|
@ -3064,6 +3065,7 @@
|
|||
"puzzles.your_pop":"Ton POP",
|
||||
"puzzles.your_routers_pick_the_path":"Tes routeurs choisissent le chemin. Dis-leur lequel : métriques, latence minimale, best effort.",
|
||||
"puzzles.your_stars":"Tes étoiles",
|
||||
"puzzles.your_stars_so_far":"Tes étoiles pour l'instant",
|
||||
"puzzles_weekly.detour":"Détour",
|
||||
"puzzles_weekly.island_hopping":"Saut d’île en île",
|
||||
"puzzles_weekly.joke_a_ring_survives_one_cut":"Un anneau survit à n’importe quelle coupure. C’est tout l’intérêt d’un anneau.",
|
||||
|
|
|
|||
|
|
@ -2946,6 +2946,7 @@
|
|||
"puzzles.every_star_in_this_pack_is":"Tutte le stelle di questo pacchetto sono tue.",
|
||||
"puzzles.everything_at_once_across_oceans":"Tutto insieme, oltre gli oceani. Budget stretti.",
|
||||
"puzzles.fat_pipes":"Tubi grossi",
|
||||
"puzzles.finish_here":"Finisci qui",
|
||||
"puzzles.fjord_focus":"Fuoco sul fiordo",
|
||||
"puzzles.flash_boys":"Flash Boys",
|
||||
"puzzles.flow_circuit_a_b":"Circuito {a} ⇄ {b}",
|
||||
|
|
@ -3064,6 +3065,7 @@
|
|||
"puzzles.your_pop":"Il tuo POP",
|
||||
"puzzles.your_routers_pick_the_path":"I tuoi router scelgono il percorso. Digli quale: metriche, latenza minima, best effort.",
|
||||
"puzzles.your_stars":"Le tue stelle",
|
||||
"puzzles.your_stars_so_far":"Le tue stelle finora",
|
||||
"puzzles_weekly.detour":"Deviazione",
|
||||
"puzzles_weekly.island_hopping":"Di isola in isola",
|
||||
"puzzles_weekly.joke_a_ring_survives_one_cut":"Un anello sopravvive a qualsiasi taglio. È proprio il bello dell’anello.",
|
||||
|
|
|
|||
|
|
@ -2946,6 +2946,7 @@
|
|||
"puzzles.every_star_in_this_pack_is":"Todas as estrelas deste pacote são suas.",
|
||||
"puzzles.everything_at_once_across_oceans":"Tudo de uma vez, atravessando oceanos. Orçamentos apertados.",
|
||||
"puzzles.fat_pipes":"Canos grossos",
|
||||
"puzzles.finish_here":"Terminar aqui",
|
||||
"puzzles.fjord_focus":"Foco no fiorde",
|
||||
"puzzles.flash_boys":"Flash Boys",
|
||||
"puzzles.flow_circuit_a_b":"Circuito {a} ⇄ {b}",
|
||||
|
|
@ -3064,6 +3065,7 @@
|
|||
"puzzles.your_pop":"Seu POP",
|
||||
"puzzles.your_routers_pick_the_path":"Seus routers escolhem o caminho. Diga qual: métricas, menor latência, best effort.",
|
||||
"puzzles.your_stars":"Suas estrelas",
|
||||
"puzzles.your_stars_so_far":"Suas estrelas até agora",
|
||||
"puzzles_weekly.detour":"Desvio",
|
||||
"puzzles_weekly.island_hopping":"De ilha em ilha",
|
||||
"puzzles_weekly.joke_a_ring_survives_one_cut":"Um anel sobrevive a qualquer corte. É para isso que serve um anel.",
|
||||
|
|
|
|||
|
|
@ -145,9 +145,11 @@ function pzCam(){const cs=[...S.pz.cities,...S.pz.via].map(c=>CITY[c]),x0=cs[0].
|
|||
function pzSnap(){const h=UI.pzHist||(UI.pzHist=[]);h.push(JSON.stringify({p:S.pops,l:S.links,m:S.pairMet||{},r:S.biz.map(b=>b.route)}));if(h.length>60)h.shift();}
|
||||
function pzAfter(){if(UI.sel&&((UI.sel.type==='link'&&!S.links.some(l=>l.id===UI.sel.id))||(UI.sel.type==='city'&&!pzKind(UI.sel.id))))UI.sel=null;
|
||||
compute();renderAll();pzCheck();}
|
||||
// Stars count the moment they are earned: a better result than this attempt has had opens the results card.
|
||||
// Stars count the moment they are earned.
|
||||
// Every solved state is recorded, so a cheaper build at the same stars counts too.
|
||||
function pzCheck(){const e=pzEval();if(e.stars)pzRecord(e);if(e.stars<=(UI.pzTop||0))return e;const prev=UI.pzTop||0;UI.pzTop=e.stars;pzResults(e,prev);return e;}
|
||||
// A new star below three is a cheer and a nudge, and play goes on; the results card opens at three stars, or when the
|
||||
// player says they are done (the card's Finish button).
|
||||
function pzCheck(){const e=pzEval();if(e.stars)pzRecord(e);if(e.stars<=(UI.pzTop||0))return e;const prev=UI.pzTop||0;UI.pzTop=e.stars;if(e.stars>=3)pzResults(e,prev);else{pzCheer(e,prev);renderAll();}return e;}
|
||||
// The best spend belongs to the best star count: more stars start it again, the same stars keep the lower spend.
|
||||
function pzRecord(e){const p=pzLoad(),P=S.pz,bag=P.id==='weekly'?p.wk:p.s,k=P.id==='weekly'?P.key:P.id,r=(P.id==='weekly'?pzWkRec(p,P):bag[k])||{st:0,sp:null};
|
||||
if(e.stars<r.st||(e.stars===r.st&&r.sp!=null&&r.sp<=e.spend))return;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ Object.assign(ACT,{
|
|||
puzzleMenu:()=>{if(S&&UI.started&&!pzOn())UI.nm=S.name;pzMenu();},
|
||||
pzStart:({id})=>{const d=pzDef(id);if(!d||!pzPackOpen(d.pack))return;pzBegin(d);},
|
||||
pzWeekly:()=>{if(pzWkLoading())return;pzBegin(pzWkDef());},
|
||||
pzFinish:()=>{if(!pzOn())return;const e=pzEval();if(e.stars)pzResults(e,e.stars);},
|
||||
pzRetry:()=>{if(!pzOn())return;pzBegin(S.pz.id==='weekly'?pzWkDef():pzDef(S.pz.id));},
|
||||
pzLeave:()=>{if(pzOn())pzLeave();},
|
||||
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();},
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ function pzRender(){const el=$('pzBox');if(!pzOn()){el.hidden=true;return;}el.hi
|
|||
const w=e.worst;
|
||||
h+=!e.goal?`<div class="pzn1">🛡 ${tr('puzzles.n_1_deliver_everything_first')}</div>`:e.n1?`<div class="pzn1 on">🛡 ${tr('puzzles.survives_any_single_cut_under_load')}</div>`
|
||||
:`<div class="pzn1 bad">⚠️ ${tr('puzzles.a_cut_on_where_drops_g',{where:pzUnitName(w.u),g:fmtG(w.g)})}<br><small>${w.lost.map(x=>esc(pzFlowName(P.dem[x.i]))).join(', ')}</small></div>`;
|
||||
h+=`<div class="btns">${btn('↶ '+tr('puzzles.undo'),'pzUndo',{},'ghost sm',!(UI.pzHist&&UI.pzHist.length))}${btn(tr('puzzles.reset'),'pzReset',{},'ghost sm',!S.links.length&&!Object.keys(S.pops).length)}${btn(UI.pzFrom==='game'?tr('puzzles.back_to_my_network'):tr('puzzles.back_to_the_title'),'pzLeave',{},'ghost sm')}</div>`;
|
||||
h+=`<div class="btns">${btn('↶ '+tr('puzzles.undo'),'pzUndo',{},'ghost sm',!(UI.pzHist&&UI.pzHist.length))}${btn(tr('puzzles.reset'),'pzReset',{},'ghost sm',!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',{},'ghost sm')}</div>`;
|
||||
if(h!==UI._pzh){UI._pzh=h;morph(el,h);}}
|
||||
// Trenches on a pair get numbers, cables their names, so parallel links say where they run.
|
||||
function pzTrench(l){if(l.cable)return esc(CAB[l.cable].name);const us=[...new Set(pairLinks(l.a,l.b).filter(x=>!x.cable).map(pzUnit))];return tr('puzzles.trench_n',{n:us.indexOf(pzUnit(l))+1});}
|
||||
|
|
@ -106,7 +106,7 @@ function pzConfetti(){if(!animOn())return '';const cols=['#FF4F9A','#FFD23F','#2
|
|||
function pzResults(e,prev){const P=S.pz,nx=P.id==='weekly'?null:pzNextDef(),left=pzPackLeft(P),done=e.stars>=3;
|
||||
const row=(ok,l,v)=>`<div class="kv"><span>${ok?'⭐':'☆'} ${l}</span><b>${v}</b></div>`;
|
||||
const stars=[0,1,2].map(i=>`<span class="pzbig${i<e.stars?' on':''}${i>=prev&&i<e.stars?' pop':''}" style="--d:${Math.max(0,i-prev)*0.45}s">⭐</span>`).join('');
|
||||
openModal(`<div class="pzres">${e.stars>=3?pzConfetti():''}<div style="display:flex;align-items:center"><div class="grow"><div class="eyebrow">${tr('puzzles.puzzle_solved')}</div><h2 style="font-size:28px">${esc(pzName(pzDef(P.id)||P))}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div>
|
||||
openModal(`<div class="pzres">${e.stars>=3?pzConfetti():''}<div style="display:flex;align-items:center"><div class="grow"><div class="eyebrow">${done?tr('puzzles.puzzle_solved'):tr('puzzles.your_stars_so_far')}</div><h2 style="font-size:28px">${esc(pzName(pzDef(P.id)||P))}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div>
|
||||
<div class="pzstars">${stars}</div><p class="tagline" style="text-align:center">${pzLine(e)}</p>${left==null?'':`<p class="pzleft">${left?trn('puzzles.n_stars_left_in_this_pack',left):tr('puzzles.every_star_in_this_pack_is')}</p>`}
|
||||
${row(true,tr('puzzles.delivered'),tr('puzzles.every_bit_arrives'))}${row(e.cheap,tr('puzzles.budget'),P.budget?tr('puzzles.spent_x_of_y',{x:fmt$(e.spend),y:fmt$(P.budget)}):tr('puzzles.on_the_house'))}${row(e.n1,'N-1',e.n1?tr('puzzles.survives_any_single_cut_under_load'):tr('puzzles.a_cut_on_where_drops_g',{where:pzUnitName(e.worst.u),g:fmtG(e.worst.g)}))}
|
||||
<div class="btns cta${done?' pzdone':''}" style="margin-top:12px">${nx?btn(tr('puzzles.next_puzzle')+(done?' →':''),'pzStart',{id:nx.id},'pink big pznext'):btn(tr('puzzles.more_puzzles'),'puzzleMenu',{},'pink big pznext')}${!done?btn(tr('puzzles.retry_for_3_stars'),'pzRetry',{},''):''}${btn(tr('common.share_2cd9'),'pzShare',{},done?'ghost':'')}${btn(tr('puzzles.keep_building'),'closeModal',{},'ghost')}</div></div>`);
|
||||
|
|
@ -114,6 +114,7 @@ function pzResults(e,prev){const P=S.pz,nx=P.id==='weekly'?null:pzNextDef(),left
|
|||
if(done){const b=document.querySelector('#modalCard .pznext');if(b)try{b.focus({preventScroll:true});}catch(_){}}
|
||||
for(let i=prev;i<e.stars;i++)setTimeout(()=>{sfx('star');haptic(15);},Math.max(0,i-prev)*450+150);
|
||||
if(e.stars>=3&&prev<3)setTimeout(()=>sfx('fanfare'),(3-prev)*450+250);}
|
||||
function pzCheer(e,prev){toast(`${'⭐'.repeat(e.stars)}${'☆'.repeat(3-e.stars)}<br>${pzLine(e)}`,'goal');for(let i=prev;i<e.stars;i++)setTimeout(()=>{sfx('star');haptic(15);},(i-prev)*450+150);}
|
||||
// ---------- the list ----------
|
||||
// The weekly row: the published puzzle once it has come (or the seeded one), its countdown and the streak.
|
||||
function pzWkRow(){const p=pzLoad(),w=pzWkDef(),wr=pzWkRec(p,w),st=p.streak,streak=st.last===w.key||st.last===pzPrevKey(w.key)?st.n:0,T=PZ_WK_THEMES[w.theme],load=pzWkLoading(),tg=pzDemTag(w);
|
||||
|
|
@ -127,7 +128,7 @@ function pzMenu(){pzWkEnsure();const p=pzLoad(),tot=pzStarsTotal(p),max=PZ.lengt
|
|||
// 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);}
|
||||
h+=`<div class="pzprog"><div class="kv"><span>${tr('puzzles.your_stars')}</span><b>⭐ ${tot} / ${max}</b></div><div class="bar me"><i style="width:${(tot/max*100).toFixed(1)}%"></i></div>${nxP?`<div class="meta">${tr('puzzles.next_pack_unlocks_at_n',{n:nxP.need,pack:esc(nxP.n)})}</div>`:''}${p.old?`<div class="meta">🖼️ ${tr('puzzles.framed_n_stars_from_the_old',{n:p.old})}</div>`:''}</div>`;
|
||||
if(pzOn())h+=`<div class="btns" style="margin:8px 0">${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">${(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+=pzWkRow();
|
||||
for(const pk of PZ_PACKS){const open=tot>=pk.need,got=PZ.filter(x=>x.pack===pk.id).reduce((a,x)=>a+((p.s[x.id]||{}).st|0),0),n=PZ.filter(x=>x.pack===pk.id).length;
|
||||
h+=`<h3 class="pzpack">${open?'':'🔒 '}${esc(pk.n)} <span class="meta">⭐ ${got}/${n*3}</span></h3><p class="meta" style="margin:0 0 2px">${open?esc(pk.d):tr('puzzles.unlocks_at_n_stars',{n:pk.need})}</p>`;
|
||||
|
|
|
|||
|
|
@ -2947,6 +2947,7 @@
|
|||
"puzzles.every_star_in_this_pack_is":"Every star in this pack is yours.",
|
||||
"puzzles.everything_at_once_across_oceans":"Everything at once, across oceans. Tight budgets.",
|
||||
"puzzles.fat_pipes":"Fat Pipes",
|
||||
"puzzles.finish_here":"Finish here",
|
||||
"puzzles.fjord_focus":"Fjord Focus",
|
||||
"puzzles.flash_boys":"Flash Boys",
|
||||
"puzzles.flow_circuit_a_b":"{a} ⇄ {b} circuit",
|
||||
|
|
@ -3065,6 +3066,7 @@
|
|||
"puzzles.your_pop":"Your POP",
|
||||
"puzzles.your_routers_pick_the_path":"Your routers pick the path. Tell them which: metrics, lowest latency, best effort.",
|
||||
"puzzles.your_stars":"Your stars",
|
||||
"puzzles.your_stars_so_far":"Your stars so far",
|
||||
"puzzles_weekly.detour":"Detour",
|
||||
"puzzles_weekly.island_hopping":"Island hopping",
|
||||
"puzzles_weekly.joke_a_ring_survives_one_cut":"A ring survives any one cut. That is the whole point of a ring.",
|
||||
|
|
|
|||
|
|
@ -314,8 +314,12 @@ test('results card: stars, the next puzzle, a retry, a share line and stars left
|
|||
const { ev, errors } = load();
|
||||
ev("localStorage.removeItem('sot-puzzles');pzBegin(pzDef('eurotrip'))");
|
||||
build(ev, REF.eurotrip.one);
|
||||
assert.ok(ev("$('modal').hidden||!document.querySelector('#modalCard .pzres')"), 'two stars: no results card, play goes on');
|
||||
assert.match(ev("document.getElementById('toasts').textContent"), /One backhoe away/, 'a cheer with the next step instead');
|
||||
assert.ok(ev("!!document.querySelector('[data-act=pzFinish]')"), 'and a Finish button on the card');
|
||||
ev("document.querySelector('[data-act=pzFinish]').click()");
|
||||
let card = ev("document.getElementById('modalCard').textContent");
|
||||
assert.match(card, /Puzzle solved/);
|
||||
assert.match(card, /Your stars so far/);
|
||||
assert.equal(evalP(ev).stars, 2, 'delivered, and the budget star is on the house');
|
||||
assert.match(card, /One backhoe away/);
|
||||
assert.match(card, /13 ⭐ left in this pack/);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue