Dark mode: Light, Dark or Auto under Settings › Theme (#80)
A device preference (localStorage sot-theme, never in the save), applied by a small script in <head> before the first paint, so there is no flash; Auto follows prefers-color-scheme live, and a choice reaches other tabs and the NOC window. Panels, HUD, drawers, toasts, modals, the phone tab bar, charts, puzzles, the architect and Pie Control take their colours from custom properties with night values (AA text contrast); light tints keep their old colour as the fallback, so the light look is unchanged. Both map renderers read a light and a dark palette (96-map/15-palette.js): sea, land, clouds, coastlines, labels and the tube outline. A theme switch repaints the cached layers once (the WebGL land buffers are rebuilt once); nothing changes per frame. The multiplayer leaderboard's own row and the menu rank badge follow the theme too.
This commit is contained in:
parent
95aa9b6532
commit
2cd6b71198
49 changed files with 645 additions and 155 deletions
|
|
@ -19,7 +19,7 @@ function confTick(d){S.confReg=S.confReg||{};
|
|||
toast(tr('conferences.conf_in_city_you_shook_a',{conf:esc(cf.n),city:esc(CITY[cf.c].name),n:CONF_DAYS,region:esc(REG[reg])})+(sp?' '+tr('conferences.your_logo_was_on_every_lanyard',{region:esc(REG[reg])}):'')+(cf.cap?' '+tr('conferences.carriers_took_your_card_expect_big'):'')+extra,'goal');sfx('coin');}
|
||||
capDealTick(d);}
|
||||
function confSection(){const up=upcomingConfs(75).slice(0,3),cb=S.conf&&S.conf.until>S.day?S.conf:null;if(!up.length&&!cb)return '';
|
||||
return `<h3 style="font-size:15px;margin:10px 0 4px">${tr('common.conferences')}</h3>${cb?`<div class="inc" style="background:#EAF7EE"><div class="nm">${tr('conferences.name_glow_n_days_left',{name:esc(cb.name),n:cb.until-S.day})}</div><div class="meta">${tr('conferences.selective_networks_in_region_need',{region:esc(REG[cb.reg])})}${cb.sp?' '+tr('conferences.as_a_sponsor_you_also_get',{region:esc(REG[cb.reg])}):''}</div></div>`:''}${up.map(confRow).join('')}`;}
|
||||
return `<h3 style="font-size:15px;margin:10px 0 4px">${tr('common.conferences')}</h3>${cb?`<div class="inc" style="background:var(--tint-g,#EAF7EE)"><div class="nm">${tr('conferences.name_glow_n_days_left',{name:esc(cb.name),n:cb.until-S.day})}</div><div class="meta">${tr('conferences.selective_networks_in_region_need',{region:esc(REG[cb.reg])})}${cb.sp?' '+tr('conferences.as_a_sponsor_you_also_get',{region:esc(REG[cb.reg])}):''}</div></div>`:''}${up.map(confRow).join('')}`;}
|
||||
function confRow(cf){const reg=S.confReg&&S.confReg[cf.key],open=cf.day>S.day,sp=confSp(cf),cost=confCost(cf),lk=cf.cap&&glassLvl()<CAP_LV;
|
||||
const tags=(reg==='sp'?'<span class="tag st on">'+tr('conferences.sponsor')+'</span>':reg?'<span class="tag st on">'+tr('common.registered')+'</span>':open?'':'<span class="tag st">'+tr('common.registration_closed')+'</span>');
|
||||
const btns=!open||reg==='sp'?'':(reg?'':lk?btn(tr('sites_and_service.level_n',{n:CAP_LV}),'confGo',{key:cf.key},'sm',true):btn(tr('conferences.attend_cost',{cost:fmt$(cost)}),'confGo',{key:cf.key},'sm',S.cash<cost))+(sp?btn(tr('conferences.sponsor_cost',{cost:fmt$(CONF_SP-(reg?CONF_COST:0))}),'confSponsor',{key:cf.key},'pink sm',S.cash<CONF_SP-(reg?CONF_COST:0)):'');
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ function seatOffer(c,d){const rs=(c?SEAT_ROUTES[c]||[]:Object.values(SEAT_ROUTES
|
|||
if(!rs.length)return null;const r=rs[hstr(S.asn+'|seat|'+d)%rs.length];return {a:r[0],b:r[1],name:r[2],km:seatKm(r[0],r[1]),exp:d+SEAT_EXP};}
|
||||
function seatConf(c){if(S.seatOff||lvl()<SEAT_LV||S.scn)return;S.seatOff=seatOffer(c,S.day);if(S.seatOff)toast(tr('specialist.a_consortium_is_selling_seats_on',{name:esc(S.seatOff.name),a:CITY[S.seatOff.a].name,b:CITY[S.seatOff.b].name}),'goal',[{l:tr('common.show_me'),act:'leftTab',args:{t:'deals'}}]);}
|
||||
function seatSection(){const o=S.seatOff;if(!o||o.exp<=S.day)return '';const pop=[o.a,o.b].filter(c=>!S.pops[c]).reduce((x,c)=>x+newPopCost(c),0);
|
||||
return `<div class="inc" style="background:#E6F4FF"><div class="nm">🚢 ${tr('specialist.consortium_seat_name',{name:esc(o.name)})}</div><div class="meta">${tr('specialist.a_b_km_km_ready_in',{a:CITY[o.a].name,b:CITY[o.b].name,km:o.km.toLocaleString(),n:seatDays(o.km),ms:linkLat({kind:'df',own:true,sub:true,km:o.km,seaDesign:'standard'}).toFixed(1)})} · ${tr('ui.n_d_left',{n:o.exp-S.day})}</div>
|
||||
return `<div class="inc" style="background:var(--tint-b,#E6F4FF)"><div class="nm">🚢 ${tr('specialist.consortium_seat_name',{name:esc(o.name)})}</div><div class="meta">${tr('specialist.a_b_km_km_ready_in',{a:CITY[o.a].name,b:CITY[o.b].name,km:o.km.toLocaleString(),n:seatDays(o.km),ms:linkLat({kind:'df',own:true,sub:true,km:o.km,seaDesign:'standard'}).toFixed(1)})} · ${tr('ui.n_d_left',{n:o.exp-S.day})}</div>
|
||||
<div class="meta">${tr('specialist.your_own_fiber_pairs_on_a')}${pop?' '+tr('specialist.includes_pops_at_the_landings_price',{price:fmt$(pop)}):''}</div>
|
||||
<div class="btns">${SEAT_N.map(n=>{const c=seatCost(o.km,n)+pop;return btn(`${trn('specialist.n_fiber_pairs',n)} <small>${fmt$(c)} · ${tr('common.price_mo',{price:fmt$(seatMo(o.km,n))})}</small>`,'seatBuy',{n},'sm',S.cash<c);}).join('')}${btn(tr('common.decline'),'seatNo',{},'ghost sm')}</div></div>`;}
|
||||
function seatPanel(l){if(!l.seat)return '';return `<div class="kv"><span>${tr('specialist.consortium_seat')}</span><b>${esc(l.cname||'')} · ${trn('specialist.n_fiber_pairs',Math.max(1,l.pairs|0))}</b></div><p class="note">${tr('specialist.the_consortium_runs_the_cable_your')}</p>`;}
|
||||
|
|
@ -97,8 +97,8 @@ function charterAsk(){if(!charterDue()||!$('modal').hidden||window.__TUBES_TEST_
|
|||
function charterCard(){if(S.scn||S.mode!=='normal')return '';
|
||||
if(broker())return baronCard();
|
||||
if(charter()!=='boutique')return '';
|
||||
if(S.solWon)return `<div class="inc" style="background:#EAF7EE"><div class="nm">⚡ ${tr('specialist.speed_of_light')}</div><div class="meta">${tr('specialist.won_on_date_your_own_glass',{date:dateStr(S.solWon)})}</div></div>`;
|
||||
const r=solRoutes();return `<div class="inc" style="background:#EEF0FF"><div class="nm">⚡ ${tr('specialist.speed_of_light')}</div><div class="meta">${tr('specialist.routes_r_of_n_beat_the',{r:Math.min(r.length,SOL_ROUTES),n:SOL_ROUTES,c:Math.min(solCust(),SOL_CUST),m:SOL_CUST})}</div>${r.slice(0,SOL_ROUTES).map(x=>`<div class="meta">✓ ${CITY[x.a].name} ⇄ ${CITY[x.b].name}: ${tr('common.ms_ms_one_way',{ms:x.o.toFixed(1)})} < ${x.l.toFixed(1)}</div>`).join('')}</div>`;}
|
||||
if(S.solWon)return `<div class="inc" style="background:var(--tint-g,#EAF7EE)"><div class="nm">⚡ ${tr('specialist.speed_of_light')}</div><div class="meta">${tr('specialist.won_on_date_your_own_glass',{date:dateStr(S.solWon)})}</div></div>`;
|
||||
const r=solRoutes();return `<div class="inc" style="background:var(--tint-v,#EEF0FF)"><div class="nm">⚡ ${tr('specialist.speed_of_light')}</div><div class="meta">${tr('specialist.routes_r_of_n_beat_the',{r:Math.min(r.length,SOL_ROUTES),n:SOL_ROUTES,c:Math.min(solCust(),SOL_CUST),m:SOL_CUST})}</div>${r.slice(0,SOL_ROUTES).map(x=>`<div class="meta">✓ ${CITY[x.a].name} ⇄ ${CITY[x.b].name}: ${tr('common.ms_ms_one_way',{ms:x.o.toFixed(1)})} < ${x.l.toFixed(1)}</div>`).join('')}</div>`;}
|
||||
// Once a day: seats expire or call, the boutique checks its win and carriers call the broker.
|
||||
function specDay(d){if(broker())brokerDay(d);if(S.seatOff&&S.seatOff.exp<=d)S.seatOff=null;
|
||||
if(!S.seatOff&&!S.scn&&S.mode!=='puzzle'&&lvl()>=SEAT_LV&&hstr(S.asn+'|seatcall|'+d)%SEAT_ODDS===0)seatConf(null);
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ function glassChain(g){const by={};for(const l of S.links)if(ownGlassL(l)&&dfCap
|
|||
return Object.values(by).some(s=>s.size>=2);}
|
||||
const baronOk=()=>cableConts()>=BARON_CONT&&capSalesMo()>=BARON_MO;
|
||||
// On the goals tab, under the charter: how far Glass Baron is.
|
||||
function baronCard(){if(S.baronWon)return `<div class="inc" style="background:#EAF7EE"><div class="nm">🌊 ${tr('broker.glass_baron')}</div><div class="meta">${tr('broker.won_on_date',{date:dateStr(S.baronWon)})}</div></div>`;
|
||||
return `<div class="inc" style="background:#E6F4FF"><div class="nm">🌊 ${tr('broker.glass_baron')}</div><div class="meta">${tr('broker.progress',{c:Math.min(cableConts(),BARON_CONT),n:BARON_CONT,mo:fmt$(capSalesMo()),m:fmt$(BARON_MO)})}</div></div>`;}
|
||||
function baronCard(){if(S.baronWon)return `<div class="inc" style="background:var(--tint-g,#EAF7EE)"><div class="nm">🌊 ${tr('broker.glass_baron')}</div><div class="meta">${tr('broker.won_on_date',{date:dateStr(S.baronWon)})}</div></div>`;
|
||||
return `<div class="inc" style="background:var(--tint-b,#E6F4FF)"><div class="nm">🌊 ${tr('broker.glass_baron')}</div><div class="meta">${tr('broker.progress',{c:Math.min(cableConts(),BARON_CONT),n:BARON_CONT,mo:fmt$(capSalesMo()),m:fmt$(BARON_MO)})}</div></div>`;}
|
||||
function showBaronWin(){openModal(`<h1 style="font-family:var(--display);font-size:40px;margin:0">🌊 ${tr('broker.glass_baron')}</h1><p class="tagline">${tr('broker.win_text',{name:esc(S.name),asn:S.asn,days:S.day,n:BARON_CONT,mo:fmt$(capSalesMo())})}</p><div class="btns">${btn(tr('help.share_my_network'),'share',{},'pink')}${btn(tr('common.keep_playing'),'closeModal',{},'ghost')}</div>`);}
|
||||
/* Carriers call the broker now and then (about three times a year, from day 60) with a capacity deal on a route the
|
||||
capacity conferences trade: the same deals at the same terms, without the trip. Picked by a hash of the day, so a
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ function ddosDone(a){if(!a||a.done)return;a.done=1;if(a.worst===undefined&&S.pop
|
|||
function ddosPanel(){return S?ddosAll().filter(a=>S.pops[a.city]).map(ddosOne).join(''):'';}
|
||||
const ddCities=l=>{const u=[...new Set(l)];return u.slice(0,3).map(c=>CITY[c].name).join(', ')+(u.length>3?' +'+(u.length-3):'');};
|
||||
function ddosOne(a){const V=DDOS_VEC[a.vec]||{n:'?',fs:false},m=ddosReport(a),row=(ok,t)=>`<div class="meta">${ok===true?'✓':ok===false?'~':'—'} ${t}</div>`;
|
||||
let h=`<div class="inc ddos" style="background:#FFE2E6;border:1px solid #FF8A9A"><div class="nm">🚨 ${tr('ddos.card_title',{g:fmtG(a.gbps),vec:esc(V.n)})}</div>
|
||||
let h=`<div class="inc ddos" style="background:var(--tint-r,#FFE2E6);border:1px solid #FF8A9A"><div class="nm">🚨 ${tr('ddos.card_title',{g:fmtG(a.gbps),vec:esc(V.n)})}</div>
|
||||
<div class="meta"><b>${esc(ddosWho(a))}</b> · ${tr('ui.n_d_left',{n:Math.max(1,a.until-S.day)})}${a.carpet?' · '+tr('ddos.carpet'):''}</div>`;
|
||||
if(!m)return h+'</div>';
|
||||
const engIdle=hasScrub()&&!a.bh&&m.eng<1&&S.scrubMode==='ondemand'&&S.ddosAuto&&S.ddosAuto.scrub===false&&a.eng===undefined;
|
||||
|
|
|
|||
|
|
@ -50,4 +50,4 @@ function mkLeave(why){const M=S.monkey,d=S.day,ok=!why&&M.n>0&&M.hurt===0;M.on=0
|
|||
if(typeof mkEnd==='function')mkEnd(ok,true);}
|
||||
// The NOC tab's card while it is here.
|
||||
function mkCard(){if(!mkOn())return '';const M=S.monkey,c=mkBananaCost();
|
||||
return `<div class="inc" style="background:#FFF1D6;border:1px solid #FFC56B"><div class="nm">🐒 ${tr('chaos_monkey.loose')}</div><div class="meta">${tr('chaos_monkey.card',{n:Math.max(1,M.until-S.day),s:M.n,hurt:M.hurt})}</div><div class="btns">${btn(tr('chaos_monkey.banana',{cost:fmt$(c)}),'mkBanana',{},'sm',S.cash<c)}</div></div>`;}
|
||||
return `<div class="inc" style="background:var(--tint-o,#FFF1D6);border:1px solid #FFC56B"><div class="nm">🐒 ${tr('chaos_monkey.loose')}</div><div class="meta">${tr('chaos_monkey.card',{n:Math.max(1,M.until-S.day),s:M.n,hurt:M.hurt})}</div><div class="btns">${btn(tr('chaos_monkey.banana',{cost:fmt$(c)}),'mkBanana',{},'sm',S.cash<c)}</div></div>`;}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ const ACT={
|
|||
leaseSwap:({a,b,src})=>{if(!S.pops[a]||!S.pops[b]||a===b)return;$('dash').hidden=true;UI.lmode='df';UI.dfSrc=['lease','build','cable'].includes(src)?src:isSub(a,b)?'cable':'build';UI.dfSys=glassLvl()>=3?'roadm':'lite';openLinkModal(a,b);},
|
||||
dashLink:({id})=>{$('dash').hidden=true;selectLink(id);focusLink(id);},
|
||||
mapSet:({v})=>{if(!['auto','2d'].includes(v))return;mapGl(v==='auto');refreshSettings();},
|
||||
themeSet:({v})=>{if(!themePick(v))return;refreshSettings();},
|
||||
animSet:({v})=>{if(!['auto','on','off'].includes(v))return;UI.anim=v;try{localStorage.setItem('sot-anim',v);}catch(e){}applyAnim();refreshSettings();},
|
||||
soundSet:({v})=>{UI.muted=v==='off';try{localStorage.setItem('sot-mute',UI.muted?'1':'0');}catch(e){}renderHUD();refreshSettings();},
|
||||
langSet:({v})=>{if(!Object.hasOwn(LANGS,v)||v===LANG)return;try{localStorage.setItem('sot-lang',v);}catch(e){}save(true);location.reload();},
|
||||
|
|
|
|||
|
|
@ -62,6 +62,6 @@ Object.assign(ACT,{
|
|||
// open anything in it. Everything but these and the pz* actions does nothing while a puzzle is on. The main game's
|
||||
// routing controls (metric, standby, the redundancy check) work in a puzzle too, and their changes can be undone.
|
||||
// This file is the last of the actions, so every one is here to wrap.
|
||||
const PZ_ACTS=new Set(['animSet','closeModal','closePanel','help','helpClose','install','keepPlaying','langSet','linkCheck','mapSet','menu','metricMode','metricSet','mute','prefSet','puzzleDoor','puzzleMenu','selLink','setMetric','setStandby','settings','settingsClose','soundSet','speed','updateLater','updateNow','vpSet','whatsNewShow']);
|
||||
const PZ_ACTS=new Set(['animSet','closeModal','closePanel','help','helpClose','install','keepPlaying','langSet','linkCheck','mapSet','menu','metricMode','metricSet','mute','prefSet','puzzleDoor','puzzleMenu','selLink','setMetric','setStandby','settings','settingsClose','soundSet','speed','themeSet','updateLater','updateNow','vpSet','whatsNewShow']);
|
||||
const PZ_UNDO=new Set(['metricMode','metricSet','setMetric','setStandby']);
|
||||
for(const k of Object.keys(ACT)){const f=ACT[k];if(PZ_UNDO.has(k))ACT[k]=a=>{if(pzOn())pzSnap();return f(a);};else if(!PZ_ACTS.has(k)&&!/^pz[A-Z]/.test(k))ACT[k]=a=>pzOn()?undefined:f(a);}
|
||||
|
|
|
|||
27
src/game/93-ui/15-theme.js
Normal file
27
src/game/93-ui/15-theme.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ---------- Light or dark (#80) ----------
|
||||
Settings › Theme: Auto follows the device's light or dark setting, or the player picks one. A choice per device
|
||||
(localStorage sot-theme, like the animation and map settings), not part of the save. The page's <head> reads it and
|
||||
sets <html data-theme> before the first paint, so a dark screen never flashes light; this keeps it in step when the
|
||||
choice or the device's setting changes. The panels follow at once (CSS custom properties, 00-base.css); the map
|
||||
keeps pictures painted in the old colours, so it paints them again, once (themeRepaint()). */
|
||||
const THEME_OPTS=['auto','light','dark'],THEME_BAR={light:'#57C4E5',dark:'#0E2A44'}; // the browser bar: --sea
|
||||
const THEME={pref:'auto',dark:false,mq:null,on:null};
|
||||
function themeRead(){let v=null;try{v=localStorage.getItem('sot-theme');}catch(e){}return THEME_OPTS.includes(v)?v:'auto';}
|
||||
const themeSys=()=>{try{return !!(THEME.mq&&THEME.mq.matches);}catch(e){return false;}};
|
||||
// The page's colours from the choice (and the device's setting, on Auto). A switch repaints the map's cached pictures.
|
||||
function themeApply(repaint=true){const dark=THEME.pref==='dark'||(THEME.pref==='auto'&&themeSys()),was=THEME.dark,R0=document.documentElement;
|
||||
THEME.dark=dark;R0.setAttribute('data-theme',dark?'dark':'light');
|
||||
for(const [n,v] of [['theme-color',THEME_BAR[dark?'dark':'light']],['color-scheme',dark?'dark':'light']]){const m=document.querySelector(`meta[name="${n}"]`);if(m)m.setAttribute('content',v);}
|
||||
if(repaint&&was!==dark)themeRepaint();return dark;}
|
||||
function themePick(v){if(!THEME_OPTS.includes(v))return false;THEME.pref=v;try{v==='auto'?localStorage.removeItem('sot-theme'):localStorage.setItem('sot-theme',v);}catch(e){}themeApply();return true;}
|
||||
// Reads the choice and listens to the device's setting, which Auto follows as it changes (a phone at dusk).
|
||||
function themeInit(){THEME.pref=themeRead();THEME.on=()=>{if(THEME.pref==='auto')themeApply();};
|
||||
try{THEME.mq=window.matchMedia?matchMedia('(prefers-color-scheme: dark)'):null;}catch(e){}
|
||||
const q=THEME.mq;if(q){try{q.addEventListener?q.addEventListener('change',THEME.on):q.addListener(THEME.on);}catch(e){}}
|
||||
THEME.dark=document.documentElement.getAttribute('data-theme')==='dark';return themeApply(false);}
|
||||
/* What the map painted in the old colours: the land (the 2D picture, the card's coastlines), every sprite (labels,
|
||||
cities), the Pie globe unless the player chose its day or night. All painted again on the next frame, not every frame. */
|
||||
function themeRepaint(){WL.key=null;FRAME.length=0;UI.drawnAt=0;spritesReset();glLandDrop();
|
||||
let g=null;try{g=localStorage.getItem('sot-globe');}catch(e){}if(!g){PG.night=THEME.dark;PG.g=null;PG.dirty=true;}}
|
||||
// Picked in another tab: this one follows, and so does the NOC window on a second screen.
|
||||
if(!RW_IN){themeInit();addEventListener('storage',e=>{if(e.key==='sot-theme'||e.key===null){THEME.pref=themeRead();themeApply();}});}
|
||||
|
|
@ -8,7 +8,7 @@ function installRow(){if(isStandalone())return '';
|
|||
return `<div class="row icard"><div class="grow"><div class="nm">📲 ${tr('install.best_played_as_an_app')}</div><div class="meta">${tr('install.full_screen_works_offline_one_tap')}${isIOS()?' '+tr('install.install_it_before_you_start_a'):''}</div></div>${btn(tr('common.install'),'install',{},'pink sm')}</div>`;}
|
||||
/* Phones get a real pitch before a new game: an installed app is full screen, works offline, and on iPhone
|
||||
keeps its save away from Safari's clean-ups. Storage is separate on iOS, so installing first matters. */
|
||||
const SHARE_SVG='<svg width="16" height="18" viewBox="0 0 16 18" aria-hidden="true"><path d="M8 1v10M4.5 4.5 8 1l3.5 3.5M5 7H2.5v9.5h11V7H11" fill="none" stroke="#1E2640" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
||||
const SHARE_SVG='<svg width="16" height="18" viewBox="0 0 16 18" aria-hidden="true"><path d="M8 1v10M4.5 4.5 8 1l3.5 3.5M5 7H2.5v9.5h11V7H11" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
||||
const needPitch=()=>isPhone()&&!isStandalone();
|
||||
function installSteps(){
|
||||
if(isIOS())return `<ol class="isteps"><li>${tr('install.tap_share_icon_in_the_browser',{icon:SHARE_SVG})}</li><li>${tr('install.tap_add_to_home_screen_you')}</li><li>${tr('install.open_series_of_tubes_from_your')}</li></ol>`;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ function renderLeft(){checkLayer();
|
|||
}else if(UI.left==='deals'){
|
||||
{const st=custStats();if(st.n)h+=`<div class="row" style="margin-bottom:8px"><div class="grow"><div class="nm">${tr('common.your_customers')} <span class="meta">${st.n} · ${tr('hud_and_panels.happiness_p',{p:Math.round(st.avg)})}</span></div><div class="bar ${moodCls(st.avg)}"><i style="width:${st.avg}%"></i></div>${st.unhappy?`<div class="why">${trn('hud_and_panels.n_unhappy_customer_price_mo_at',st.unhappy,{price:fmt$(st.risk)})}</div>`:''}</div>${btn(st.unhappy?tr('common.see_who'):tr('common.all_customers'),'custOpen',{sad:st.unhappy?1:0},st.unhappy?'pink sm':'ghost sm')}</div>`;}
|
||||
h+=salesCard()+clDealsHtml()+confSection()+seatSection();
|
||||
{const lv=S.lvl||1,nx=LEVELS[lv];h+=`<div class="inc" style="background:#FFF6CF"><div class="nm">${tr('hud_and_panels.customer_level_lv_name',{lv,name:LEVELS[lv-1].n})}</div><div class="meta">${nx?tr('hud_and_panels.next_req_unlocks_what',{req:nx.req,what:lc1(nx.unlock)}):tr('common.every_customer_type_is_unlocked_go')}</div></div>`;}
|
||||
{const lv=S.lvl||1,nx=LEVELS[lv];h+=`<div class="inc" style="background:var(--tint-y,#FFF6CF)"><div class="nm">${tr('hud_and_panels.customer_level_lv_name',{lv,name:LEVELS[lv-1].n})}</div><div class="meta">${nx?tr('hud_and_panels.next_req_unlocks_what',{req:nx.req,what:lc1(nx.unlock)}):tr('common.every_customer_type_is_unlocked_go')}</div></div>`;}
|
||||
if(!S.offers.length)h+=`<p class="empty">${tr('hud_and_panels.no_open_offers_right_now_businesses')}</p>`;
|
||||
for(const o of S.offers.slice().sort((a,b)=>a.exp-b.exp)){const has=bHas(o);
|
||||
h+=`<div class="row"><div class="grow"><div class="nm">${esc(o.name)}</div><div class="meta">${esc(BIZ_T[o.type].l)} · ${CITY[o.city].name}${o.city2?' ⇄ '+CITY[o.city2].name:''} · <b>${bTerms(o)}</b> · ${tr('ui.n_d_left',{n:o.exp-S.day})}${(o.reqs||[]).length?` · ${trn('hud_and_panels.n_special_requirement',o.reqs.length)}`:''}</div>${o.refN?`<div class="meta">${tr('lifecycle.referred_by',{name:esc(o.refN)})}</div>`:''}${spotWhy(o)}${bRisk(o)}${reqList(o)}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ function linkTrial(id){const save=S,live=R,hot=UI.hotMap,cache=TE_CACHE;
|
|||
}finally{S=save;R=live;UI.hotMap=hot;TE_CACHE=cache;}}
|
||||
function linkCheckModal(l){const t=linkTrial(l.id);if(!t)return;
|
||||
const title=t.split?tr('link_panels.this_backhoe_wins'):t.loss>.01?tr('link_panels.connected_but_tight'):tr('link_panels.one_backhoe_is_not_enough');
|
||||
openModal(`<div style="display:flex;align-items:center;justify-content:space-between;gap:10px"><h2>${tr('common.redundancy_check')}</h2><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div><p class="eyebrow">${esc(CITY[l.a].name)} ⇄ ${esc(CITY[l.b].name)} · ${dateStr(t.day)}</p><div class="inc" style="background:${t.split?'#FFE3E3':t.loss>.01?'#FFF6CF':'#EAF7EE'}"><div class="nm">${title}</div><p class="lead">${t.split?tr('link_panels.no_alternate_backbone_path_connects'):t.loss>.01?tr('link_panels.an_alternate_path_exists_but_current'):tr('link_panels.with_current_demand_and_routing_this')}</p><div class="kv"><span>${tr('link_panels.additional_traffic_lost')}</span><b>${fmtG(t.loss)}</b></div></div>${t.losses.length?`<h3>${tr('common.service_affected')}</h3>${t.losses.map(x=>`<div class="kv"><span>${esc(x.name)}</span><b>−${fmtG(x.g)}</b></div>`).join('')}`:''}${t.busy.length?`<h3>${tr('link_panels.full_links_during_the_test')}</h3>${t.busy.slice(0,6).map(x=>`<div class="kv"><span>${esc(x.name)}</span><b>${fmtG(x.g)} / ${fmtG(x.cap)}</b></div>`).join('')}`:''}<p class="note">${tr('link_panels.snapshot_only_one_selected_link')}</p><div class="btns">${btn(tr('common.close'),'closeModal',{},'ghost')}</div>`,'link-check');}
|
||||
openModal(`<div style="display:flex;align-items:center;justify-content:space-between;gap:10px"><h2>${tr('common.redundancy_check')}</h2><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div><p class="eyebrow">${esc(CITY[l.a].name)} ⇄ ${esc(CITY[l.b].name)} · ${dateStr(t.day)}</p><div class="inc" style="background:${t.split?'var(--tint-r,#FFE3E3)':t.loss>.01?'var(--tint-y,#FFF6CF)':'var(--tint-g,#EAF7EE)'}"><div class="nm">${title}</div><p class="lead">${t.split?tr('link_panels.no_alternate_backbone_path_connects'):t.loss>.01?tr('link_panels.an_alternate_path_exists_but_current'):tr('link_panels.with_current_demand_and_routing_this')}</p><div class="kv"><span>${tr('link_panels.additional_traffic_lost')}</span><b>${fmtG(t.loss)}</b></div></div>${t.losses.length?`<h3>${tr('common.service_affected')}</h3>${t.losses.map(x=>`<div class="kv"><span>${esc(x.name)}</span><b>−${fmtG(x.g)}</b></div>`).join('')}`:''}${t.busy.length?`<h3>${tr('link_panels.full_links_during_the_test')}</h3>${t.busy.slice(0,6).map(x=>`<div class="kv"><span>${esc(x.name)}</span><b>${fmtG(x.g)} / ${fmtG(x.cap)}</b></div>`).join('')}`:''}<p class="note">${tr('link_panels.snapshot_only_one_selected_link')}</p><div class="btns">${btn(tr('common.close'),'closeModal',{},'ghost')}</div>`,'link-check');}
|
||||
function linkCheckControl(l){return `<section><h3>${tr('common.redundancy_check')}</h3><p class="note">${tr('link_panels.what_happens_if_this_link_fails')}</p>${btn(tr('common.check_redundancy'),'linkCheck',{id:l.id},'ghost sm',linkDown(l))}</section>`;}
|
||||
// At its own POP a carrier's port always takes that carrier's traffic (25-direct-egress.js). From POPs with no port of it, the
|
||||
// traffic goes to the nearest transit port, or across your network to this one. Only worth asking when something else could take it.
|
||||
|
|
@ -169,7 +169,7 @@ function svgChart(rows,stackKeys,lines,fmtY,id){
|
|||
for(let j=0;j<=3;j++){const v=ymax*j/3,yy=y(v);g+=`<line x1="${L}" x2="${W-Rr}" y1="${yy}" y2="${yy}" stroke="#D5DEEC" stroke-width="1"/><text x="${L-6}" y="${yy+3}" text-anchor="end" font-size="10" fill="#55608A" font-weight="700">${fmtY(v)}</text>`;}
|
||||
const base=rows.map(()=>0);
|
||||
for(const k of stackKeys){const top=rows.map((r,i)=>base[i]+(r[k]||0));let d=`M${x(0)},${y(top[0])}`;for(let i=1;i<rows.length;i++)d+=`L${x(i)},${y(top[i])}`;for(let i=rows.length-1;i>=0;i--)d+=`L${x(i)},${y(base[i])}`;g+=`<path d="${d}Z" fill="${EGC[k][1]}" fill-opacity=".85" stroke="#1E2640" stroke-width=".8"/>`;top.forEach((v,i)=>base[i]=v);}
|
||||
for(const ln of lines){let d='';rows.forEach((r,i)=>{d+=(i?'L':'M')+x(i)+','+y(r[ln.k]||0);});g+=`<path d="${d}" fill="none" stroke="${ln.col}" stroke-width="2.5" ${ln.dash?'stroke-dasharray="5 4"':''} stroke-linejoin="round"/>`;const last=rows[rows.length-1][ln.k]||0;g+=`<circle cx="${x(rows.length-1)}" cy="${y(last)}" r="3.5" fill="${ln.col}" stroke="#1E2640" stroke-width="1.5"/>`;}
|
||||
for(const ln of lines){let d='';rows.forEach((r,i)=>{d+=(i?'L':'M')+x(i)+','+y(r[ln.k]||0);});g+=`<path d="${d}" fill="none" style="stroke:${ln.col}" stroke-width="2.5" ${ln.dash?'stroke-dasharray="5 4"':''} stroke-linejoin="round"/>`;const last=rows[rows.length-1][ln.k]||0;g+=`<circle cx="${x(rows.length-1)}" cy="${y(last)}" r="3.5" style="fill:${ln.col}" stroke="#1E2640" stroke-width="1.5"/>`;}
|
||||
g+=`<text x="${L}" y="${H-5}" font-size="10" fill="#55608A" font-weight="700">${dateStr(rows[0].d)}</text><text x="${W-Rr}" y="${H-5}" text-anchor="end" font-size="10" fill="#55608A" font-weight="700">${dateStr(rows[rows.length-1].d)}</text>`;
|
||||
return `<svg class="chart" viewBox="0 0 ${W} ${H}" role="img"${id?` data-ch="${id}"`:''}>${g}</svg>`;}
|
||||
// For a network you currently reach over transit: the cheapest way to move it to peering.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ function renderDash(){checkLayer();
|
|||
const tile=(l,v,sub)=>`<div class="tile"><div class="lbl">${l}</div><div class="val">${v}</div>${sub?`<div class="sub">${sub}</div>`:''}</div>`;
|
||||
let h=`<div style="display:flex;align-items:center;gap:10px"><div><div class="eyebrow">AS${S.asn} · ${esc(S.name)} · ${tierLabel()}</div><h2 style="font-size:28px">${tr('common.noc_dashboard')}</h2></div><button class="x" data-act="dashClose" aria-label="${tr('common.close')}">×</button></div>`+dashTabs();const DT=UI.dtab||'overview';if(DT==='overview')h+=`
|
||||
<div class="dgrid">${tile(tr('common.traffic_now'),fmtG(R.served),tr('dashboard.of_g_wanted',{g:fmtG(R.demand)}))}${tile(tr('common.peak'),fmtG(S.stats.peak))}${tile(tr('dashboard.delivered_30_days'),(up*100).toFixed(1)+'%',up>=0.999?tr('dashboard.five_nines_ish'):up>=0.99?tr('dashboard.two_nines_and_change'):tr('dashboard.customers_are_upset'))}${tile(tr('common.peering_ratio'),pct(R.peerShare||0),tr('dashboard.caches_pnis_and_ix'))}${tile(tr('dashboard.monthly_p_l'),`<span style="color:${net>=0?'var(--eye)':'var(--bad)'}">${net>=0?'+':''}${fmt$(net)}</span>`,tr('dashboard.in_in_out_out',{in:fmt$(R.revMo),out:fmt$(R.costMo)}))}${tile(tr('common.incidents'),S.stats.incidents,tr('dashboard.n_shrugged_off',{n:S.stats.survived}))}</div>
|
||||
<div class="dcols"><div class="panel2"><h3>${tr('dashboard.traffic_by_way_out')}</h3>${svgChart(rows,['c','p','ix','t','l2'],[{k:'dem',col:'#1E2640',dash:true}],v=>fmtCap(Math.round(v)),'traffic')}${chartLegend('traffic',k=>k==='dem'?'':' '+pct((R.egT[k]||0)/tot))}</div>
|
||||
<div class="dcols"><div class="panel2"><h3>${tr('dashboard.traffic_by_way_out')}</h3>${svgChart(rows,['c','p','ix','t','l2'],[{k:'dem',col:'var(--text)',dash:true}],v=>fmtCap(Math.round(v)),'traffic')}${chartLegend('traffic',k=>k==='dem'?'':' '+pct((R.egT[k]||0)/tot))}</div>
|
||||
<div class="panel2"><h3>${tr('dashboard.money_per_month')}</h3>${svgChart(rows,[],[{k:'rev',col:'#16A866'},{k:'cost',col:'#FF4D5E'}],v=>fmt$(v),'money')}${chartLegend('money')}
|
||||
<h3 style="margin-top:8px">${tr('dashboard.where_the_money_goes')}</h3>${Object.entries(R.cost).filter(([k,v])=>v>0).sort((a,b)=>b[1]-a[1]).map(([k,v])=>`<div class="kv"><span>${{pops:tr('dashboard.pops_and_routers'),links:tr('dashboard.waves_and_fiber'),transit:tr('common.transit'),ix:tr('common.ix_ports'),pni:tr('common.pnis'),caches:tr('common.cache_power'),nni:tr('common.fabric_ports'),optical:tr('dashboard.amp_huts_and_spares'),loans:tr('common.loan_repayments'),revshare:tr('dashboard.investor_revenue_share'),extras:tr('dashboard.licenses_and_scrubbing'),wholesale:tr('dashboard.nearly_broadband_network_wholesale'),levy:tr('dashboard.regional_broadband_levy'),pie:tr('pie.costs_row')}[k]||k}</span><b>${tr('common.price_mo',{price:fmt$(v)})}</b></div>`).join('')}</div></div>`;
|
||||
const tT=(R.egT.t||0)||1;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
/* The NOC charts: legend entries switch a series on and off (the scale follows what is left), and hovering or
|
||||
touching a chart shows every visible series on that day. View state only: UI.chartOff is never saved. */
|
||||
const CHARTS={
|
||||
traffic:{stack:['c','p','ix','t','l2'],lines:['dem'],fmt:v=>fmtG(v),name:k=>k==='dem'?tr('common.demand'):EGC[k][0],col:k=>k==='dem'?'#1E2640':EGC[k][1]},
|
||||
traffic:{stack:['c','p','ix','t','l2'],lines:['dem'],fmt:v=>fmtG(v),name:k=>k==='dem'?tr('common.demand'):EGC[k][0],col:k=>k==='dem'?'var(--text)':EGC[k][1]},
|
||||
mix:{stack:['c','p','ix','t'],lines:[],fmt:v=>fmtG(v),name:k=>EGC[k][0],col:k=>EGC[k][1]}, // the Traffic tab's table
|
||||
money:{stack:[],lines:['rev','cost'],fmt:v=>fmt$(v),name:k=>k==='rev'?tr('common.revenue'):tr('common.costs'),col:k=>k==='rev'?'#16A866':'#FF4D5E'}
|
||||
};
|
||||
const chartKeys=C=>[...C.stack,...C.lines];
|
||||
// The demand line's key is a dashed outline, in the line's own colour (dark ink by day, light text at night).
|
||||
function chartLegend(id,label){const C=CHARTS[id],off=(UI.chartOff&&UI.chartOff[id])||{};
|
||||
return `<div class="legend">${chartKeys(C).map(k=>`<button class="lg${off[k]?' off':''}" aria-pressed="${!off[k]}" data-act="chartToggle" data-args="${esc(JSON.stringify({c:id,k}))}"><i style="background:${k==='dem'?'#fff;border-style:dashed':C.col(k)}"></i>${C.name(k)}${label?label(k):''}</button>`).join('')}</div>`;}
|
||||
return `<div class="legend">${chartKeys(C).map(k=>`<button class="lg${off[k]?' off':''}" aria-pressed="${!off[k]}" data-act="chartToggle" data-args="${esc(JSON.stringify({c:id,k}))}"><i style="background:${k==='dem'?`var(--paper);border-style:dashed;border-color:${C.col(k)}`:C.col(k)}"></i>${C.name(k)}${label?label(k):''}</button>`).join('')}</div>`;}
|
||||
Object.assign(ACT,{
|
||||
chartToggle:({c,k})=>{const C=CHARTS[c];if(!C||!chartKeys(C).includes(k))return;
|
||||
const off=((UI.chartOff=UI.chartOff||{})[c]=UI.chartOff[c]||{});if(off[k])delete off[k];else off[k]=1;
|
||||
|
|
|
|||
11
src/game/96-map/15-palette.js
Normal file
11
src/game/96-map/15-palette.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* The map's colours by theme (#80): the cartoon day, and a night under the same stickers (cities and markers keep
|
||||
theirs; a dark outline round a white sticker reads on either). Both renderers read them when they paint: the 2D map
|
||||
in drawFrame()/paintWorld(), the card in glBegin()/glFrame() (glPal()). Labels: the pill, its text and its edge.
|
||||
What is only an outline turns light at night, or it would vanish into the dark land and sea: the tubes' casing
|
||||
(casing) and a puzzle's stepping-stone ring (via). */
|
||||
const MAP_PAL={
|
||||
light:{sea:'#62CBEA',sea2:'#43AED6',wave:'rgba(255,255,255,.45)',cloud:'rgba(255,255,255,.55)',shadow:'rgba(20,90,130,.35)',sand:'#F8E6A8',land:'#9BDA6C',hill:'#86CB5B',shine:'rgba(255,255,255,.18)',coast:'#1E2640',
|
||||
pill:'#FFFFFF',pillInk:'#1E2640',pillEdge:'#1E2640',halo:'rgba(255,255,255,.85)',casing:'#1E2640',via:'rgba(30,38,64,.7)'},
|
||||
dark:{sea:'#173E5E',sea2:'#0B2440',wave:'rgba(160,210,255,.14)',cloud:'rgba(200,220,255,.1)',shadow:'rgba(0,0,0,.35)',sand:'#4E5440',land:'#2E5A3A',hill:'#284F31',shine:'rgba(255,255,255,.05)',coast:'#081020',
|
||||
pill:'#1A2340',pillInk:'#E9EFFB',pillEdge:'#070B16',halo:'rgba(8,16,32,.85)',casing:'#A9B7D8',via:'rgba(233,239,251,.75)'}};
|
||||
const MPAL=()=>THEME.dark?MAP_PAL.dark:MAP_PAL.light;
|
||||
|
|
@ -31,6 +31,7 @@ function settingsHtml(){const seg=(lab,act,cur,opts,note)=>`<div class="setline"
|
|||
${seg(tr('settings.pause_on_outages_that_hurt'),'prefSet',cur('pauseIncident'),onoff('pauseIncident'),tr('settings.stops_the_game_when_a_failure'))}
|
||||
${seg(tr('settings.quiet_notifications'),'prefSet',cur('quiet'),onoff('quiet'),tr('settings.only_trouble_and_milestones_pop_up'))}
|
||||
<h3 class="sub4">${tr('settings.display_and_sound')}</h3>
|
||||
${seg(tr('settings.theme'),'themeSet',THEME.pref,[['auto',tr('common.auto')],['light',tr('settings.light')],['dark',tr('settings.dark')]],tr('settings.auto_follows_your_device_s_light'))}
|
||||
${seg(tr('common.animations'),'animSet',UI.anim||'auto',[['auto',tr('common.auto')],['on',tr('common.on')],['off',tr('common.off')]],tr('settings.auto_follows_your_device_s_reduce'))}
|
||||
${seg(tr('settings.map_drawing'),'mapSet',GLX.want?'auto':'2d',[['auto',tr('common.auto')],['2d',tr('settings.always_2d')]],tr('settings.auto_draws_the_map_with_your')+(GLX.want&&!glCan()?' '+tr('settings.this_browser_cannot_so_the_map'):''))}
|
||||
${seg(tr('common.sound'),'soundSet',UI.muted?'off':'on',[['on',tr('common.on')],['off',tr('common.off')]])}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ function drawCables(ks){const G=glOn(),z=cam.z,selC=UI.drag&&UI.drag.mode==='lin
|
|||
const ar=arOn();for(const cp of CABLE_PAIRS){const C=CAB[cp.cid],hot=!!selC&&(cp.a===selC||cp.b===selC);if(!hot&&cached&&z<1.7)continue;if(ar&&!hot&&!(arKind(cp.a)&&arKind(cp.b)))continue;const col=cableCol(C);
|
||||
for(const k of ks){const sp=cp.pts.map(p=>toS(p[0],p[1],k));let mn=Infinity,mx=-Infinity;for(const q of sp){if(q[0]<mn)mn=q[0];if(q[0]>mx)mx=q[0];}if(mx<-20||mn>CW+20)continue;
|
||||
if(!G&&(hot||!cached)){ctx.globalAlpha=hot?0.95:0.4;ctx.strokeStyle=col;ctx.lineWidth=hot?3:1.6;ctx.lineJoin='round';ctx.setLineDash(C.age==='old'?[6,5]:[]);ctx.beginPath();ctx.moveTo(sp[0][0],sp[0][1]);for(let i=1;i<sp.length;i++)ctx.lineTo(sp[i][0],sp[i][1]);ctx.stroke();ctx.setLineDash([]);}
|
||||
if((hot||(z>=1.7&&!ar))&&lbOk(sp[Math.floor(sp.length/2)][0],sp[Math.floor(sp.length/2)][1]-8,labW(C.name),sp,hot)){const m=sp[Math.floor(sp.length/2)];ctx.globalAlpha=hot?1:0.75;textStamp(C.name,ctx.font,10,labW(C.name),col,'rgba(255,255,255,.85)',3,m[0],m[1]-8);}
|
||||
if((hot||(z>=1.7&&!ar))&&lbOk(sp[Math.floor(sp.length/2)][0],sp[Math.floor(sp.length/2)][1]-8,labW(C.name),sp,hot)){const m=sp[Math.floor(sp.length/2)];ctx.globalAlpha=hot?1:0.75;textStamp(C.name,ctx.font,10,labW(C.name),col,MPAL().halo,3,m[0],m[1]-8);}
|
||||
ctx.globalAlpha=1;}}}
|
||||
function bezGeom(l,at){const A=CITY[l.a],B=CITY[l.b];const i=at!==undefined?at:lineIdx(l);const key=l.id+'|b'+i;const hit=GEO.get(key);if(hit)return hit;
|
||||
const bx=A.x+wrapDx(A.x,B.x),by=B.y;const dx=bx-A.x,dy=by-A.y,len=Math.hypot(dx,dy)||1;let nx=-dy/len,ny=dx/len;if(ny>0){nx=-nx;ny=-ny;}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@
|
|||
the 2D map paints them (drawFrame(), paintWorld()) and in the same colours. The land and the cables are geometry
|
||||
built once, so panning and zooming repaint nothing; only the waves and the clouds move. */
|
||||
const glPm=s=>{const [r,g,b,a]=glColor(s);return [r*a,g*a,b*a,a];}; // premultiplied, as the card blends
|
||||
const SEA_TOP=glPm('#62CBEA'),SEA_BOT=glPm('#43AED6'),CLOUD_COL=glPm('rgba(255,255,255,.55)');
|
||||
const LAND_SHADOW=glPm('rgba(20,90,130,.35)'),LAND_GRASS=glPm('#9BDA6C'),HILL_COL=glPm('#86CB5B'),HILL_SHINE=glPm('rgba(255,255,255,.18)');
|
||||
// The theme's colours (MPAL(), 15-palette.js) as the card takes them, worked out again only when the theme changes.
|
||||
const GLP={m:null};
|
||||
function glPal(){const m=MPAL();if(GLP.m!==m)Object.assign(GLP,{m,seaTop:glPm(m.sea),seaBot:glPm(m.sea2),cloud:glPm(m.cloud),shadow:glPm(m.shadow),grass:glPm(m.land),
|
||||
hill:glPm(m.hill),shine:glPm(m.shine),wave:glColor(m.wave),sand:glColor(m.sand),edge:glColor(m.coast),casing:glColor(m.casing)});return GLP;}
|
||||
// The land's fill: a fan of triangles per coastline, counted in the stencil (how many times the coasts wind round each
|
||||
// pixel: glLandFill()), then one cover where the count is not zero. uOff shifts it in CSS px (the shadow).
|
||||
const FAN_VS=GL_HEAD+GL_CLIP+`layout(location=0) in vec2 aV;uniform vec2 uView,uOff;uniform vec3 uCam;
|
||||
|
|
@ -49,7 +51,7 @@ function coastLevel(z){const want=Math.floor(Math.log2(Math.max(z,1/64))),cur=GL
|
|||
function coastFan(P,out){let a=0;const n=P.length;for(let i=0;i<n;i++){const p=P[i],q=P[(i+1)%n];a+=p[0]*q[1]-q[0]*p[1];}
|
||||
const s=a<0?1:0;for(let i=1;i+1<n;i++){const b=P[i+s],c=P[i+1-s];out.push(P[0][0],P[0][1],b[0],b[1],c[0],c[1]);}return out;}
|
||||
function glLandGeo(gl,far,lv){const key=(far?'far':'all')+(lv===undefined?'':'@'+lv);let G=GLX.land[key];if(G)return G;
|
||||
const keep=far?new Set(LANDP_FAR):null,tol=lv===undefined?0:COAST_TOL/Math.pow(2,lv),fan=[],sand=[],edge=[],SAND=glColor('#F8E6A8'),EDGE=glColor('#1E2640');
|
||||
const keep=far?new Set(LANDP_FAR):null,tol=lv===undefined?0:COAST_TOL/Math.pow(2,lv),fan=[],sand=[],edge=[],P=glPal(),SAND=P.sand,EDGE=P.edge;
|
||||
COAST.forEach((ring,ri)=>{if(keep&&!keep.has(LANDP_ALL[ri]))return;if(ring.length<3)return;
|
||||
const P=coastSimplify(coastPts(ri),tol);if(P.length<4)return;
|
||||
coastFan(P,fan);
|
||||
|
|
@ -57,10 +59,14 @@ function glLandGeo(gl,far,lv){const key=(far?'far':'all')+(lv===undefined?'':'@'
|
|||
const s0=sand.length/LINE_STRIDE;for(let i=0;i+1<P.length;i++){glSeg(sand,P[i],P[i+1],0,10,0,LINE_ROUND,SAND);glSeg(edge,P[i],P[i+1],0,2.5,0,LINE_ROUND,EDGE);}
|
||||
const s1=sand.length/LINE_STRIDE;glJoin(sand,s0,s1,true);glJoin(edge,s0,s1,true);});
|
||||
const hills=[],shine=[];for(const [x,y,r] of HILLS){hills.push(x,y,r*1.4,r*.8);shine.push(x-r*.3,y-r*.25,r*.6,r*.3);}
|
||||
const F=a=>new Float32Array(a);
|
||||
G={fan:glVao(gl,[2],0,F(fan)).v,nFan:fan.length/2,sand:glVao(gl,[4,4,4,4],1,F(sand)).v,edge:glVao(gl,[4,4,4,4],1,F(edge)).v,nSeg:sand.length/LINE_STRIDE,
|
||||
hills:glVao(gl,[4],1,F(hills)).v,shine:glVao(gl,[4],1,F(shine)).v,nHill:HILLS.length};
|
||||
// The buffers are kept with the land, so a theme change can let them go (the coastlines' colours are in them).
|
||||
const bufs=[],V=(sz,div,a)=>{const x=glVao(gl,sz,div,new Float32Array(a));bufs.push(x);return x.v;};
|
||||
G={fan:V([2],0,fan),nFan:fan.length/2,sand:V([4,4,4,4],1,sand),edge:V([4,4,4,4],1,edge),nSeg:sand.length/LINE_STRIDE,
|
||||
hills:V([4],1,hills),shine:V([4],1,shine),nHill:HILLS.length,bufs};
|
||||
glMem(gl,'the land');return GLX.land[key]=G;}
|
||||
// A theme change (themeRepaint()): every level of the land is built again, in the new colours, when next drawn.
|
||||
function glLandDrop(){const gl=GLX.gl,L=GLX.land;GLX.land={};if(!gl||!L)return;
|
||||
try{if(gl.isContextLost())return;for(const G of Object.values(L))for(const x of G.bufs||[]){gl.deleteVertexArray(x.v);gl.deleteBuffer(x.b);}}catch(e){}}
|
||||
// Fills the land's shape (shifted by ox, oy CSS px) with one colour, for every copy of the map.
|
||||
// The stencil counts the coasts' windings (+1 for a triangle facing one way, -1 the other: coastFan()), as the 2D
|
||||
// canvas's nonzero rule does; counting only odd or even made two overlapping coasts cancel out into sea.
|
||||
|
|
@ -75,16 +81,15 @@ function glLandFill(gl,G,ks,ox,oy,col){const P=GLX.fan;gl.enable(gl.STENCIL_TEST
|
|||
function glEllipses(gl,vao,n,ks,col){const P=GLX.ell;gl.useProgram(P.p);gl.bindVertexArray(vao);gl.uniform2f(P.u.uView,CW,CH);gl.uniform1f(P.u.uDpr,DPR);gl.uniform4fv(P.u.uCol,col);
|
||||
for(const k of ks){gl.uniform3f(P.u.uCam,cam.x-k*W,cam.y,cam.z);gl.drawArraysInstanced(gl.TRIANGLE_STRIP,0,4,n);}}
|
||||
// In paintWorld()'s order: the shadow (5, 7 px down and right), the sand, the grass, the hills, the coastline.
|
||||
function glLand(gl,ks){const G=glLandGeo(gl,lodFar(),coastLevel(cam.z));
|
||||
glLandFill(gl,G,ks,5,7,LAND_SHADOW);
|
||||
function glLand(gl,ks){const G=glLandGeo(gl,lodFar(),coastLevel(cam.z)),P=glPal();
|
||||
glLandFill(gl,G,ks,5,7,P.shadow);
|
||||
glLines(gl,G.sand,G.nSeg,ks);
|
||||
glLandFill(gl,G,ks,0,0,LAND_GRASS);
|
||||
glEllipses(gl,G.hills,G.nHill,ks,HILL_COL);glEllipses(gl,G.shine,G.nHill,ks,HILL_SHINE);
|
||||
glLandFill(gl,G,ks,0,0,P.grass);
|
||||
glEllipses(gl,G.hills,G.nHill,ks,P.hill);glEllipses(gl,G.shine,G.nHill,ks,P.shine);
|
||||
glLines(gl,G.edge,G.nSeg,ks);}
|
||||
// The waves: each one two quadratic curves of four segments, swaying with the map's clock as in drawFrame(). They are
|
||||
// written into the same array every frame (no garbage for the collector to pick up while you play).
|
||||
const WAVE_COL=glColor('rgba(255,255,255,.45)');
|
||||
function glWaves(gl,now,ks){const A=GLX.wa||(GLX.wa=new Float32Array(WAVES.length*8*LINE_STRIDE)),ph0=now/900;let m=0;
|
||||
function glWaves(gl,now,ks){const A=GLX.wa||(GLX.wa=new Float32Array(WAVES.length*8*LINE_STRIDE)),ph0=now/900,WAVE_COL=glPal().wave;let m=0;
|
||||
for(const [x,y,ph] of WAVES){const o=Math.sin(ph0+ph*6)*3,m0=m;
|
||||
// Two curves: up from x-9 to x, then down to x+9 (no array literals per wave: they were garbage every frame).
|
||||
for(let c=0;c<2;c++){const x0=x+o+(c?0:-9),cx=x0+4.5,cy=y+(c?4:-4),x1=x0+9;let px=x0,py=y;
|
||||
|
|
@ -100,7 +105,7 @@ function glClouds(gl,now,ks){const need=ks.length*CLOUDS.length*12;if(!need)retu
|
|||
const F=A.subarray(0,n),P=GLX.circ;gl.bindBuffer(gl.ARRAY_BUFFER,GLX.cl.b);gl.bufferData(gl.ARRAY_BUFFER,F,gl.DYNAMIC_DRAW);
|
||||
gl.enable(gl.STENCIL_TEST);gl.stencilFunc(gl.ALWAYS,1,255);gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE);gl.colorMask(false,false,false,false);
|
||||
gl.useProgram(P.p);gl.bindVertexArray(GLX.cl.v);gl.uniform2f(P.u.uView,CW,CH);gl.uniform3f(P.u.uCam,cam.x,cam.y,cam.z);gl.drawArraysInstanced(gl.TRIANGLE_STRIP,0,4,F.length/4);
|
||||
gl.colorMask(true,true,true,true);gl.stencilFunc(gl.EQUAL,1,255);gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP);glFill(gl,CLOUD_COL);gl.disable(gl.STENCIL_TEST);}
|
||||
gl.colorMask(true,true,true,true);gl.stencilFunc(gl.EQUAL,1,255);gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP);glFill(gl,glPal().cloud);gl.disable(gl.STENCIL_TEST);}
|
||||
// The cables, as drawCables() strokes them: rebuilt only when the highlighted city or the architect view changes.
|
||||
function glCables(gl,ks,selC,ar){const key=[selC,ar];
|
||||
if(!GLX.ckey||key.some((v,i)=>v!==GLX.ckey[i])){const A=[];
|
||||
|
|
@ -119,7 +124,7 @@ function glBegin(now,ks){const gl=GLX.gl,c=GLX.c,f=GLX.f;glShow(true);GLS.frame=
|
|||
gl.viewport(0,0,c.width,c.height);gl.clearColor(0,0,0,0);gl.clearDepth(1);gl.clearStencil(0);gl.colorMask(true,true,true,true);gl.depthMask(true);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT|gl.STENCIL_BUFFER_BIT);
|
||||
gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE_MINUS_SRC_ALPHA);gl.disable(gl.DEPTH_TEST);gl.disable(gl.STENCIL_TEST);
|
||||
glFill(gl,SEA_TOP,SEA_BOT);
|
||||
const P=glPal();glFill(gl,P.seaTop,P.seaBot);
|
||||
glLand(gl,ks);
|
||||
glWaves(gl,now,ks);
|
||||
glClouds(gl,now,ks);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ function glJoin(A,i0,i1,closed){closed=closed&&i1-i0>2;
|
|||
meet, their round ends overlap: each keeps only its side of the corner's bisector, so a see-through line (the
|
||||
halo, the cables, the waves, the fiber's dots) is blended once there, as the 2D canvas strokes a path once. */
|
||||
const GL_LINE_VS=GL_HEAD+GL_CLIP+`layout(location=0) in vec4 aSeg;layout(location=1) in vec4 aP;layout(location=2) in vec4 aC;layout(location=3) in vec4 aN;
|
||||
uniform vec2 uView;uniform vec3 uCam;uniform float uWMul,uDpr,uBusy;uniform int uPass;
|
||||
uniform vec2 uView;uniform vec3 uCam,uCas;uniform float uWMul,uDpr,uBusy;uniform int uPass;
|
||||
out vec2 vLoc;out float vLen,vS0,vHalf,vButt;flat out vec4 vCol,vK;flat out vec2 vDash,vEnd;
|
||||
// The corner's bisector between directions u and v, in the segment's own frame (t along it, n across), and whether there is one.
|
||||
vec3 cut(vec2 u,vec2 v,vec2 t,vec2 n){vec2 m=u+v;float l=length(m);if(length(u)<.5||length(v)<.5||l<1e-3)return vec3(0.);m/=l;return vec3(dot(t,m),dot(n,m),1.);}
|
||||
|
|
@ -32,7 +32,7 @@ vec2 dashOf(int k){${LDASH.map((d,i)=>d.length?`if(k==${i})return vec2(${d[0]}.,
|
|||
void main(){vec2 h=uView*.5,a=(aSeg.xy-uCam.xy)*uCam.z+h,b=(aSeg.zw-uCam.xy)*uCam.z+h;
|
||||
float w=aP.y*uWMul,hw=w*.5;int fl=int(aP.w+.5);vec4 col=vec4(aC.yzw,1.);vec2 dash=dashOf(int(aP.z+.5));bool skip=false;
|
||||
if(uPass==${LP.halo}){hw=(w+14.)*.5;col=vec4(1.,79./255.,154./255.,.35);dash=vec2(0.);skip=(fl&${LINE_SEL})==0;}
|
||||
else if(uPass==${LP.casing}){hw=(w+4.)*.5;col=vec4(30./255.,38./255.,64./255.,1.);}
|
||||
else if(uPass==${LP.casing}){hw=(w+4.)*.5;col=vec4(uCas,1.);}
|
||||
else if(uPass==${LP.dots}){hw=max(1.,w*.25)*.5;col=vec4(1.,1.,1.,.75);dash=dashOf(5);skip=(fl&${LINE_FIBER})==0||uBusy>.5;}
|
||||
else if(uPass==${LP.plain})col.a=aC.x;
|
||||
if(skip){gl_Position=vec4(2.,2.,2.,1.);return;}
|
||||
|
|
@ -103,7 +103,9 @@ function glFrame(ML,ks,far,busy,now,sc){const gl=GLX.gl;
|
|||
if(net)glBuild(ML.LG,ML.GM,ML.looks);
|
||||
if(net||GLX.key[1]!==selId){glHalo(ML.LG,ML.GM,ML.looks,selId);GLX.key=[ML,selId];}
|
||||
gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE_MINUS_SRC_ALPHA);gl.enable(gl.DEPTH_TEST);gl.depthFunc(gl.LEQUAL);gl.depthMask(true);
|
||||
const L=GLX.line,K=GLX.pk,wm=sc*(far?0.5:1),lines=(pass,v=GLX.lv.v,n=GLX.nSeg)=>{gl.useProgram(L.p);gl.bindVertexArray(v);gl.uniform1f(L.u.uBusy,busy?1:0);gl.uniform1i(L.u.uPass,pass);
|
||||
// The casing is the theme's (glPal()), a uniform: the tubes' buffers keep only their own colours.
|
||||
const L=GLX.line,K=GLX.pk,wm=sc*(far?0.5:1),cas=glPal().casing,lines=(pass,v=GLX.lv.v,n=GLX.nSeg)=>{gl.useProgram(L.p);gl.bindVertexArray(v);gl.uniform1f(L.u.uBusy,busy?1:0);gl.uniform1i(L.u.uPass,pass);
|
||||
gl.uniform3f(L.u.uCas,cas[0],cas[1],cas[2]);
|
||||
for(const k of ks){glSet(gl,L,k,wm);gl.drawArraysInstanced(gl.TRIANGLE_STRIP,0,4,n);}};
|
||||
if(GLX.nSeg)for(const pass of [LP.casing,LP.colour,LP.dots])lines(pass);
|
||||
if(GLX.nPk){gl.useProgram(K.p);gl.bindVertexArray(GLX.pv.v);gl.activeTexture(gl.TEXTURE0);gl.bindTexture(gl.TEXTURE_2D,GLX.tex);gl.uniform1i(K.u.uPts,0);
|
||||
|
|
@ -111,11 +113,11 @@ function glFrame(ML,ks,far,busy,now,sc){const gl=GLX.gl;
|
|||
// The selection's halo goes over earlier tubes but under its own line and later ones, as in 2D.
|
||||
if(GLX.nHalo){gl.depthFunc(gl.LESS);gl.depthMask(false);lines(LP.halo,GLX.hv.v,GLX.nHalo);gl.depthMask(true);}
|
||||
gl.bindVertexArray(null);}
|
||||
// The link being dragged out (x,y in CSS px): the dark dotted line, then the pink one running along it, over the tubes
|
||||
// and, since the pictures are drawn after it, under the cities, as in 2D.
|
||||
const DRAG_INK=glColor('#1E2640'),DRAG_PINK=glColor('#FF4F9A');
|
||||
// The link being dragged out (x,y in CSS px): the dotted line in the tubes' casing colour, then the pink one running
|
||||
// along it, over the tubes and, since the pictures are drawn after it, under the cities, as in 2D.
|
||||
const DRAG_PINK=glColor('#FF4F9A');
|
||||
function glDrag(ax,ay,tx,ty,now){const gl=GLX.gl,A=GLX.da||(GLX.da=new Float32Array(2*LINE_STRIDE)),z=cam.z,mx=x=>(x-CW/2)/z+cam.x,my=y=>(y-CH/2)/z+cam.y;
|
||||
glSegAt(A,0,mx(ax),my(ay),mx(tx),my(ty),0,7,7,LINE_ROUND,1,DRAG_INK);
|
||||
glSegAt(A,0,mx(ax),my(ay),mx(tx),my(ty),0,7,7,LINE_ROUND,1,glPal().casing);
|
||||
glSegAt(A,1,mx(ax),my(ay),mx(tx),my(ty),-now/30/z,4,7,LINE_ROUND,1,DRAG_PINK);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER,GLX.dv.b);gl.bufferData(gl.ARRAY_BUFFER,A,gl.DYNAMIC_DRAW);
|
||||
gl.disable(gl.DEPTH_TEST);glLines(gl,GLX.dv.v,2,[0]);gl.bindVertexArray(null);}
|
||||
|
|
|
|||
|
|
@ -16,21 +16,21 @@ function drawFrame(now){
|
|||
// WebGL on: the sea, land, waves, clouds and cables are on the card (glBegin); the 2D canvas below them stays empty.
|
||||
// Off (2D chosen, no game, a puzzle, the card given up), its layers are hidden here, before anything can return early.
|
||||
if(G){try{glBegin(now,ks);}catch(e){throw glErr(e);}}
|
||||
else{glShow(false);GLX.c0clean=false;const wl=worldLayer(z);
|
||||
else{glShow(false);GLX.c0clean=false;const wl=worldLayer(z),mp=MPAL();
|
||||
ctx.setTransform(DPR,0,0,DPR,0,0);
|
||||
// sea
|
||||
const g=ctx.createLinearGradient(0,0,0,CH);g.addColorStop(0,'#62CBEA');g.addColorStop(1,'#43AED6');ctx.fillStyle=g;ctx.fillRect(0,0,CW,CH);
|
||||
const g=ctx.createLinearGradient(0,0,0,CH);g.addColorStop(0,mp.sea);g.addColorStop(1,mp.sea2);ctx.fillStyle=g;ctx.fillRect(0,0,CW,CH);
|
||||
for(const k of ks){
|
||||
ctx.setTransform(DPR*z,0,0,DPR*z,DPR*((k*W-cam.x)*z+CW/2),DPR*((-cam.y)*z+CH/2));
|
||||
// waves: one path, one stroke
|
||||
ctx.strokeStyle='rgba(255,255,255,.45)';ctx.lineWidth=2/z;ctx.lineCap='round';ctx.beginPath();
|
||||
ctx.strokeStyle=mp.wave;ctx.lineWidth=2/z;ctx.lineCap='round';ctx.beginPath();
|
||||
const ph0=now/900;for(const [x,y,ph] of WAVES){const o=Math.sin(ph0+ph*6)*3;ctx.moveTo(x-9+o,y);ctx.quadraticCurveTo(x-4.5+o,y-4,x+o,y);ctx.quadraticCurveTo(x+4.5+o,y+4,x+9+o,y);}ctx.stroke();
|
||||
}
|
||||
for(const k of ks){if(wl)drawWorldLayer(wl,k,z,ks[0]);else{ctx.setTransform(DPR*z,0,0,DPR*z,DPR*((k*W-cam.x)*z+CW/2),DPR*((-cam.y)*z+CH/2));paintWorld(ctx,z,false);}}
|
||||
for(const k of ks){
|
||||
ctx.setTransform(DPR*z,0,0,DPR*z,DPR*((k*W-cam.x)*z+CW/2),DPR*((-cam.y)*z+CH/2));
|
||||
// clouds
|
||||
ctx.fillStyle='rgba(255,255,255,.55)';ctx.beginPath();
|
||||
ctx.fillStyle=mp.cloud;ctx.beginPath();
|
||||
for(const c of CLOUDS){const x=((c.x+now/1000*c.v)%(W+200))-100,y=c.y;ctx.moveTo(x+16*c.s,y);ctx.arc(x,y,16*c.s,0,7);ctx.moveTo(x+38*c.s,y-8*c.s);ctx.arc(x+18*c.s,y-8*c.s,20*c.s,0,7);ctx.moveTo(x+55*c.s,y);ctx.arc(x+40*c.s,y,15*c.s,0,7);}ctx.fill();
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ function drawFrame(now){
|
|||
drawCables(ks);
|
||||
// links
|
||||
AR_PILLS.length=0;
|
||||
const far=lodFar(),ML=mapLinks(day),LG=ML.LG,GM=ML.GM,PI=ML.PI,busy=linesOnScreen(GM,ks)>MAP_BUSY;
|
||||
const far=lodFar(),ML=mapLinks(day),LG=ML.LG,GM=ML.GM,PI=ML.PI,busy=linesOnScreen(GM,ks)>MAP_BUSY,cas=MPAL().casing;
|
||||
// WebGL on: the card draws every line and packet now, and the rest (labels, markers, cities…) goes on the overlay.
|
||||
if(G)try{glFrame(ML,ks,far,busy,now,sc);}catch(e){throw glErr(e);}
|
||||
for(let gi=0;gi<LG.length;gi++){const grp=LG[gi],{l,many,up,cap,load,df,bld,cut,dark,vx,w0,col,dash,pk}=ML.looks[gi],gm=GM[gi];
|
||||
|
|
@ -62,10 +62,10 @@ function drawFrame(now){
|
|||
const path=()=>{ctx.beginPath();ctx.moveTo(SX[0],SY[0]);for(let i=1;i<np;i++)ctx.lineTo(SX[i],SY[i]);};
|
||||
ctx.lineCap='round';ctx.lineJoin='round';
|
||||
if(sel){ctx.strokeStyle='rgba(255,79,154,.35)';ctx.lineWidth=w+14;path();ctx.stroke();}
|
||||
ctx.strokeStyle='#1E2640';ctx.lineWidth=w+4;ctx.setLineDash(LDASH[dash]);path();ctx.stroke();
|
||||
ctx.strokeStyle=cas;ctx.lineWidth=w+4;ctx.setLineDash(LDASH[dash]);path();ctx.stroke();
|
||||
ctx.strokeStyle=col;ctx.lineWidth=w;ctx.stroke();ctx.setLineDash([]);
|
||||
// Architect runs: tubes sharing one trench are drawn as strands of one bundle (one snip takes them all).
|
||||
if(pz&&many){ctx.strokeStyle='#1E2640';ctx.lineWidth=1.3;for(let j=1;j<grp.length;j++){const d=w*(j/grp.length-0.5);ctx.beginPath();for(let i=0;i<np;i++){const a=Math.max(0,i-1),b=Math.min(np-1,i+1),dx=SX[b]-SX[a],dy=SY[b]-SY[a],n=Math.hypot(dx,dy)||1,x=SX[i]-dy/n*d,y=SY[i]+dx/n*d;i?ctx.lineTo(x,y):ctx.moveTo(x,y);}ctx.stroke();}path();}
|
||||
if(pz&&many){ctx.strokeStyle=cas;ctx.lineWidth=1.3;for(let j=1;j<grp.length;j++){const d=w*(j/grp.length-0.5);ctx.beginPath();for(let i=0;i<np;i++){const a=Math.max(0,i-1),b=Math.min(np-1,i+1),dx=SX[b]-SX[a],dy=SY[b]-SY[a],n=Math.hypot(dx,dy)||1,x=SX[i]-dy/n*d,y=SY[i]+dx/n*d;i?ctx.lineTo(x,y):ctx.moveTo(x,y);}ctx.stroke();}path();}
|
||||
// Still the same path: strokes keep it, so the dotted fiber line goes on top without building it again.
|
||||
if(df&&!bld&&!dark&&!busy){ctx.strokeStyle='rgba(255,255,255,.75)';ctx.lineWidth=Math.max(1,w*0.25);ctx.setLineDash([1,6]);ctx.stroke();ctx.setLineDash([]);}
|
||||
const at=t=>polyAtXY(SX,SY,gm.cum,t);
|
||||
|
|
@ -75,7 +75,7 @@ function drawFrame(now){
|
|||
[mxx,my]=at(.5);}
|
||||
if(bld){if(far)stamp('bldfar',12,12,6,6,1,mxx,my,g=>{g.fillStyle='#FF8A3D';g.strokeStyle='#1E2640';g.lineWidth=1.5;g.beginPath();g.arc(0,0,4,0,7);g.fill();g.stroke();});else drawCone(mxx,my,now);}
|
||||
else if(cut&&!vx){if(far)stamp('cutfar',14,14,7,7,1,mxx,my,g=>{g.fillStyle='#FF4D5E';g.strokeStyle='#1E2640';g.lineWidth=1.5;g.beginPath();g.arc(0,0,5,0,7);g.fill();g.stroke();g.fillStyle='#fff';g.font='900 8px Nunito, sans-serif';g.textAlign='center';g.textBaseline='middle';g.fillText('!',0,0.5);});else if(!arPz)drawBackhoe(mxx,my,now,l.sub);}
|
||||
else if(sel||(pz?!S.ar:z>0.9&&!busy)){const t=lab||(lab=pz?pzLinkLab(grp,up||[l],load,cap):many?groupLabel(grp,up):capName(l));ctx.font='800 11px "Baloo 2", sans-serif';let tw=LINKW.get(t);if(tw===undefined)LINKW.set(t,tw=ctx.measureText(t).width+10);pill(t,ctx.font,tw,17,8,'#fff','#1E2640','#1E2640',2,mxx,my-0.5,1.5);}
|
||||
else if(sel||(pz?!S.ar:z>0.9&&!busy)){const t=lab||(lab=pz?pzLinkLab(grp,up||[l],load,cap):many?groupLabel(grp,up):capName(l));ctx.font='800 11px "Baloo 2", sans-serif';let tw=LINKW.get(t);if(tw===undefined)LINKW.set(t,tw=ctx.measureText(t).width+10);const mp=MPAL();pill(t,ctx.font,tw,17,8,mp.pill,mp.pillInk,mp.pillEdge,2,mxx,my-0.5,1.5);}
|
||||
// Every puzzle: say whether the tubes between two cities share one trench or take separate paths.
|
||||
if(pz&&!cut&&!bld&&(many||arPaths(l)>1)&&(many||lineIdx(l,PI.get(edgeKey(l)))===0))AR_PILLS.push([mxx,my+(sel||!S.ar?19:0),many?tr('architect.n_in_one_trench',{n:grp.length}):'✓ '+tr('architect.n_paths',{n:arPaths(l)}),many]);
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ function drawFrame(now){
|
|||
if(UI.snap){const B=CITY[UI.snap.id];const wx=A.x+wrapDx(A.x,B.x);for(const k of [-1,1]){const [px,py]=toS(A.x,A.y,k),[qx]=toS(wx,B.y,k);if(Math.abs(qx-CW/2)<Math.abs(tx-CW/2)){ax=px;ay=py;tx=qx;}}}
|
||||
// On the card it goes under the cities and their labels, as in 2D (the overlay would put it over them).
|
||||
if(G)try{glDrag(ax,ay,tx,ty,now);}catch(e){throw glErr(e);}
|
||||
else{ctx.strokeStyle='#1E2640';ctx.lineWidth=7;ctx.lineCap='round';ctx.setLineDash(LDASH[7]);ctx.beginPath();ctx.moveTo(ax,ay);ctx.lineTo(tx,ty);ctx.stroke();
|
||||
else{ctx.strokeStyle=MPAL().casing;ctx.lineWidth=7;ctx.lineCap='round';ctx.setLineDash(LDASH[7]);ctx.beginPath();ctx.moveTo(ax,ay);ctx.lineTo(tx,ty);ctx.stroke();
|
||||
ctx.strokeStyle='#FF4F9A';ctx.lineWidth=4;ctx.lineDashOffset=-now/30;ctx.stroke();ctx.setLineDash([]);ctx.lineDashOffset=0;}
|
||||
if(UI.snap&&UI.snap.id!==UI.drag.from){const b=UI.snap.id,km=kmBetween(UI.drag.from,b),sub=isSub(UI.drag.from,b);
|
||||
const t=`${km.toLocaleString()} km${sub?' · '+tr('common.subsea'):''} · ${sub&&!cablesFor(UI.drag.from,b).length?tr('draw.no_cable_lands_here'):tr('draw.from_price_mo',{price:fmt$(waveMo(km,sub,0))})}`;
|
||||
|
|
@ -141,13 +141,13 @@ function linesOnScreen(GM,ks){let n=0;for(const gm of GM){const b=gm.box||(gm.bo
|
|||
function ptsBox(pts){let a=Infinity,b=Infinity,c=-Infinity,d=-Infinity;for(const p of pts){if(p[0]<a)a=p[0];if(p[1]<b)b=p[1];if(p[0]>c)c=p[0];if(p[1]>d)d=p[1];}return [a,b,c,d];}
|
||||
function drawCone(x,y,now){stamp('cone',26,28,13,13,1,x,y-12+Math.sin(now/300)*1.5,()=>{ctx.strokeStyle='#1E2640';ctx.lineWidth=2;ctx.fillStyle='#FF8A3D';ctx.beginPath();ctx.moveTo(-7,9);ctx.lineTo(0,-10);ctx.lineTo(7,9);ctx.closePath();ctx.fill();ctx.stroke();ctx.fillStyle='#fff';ctx.fillRect(-4,-1,8,3);ctx.fillStyle='#1E2640';rr(-10,8,20,4,2);ctx.fill();});}
|
||||
// Static land + cable map, rendered once per zoom bucket into an offscreen canvas.
|
||||
function paintWorld(c,z,withCables){const LANDP=lodFar()?LANDP_FAR:LANDP_ALL;
|
||||
for(const o of [0,W,-W]){c.save();c.translate(o+5/z,7/z);c.fillStyle='rgba(20,90,130,.35)';for(const p of LANDP)c.fill(p);c.restore();}
|
||||
c.strokeStyle='#F8E6A8';c.lineWidth=10/z;c.lineJoin='round';for(const o of [0,W,-W]){c.save();c.translate(o,0);for(const p of LANDP)c.stroke(p);c.restore();}
|
||||
c.fillStyle='#9BDA6C';for(const o of [0,W,-W]){c.save();c.translate(o,0);for(const p of LANDP)c.fill(p);c.restore();}
|
||||
c.fillStyle='#86CB5B';c.beginPath();for(const [x,y,r] of HILLS){c.moveTo(x+r*1.4,y);c.ellipse(x,y,r*1.4,r*.8,0,0,Math.PI*2);}c.fill();
|
||||
c.fillStyle='rgba(255,255,255,.18)';c.beginPath();for(const [x,y,r] of HILLS){c.moveTo(x-r*.3+r*.6,y-r*.25);c.ellipse(x-r*.3,y-r*.25,r*.6,r*.3,0,0,Math.PI*2);}c.fill();
|
||||
c.strokeStyle='#1E2640';c.lineWidth=2.5/z;for(const o of [0,W,-W]){c.save();c.translate(o,0);for(const p of LANDP)c.stroke(p);c.restore();}
|
||||
function paintWorld(c,z,withCables){const LANDP=lodFar()?LANDP_FAR:LANDP_ALL,mp=MPAL();
|
||||
for(const o of [0,W,-W]){c.save();c.translate(o+5/z,7/z);c.fillStyle=mp.shadow;for(const p of LANDP)c.fill(p);c.restore();}
|
||||
c.strokeStyle=mp.sand;c.lineWidth=10/z;c.lineJoin='round';for(const o of [0,W,-W]){c.save();c.translate(o,0);for(const p of LANDP)c.stroke(p);c.restore();}
|
||||
c.fillStyle=mp.land;for(const o of [0,W,-W]){c.save();c.translate(o,0);for(const p of LANDP)c.fill(p);c.restore();}
|
||||
c.fillStyle=mp.hill;c.beginPath();for(const [x,y,r] of HILLS){c.moveTo(x+r*1.4,y);c.ellipse(x,y,r*1.4,r*.8,0,0,Math.PI*2);}c.fill();
|
||||
c.fillStyle=mp.shine;c.beginPath();for(const [x,y,r] of HILLS){c.moveTo(x-r*.3+r*.6,y-r*.25);c.ellipse(x-r*.3,y-r*.25,r*.6,r*.3,0,0,Math.PI*2);}c.fill();
|
||||
c.strokeStyle=mp.coast;c.lineWidth=2.5/z;for(const o of [0,W,-W]){c.save();c.translate(o,0);for(const p of LANDP)c.stroke(p);c.restore();}
|
||||
if(withCables)for(const off of [0,W,-W]){c.save();c.translate(off,0);for(const cp of CABLE_PAIRS){const C=CAB[cp.cid];c.globalAlpha=0.4;c.strokeStyle=cableCol(C);c.lineWidth=1.6/z;c.lineJoin='round';c.setLineDash(C.age==='old'?[6/z,5/z]:[]);c.beginPath();c.moveTo(cp.pts[0][0],cp.pts[0][1]);for(let i=1;i<cp.pts.length;i++)c.lineTo(cp.pts[i][0],cp.pts[i][1]);c.stroke();}c.restore();}
|
||||
c.globalAlpha=1;c.setLineDash([]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ function drawCityFar(C,sx,sy,sc,now,lyOverride){
|
|||
stamp(m.k,36,36,18,18,1,sx,sy,()=>cityFarStatic(C,p,down,sel,hov,ph));
|
||||
if(CM.dish&&CM.dish.has(C.id))dishBadge(sx+(p?10:6),sy+(p?6:5),CM.dish.get(C.id),CM.dl&&CM.dl[C.id]);
|
||||
if(lyOverride!==null&&(p||sel||hov)){ctx.font=`800 ${p?12:11}px "Baloo 2", sans-serif`;const t=C.name,wk=C.id+(p?1:0);let tw=LBLF.get(wk);if(tw===undefined)LBLF.set(wk,tw=ctx.measureText(t).width+12);const ly=lyOverride==null?sy+15:lyOverride;
|
||||
pill(t,ctx.font,tw,16,8,p?'#FF4F9A':'#FFFFFF',p?'#FFFFFF':'#1E2640','#1E2640',1.6,sx,ly,1);}
|
||||
const mp=MPAL();pill(t,ctx.font,tw,16,8,p?'#FF4F9A':mp.pill,p?'#FFFFFF':mp.pillInk,mp.pillEdge,1.6,sx,ly,1);}
|
||||
}
|
||||
function cityFarStatic(C,p,down,sel,hov,ph){ctx.strokeStyle='#1E2640';
|
||||
if(sel){ctx.strokeStyle='#FF4F9A';ctx.lineWidth=2.5;ctx.setLineDash([4,4]);ctx.lineDashOffset=-ph;ctx.beginPath();ctx.arc(0,0,p?14:9,0,7);ctx.stroke();ctx.setLineDash([]);ctx.lineDashOffset=0;ctx.strokeStyle='#1E2640';}
|
||||
|
|
@ -141,7 +141,7 @@ function drawCity(C,sx,sy,sc,now,lyOverride,dem){
|
|||
// label
|
||||
if((cam.z>=0.62||p||sel||hov)&&(lyOverride!==null||hov)){
|
||||
ctx.font=`800 ${p?13:12}px "Baloo 2", sans-serif`;const t=C.name,tw=LBLW[C.id+(p?1:0)]||(LBLW[C.id+(p?1:0)]=ctx.measureText(t).width+14),ly=lyOverride==null?sy+16*sc+8:lyOverride;
|
||||
pill(t,ctx.font,tw,19,9,p?'#FF4F9A':'#FFFFFF',p?'#FFFFFF':'#1E2640','#1E2640',2,sx,ly+0.5,0.5);
|
||||
const mp=MPAL();pill(t,ctx.font,tw,19,9,p?'#FF4F9A':mp.pill,p?'#FFFFFF':mp.pillInk,mp.pillEdge,2,sx,ly+0.5,0.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ function pzDrawCity(v,sc,now){const k=pzKind(v.C.id);
|
|||
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,gold=S.ar&&S.ar.gold.includes(v.C.id),dk=S.ar&&arDarkNow(v.C.id);ctx.strokeStyle=dk?`rgba(255,77,94,${a})`:gold?`rgba(224,160,0,${p?1:a})`:k==='goal'?`rgba(255,79,154,${p?1:a})`:'rgba(30,38,64,.7)';if(gold||dk)ctx.lineWidth=5;if(k==='via')ctx.setLineDash([5,5]);
|
||||
else{const a=animOn()?.55+.35*Math.sin(now/300):.8,gold=S.ar&&S.ar.gold.includes(v.C.id),dk=S.ar&&arDarkNow(v.C.id);ctx.strokeStyle=dk?`rgba(255,77,94,${a})`:gold?`rgba(224,160,0,${p?1:a})`:k==='goal'?`rgba(255,79,154,${p?1:a})`:MPAL().via;if(gold||dk)ctx.lineWidth=5;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,v.dem);
|
||||
const b=k==='goal'&&!CM.far?pzBadge(v.C.id):'';if(b){ctx.font=`${Math.round(15*sc)}px sans-serif`;ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(b,v.sx-r*.75,y-r*.75);}} // top left: the IX badge has the top right
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ const PG_ST={
|
|||
const PG={cv:null,ctx:null,get:null,raf:0,last:0,t:0,yaw:-20,tilt:18,vy:0,drag:null,night:null,anim:true,dirty:true,
|
||||
data:null,dAt:-1e9,sig:'',sm:[],dish:[],fl:[],hi:null,pads:[],lch:[],fly:[],on:null,g:null,frames:0,m:new Float64Array(9)};
|
||||
let PG_LAND=null,PG_LAND_DIR=null,PG_TURN=1,PG_GRID=null,PG_LIGHT=null,PG_STAR=null;
|
||||
const pgNightPref=()=>{if(PG.night===null){try{PG.night=localStorage.getItem('sot-globe')==='night';}catch(e){PG.night=false;}}return PG.night;};
|
||||
// Day or night as the player last chose it; until then, as the theme (#80).
|
||||
const pgNightPref=()=>{if(PG.night===null){try{const g=localStorage.getItem('sot-globe');PG.night=g?g==='night':THEME.dark;}catch(e){PG.night=THEME.dark;}}return PG.night;};
|
||||
// Unit vectors for the land rings (LANDS_LL), the graticule, city lights and stars: worked out once, on first open.
|
||||
function pgUnit(lo,la,a,i){const b=la*PG_D,c=Math.cos(b),o=lo*PG_D;a[i]=c*Math.cos(o);a[i+1]=c*Math.sin(o);a[i+2]=Math.sin(b);}
|
||||
// One land ring, clipped to the near side (as map libraries clip). The coast runs to where it meets the horizon; from there the
|
||||
|
|
|
|||
|
|
@ -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','keys','randomName','pickStart','cont','help','helpClose','newgame','mute','animSet','mapSet','soundSet','langSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','presetSet','chaosSet','puzzleDoor','puzzleMenu','pzStart','pzArStart','pzWeekly','scenarios','startScn','startWeekly','settings','settingsClose','prefSet','vpSet','install','pitchSkip','slotMenu','slotExport','slotDel','slotDelGo','slotBack','slotSwitch','slotTake','slotSpace','toTitle','mpDoor','mpBack','mpStart','mpJoin'].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','keys','randomName','pickStart','cont','help','helpClose','newgame','mute','animSet','mapSet','soundSet','langSet','themeSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','presetSet','chaosSet','puzzleDoor','puzzleMenu','pzStart','pzArStart','pzWeekly','scenarios','startScn','startWeekly','settings','settingsClose','prefSet','vpSet','install','pitchSkip','slotMenu','slotExport','slotDel','slotDelGo','slotBack','slotSwitch','slotTake','slotSpace','toTitle','mpDoor','mpBack','mpStart','mpJoin'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue