Puzzles: small, calm network builds with stars, packs and a weekly puzzle (#190)
This commit is contained in:
parent
c011022203
commit
7fc8d0f080
28 changed files with 1283 additions and 23 deletions
39
src/game/60-features/90-puzzles-data.js
Normal file
39
src/game/60-features/90-puzzles-data.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* Puzzles: one entry per line, in play order. A puzzle is data:
|
||||
id, pack, n (name), j (one-line joke), cities (all must end up connected), via (optional stepping stones),
|
||||
budget (setup + a year of monthly, 0 = no budget star to chase: it is given), and at most a twist or two:
|
||||
noSub (no subsea cables), ring (one ring through every POP), lat:[a,b,ms] (best path under ms), minG (every link at
|
||||
least this many Gbps), avoid (cities shown on the map that you may not build in). */
|
||||
const PZ_PACKS=[
|
||||
{id:'hello',n:tr('puzzles.hello_world'),d:tr('puzzles.your_first_tubes_no_pressure'),need:0},
|
||||
{id:'fire',n:tr('puzzles.ring_of_fire'),d:tr('puzzles.the_pacific_rim_where_every_hop'),need:6},
|
||||
{id:'speed',n:tr('puzzles.speed_runs'),d:tr('puzzles.beat_the_clock_light_in_glass'),need:14},
|
||||
{id:'n1',n:tr('puzzles.n_1_club'),d:tr('puzzles.for_architects_who_sleep_through_backhoes'),need:22},
|
||||
];
|
||||
const PZ=[
|
||||
{id:'hello',pack:'hello',n:tr('puzzles.hello_world'),j:tr('puzzles.every_internet_starts_with_one_tube'),cities:['lon','nyc'],budget:0},
|
||||
{id:'eurotrip',pack:'hello',n:tr('puzzles.euro_trip'),j:tr('puzzles.three_cities_two_currencies_one_very'),cities:['lon','ams','fra'],budget:0},
|
||||
{id:'shining',pack:'hello',n:tr('puzzles.sea_to_shining_sea'),j:tr('puzzles.four_cities_one_continent_and_a'),cities:['nyc','chi','dal','sjc'],budget:300000},
|
||||
{id:'smorgas',pack:'hello',n:tr('puzzles.smorgasbord'),j:tr('puzzles.four_capitals_one_very_long_winter'),cities:['osl','sto','cph','hel'],budget:190000},
|
||||
{id:'downunder',pack:'hello',n:tr('puzzles.down_under_up_and_running'),j:tr('puzzles.one_very_big_island_and_a'),cities:['syd','mel','bne','adl'],budget:300000},
|
||||
{id:'aloha',pack:'fire',n:tr('puzzles.aloha_latency'),j:tr('puzzles.honolulu_the_world_s_most_scenic'),cities:['sjc','hnl','syd'],budget:1750000},
|
||||
{id:'rimshot',pack:'fire',n:tr('puzzles.pacific_rim_shot'),j:tr('puzzles.seattle_to_singapore_with_a_stop'),cities:['sea','tok','hkg','sin'],budget:1200000},
|
||||
{id:'fire',pack:'fire',n:tr('puzzles.ring_of_fire'),j:tr('puzzles.four_cities_four_cables_one_ring'),cities:['tok','hkg','sin','syd'],ring:true,budget:1600000},
|
||||
{id:'kiwi',pack:'fire',n:tr('puzzles.kiwi_fruit_salad'),j:tr('puzzles.new_zealand_is_far_from_everything'),cities:['akl','syd','sea'],via:['hnl','suv'],budget:1400000},
|
||||
{id:'guam',pack:'fire',n:tr('puzzles.guam_slam'),j:tr('puzzles.a_tiny_island_where_half_the'),cities:['tok','mnl','syd'],via:['gum'],budget:1600000},
|
||||
{id:'flash',pack:'speed',n:tr('puzzles.flash_boys'),j:tr('puzzles.traders_paid_millions_to_shave_milliseconds'),cities:['nyc','lon'],lat:['nyc','lon',27],budget:450000},
|
||||
{id:'pingpong',pack:'speed',n:tr('puzzles.ping_pong_to_tokyo'),j:tr('puzzles.the_pacific_is_big_light_is'),cities:['lax','tok'],via:['sea','sjc'],lat:['lax','tok',47],budget:850000},
|
||||
{id:'suez',pack:'speed',n:tr('puzzles.suez_you_later'),j:tr('puzzles.frankfurt_to_singapore_the_short_way'),cities:['fra','sin'],via:['mrs','bom'],lat:['fra','sin',68],budget:1000000},
|
||||
{id:'samba',pack:'speed',n:tr('puzzles.samba_sprint'),j:tr('puzzles.sao_paulo_to_miami_before_the'),cities:['sao','mia'],via:['for','rio'],lat:['sao','mia',45],budget:950000},
|
||||
{id:'sharks',pack:'n1',n:tr('puzzles.the_shark_tank'),j:tr('puzzles.the_sharks_have_been_biting_again'),cities:['lis','mad','par','mil'],via:['bcn','mrs'],noSub:true,budget:210000},
|
||||
{id:'braces',pack:'n1',n:tr('puzzles.belt_and_braces'),j:tr('puzzles.two_cables_across_the_atlantic_because'),cities:['nyc','lon','dub'],budget:380000},
|
||||
{id:'nofra',pack:'n1',n:tr('puzzles.not_through_frankfurt'),j:tr('puzzles.de_kicks_sales_has_your_number'),cities:['ams','ber','muc','zrh'],via:['ham','dus'],avoid:['fra'],budget:200000},
|
||||
{id:'fatpipes',pack:'n1',n:tr('puzzles.fat_pipes_only'),j:tr('puzzles.nobody_ever_got_fired_for_buying'),cities:['par','mrs','mil','zrh'],minG:100,budget:240000},
|
||||
];
|
||||
// Weekly puzzle pools: each is one landmass and one region, so every pair has an overland route.
|
||||
const PZ_WEEK_POOLS=[
|
||||
['fra','ams','par','mad','mil','ber','waw','vie','sto','cph','prg','zrh','bcn','mrs','muc','bud'],
|
||||
['nyc','chi','dal','sea','sjc','lax','mia','ash','atn','den','bos','hou','phx','tor','mtl'],
|
||||
['sao','rio','bsb','bhz','cwb','poa','ssa','rec','for','cpq'],
|
||||
['syd','mel','bne','adl','cbr','per'],
|
||||
['bom','del','maa','blr','hyd'],
|
||||
];
|
||||
104
src/game/60-features/92-puzzles.js
Normal file
104
src/game/60-features/92-puzzles.js
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/* ================= PUZZLES (#190) =================
|
||||
Small, calm builds: connect a few cities, earn up to three stars. A puzzle runs as its own S (S.mode='puzzle'):
|
||||
no clock, no bills, no incidents, links up at once. That S is never saved. Only progress (stars and best spend per
|
||||
puzzle, weekly results and the weekly streak) is kept, under its own key, so the main save is never touched. */
|
||||
const PZ_KEY='sot-puzzles',PZ_YEAR=12;
|
||||
const pzOn=()=>!!(S&&S.mode==='puzzle'&&S.pz);
|
||||
const pzDef=id=>PZ.find(p=>p.id===id)||null;
|
||||
const pzKind=c=>!pzOn()?null:S.pz.cities.includes(c)?'goal':S.pz.via.includes(c)?'via':S.pz.avoid.includes(c)?'avoid':null;
|
||||
const pzName=d=>d.id==='weekly'?tr('puzzles.weekly_puzzle_key',{key:d.key}):d.n;
|
||||
const pzStarStr=n=>'⭐'.repeat(n)+'⬜'.repeat(3-n);
|
||||
// ---------- progress (localStorage, never trusted) ----------
|
||||
function pzClean(j){const o={s:{},wk:{},streak:{last:null,n:0,best:0}};if(!j||typeof j!=='object')return o;
|
||||
const rec=r=>r&&typeof r==='object'?{st:int(r.st,0,3,0),sp:r.sp==null||!isFinite(+r.sp)||+r.sp<0?null:Math.round(+r.sp)}:null;
|
||||
if(j.s&&typeof j.s==='object')for(const k of Object.keys(j.s)){const r=rec(j.s[k]);if(pzDef(k)&&r)o.s[k]=r;}
|
||||
if(j.wk&&typeof j.wk==='object')for(const k of Object.keys(j.wk)){const r=rec(j.wk[k]);if(/^\d{4}-W\d{2}$/.test(k)&&r)o.wk[k]=r;}
|
||||
const st=j.streak;if(st&&typeof st==='object'){o.streak.last=typeof st.last==='string'&&/^\d{4}-W\d{2}$/.test(st.last)?st.last:null;o.streak.n=int(st.n,0,9999,0);o.streak.best=int(st.best,0,9999,0);}
|
||||
return o;}
|
||||
function pzLoad(){try{return pzClean(JSON.parse(localStorage.getItem(PZ_KEY)||'{}'));}catch(e){return pzClean(null);}}
|
||||
function pzStore(p){try{localStorage.setItem(PZ_KEY,JSON.stringify(p));}catch(e){}}
|
||||
const pzStarsTotal=p=>PZ.reduce((a,x)=>a+((p.s[x.id]||{}).st|0),0);
|
||||
const pzPackOpen=(k,p)=>{const P=PZ_PACKS.find(x=>x.id===k);return !!P&&pzStarsTotal(p||pzLoad())>=P.need;};
|
||||
// ---------- prices: the real game's waves, on day 0, for a year ----------
|
||||
const pzMood=(a,b,sub)=>{const k=waveMarket(a,b,sub);return k.m/k.ero;};
|
||||
// Overland (when the two cities share a landmass) and every cable between them, each with its price factor and latency.
|
||||
function pzRoutes(a,b){const out=[],sub=isSub(a,b);
|
||||
if(!sub){const km=kmBetween(a,b);out.push({via:'land',cab:null,km,sub:false,f:landMult(a,b)*pzMood(a,b,false),ms:km*1.3/200});}
|
||||
for(const c of cablesFor(a,b))if(!out.some(r=>r.via===c.cid))out.push({via:c.cid,cab:c.cid,km:c.km,sub:true,f:CAB[c.cid].price*pzMood(a,b,true),ms:c.km*(CAB[c.cid].lat||1)/200});
|
||||
return out;}
|
||||
const pzMo=(r,tier,div)=>Math.round(waveMo(r.km,r.sub,tier)*r.f*(div?DIVERSE:1));
|
||||
const pzLinkCost=(r,tier,div)=>pzMo(r,tier,div)*PZ_YEAR;// leased waves have no setup fee: a year of rent
|
||||
const pzPopCost=c=>popCost(c)+PZ_YEAR*POP_MO;
|
||||
const PZ_TIERS=[0,1,2];
|
||||
function pzSpend(){let s=0;for(const c in S.pops)s+=pzPopCost(c);for(const l of S.links)s+=l.mo*PZ_YEAR;return s;}
|
||||
// What one backhoe or one anchor takes out: waves in the same trench, or on the same cable between the same cities.
|
||||
const pzUnit=l=>l.cable?'cab:'+l.cable+':'+edgeKey(l):String(l.trench||l.id);
|
||||
// ---------- checks ----------
|
||||
function pzComp(ls,skip,from){const adj={};for(const l of ls){if(skip&&pzUnit(l)===skip)continue;(adj[l.a]=adj[l.a]||[]).push(l.b);(adj[l.b]=adj[l.b]||[]).push(l.a);}
|
||||
const seen=new Set([from]),q=[from];while(q.length){const u=q.pop();for(const v of adj[u]||[])if(!seen.has(v)){seen.add(v);q.push(v);}}return seen;}
|
||||
function pzRingOk(ls){const nb={};for(const l of ls){(nb[l.a]=nb[l.a]||new Set()).add(l.b);(nb[l.b]=nb[l.b]||new Set()).add(l.a);}
|
||||
const ns=Object.keys(nb);if(ns.length<3||!S.pz.cities.every(c=>nb[c])||!Object.keys(S.pops).every(c=>nb[c])||!ns.every(c=>nb[c].size===2))return false;
|
||||
let prev=null,cur=ns[0],n=0;do{const nx=[...nb[cur]].find(x=>x!==prev);prev=cur;cur=nx;n++;}while(cur!==ns[0]&&n<=ns.length);return cur===ns[0]&&n===ns.length;}
|
||||
function pzEval(){const P=S.pz,ls=S.links,cs=P.cities,spend=pzSpend();
|
||||
// The checklist ticks the goal cities that are already joined up: the group holding the most of them.
|
||||
let best=new Set();for(const c of cs){if(!S.pops[c]||best.has(c))continue;const g=pzComp(ls,null,c);if(cs.filter(x=>g.has(x)).length>cs.filter(x=>best.has(x)).length)best=g;}
|
||||
const joined=cs.filter(c=>best.has(c)).length>=2?best:new Set();
|
||||
const marks=cs.map(c=>({c,st:joined.has(c)?2:S.pops[c]?1:0}));
|
||||
const conn=cs.every(c=>joined.has(c));
|
||||
const tw=[];if(P.noSub)tw.push({k:'sub',ok:!S.links.some(l=>l.sub)});
|
||||
if(P.ring)tw.push({k:'ring',ok:pzRingOk(ls)});
|
||||
if(P.lat){const ms=S.pops[P.lat[0]]&&S.pops[P.lat[1]]?bestLat(P.lat[0],P.lat[1]):Infinity;tw.push({k:'lat',ok:ms<=P.lat[2],ms});}
|
||||
if(P.minG)tw.push({k:'g',ok:ls.every(l=>LT[l.tier].g>=P.minG)});
|
||||
if(P.avoid.length)tw.push({k:'avoid',ok:P.avoid.every(c=>!S.pops[c])});
|
||||
const goal=conn&&tw.every(t=>t.ok),units=[...new Set(ls.map(pzUnit))];
|
||||
// N-1: the goal cities stay joined whichever single trench or cable segment is cut.
|
||||
const weak=conn?units.filter(u=>{const g=pzComp(ls,u,cs[0]);return !cs.every(c=>g.has(c));}):[];
|
||||
const n1=conn&&units.length>0&&!weak.length,cheap=!P.budget||spend<=P.budget;
|
||||
return {marks,conn,tw,goal,spend,cheap,n1,weak,stars:goal?1+(cheap?1:0)+(n1?1:0):0};}
|
||||
// ---------- the weekly puzzle: the same for everyone, seeded by the ISO week like the weekly challenge ----------
|
||||
function pzWeekKey(dt){const {y,w}=isoWeek(dt);return `${y}-W${String(w).padStart(2,'0')}`;}
|
||||
function pzPrevKey(key){const m=/^(\d{4})-W(\d{2})$/.exec(key);if(!m)return null;return pzWeekKey(new Date(+m[1],0,4+(+m[2]-2)*7));}
|
||||
function pzWeekly(dt){const key=pzWeekKey(dt||new Date());let r=hstr('puzzle|'+key)||1;const nx=()=>{r=(Math.imul(r,1103515245)+12345)>>>0;return r/4294967296;};
|
||||
const pool=PZ_WEEK_POOLS[Math.floor(nx()*PZ_WEEK_POOLS.length)].slice(),n=4+Math.floor(nx()*2),cities=[];
|
||||
while(cities.length<n&&pool.length)cities.push(pool.splice(Math.floor(nx()*pool.length),1)[0]);
|
||||
// The budget is a ring through the cities, nearest first, on the cheapest 10G route of each hop, plus 10%:
|
||||
// a ring survives any single cut, so three stars are always possible.
|
||||
const ring=[cities[0]],left=cities.slice(1);while(left.length){const u=ring[ring.length-1];left.sort((a,b)=>kmBetween(u,a)-kmBetween(u,b));ring.push(left.shift());}
|
||||
let cost=cities.reduce((a,c)=>a+pzPopCost(c),0);for(let i=0;i<ring.length;i++)cost+=Math.min(...pzRoutes(ring[i],ring[(i+1)%ring.length]).map(x=>pzLinkCost(x,0,false)));
|
||||
return {id:'weekly',key,cities,via:[],budget:Math.ceil(cost*1.1/10000)*10000,ref:ring};}
|
||||
function pzStreak(p,key){const st=p.streak;if(st.last===key)return;st.n=st.last&&st.last===pzPrevKey(key)?st.n+1:1;st.last=key;st.best=Math.max(st.best,st.n);}
|
||||
function pzShareText(e){const P=S.pz;return tr('puzzles.share_line',{what:P.id==='weekly'?P.key:pzName(pzDef(P.id)),stars:pzStarStr(e.stars),spend:fmt$(e.spend)});}
|
||||
// ---------- entering and leaving ----------
|
||||
// The running game gets its usual save first, so leaving the puzzle can load it back exactly as booting does. A huge
|
||||
// save is compressed in the background and may not have landed yet, so the game object is kept in memory too.
|
||||
function pzFlush(){save(true);UI.pzKeep=UI.gzBusy||saveFailing()?S:null;}
|
||||
function pzBegin(def){if(!def)return;
|
||||
const go=()=>{newGame(pzName(def),def.cities[0]);S.pops={};S.mode='puzzle';S.nextFail=S.nextEvent=1e9;S.tut=null;
|
||||
S.pz={id:def.id,key:def.key||null,cities:def.cities.slice(),via:(def.via||[]).slice(),avoid:(def.avoid||[]).slice(),budget:def.budget||0,noSub:!!def.noSub,ring:!!def.ring,minG:def.minG||0,lat:def.lat?def.lat.slice():null};
|
||||
UI.pzHist=[];UI.pzTop=0;UI.speed=0;UI.resumeSpeed=null;UI.started=true;UI.sel=null;UI.leftOpen=false;UI.confirm=null;UI._pzh=null;
|
||||
$('dash').hidden=true;$('bankBox').hidden=true;closeModal();document.body.classList.add('pz');
|
||||
compute();pzCam();renderAll();track('puzzle_'+def.id);
|
||||
toast(`<b>${esc(pzName(def))}</b><br>${tr('puzzles.connect_list',{list:def.cities.map(c=>CITY[c].name).join(', ')})}`,'goal');};
|
||||
if(pzOn()){go();return;}
|
||||
const live=!!(S&&UI.started&&!S.lost);UI.pzFrom=live?'game':'title';
|
||||
if(live)pzFlush();go();}
|
||||
function pzLeave(){const from=UI.pzFrom;document.body.classList.remove('pz');UI.sel=null;UI.pzHist=null;UI.pzFrom=null;closeModal();$('panel').hidden=true;$('pzBox').hidden=true;S=null;R=emptyR();UI.started=false;
|
||||
if(from==='game'){const sv=UI.pzKeep||loadSave();UI.pzKeep=null;
|
||||
if(sv){try{S=migrate(sv);compute();UI.started=true;UI.speed=[0,0.5,1,2,4,8].includes(S.uiSpeed)?S.uiSpeed:1;if(S.cam&&isFinite(S.cam.x))Object.assign(cam,S.cam);renderAll();return;}catch(e){S=null;UI.started=false;}}}
|
||||
renderAll();showTitle();}
|
||||
// The camera frames the puzzle's cities, leaving room for the puzzle card (left on wide screens, a bottom sheet on phones).
|
||||
function pzCam(){const cs=[...S.pz.cities,...S.pz.via].map(c=>CITY[c]),x0=cs[0].x;let a=Infinity,b=-Infinity,c=Infinity,d=-Infinity;
|
||||
for(const C of cs){const x=x0+wrapDx(x0,C.x);a=Math.min(a,x);b=Math.max(b,x);c=Math.min(c,C.y);d=Math.max(d,C.y);}
|
||||
const ph=isPhone(),pl=ph?0:330,pb=ph?Math.min(230,CH*0.4):0,aw=Math.max(120,CW-pl-90),ah=Math.max(120,CH-pb-150);
|
||||
cam.z=clamp(Math.min(aw/Math.max(40,b-a),ah/Math.max(40,d-c)),0.5,4);cam.x=(a+b)/2-pl/2/cam.z;cam.y=(c+d)/2+(pb/2-30)/cam.z;wrapCam();}
|
||||
// ---------- building ----------
|
||||
function pzSnap(){const h=UI.pzHist||(UI.pzHist=[]);h.push(JSON.stringify({p:S.pops,l:S.links}));if(h.length>60)h.shift();}
|
||||
const pzNewPop=()=>({day:0,bb:null,boost:0,down:0,routers:1,gen:false});
|
||||
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.
|
||||
function pzCheck(){const e=pzEval();if(e.stars<=(UI.pzTop||0))return e;const prev=UI.pzTop||0;UI.pzTop=e.stars;pzRecord(e);pzResults(e,prev);return e;}
|
||||
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=bag[k]||{st:0,sp:null};
|
||||
r.st=Math.max(r.st,e.stars);r.sp=r.sp==null?e.spend:Math.min(r.sp,e.spend);bag[k]=r;if(P.id==='weekly')pzStreak(p,P.key);pzStore(p);}
|
||||
// The next puzzle in the list whose pack is open.
|
||||
function pzNextDef(){const p=pzLoad(),i=PZ.findIndex(x=>x.id===S.pz.id);for(let j=i+1;j<PZ.length;j++)if(pzPackOpen(PZ[j].pack,p))return PZ[j];return null;}
|
||||
|
|
@ -4,6 +4,8 @@ const num=(v,d=0)=>{v=+v;return Number.isFinite(v)?v:d;},int=(v,lo,hi,d)=>{v=Mat
|
|||
/* Saves come from localStorage or from imported files, so treat them as untrusted: fill in anything
|
||||
missing, drop references to cities, networks or types that do not exist, and force numbers to be numbers. */
|
||||
function sanitize(s){
|
||||
// A puzzle is never saved; a save that says otherwise is played as a normal game.
|
||||
if(s.mode==='puzzle')s.mode='normal';delete s.pz;
|
||||
const arr=k=>{if(!Array.isArray(s[k]))s[k]=[];},obj=k=>{if(!s[k]||typeof s[k]!=='object'||Array.isArray(s[k]))s[k]={};};
|
||||
['links','nni','transit','pni','caches','biz','offers','inc','usedNames','loans','loanOffers','hist','log'].forEach(arr);
|
||||
['pops','ixp','rs','peers','myIx','done','ev','stats','ixn','ixPref','ixSite','confReg','ach','pairMet'].forEach(obj);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
/* ================= ACTIONS ================= */
|
||||
function spend(c){if(S.cash<c){toast(tr('interface.not_enough_cash_wait_for_revenue'),'bad');sfx('err');return false;}S.cash-=c;sfx('build');return true;}
|
||||
const ACT={
|
||||
speed:({v})=>{v=+v;if(![0,0.5,1,2,4,8].includes(v))return;if(v)UI.lastSpeed=v;UI.speed=v;renderHUD();},
|
||||
speed:({v})=>{v=+v;if(pzOn())return;if(![0,0.5,1,2,4,8].includes(v))return;if(v)UI.lastSpeed=v;UI.speed=v;renderHUD();},
|
||||
help:()=>showHelp(),
|
||||
dash:()=>{if(!S)return;const d=$('dash');d.hidden=!d.hidden;if(!d.hidden)renderDash();},
|
||||
dash:()=>{if(!S||pzOn())return;const d=$('dash');d.hidden=!d.hidden;if(!d.hidden)renderDash();},
|
||||
dashClose:()=>{$('dash').hidden=true;},
|
||||
dashTab:({k})=>{if(!DTABS.includes(k))return;UI.dtab=k;renderDash();const d=$('dash');if(d)d.scrollTop=0;},
|
||||
dashSort:({k})=>{if(!['name','asn','type','traffic','cost','lost'].includes(k))return;if(UI.dashSort===k)UI.dashDir=-(UI.dashDir||-1);else{UI.dashSort=k;UI.dashDir=k==='name'||k==='type'||k==='asn'?1:-1;}renderDash();},
|
||||
bank:()=>{if(!S)return;UI.confirm=null;$('dash').hidden=true;const b=$('bankBox');b.hidden=false;UI._bh=null;renderBank();},
|
||||
bank:()=>{if(!S||pzOn())return;UI.confirm=null;$('dash').hidden=true;const b=$('bankBox');b.hidden=false;UI._bh=null;renderBank();},
|
||||
bankClose:()=>{UI.confirm=null;$('bankBox').hidden=true;},
|
||||
takeLoan:({id})=>{const o=S.loanOffers.find(x=>x.id===id);if(!o)return;S.stats.loans=(S.stats.loans||0)+1;const B=BANKS[o.bank];let got=o.amount,note='';
|
||||
if(B.crypto){const f=0.55+Math.random()*0.8;got=Math.round(o.amount*f);note=' '+(f>=1?tr('interface.tubecoin_moved_up_p_on_the',{p:Math.round(Math.abs(f-1)*100)}):tr('interface.tubecoin_moved_down_p_on_the',{p:Math.round(Math.abs(f-1)*100)}));}
|
||||
|
|
@ -33,8 +33,8 @@ const ACT={
|
|||
meetGo:({city})=>{if(!isCity(city))return;$('dash').hidden=true;ACT.focusCity({city});if(S.pops[city]){UI.tab='peer';renderPanel();}},
|
||||
toggleLeft:()=>{UI.leftOpen=!UI.leftOpen;renderLeft();},
|
||||
phoneTab:({t})=>{if(!['goals','deals','noc','nets'].includes(t))return;haptic(8);if(UI.leftOpen&&UI.left===t&&!UI.sel){UI.leftOpen=false;}else{UI.left=t;UI.leftOpen=true;UI.sel=null;renderPanel();}$('left').classList.remove('full');renderLeft();},
|
||||
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();},
|
||||
phonePlay:()=>{if(pzOn())return;haptic(10);if(UI.speed){UI.lastSpeed=UI.speed;UI.speed=0;}else UI.speed=UI.lastSpeed||1;renderHUD();},
|
||||
phoneSpeed:()=>{if(pzOn())return;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(pitchHtml(false));},
|
||||
pitchSkip:()=>{const p=UI.pendGame;UI.pendGame=null;UI.pitched=true;if(p)beginGame(...p);else closeModal();},
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ Object.assign(ACT,{
|
|||
exportSave:()=>exportSave(),
|
||||
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('game_and_settings.import_failed_that_save_is_damaged'),'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('game_and_settings.welcome_back_name_imported_and_saved',{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('common.close')}">×</button></div>
|
||||
menu:()=>{if(!S||!UI.started){showTitle();return;}if(pzOn()){pzMenu();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('common.close')}">×</button></div>
|
||||
${saveFailing()?`<p class="why">${saveFailMsg()}</p>`:`<p class="tagline">${tr('game_and_settings.your_game_saves_itself_every_few')}</p>`}${isPhone()?installRow():''}
|
||||
<div class="menu-list">
|
||||
${btn(tr('common.back_to_the_map'),'closeModal',{},'pink big')}
|
||||
|
|
@ -21,6 +21,7 @@ Object.assign(ACT,{
|
|||
${btn(tr('game_and_settings.import_a_save_from_a_file'),'importPick',{},'')}
|
||||
${btn(tr('game_and_settings.share_your_network_image_card'),'share',{},'')}
|
||||
${btn(tr('game_and_settings.scenarios_amp_weekly_challenge'),'scenarios',{},'ghost')}
|
||||
${btn(tr('puzzles.puzzles'),'puzzleMenu',{},'ghost')}
|
||||
${btn(tr('common.how_to_play'),'help',{},'ghost')}
|
||||
${RELEASE_NOTES.length?btn(tr('common.what_s_new_in_v',{v:esc(APP_VERSION)}),'whatsNewShow',{},'ghost'):''}
|
||||
${btn(tr('common.settings'),'settings',{},'ghost')}
|
||||
|
|
|
|||
26
src/game/90-actions/95-puzzles.js
Normal file
26
src/game/90-actions/95-puzzles.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
Object.assign(ACT,{
|
||||
// The puzzle list. The ruleset's title-screen door calls this.
|
||||
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:()=>pzBegin(pzWeekly()),
|
||||
pzRetry:()=>{if(!pzOn())return;pzBegin(S.pz.id==='weekly'?pzWeekly():pzDef(S.pz.id));},
|
||||
pzLeave:()=>{if(pzOn())pzLeave();},
|
||||
pzPop:({city})=>{if(!pzOn()||S.pops[city]||!['goal','via'].includes(pzKind(city)))return;pzSnap();S.pops[city]=pzNewPop();sfx('build');haptic(10);floater(CITY[city].x,CITY[city].y-30,tr('common.new_pop'),'#FF4F9A');pzAfter();},
|
||||
pzRmPop:({city})=>{if(!pzOn()||!S.pops[city])return;pzSnap();delete S.pops[city];S.links=S.links.filter(l=>l.a!==city&&l.b!==city);sfx('click');UI.sel=null;pzAfter();},
|
||||
pzLinkTo:({a,b})=>{if(!pzOn()||!S.pops[a]||a===b)return;pzLinkModal(a,b);},
|
||||
pzVia:({v})=>{const p=UI.pending;if(!pzOn()||!p)return;UI.pzVia=v;pzLinkModal(p.a,p.b,true);},
|
||||
pzDiv:({v})=>{const p=UI.pending;if(!pzOn()||!p)return;UI.pzDiv=!!+v;pzLinkModal(p.a,p.b,true);},
|
||||
pzLink:({tier})=>{tier=+tier;const p=UI.pending;if(!pzOn()||!p||!PZ_TIERS.includes(tier))return;const {a,b}=p;if(!S.pops[a]||!['goal','via'].includes(pzKind(b)))return;
|
||||
const r=pzRoutes(a,b).find(x=>x.via===UI.pzVia);if(!r||(S.pz.noSub&&r.sub)||subWaveWhy(tier,r.km,r.sub))return;
|
||||
const same=!r.sub&&UI.pzDiv===false?S.links.find(l=>edgeKey(l)===edgeKey({a,b})&&!l.cable):null,div=!r.sub&&!same&&S.links.some(l=>edgeKey(l)===edgeKey({a,b})&&!l.cable);
|
||||
pzSnap();if(!S.pops[b])S.pops[b]=pzNewPop();const id=uid(),f=r.f*(div?DIVERSE:1);
|
||||
S.links.push({id,a,b,kind:'wave',border:false,premium:false,tier,km:r.km,sub:r.sub,cable:r.cab,mo:pzMo(r,tier,div),mult:f,trench:r.cab?'cab:'+r.cab:same?(same.trench||same.id):id,cut:0,day:0});
|
||||
closeModal();sfx('build');haptic(12);floater((CITY[a].x+CITY[a].x+wrapDx(CITY[a].x,CITY[b].x))/2,(CITY[a].y+CITY[b].y)/2-20,tr('links.wave_lit',{wave:LT[tier].n}),'#FF4F9A');UI.sel=null;pzAfter();},
|
||||
pzTier:({id,tier})=>{tier=+tier;const l=pzOn()&&S.links.find(x=>x.id===id);if(!l||!PZ_TIERS.includes(tier)||l.tier===tier||subWaveWhy(tier,l.km,l.sub))return;pzSnap();l.tier=tier;l.mo=pzMo({km:l.km,sub:l.sub,f:l.mult||1},tier,false);sfx('build');pzAfter();},
|
||||
pzRmLink:({id})=>{if(!pzOn()||!S.links.some(l=>l.id===id))return;pzSnap();S.links=S.links.filter(l=>l.id!==id);sfx('click');UI.sel=null;pzAfter();},
|
||||
pzUndo:()=>{const h=UI.pzHist;if(!pzOn()||!h||!h.length)return;const o=JSON.parse(h.pop());S.pops=o.p;S.links=o.l;sfx('click');pzAfter();},
|
||||
pzReset:()=>{if(!pzOn())return;pzSnap();S.pops={};S.links=[];UI.sel=null;sfx('click');pzAfter();},
|
||||
pzShare:()=>{if(!pzOn())return;const t=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');},
|
||||
});
|
||||
|
|
@ -2,7 +2,8 @@
|
|||
/* A network too big for the browser's storage fails to save every time, and turning it into text takes a
|
||||
moment on huge saves, every 5 seconds and after every click. After a failure the autosave waits before trying
|
||||
again (1 minute, then 2, 4, at most 5); leaving the page, exporting or another game (a new S) still try at once. */
|
||||
function save(force){if(!S||S.lost)return;S.uiSpeed=UI.speed;S.cam={x:cam.x,y:cam.y,z:cam.z};const f=UI.saveFail;
|
||||
// A puzzle is never saved: only its stars are, under their own key (sot-puzzles).
|
||||
function save(force){if(!S||S.lost||S.mode==='puzzle')return;S.uiSpeed=UI.speed;S.cam={x:cam.x,y:cam.y,z:cam.z};const f=UI.saveFail;
|
||||
if(!force&&f&&f.s===S&&performance.now()-f.at<f.wait){UI.lastSave=performance.now();return;}
|
||||
const txt=JSON.stringify(packSave(S));
|
||||
const seq=UI.saveSeq=(UI.saveSeq||0)+1;
|
||||
|
|
@ -25,7 +26,7 @@ const unb64=t=>{const s=atob(t),u=new Uint8Array(s.length);for(let i=0;i<s.lengt
|
|||
const gzip=async txt=>GZ+b64(await gzPipe(new TextEncoder().encode(txt),new CompressionStream('gzip')));
|
||||
const gunzip=async raw=>new TextDecoder().decode(await gzPipe(unb64(raw.slice(GZ.length)),new DecompressionStream('gzip')));
|
||||
function gzSave(s,txt,seq){if(UI.gzBusy){UI.gzNext={s,txt,seq};return;}UI.gzBusy=true;
|
||||
gzip(txt).then(v=>{if(s!==S||seq!==UI.saveSeq)return;try{localStorage.setItem('sot-save-v1',v);UI.saveFail=null;}catch(e){saveErr(e,s);}})
|
||||
gzip(txt).then(v=>{if((s!==S&&s!==UI.pzKeep)||seq!==UI.saveSeq)return;try{localStorage.setItem('sot-save-v1',v);UI.saveFail=null;}catch(e){saveErr(e,s);}})
|
||||
.catch(e=>{console.error('[tubes] compressing the save failed',e);})
|
||||
.finally(()=>{UI.gzBusy=false;const n=UI.gzNext;UI.gzNext=null;if(n&&n.s===S)gzSave(n.s,n.txt,n.seq);});}
|
||||
// A compressed save is unpacked before the game boots, so loadSave() stays synchronous for everything else.
|
||||
|
|
@ -52,7 +53,7 @@ document.addEventListener('visibilitychange',()=>{if(document.visibilityState===
|
|||
/* Export / import: move a network to another device or keep a backup. The file is the same
|
||||
object the autosave writes, wrapped with a little metadata. */
|
||||
function saveFileName(){const d=new Date().toISOString().slice(0,10),n=(S&&S.name||'network').toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/^-|-$/g,'')||'network';return `series-of-tubes-${n}-${d}.json`;}
|
||||
function exportSave(){if(!S)return;save(true);const blob=new Blob([JSON.stringify({app:'series-of-tubes',version:APP_VERSION,exported:new Date().toISOString(),S:packSave(S)},null,1)],{type:'application/json'});
|
||||
function exportSave(){if(!S||S.mode==='puzzle')return;save(true);const blob=new Blob([JSON.stringify({app:'series-of-tubes',version:APP_VERSION,exported:new Date().toISOString(),S:packSave(S)},null,1)],{type:'application/json'});
|
||||
const a=document.createElement('a');a.href=URL.createObjectURL(blob);a.download=saveFileName();document.body.appendChild(a);a.click();setTimeout(()=>{URL.revokeObjectURL(a.href);a.remove();},1000);
|
||||
toast(tr('save.save_exported_file_is_in_your',{file:esc(saveFileName())}),'good');}
|
||||
function parseSave(txt){if(typeof txt!=='string')return {err:tr('save.that_file_is_not_valid_json')};let j;try{j=JSON.parse(txt);}catch(e){return {err:tr('save.that_file_is_not_valid_json')};}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ function sfx(k){if(UI.muted||!AC)return;try{
|
|||
else if(k==='build'){tone(523,0,.07,'triangle',.08);tone(784,.06,.12,'triangle',.08);}
|
||||
else if(k==='err'){tone(180,0,.18,'sawtooth',.04);}
|
||||
else if(k==='alert'){tone(880,0,.1,'square',.04);tone(660,.12,.1,'square',.04);tone(880,.24,.12,'square',.04);}
|
||||
else if(k==='star'){tone(784,0,.09,'triangle',.07);tone(1175,.08,.2,'triangle',.07);}
|
||||
else if(k==='fanfare'){tone(523,0,.12,'triangle',.07);tone(659,.12,.12,'triangle',.07);tone(784,.24,.12,'triangle',.07);tone(1047,.36,.35,'triangle',.08);}
|
||||
else if(k==='click'){tone(660,0,.04,'triangle',.05);}
|
||||
}catch(e){}}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,6 @@ function morphKids(a,b){let x=a.firstChild,y=b.firstChild;
|
|||
else if(x.nodeValue!==y.nodeValue)x.nodeValue=y.nodeValue;
|
||||
x=x&&x.nextSibling;y=ny;}
|
||||
while(x){const nx=x.nextSibling;a.removeChild(x);x=nx;}}
|
||||
function renderAll(){if(isTablet()&&!UI.sel)UI.leftOpen=false;renderHUD();renderLeft();renderPanel();renderHint();renderMega();renderCoach();}
|
||||
function renderAll(){if(isTablet()&&!UI.sel)UI.leftOpen=false;renderHUD();renderLeft();renderPanel();renderHint();renderMega();renderCoach();pzRender();}
|
||||
function renderMega(){const el=$('mega');if(!el)return;const on=!!(S&&S.ev&&S.ev.php>S.day);if(el.hidden===!on)return;el.hidden=!on;}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* ================= PHONE ================= */
|
||||
const isPhone=()=>innerWidth<=760||(innerHeight<=500&&matchMedia('(pointer:coarse)').matches);
|
||||
const SPEEDS=[0.5,1,2,4,8];
|
||||
function renderTabbar(){const tb=$('tabbar');if(!tb||(pressing&&UI.ticking))return;if(!isPhone()||!S||!UI.started){tb.hidden=true;document.body.classList.remove('sheet-open');return;}tb.hidden=false;
|
||||
function renderTabbar(){const tb=$('tabbar');if(!tb||(pressing&&UI.ticking))return;if(!isPhone()||!S||!UI.started||pzOn()){tb.hidden=true;document.body.classList.toggle('sheet-open',pzOn()&&isPhone()&&!!UI.sel);return;}tb.hidden=false;
|
||||
const open=UI.leftOpen&&!UI.sel,cur=UI.left||'goals',ndone=GOALS.filter(g=>S.done[g.id]!==undefined).length;
|
||||
const tab=(k,ic,l,cnt,red)=>`<button class="${open&&cur===k?'on':''}" data-act="phoneTab" data-args='{"t":"${k}"}' aria-label="${esc(l)}"><span class="ic" aria-hidden="true">${ic}</span>${esc(l)}${cnt?`<span class="cnt${red?' red':''}">${cnt}</span>`:''}</button>`;
|
||||
const h=`<button class="play${UI.speed?'':' paused'}" data-act="phonePlay" aria-label="${UI.speed?tr('common.pause'):tr('common.play')}"><span class="ic" aria-hidden="true">${UI.speed?'❚❚':'▶'}</span>${UI.speed?tr('common.pause'):tr('common.play')}</button>`+
|
||||
|
|
@ -15,7 +15,8 @@ function haptic(ms){if(UI.muted)return;try{navigator.vibrate&&navigator.vibrate(
|
|||
document.addEventListener('pointerdown',e=>{const h=e.target.closest('[data-grab]');if(!h||!isPhone())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('full');return;}
|
||||
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(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);})();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ function renderHUD(){
|
|||
for(const v of [0,0.5,1,2,4,8]){const b=$('sp'+v);if(b)b.classList.toggle('on',UI.speed===v);}
|
||||
$('muteBtn').style.opacity=UI.muted?.4:1;
|
||||
if(!S)return;
|
||||
if(pzOn()){$('hName').textContent=pzName(pzDef(S.pz.id)||S.pz);$('hAsn').textContent=tr('puzzles.puzzle');renderTabbar();return;}
|
||||
$('hName').textContent=S.name;$('hAsn').textContent='AS'+S.asn+(S.mode==='sandbox'?' · '+tr('common.sandbox'):S.scn?' · '+(scnName())+(S.scn.done||S.scn.failed?'':` · ${tr('ui.n_d_left',{n:Math.max(0,S.scn.days-S.day)})}`):'');
|
||||
$('hCash').textContent=fmt$(S.cash);$('hCash').style.color=S.cash<0?'var(--bad)':'';
|
||||
const net=R.revMo-R.costMo;$('hRate').innerHTML=`<span class="${net>=0?'up':'down'}">${net>=0?'▲':'▼'} ${tr('common.price_mo',{price:fmt$(Math.abs(net))})}</span>`;
|
||||
|
|
@ -26,7 +27,7 @@ function renderLeft(){checkLayer();
|
|||
// while a city or link is open and comes back with the toggle button.
|
||||
const tab=isTablet(),L=$('left');L.classList.toggle('closed',tab?(!!UI.sel&&!UI.leftOpen):!UI.leftOpen);const tg=$('leftToggle');if(tg&&innerWidth>760)tg.hidden=!(tab&&L.classList.contains('closed'));
|
||||
renderTabbar();
|
||||
if(!S){L.hidden=true;return;}L.hidden=false;
|
||||
if(!S||pzOn()){L.hidden=true;return;}L.hidden=false;
|
||||
const ndone=GOALS.filter(g=>S.done[g.id]!==undefined).length;
|
||||
const tabs=[['goals',`${tr('common.goals')}<span class="cnt">${ndone}/${GOALS.length}</span>`],['deals',`${tr('common.deals')}${S.offers.length?`<span class="cnt">${S.offers.length}</span>`:''}`],['noc',`NOC${S.inc.length?`<span class="cnt red">${S.inc.length}</span>`:''}`],['nets',`${tr('common.networks')}${ibxOpen()?`<span class="cnt${ibxUrgent()?' red':''}">${ibxOpen()}</span>`:''}`]];
|
||||
$('leftTabs').innerHTML=tabs.map(([k,l])=>`<button class="${UI.left===k?'on':''}" data-act="leftTab" data-args='{"t":"${k}"}'>${l}</button>`).join('')+(innerWidth<760?`<button data-act="toggleLeft" style="margin-left:auto" aria-label="${tr('common.close')}">×</button>`:'');
|
||||
|
|
@ -86,6 +87,6 @@ function renderPanel(){checkLayer();
|
|||
if(!S||!UI.sel){P.hidden=true;return;}
|
||||
P.hidden=false;
|
||||
const scrollEl=$('panelBody').querySelector('.scroll');const st=scrollEl?scrollEl.scrollTop:0;
|
||||
const html=UI.sel.type==='city'?cityPanel(UI.sel.id):linkPanel(UI.sel.id);if(html===UI._ph&&!P.hidden&&$('panelBody').firstChild)return;UI._ph=html;morph($('panelBody'),html);
|
||||
const html=pzOn()?pzPanel(UI.sel):UI.sel.type==='city'?cityPanel(UI.sel.id):linkPanel(UI.sel.id);if(!html){P.hidden=true;return;}if(html===UI._ph&&!P.hidden&&$('panelBody').firstChild)return;UI._ph=html;morph($('panelBody'),html);
|
||||
const ns=$('panelBody').querySelector('.scroll');if(ns)ns.scrollTop=st;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
function renderHint(){
|
||||
const hn=$('hint');if(!S||UI.hintOff||(S.tut!==undefined&&S.tut!==null)||(innerWidth<760&&(UI.sel||UI.leftOpen)&&!(UI.drag&&UI.drag.mode==='link'))){hn.hidden=true;return;}
|
||||
let t='';
|
||||
if(pzOn()){t=UI.drag&&UI.drag.mode==='link'?(UI.snap?tr('hint.release_to_plan_a_link'):tr('hint.drag_onto_another_city')):!Object.keys(S.pops).length?tr('puzzles.tap_a_goal_city_to_open'):!S.links.length?tr('puzzles.drag_from_a_pink_pop_to'):'';hn.textContent=t;hn.hidden=!t;return;}
|
||||
if(UI.drag&&UI.drag.mode==='link')t=UI.snap?tr('hint.release_to_plan_a_link'):tr('hint.drag_onto_another_city');
|
||||
else if(!S.links.length&&S.done.tr)t=tr('hint.tip_drag_from_your_pink_router');
|
||||
else if(!S.done.bb)t=tr('hint.tap_your_city_then_launch_broadband');
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ function showTitle(){
|
|||
${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 homes">${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><span id="homeWhat">${homeWhat()}</span>${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">${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')}${/* v2: replaced by the Puzzles door */btn(tr('puzzles.puzzles'),'puzzleMenu',{},'sm')}</div>
|
||||
<label class="f" for="langTitle">${tr('common.language')}</label>${langPick('langTitle')}
|
||||
<div class="btns cta tcta" style="margin-top:16px">${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')}${btn(tr('common.settings'),'settings',{},'ghost')}</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>`);
|
||||
$('nmIn').addEventListener('input',e=>{UI.nm=e.target.value;});
|
||||
|
|
|
|||
81
src/game/95-modals/95-puzzles.js
Normal file
81
src/game/95-modals/95-puzzles.js
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* ---------- puzzles: the card, the panels, the link picker, the results and the list ---------- */
|
||||
const PZ_ICON={goal:'🎯',via:'🪨',avoid:'🚫'};
|
||||
function pzTwistTxt(t){const P=S.pz;
|
||||
if(t.k==='sub')return tr('puzzles.no_subsea_cables');
|
||||
if(t.k==='ring')return tr('puzzles.one_ring_through_every_pop');
|
||||
if(t.k==='g')return tr('puzzles.every_link_n_g_or_more',{n:P.minG});
|
||||
if(t.k==='avoid')return tr('puzzles.no_pop_in_list',{list:P.avoid.map(c=>CITY[c].name).join(', ')});
|
||||
const [a,b,ms]=P.lat;return isFinite(t.ms)?tr('puzzles.a_to_b_under_ms_now',{a:CITY[a].name,b:CITY[b].name,ms,now:t.ms.toFixed(1)}):tr('puzzles.a_to_b_under_ms',{a:CITY[a].name,b:CITY[b].name,ms});}
|
||||
// The short version, for the puzzle list.
|
||||
function pzTwistTag(d){const t=[];if(d.noSub)t.push(tr('puzzles.no_subsea'));if(d.ring)t.push(tr('puzzles.ring'));if(d.lat)t.push(tr('puzzles.under_n_ms',{n:d.lat[2]}));if(d.minG)t.push(tr('puzzles.n_g_links',{n:d.minG}));if(d.avoid)t.push(tr('puzzles.avoid_list',{list:d.avoid.map(c=>CITY[c].name).join(', ')}));return t;}
|
||||
const pzUnitName=u=>{const l=S.links.find(x=>pzUnit(x)===u);return l?`${CITY[l.a].name} ⇄ ${CITY[l.b].name}${l.cable?' ('+esc(CAB[l.cable].name)+')':''}`:'';};
|
||||
function pzRender(){const el=$('pzBox');if(!pzOn()){el.hidden=true;return;}el.hidden=false;
|
||||
const e=pzEval(),P=S.pz,d=pzDef(P.id),pk=d&&PZ_PACKS.find(x=>x.id===d.pack);
|
||||
const star=(on,l)=>`<span class="${on?'on':''}">⭐<small>${l}</small></span>`;
|
||||
let h=`<div class="grab" data-grab="pz" aria-hidden="true"></div><div class="pzh"><div class="grow"><div class="eyebrow">${pk?esc(pk.n):tr('puzzles.weekly_puzzle')}</div><h3>${esc(pzName(d||P))}</h3></div>${btn('☰','puzzleMenu',{},'ghost sm')}</div>`;
|
||||
if(d)h+=`<p class="pzj">${esc(d.j)}</p>`;
|
||||
h+=`<div class="pzs">${star(e.goal,tr('puzzles.goal'))}${star(e.goal&&e.cheap,P.budget?tr('puzzles.budget'):tr('puzzles.free'))}${star(e.goal&&e.n1,'N-1')}</div>`;
|
||||
h+=`<div class="pzck">${e.marks.map(m=>`<span class="pzc s${m.st}">${esc(CITY[m.c].name)}${m.st===2?' ✓':m.st===1?' ·':' …'}</span>`).join('')}</div>`;
|
||||
for(const t of e.tw)h+=`<div class="pztw ${t.ok?'ok':''}">${t.ok?'✓':'✗'} ${pzTwistTxt(t)}</div>`;
|
||||
const sp=fmt$(e.spend);
|
||||
h+=P.budget?`<div class="pzbud"><div class="kv"><span>${tr('puzzles.spent_x_of_y',{x:sp,y:fmt$(P.budget)})}</span><b>${e.cheap?'✓':'✗'}</b></div><div class="bar ${e.cheap?(e.spend>P.budget*0.85?'warn':''):'bad'}"><i style="width:${Math.min(100,e.spend/P.budget*100).toFixed(1)}%"></i></div></div>`
|
||||
:`<div class="pzbud"><div class="kv"><span>${tr('puzzles.spent_x',{x:sp})}</span><b>${tr('puzzles.no_budget_star_on_the_house')}</b></div></div>`;
|
||||
h+=!e.conn?`<div class="pzn1">🛡 ${tr('puzzles.n_1_connect_everything_first')}</div>`:e.n1?`<div class="pzn1 on">🛡 ${tr('puzzles.survives_any_single_cut')}</div>`:`<div class="pzn1 bad">⚠️ ${tr('puzzles.one_cut_splits_it_where',{where:pzUnitName(e.weak[0])})}</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>`;
|
||||
if(h!==UI._pzh){UI._pzh=h;morph(el,h);}}
|
||||
function pzPanel(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];if(!k)return '';
|
||||
const eb=k==='goal'?tr('puzzles.goal_city'):k==='via'?tr('puzzles.stepping_stone_optional'):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">';
|
||||
if(k==='avoid')return h+`<p class="lead">${tr('puzzles.not_this_one_find_a_way_around')}</p></div>`;
|
||||
if(!p)h+=`<p class="lead">${tr('puzzles.a_pop_costs_setup_plus_a_year',{setup:fmt$(popCost(c)),mo:fmt$(POP_MO)})}</p><div class="btns">${btn(tr('puzzles.open_a_pop_cost',{cost:fmt$(pzPopCost(c))}),'pzPop',{city:c},'pink big')}</div>`;
|
||||
else{const others=[...S.pz.cities,...S.pz.via].filter(x=>x!==c);
|
||||
h+=`<p class="lead">${tr('puzzles.drag_from_this_pop_onto_another')}</p><h3>${tr('puzzles.lease_a_wave_to')}</h3><div class="seg">${others.map(x=>btn(esc(CITY[x].name),'pzLinkTo',{a:c,b:x},S.pops[x]?'':'ghost')).join('')}</div>`;
|
||||
const ls=S.links.filter(l=>l.a===c||l.b===c);if(ls.length)h+=`<h3 style="margin-top:10px">${tr('common.links')}</h3>`+ls.map(l=>`<div class="row"><div class="grow"><div class="nm">${esc(CITY[l.a===c?l.b:l.a].name)}</div><div class="meta">${capName(l)} · ${linkLat(l).toFixed(1)} ms</div></div>${btn(tr('common.open'),'selLink',{id:l.id},'ghost sm')}</div>`).join('');
|
||||
h+=`<div class="btns" style="margin-top:10px">${btn(tr('puzzles.remove_this_pop'),'pzRmPop',{city:c},'red sm')}</div>`;}
|
||||
return h+'</div>';}
|
||||
const l=S.links.find(x=>x.id===sel.id);if(!l)return '';
|
||||
let h=head(l.cable?esc(CAB[l.cable].name):tr('common.overland'),`${esc(CITY[l.a].name)} ⇄ ${esc(CITY[l.b].name)}`,`<span class="fact">${capName(l)}</span><span class="fact">${l.km.toLocaleString()} km</span><span class="fact">${linkLat(l).toFixed(1)} ms</span><span class="fact">${tr('puzzles.price_per_year',{price:fmt$(l.mo*PZ_YEAR)})}</span>`)+'<div class="scroll">';
|
||||
h+=`<h3>${tr('puzzles.size')}</h3><div class="seg">${PZ_TIERS.map(i=>{const r={km:l.km,sub:l.sub,f:l.mult||1},why=subWaveWhy(i,l.km,l.sub);return btn(`${LT[i].n} <small>${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>`;
|
||||
return h+`<div class="btns" style="margin-top:10px">${btn(tr('puzzles.remove_this_link'),'pzRmLink',{id:l.id},'red sm')}</div></div>`;}
|
||||
// The link picker: overland or one of the real cables between the two cities, and a size. Prices are for a year.
|
||||
function pzLinkModal(a,b,keep){const kb=pzKind(b);
|
||||
if(!kb||kb==='avoid'||!pzKind(a)){toast(kb==='avoid'?tr('puzzles.not_this_one_find_a_way_around'):tr('puzzles.that_city_is_not_part_of'),'bad');sfx('err');return;}
|
||||
if(!keep){UI.pzVia=null;UI.pzDiv=true;}UI.pending={a,b};const rs=pzRoutes(a,b),P=S.pz;
|
||||
const head=`<div style="display:flex;align-items:center"><div><div class="eyebrow">${kmBetween(a,b).toLocaleString()} km</div><h2 style="font-size:26px">${esc(CITY[a].name)} → ${esc(CITY[b].name)}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div>`;
|
||||
if(!rs.length){openModal(head+`<p class="lead" style="margin-top:10px">${tr('puzzles.no_cable_lands_in_both_try',{a:esc(CITY[a].name),b:esc(CITY[b].name)})}</p>`);return;}
|
||||
const r=rs.find(x=>x.via===UI.pzVia)||rs.find(x=>!(P.noSub&&x.sub))||rs[0];UI.pzVia=r.via;
|
||||
const land=!r.sub&&S.links.some(l=>edgeKey(l)===edgeKey({a,b})&&!l.cable),div=land&&UI.pzDiv!==false,pop=S.pops[b]?0:pzPopCost(b);
|
||||
let h=head+`<h4 class="sub4">${tr('common.route')}</h4><div class="seg">${rs.map(x=>btn(`${x.cab?esc(CAB[x.cab].name):tr('common.overland')} <small>${x.ms.toFixed(1)} ms${x.cab&&CAB[x.cab].age==='old'?'':''}</small>`,'pzVia',{v:x.via},x.via===r.via?'pink':'ghost',P.noSub&&x.sub)).join('')}</div>`;
|
||||
if(P.noSub&&r.sub)h+=`<p class="why">${tr('puzzles.the_sharks_say_no')}</p>`;
|
||||
if(r.cab)h+=`<p class="note">${esc(CAB[r.cab].blurb)}</p>`;
|
||||
if(land)h+=`<div class="seg" style="margin-top:8px">${btn(tr('puzzles.diverse_route_40_survives_a_backhoe'),'pzDiv',{v:1},div?'pink':'ghost')}${btn(tr('puzzles.same_trench_cheaper_one_backhoe_cuts'),'pzDiv',{v:0},div?'ghost':'pink')}</div>`;
|
||||
if(pop)h+=`<p class="lead" style="margin-top:8px">${tr('puzzles.includes_a_new_pop_in_city',{city:esc(CITY[b].name),price:fmt$(pop)})}</p>`;
|
||||
h+=`<div class="tiers">${PZ_TIERS.map(i=>{const why=subWaveWhy(i,r.km,r.sub),c=pzLinkCost(r,i,div)+pop;return `<button class="tierbtn" data-act="pzLink" data-args='{"tier":${i}}'${why||(P.noSub&&r.sub)?' disabled':''}><span class="sz">${LT[i].n}</span><span class="grow meta">${why?tr('common.too_far_for_this_cable'):pop?tr('puzzles.with_the_pop_price',{price:fmt$(c)}):''}</span><span class="pr num">${tr('puzzles.price_per_year',{price:fmt$(pzLinkCost(r,i,div))})}</span></button>`;}).join('')}</div>`;
|
||||
openModal(h);}
|
||||
// ---------- results ----------
|
||||
function pzLine(e){return e.stars>=3?tr('puzzles.a_backhoe_walks_into_your_network'):!e.n1&&!e.cheap?tr('puzzles.it_works_finance_and_the_backhoe'):!e.n1?tr('puzzles.one_backhoe_away_from_a_very'):tr('puzzles.rock_solid_and_gold_plated_the');}
|
||||
function pzConfetti(){if(!animOn())return '';const cols=['#FF4F9A','#FFD23F','#22C47A','#2F8CFF','#FF8A3D','#7B61FF'];let h='';
|
||||
for(let i=0;i<28;i++)h+=`<i style="--x:${(i*37)%100}%;--c:${cols[i%cols.length]};--r:${(i%2?1:-1)*(180+(i*53)%360)}deg;--t:${1.4+(i%5)*0.25}s;--dl:${((i*7)%10)/10}s"></i>`;
|
||||
return `<div class="pzconf" aria-hidden="true">${h}</div>`;}
|
||||
function pzResults(e,prev){const P=S.pz,nx=P.id==='weekly'?null:pzNextDef();
|
||||
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>
|
||||
<div class="pzstars">${stars}</div><p class="tagline" style="text-align:center">${pzLine(e)}</p>
|
||||
${row(true,tr('puzzles.goal'),tr('puzzles.connected'))}${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'):tr('puzzles.one_cut_splits_it'))}
|
||||
<div class="btns cta" style="margin-top:12px">${nx?btn(tr('puzzles.next_puzzle'),'pzStart',{id:nx.id},'pink big'):btn(tr('puzzles.more_puzzles'),'puzzleMenu',{},'pink big')}${e.stars<3?btn(tr('puzzles.retry_for_3_stars'),'pzRetry',{},''):''}${btn(tr('common.share_2cd9'),'pzShare',{},'')}${btn(tr('puzzles.keep_building'),'closeModal',{},'ghost')}</div></div>`);
|
||||
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);}
|
||||
// ---------- the list ----------
|
||||
function pzMenu(){const p=pzLoad(),tot=pzStarsTotal(p),max=PZ.length*3,nxP=PZ_PACKS.find(x=>x.need>tot),w=pzWeekly(),wr=p.wk[w.key],st=p.streak,streak=st.last===w.key||st.last===pzPrevKey(w.key)?st.n:0;
|
||||
let h=`<div style="display:flex;align-items:center"><div class="grow"><div class="eyebrow">${tr('puzzles.puzzles')}</div><h2 style="font-size:28px">${tr('puzzles.small_calm_network_builds')}</h2></div><button class="x" data-act="helpClose" aria-label="${tr('common.close')}">×</button></div>
|
||||
<p class="tagline">${tr('puzzles.no_clock_no_bills_nothing_breaks')}</p>
|
||||
<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>`:''}</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>`;
|
||||
h+=`<div class="scn wk"><div class="grow"><div class="nm">${tr('puzzles.weekly_puzzle_key',{key:esc(w.key)})} ${wr?`<span class="pzst">${pzStarStr(wr.st)}</span>`:''}</div><div class="meta">${w.cities.map(c=>esc(CITY[c].name)).join(' · ')} · ${tr('puzzles.budget_x',{x:fmt$(w.budget)})}</div><div class="meta">${tr('puzzles.same_puzzle_for_everyone_this_week')}${streak?' · 🔥 '+trn('puzzles.n_week_streak',streak):''}</div></div>${btn(tr('common.play'),'pzWeekly',{},'pink')}</div>`;
|
||||
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>`;
|
||||
for(const d of PZ.filter(x=>x.pack===pk.id)){const r=p.s[d.id],tg=pzTwistTag(d);
|
||||
h+=`<div class="scn${open?'':' lock'}"><div class="grow"><div class="nm">${esc(d.n)} <span class="pzst">${pzStarStr(r?r.st:0)}</span></div><div class="meta">${esc(d.j)}</div><div class="meta">${d.cities.map(c=>esc(CITY[c].name)).join(' · ')} · ${d.budget?tr('puzzles.budget_x',{x:fmt$(d.budget)}):tr('puzzles.no_budget')}${tg.length?' · <b>'+tg.join(' · ')+'</b>':''}${r&&r.sp!=null?' · '+tr('puzzles.best_x',{x:fmt$(r.sp)}):''}</div></div>${btn(tr('common.play'),'pzStart',{id:d.id},r&&r.st>=3?'ghost':'',!open)}</div>`;}}
|
||||
openModal(h);}
|
||||
|
|
@ -85,7 +85,7 @@ function drawFrame(now){
|
|||
// Which cities show an offer bubble (a big one?) or an incident marker, worked out once for all of them.
|
||||
CM.off=new Set();CM.big=new Set();for(const o of S.offers){const big=BIZ_T[o.type].lv>=3||BIZ_T[o.type].event;for(const c of bCities(o)){CM.off.add(c);if(big)CM.big.add(c);}}
|
||||
CM.inc=new Set(S.inc.filter(i=>i.type!=='leak').map(i=>i.ref));CM.far=farL;
|
||||
for(const v of vis.slice().reverse())drawCity(v.C,v.sx,v.sy,sc,now,v.ly);
|
||||
if(pzOn())for(const v of vis.slice().reverse())pzDrawCity(v,sc,now);else for(const v of vis.slice().reverse())drawCity(v.C,v.sx,v.sy,sc,now,v.ly);
|
||||
// floaters
|
||||
for(let i=FLOATS.length-1;i>=0;i--){const f=FLOATS[i],a=(now-f.t)/1600;if(a>1){FLOATS.splice(i,1);continue;}
|
||||
for(const k of ks){const [sx,sy]=toS(f.x,f.y,k);ctx.globalAlpha=1-a*a;ctx.font='800 17px "Baloo 2", sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.lineWidth=4;ctx.strokeStyle='#fff';ctx.strokeText(f.text,sx,sy-a*40);ctx.fillStyle=f.col;ctx.fillText(f.text,sx,sy-a*40);ctx.globalAlpha=1;}}
|
||||
|
|
|
|||
10
src/game/96-map/85-puzzle-cities.js
Normal file
10
src/game/96-map/85-puzzle-cities.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/* Puzzle map: the puzzle's cities stand out (goals with a pulsing ring, stepping stones with a dashed one, cities to
|
||||
avoid crossed out); every other city stays on the map, faded and untappable. */
|
||||
function pzDrawCity(v,sc,now){const k=pzKind(v.C.id);
|
||||
if(!k){ctx.save();ctx.globalAlpha=0.3;drawCity(v.C,v.sx,v.sy,sc,now,null);ctx.restore();return;}
|
||||
const r=(CM.far?16:34)*sc,y=v.sy-(CM.far?0:6*sc),p=S.pops[v.C.id];
|
||||
ctx.save();ctx.lineWidth=3;
|
||||
if(k==='avoid'){ctx.strokeStyle='#FF4D5E';ctx.beginPath();ctx.arc(v.sx,y,r,0,7);ctx.moveTo(v.sx-r*.7,y-r*.7);ctx.lineTo(v.sx+r*.7,y+r*.7);ctx.stroke();}
|
||||
else{const a=animOn()?.55+.35*Math.sin(now/300):.8;ctx.strokeStyle=k==='goal'?`rgba(255,79,154,${p?1:a})`:'rgba(30,38,64,.7)';if(k==='via')ctx.setLineDash([5,5]);
|
||||
ctx.fillStyle=k==='goal'&&!p?'rgba(255,210,63,.35)':'rgba(255,255,255,.25)';ctx.beginPath();ctx.arc(v.sx,y,r,0,7);ctx.fill();ctx.stroke();ctx.setLineDash([]);}
|
||||
ctx.restore();drawCity(v.C,v.sx,v.sy,sc,now,v.ly===null?undefined:v.ly);}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* ---------- hit tests & input ---------- */
|
||||
function hitCity(x,y,r=28){let best=null,bd=r*iconScale();const KS=visibleKs();for(const C of CITIES){if(C.off&&!cityOn(C.id))continue;for(const k of KS){const [sx,sy]=toS(C.x,C.y,k);const d=Math.hypot(sx-x,sy+4-y);if(d<bd){bd=d;best={id:C.id,sx,sy};}}}return best;}
|
||||
function hitCity(x,y,r=28){let best=null,bd=r*iconScale();const KS=visibleKs();const pz=pzOn();for(const C of CITIES){if(C.off&&!cityOn(C.id))continue;if(pz&&!pzKind(C.id))continue;for(const k of KS){const [sx,sy]=toS(C.x,C.y,k);const d=Math.hypot(sx-x,sy+4-y);if(d<bd){bd=d;best={id:C.id,sx,sy};}}}return best;}
|
||||
// A tap on a city's icon picks the city; in the rest of its (generous) tap circle, a link right under the finger wins,
|
||||
// or a short link between two close cities could not be picked at all (#126).
|
||||
function pickCity(x,y){const h=hitCity(x,y);if(!h)return null;if(Math.hypot(h.sx-x,h.sy+4-y)<=16*iconScale())return h;return hitLink(x,y)?null:h;}
|
||||
|
|
@ -25,7 +25,7 @@ cv.addEventListener('pointermove',e=>{
|
|||
function endPtr(e){
|
||||
ptrs.delete(e.pointerId);const d=UI.drag;if(!d)return;
|
||||
if(d.mode==='pinch'){if(ptrs.size===0){UI.drag=null;UI.snap=null;cv.classList.remove('linking');}return;}
|
||||
if(d.mode==='link'){if(UI.snap&&UI.snap.id!==d.from){openLinkModal(d.from,UI.snap.id);sfx('click');}}
|
||||
if(d.mode==='link'){if(UI.snap&&UI.snap.id!==d.from){if(pzOn())pzLinkModal(d.from,UI.snap.id);else openLinkModal(d.from,UI.snap.id);sfx('click');}}
|
||||
else if(!d.moved&&S){const h=pickCity(e.clientX,e.clientY);
|
||||
if(h){selectCity(h.id);renderLeft();sfx('click');}
|
||||
else{const l=hitLink(e.clientX,e.clientY);if(l){selectLink(l);sfx('click');}else{UI.sel=null;renderPanel();renderLeft();}}}
|
||||
|
|
@ -38,5 +38,5 @@ cv.addEventListener('pointerup',endPtr);cv.addEventListener('pointercancel',canc
|
|||
const ZMIN=0.35,ZMAX=16;
|
||||
function zoomAt(mx,my,f){const wx=cam.x+(mx-CW/2)/cam.z,wy=cam.y+(my-CH/2)/cam.z;cam.z=clamp(cam.z*f,ZMIN,ZMAX);cam.x=wx-(mx-CW/2)/cam.z;cam.y=wy-(my-CH/2)/cam.z;wrapCam();}
|
||||
cv.addEventListener('wheel',e=>{e.preventDefault();zoomAt(e.clientX,e.clientY,Math.exp(-e.deltaY*0.0015));},{passive:false});
|
||||
addEventListener('keydown',e=>{if(e.target.closest&&e.target.closest('input,textarea,select,[contenteditable]'))return;if(e.ctrlKey||e.metaKey||e.altKey)return;if(e.code==='Space'&&e.target.closest&&e.target.closest('button,a'))return;if(e.code==='Space'){e.preventDefault();UI.speed=UI.speed?0:1;renderHUD();}if(e.key==='0')ACT.speed({v:0.5});if(e.key==='1')ACT.speed({v:1});if(e.key==='2')ACT.speed({v:2});if(e.key==='3')ACT.speed({v:4});if(e.key==='4')ACT.speed({v:8});if(e.key==='Escape'&&!$('bankBox').hidden){$('bankBox').hidden=true;return;}if(e.key==='Escape'&&!$('dash').hidden){$('dash').hidden=true;return;}if(e.key==='Escape'){if(!$('modal').hidden){if(S&&UI.started&&!S.lost)closeModal();}else{UI.sel=null;renderPanel();}}});
|
||||
addEventListener('keydown',e=>{if(e.target.closest&&e.target.closest('input,textarea,select,[contenteditable]'))return;if(e.ctrlKey||e.metaKey||e.altKey)return;if(e.code==='Space'&&e.target.closest&&e.target.closest('button,a'))return;if(e.code==='Space'){e.preventDefault();if(!pzOn()){UI.speed=UI.speed?0:1;renderHUD();}}if(e.key==='0')ACT.speed({v:0.5});if(e.key==='1')ACT.speed({v:1});if(e.key==='2')ACT.speed({v:2});if(e.key==='3')ACT.speed({v:4});if(e.key==='4')ACT.speed({v:8});if(e.key==='Escape'&&!$('bankBox').hidden){$('bankBox').hidden=true;return;}if(e.key==='Escape'&&!$('dash').hidden){$('dash').hidden=true;return;}if(e.key==='Escape'){if(!$('modal').hidden){if(S&&UI.started&&!S.lost)closeModal();}else{UI.sel=null;renderPanel();}}});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* ---------- click delegation ---------- */
|
||||
let pressing=false;
|
||||
document.addEventListener('pointerdown',e=>{if(e.target.closest('#panel,#left,#dash,#bankBox,#modal,#tabbar,#toasts'))pressing=true;});
|
||||
document.addEventListener('pointerdown',e=>{if(e.target.closest('#panel,#left,#dash,#bankBox,#modal,#tabbar,#toasts,#pzBox'))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&&!['langSet','pickHome'].includes(el.dataset.chg)))return;const fn=ACT[el.dataset.chg];if(fn)fn({v:el.value});});
|
||||
|
|
@ -11,5 +11,5 @@ let PD={t:0,b:null};
|
|||
document.addEventListener('pointerdown',e=>{PD={t:performance.now(),b:e.target.closest('[data-act]')};},true);
|
||||
function tapOk(e,b){if(!e.isTrusted||!PD.t||e.detail===0)return true;const now=performance.now();if(now-PD.t>4000)return true;
|
||||
if(PD.b!==b)return false;if((UI.layerAt||0)>PD.t)return false;const ts=b.closest('.toast');if(ts&&PD.t-(+ts.dataset.born||0)<500)return false;return true;}
|
||||
document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;if(!$('modal').hidden&&!b.closest('#modal'))return;if(!tapOk(e,b))return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','randomName','pickStart','cont','help','helpClose','newgame','mute','animSet','soundSet','langSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','scenarios','startScn','startWeekly','settings','settingsClose','prefSet','vpSet','install','pitchSkip'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);});
|
||||
document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;if(!$('modal').hidden&&!b.closest('#modal'))return;if(!tapOk(e,b))return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','randomName','pickStart','cont','help','helpClose','newgame','mute','animSet','soundSet','langSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','scenarios','startScn','startWeekly','settings','settingsClose','prefSet','vpSet','install','pitchSkip','puzzleMenu','pzStart','pzWeekly'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);});
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ function frame(now){
|
|||
if(S&&UI.started&&!S.lost&&now-(UI.lastSave||0)>5000)save();
|
||||
// The panels catch up on the frame after a day, so one frame does not carry both the day's simulation and them.
|
||||
if(UI.panelsDue){UI.panelsDue=false;if(!pressing){renderPanel();renderLeft();if(!$('dash').hidden)renderDash();renderBank();}renderHint();}
|
||||
if(S&&!S.lost&&$('modal').hidden&&UI.speed){acc+=dt*UI.speed;let n=0;while(acc>=DAY_MS&&n<4&&UI.speed){acc-=DAY_MS;try{dayTick();}catch(e){tickErr(e);}n++;}
|
||||
if(S&&!S.lost&&$('modal').hidden&&UI.speed&&!pzOn()){acc+=dt*UI.speed;let n=0;while(acc>=DAY_MS&&n<4&&UI.speed){acc-=DAY_MS;try{dayTick();}catch(e){tickErr(e);}n++;}
|
||||
if(n){UI.ticking=true;renderHUD();UI.ticking=false;UI.panelsDue=true;}}
|
||||
if(UI.speed&&!(S&&S.lost))animT+=dt; /* paused = frozen dots, waves and clouds */
|
||||
if((UI.speed||pzOn())&&!(S&&S.lost))animT+=dt; /* paused = frozen dots, waves and clouds */
|
||||
const t=animOn()?animT:0;
|
||||
if(!(UI.mapHid=mapHidden())&&!mapStill(t,now)){try{draw(t);}catch(e){tickErr(e);}UI.drawnAt=now;}
|
||||
}
|
||||
|
|
|
|||
116
src/i18n/en.js
116
src/i18n/en.js
|
|
@ -2660,6 +2660,122 @@
|
|||
"progress.under_attack_now":"Under attack now",
|
||||
"progress.your_score_peak_traffic":"Your score: peak traffic",
|
||||
"progress.your_traffic_to_and_from_asia":"Your traffic to and from Asia",
|
||||
"puzzles.a_backhoe_walks_into_your_network":"A backhoe walks into your network. Nothing happens.",
|
||||
"puzzles.a_pop_costs_setup_plus_a_year":"A POP costs {setup} to set up, then {mo}/mo. Puzzles count the setup and a year of rent.",
|
||||
"puzzles.a_tiny_island_where_half_the":"A tiny island where half the Pacific's cables stop for coffee.",
|
||||
"puzzles.a_to_b_under_ms":"{a} → {b} under {ms} ms",
|
||||
"puzzles.a_to_b_under_ms_now":"{a} → {b} under {ms} ms (now {now} ms)",
|
||||
"puzzles.aloha_latency":"Aloha Latency",
|
||||
"puzzles.avoid_list":"avoid {list}",
|
||||
"puzzles.back_to_my_network":"Back to my network",
|
||||
"puzzles.back_to_the_title":"Back to the title screen",
|
||||
"puzzles.beat_the_clock_light_in_glass":"Light in glass does 200 km per millisecond. Pick your cables like it matters.",
|
||||
"puzzles.belt_and_braces":"Belt and Braces",
|
||||
"puzzles.best_x":"best {x}",
|
||||
"puzzles.budget":"Budget",
|
||||
"puzzles.budget_x":"budget {x}",
|
||||
"puzzles.connect_list":"Connect {list}.",
|
||||
"puzzles.connected":"Connected",
|
||||
"puzzles.copied_paste_it_anywhere":"Copied! Paste it anywhere:<br>{t}",
|
||||
"puzzles.de_kicks_sales_has_your_number":"DE-KICKS sales has your number. Connect Germany without Frankfurt.",
|
||||
"puzzles.diverse_route_40_survives_a_backhoe":"Diverse route (+40%, survives a backhoe)",
|
||||
"puzzles.down_under_up_and_running":"Down Under, Up and Running",
|
||||
"puzzles.drag_from_a_pink_pop_to":"Drag from a pink POP to another city to lease a wave",
|
||||
"puzzles.drag_from_this_pop_onto_another":"Drag from this POP onto another puzzle city, or pick one here.",
|
||||
"puzzles.euro_trip":"Euro Trip",
|
||||
"puzzles.every_internet_starts_with_one_tube":"Every internet starts with one tube.",
|
||||
"puzzles.every_link_n_g_or_more":"Every link {n}G or more",
|
||||
"puzzles.fat_pipes_only":"Fat Pipes Only",
|
||||
"puzzles.flash_boys":"Flash Boys",
|
||||
"puzzles.for_architects_who_sleep_through_backhoes":"For architects who sleep through backhoe season.",
|
||||
"puzzles.four_capitals_one_very_long_winter":"Four capitals, one very long winter, zero excuses for downtime.",
|
||||
"puzzles.four_cities_four_cables_one_ring":"Four cities, one ring. Tolkien would approve; your NOC definitely does.",
|
||||
"puzzles.four_cities_one_continent_and_a":"Four cities, one continent and a lot of corn between them.",
|
||||
"puzzles.frankfurt_to_singapore_the_short_way":"Frankfurt to Singapore the short way. The long way is overland, and it shows.",
|
||||
"puzzles.free":"Free",
|
||||
"puzzles.goal":"Goal",
|
||||
"puzzles.goal_city":"Goal city",
|
||||
"puzzles.guam_slam":"Guam Slam",
|
||||
"puzzles.hello_world":"Hello, World",
|
||||
"puzzles.honolulu_the_world_s_most_scenic":"Honolulu: the world's most scenic regeneration site.",
|
||||
"puzzles.includes_a_new_pop_in_city":"Includes a new POP in {city} ({price} for a year).",
|
||||
"puzzles.it_works_finance_and_the_backhoe":"It works! Finance and the backhoe would like a word.",
|
||||
"puzzles.keep_building":"Keep building",
|
||||
"puzzles.kiwi_fruit_salad":"Kiwi Fruit Salad",
|
||||
"puzzles.lease_a_wave_to":"Lease a wave to",
|
||||
"puzzles.more_puzzles":"More puzzles",
|
||||
"puzzles.n_1_club":"N-1 Club",
|
||||
"puzzles.n_1_connect_everything_first":"N-1: connect everything first",
|
||||
"puzzles.n_g_links":"{n}G links",
|
||||
"puzzles.n_week_streak":{"one":"{n} week in a row","other":"{n} weeks in a row"},
|
||||
"puzzles.new_zealand_is_far_from_everything":"New Zealand is far from everything. That is the point, and the problem.",
|
||||
"puzzles.next_pack_unlocks_at_n":"Next pack, {pack}, unlocks at {n}⭐",
|
||||
"puzzles.next_puzzle":"Next puzzle",
|
||||
"puzzles.no_budget":"no budget",
|
||||
"puzzles.no_budget_star_on_the_house":"no budget: ⭐ on the house",
|
||||
"puzzles.no_cable_lands_in_both_try":"No cable lands in both {a} and {b}. Try a stepping stone in between.",
|
||||
"puzzles.no_clock_no_bills_nothing_breaks":"No clock, no bills, nothing breaks. Connect the cities, then go for three stars: under budget, and still connected when any one link is cut.",
|
||||
"puzzles.no_pop_in_list":"No POP in {list}",
|
||||
"puzzles.no_subsea":"no subsea",
|
||||
"puzzles.no_subsea_cables":"No subsea cables",
|
||||
"puzzles.nobody_ever_got_fired_for_buying":"Nobody ever got fired for buying 100G.",
|
||||
"puzzles.not_this_one_find_a_way_around":"Not this one. Find a way around.",
|
||||
"puzzles.not_through_frankfurt":"Not Through Frankfurt",
|
||||
"puzzles.off_limits":"Off limits",
|
||||
"puzzles.on_the_house":"On the house",
|
||||
"puzzles.one_backhoe_away_from_a_very":"One backhoe away from a very long night. Add a second path for ⭐⭐⭐.",
|
||||
"puzzles.one_cut_splits_it":"One cut splits it",
|
||||
"puzzles.one_cut_splits_it_where":"One cut splits it: {where}",
|
||||
"puzzles.one_ring_through_every_pop":"One ring through every POP",
|
||||
"puzzles.one_very_big_island_and_a":"One very big island, and a lot of very empty fiber.",
|
||||
"puzzles.open_a_pop_cost":"Open a POP · {cost}",
|
||||
"puzzles.pacific_rim_shot":"Pacific Rim Shot",
|
||||
"puzzles.ping_pong_to_tokyo":"Ping Pong to Tokyo",
|
||||
"puzzles.price_per_year":"{price}/yr",
|
||||
"puzzles.puzzle":"Puzzle",
|
||||
"puzzles.puzzle_solved":"Puzzle solved",
|
||||
"puzzles.puzzles":"Puzzles",
|
||||
"puzzles.remove_this_link":"Remove this link",
|
||||
"puzzles.remove_this_pop":"Remove this POP",
|
||||
"puzzles.reset":"Reset",
|
||||
"puzzles.retry_for_3_stars":"Retry for ⭐⭐⭐",
|
||||
"puzzles.ring":"ring",
|
||||
"puzzles.ring_of_fire":"Ring of Fire",
|
||||
"puzzles.rock_solid_and_gold_plated_the":"Rock solid, and gold plated. The CFO has questions.",
|
||||
"puzzles.samba_sprint":"Samba Sprint",
|
||||
"puzzles.same_puzzle_for_everyone_this_week":"Same puzzle for everyone this week",
|
||||
"puzzles.same_trench_cheaper_one_backhoe_cuts":"Same trench (cheaper, one backhoe cuts both)",
|
||||
"puzzles.sao_paulo_to_miami_before_the":"São Paulo to Miami before the caipirinha gets warm.",
|
||||
"puzzles.sea_to_shining_sea":"Sea to Shining Sea",
|
||||
"puzzles.seattle_to_singapore_with_a_stop":"Seattle to Singapore, with a stop for sushi and dim sum.",
|
||||
"puzzles.share_line":"Series of Tubes puzzle {what} {stars} {spend} · seriesoftub.es",
|
||||
"puzzles.size":"Size",
|
||||
"puzzles.small_calm_network_builds":"Small, calm network builds",
|
||||
"puzzles.smorgasbord":"Smörgåsbord",
|
||||
"puzzles.speed_runs":"Speed Runs",
|
||||
"puzzles.spent_x":"Spent {x}",
|
||||
"puzzles.spent_x_of_y":"Spent {x} / {y}",
|
||||
"puzzles.stepping_stone_optional":"Stepping stone (optional)",
|
||||
"puzzles.suez_you_later":"Suez You Later",
|
||||
"puzzles.survives_any_single_cut":"Survives any single cut",
|
||||
"puzzles.tap_a_goal_city_to_open":"Tap a glowing city to open your first POP",
|
||||
"puzzles.that_city_is_not_part_of":"That city is not part of this puzzle.",
|
||||
"puzzles.the_pacific_is_big_light_is":"The Pacific is big. Light is fast. Your budget is neither.",
|
||||
"puzzles.the_pacific_rim_where_every_hop":"The Pacific rim, where every hop is an ocean.",
|
||||
"puzzles.the_shark_tank":"The Shark Tank",
|
||||
"puzzles.the_sharks_have_been_biting_again":"The sharks have been biting again. Keep it on dry land.",
|
||||
"puzzles.the_sharks_say_no":"The sharks say no.",
|
||||
"puzzles.three_cities_two_currencies_one_very":"Three cities, two currencies, one very short tunnel under the sea.",
|
||||
"puzzles.traders_paid_millions_to_shave_milliseconds":"Traders paid millions to shave milliseconds off this route. You get to do it for less.",
|
||||
"puzzles.two_cables_across_the_atlantic_because":"Two cables across the Atlantic, because one is a hope, not a plan.",
|
||||
"puzzles.under_n_ms":"under {n} ms",
|
||||
"puzzles.undo":"Undo",
|
||||
"puzzles.unlocks_at_n_stars":"Unlocks at {n}⭐",
|
||||
"puzzles.weekly_puzzle":"Weekly puzzle",
|
||||
"puzzles.weekly_puzzle_key":"Weekly puzzle {key}",
|
||||
"puzzles.with_the_pop_price":"with the POP: {price}",
|
||||
"puzzles.your_first_tubes_no_pressure":"Your first tubes. No pressure, no budget.",
|
||||
"puzzles.your_stars":"Your stars",
|
||||
"reach_and_subsea.premium_submarine_terminals":"Premium submarine terminals",
|
||||
"release_notes.and_n_more_change":{"one":"…and {n} more change","other":"…and {n} more changes"},
|
||||
"release_notes.read_the_full_notes_on_github":"Read the full notes on GitHub",
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@
|
|||
<div id="panelBody" style="display:flex;flex-direction:column;min-height:0;flex:1"></div>
|
||||
</aside>
|
||||
|
||||
<aside id="pzBox" class="card" hidden aria-label="Puzzle" data-i18n-aria-label="puzzles.puzzle"></aside>
|
||||
<div id="hint" hidden></div>
|
||||
<div id="coach" hidden role="status"></div>
|
||||
<div id="toasts" aria-live="polite"></div>
|
||||
|
|
|
|||
39
src/styles/70-puzzles.css
Normal file
39
src/styles/70-puzzles.css
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* Puzzles (#190): one card for the goal, the stars and the budget; on phones a bottom sheet you can shrink. */
|
||||
body.pz #hud .chip:not(.brand):not(.speed),body.pz #hud .speed button:not(#muteBtn),body.pz #leftToggle,body.pz #left{display:none !important}
|
||||
#pzBox{position:fixed;top:calc(env(safe-area-inset-top,0px) + 76px);left:max(12px,env(safe-area-inset-left,0px));width:300px;max-height:calc(100% - 96px - env(safe-area-inset-top,0px));overflow:auto;z-index:4;padding:10px 14px 12px;box-sizing:border-box}
|
||||
#pzBox .pzh{display:flex;align-items:center;gap:8px}#pzBox h3{font-size:19px}
|
||||
.pzj{margin:4px 0 6px;font-size:12.5px;color:var(--ink2);line-height:1.35}
|
||||
.pzs{display:flex;gap:6px;margin:6px 0}.pzs span{flex:1;display:flex;flex-direction:column;align-items:center;border:2.5px solid var(--ink);border-radius:11px;padding:3px 0;font-size:20px;filter:grayscale(1);opacity:.45;transition:transform .25s,opacity .25s}
|
||||
.pzs span small{font:900 10px var(--body);text-transform:uppercase;letter-spacing:.05em}.pzs span.on{filter:none;opacity:1;background:#FFF3C4;transform:scale(1.05)}
|
||||
.pzck{display:flex;flex-wrap:wrap;gap:5px;margin:6px 0}.pzc{font-weight:900;font-size:12px;border:2px solid var(--ink);border-radius:999px;padding:1px 8px;background:#fff}
|
||||
.pzc.s1{background:#FFE3F0}.pzc.s2{background:var(--ok);color:#fff}
|
||||
.pztw{font-size:12.5px;font-weight:800;color:var(--bad);margin:3px 0}.pztw.ok{color:var(--eye)}
|
||||
.pzbud{margin:6px 0}.pzbud .kv{font-size:12.5px}
|
||||
.pzn1{font-size:12.5px;font-weight:800;margin:6px 0;padding:4px 8px;border:2px solid var(--line);border-radius:10px;color:var(--ink2)}
|
||||
.pzn1.on{border-color:var(--ok);background:#DFFBEA;color:var(--ink);animation:pzglow 1.6s ease-in-out infinite}.pzn1.bad{border-color:var(--warn);background:#FFF4D6;color:var(--ink)}
|
||||
@keyframes pzglow{50%{box-shadow:0 0 0 4px rgba(34,196,122,.25)}}
|
||||
#pzBox .btns{display:flex;flex-wrap:wrap;gap:6px;margin-top:6px}
|
||||
#pzBox .grab{display:none}
|
||||
.pzprog{margin:6px 0 4px}.pzpack{font-size:17px;margin:14px 0 2px}.pzst{font-size:12px;letter-spacing:-1px;white-space:nowrap}
|
||||
.scn.lock{opacity:.5}
|
||||
.pzres{position:relative}.pzstars{display:flex;justify-content:center;gap:10px;margin:10px 0 2px}
|
||||
.pzbig{font-size:46px;filter:grayscale(1);opacity:.3}.pzbig.on{filter:none;opacity:1}
|
||||
.pzbig.pop{animation:pzpop .5s cubic-bezier(.3,1.6,.5,1) var(--d) both}
|
||||
@keyframes pzpop{0%{transform:scale(0) rotate(-40deg);opacity:0}100%{transform:scale(1) rotate(0);opacity:1}}
|
||||
.pzconf{position:absolute;inset:-16px;pointer-events:none;overflow:hidden;z-index:2}
|
||||
.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.mini{max-height:none}#pzBox.mini>:not(.grab):not(.pzh):not(.pzs){display:none}
|
||||
#pzBox.mini .pzs{margin-top:0}
|
||||
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}
|
||||
}
|
||||
@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:none;border-radius:20px 0 0 0;border-right:0}
|
||||
body.pz #hint{bottom:12px !important;left:30% !important}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue