From f24abe8fc7d19f2363864232908ddc32c33d6c70 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 29 Oct 2026 11:44:39 +0100 Subject: [PATCH] Puzzles keep going until three stars: a cheer for each new star, results at three or on Finish --- site/i18n/de.js | 2 ++ site/i18n/es.js | 2 ++ site/i18n/fr.js | 2 ++ site/i18n/it.js | 2 ++ site/i18n/pt.js | 2 ++ src/game/60-features/92-puzzles.js | 6 ++++-- src/game/90-actions/95-puzzles.js | 1 + src/game/95-modals/95-puzzles.js | 7 ++++--- src/i18n/en.js | 2 ++ tests/puzzles.test.js | 6 +++++- 10 files changed, 26 insertions(+), 6 deletions(-) diff --git a/site/i18n/de.js b/site/i18n/de.js index 3e92480..5a70307 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -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.", diff --git a/site/i18n/es.js b/site/i18n/es.js index fa2aec2..ddaaea1 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -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.", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 030f85f..a45927a 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -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.", diff --git a/site/i18n/it.js b/site/i18n/it.js index 09c5feb..9afaeb6 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -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.", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index 32d8965..0dba80c 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -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.", diff --git a/src/game/60-features/92-puzzles.js b/src/game/60-features/92-puzzles.js index 4b2b9ee..c840b9f 100644 --- a/src/game/60-features/92-puzzles.js +++ b/src/game/60-features/92-puzzles.js @@ -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{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();}, diff --git a/src/game/95-modals/95-puzzles.js b/src/game/95-modals/95-puzzles.js index cb22b32..e0311fd 100644 --- a/src/game/95-modals/95-puzzles.js +++ b/src/game/95-modals/95-puzzles.js @@ -29,7 +29,7 @@ function pzRender(){const el=$('pzBox');if(!pzOn()){el.hidden=true;return;}el.hi const w=e.worst; h+=!e.goal?`
🛡 ${tr('puzzles.n_1_deliver_everything_first')}
`:e.n1?`
🛡 ${tr('puzzles.survives_any_single_cut_under_load')}
` :`
⚠️ ${tr('puzzles.a_cut_on_where_drops_g',{where:pzUnitName(w.u),g:fmtG(w.g)})}
${w.lost.map(x=>esc(pzFlowName(P.dem[x.i]))).join(', ')}
`; - h+=`
${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')}
`; + h+=`
${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')}
`; 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)=>`
${ok?'⭐':'☆'} ${l}${v}
`; const stars=[0,1,2].map(i=>`⭐`).join(''); - openModal(`
${e.stars>=3?pzConfetti():''}
${tr('puzzles.puzzle_solved')}

${esc(pzName(pzDef(P.id)||P))}

+ openModal(`
${e.stars>=3?pzConfetti():''}
${done?tr('puzzles.puzzle_solved'):tr('puzzles.your_stars_so_far')}

${esc(pzName(pzDef(P.id)||P))}

${stars}

${pzLine(e)}

${left==null?'':`

${left?trn('puzzles.n_stars_left_in_this_pack',left):tr('puzzles.every_star_in_this_pack_is')}

`} ${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)}))}
${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')}
`); @@ -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{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)}
${pzLine(e)}`,'goal');for(let i=prev;i{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+=`
🖼️ ${tr('puzzles.puzzles_got_traffic_note',{n:p.old})}
`;p.noted=1;pzStore(p);} h+=`
${tr('puzzles.your_stars')}⭐ ${tot} / ${max}
${nxP?`
${tr('puzzles.next_pack_unlocks_at_n',{n:nxP.need,pack:esc(nxP.n)})}
`:''}${p.old?`
🖼️ ${tr('puzzles.framed_n_stars_from_the_old',{n:p.old})}
`:''}
`; - if(pzOn())h+=`
${btn(UI.pzFrom==='game'?tr('puzzles.back_to_my_network'):tr('puzzles.back_to_the_title'),'pzLeave',{},'')}${btn(tr('puzzles.keep_building'),'closeModal',{},'ghost')}
`; + if(pzOn())h+=`
${(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')}
`; 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+=`

${open?'':'🔒 '}${esc(pk.n)} ⭐ ${got}/${n*3}

${open?esc(pk.d):tr('puzzles.unlocks_at_n_stars',{n:pk.need})}

`; diff --git a/src/i18n/en.js b/src/i18n/en.js index eec9b80..c0e470a 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -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.", diff --git a/tests/puzzles.test.js b/tests/puzzles.test.js index 8e1db0d..de3ba39 100644 --- a/tests/puzzles.test.js +++ b/tests/puzzles.test.js @@ -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/);