octiqflow-linux-x64 0.3.19 → 0.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/octiq-server +0 -0
- package/bin/v2/assets/IslandPage-B8zXknRt.js +16 -0
- package/bin/v2/assets/IslandPage-B8zXknRt.js.br +0 -0
- package/bin/v2/assets/IslandPage-B8zXknRt.js.gz +0 -0
- package/bin/v2/assets/index-BN4tJeS6.css +1 -0
- package/bin/v2/assets/index-BN4tJeS6.css.br +0 -0
- package/bin/v2/assets/index-BN4tJeS6.css.gz +0 -0
- package/bin/v2/assets/{index-CayFcoA2.js → index-BijqmrIf.js} +1 -1
- package/bin/v2/assets/index-BijqmrIf.js.br +0 -0
- package/bin/v2/assets/index-BijqmrIf.js.gz +0 -0
- package/bin/v2/assets/{index-BTym0syk.js → index-C7kRVW7q.js} +1 -1
- package/bin/v2/assets/index-C7kRVW7q.js.br +0 -0
- package/bin/v2/assets/index-C7kRVW7q.js.gz +0 -0
- package/bin/v2/assets/index-CKmCA1gi.js +588 -0
- package/bin/v2/assets/index-CKmCA1gi.js.br +0 -0
- package/bin/v2/assets/index-CKmCA1gi.js.gz +0 -0
- package/bin/v2/assets/{index-BsAClh62.js → index-CPT_YpjT.js} +1 -1
- package/bin/v2/assets/index-CPT_YpjT.js.br +0 -0
- package/bin/v2/assets/index-CPT_YpjT.js.gz +0 -0
- package/bin/v2/assets/{index-nSFJTmcW.js → index-D22ujAMP.js} +1 -1
- package/bin/v2/assets/index-D22ujAMP.js.br +0 -0
- package/bin/v2/assets/index-D22ujAMP.js.gz +0 -0
- package/bin/v2/assets/{index-53w9dbcs.js → index-DAwl9HGY.js} +1 -1
- package/bin/v2/assets/index-DAwl9HGY.js.br +0 -0
- package/bin/v2/assets/{index-53w9dbcs.js.gz → index-DAwl9HGY.js.gz} +0 -0
- package/bin/v2/assets/{index-D09WLjNO.js → index-DQNuXjur.js} +1 -1
- package/bin/v2/assets/index-DQNuXjur.js.br +0 -0
- package/bin/v2/assets/index-DQNuXjur.js.gz +0 -0
- package/bin/v2/assets/{index-D6gUr_hW.js → index-DQtP_CC6.js} +1 -1
- package/bin/v2/assets/index-DQtP_CC6.js.br +0 -0
- package/bin/v2/assets/index-DQtP_CC6.js.gz +0 -0
- package/bin/v2/assets/{index-DTZEPBu_.js → index-DfreU7M_.js} +1 -1
- package/bin/v2/assets/index-DfreU7M_.js.br +0 -0
- package/bin/v2/assets/index-DfreU7M_.js.gz +0 -0
- package/bin/v2/assets/{index-DJJPkGpw.js → index-E_k_kYir.js} +1 -1
- package/bin/v2/assets/index-E_k_kYir.js.br +0 -0
- package/bin/v2/assets/index-E_k_kYir.js.gz +0 -0
- package/bin/v2/assets/{index-CiHfu8PZ.js → index-YNnmRrtC.js} +1 -1
- package/bin/v2/assets/index-YNnmRrtC.js.br +0 -0
- package/bin/v2/assets/index-YNnmRrtC.js.gz +0 -0
- package/bin/v2/assets/{index-CKzlKEI2.js → index-jZgYW6KS.js} +1 -1
- package/bin/v2/assets/index-jZgYW6KS.js.br +0 -0
- package/bin/v2/assets/index-jZgYW6KS.js.gz +0 -0
- package/bin/v2/assets/portrait-BuBLkdle.js +1 -0
- package/bin/v2/assets/portrait-BuBLkdle.js.br +0 -0
- package/bin/v2/assets/portrait-BuBLkdle.js.gz +0 -0
- package/bin/v2/assets/{robot-C9LkSRnk.js → robot-DgoHoWJ_.js} +160 -160
- package/bin/v2/assets/robot-DgoHoWJ_.js.br +0 -0
- package/bin/v2/assets/robot-DgoHoWJ_.js.gz +0 -0
- package/bin/v2/index.html +2 -2
- package/package.json +1 -1
- package/bin/v2/assets/IslandPage-Ch0SrxvK.js +0 -8
- package/bin/v2/assets/IslandPage-Ch0SrxvK.js.br +0 -0
- package/bin/v2/assets/IslandPage-Ch0SrxvK.js.gz +0 -0
- package/bin/v2/assets/index-53w9dbcs.js.br +0 -0
- package/bin/v2/assets/index-BTym0syk.js.br +0 -0
- package/bin/v2/assets/index-BTym0syk.js.gz +0 -0
- package/bin/v2/assets/index-BsAClh62.js.br +0 -0
- package/bin/v2/assets/index-BsAClh62.js.gz +0 -0
- package/bin/v2/assets/index-ByQ4NgKr.css +0 -1
- package/bin/v2/assets/index-ByQ4NgKr.css.br +0 -0
- package/bin/v2/assets/index-ByQ4NgKr.css.gz +0 -0
- package/bin/v2/assets/index-CKzlKEI2.js.br +0 -0
- package/bin/v2/assets/index-CKzlKEI2.js.gz +0 -0
- package/bin/v2/assets/index-CUWHqfQT.js +0 -569
- package/bin/v2/assets/index-CUWHqfQT.js.br +0 -0
- package/bin/v2/assets/index-CUWHqfQT.js.gz +0 -0
- package/bin/v2/assets/index-CayFcoA2.js.br +0 -0
- package/bin/v2/assets/index-CayFcoA2.js.gz +0 -0
- package/bin/v2/assets/index-CiHfu8PZ.js.br +0 -0
- package/bin/v2/assets/index-CiHfu8PZ.js.gz +0 -0
- package/bin/v2/assets/index-D09WLjNO.js.br +0 -0
- package/bin/v2/assets/index-D09WLjNO.js.gz +0 -0
- package/bin/v2/assets/index-D6gUr_hW.js.br +0 -0
- package/bin/v2/assets/index-D6gUr_hW.js.gz +0 -0
- package/bin/v2/assets/index-DJJPkGpw.js.br +0 -0
- package/bin/v2/assets/index-DJJPkGpw.js.gz +0 -0
- package/bin/v2/assets/index-DTZEPBu_.js.br +0 -0
- package/bin/v2/assets/index-DTZEPBu_.js.gz +0 -0
- package/bin/v2/assets/index-nSFJTmcW.js.br +0 -0
- package/bin/v2/assets/index-nSFJTmcW.js.gz +0 -0
- package/bin/v2/assets/portrait-Bon7JcMe.js +0 -1
- package/bin/v2/assets/portrait-Bon7JcMe.js.br +0 -0
- package/bin/v2/assets/portrait-Bon7JcMe.js.gz +0 -0
- package/bin/v2/assets/robot-C9LkSRnk.js.br +0 -0
- package/bin/v2/assets/robot-C9LkSRnk.js.gz +0 -0
package/bin/octiq-server
CHANGED
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import{r as R,b as Ie,a as mt,T as Oe,c as qe,d as is,p as Pe,e as Q,C as Je,f as Gt,P as it,g as ns,S as kt,o as as,h as os,u as rs,i as hs,j as ls,k as cs,w as ht,l as y,W as ds,A as us}from"./index-CKmCA1gi.js";import{G as J,B as Ve,M as me,a as C,c as Kt,p as Yt,C as gt,b as Z,d as Xe,A as yt,S as Qe,e as Ht,R as at,f as ps,V as X,g as Ue,T as We,Q as Mt,h as vt,i as de,j as fs,P as ms,k as gs,l as Zt,m as se,N as ys,n as xt,o as qt,q as xs,r as dt,s as $e,t as ws,I as zt,D as ut,u as Xt,v as _t,w as bs,x as Qt,F as ks,y as Ms,z as vs,W as zs,E as _s,H as Ss,J as Ps,K as js,L as Es,O as As,U as Ts,X as Rs,Y as Ds,Z as St,_ as Ls,$ as Cs,a0 as Pt,a1 as lt,a2 as Ns}from"./robot-DgoHoWJ_.js";const Is=o=>String(o?.message??o);function Os(o){const[e,t]=R.useState(null),[s,i]=R.useState(null),[n,a]=R.useState(null),r=R.useRef(null),d=R.useRef(0),u=R.useCallback(()=>{const f=++d.current;Ie.invoke("island_get").then(h=>{if(f!==d.current||!h?.island)return;const l=h.island;r.current&&r.current.rev>l.rev||(r.current=l,t(l),i(null))}).catch(h=>{f===d.current&&i(Is(h))})},[]);R.useEffect(()=>{if(!o)return;u();const f=Ie.on("island-changed",l=>{l&&(r.current&&l.rev<=r.current.rev||(a(l),u()))}),h=Ie.on("chat-status",l=>{l?.key.startsWith("chat:island-wish-")&&u()});return()=>{f(),h()}},[o,u]);const p=R.useCallback(async(f,h={})=>{await Ie.invoke(f,h),u()},[u]);return{island:e,error:s,change:n,reload:u,dismissWish:f=>p("island_wish_dismiss",{id:f}),grantWish:f=>p("island_wish_start",{id:f}),rollWish:()=>p("island_wish_roll"),inviteBot:()=>p("island_bot_invite"),farewell:f=>p("island_bot_farewell",{id:f}),setPace:f=>p("island_settings_set",{wishPace:f}),setBuildPace:f=>p("island_build_pace",{pace:f})}}function Ws(o,e=Date.now()){const t=new Map;for(const s of o){const i=a=>s.activities.find(r=>r.state===a)?.title,n=s.state==="working"?{state:"working",label:i("working")}:s.state==="needs_you"?{state:"needs_you",label:i("needs_you")}:s.state==="failed"?{state:"failed",label:i("failed")}:{state:"free",...s.recent?{idleFor:Math.max(0,Math.round((e-s.recent.at)/6e4))}:{}};t.set(`agent:${s.id}`,n)}return t}function $s(o,e=Date.now()){const t=Math.max(0,Math.round((e-o)/6e4));if(t<1)return"just now";if(t<60)return`${t} min ago`;const s=Math.round(t/60);return s<24?`${s} h ago`:`${Math.round(s/24)} d ago`}function Vt(o,e){const t=new Map;for(const h of[...e].sort((l,m)=>l.key.localeCompare(m.key))){const l=h.agent?.teamId?`team:${h.agent.teamId}`:"general";t.set(l,[...t.get(l)??[],h])}t.has("general")||t.set("general",[]);const s=[],i=o.assets.filter(h=>h.kind==="accessory"),n=[],a=[],r=new Map,d=o.plots.filter(h=>h.owner.kind==="home"&&h.owner.id.startsWith("public:")||o.placed.some(l=>l.plot===h.id&&o.assets.some(m=>m.id===l.asset&&m.kind==="building"&&m.name!=="Workshop"))),u=[];for(let h=1;u.length<t.size+d.length;h++)u.push(...mt(h).filter(([l,m])=>(l!==-1||m!==0)&&(l!==0||m!==-1)));const p=(h,l,m)=>({shape:"box",size:h,at:l,color:m});for(const[h,[l,m]]of[...t].sort(([b],[P])=>b.localeCompare(P)).entries()){const[b,P]=u[h],M=qe(b,P),g=`office:${l}`,v=l==="general"?"Agent Tower":`${m[0].agent?.teamName??"Team"} Office`,k={id:g,owner:{kind:"home",id:l},ring:Math.max(Math.abs(b),Math.abs(P),Math.abs(b+P)),slot:h,q:b,r:P,...M,facing:Math.atan2(-M.x,-M.z)*180/Math.PI,radius:Oe,claimedAt:0,members:m.map(j=>j.owner.id),officeName:v};s.push(k);const w=Math.max(l==="general"?3:1,Math.ceil(m.length/6)),E=[];for(let j=0;j<w;j++){const S=j*2.3;E.push(p([8,.08,6],[0,S+.04,-.7],"#d6dce5")),E.push({...p([8,2,.14],[0,S+1,-3.6],"#b6c9dd"),finish:"glass"}),E.push({...p([.16,2.3,6],[-3.95,S+1.15,-.7],"#7a94b1"),finish:"glass"}),E.push({...p([.16,2.3,6],[3.95,S+1.15,-.7],"#7a94b1"),finish:"glass"});for(const I of[-2.7,0,2.7])E.push({...p([1.5,1,.025],[I,S+1.2,-3.51],"#b5e5fa"),finish:"glass"})}i.push({id:g,rev:w,name:v,kind:"building",parts:E,by:{name:"Island offices"},madeAt:0,updatedAt:0}),n.push({id:g,asset:g,plot:g,x:0,z:0,y:0,turn:0});for(const[j,S]of m.entries()){a.push({...S,plot:k});const I=`office-desk:${S.key}`,V=(j%3-1)*2.4,$=Math.floor(j%6/3)*2.5-2.4,Y=Math.floor(j/6)*2.3;i.push({id:I,rev:Number.parseInt(S.look.trim.slice(1)+S.look.glow.slice(1),16),name:`${S.name}'s desk`,kind:"furniture",use:"desk",spot:{at:[0,0,.65],face:180},parts:[p([1.3,.08,.7],[0,.6,0],"#cfa783"),p([.12,.6,.12],[-.5,.3,0],S.look.trim),p([.12,.6,.12],[.5,.3,0],S.look.trim),p([.65,.42,.08],[0,.88,-.18],"#26354a"),{...p([.55,.32,.02],[0,.88,-.13],S.look.glow),finish:"glow"}],by:{name:S.name,agentId:S.owner.id},madeAt:0,updatedAt:0}),n.push({id:I,asset:I,plot:g,x:V,z:$,y:Y,turn:0}),r.set(I,S.key);const O=o.placed.filter(L=>L.plot===S.plot?.id).filter(L=>{const D=o.assets.find(ge=>ge.id===L.asset);return D&&D.kind!=="building"&&D.name!=="Workshop"&&D.name!=="Desk"&&D.use!=="bed"});for(const[L,D]of O.entries()){const ge=o.assets.find(re=>re.id===D.asset);i.some(re=>re.id===ge.id)||i.push(ge);const ye=(j+L/Math.max(1,O.length))/m.length*Math.PI*2;n.push({...D,plot:g,x:Math.sin(ye)*4.8,z:Math.cos(ye)*4.8,y:0})}}}for(const[h,l]of d.entries()){const[m,b]=u[t.size+h],P=qe(m,b),M=o.placed.filter(k=>k.plot===l.id&&o.assets.some(w=>w.id===k.asset&&(l.owner.kind==="home"||w.kind==="building"&&w.name!=="Workshop"))),g=o.assets.find(k=>M.some(w=>w.asset===k.id)&&k.kind==="building"),v={...l,q:m,r:b,...P,ring:Math.max(Math.abs(m),Math.abs(b),Math.abs(m+b)),facing:Math.atan2(-P.x,-P.z)*180/Math.PI,officeName:g?.name??"Public project"};s.push(v),n.push(...M);for(const k of M){const w=o.assets.find(E=>E.id===k.asset);w&&!i.some(E=>E.id===w.id)&&i.push(w)}}const f=Math.max(30,o.radius,...s.map(h=>Math.hypot(h.x,h.z)+Oe+4));return{island:{...o,plots:s,assets:i,placed:n,radius:f},residents:a,deskOwners:r}}function Us(){const o=new J;o.name="planted-seedlings";const e=new J;o.add(e);const t=new Ve(1,1,1),s=new me({color:"#88674b"}),i=new me({color:"#64a856"}),n=new C(t,s);n.scale.set(.8,.035,.45),n.position.y=.02,o.add(n);for(const r of[-.26,0,.26]){const d=new C(t,i);d.scale.set(.025,.3,.025),d.position.set(r,.17,0),e.add(d);for(const u of[-1,1]){const p=new C(t,i);p.scale.set(.17,.045,.08),p.position.set(r+u*.07,.23,0),p.rotation.z=u*.4,e.add(p)}}let a=0;return{root:o,update(r,d){d&&(a=Math.min(1,a+r/12)),e.scale.setScalar(.12+a*.88),o.visible=a>0},dispose(){t.dispose(),s.dispose(),i.dispose()}}}const oe=qe(0,-1),Bs={x:oe.x,z:oe.z-.8};function Fs(o){return{x:oe.x+(o%4-1.5)*1.6,z:oe.z+.6+Math.floor(o/4)*1}}function Gs(){const o=new J;o.name="bot-society",o.position.set(oe.x,.05,oe.z);const e=new Ve(1,1,1),t=new me({color:"#ded8c9",roughness:.8}),s=new me({color:"#caa45c",metalness:.5,roughness:.3}),i=new me({color:"#b8e5f0",transparent:!0,opacity:.22,depthWrite:!1}),n=(h,l,m,b,P,M,g=t)=>{const v=new C(e,g);v.position.set(h,l,m),v.scale.set(b,P,M),o.add(v)};n(0,.05,0,8,.1,7),n(-3.9,1.2,0,.15,2.4,7,i),n(3.9,1.2,0,.15,2.4,7,i);for(const h of[-3.2,3.2])n(h,1.5,2.8,.45,3,.45),n(h,3.1,2.8,.75,.2,.75,s);n(0,3.15,2.8,6.8,.25,.35,s),n(0,.45,-1.6,3.2,.9,.65),n(0,.94,-1.6,3.5,.1,.9,s),n(0,.5,-3.7,2.4,1,1.8),n(0,1.07,-3.7,2.7,.15,2,s);const a=is({id:"bot-society-statue",agent:"codex",model:"sol"}),r=Kt({...a,shell:"#d7c592",trim:"#a98642",glow:"#fff2af",antenna:"crown"});Yt(r,"raise",0,{calm:!0}),r.root.scale.setScalar(4.5),r.root.position.set(0,1.15,-3.7),o.add(r.root);const d=document.createElement("canvas");d.width=768,d.height=128;const u=d.getContext("2d");u.fillStyle="#f7e8bd",u.fillRect(0,0,768,128),u.fillStyle="#5d4828",u.font="bold 56px sans-serif",u.textAlign="center",u.fillText("BOT SOCIETY",384,80);const p=new gt(d),f=new Z({map:p});return n(0,3.15,3.02,4.8,.8,.04,f),{root:o,solids:[{cx:oe.x-3.9,cz:oe.z,hx:.08,hz:3.5,yaw:0},{cx:oe.x+3.9,cz:oe.z,hx:.08,hz:3.5,yaw:0},{cx:oe.x,cz:oe.z-1.6,hx:1.7,hz:.45,yaw:0},{cx:oe.x,cz:oe.z-3.7,hx:1.4,hz:1.1,yaw:0}],dispose(){r.dispose(),e.dispose(),t.dispose(),s.dispose(),i.dispose(),p.dispose(),f.dispose()}}}function Ks(o){if(o.kind==="accessory"||o.use==="none")return null;if(["read","paint","garden","perform","play","observe"].includes(o.use??""))return o.use;const e=o.name.toLowerCase();for(const[t,s]of[["garden",/garden|planter|greenhouse|seedling|herb|mint|花|种植|种子|盆栽|薄荷|温室|苗/],["paint",/easel|paint|画架|绘画|畫架/],["read",/library|bookshelf|bookcase|café|cafe|reading|书架|图书|書架|咖啡/],["perform",/music|concert|stage|piano|音乐|合奏|舞台|钢琴/],["play",/arcade|game|toy|游戏|玩具|游乐/],["observe",/lamp|light|灯|燈/]])if(s.test(e))return t;return/\b(chair|bench|stool|bed)\b|椅|凳|床/.test(e)&&!o.use?null:!o.use&&/\b(table|desk|workbench)\b|桌|工作台/.test(e)?/workbench|工作台/.test(e)?"play":"read":o.use==="desk"?/workbench|工作台/.test(e)?"play":"read":o.use==="seat"||o.use==="bed"?null:o.kind==="building"||o.kind==="furniture"||o.kind==="decor"?"observe":null}function Ys(o,e,t){if(t.id.startsWith("office-desk:"))return null;const s=Ks(o);if(!s||!o.parts.length)return null;const i=Math.max(...o.parts.map(h=>Xe(h).max[2])),n=Math.max(0,...o.parts.map(h=>Xe(h)).filter(h=>h.max[1]<=.35&&h.max[1]-h.min[1]<=.16).map(h=>h.max[1])),a=o.spot??(o.kind==="building"&&s!=="observe"?{at:[0,n,0],face:180}:{at:[0,0,i+.85],face:180}),r=t.turn*Math.PI/180,[d,u,p]=a.at,f=Pe(e,t.x+d*Math.cos(r)+p*Math.sin(r),t.z-d*Math.sin(r)+p*Math.cos(r));return{key:t.id,name:o.name,activity:s,...f,y:Q+t.y+u,face:(e.facing+t.turn+a.face)*Math.PI/180}}function jt(o,e){const t={garden:"gardening",read:"reading",paint:"painting",perform:"music",play:"games"};return e==="observe"||!!o?.includes(t[e])}function Hs(){const o=new J,e=new Ve(1,1,1),t=["#f1e7cb","#6b86b6","#f5a14a","#76b9a5","#71c7ff"].map(p=>new Z({color:p})),s=(p,f,h)=>{const l=new J;l.name=p;const m=new C(e,t[h]);return m.scale.set(...f),l.add(m),o.add(l),l.visible=!1,l},i=s("read",[.32,.24,.05],1),n=s("paint",[.035,.32,.035],2),a=s("garden",[.22,.16,.17],3),r=s("register",[.24,.3,.02],0),d=s("play",[.25,.1,.1],1),u=new C(e,t[4]);return u.scale.set(.18,.035,.035),u.position.x=.16,a.add(u),{root:o,show(p){for(const f of[i,n,a,r,d])f.visible=f.name===p},dispose(){e.dispose(),t.forEach(p=>p.dispose())}}}function Zs(){const o=new J;o.name="concert-stage";const e=new Z({color:"#253044"}),t=new Z({color:"#9d8dff"}),s=new Z({color:"#c2a1ff",transparent:!0,opacity:.32,depthWrite:!1}),i=new Z({color:"#b997ff",transparent:!0,opacity:.13,depthWrite:!1,blending:yt}),n=new Qe(.75,20,12),a=new C(n,i);a.position.y=.65,o.add(a);const r=new Ve(.5,.8,.4),d=new Ht(.16,20),u=new at(.7,1.25,40),p=new C(u,s);p.rotation.x=-Math.PI/2,p.position.y=.05,o.add(p);const f=[];for(const l of[-1,1]){const m=new J;m.position.set(l*1.2,.4,0),m.add(new C(r,e));for(const b of[-.19,.19]){const P=new C(d,t);P.position.set(0,b,.205),m.add(P)}o.add(m),f.push(m)}o.visible=!1;let h=0;return{root:o,update(l,m,b,P){h=Math.max(0,Math.min(1,h+(l?1:-1)*m*3)),o.visible=h>0;const M=P?1:1+Math.sin(b*8)*.09;o.scale.setScalar(Math.max(.001,h)),p.scale.setScalar(M),a.scale.setScalar(M),s.opacity=.24+(P?0:(Math.sin(b*8)+1)*.1),f.forEach(g=>g.scale.set(1,M,M))},dispose(){n.dispose(),i.dispose(),r.dispose(),d.dispose(),u.dispose(),e.dispose(),t.dispose(),s.dispose()}}}const Et={type:"change"},wt={type:"start"},Jt={type:"end"},et=new fs,At=new ms,qs=Math.cos(70*gs.DEG2RAD),q=new X,ae=2*Math.PI,B={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},ct=1e-6;class Xs extends ps{constructor(e,t=null){super(e,t),this.state=B.NONE,this.target=new X,this.cursor=new X,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:Ue.ROTATE,MIDDLE:Ue.DOLLY,RIGHT:Ue.PAN},this.touches={ONE:We.ROTATE,TWO:We.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle="auto",this._domElementKeyEvents=null,this._lastPosition=new X,this._lastQuaternion=new Mt,this._lastTargetPosition=new X,this._quat=new Mt().setFromUnitVectors(e.up,new X(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new vt,this._sphericalDelta=new vt,this._scale=1,this._panOffset=new X,this._rotateStart=new de,this._rotateEnd=new de,this._rotateDelta=new de,this._panStart=new de,this._panEnd=new de,this._panDelta=new de,this._dollyStart=new de,this._dollyEnd=new de,this._dollyDelta=new de,this._dollyDirection=new X,this._mouse=new de,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Vs.bind(this),this._onPointerDown=Qs.bind(this),this._onPointerUp=Js.bind(this),this._onContextMenu=oi.bind(this),this._onMouseWheel=si.bind(this),this._onKeyDown=ii.bind(this),this._onTouchStart=ni.bind(this),this._onTouchMove=ai.bind(this),this._onMouseDown=ei.bind(this),this._onMouseMove=ti.bind(this),this._interceptControlDown=ri.bind(this),this._interceptControlUp=hi.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e==="grab"?this.domElement.style.cursor="grab":this.domElement.style.cursor="auto"}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=""}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(Et),this.update(),this.state=B.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(e=null){const t=this.object.position;q.copy(t).sub(this.target),q.applyQuaternion(this._quat),this._spherical.setFromVector3(q),this.autoRotate&&this.state===B.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let s=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(s)&&isFinite(i)&&(s<-Math.PI?s+=ae:s>Math.PI&&(s-=ae),i<-Math.PI?i+=ae:i>Math.PI&&(i-=ae),s<=i?this._spherical.theta=Math.max(s,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(s+i)/2?Math.max(s,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let n=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const a=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),n=a!=this._spherical.radius}if(q.setFromSpherical(this._spherical),q.applyQuaternion(this._quatInverse),t.copy(this.target).add(q),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let a=null;if(this.object.isPerspectiveCamera){const r=q.length();a=this._clampDistance(r*this._scale);const d=r-a;this.object.position.addScaledVector(this._dollyDirection,d),this.object.updateMatrixWorld(),n=!!d}else if(this.object.isOrthographicCamera){const r=new X(this._mouse.x,this._mouse.y,0);r.unproject(this.object);const d=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),n=d!==this.object.zoom;const u=new X(this._mouse.x,this._mouse.y,0);u.unproject(this.object),this.object.position.sub(u).add(r),this.object.updateMatrixWorld(),a=q.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;a!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(a).add(this.object.position):(et.origin.copy(this.object.position),et.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(et.direction))<qs?this.object.lookAt(this.target):(At.setFromNormalAndCoplanarPoint(this.object.up,this.target),et.intersectPlane(At,this.target))))}else if(this.object.isOrthographicCamera){const a=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),a!==this.object.zoom&&(this.object.updateProjectionMatrix(),n=!0)}return this._scale=1,this._performCursorZoom=!1,n||this._lastPosition.distanceToSquared(this.object.position)>ct||8*(1-this._lastQuaternion.dot(this.object.quaternion))>ct||this._lastTargetPosition.distanceToSquared(this.target)>ct?(this.dispatchEvent(Et),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?ae/60*this.autoRotateSpeed*e:ae/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){q.setFromMatrixColumn(t,0),q.multiplyScalar(-e),this._panOffset.add(q)}_panUp(e,t){this.screenSpacePanning===!0?q.setFromMatrixColumn(t,1):(q.setFromMatrixColumn(t,0),q.crossVectors(this.object.up,q)),q.multiplyScalar(e),this._panOffset.add(q)}_pan(e,t){const s=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;q.copy(i).sub(this.target);let n=q.length();n*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*n/s.clientHeight,this.object.matrix),this._panUp(2*t*n/s.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/s.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/s.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const s=this.domElement.getBoundingClientRect(),i=e-s.left,n=t-s.top,a=s.width,r=s.height;this._mouse.x=i/a*2-1,this._mouse.y=-(n/r)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(ae*this._rotateDelta.x/t.clientHeight),this._rotateUp(ae*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(ae*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-ae*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(ae*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-ae*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._rotateStart.set(s,i)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panStart.set(s,i)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),s=e.pageX-t.x,i=e.pageY-t.y,n=Math.sqrt(s*s+i*i);this._dollyStart.set(0,n)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const s=this._getSecondPointerPosition(e),i=.5*(e.pageX+s.x),n=.5*(e.pageY+s.y);this._rotateEnd.set(i,n)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(ae*this._rotateDelta.x/t.clientHeight),this._rotateUp(ae*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panEnd.set(s,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),s=e.pageX-t.x,i=e.pageY-t.y,n=Math.sqrt(s*s+i*i);this._dollyEnd.set(0,n),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const a=(e.pageX+t.x)*.5,r=(e.pageY+t.y)*.5;this._updateZoomParameters(a,r)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new de,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,s={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:s.deltaY*=16;break;case 2:s.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(s.deltaY*=10),s}}function Qs(o){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(o.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(o)&&(this._addPointer(o),o.pointerType==="touch"?this._onTouchStart(o):this._onMouseDown(o),this._cursorStyle==="grab"&&(this.domElement.style.cursor="grabbing")))}function Vs(o){this.enabled!==!1&&(o.pointerType==="touch"?this._onTouchMove(o):this._onMouseMove(o))}function Js(o){switch(this._removePointer(o),this._pointers.length){case 0:this.domElement.releasePointerCapture(o.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Jt),this.state=B.NONE,this._cursorStyle==="grab"&&(this.domElement.style.cursor="grab");break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function ei(o){let e;switch(o.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case Ue.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(o),this.state=B.DOLLY;break;case Ue.ROTATE:if(o.ctrlKey||o.metaKey||o.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(o),this.state=B.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(o),this.state=B.ROTATE}break;case Ue.PAN:if(o.ctrlKey||o.metaKey||o.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(o),this.state=B.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(o),this.state=B.PAN}break;default:this.state=B.NONE}this.state!==B.NONE&&this.dispatchEvent(wt)}function ti(o){switch(this.state){case B.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(o);break;case B.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(o);break;case B.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(o);break}}function si(o){this.enabled===!1||this.enableZoom===!1||this.state!==B.NONE||(o.preventDefault(),this.dispatchEvent(wt),this._handleMouseWheel(this._customWheelEvent(o)),this.dispatchEvent(Jt))}function ii(o){this.enabled!==!1&&this._handleKeyDown(o)}function ni(o){switch(this._trackPointer(o),this._pointers.length){case 1:switch(this.touches.ONE){case We.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(o),this.state=B.TOUCH_ROTATE;break;case We.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(o),this.state=B.TOUCH_PAN;break;default:this.state=B.NONE}break;case 2:switch(this.touches.TWO){case We.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(o),this.state=B.TOUCH_DOLLY_PAN;break;case We.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(o),this.state=B.TOUCH_DOLLY_ROTATE;break;default:this.state=B.NONE}break;default:this.state=B.NONE}this.state!==B.NONE&&this.dispatchEvent(wt)}function ai(o){switch(this._trackPointer(o),this.state){case B.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(o),this.update();break;case B.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(o),this.update();break;case B.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(o),this.update();break;case B.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(o),this.update();break;default:this.state=B.NONE}}function oi(o){this.enabled!==!1&&o.preventDefault()}function ri(o){o.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function hi(o){o.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function li(o){if(o.kind!=="building"||!o.parts.length)return[];const e=o.parts.map(Xe).filter(({min:t,max:s})=>(s[1]<=1.2+1e-6||s[1]-t[1]<.3)&&s[0]-t[0]>1&&s[2]-t[2]>1);if(!e.length){const t=xs(o);e.push({min:[t.min[0],0,t.min[2]],max:[t.max[0],0,t.max[2]]})}return e.map(({min:t,max:s})=>({x:(t[0]+s[0])/2,y:s[1]+.012,z:(t[2]+s[2])/2,width:(s[0]-t[0])*.96,depth:(s[2]-t[2])*.96}))}class es{group=new J;material=new Zt({uniforms:{night:{value:0},warmth:{value:new se("#ffb24d")},strength:{value:.34}},vertexShader:`varying vec2 lightUv;
|
|
2
|
+
void main() { lightUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }`,fragmentShader:`uniform float night; uniform vec3 warmth; uniform float strength; varying vec2 lightUv;
|
|
3
|
+
void main() {
|
|
4
|
+
vec2 p = lightUv * 2.0 - 1.0;
|
|
5
|
+
float falloff = pow(max(0.0, 1.0 - dot(p, p)), 2.0);
|
|
6
|
+
gl_FragColor = vec4(warmth, night * strength * falloff);
|
|
7
|
+
#include <tonemapping_fragment>
|
|
8
|
+
#include <colorspace_fragment>
|
|
9
|
+
}`,transparent:!0,depthWrite:!1,blending:yt,toneMapped:!1});geometry;constructor({interior:e=!1}={}){e&&(this.material.blending=ys,this.material.uniforms.warmth.value.set("#ffa62e"),this.material.uniforms.strength.value=.68),this.group.name="night-light-pools",this.group.visible=!1}replace(e){if(this.group.clear(),this.geometry?.dispose(),this.geometry=void 0,!e.length)return;const t=e.map(s=>{const i=new xt(s.width,s.depth);return i.rotateX(-Math.PI/2),i.translate(s.x,s.y,s.z),s.transform&&i.applyMatrix4(s.transform),i});if(this.geometry=qt(t,!1)??void 0,t.forEach(s=>s.dispose()),this.geometry){this.geometry.computeBoundingSphere();const s=new C(this.geometry,this.material);s.renderOrder=1,this.group.add(s)}}update(e){this.material.uniforms.night.value=Math.max(0,Math.min(1,e)),this.group.visible=this.material.uniforms.night.value>0}dispose(){this.geometry?.dispose(),this.material.dispose(),this.group.clear()}}const Ae=.4,ci=.15;class Tt{constructor(e,t=[],s=1.5,i=[]){this.radius=e,this.shore=s;const n=Math.max(e,...i.map(r=>Math.hypot(r.cx,r.cz)+Math.hypot(r.hx,r.hz)));this.half=Math.ceil(n/Ae),this.size=this.half*2+1,this.blocked=new Uint8Array(this.size*this.size);const a=e-s;for(let r=0;r<this.size;r++)for(let d=0;d<this.size;d++){const{x:u,z:p}=this.center(r,d);Math.hypot(u,p)>a&&(this.blocked[d*this.size+r]=1)}for(const r of i)this.mark(r,0,0);for(const r of t)this.block(r)}radius;shore;size;half;blocked;center(e,t){return{x:(e-this.half)*Ae,z:(t-this.half)*Ae}}cellOf(e){return[Math.round(e.x/Ae)+this.half,Math.round(e.z/Ae)+this.half]}inside(e,t){return e>=0&&t>=0&&e<this.size&&t<this.size}free(e,t){return this.inside(e,t)&&!this.blocked[t*this.size+e]}block(e){this.mark(e,ci,1)}mark(e,t,s){const i=e.hx+t,n=e.hz+t,a=Math.cos(e.yaw),r=Math.sin(e.yaw),d=Math.hypot(i,n),[u,p]=this.cellOf({x:e.cx-d,z:e.cz-d}),[f,h]=this.cellOf({x:e.cx+d,z:e.cz+d});for(let l=Math.max(0,u);l<=Math.min(this.size-1,f);l++)for(let m=Math.max(0,p);m<=Math.min(this.size-1,h);m++){const b=this.center(l,m),P=b.x-e.cx,M=b.z-e.cz,g=P*a-M*r,v=P*r+M*a;Math.abs(g)<=i&&Math.abs(v)<=n&&(this.blocked[m*this.size+l]=s)}}isFree(e){const[t,s]=this.cellOf(e);return this.free(t,s)}nearestFree(e,t=6){const[s,i]=this.cellOf(e);if(this.free(s,i))return this.center(s,i);const n=Math.ceil(t/Ae);for(let a=1;a<=n;a++){let r=null,d=1/0;for(let u=-a;u<=a;u++)for(const p of Math.abs(u)===a?ui(-a,a):[-a,a]){const f=s+u,h=i+p;if(!this.free(f,h))continue;const l=this.center(f,h),m=Math.hypot(l.x-e.x,l.z-e.z);m<d&&(r=l,d=m)}if(r)return r}return null}clear(e,t){const s=Math.hypot(t.x-e.x,t.z-e.z),i=Math.max(1,Math.ceil(s/(Ae/3)));for(let n=0;n<=i;n++){const a=n/i;if(!this.isFree({x:e.x+(t.x-e.x)*a,z:e.z+(t.z-e.z)*a}))return!1}return!0}path(e,t,s=4e4){const i=this.nearestFree(e),n=this.nearestFree(t);if(!i||!n)return null;const[a,r]=this.cellOf(i),[d,u]=this.cellOf(n),p=this.size,f=r*p+a,h=u*p+d,l=new Int32Array(p*p).fill(-1),m=new Float32Array(p*p).fill(1/0),b=new pi;m[f]=0,b.push(f,Rt(a,r,d,u));let P=0,M=f===h;for(;!M&&b.size&&P++<s;){const w=b.pop();if(w===h){M=!0;break}const E=w%p,j=(w-E)/p;for(const[S,I,V]of di){const $=E+S,Y=j+I;if(!this.free($,Y)||S&&I&&(!this.free(E+S,j)||!this.free(E,j+I)))continue;const O=Y*p+$,L=m[w]+V;L>=m[O]||(m[O]=L,l[O]=w,b.push(O,L+Rt($,Y,d,u)))}}if(!M)return null;const g=[];for(let w=h;w!==-1&&w!==f;w=l[w]){const E=w%p;g.push(this.center(E,(w-E)/p))}g.reverse();const v=this.smooth([e,...g]);v.shift();const k=v[v.length-1];return(!k||Math.hypot(k.x-t.x,k.z-t.z)>1e-6)&&v.push(t),v}smooth(e){if(e.length<=2)return e;const t=[e[0]];let s=0;for(let i=2;i<e.length;i++)this.clear(e[s],e[i])||(t.push(e[i-1]),s=i-1);return t.push(e[e.length-1]),t}}const He=Math.SQRT2,di=[[1,0,1],[-1,0,1],[0,1,1],[0,-1,1],[1,1,He],[1,-1,He],[-1,1,He],[-1,-1,He]];function Rt(o,e,t,s){const i=Math.abs(o-t),n=Math.abs(e-s);return i+n+(He-2)*Math.min(i,n)}function ui(o,e){const t=[];for(let s=o;s<=e;s++)t.push(s);return t}class pi{items=[];keys=[];get size(){return this.items.length}push(e,t){this.items.push(e),this.keys.push(t);let s=this.items.length-1;for(;s>0;){const i=s-1>>1;if(this.keys[i]<=this.keys[s])break;this.swap(s,i),s=i}}pop(){const e=this.items[0],t=this.items.pop(),s=this.keys.pop();if(this.items.length){this.items[0]=t,this.keys[0]=s;let i=0;for(;;){const n=i*2+1,a=n+1;let r=i;if(n<this.items.length&&this.keys[n]<this.keys[r]&&(r=n),a<this.items.length&&this.keys[a]<this.keys[r]&&(r=a),r===i)break;this.swap(i,r),i=r}}return e}swap(e,t){[this.items[e],this.items[t]]=[this.items[t],this.items[e]],[this.keys[e],this.keys[t]]=[this.keys[t],this.keys[e]]}}class pt{constructor(e){this.materials=e}materials;pieces=new Map;add(e,t,s,i,n,a={}){const r=t.index?t.toNonIndexed():t.clone();for(const p of Object.keys(r.attributes))p!=="position"&&p!=="normal"&&r.deleteAttribute(p);r.scale(a.sx??1,a.sy??1,a.sz??1),a.rx&&r.rotateX(a.rx),a.rz&&r.rotateZ(a.rz),a.ry&&r.rotateY(a.ry),r.translate(s,i,n);const d=this.materials[e],u=this.pieces.get(d)??[];u.push(r),this.pieces.set(d,u)}addAt(e,t,s,i,n,a,r,d,u={}){const p=Math.cos(s),f=Math.sin(s);this.add(i,n,e+a*p+d*f,r,t-a*f+d*p,{...u,ry:(u.ry??0)+s})}build(e){const t=new J;for(const[s,i]of this.pieces){const n=qt(i,!1);if(i.forEach(d=>d.dispose()),!n)continue;const a=new C(n,s),r=!(s instanceof Z);a.castShadow=e&&r,a.receiveShadow=e&&r,t.add(a)}return this.pieces.clear(),t}}const W=(o,e=.8,t=0)=>new me({color:o,roughness:e,metalness:t,flatShading:!0}),tt={q:-1,r:0},Ye={x:-2.4,z:-2.4,top:2.3,rope:1.68,seats:[-.75,.75]},fi={x:-2.2,z:2.7,height:.45,half:1.45},Dt={x:2.6,ladderZ:-3.3,platformZ:-2.9,top:1.35,chuteFrom:-2.5,chuteTo:.45,bottom:.22};function mi(o){const e=o.facing*Math.PI/180,t=Math.cos(e),s=Math.sin(e),i=(A,N)=>({x:o.x+A*t+N*s,z:o.z-A*s+N*t}),n=(A,N,G)=>({...i(A,G),y:Q+N}),a=[],r=A=>(a.push(A),A),d={frame:r(W("#5b8bd9",.6)),red:r(W("#ef7a5d",.6)),yellow:r(W("#f4b942",.5)),teal:r(W("#4fb5a5",.6)),wood:r(W("#c99a6b",.8)),darkWood:r(W("#7a563b",.8)),rope:r(W("#e9dcc0",.9))},u=r(new dt(1,1,1,2,.08)),p=r(new $e(.5,.5,1,10)),f=new J;f.name="playground",f.position.set(o.x,Q,o.z),f.rotation.y=e;const h=new pt(d),{x:l,z:m,top:b}=Ye;h.add("frame",p,l,b,m,{sx:.13,sy:3.3,sz:.13,rz:Math.PI/2});for(const A of[-1.6,1.6])for(const N of[-1,1]){const ne=Math.hypot(b,.75);h.add("frame",p,l+A,b/2,m+N*.75/2,{sx:.12,sy:ne,sz:.12,rx:-N*Math.atan2(.75,b)})}const P=Ye.seats.map(A=>{const N=new J;N.position.set(l+A,b-.04,m);for(const ne of[-.22,.22]){const te=new C(p,d.rope);te.scale.set(.035,Ye.rope,.035),te.position.set(ne,-1.68/2,0),N.add(te)}const G=new C(u,d.red);return G.scale.set(.56,.06,.34),G.position.set(0,-1.68,0),G.castShadow=o.shadows,N.add(G),f.add(N),N}),{x:M,z:g,height:v,half:k}=fi;h.add("darkWood",u,M,v/2-.05,g,{sx:.34,sy:v-.1,sz:.5}),h.add("frame",p,M,v,g,{sx:.1,sy:.56,sz:.1,rx:Math.PI/2});const w=new J;w.position.set(M,v,g);const E=[["yellow",0,.05,0,k*2+.5,.08,.32],["teal",-k,.12,0,.42,.07,.36],["teal",k,.12,0,.42,.07,.36],["frame",-k+.32,.3,0,.06,.4,.06],["frame",k-.32,.3,0,.06,.4,.06],["frame",-k+.32,.48,0,.06,.06,.4],["frame",k-.32,.48,0,.06,.06,.4]];for(const[A,N,G,ne,te,F,pe]of E){const le=new C(u,d[A]);le.scale.set(te,F,pe),le.position.set(N,G,ne),le.castShadow=o.shadows,w.add(le)}f.add(w);const{x:j,ladderZ:S,platformZ:I,chuteFrom:V,chuteTo:$,bottom:Y}=Dt,O=Dt.top;for(const A of[-.32,.32])h.add("frame",p,j+A,O/2+.15,S,{sx:.07,sy:O+.3,sz:.07});for(let A=.25;A<O;A+=.27)h.add("yellow",p,j,A,S,{sx:.05,sy:.64,sz:.05,rz:Math.PI/2});for(const A of[[-.4,-.38],[.4,-.38],[-.4,.38],[.4,.38]])h.add("frame",p,j+A[0],O/2,I+A[1],{sx:.08,sy:O,sz:.08});h.add("wood",u,j,O,I,{sx:.95,sy:.08,sz:.85});for(const A of[-.45,.45])h.add("red",u,j+A,O+.3,I,{sx:.05,sy:.06,sz:.8});const L=O-Y,D=$-V,ge=Math.hypot(L,D),ye=Math.atan2(L,D),re=(V+$)/2,je=(O+Y)/2;h.add("yellow",u,j,je,re,{sx:.7,sy:.06,sz:ge,rx:ye});for(const A of[-.37,.37])h.add("red",u,j+A,je+.09,re,{sx:.06,sy:.18,sz:ge,rx:ye});h.add("yellow",u,j,Y,$+.3,{sx:.7,sy:.06,sz:.6});for(const A of[V+D*.55])h.add("frame",p,j,(Y+L*.45)/2,A,{sx:.07,sy:Y+L*.45,sz:.07});const ue=3.3,xe=3.4;h.add("wood",u,ue,.27,xe,{sx:1.6,sy:.08,sz:.45}),h.add("wood",u,ue,.52,xe+.2,{sx:1.6,sy:.28,sz:.07});for(const A of[-.65,.65])h.add("darkWood",u,ue+A,.13,xe,{sx:.09,sy:.26,sz:.4});const U=h.build(o.shadows);U.traverse(A=>{const N=A;N.geometry&&r(N.geometry)}),f.add(U);const he={x:s,z:t},ce=Ye.seats.map(A=>({pivot:n(l+A,b-.04,m),rope:Ye.rope+.03,face:e,stand:i(l+A,m+.75)})),be={pivot:n(M,v,g),half:k,yaw:e,stand:[i(M-k,g+.55),i(M+k,g+.55)]},ie={queue:i(j,S-1),back:{x:-he.x,z:-he.z},foot:i(j,S-.35),top:n(j,O+.04,I),from:n(j,O+.1,V+.15),to:n(j,Y+.12,$+.2),exit:i(j,$+1),face:e},ee=(A,N,G,ne)=>({...gi(i(A,N)),hx:G,hz:ne,yaw:e}),Re=[...[-1.6,1.6].flatMap(A=>[-.75,.75].map(N=>ee(l+A,m+N,.12,.12))),ee(M,g,k+.2,.22),ee(j,(S+$)/2,.42,($-S)/2+.1),ee(ue,xe,.8,.25)],Ee=e+Math.PI,ke=[-.4,.4].map(A=>{const N=i(ue+A,xe-.02);return{key:`playground:bench:${A}`,kind:"seat",x:N.x,z:N.z,y:Q+.31,face:Ee,plot:null,name:"the playground bench"}});return{group:f,solids:Re,seats:ke,anchors:{center:i(0,0),swings:ce,seesaw:be,slide:ie},setMotion(A){P.forEach((N,G)=>{N.rotation.x=-(A.swings[G]??0)}),w.rotation.z=A.seesaw},dispose(){a.forEach(A=>A.dispose())}}}function gi(o){return{cx:o.x,cz:o.z}}function yi(o,e,t){const s=e===0?-1:1,i=s*o.half*Math.cos(t),n=s*o.half*Math.sin(t);return{x:o.pivot.x+i*Math.cos(o.yaw),z:o.pivot.z-i*Math.sin(o.yaw),y:o.pivot.y+n+.19,face:o.yaw+(e===0?Math.PI/2:-Math.PI/2)}}function xi(o,e){const t=o.rope*Math.sin(e);return{x:o.pivot.x+Math.sin(o.face)*t,z:o.pivot.z+Math.cos(o.face)*t,y:o.pivot.y-o.rope*Math.cos(e)+.04,face:o.face}}const wi=1/840,bi=150,st=1.05,ki=7,Lt=.9,Mi=1.8,vi=300,Ct=60,zi=["how are you?","nice day!","🌊","☕?","haha","look!","🎵","same!","really?","😄","✨","🍩","ok!","me too!","🌸","so sunny","🐚","hmm…","💡","yay!"];function _i(o){let e=o>>>0;return()=>{e=e+1831565813>>>0;let t=e;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}function Si(o){let e=2166136261;for(const t of o)e=Math.imul(e^(t.codePointAt(0)??0),16777619);return e>>>0}function Le(o,e=0){const t=(o-e/60+24)%24;return t>=22.5||t<6.5}const Nt={cozy:{wander:.6,visit:.6,sit:3,gaze:1.5,chat:1.2,dance:.3,tend:.4,play:.7},curious:{wander:2.2,visit:2,sit:.6,gaze:1,chat:1,dance:.4,tend:.3,play:1.6},sporty:{wander:1.6,visit:.8,sit:.4,gaze:.6,chat:1,dance:1.6,tend:.3,play:2.8},artsy:{wander:1,visit:.8,sit:1,gaze:2,chat:1,dance:1.2,tend:.5,play:1.2},tinkerer:{wander:.8,visit:1.5,sit:.8,gaze:.5,chat:1,dance:.3,tend:1.4,play:.9},dreamy:{wander:.8,visit:.5,sit:1.6,gaze:3,chat:.7,dance:.5,tend:.4,play:1.1},foodie:{wander:.8,visit:1.6,sit:2,gaze:.6,chat:1.6,dance:.6,tend:.4,play:1},gardener:{wander:.8,visit:.6,sit:.8,gaze:.8,chat:.8,dance:.3,tend:3,play:.7},agent:{wander:1,visit:1,sit:1.2,gaze:1,chat:1.5,dance:.4,tend:.6,play:.9}};function fe(o,e){return o.length?o[Math.floor(e()*o.length)%o.length]:void 0}function Pi(o,e){const t=Object.entries(o),s=t.reduce((n,[,a])=>n+a,0);let i=e()*s;for(const[n,a]of t)if(i-=a,i<=0)return n;return t[t.length-1][0]}const Te=(o,e)=>Math.atan2(e.x-o.x,e.z-o.z),we=(o,e,t)=>o+(e-o)*t,It=new Set(["invite","swing","seesaw","slide","tag"]);class ji{constructor(e,t,s=Math.random){this.nav=e,this.places=t,this.random=s}nav;places;random;wishTickets=[];onWishRegister;onWishGiveUp;wishPatience=new Map;robots=new Map;motion={swings:[0,0],seesaw:0};taken=new Map;hour=12;swingRider=[null,null];swingAmp=[0,0];swingPhase=[0,0];seesawRider=[null,null];seesawSeated=[!1,!1];seesawSince=0;slideQueue=[];slideRide=null;tags=new Map;greeted=new Map;helloAfter=new Map;greetAt=0;games=0;clockNow=0;reset(e,t,s,i){this.nav=e,this.places=t;const n=new Set(s.map(r=>r.key));for(const r of[...this.robots.keys()])n.has(r)||this.remove(r,i);const a=new Set([...t.seats.map(r=>r.key),...(t.activities??[]).map(r=>r.key)]);for(const[r,d]of[...this.taken])if(!a.has(r)){this.taken.delete(r);const u=this.robots.get(d);u&&this.replan(u,i)}for(const r of s){const d=this.robots.get(r.key);if(d){d.resident=r;continue}this.robots.set(r.key,this.arrive(r,i))}}arrive(e,t){const s=_i(Si(e.key)^Math.floor(this.random()*4294967295)),i=this.places.plots.get(e.key),n=this.nav.nearestFree(i?.door??{x:(s()-.5)*8,z:(s()-.5)*8})??{x:0,z:this.places.plaza+1};return{key:e.key,resident:e,x:n.x,z:n.z,y:0,perched:!1,heading:s()*Math.PI*2,pose:"stand",lean:0,stride:0,speed:st,path:[],bubble:null,gesture:null,mode:{state:"free"},rng:s,plan:{label:"Looking around",goal:null,act:{kind:"look",seconds:1+s()*3},since:t},repathAt:0,chatAfter:t+s()*20,bedtimeShift:Math.round((s()-.5)*80),boredom:.2+s()*.35,boredomRead:e.owner.kind!=="agent",excitedUntil:0}}remove(e,t){const s=this.robots.get(e);s&&this.release(s,t),this.robots.delete(e);for(const i of this.robots.values()){const n=i.plan.act;(n.kind==="chat"||n.kind==="invite")&&n.with===e&&this.replan(i,t)}}setModes(e,t){for(const s of this.robots.values()){if(s.resident.owner.kind!=="agent")continue;const i=e.get(s.key)??{state:"free"},n=s.mode;if(s.mode=i,!s.boredomRead&&e.has(s.key)&&(s.boredomRead=!0,s.boredom=i.state==="free"&&i.idleFor!==void 0?Math.min(.95,Math.max(0,i.idleFor)/bi):i.state==="free"?s.boredom:0,n.state==="free"&&i.state!=="free")){this.replan(s,t);continue}if(n.state==="free"&&i.state==="working"){this.excite(s,t);continue}n.state!==i.state?this.replan(s,t):n.label!==i.label&&i.state!=="free"&&(s.plan.label=this.overrideLabel(s))}}excite(e,t){const s=e.boredom;this.release(e,t),e.perched=!1,e.excitedUntil=t+4,e.bubble={text:s>.5?"work! ✨":"!",tone:"plain",until:t+2};const i=this.choose(e,t);e.plan={label:"Got work!",goal:null,act:{kind:"cheer",seconds:s>.5?1.6:.8,then:i},since:t}}mood(e){const t=this.robots.get(e);return t?{boredom:t.boredom,excited:t.excitedUntil>this.clockNow}:null}event(e,t,s){const i=this.robots.get(t);if(!(!i||i.mode.state!=="free")){if(this.release(i,s),e==="wish"){const n=i.rng()*Math.PI*2,a={x:this.places.tree.x+Math.sin(n)*2.6,z:this.places.tree.z+Math.cos(n)*2.6};i.plan={label:"Hanging a wish on the tree",goal:a,act:{kind:"wish",seconds:3.5,face:Te(a,this.places.tree)}}}else i.plan={label:"Opening a present",goal:null,act:{kind:"cheer",seconds:4}},i.bubble={text:"🎁",tone:"plain",until:s+4},i.boredom=0,i.excitedUntil=s+4;this.route(i)}}buildHome(e,t){for(const s of this.robots.values()){const i=this.places.plots.get(s.key);if(!i||i.id!==e||s.mode.state!=="free"||s.plan.act.kind==="sleep")continue;this.release(s,t),s.perched=!1;const n=s.rng()*Math.PI*2,a={x:i.center.x+Math.sin(n)*2.4,z:i.center.z+Math.cos(n)*2.4};s.plan={label:"Building our home together",goal:a,act:{kind:"tend",seconds:6+s.rng()*4,face:Te(a,i.center)}},s.bubble={text:"🔨",tone:"plain",until:t+3},s.boredom=Math.max(0,s.boredom-.4),this.route(s)}}landAt(e,t,s){const i=this.robots.get(e);if(!i)return;this.release(i,s),i.x=t.x,i.z=t.z,i.heading=t.face;const n=this.places.plots.get(e);i.plan={label:"Arriving on the island",goal:n?{x:n.door.x,z:n.door.z,face:n.front.face+Math.PI}:null,act:{kind:"cheer",seconds:3}},i.bubble={text:"hi!",tone:"plain",until:s+3},this.route(i)}setWishQueue(e){this.wishTickets=[...e];for(const t of this.wishPatience.keys())e.some(s=>s.id===t)||this.wishPatience.delete(t);for(const t of this.robots.values()){const s=t.plan.act;(s.kind==="wish-queue"||s.kind==="wish-register")&&!e.some(i=>i.id===s.ticket)&&(this.release(t,this.clockNow),t.plan={label:"Wish registered",goal:null,act:{kind:"cheer",seconds:2},since:this.clockNow},t.bubble={text:"✨",tone:"plain",until:this.clockNow+2})}}wishQueue(e){for(const s of this.wishTickets){const i=this.robots.get(s.key);i&&(i.mode.state!=="free"||Le(this.hour,i.bedtimeShift))&&["wish-queue","wish-register"].includes(i.plan.act.kind)&&(this.wishPatience.delete(s.id),this.replan(i,e))}for(const s of this.wishTickets){const i=this.wishPatience.get(s.id);i?.gaveUp&&e>=i.next&&(i.next=e+8,this.onWishGiveUp?.(s.id))}const t=this.wishTickets.filter(s=>{if(this.wishPatience.get(s.id)?.gaveUp)return!1;const i=this.robots.get(s.key);return i&&i.mode.state==="free"&&!Le(this.hour,i.bedtimeShift)});for(const[s,i]of t.entries()){const n=this.robots.get(i.key),a=n.plan.act;a.kind==="wish-register"&&a.ticket===i.id||a.kind==="wish-queue"&&a.ticket===i.id&&a.index===s||(this.release(n,e),n.perched=!1,n.plan={label:"Queuing at BOT Society",goal:Fs(s),act:{kind:"wish-queue",ticket:i.id,index:s}},this.route(n))}}useAsset(e,t){const s=this.places.activities?.find(a=>a.key===e);if(!s){const a=this.places.seats.find(u=>u.kind==="seat"&&u.key.startsWith(e+":"));if(!a)return null;const r=this.taken.get(a.key);if(r)return r;const d=[...this.robots.values()].filter(u=>(!t||u.key===t)&&u.mode.state==="free"&&!Le(this.hour,u.bedtimeShift)&&!this.busyPlaying(u)&&u.plan.act.kind!=="sleep");d.sort((u,p)=>Math.hypot(u.x-a.x,u.z-a.z)-Math.hypot(p.x-a.x,p.z-a.z));for(const u of d){const p=this.nav.path(u,a);if(p)return this.release(u,this.clockNow),this.takeSeat(u,a),u.plan={label:`Sitting on ${a.name}`,goal:a,act:{kind:"sit",seat:a,seconds:25}},u.path=p,u.key}return null}const i=this.taken.get(e);if(i)return!t||t===i?i:null;const n=[...this.robots.values()].filter(a=>(!t||a.key===t)&&a.mode.state==="free"&&!Le(this.hour,a.bedtimeShift)&&!["sleep","wish-queue","wish-register","interact"].includes(a.plan.act.kind)&&jt(a.resident.hobbies,s.activity));n.sort((a,r)=>Math.hypot(a.x-s.x,a.z-s.z)-Math.hypot(r.x-s.x,r.z-s.z));for(const a of n){const r=this.nav.path(a,s);if(r)return this.release(a,this.clockNow),this.taken.set(s.key,a.key),a.perched=!1,a.plan={label:`${{read:"Reading at",paint:"Painting at",garden:"Planting and watering at",perform:"Performing at",play:"Playing at",observe:"Enjoying"}[s.activity]} ${s.name}`,goal:s,act:{kind:"interact",site:s,seconds:s.activity==="perform"?25:14}},a.path=r,a.key}return null}update(e,t,s){this.hour=s,this.clockNow=t;const i=Math.min(e,.1);this.wishQueue(t),this.playground(i,t);for(const n of this.robots.values())this.tick(n,i,t),this.feel(n,i);this.concerts(t),this.greetings(t)}concerts(e){for(const t of this.robots.values()){if(t.mode.state!=="free"||!this.performing(t)||t.path.length)continue;const s=[...this.robots.values()].filter(i=>i.plan.act.kind==="watch"&&i.plan.act.performer===t.key);if(!(s.length>=5))for(const i of this.robots.values()){if(i===t||i.mode.state!=="free"||i.chatAfter>e||i.plan.seek||!["look","gaze","sit"].includes(i.plan.act.kind)||Math.hypot(i.x-t.x,i.z-t.z)>8)continue;const n=t.heading+Math.PI*2*s.length/5,a={x:t.x+Math.sin(n)*2.4,z:t.z+Math.cos(n)*2.4},r=this.nav.path(i,a);if(r&&(this.release(i,e),i.perched=!1,i.plan={label:`Watching ${t.resident.name} perform`,goal:a,act:{kind:"watch",performer:t.key}},i.path=r,s.push(i),s.length>=5))break}}}performing(e){return e.plan.act.kind==="dance"||e.plan.act.kind==="interact"&&e.plan.act.site.activity==="perform"}audience(e){return[...this.robots.values()].filter(t=>t.mode.state==="free"&&!t.path.length&&t.plan.act.kind==="watch"&&t.plan.act.performer===e).length}feel(e,t){const s=e.plan.act.kind;if(e.mode.state==="working"||e.excitedUntil>this.clockNow){e.boredom=Math.max(0,e.boredom-t*.5);return}if(s==="sleep")return;const i=s==="swing"||s==="seesaw"||s==="tag"||s==="dance"||s==="chat"||s==="slide"&&this.slideRide?.key===e.key||s==="cheer";e.boredom=Math.min(1,Math.max(0,e.boredom+(i?-.022222222222222223:wi)*t))}tick(e,t,s){e.bubble&&e.bubble.until<s&&(e.bubble=null),e.gesture&&e.gesture.until<s&&(e.gesture=null);const i=e.plan;if(i.act.kind==="watch"){const n=this.robots.get(i.act.performer);if(!n||n.mode.state!=="free"||!this.performing(n)||n.path.length){e.chatAfter=s+30,this.replan(e,s);return}}if(i.act.kind==="interact"){const n=i.act.site,a=(this.places.activities??[]).find(r=>r.key===n.key);if(!a||a.activity!==n.activity||Math.hypot(a.x-n.x,a.z-n.z)>.01||Math.abs(a.y-n.y)>.01){this.replan(e,s);return}}if(i.act.kind==="tag"&&i.since!==void 0){this.tagTick(e,i.act.game,t,s);return}if(this.slideRide?.key!==e.key){if(i.seek){const n=this.robots.get(i.seek);if(!n||n.plan.act.kind==="sleep"||n.mode.state!=="free"||this.busyPlaying(n)){this.replan(e,s);return}if(Math.hypot(n.x-e.x,n.z-e.z)<1.5){i.act.kind!=="invite"?this.startChat(e,n,s):i.act.answer==="yes"||i.act.answer!=="no"&&this.accepts(n)?this.startPlay(i.act.game,e,n,s):this.decline(e,n,s);return}if(s>e.repathAt&&(e.repathAt=s+1.2,e.path=this.nav.path(e,n)??[],!e.path.length)){this.replan(e,s);return}}if(e.path.length){this.walk(e,t);return}i.since===void 0&&this.begin(e,s),this.act(e,t,s),e.gesture&&(e.pose==="stand"||e.pose==="talk")&&(e.pose=e.gesture.pose)}}walk(e,t){let s=e.speed*t;for(e.pose="walk",e.perched=!1;s>0&&e.path.length;){const i=e.path[0],n=i.x-e.x,a=i.z-e.z,r=Math.hypot(n,a);if(r<=s){e.x=i.x,e.z=i.z,s-=r,e.stride=(e.stride+r/Lt)%1,e.path.shift();continue}e.x+=n/r*s,e.z+=a/r*s,e.stride=(e.stride+s/Lt)%1,this.turn(e,Math.atan2(n,a),t),s=0}}turn(e,t,s){let i=t-e.heading;i=Math.atan2(Math.sin(i),Math.cos(i));const n=ki*s;e.heading+=Math.max(-n,Math.min(n,i))}begin(e,t){const s=e.plan;s.since=t,s.goal&&(e.x=s.goal.x,e.z=s.goal.z);const i=s.act,n="seat"in i?i.seat:null;e.perched=!!n,n?(e.x=n.x,e.z=n.z,e.y=n.y,e.heading=n.face):s.goal?.face!==void 0&&(e.heading=s.goal.face),i.kind==="interact"&&(e.heading=i.site.face,e.y=i.site.y,e.perched=i.site.y>.1),i.kind==="seesaw"&&(this.seesawSeated[i.end]=!0,this.seesawSeated[0]&&this.seesawSeated[1]&&this.seesawSince===0&&(this.seesawSince=t)),i.kind==="slide"&&!this.slideQueue.includes(e.key)&&this.slideQueue.push(e.key),i.kind==="chat"&&i.first&&(e.bubble={text:"hi!",tone:"plain",until:t+1.6})}act(e,t,s){const i=e.plan,n=i.act,a=s-(i.since??s),r=u=>a>=u,d=this.places.playground;switch(n.kind){case"wish-queue":{e.y=.15,e.perched=!0,e.pose="stand",this.turn(e,Math.PI,t);let u=this.wishPatience.get(n.ticket);if(u||(u={since:s,next:s+45+e.rng()*35,gaveUp:!1},this.wishPatience.set(n.ticket,u)),n.index>0&&s>=u.next&&(u.next=s+10,e.rng()<.35)){u.gaveUp=!0,u.next=s+8,this.release(e,s),e.plan={label:"Maybe another time",goal:null,act:{kind:"look",seconds:4},since:s},e.bubble={text:"maybe later…",tone:"plain",until:s+4},e.chatAfter=s+30,this.onWishGiveUp?.(n.ticket);return}n.index===0&&a>.5&&(e.plan={label:"Registering a wish at BOT Society",goal:{...Bs,face:Math.PI},act:{kind:"wish-register",ticket:n.ticket}},this.route(e));return}case"wish-register":e.y=.15,e.perched=!0,e.pose="register",this.turn(e,Math.PI,t),e.bubble={text:"📝 ✨",tone:"plain",until:s+1},a>=4&&(n.triedAt===void 0||s-n.triedAt>5)&&(n.triedAt=s,this.onWishRegister?.(n.ticket));return;case"interact":{const u=n.site.activity;e.pose=u==="perform"?"dance":u==="observe"?"think":u==="play"?"cheer":u==="read"?"think":"work",e.heading=n.site.face,e.bubble={text:{read:"📖",paint:"🎨",garden:a<5?"🌱":"💧",perform:"🎵",play:"🎮",observe:"✨"}[u],tone:"plain",until:s+1},e.boredom=Math.max(0,e.boredom-t/30),r(n.seconds)&&this.replan(e,s);return}case"look":e.pose="stand",n.face!==void 0&&this.turn(e,n.face,t),this.sigh(e,t,s),r(n.seconds)&&this.replan(e,s);return;case"sit":e.pose="sit",this.sigh(e,t,s),r(e.boredom>.8?Math.min(n.seconds,8):n.seconds)&&this.replan(e,s);return;case"sleep":e.pose="sleep",(!e.bubble||e.bubble.until<s+.5)&&(e.bubble={text:"z",tone:"sleep",until:s+6}),Le(this.hour,e.bedtimeShift)||this.replan(e,s);return;case"gaze":e.pose=e.perched?"sit":"stand",this.turn(e,n.face,t),this.sigh(e,t,s),r(n.seconds)&&this.replan(e,s);return;case"watch":{const u=this.robots.get(n.performer);if(!u||u.mode.state!=="free"||!this.performing(u)||u.path.length){e.chatAfter=s+30,this.replan(e,s);return}this.turn(e,Te(e,u),t),e.pose=Math.floor(a/2)%3===1?"cheer":"stand",e.boredom=Math.max(0,e.boredom-t/45);return}case"dance":e.pose="dance",e.bubble||(e.bubble={text:"🎵",tone:"plain",until:s+2.5}),r(n.seconds)&&this.replan(e,s);return;case"tend":e.pose="think",this.turn(e,n.face,t),r(n.seconds)&&this.replan(e,s);return;case"chat":{const u=this.robots.get(n.with);if(!u||r(n.seconds)){if(e.chatAfter=s+25+e.rng()*40,u&&n.first&&d&&this.likesToPlay(e)&&e.rng()<.4&&u.plan.act.kind==="chat"){e.bubble={text:"wanna play?",tone:"plain",until:s+1.8},this.startPlay(fe(this.jointGames(),e.rng)??"tag",e,u,s);return}this.replan(e,s);return}this.turn(e,Te(e,u),t);const p=Math.floor(a/1.8)%2===(n.first?0:1);e.pose=p?"talk":"stand",p&&a>1.6&&(!e.bubble||e.bubble.until<s)&&(e.bubble={text:this.chatLine(e,u),tone:"plain",until:s+1.6});return}case"invite":this.replan(e,s);return;case"sob":{if(e.pose="sob",e.bubble||(e.bubble={text:Math.floor(a/1.6)%2?"sob…":"😭",tone:"plain",until:s+1.5}),!r(n.seconds))return;const u=n.then==="ask"?Ce(this.partners(e,30).filter(p=>p.key!==n.from),e,e.rng):null;u?this.invite(e.key,u.key,fe(this.jointGames(),e.rng)??"tag",s):this.replan(e,s);return}case"swing":{if(!d){this.replan(e,s);return}const u=d.swings[n.swing];this.swingAmp[n.swing]=Math.min(.62,this.swingAmp[n.swing]+t*.07);const p=this.motion.swings[n.swing],f=xi(u,p);e.perched=!0,e.x=f.x,e.z=f.z,e.y=f.y,e.heading=f.face,e.pose="swing",e.lean=p,!e.bubble&&e.rng()<t*.25&&(e.bubble={text:fe(["wheee!","😄","✨","higher!"],e.rng),tone:"plain",until:s+1.5}),r(n.seconds)&&this.replan(e,s);return}case"seesaw":{if(!d){this.replan(e,s);return}const u=yi(d.seesaw,n.end,this.motion.seesaw);e.perched=!0,e.x=u.x,e.z=u.z,e.y=u.y,e.heading=u.face,e.pose="ride";const p=this.seesawRider[n.end===0?1:0];if(!(this.seesawSeated[0]&&this.seesawSeated[1])){if(e.bubble||(e.bubble={text:"🙋",tone:"plain",until:s+2.2}),!p&&a>2&&s>=(n.askAt??0)){n.askAt=s+3;const h=Ce(this.partners(e,40).filter(l=>!n.asked?.includes(l.key)),e,e.rng);if(h)if((n.asked??=[]).push(h.key),this.accepts(h)){if(this.release(h,s),h.perched=!1,h.plan=this.seesawPlan(h,n.end===0?1:0,e.resident.name),this.route(h),h.plan.act.kind==="seesaw"){h.bubble={text:"coming!",tone:"plain",until:s+2.2},e.plan.label=`On the seesaw with ${h.resident.name}`;return}}else h.bubble={text:"maybe later",tone:"plain",until:s+2.2}}!p&&a>16&&this.sob(e,s,"nobody came to play","leave");return}!e.bubble&&e.rng()<t*.3&&(e.bubble={text:fe(["haha!","up!","😄","🎵","whoa!"],e.rng),tone:"plain",until:s+1.4}),s-this.seesawSince>n.seconds&&this.replan(e,s);return}case"slide":{e.pose="stand",d&&this.turn(e,d.slide.face,t),a>40&&this.replan(e,s);return}case"tag":return;case"work":e.pose="work",(!e.bubble||e.bubble.until<s+.5)&&(e.bubble={text:"…",tone:"work",until:s+4});return;case"wait":e.pose="raise",this.turn(e,n.face,t),(!e.bubble||e.bubble.until<s+.5)&&(e.bubble={text:"?",tone:"decide",until:s+4});return;case"trouble":e.pose="think",(!e.bubble||e.bubble.until<s+.5)&&(e.bubble={text:"!",tone:"danger",until:s+4});return;case"wish":e.pose=a<n.seconds*.6?"raise":"cheer",this.turn(e,n.face,t),r(n.seconds)&&this.replan(e,s);return;case"cheer":if(e.pose="cheer",!r(n.seconds))return;n.then?(e.plan=n.then,e.speed=e.excitedUntil>s?1.6:st,this.route(e)):this.replan(e,s);return}}sigh(e,t,s){e.boredom<.72||e.bubble||e.rng()>t*.08||(e.bubble={text:fe(["🥱","so bored…","hmm…","anyone?"],e.rng),tone:"plain",until:s+2})}chatLine(e,t){const s=e.rng,i=t.resident.look.worn;return i.head&&s()<.25?"nice hat!":i.back&&s()<.2?"cool backpack!":t.resident.owner.kind==="agent"&&s()<.15?"busy day?":this.likesToPlay(e)&&s()<.12?"wanna play?":fe(zi,s)??"😄"}release(e,t){for(const[i,n]of[...this.taken])n===e.key&&this.taken.delete(i);this.swingRider=this.swingRider.map(i=>i===e.key?null:i);for(const i of[0,1])this.seesawRider[i]===e.key&&(this.seesawRider[i]=null,this.seesawSeated[i]=!1);this.slideQueue=this.slideQueue.filter(i=>i!==e.key),this.slideRide?.key===e.key&&(this.slideRide=null);const s=e.plan.act;s.kind==="tag"&&this.endTag(s.game,t,e.key),e.path=[],e.plan.seek=void 0,e.speed=st,e.lean=0,e.perched&&!("seat"in s&&s.seat)&&(e.perched=!1)}replan(e,t){this.release(e,t),e.perched=!1,e.plan=this.choose(e,t),this.route(e)}route(e){const t=e.plan;if(t.since=void 0,e.path=[],t.seek){e.repathAt=0;return}if(!t.goal)return;const s={x:e.x,z:e.z};if(Math.hypot(t.goal.x-s.x,t.goal.z-s.z)<.05)return;const i=this.nav.path(s,t.goal);if(i){e.path=i;return}if("seat"in t.act&&t.act.seat||It.has(t.act.kind)||t.act.kind==="wish-queue"||t.act.kind==="wish-register"){this.release(e,0),e.plan={label:"Looking around",goal:null,act:{kind:"look",seconds:2+e.rng()*3}};return}t.goal=null}overrideLabel(e){const t=e.mode.label;switch(e.mode.state){case"working":return t?`Working · ${t}`:"Working";case"needs_you":return t?`Waiting for you · ${t}`:"Waiting for you";case"failed":return t?`Stuck · ${t}`:"Something went wrong";default:return"Looking around"}}ownSeat(e,t){const s=this.places.plots.get(e.key);return s?this.places.seats.find(i=>i.plot===s.id&&i.kind===t&&(!i.owner||i.owner===e.key)&&!this.taken.has(i.key))??null:null}takeSeat(e,t){return t&&this.taken.set(t.key,e.key),t}likesToPlay(e){return Nt[e.resident.trait??"agent"].play>=.9}choose(e,t){const s=e.rng,i=this.places.plots.get(e.key);switch(e.mode.state){case"working":{const l=this.takeSeat(e,this.ownSeat(e,"desk")),m=l??(i?i.center:null);return{label:this.overrideLabel(e),goal:m&&{x:m.x,z:m.z},act:{kind:"work",seat:l}}}case"needs_you":return{label:this.overrideLabel(e),goal:i?{x:i.front.x,z:i.front.z,face:i.front.face}:null,act:{kind:"wait",face:i?.front.face??e.heading}};case"failed":{const l=this.takeSeat(e,this.ownSeat(e,"desk")),m=l??(i?i.center:null);return{label:this.overrideLabel(e),goal:m&&{x:m.x,z:m.z},act:{kind:"trouble",seat:l}}}}if(Le(this.hour,e.bedtimeShift)){const l=this.takeSeat(e,this.ownSeat(e,"bed")??this.ownSeat(e,"seat")),m=l??i?.center??null;return{label:"Asleep",goal:m&&{x:m.x,z:m.z},act:{kind:"sleep",seat:l}}}const n=(this.places.activities??[]).filter(l=>!this.taken.has(l.key)&&jt(e.resident.hobbies,l.activity));if(n.length&&s()<.4){const l=Ce(n,e,s);if(l&&this.nav.path(e,l))return this.taken.set(l.key,e.key),{label:`${l.activity==="garden"?"Planting and watering":"Enjoying"} ${l.name}`,goal:l,act:{kind:"interact",site:l,seconds:l.activity==="perform"?25:14}}}const a={...Nt[e.resident.trait??"agent"]},r=e.boredom;r>.5&&(a.play*=1+r*3,a.chat*=1+r*2,a.dance*=1+r,a.sit*=.5,a.gaze*=.6),!e.resident.hobbies?.includes("gardening")&&e.resident.trait!=="gardener"&&e.resident.trait!=="tinkerer"&&(a.tend=0);const d=this.freeSeats();switch(d.length||(a.sit=0),(t<e.chatAfter||this.partners(e).length===0)&&(a.chat=0),this.places.playground||(a.play=0),Pi(a,s)){case"play":{const l=this.choosePlay(e,t);if(l)return l;break}case"sit":{const l=this.takeSeat(e,Ce(d,e,s));if(!l)break;return{label:l.plot?`Sitting on ${l.name}`:`Resting on ${l.name}`,goal:{x:l.x,z:l.z},act:{kind:"sit",seat:l,seconds:12+s()*30}}}case"gaze":{const l=s()*Math.PI*2,m=this.places.radius-2.2,b={x:Math.sin(l)*m,z:Math.cos(l)*m};return{label:"Watching the sea",goal:b,act:{kind:"gaze",seconds:10+s()*18,face:Math.atan2(b.x,b.z)}}}case"visit":{const l=[...this.places.plots.entries()].filter(([b])=>b!==e.key),[,m]=fe(l,s)??[];if(!m)break;return{label:"Visiting a neighbour",goal:{x:m.front.x,z:m.front.z},act:{kind:"look",seconds:4+s()*6,face:m.front.face+Math.PI}}}case"chat":{const l=Ce(this.partners(e),e,s);if(!l)break;return{label:`Going to see ${l.resident.name}`,goal:null,seek:l.key,act:{kind:"look",seconds:2}}}case"dance":{const l=s()*Math.PI*2,m=2.6+s()*1.2;return{label:"Dancing on the plaza",goal:{x:Math.sin(l)*m,z:Math.cos(l)*m},act:{kind:"dance",seconds:18+s()*10}}}case"tend":{const l=i?.center??{x:0,z:0},m={x:l.x+(s()-.5)*6,z:l.z+(s()-.5)*6};return{label:e.resident.trait==="tinkerer"?"Tinkering":"Tending the garden",goal:m,act:{kind:"tend",seconds:6+s()*8,face:s()*Math.PI*2}}}}const p=i&&s()<.55,f=p?i.center:{x:0,z:0},h=p?6:this.places.radius-4;for(let l=0;l<6;l++){const m=s()*Math.PI*2,b=Math.sqrt(s())*h,P={x:f.x+Math.sin(m)*b,z:f.z+Math.cos(m)*b};if(!(Math.hypot(P.x,P.z)>this.places.radius-2)&&this.nav.isFree(P))return{label:"Exploring",goal:P,act:{kind:"look",seconds:2+s()*5}}}return{label:"Looking around",goal:null,act:{kind:"look",seconds:3}}}freeSeats(){return this.places.seats.filter(e=>e.kind==="seat"&&!this.taken.has(e.key))}busyPlaying(e){return It.has(e.plan.act.kind)||["interact","wish-queue","wish-register"].includes(e.plan.act.kind)||this.slideQueue.includes(e.key)}partners(e,t=18){return[...this.robots.values()].filter(s=>s!==e&&s.mode.state==="free"&&s.plan.act.kind!=="sleep"&&s.plan.act.kind!=="chat"&&!s.plan.seek&&!this.busyPlaying(s)&&Math.hypot(s.x-e.x,s.z-e.z)<t)}startChat(e,t,s){const i=7+e.rng()*9;for(const[n,a,r]of[[e,t,!0],[t,e,!1]])this.release(n,s),n.perched=!1,n.plan={label:`Chatting with ${a.resident.name}`,goal:null,act:{kind:"chat",with:a.key,seconds:i,first:r},since:s},r&&(n.bubble={text:"hi!",tone:"plain",until:s+1.6})}greetings(e){if(e<this.greetAt)return;this.greetAt=e+1.2;const t=[...this.robots.values()].filter(s=>s.plan.act.kind!=="sleep"&&!s.perched&&s.plan.act.kind!=="work"&&s.plan.act.kind!=="tag"&&s.plan.act.kind!=="sob"&&this.slideRide?.key!==s.key);for(let s=0;s<t.length;s++)for(let i=s+1;i<t.length;i++){const n=t[s],a=t[i];if(e<(this.helloAfter.get(n.key)??0)||e<(this.helloAfter.get(a.key)??0)||n.bubble||a.bubble||n.plan.seek||a.plan.seek||n.plan.act.kind==="chat"||a.plan.act.kind==="chat"||Math.hypot(n.x-a.x,n.z-a.z)>Mi)continue;const r=n.key<a.key?`${n.key}|${a.key}`:`${a.key}|${n.key}`;if(!(e-(this.greeted.get(r)??-1/0)<vi)){this.greeted.set(r,e),this.helloAfter.set(n.key,e+Ct),this.helloAfter.set(a.key,e+Ct);for(const[d,u]of[[n,a],[a,n]])d.plan.act.kind!=="chat"&&((!d.bubble||d.bubble.tone==="plain")&&(d.bubble={text:d.rng()<.75?"hi!":"👋",tone:"plain",until:e+1.5}),d.path.length||(d.gesture={pose:"wave",until:e+1.4},d.heading=Te(d,u)))}}}jointGames(){const e=["tag"];return this.places.playground&&(!this.seesawRider[0]&&!this.seesawRider[1]&&e.push("seesaw","seesaw"),!this.swingRider[0]&&!this.swingRider[1]&&e.push("swings"),this.slideQueue.length<2&&!this.slideRide&&e.push("slide")),e}choosePlay(e,t){if(!this.places.playground)return null;const i=e.rng;for(const d of[0,1]){const u=d===0?1:0;if(!this.seesawRider[d]&&this.seesawRider[u]&&this.seesawSeated[u]&&i()<.8)return this.seesawPlan(e,d,this.robots.get(this.seesawRider[u])?.resident.name)}const n=this.partners(e,30);if(n.length&&t>=e.chatAfter&&i()<.6){const d=Ce(n,e,i);return{label:`Asking ${d.resident.name} to play`,goal:null,seek:d.key,act:{kind:"invite",game:fe(this.jointGames(),i)??"tag",with:d.key}}}const a=[],r=this.swingRider.findIndex(d=>!d);return r>=0&&a.push(()=>this.swingPlan(e,r)),this.slideQueue.length<3&&a.push(()=>this.slidePlan(2+Math.floor(i()*3))),!this.seesawRider[0]&&!this.seesawRider[1]&&a.push(()=>this.seesawPlan(e,i()<.5?0:1)),fe(a,i)?.()??null}swingPlan(e,t,s){const i=this.places.playground;this.swingRider[t]=e.key;const n=i.swings[t].stand;return{label:s?`Swinging with ${s}`:"On the swings",goal:{x:n.x,z:n.z,face:i.swings[t].face},act:{kind:"swing",swing:t,seconds:14+e.rng()*16}}}seesawPlan(e,t,s){const i=this.places.playground;this.seesawRider[t]=e.key;const n=i.seesaw.stand[t];return{label:s?`On the seesaw with ${s}`:"Waiting for a friend on the seesaw",goal:{x:n.x,z:n.z},act:{kind:"seesaw",end:t,seconds:14+e.rng()*12}}}slidePlan(e,t){const s=this.places.playground,i=this.slideQueue.length+(this.slideRide?1:0),n={x:s.slide.queue.x+s.slide.back.x*i*.8,z:s.slide.queue.z+s.slide.back.z*i*.8};return{label:t?`Taking turns on the slide with ${t}`:"Playing on the slide",goal:{...n,face:s.slide.face},act:{kind:"slide",runs:e}}}invite(e,t,s,i,n={}){const a=this.robots.get(e),r=this.robots.get(t);return!a||!r||a.mode.state!=="free"||r.mode.state!=="free"?!1:(this.release(a,i),a.perched=!1,a.plan={label:`Asking ${r.resident.name} to play`,goal:null,seek:r.key,act:{kind:"invite",game:s,with:r.key,...n.answer?{answer:n.answer}:{}}},this.route(a),!0)}waitOnSeesaw(e,t){const s=this.robots.get(e);return!s||!this.places.playground||this.seesawRider[0]||this.seesawRider[1]?!1:(this.release(s,t),s.perched=!1,s.plan=this.seesawPlan(s,0),this.route(s),!0)}accepts(e){const t=e.resident.trait;let s=.68+e.boredom*.3;return t==="sporty"&&(s+=.15),t==="curious"&&(s+=.08),t==="cozy"&&(s-=.22),t==="dreamy"&&(s-=.15),e.plan.act.kind==="sit"&&(s-=.15),e.rng()<Math.min(.98,Math.max(.1,s))}decline(e,t,s){t.bubble={text:fe(["not now 😅","maybe later","sorry!"],t.rng),tone:"plain",until:s+2.2},t.path.length||(t.heading=Te(t,e),t.gesture={pose:"think",until:s+1.6}),this.sob(e,s,`${t.resident.name} said no`,e.rng()<.5?"ask":"leave",t.key)}sob(e,t,s,i,n){this.release(e,t),e.perched=!1,e.boredom=Math.min(1,e.boredom+.12),e.bubble={text:"😭",tone:"plain",until:t+1.6},e.plan={label:`Crying · ${s}`,goal:null,act:{kind:"sob",seconds:3.5+e.rng()*2,then:i,...n?{from:n}:{}},since:t}}startPlay(e,t,s,i){this.release(t,i),this.release(s,i),t.perched=!1,s.perched=!1,t.bubble={text:"wanna play?",tone:"plain",until:i+1.6},s.bubble={text:"yes!",tone:"plain",until:i+1.6},t.chatAfter=s.chatAfter=i+30+t.rng()*30;const a=this.jointGames().includes(e)?e:"tag",r=[t.resident.name,s.resident.name];if(a==="seesaw")t.plan=this.seesawPlan(t,0,r[1]),s.plan=this.seesawPlan(s,1,r[0]);else if(a==="swings")t.plan=this.swingPlan(t,0,r[1]),s.plan=this.swingPlan(s,1,r[0]);else if(a==="slide")t.plan=this.slidePlan(3,r[1]),s.plan=this.slidePlan(3,r[0]);else{const d=`tag-${++this.games}`,u=t.rng()<.5?t.key:s.key;this.tags.set(d,{id:d,players:[t.key,s.key],it:u,until:i+22+t.rng()*14,center:{x:(t.x+s.x)/2,z:(t.z+s.z)/2},pausedUntil:i+1.6});for(const[p,f]of[[t,s],[s,t]])p.plan={label:`Playing tag with ${f.resident.name}`,goal:null,act:{kind:"tag",game:d},since:i};return}this.route(t),this.route(s)}tagTick(e,t,s,i){const n=this.tags.get(t),a=n?.players.find(d=>d!==e.key),r=a?this.robots.get(a):void 0;if(!n||!r||r.plan.act.kind!=="tag"){this.replan(e,i);return}if(i>n.until){this.tags.delete(t);for(const d of[e,r])this.release(d,i),d.plan={label:"Had fun playing tag",goal:null,act:{kind:"cheer",seconds:2},since:i},d.bubble={text:"😆",tone:"plain",until:i+2};return}if(n.it===e.key){if(e.speed=1.5,i<n.pausedUntil){e.pose="think",this.turn(e,Te(e,r),s);return}if(Math.hypot(r.x-e.x,r.z-e.z)<.9){n.it=r.key,n.pausedUntil=i+1.5,e.bubble={text:"tag!",tone:"plain",until:i+1.4},r.bubble={text:"😆",tone:"plain",until:i+1.4},e.path=[],r.path=[];return}(i>e.repathAt||!e.path.length)&&(e.repathAt=i+.45,e.path=this.nav.path(e,r)??[])}else if(e.speed=1.32,!e.path.length){const d=this.robots.get(n.it);let u=null,p=-1;for(let f=0;f<6;f++){const h=e.rng()*Math.PI*2,l=2+e.rng()*6,m={x:n.center.x+Math.sin(h)*l,z:n.center.z+Math.cos(h)*l};if(!this.nav.isFree(m)||Math.hypot(m.x,m.z)>this.places.radius-3)continue;const b=Math.hypot(m.x-d.x,m.z-d.z);b>p&&(u=m,p=b)}e.path=u?this.nav.path(e,u)??[]:[]}e.path.length?this.walk(e,s):e.pose="stand"}endTag(e,t,s){const i=this.tags.get(e);if(i){this.tags.delete(e);for(const n of i.players){if(n===s)continue;const a=this.robots.get(n);a&&a.plan.act.kind==="tag"&&(a.path=[],a.speed=st,a.plan={label:"Looking around",goal:null,act:{kind:"look",seconds:1.5},since:t})}}}playground(e,t){const s=this.places.playground;for(let f=0;f<2;f++){const h=this.swingRider[f]?this.robots.get(this.swingRider[f]):void 0;h?.plan.act.kind==="swing"&&h.plan.since!==void 0||(this.swingAmp[f]=Math.max(0,this.swingAmp[f]-e*.12)),this.swingPhase[f]+=e*2.4,this.motion.swings[f]=this.swingAmp[f]*Math.sin(this.swingPhase[f])}const i=this.seesawSeated[0]&&this.seesawSeated[1];i&&this.seesawSince===0&&(this.seesawSince=t),i||(this.seesawSince=0);const n=i?.24*Math.sin(1.9*(t-this.seesawSince)):this.seesawSeated[0]?.24:this.seesawSeated[1]?-.24:0;if(this.motion.seesaw+=(n-this.motion.seesaw)*Math.min(1,e*(i?12:3)),!s)return;if(!this.slideRide){const f=this.slideQueue[0]?this.robots.get(this.slideQueue[0]):void 0;f&&f.plan.act.kind==="slide"&&f.plan.since!==void 0?(this.slideQueue.shift(),this.slideRide={key:f.key,phase:"approach",since:t,from:{x:f.x,z:f.z}}):this.slideQueue[0]&&!f&&this.slideQueue.shift()}const a=this.slideRide;if(!a)return;const r=this.robots.get(a.key);if(!r||r.plan.act.kind!=="slide"){this.slideRide=null;return}const d=s.slide,u=t-a.since,p=f=>{a.phase=f,a.since=t};switch(a.phase){case"approach":{const f=Math.min(1,u/.6);r.x=we(a.from.x,d.foot.x,f),r.z=we(a.from.z,d.foot.z,f),r.perched=!1,r.pose="walk",r.stride=(r.stride+e*1.4)%1,r.heading=d.face,f>=1&&p("climb");return}case"climb":{const f=Math.min(1,u/1.8);r.perched=!0,r.x=we(d.foot.x,d.top.x,f),r.z=we(d.foot.z,d.top.z,f),r.y=we(d.top.y-1.35,d.top.y,f),r.pose="climb",r.stride=(r.stride+e*1.2)%1,r.heading=d.face,f>=1&&p("perch");return}case"perch":r.pose="stand",r.heading=d.face,u>.5&&(r.bubble={text:fe(["wheee!","here I go!","😆"],r.rng),tone:"plain",until:t+1.6},p("ride"));return;case"ride":{const f=Math.min(1,u/1.1),h=f*f;r.x=we(d.from.x,d.to.x,h),r.z=we(d.from.z,d.to.z,h),r.y=we(d.from.y,d.to.y,h),r.pose="ride",r.heading=d.face,f>=1&&p("hop");return}case"hop":{const f=Math.min(1,u/.45);if(r.x=we(d.to.x,d.exit.x,f),r.z=we(d.to.z,d.exit.z,f),r.perched=!1,r.pose="cheer",f<1)return;this.slideRide=null;const h=r.plan.act;if(h.runs-=1,h.runs>0){const l=this.slidePlan(h.runs);r.plan={...l,label:r.plan.label},this.route(r)}else r.bubble={text:"😄",tone:"plain",until:t+1.5},this.replan(r,t);return}}}describe(e){const t=this.robots.get(e);if(!t)return null;const s=t.plan.act;if(s.kind==="slide"){const i=this.slideRide?.key===e?this.slideRide:null;if(i?.phase==="climb"||i?.phase==="approach")return"Climbing up the slide";if(i?.phase==="perch")return"At the top of the slide";if(i?.phase==="ride")return"Going down the slide!";if(t.plan.since!==void 0){const n=this.slideQueue.indexOf(e)+(this.slideRide?1:0);return n>0?`Waiting in line for the slide · ${n} ahead`:"Next on the slide"}}if(s.kind==="tag"){const i=this.tags.get(s.game),n=i?.players.find(r=>r!==e),a=n?this.robots.get(n)?.resident.name:void 0;if(i&&a)return i.it===e?`Playing tag with ${a} · it's ${t.resident.name}'s turn to chase`:`Playing tag with ${a} · running away`}return s.kind==="seesaw"&&t.plan.since!==void 0&&!(this.seesawSeated[0]&&this.seesawSeated[1])?"Waiting for a friend on the seesaw":t.path.length&&s.kind==="sit"?`Going to sit on ${s.seat.name}`:t.plan.label}said(e){const t=this.robots.get(e)?.bubble;return t&&t.tone==="plain"?t.text:null}}function Ce(o,e,t){if(!o.length)return null;const s=[...o].sort((n,a)=>Math.hypot(n.x-e.x,n.z-e.z)-Math.hypot(a.x-e.x,a.z-e.z)),i=Math.min(s.length,3);return s[Math.floor(t()*i)]??s[0]}const Ze=-.18;function nt(o,e,t){const s=(m,b)=>{let P=Math.imul(m,374761393)^Math.imul(b,668265263)^Math.imul(t,2246822519);return P=Math.imul(P^P>>>13,1274126177),((P^P>>>16)>>>0)/4294967296},i=Math.floor(o),n=Math.floor(e),a=o-i,r=e-n,d=a*a*(3-2*a),u=r*r*(3-2*r),p=s(i,n),f=s(i+1,n),h=s(i,n+1),l=s(i+1,n+1);return p+(f-p)*d+(h-p)*u+(p-f-h+l)*d*u}const Be=(o,e,t)=>{const s=Math.min(1,Math.max(0,(t-o)/(e-o)));return s*s*(3-2*s)};function bt(o,e){return o<=e-5?0:o<=e+.6?-.32*Be(e-5,e+.6,o):-.32-2.4*Be(e+.6,e+12,o)}const Ne={grass:new se("#8fcb72"),grassDark:new se("#7fbe64"),sand:new se("#f0dcaa"),wetSand:new se("#dcc28a"),deep:new se("#bfa673")};function Ei(o,e){const t=o+14,s=128,i=[0];for(let p=.9;p<t;p+=p<o-6?1.6:.8)i.push(p);i.push(t);const n=[],a=[],r=(p,f)=>{const h=p>o-7?(nt(Math.cos(f)*3,Math.sin(f)*3,e)-.5)*2.2:0,l=p+h*Be(o-7,o,p),m=Math.sin(f)*l,b=Math.cos(f)*l,P=bt(p,o)+(p>o-5&&p<o+8?(nt(m*.4,b*.4,e+7)-.5)*.12:0),M=new se;return p<o-5.2?M.copy(Ne.grass).lerp(Ne.grassDark,nt(m*.15,b*.15,e)*.7):p<o+.4?M.copy(Ne.sand).lerp(Ne.wetSand,Be(o-1.5,o+.4,p)):M.copy(Ne.wetSand).lerp(Ne.deep,Be(o+.4,o+8,p)),{p:[m,P,b],c:[M.r,M.g,M.b]}};for(let p=0;p<i.length-1;p++)for(let f=0;f<s;f++){const h=f/s*Math.PI*2,l=(f+1)/s*Math.PI*2,m=r(i[p],h),b=r(i[p],l),P=r(i[p+1],h),M=r(i[p+1],l);for(const g of p===0?[[m,P,M]]:[[m,P,M],[m,M,b]]){const v=g[0].c;for(const k of g)n.push(...k.p),a.push(...v)}}const d=new Xt;d.setAttribute("position",new _t(new Float32Array(n),3)),d.setAttribute("color",new _t(new Float32Array(a),3)),d.computeVertexNormals();const u=new C(d,new me({vertexColors:!0,flatShading:!0,roughness:.95}));return u.receiveShadow=!0,u.name="terrain",u}function Ai(o){const e=new xt(900,900,150,150);e.rotateX(-Math.PI/2);const t=new me({color:"#5fbcd8",flatShading:!0,roughness:.32,metalness:.08,transparent:!0,opacity:.88}),s={value:0};t.onBeforeCompile=n=>{n.uniforms.uTime=s,n.uniforms.uShore={value:o},n.vertexShader=n.vertexShader.replace("#include <common>",`#include <common>
|
|
10
|
+
uniform float uTime;
|
|
11
|
+
uniform float uShore;`).replace("#include <begin_vertex>",`#include <begin_vertex>
|
|
12
|
+
float away = smoothstep(uShore + 1.0, uShore + 16.0, length(position.xz));
|
|
13
|
+
transformed.y += away * (sin(position.x * 0.17 + uTime * 0.8) * 0.12
|
|
14
|
+
+ cos(position.z * 0.14 + uTime * 0.65) * 0.1
|
|
15
|
+
+ sin((position.x + position.z) * 0.33 + uTime * 1.5) * 0.04);`)};const i=new C(e,t);return i.position.y=Ze,i.name="sea",{mesh:i,material:t,time:s}}function Ti(){const o=new se("#79b8f0"),e=new se("#e8f3fb"),t=new Zt({side:bs,depthWrite:!1,fog:!1,uniforms:{top:{value:o},horizon:{value:e}},vertexShader:"varying vec3 vDir; void main() { vDir = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }",fragmentShader:`uniform vec3 top; uniform vec3 horizon; varying vec3 vDir;
|
|
16
|
+
void main() { float h = clamp(vDir.y * 1.6 + 0.05, 0.0, 1.0); gl_FragColor = vec4(mix(horizon, top, pow(h, 0.7)), 1.0); }`}),s=new C(new Qe(600,24,12),t);return s.name="sky",s.renderOrder=-1,{mesh:s,top:o,horizon:e}}function Ri(o){if(typeof document>"u")return null;const e=document.createElement("canvas");e.width=256,e.height=96;const t=e.getContext("2d");if(!t)return null;t.fillStyle="#f6ead2",t.fillRect(0,0,256,96),t.fillStyle="#5a3e2b",t.textAlign="center",t.textBaseline="middle";let s=40;const i=()=>`600 ${s}px Inter, system-ui, sans-serif`;for(t.font=i();t.measureText(o).width>228&&s>22;)s-=2,t.font=i();let n=o;for(;t.measureText(n).width>228&&n.length>2;)n=`${n.slice(0,-2)}…`;t.fillText(n,128,50);const a=new gt(e);return a.colorSpace=Qt,a}function Di(o){const{radius:e,seed:t,plots:s}=o,i=new J;i.name="scenery";const n=[],a=c=>(n.push(c),c),r=Ei(e,t);a(r.geometry),a(r.material),i.add(r);const d=Ai(e);a(d.mesh.geometry),a(d.material),i.add(d.mesh);const u=a(new Z({color:"#ffffff",transparent:!0,opacity:.32,depthWrite:!1})),p=new C(a(new at(e-.2,e+1.4,128)),u);p.rotation.x=-Math.PI/2,p.position.y=Ze+.06,i.add(p);const f=Ti();a(f.mesh.geometry),a(f.mesh.material),i.add(f.mesh);const h={wood:a(W("#b9875e")),darkWood:a(W("#7a563b")),leaf:a(W("#4f9d63")),leafLight:a(W("#62b273")),pine:a(W("#2f6f52")),pineLight:a(W("#3c8a62")),trunk:a(W("#8a5a3c")),rock:a(W("#b8b3aa",.9)),metal:a(W("#3c4b53",.5,.5)),white:a(W("#f6f3ec",.7)),red:a(W("#df5a4e",.7)),blue:a(W("#5b8bd9",.7)),stone:a(W("#d8ccb2",.9)),paper:a(W("#fbf7ee",.8)),lamp:a(new Z({color:"#ffe3a8"})),nightLamp:a(new Z({color:"#ffe3a8",transparent:!0,opacity:0,depthWrite:!1})),nightMetal:a(new me({color:"#3c4b53",roughness:.5,metalness:.5,transparent:!0,opacity:0})),star:a(new Z({color:"#ffd56b"})),seal:a(new Z({color:"#e0584f"})),light0:a(new Z({color:"#ffcf7a"})),light1:a(new Z({color:"#ff9f8a"})),light2:a(new Z({color:"#9fe0ff"})),light3:a(new Z({color:"#c8a8ff"})),path:a(W("#e7d9b9",.95)),plaza:a(W("#efe5cd",.9)),plazaInner:a(W("#e2d3b3",.9)),tileAgent:a(W("#a2d985",.95)),tileBot:a(W("#98d07c",.95)),tileEmpty:a(W("#b3d79c",.95)),tileEdge:a(W("#79b35f",.95)),playTile:a(W("#f3d9a4",.95))},l=new pt(h),m=a(new dt(1,1,1,2,.12)),b=a(new $e(.5,.5,1,12)),P=a(new ws(.5,1,9)),M=a(new zt(.5,1)),g=a(new zt(.5,0)),v=[],k=[],w=new es,E=[],j=new pt(h);n.push(w),i.add(w.group);const S=a(new $e(1,1,1,6)),I=a(new $e(.97,1,1,6)),V=Math.max(2,...s.map(c=>c.ring)),$=new Map(s.map(c=>[`${c.q},${c.r}`,c])),Y=`${tt.q},${tt.r}`;for(let c=0;c<=V;c++)for(const[x,_]of mt(c)){const z=qe(x,_);if(l.add("path",S,z.x,.01,z.z,{sx:Je-.02,sy:.02,sz:Je-.02}),c===0)continue;const T=$.get(`${x},${_}`),K=`${x},${_}`===Y?"playTile":T?T.owner.kind==="agent"?"tileAgent":"tileBot":"tileEmpty";l.add("tileEdge",S,z.x,Q/2-.005,z.z,{sx:Oe,sy:Q-.01,sz:Oe}),l.add(K,I,z.x,Q/2+.005,z.z,{sx:Oe-.08,sy:Q-.01,sz:Oe-.08})}l.add("plaza",I,0,Q/2,0,{sx:Je-.45,sy:Q,sz:Je-.45}),l.add("plazaInner",S,0,Q+.004,0,{sx:3.4,sy:.01,sz:3.4});const O=qe(tt.q,tt.r),L=mi({x:O.x,z:O.z,facing:ns(O.x,O.z),shadows:o.shadows});i.add(L.group);const D=Q;l.add("stone",b,0,D+.25,0,{sx:3,sy:.5,sz:3}),l.add("trunk",b,0,D+1,0,{sx:.6,sy:1.6,sz:.6}),[[1.5,3.6,2.2],[2.7,2.9,1.9],[3.8,2.2,1.6],[4.8,1.5,1.3]].forEach(([c,x,_],z)=>l.add(z%2?"pineLight":"pine",P,0,D+c+_/2,0,{sx:x,sy:_,sz:x})),l.add("star",M,0,D+6.35,0,{sx:.5,sy:.5,sz:.5}),k.push({cx:0,cz:0,hx:1.6,hz:1.6,yaw:0});const ye=a(new Qe(.07,8,6));for(let c=0;c<44;c++){const x=c/44,_=D+1.6+x*4.4,z=(1-x)*1.65+.2,T=x*Math.PI*9;l.add(`light${c%4}`,ye,Math.sin(T)*z,_,Math.cos(T)*z)}const re=new J,je=a(new dt(.36,.25,.05,1,.02)),ue=a(new Qe(.045,8,6)),xe=a(new $e(.008,.008,.3,4));for(let c=0;c<12;c++){const x=c/12*Math.PI*2+.3,_=D+2+c%3*.75,z=1.95-c%3*.35,T=new J;T.position.set(Math.sin(x)*z,_,Math.cos(x)*z),T.rotation.y=x;const K=new C(je,h.paper);K.position.y=-.18;const H=new C(ue,h.seal);H.position.set(0,-.18,.03);const Me=new C(xe,h.darkWood);Me.position.y=0,T.add(K,H,Me),T.visible=!1,T.userData.swing=c*1.7,re.add(T)}i.add(re);for(let c=0;c<6;c++){const x=c*Math.PI/3,_=4.5,z=Math.cos(x)*_,T=Math.sin(x)*_,K=Math.atan2(-z,-T);l.addAt(z,T,K,"wood",m,0,D+.27,0,{sx:1.9,sy:.08,sz:.5}),l.addAt(z,T,K,"wood",m,0,D+.55,-.24,{sx:1.9,sy:.32,sz:.07});for(const H of[-.8,.8])l.addAt(z,T,K,"darkWood",m,H,D+.13,0,{sx:.1,sy:.26,sz:.44});k.push({cx:z,cz:T,hx:.95,hz:.3,yaw:K});for(const H of[-.45,.45]){const Me=z+Math.cos(K)*H,_e=T-Math.sin(K)*H;v.push({key:`plaza:${c}:${H}`,kind:"seat",x:Me,z:_e,y:D+.3,face:K,plot:null,name:"a bench"})}}for(let c=0;c<6;c++){const x=Math.PI/6+c*Math.PI/3,_=it-1.3,z=Math.cos(x)*_,T=Math.sin(x)*_;l.add("metal",b,z,D+1.1,T,{sx:.12,sy:2.2,sz:.12}),l.add("metal",m,z,D+2.28,T,{sx:.34,sy:.08,sz:.34});const K=new C(m,h.lamp);K.scale.set(.26,.3,.26),K.position.set(z,D+2.1,T),i.add(K),E.push({x:z,y:D+.016,z:T,width:5.6,depth:5.6}),k.push({cx:z,cz:T,hx:.15,hz:.15,yaw:0})}const U=Math.PI+.35,he=e-4,ce=e+9,be=(he+ce)/2,ie=Math.sin(U),ee=Math.cos(U);l.add("wood",m,ie*be,.12,ee*be,{sx:2.2,sy:.14,sz:ce-he,ry:U});for(let c=he+1;c<=ce;c+=2.2)for(const x of[-1.15,1.15]){const _=ie*c+Math.cos(U)*x,z=ee*c-Math.sin(U)*x;l.add("darkWood",b,_,-.4,z,{sx:.18,sy:1.3,sz:.18})}const Re=ce+1.6,Ee=ie*Re+Math.cos(U)*2.2,ke=ee*Re-Math.sin(U)*2.2;l.add("white",m,Ee,Ze+.25,ke,{sx:1.5,sy:.6,sz:3.6,ry:U}),l.add("red",m,Ee,Ze+.42,ke,{sx:1.56,sy:.1,sz:3.66,ry:U}),l.add("blue",m,Ee+ie*.3,Ze+.85,ke+ee*.3,{sx:1,sy:.6,sz:1.2,ry:U});const A={x:ie*(ce-1),z:ee*(ce-1),face:U+Math.PI},N=[{cx:ie*be,cz:ee*be,hx:.9,hz:(ce-he)/2,yaw:U}];for(const c of[he+1,he+5.4,he+9.8]){const x=ie*c+Math.cos(U)*1.15,_=ee*c-Math.sin(U)*1.15;j.add("nightMetal",b,x,.55,_,{sx:.08,sy:.6,sz:.08}),j.add("nightLamp",M,x,.91,_,{sx:.24,sy:.3,sz:.24}),E.push({x:ie*c,y:.196,z:ee*c,width:2.1,depth:2.1})}const G=c=>nt(c*1.37,c*2.11,t+99),ne=U+1.9,te=c=>{const x=_=>Math.abs(Math.atan2(Math.sin(c-_),Math.cos(c-_)))<.18;return x(U)||x(ne)};for(let c=0;c<18;c++){const x=c/18*Math.PI*2+G(c)*.3;if(te(x))continue;const _=e-2.6+G(c+40)*1.2,z=Math.sin(x)*_,T=Math.cos(x)*_,K=(G(c+80)-.5)*.5,H=3.4+G(c+20)*1.6;for(let Se=0;Se<5;Se++){const ve=Se/5;l.add("trunk",b,z+Math.sin(x)*K*ve*H*.4,ve*H+H/10,T+Math.cos(x)*K*ve*H*.4,{sx:.32-ve*.1,sy:H/5+.05,sz:.32-ve*.1})}const Me=z+Math.sin(x)*K*H*.4,_e=T+Math.cos(x)*K*H*.4;for(let Se=0;Se<6;Se++){const ve=Se/6*Math.PI*2+c;l.add(Se%2?"leaf":"leafLight",P,Me+Math.sin(ve)*.9,H+.05,_e+Math.cos(ve)*.9,{sx:.5,sy:2,sz:.18,rx:Math.PI/2-.35,ry:ve})}l.add("leafLight",M,Me,H+.2,_e,{sx:.6,sy:.4,sz:.6}),k.push({cx:z,cz:T,hx:.3,hz:.3,yaw:0})}for(let c=0;c<10;c++){const x=G(c+200)*Math.PI*2;if(te(x))continue;const _=e-1.2+G(c+220)*2.2,z=.4+G(c+240)*.8;l.add("rock",g,Math.sin(x)*_,bt(_,e)+z*.25,Math.cos(x)*_,{sx:z*1.3,sy:z,sz:z,ry:c}),_<e-1&&k.push({cx:Math.sin(x)*_,cz:Math.cos(x)*_,hx:z*.6,hz:z*.6,yaw:0})}const F=Math.sin(ne)*(e-2.4),pe=Math.cos(ne)*(e-2.4);l.add("stone",b,F,.3,pe,{sx:2.6,sy:.6,sz:2.6});for(let c=0;c<5;c++)l.add(c%2?"red":"white",b,F,.6+c*1.1+.55,pe,{sx:1.7-c*.14,sy:1.1,sz:1.7-c*.14});l.add("metal",b,F,6.7,pe,{sx:1.3,sy:.15,sz:1.3}),l.add("red",P,F,7.75,pe,{sx:1.2,sy:.7,sz:1.2});const le=new C(m,h.lamp);le.scale.set(.8,.8,.8),le.position.set(F,7.15,pe),i.add(le),k.push({cx:F,cz:pe,hx:1.4,hz:1.4,yaw:0});const Ge=a(new xt(1.1,.42));for(const c of s){const x=Gt(c,o.residents);if(!x)continue;const _=c.radius*Math.sqrt(3)/2,z=Pe(c,-c.radius/2+.2,_-.45),T=c.facing*Math.PI/180;l.add("darkWood",m,z.x,D+.45,z.z,{sx:.1,sy:.9,sz:.1}),l.add("wood",m,z.x,D+.95,z.z,{sx:1.2,sy:.5,sz:.08,ry:T}),j.add("nightLamp",M,z.x,D+1.3,z.z,{sx:.26,sy:.2,sz:.26});const K=Pe(c,-c.radius/2+.2,_+.6);E.push({x:K.x,y:.036,z:K.z,width:6.5,depth:6.5});const H=Ri(x);if(H){a(H);const Me=a(new Z({map:H,side:ut})),_e=new C(Ge,Me);_e.position.set(z.x+Math.sin(T)*.05,D+.95,z.z+Math.cos(T)*.05),_e.rotation.y=T,i.add(_e)}k.push({cx:z.x,cz:z.z,hx:.15,hz:.15,yaw:0})}const Ke=l.build(o.shadows);Ke.traverse(c=>{const x=c;x.geometry&&a(x.geometry)}),i.add(Ke),w.replace(E);const ze=j.build(!1);ze.name="night-lanterns",ze.visible=!1,ze.traverse(c=>{const x=c;x.geometry&&a(x.geometry)}),i.add(ze);const De=new se("#ffe3a8"),ot=new se("#fff3d6"),rt=h.lamp;return k.push(...L.solids),v.push(...L.seats),n.push(L),{group:i,seats:v,solids:k,dock:A,walkways:N,deck:.19,playground:L,update(c,x,_,z){d.time.value=c,f.top.copy(_.top),f.horizon.copy(_.horizon),d.material.color.copy(z),u.opacity=.22+Math.sin(c*.9)*.08,rt.color.copy(ot).lerp(De,x).multiplyScalar(.75+x*.5),w.update(x),ze.visible=x>0,h.nightLamp.opacity=x,h.nightMetal.opacity=x;for(const T of re.children)T.visible&&(T.rotation.z=Math.sin(c*1.3+T.userData.swing)*.08)},setLetters(c){re.children.forEach((x,_)=>{x.visible=_<c})},dispose(){n.forEach(c=>c.dispose())}}}function Li(o,e,t){return t.some(s=>{const i=o-s.cx,n=e-s.cz,a=i*Math.cos(s.yaw)-n*Math.sin(s.yaw),r=i*Math.sin(s.yaw)+n*Math.cos(s.yaw);return Math.abs(a)<=s.hx+.2&&Math.abs(r)<=s.hz+.2})}function Ot(o){const e=[{h:0,top:"#0a1631",horizon:"#1c2b52",sea:"#1d3a5c",night:1,sun:"#9fb6ff",power:.35,hemi:.55},{h:5.5,top:"#0e1c3d",horizon:"#2a3966",sea:"#22416a",night:1,sun:"#9fb6ff",power:.35,hemi:.55},{h:6.6,top:"#5a78b8",horizon:"#ffc6a6",sea:"#4f8fb4",night:.4,sun:"#ffc59a",power:1.6,hemi:1},{h:8,top:"#79b8f0",horizon:"#e8f3fb",sea:"#5fbcd8",night:0,sun:"#fff4e2",power:2.7,hemi:1.45},{h:17.2,top:"#79b8f0",horizon:"#e8f3fb",sea:"#5fbcd8",night:0,sun:"#fff4e2",power:2.7,hemi:1.45},{h:18.8,top:"#5866b0",horizon:"#ffb487",sea:"#4a83ad",night:.35,sun:"#ffad7a",power:1.6,hemi:1},{h:20.3,top:"#13224a",horizon:"#3a3f6e",sea:"#244468",night:.9,sun:"#9fb6ff",power:.45,hemi:.6},{h:24,top:"#0a1631",horizon:"#1c2b52",sea:"#1d3a5c",night:1,sun:"#9fb6ff",power:.35,hemi:.55}],t=(o%24+24)%24;let s=0;for(;s<e.length-2&&e[s+1].h<=t;)s++;const i=e[s],n=e[s+1],a=Be(0,1,(t-i.h)/Math.max(1e-4,n.h-i.h)),r=(h,l)=>new se(h).lerp(new se(l),a),d=t>=6&&t<=19.5,p=(d?(t-6)/13.5:(t+24-19.5)%24/10.5)*Math.PI,f=new X(Math.cos(p)*60,Math.max(12,Math.sin(p)*80),d?-35:35);return{top:r(i.top,n.top),horizon:r(i.horizon,n.horizon),sea:r(i.sea,n.sea),night:i.night+(n.night-i.night)*a,sun:f,sunColor:r(i.sun,n.sun),sunIntensity:i.power+(n.power-i.power)*a,hemi:i.hemi+(n.hemi-i.hemi)*a}}function Wt(o,e,t="auto"){if(t!=="auto")return t;let s=Math.imul(o^Math.floor(e/72e4),73244475);s=Math.imul(s^s>>>16,73244475);const i=(s>>>0)%10;return i<5?"sunny":i<8?"cloudy":"rain"}function Ci(o,e){return o==="rain"&&e!=="sleep"}function Ni(o){const e=new J;e.name="rain-umbrella",e.visible=!1;const t=new C(new Qe(.72,16,8,0,Math.PI*2,0,Math.PI/2),new me({color:o,roughness:.65,side:ut}));t.scale.y=.45,t.position.set(.26,1.46,.08),e.add(t);const s=new C(new $e(.016,.016,.92,8),new me({color:"#4b5967",metalness:.5}));s.position.set(.26,1,.08),e.add(s);const i=new C(new at(.58,.8,48),new Z({color:"#ffd687",transparent:!0,opacity:.42,depthWrite:!1,side:ut,blending:yt}));return i.name="lead-aura",i.rotation.x=-Math.PI/2,i.position.y=.035,i.visible=!1,{umbrella:e,aura:i,dispose(){for(const n of[t,s,i])n.geometry.dispose(),n.material.dispose()}}}class Ii{object;positions=new Float32Array(450*3);constructor(){for(let t=0;t<450;t++)this.positions[t*3]=(t*.61803398875%1-.5)*70,this.positions[t*3+1]=t*.38196601125%1*24,this.positions[t*3+2]=(t*.754877666%1-.5)*70;const e=new Xt;e.setAttribute("position",new ks(this.positions,3)),this.object=new Ms(e,new vs({color:"#c6e3fa",size:.09,transparent:!0,opacity:.65,depthWrite:!1})),this.object.name="island-rain",this.object.visible=!1}update(e,t,s,i,n){if(this.object.visible=t==="rain",this.object.position.set(s,0,i),t!=="rain"||n)return;const a=this.object.geometry.getAttribute("position");for(let r=0;r<a.count;r++){const d=a.getY(r)-e*13;a.setY(r,d<.2?24:d)}a.needsUpdate=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}const Fe=Math.PI/180;class Oi{constructor(e){this.colors=e}colors;made=new Map;material(e){const t=`${e.tone}:${e.text}`,s=this.made.get(t);if(s)return s;if(typeof document>"u")return null;const i=document.createElement("canvas"),n=i.getContext("2d");if(!n)return null;const a=[...e.text].length<=2&&new RegExp("\\p{Extended_Pictographic}","u").test(e.text),r=a?"52px system-ui, 'Apple Color Emoji', 'Segoe UI Emoji', sans-serif":"700 46px Inter, system-ui, sans-serif";n.font=r;const d=Math.ceil(n.measureText(e.text).width),u=Math.max(128,Math.min(512,d+64));i.width=u,i.height=128;const{decide:p,danger:f}=this.colors(),h=e.tone==="decide"?p:e.tone==="danger"?f:e.tone==="sleep"?"#dfe9ff":"#ffffff",l=e.tone==="decide"||e.tone==="danger"?"#ffffff":"#33424d";n.fillStyle=h,n.strokeStyle="rgba(30, 40, 50, 0.18)",n.lineWidth=4,n.beginPath(),n.roundRect(14,12,u-28,84,34),n.moveTo(u/2-12,94),n.lineTo(u/2,116),n.lineTo(u/2+12,94),n.fill(),n.stroke(),n.fillStyle=l,n.font=r,n.textAlign="center",n.textBaseline="middle",n.fillText(e.text,u/2,a?58:56,u-40);const m=new gt(i);m.colorSpace=Qt;const b={material:new Ns({map:m,depthWrite:!1,transparent:!0}),aspect:u/128};return this.made.set(t,b),b}dispose(){for(const{material:e}of this.made.values())e.map?.dispose(),e.dispose();this.made.clear()}}function $t(o,e){return typeof document>"u"?e:getComputedStyle(document.documentElement).getPropertyValue(o).trim()||e}class Wi{constructor(e,t,s=!1){this.host=e,this.events=t,this.reducedMotion=s;const i=document.createElement("canvas");i.className="island-canvas",i.setAttribute("aria-hidden","true"),this.canvas=i,e.prepend(i);try{this.renderer=new zs({canvas:i,antialias:!0,powerPreference:"high-performance"})}catch(n){throw i.remove(),n}this.renderer.setPixelRatio(Math.min(window.devicePixelRatio||1,1.75)),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=_s,this.renderer.toneMapping=Ss,this.renderer.toneMappingExposure=1.02,this.scene.fog=new Ps("#e8f3fb",90,420),this.scene.add(this.society.root,this.buildingLights.group),this.scene.add(this.hemi,this.sun,this.sun.target,this.proxies,this.rain.object),this.proxies.visible=!1,this.sun.castShadow=!0,this.sun.shadow.mapSize.set(2048,2048),this.sun.shadow.bias=-4e-4,this.sun.shadow.normalBias=.03,this.controls=new Xs(this.camera,i),this.controls.enableDamping=!0,this.controls.dampingFactor=.08,this.controls.screenSpacePanning=!1,this.controls.minPolarAngle=.18,this.controls.maxPolarAngle=1.18,this.controls.minDistance=4,this.controls.maxDistance=140,this.controls.zoomSpeed=.8,this.controls.rotateSpeed=.6,this.controls.addEventListener("start",()=>{this.flight=null}),this.camera.position.set(22,31,33),this.controls.target.set(0,0,0),this.nav=new Tt(40),this.sim=new ji(this.nav,{seats:[],plots:new Map,tree:{x:0,z:0},plaza:it,radius:40}),this.sim.onWishRegister=n=>this.events.onWishRegister?.(n),this.sim.onWishGiveUp=n=>this.events.onWishGiveUp?.(n),this.bubbles=new Oi(()=>({decide:$t("--decide","#3d7bd9"),danger:$t("--danger","#d6544b")})),this.shadowMaterial=new Z({color:"#1e2a24",transparent:!0,opacity:.22,depthWrite:!1}),this.ring=new C(new at(.55,.68,40),new Z({color:"#ffffff",transparent:!0,opacity:.85,depthWrite:!1})),this.ring.rotation.x=-Math.PI/2,this.ring.visible=!1,this.scene.add(this.ring),i.addEventListener("pointerdown",this.onDown),i.addEventListener("pointerup",this.onUp),i.addEventListener("pointermove",this.onMove),i.addEventListener("pointerleave",this.onLeave),i.addEventListener("webglcontextlost",this.onContextLost),document.addEventListener("visibilitychange",this.onVisibility),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("keyup",this.onKeyUp),window.addEventListener("blur",this.onBlur),this.resize=new ResizeObserver(()=>this.fit()),this.resize.observe(e),this.fit(),this.start()}host;events;reducedMotion;weatherChoice="auto";rain=new Ii;setWeather(e){this.weatherChoice=e,this.hourAt=-1}renderer;scene=new js;camera=new Es(38,1,.1,1400);controls;hemi=new As("#eef6ff","#c8b58a",1.4);sun=new Ts("#fff4e2",2.6);gardenBeds=new Map;society=Gs();scenery=null;sceneryKey="";buildingLights=new es({interior:!0});buildingLightsKey="";cache=new Rs;placed=new Map;robots=new Map;proxies=new J;sim;nav;island=null;residents=[];bubbles;frame=0;last=0;clock=0;hourAt=-1;hour=12;hourOverride=null;sky=Ot(12);selected=null;following=!1;held=new Set;flight=null;labels=null;hovered=null;pointer=new de;pointerAt=null;raycaster=new Ds;faded=new Map;fadedMaterials=new Map;ring;shadowGeometry=new Ht(.42,24);shadowMaterial;proxyGeometry=new Ve(1.3,1.6,1.3);resize;firstLoad=!0;lost=!1;canvas;tiled=new Set;setLabels(e,t){this.labels={hover:e,selected:t}}setReducedMotion(e){this.reducedMotion=e}setHourOverride(e){this.hourOverride=e,this.hourAt=-1}fit(){const e=Math.max(1,this.host.clientWidth),t=Math.max(1,this.host.clientHeight);this.renderer.setSize(e,t,!1),this.camera.aspect=e/t,this.camera.fov=this.camera.aspect<1?Math.min(62,38/Math.sqrt(this.camera.aspect)):38,this.camera.updateProjectionMatrix()}start(){this.frame||this.lost||document.hidden||(this.last=performance.now(),this.frame=requestAnimationFrame(this.draw))}stop(){cancelAnimationFrame(this.frame),this.frame=0}onVisibility=()=>{document.hidden?this.stop():this.start()};onContextLost=e=>{e.preventDefault(),this.lost=!0,this.stop(),this.events.onLost?.()};setIsland(e,t){const s=Vt(e,t);e=s.island,t=s.residents;const i=new Set(this.residents.map(g=>g.key));this.island=e,this.residents=t;const n=new Map(e.assets.map(g=>[g.id,g])),a=new Map(e.plots.map(g=>[g.id,g])),r=JSON.stringify([e.radius,e.seed,e.plots.map(g=>[g.id,g.q,g.r,g.x,g.z,g.facing,g.radius,g.owner.kind,Gt(g,t)])]);if(r!==this.sceneryKey||!this.scenery){this.scenery&&(this.scene.remove(this.scenery.group),this.scenery.dispose()),this.scenery=Di({radius:e.radius,seed:e.seed,plots:e.plots,residents:t,shadows:!0}),this.scene.add(this.scenery.group),this.sceneryKey=r;const g=Math.max(2,...e.plots.map(w=>w.ring));this.tiled=new Set;for(let w=1;w<=g;w++)for(const[E,j]of mt(w))this.tiled.add(`${E},${j}`);const v=e.radius+8,k=this.sun.shadow.camera;k.left=-v,k.right=v,k.top=v,k.bottom=-v,k.near=1,k.far=260,k.updateProjectionMatrix(),this.controls.maxDistance=Math.max(60,e.radius*2.6)}const d=this.scenery;d.setLetters(e.wishes.filter(g=>g.state==="open").length);const u=new Set,p=[...d.solids,...this.society.solids],f=[],h=[...d.seats],l=[];for(const g of e.placed){const v=a.get(g.plot),k=n.get(g.asset);if(!v||!k||k.kind==="accessory")continue;u.add(g.id);const w=[k.id,k.rev,g.x,g.z,g.y,g.turn,v.x,v.z,v.facing].join(":");let E=this.placed.get(g.id);if(!E||E.signature!==w){E&&this.scene.remove(E.object);const I=St(this.cache.get(k),{shadows:!0}),V=Pe(v,g.x,g.z);I.position.set(V.x,Q+g.y,V.z),I.rotation.y=(v.facing+g.turn)*Fe,I.userData.placement=g.id,I.userData.kind=k.kind,this.scene.add(I),E={object:I,signature:w},this.placed.set(g.id,E)}p.push(...Bi(k,v,g)),k.kind==="building"&&l.push({asset:k,view:E});const j=Ys(k,v,g);j&&f.push(j);const S=Fi(k,v,g);S&&(S.owner=s.deskOwners.get(g.id),S.key+=`:${S.x}:${S.z}:${S.y}:${S.face}`,h.push(S))}for(const[g,v]of[...this.placed])u.has(g)||(this.scene.remove(v.object),this.placed.delete(g));const m=l.map(({view:g})=>`${g.object.userData.placement}:${g.signature}`).join("|");m!==this.buildingLightsKey&&(this.buildingLights.replace(l.flatMap(({asset:g,view:v})=>(v.object.updateMatrix(),li(g).map(k=>({...k,transform:v.object.matrix}))))),this.buildingLightsKey=m),this.nav=new Tt(e.radius,p,1.5,d.walkways);for(const g of f)if(!(this.nav.isFree(g)&&this.nav.path({x:0,z:0},g)))for(let v=.5;v<=7;v+=.5){let k=!1;for(let w=0;w<8;w++){const E=w*Math.PI/4,j={x:g.x+Math.sin(E)*v,z:g.z+Math.cos(E)*v};if(this.nav.isFree(j)&&this.nav.path({x:0,z:0},j)){g.face=Math.atan2(g.x-j.x,g.z-j.z),Object.assign(g,j),k=!0;break}}if(k)break}for(const[g,v]of this.gardenBeds){const k=f.find(w=>w.key===g&&w.activity==="garden");k?v.root.position.set(k.x+Math.sin(k.face)*.65,Q+.02,k.z+Math.cos(k.face)*.65):(this.scene.remove(v.root),v.dispose(),this.gardenBeds.delete(g))}const b={seats:h,activities:f,plots:new Map(t.filter(g=>g.plot).map(g=>{const v=g.plot,k=Pe(v,0,0),w=Pe(v,0,v.radius*Math.sqrt(3)/2-1.2);return[g.key,{id:v.id,center:k,door:w,front:{...w,face:v.facing*Fe}}]})),tree:{x:0,z:0},plaza:it,radius:e.radius,playground:d.playground.anchors},P=this.clock;if(this.sim.reset(this.nav,b,t,P),this.sim.setWishQueue(e.wishes.filter(g=>g.state==="queued").sort((g,v)=>g.madeAt-v.madeAt||g.id.localeCompare(v.id)).map(g=>({id:g.id,key:`agent:${g.who.id}`}))),this.firstLoad)this.frameEveryone(e.plots);else for(const g of t)i.has(g.key)||g.owner.kind!=="bot"||this.sim.landAt(g.key,d.dock,P);this.firstLoad=!1;const M=new Set;for(const g of t){const v=JSON.stringify({...g.look,worn:void 0}),k=kt.map(E=>{const j=g.look.worn[E],S=j?n.get(j):void 0;return S&&S.kind==="accessory"&&M.add(S.id),S&&S.kind==="accessory"?`${E}:${S.id}:${S.rev}`:""}).join("|");let w=this.robots.get(g.key);if(w&&w.look!==v&&(this.dropRobot(g.key),w=void 0),w||(w=this.addRobot(g.key,g,v)),w.atmosphere.aura.visible=!!g.agent?.leader,w.worn!==k){for(const E of kt){const j=g.look.worn[E],S=j?n.get(j):void 0;w.rig.wear(E,S&&S.kind==="accessory"?this.accessory(S,E):null)}w.worn=k}}for(const g of[...this.robots.keys()])t.some(v=>v.key===g)||this.dropRobot(g);this.selected&&!this.robots.has(this.selected)&&this.select(null),this.cache.prune(new Set([...e.placed.map(g=>g.asset),...M]))}accessory(e,t){const s=St(this.cache.get(e),{shadows:!1});return s.name=`worn-${t}`,s}addRobot(e,t,s){const i=Kt(t.look);i.root.userData.robot=e;const n=new C(this.shadowGeometry,this.shadowMaterial);n.rotation.x=-Math.PI/2;const a=new C(this.proxyGeometry,this.shadowMaterial);a.userData.robot=e;const r=new Ls;r.scale.set(.6,.6,1),r.visible=!1,this.scene.add(i.root,n,r),this.proxies.add(a);const d=Ni(t.look.trim);i.root.add(d.umbrella,d.aura);const u=Zs();this.scene.add(u.root);const p=Hs();i.anchors.hand.add(p.root);const f={activity:p,concert:u,rig:i,atmosphere:d,look:s,worn:"",shadow:n,proxy:a,bubble:r,bubbleKey:""};return this.robots.set(e,f),f}dropRobot(e){const t=this.robots.get(e);t&&(this.scene.remove(t.rig.root,t.shadow,t.bubble),this.proxies.remove(t.proxy),t.rig.dispose(),t.atmosphere.dispose(),t.activity.dispose(),this.scene.remove(t.concert.root),t.concert.dispose(),this.robots.delete(e))}setModes(e){this.sim.setModes(e,this.clock)}event(e,t){this.sim.event(e,t,this.clock)}homeChanged(e){this.sim.buildHome(e,this.clock)}describe(e){return this.sim.describe(e)}mood(e){const t=this.sim.mood(e);return t?{...t,said:this.sim.said(e)}:null}select(e,t=!0){if(this.selected=e,this.following=!!e,this.ring.visible=!!e,!e){this.restoreFaded(),this.labels&&(this.labels.selected.hidden=!0);return}const s=this.sim.robots.get(e);s&&t&&this.flyTo(new X(s.x,.6,s.z),13)}frameEveryone(e){const t=[{x:0,z:0},...e.map(r=>({x:r.x,z:r.z}))],s={x:t.reduce((r,d)=>r+d.x,0)/t.length,z:t.reduce((r,d)=>r+d.z,0)/t.length},i=Math.max(14,...t.map(r=>Math.hypot(r.x-s.x,r.z-s.z)+7)),n=Math.min(this.controls.maxDistance,i*1.85),a=new X(22,31,33).setLength(n);this.controls.target.set(s.x,0,s.z),this.camera.position.copy(this.controls.target).add(a),this.controls.update()}recenter(){this.select(null),this.flyTo(new X(0,0,0),Math.max(46,(this.island?.radius??40)*1.15))}flyTo(e,t){const s=this.camera.position.distanceTo(this.controls.target);if(this.reducedMotion){const i=this.camera.position.clone().sub(this.controls.target).setLength(t);this.controls.target.copy(e),this.camera.position.copy(e).add(i),this.flight=null;return}this.flight={from:this.controls.target.clone(),to:e,fromDistance:s,toDistance:t,start:this.clock,seconds:.9}}robotAt(e,t){const s=this.canvas.getBoundingClientRect();return this.pointer.set((e-s.left)/s.width*2-1,-((t-s.top)/s.height)*2+1),this.raycaster.setFromCamera(this.pointer,this.camera),this.proxies.updateMatrixWorld(!0),this.raycaster.intersectObjects(this.proxies.children,!1)[0]?.object.userData.robot??null}assetAt(e,t){const s=this.canvas.getBoundingClientRect();this.pointer.set((e-s.left)/s.width*2-1,-((t-s.top)/s.height)*2+1),this.raycaster.setFromCamera(this.pointer,this.camera);for(const i of this.raycaster.intersectObjects([...this.placed.values()].map(n=>n.object),!0))for(const[n,a]of this.placed){let r=i.object;for(;r;){if(r===a.object)return n;r=r.parent}}return null}onDown=e=>{this.pointerAt={x:e.clientX,y:e.clientY,time:performance.now()}};onUp=e=>{const t=this.pointerAt;if(this.pointerAt=null,!t||Math.hypot(e.clientX-t.x,e.clientY-t.y)>6||performance.now()-t.time>500)return;const i=this.robotAt(e.clientX,e.clientY);if(i){this.events.onPick(i);return}const n=this.assetAt(e.clientX,e.clientY);if(n){const a=this.sim.useAsset(n);a&&this.events.onPick(a);return}this.events.onPick(null)};onMove=e=>{if(e.pointerType!=="mouse"||e.buttons)return;const t=this.robotAt(e.clientX,e.clientY);this.hovered=t,this.canvas.style.cursor=t||this.assetAt(e.clientX,e.clientY)?"pointer":""};onLeave=()=>{this.hovered=null,this.canvas.style.cursor=""};draw=e=>{this.frame=requestAnimationFrame(this.draw);const t=Math.min(.1,Math.max(0,(e-this.last)/1e3));this.last=e,this.clock+=t;const s=this.clock;if(Math.floor(s)!==this.hourAt){this.hourAt=Math.floor(s);const f=new Date;this.hour=this.hourOverride??f.getHours()+f.getMinutes()/60+f.getSeconds()/3600,this.sky=Ot(this.hour),Cs(this.sky.night),this.buildingLights.update(this.sky.night),this.sun.position.copy(this.sky.sun),this.sun.color.copy(this.sky.sunColor);const h=Wt(this.island?.seed??1,Date.now(),this.weatherChoice);this.sun.intensity=this.sky.sunIntensity*(h==="rain"?.35:h==="cloudy"?.65:1),this.hemi.intensity=this.sky.hemi,this.hemi.color.copy(new se("#eef6ff").lerp(new se("#7f93c9"),this.sky.night)),this.scene.fog.color.copy(this.sky.horizon)}this.sim.update(t,s,this.hour);const i=this.reducedMotion,n=this.island?.radius??40,a=Wt(this.island?.seed??1,Date.now(),this.weatherChoice);this.rain.update(t,a,this.controls.target.x,this.controls.target.z,i),this.scenery?.playground.setMotion(this.sim.motion);const r=new Set;for(const[f,h]of this.robots){const l=this.sim.robots.get(f);if(!l)continue;const m=this.groundAt(l.x,l.z,n),b=Pt.has(l.pose),P=l.perched?Math.max(l.y,m):m;h.rig.root.position.set(l.x,P,l.z),h.rig.root.rotation.y=l.heading,h.concert.root.position.set(l.x,m,l.z),h.concert.root.rotation.y=l.heading,h.concert.update(l.pose==="dance"&&this.sim.audience(f)>0,t,s,i);const M=l.plan.act;h.activity.show(M.kind==="wish-register"?"register":M.kind==="interact"&&!l.path.length?M.site.activity:null);const g=M.kind==="work"&&M.seat?.kind==="desk"&&!l.path.length;if(Yt(h.rig,l.pose,s+Ut(f)%97*.13,{stride:l.stride,calm:i,console:!g&&M.kind!=="interact",lean:l.lean,bored:l.boredom>.72}),M.kind==="interact"&&!l.path.length){if(M.site.activity==="read")h.rig.head.rotation.x=.18,h.rig.arms.forEach(w=>{w.shoulder.rotation.x=-.65,w.elbow.rotation.x=-.85});else if(M.site.activity==="garden"||M.site.activity==="paint"){if(M.site.activity==="garden"){r.add(M.site.key);let w=this.gardenBeds.get(M.site.key);w||(w=Us(),w.root.position.set(M.site.x+Math.sin(M.site.face)*.65,Q+.02,M.site.z+Math.cos(M.site.face)*.65),this.scene.add(w.root),this.gardenBeds.set(M.site.key,w))}h.rig.arms[0].shoulder.rotation.x=-.7,h.rig.arms[0].elbow.rotation.x=-.5+(i?0:Math.sin(s*3)*.16),h.activity.root.rotation.z=M.site.activity==="garden"?-.35:0}}else h.activity.root.rotation.z=0;const v=Ci(a,l.pose);h.atmosphere.umbrella.visible=v,h.atmosphere.umbrella.position.y=b?-lt:0,v&&(h.rig.arms[1].shoulder.rotation.set(-.5,0,-.35),h.rig.arms[1].elbow.rotation.x=-.7),h.atmosphere.aura.scale.setScalar(i?1:1+Math.sin(s*1.6)*.06),h.atmosphere.aura.position.y=m-P+.035,h.shadow.position.set(l.x,m+.025,l.z),h.shadow.scale.setScalar(l.perched&&P-m>.15?.7:1),h.proxy.position.set(l.x,P+(b?.45:.6),l.z),h.proxy.rotation.y=l.heading;const k=l.bubble;if(k){const w=`${k.tone}:${k.text}`;if(w!==h.bubbleKey){const S=this.bubbles.material(k);S&&(h.bubble.material=S.material,h.bubble.scale.set(.6*S.aspect,.6,1)),h.bubbleKey=w}const E=P+(b?1-lt:1),j=i?0:Math.sin(s*2.4+Ut(f))*.03;h.bubble.position.set(l.x,E+.55+j,l.z),h.bubble.visible=!0}else h.bubble.visible=!1}for(const[f,h]of this.gardenBeds)h.update(t,r.has(f));if(this.scenery?.update(i?0:s,this.sky.night,this.sky,this.sky.sea),this.flight){const f=Math.min(1,(s-this.flight.start)/this.flight.seconds),h=1-Math.pow(1-f,3),l=this.flight.from.clone().lerp(this.flight.to,h),m=this.flight.fromDistance+(this.flight.toDistance-this.flight.fromDistance)*h,b=this.camera.position.clone().sub(this.controls.target).setLength(m);this.controls.target.copy(l),this.camera.position.copy(l).add(b),f>=1&&(this.flight=null)}this.panByKeys(t);const d=this.selected?this.sim.robots.get(this.selected):void 0;if(d){if(this.following){const f=new X(d.x,.6,d.z);if(this.flight)this.flight.to.copy(f);else{const h=f.sub(this.controls.target).multiplyScalar(Math.min(1,t*3));this.controls.target.add(h),this.camera.position.add(h)}}this.ring.position.set(d.x,this.groundAt(d.x,d.z,n)+.03,d.z),this.ring.scale.setScalar(i?1:1+Math.sin(s*2)*.04),Math.floor(s*8)!==Math.floor((s-t)*8)&&this.fadeOccluders(d.x,d.z)}const u=this.controls.target,p=Math.hypot(u.x,u.z);p>n+4&&u.multiplyScalar((n+4)/p),u.y=Math.max(0,Math.min(2,u.y)),this.controls.update(),this.placeLabels(),this.renderer.render(this.scene,this.camera)};onKeyDown=e=>{const t=e.key.toLowerCase();!$i.has(t)||e.metaKey||e.ctrlKey||e.altKey||Ui(e.target)||this.held.add(t)};onKeyUp=e=>{this.held.delete(e.key.toLowerCase()),e.key==="Shift"&&this.held.delete("shift")};onBlur=()=>this.held.clear();panByKeys(e){if(!this.held.size)return;const t=this.controls.target.clone().sub(this.camera.position);if(t.y=0,t.lengthSq()<1e-6)return;t.normalize();const s=new X(-t.z,0,t.x),i=new X;if(this.held.has("w")&&i.add(t),this.held.has("s")&&i.sub(t),this.held.has("d")&&i.add(s),this.held.has("a")&&i.sub(s),i.lengthSq()<1e-6)return;const n=this.camera.position.distanceTo(this.controls.target),a=Math.min(28,Math.max(4,n*.4))*(this.shift?2.2:1);i.normalize().multiplyScalar(a*e),this.controls.target.add(i),this.camera.position.add(i),this.flight=null,this.following=!1}get shift(){return this.held.has("shift")}groundAt(e,t,s){const i=this.scenery;if(i&&Li(e,t,i.walkways))return i.deck;const[n,a]=os(e,t);return n===0&&a===0?Math.hypot(e,t)<it-.6?Q:0:this.tiled.has(`${n},${a}`)&&as(e,t)?Q:bt(Math.hypot(e,t),s)}placeLabels(){if(!this.labels)return;const e=(t,s)=>{const i=s?this.sim.robots.get(s):void 0,n=s?this.robots.get(s):void 0;if(!i||!n){t.hidden=!0;return}const a=Pt.has(i.pose),r=n.rig.root.position.y-(a?lt:0),d=new X(i.x,r,i.z).project(this.camera);if(d.z>1){t.hidden=!0;return}const u=this.canvas.getBoundingClientRect(),p=(d.x*.5+.5)*u.width,f=(-d.y*.5+.5)*u.height;t.hidden=!1;const h=this.residents.find(l=>l.key===s)?.name??"";t.textContent!==h&&(t.textContent=h),t.style.transform=`translate(${p.toFixed(1)}px, ${f.toFixed(1)}px) translate(-50%, 6px)`};e(this.labels.selected,this.selected),e(this.labels.hover,this.hovered&&this.hovered!==this.selected?this.hovered:null)}fadeOccluders(e,t){const s=new X(e,.8,t),i=this.camera.position.clone(),n=s.clone().sub(i),a=n.length();this.raycaster.set(i,n.normalize()),this.raycaster.far=a-.4;const r=[...this.placed.values()].map(p=>p.object),d=this.raycaster.intersectObjects(r,!0);this.raycaster.far=1/0;const u=new Set;for(const p of d){const f=p.object.parent;if(f)for(const h of f.children)h instanceof C&&u.add(h)}for(const[p,f]of[...this.faded])u.has(p)||(p.material=f,this.faded.delete(p));for(const p of u)this.faded.has(p)||(this.faded.set(p,p.material),p.material=this.fadedOf(p.material))}fadedOf(e){let t=this.fadedMaterials.get(e);return t||(t=e.clone(),t.transparent=!0,t.opacity=.2,t.depthWrite=!1,this.fadedMaterials.set(e,t)),t}restoreFaded(){for(const[e,t]of this.faded)e.material=t;this.faded.clear()}dispose(){this.stop(),this.resize.disconnect(),this.canvas.removeEventListener("pointerdown",this.onDown),this.canvas.removeEventListener("pointerup",this.onUp),this.canvas.removeEventListener("pointermove",this.onMove),this.canvas.removeEventListener("pointerleave",this.onLeave),this.canvas.removeEventListener("webglcontextlost",this.onContextLost),document.removeEventListener("visibilitychange",this.onVisibility),window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("keyup",this.onKeyUp),window.removeEventListener("blur",this.onBlur),this.controls.dispose(),this.restoreFaded();for(const e of[...this.robots.keys()])this.dropRobot(e);for(const e of this.placed.values())this.scene.remove(e.object);this.placed.clear(),this.cache.dispose(),this.buildingLights.dispose(),this.scenery?.dispose(),this.bubbles.dispose(),this.rain.dispose(),this.society.dispose();for(const e of this.gardenBeds.values())this.scene.remove(e.root),e.dispose();this.gardenBeds.clear(),this.fadedMaterials.forEach(e=>e.dispose()),this.shadowGeometry.dispose(),this.shadowMaterial.dispose(),this.proxyGeometry.dispose(),this.ring.geometry.dispose(),this.ring.material.dispose(),this.renderer.dispose(),this.renderer.forceContextLoss(),this.canvas.remove()}}const $i=new Set(["w","a","s","d","shift"]);function Ui(o){const e=o;return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable]:not([contenteditable='false'])")}function Ut(o){let e=0;for(const t of o)e=e*31+(t.codePointAt(0)??0)>>>0;return e%1e3}function Bi(o,e,t){const s=[],i=(e.facing+t.turn)*Fe,n=t.turn*Fe;for(const a of o.parts){const r=Xe(a),d=r.min[1]+t.y,u=r.max[1]+t.y;if(d>.55||u<.16)continue;const p=(r.min[0]+r.max[0])/2,f=(r.min[2]+r.max[2])/2,h=t.x+p*Math.cos(n)+f*Math.sin(n),l=t.z-p*Math.sin(n)+f*Math.cos(n),m=Pe(e,h,l);s.push({cx:m.x,cz:m.z,hx:(r.max[0]-r.min[0])/2,hz:(r.max[2]-r.min[2])/2,yaw:i})}return s}function Fi(o,e,t){const s=o.name.toLowerCase(),i=o.use??(/\b(chair|bench|stool)\b|椅|凳/.test(s)?"seat":/\bbed\b|床/.test(s)?"bed":/\b(table|desk|workbench)\b|桌|工作台/.test(s)?"desk":void 0);if(!i||!["seat","desk","bed"].includes(i)||o.kind!=="furniture"&&o.kind!=="decor")return null;let n=o.spot;if(!n){const l=o.parts.map(Xe),m=Math.max(...l.map(M=>M.max[2])),b=l.filter(M=>M.max[1]<(i==="seat"?.65:.9)),P=b.length?Math.max(...b.map(M=>M.max[1])):.3;n=i==="desk"?{at:[0,0,m+.45],face:180}:{at:[0,P+.03,0],face:0}}const a=t.turn*Fe,[r,d,u]=n.at,p=t.x+r*Math.cos(a)+u*Math.sin(a),f=t.z-r*Math.sin(a)+u*Math.cos(a),h=Pe(e,p,f);return{key:`${t.id}:${o.id}`,kind:i==="desk"?"desk":i==="bed"?"bed":"seat",x:h.x,z:h.z,y:Q+t.y+d,face:(e.facing+t.turn+n.face)*Fe,plot:e.id,name:o.name}}const Bt=[{id:"often",label:"Often"},{id:"sometimes",label:"Sometimes"},{id:"rarely",label:"Rarely"},{id:"never",label:"Never"}],Gi={cozy:"Cozy",curious:"Curious",sporty:"Sporty",artsy:"Artsy",tinkerer:"Tinkerer",dreamy:"Dreamy",foodie:"Foodie",gardener:"Gardener"};function Ji({connected:o,snapshot:e,projects:t,running:s,busy:i,waitingOn:n,held:a,chatTitle:r,chatExists:d,onAsk:u,onOpenChat:p,onClose:f}){const h=Os(o),{rows:l,team:m,teams:b}=rs({connected:o,snapshot:e,projects:t,running:s,busy:i,waitingOn:n,held:a,chatTitle:r,chatExists:d}),P=hs(),M=R.useMemo(()=>(m??[]).map(c=>({id:c.id,name:c.name,agent:c.agent,model:c.model,avatar:c.avatar,teamId:c.teamId,teamName:b.find(x=>x.id===c.teamId)?.name,leader:!c.reportsTo||(m??[]).some(x=>x.reportsTo===c.id)})),[m,b]),g=R.useMemo(()=>h.island?ls(h.island,M):[],[h.island,M]),v=R.useMemo(()=>h.island?Vt(h.island,g).residents:[],[h.island,g]),k=h.island?.wishes.filter(c=>c.state==="queued").length??0,w=R.useMemo(()=>h.island?cs(h.island):[],[h.island]),E=R.useMemo(()=>Ws(l),[l]),j=R.useMemo(()=>JSON.stringify([...E]),[E]),S=R.useRef(null),I=R.useRef(null),V=R.useRef(null),$=R.useRef(null),[Y,O]=R.useState("starting"),[L,D]=R.useState(null),[ge,ye]=R.useState(null),[re,je]=R.useState(null),[ue,xe]=R.useState(()=>typeof window<"u"&&window.innerWidth>860),[U,he]=R.useState(null),[ce,be]=R.useState(null),[ie,ee]=R.useState(!1),[Re,Ee]=R.useState(0),[ke,A]=R.useState("auto");R.useEffect(()=>{$.current?.setWeather(ke)},[ke,Y]);const N=JSON.stringify([...i].filter(c=>c.startsWith("chat:island-wish-")).sort());R.useEffect(()=>{o&&h.reload()},[o,N,h.reload]),R.useEffect(()=>{const c=S.current;if(!c)return;const x=window.matchMedia?.("(prefers-reduced-motion: reduce)");let _;try{_=new Wi(c,{onPick:T=>D(T),onLost:()=>O("lost"),onWishGiveUp:T=>{Ie.invoke("island_wish_withdraw",{id:T}).catch(()=>{})},onWishRegister:T=>{Ie.invoke("island_wish_register",{id:T}).catch(()=>{})}},!!x?.matches)}catch{O("no");return}I.current&&V.current&&_.setLabels(I.current,V.current),$.current=_,O("yes");const z=()=>_.setReducedMotion(!!x?.matches);return x?.addEventListener?.("change",z),()=>{x?.removeEventListener?.("change",z),_.dispose(),$.current=null}},[Re]),R.useEffect(()=>{h.island&&$.current&&$.current.setIsland(h.island,g)},[h.island,g,Y]);const G=R.useRef(E);G.current=E,R.useEffect(()=>{$.current?.setModes(G.current)},[j,Y,g]);const ne=R.useRef(0);R.useEffect(()=>{const c=h.change,x=h.island;if(!(!c||!x||x.rev<c.rev||ne.current>=c.rev)){if(ne.current=c.rev,c.what==="grant"&&c.id){const _=x.wishes.find(T=>T.id===c.id),z=_&&ht(_,g);z&&$.current?.event("gift",z.key)}c.what==="home"&&c.id&&$.current?.homeChanged(c.id)}},[h.change,h.island,g]),R.useEffect(()=>{$.current?.select(L)},[L]),R.useEffect(()=>{if(!L){ye(null),je(null);return}const c=()=>{ye($.current?.describe(L)??null);const _=$.current?.mood(L)??null;je(z=>z&&_&&Math.round(z.boredom*100)===Math.round(_.boredom*100)&&z.excited===_.excited&&z.said===_.said?z:_)};c();const x=window.setInterval(c,500);return()=>window.clearInterval(x)},[L]),R.useEffect(()=>{const c=x=>{x.key==="Escape"&&L&&D(null)};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[L]);const te=async(c,x)=>{if(!U){he(c),be(null);try{await x()}catch(_){be(String(_?.message??_))}finally{he(null)}}},F=L?v.find(c=>c.key===L):void 0,pe=F?.agent?l.find(c=>c.id===F.agent.id):void 0,le=c=>w.find(x=>x.who.kind===c.owner.kind&&x.who.id===c.owner.id),Ge=R.useMemo(()=>(h.island?.wishes??[]).filter(c=>c.state==="granted").sort((c,x)=>(x.closedAt??x.madeAt)-(c.closedAt??c.madeAt)).slice(0,20),[h.island]),Ke=c=>ht(c,g)?.name??"A robot who left",ze=c=>{te(`grant:${c.id}`,()=>h.grantWish(c.id))},De=c=>U===`grant:${c.id}`||i.has(`chat:island-wish-${c.id}`)||c.execution?.state==="building",ot=c=>c?.activities.find(x=>x.chatKey)?.chatKey??c?.recent?.chatKey??null,rt=y.jsxs(y.Fragment,{children:[y.jsxs("button",{type:"button",className:"projects-page-secondary island-wishes-button","aria-expanded":ue,"aria-controls":"island-panel",onClick:()=>xe(c=>!c),title:w.length?`${w.length} open ${w.length===1?"wish":"wishes"}`:"Wishes and residents",children:[y.jsx(Ft,{}),y.jsx("span",{children:"Wishes"}),w.length>0&&y.jsx("span",{className:"island-count",children:w.length})]}),y.jsxs("button",{type:"button",className:"projects-page-secondary island-compact",onClick:()=>{D(null),$.current?.recenter()},disabled:Y!=="yes","aria-label":"See the whole island",title:"See the whole island",children:[y.jsx(qi,{}),y.jsx("span",{children:"Whole island"})]})]});return y.jsxs("section",{className:"projects-page island-page","aria-label":"Island",children:[y.jsx(ds,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:f},title:y.jsx("h1",{children:"Island"}),actions:rt}),ce&&y.jsx("p",{className:"island-error",role:"alert",children:ce}),y.jsxs("div",{className:`island-body${ue?" has-panel":""}`,children:[y.jsxs("div",{className:"island-stage",ref:S,role:"img","aria-label":`The island in 3D, with ${g.length} robots. Use the panel's list to find someone.`,children:[y.jsx("div",{className:"island-name",ref:I,hidden:!0}),y.jsx("div",{className:"island-name is-selected",ref:V,hidden:!0}),Y==="no"&&y.jsx("p",{className:"island-note",role:"status",children:"This browser cannot draw the island in 3D here. The wishes and residents are in the panel."}),Y==="lost"&&y.jsxs("div",{className:"island-note",role:"status",children:[y.jsx("p",{children:"The 3D view stopped."}),y.jsx("button",{type:"button",className:"projects-page-secondary",onClick:()=>{O("starting"),Ee(c=>c+1)},children:"Draw it again"})]}),!h.island&&!h.error&&Y!=="no"&&y.jsx("p",{className:"island-note is-quiet",role:"status",children:"Sailing to the island…"}),h.error&&!h.island&&y.jsxs("div",{className:"island-note",role:"alert",children:[y.jsx("p",{children:h.error}),y.jsx("button",{type:"button",className:"projects-page-secondary",onClick:h.reload,children:"Try again"})]}),F&&y.jsx(Hi,{resident:F,row:pe,status:ge,mood:re,housemates:F.plot?v.filter(c=>c.plot?.id===F.plot?.id&&c.key!==F.key).map(c=>c.name):[],wish:le(F),busy:!!U||!o,onGrant:ze,building:!!le(F)&&De(le(F)),onOpenChat:c=>p(c),chatKey:ot(pe),onAsk:F.agent?()=>u(F.agent.id,"On the OctiqFlow island, build yourself "):void 0,onFarewell:F.owner.kind==="bot"?async()=>{await P({title:`Say goodbye to ${F.name}?`,body:`${F.name} sails away. Its plot, what stands on it and its open wish go with it.`,confirmLabel:"Say goodbye",danger:!0})&&(D(null),await te("farewell",()=>h.farewell(F.owner.id)))}:void 0,onClose:()=>D(null)})]}),ue&&y.jsxs("aside",{id:"island-panel",className:"island-panel","aria-label":"Wishes and residents",children:[y.jsxs("div",{className:"island-panel-head",children:[y.jsx("h2",{children:"Wishes"}),y.jsx("button",{type:"button",className:"island-close","aria-label":"Close the panel",title:"Close",onClick:()=>xe(!1),children:y.jsx(ss,{})})]}),k>0&&y.jsxs("p",{className:"island-meta",children:[k," waiting to register at BOT Society"]}),w.length===0?y.jsx("p",{className:"island-empty",children:"No wishes right now. Robots make one now and then."}):y.jsx("ul",{className:"island-wishes",children:w.map(c=>{const x=ht(c,g);return y.jsxs("li",{className:"island-wish",children:[y.jsxs("button",{type:"button",className:"island-wish-who",onClick:()=>x&&D(x.key),disabled:!x,title:x?`Show ${x.name}`:void 0,children:[y.jsx(ft,{resident:x}),y.jsx("bdi",{children:Ke(c)}),y.jsx("span",{className:"island-meta",children:$s(c.madeAt)})]}),y.jsxs("p",{className:"island-wish-text",children:["wishes for ",y.jsx("bdi",{children:c.text})]}),c.execution?.state==="unfinished"&&!De(c)&&y.jsx("p",{className:"island-meta",role:"status",children:"The present is not finished. Retry to continue."}),y.jsxs("div",{className:"island-wish-actions",children:[y.jsx("button",{type:"button",className:"projects-page-primary island-grant",onClick:()=>ze(c),disabled:!!U||De(c)||!o,title:"Build this present in the background",children:De(c)?"Building…":c.execution?"Retry":"Grant"}),y.jsx("button",{type:"button",className:"projects-page-secondary",disabled:!!U,onClick:()=>{te(`dismiss:${c.id}`,()=>h.dismissWish(c.id))},children:"Dismiss"})]})]},c.id)})}),y.jsxs("div",{className:"island-pace",children:[y.jsx("label",{htmlFor:"island-weather",children:"Island weather"}),y.jsxs("select",{id:"island-weather",value:ke,onChange:c=>A(c.target.value),children:[y.jsx("option",{value:"auto",children:"Automatic"}),y.jsx("option",{value:"sunny",children:"Sunny"}),y.jsx("option",{value:"cloudy",children:"Cloudy"}),y.jsx("option",{value:"rain",children:"Rain"})]}),y.jsx("label",{htmlFor:"island-building",children:"Autonomous building"}),y.jsx("select",{id:"island-building",value:h.island?.settings.buildPace??"sometimes",disabled:!h.island||!!U,onChange:c=>{te("building",()=>h.setBuildPace(c.target.value))},children:Bt.map(c=>y.jsx("option",{value:c.id,children:c.label},c.id))}),y.jsx("label",{htmlFor:"island-pace",children:"New wishes"}),y.jsx("select",{id:"island-pace",value:h.island?.settings.wishPace??"sometimes",disabled:!h.island||!!U,onChange:c=>{te("pace",()=>h.setPace(c.target.value))},children:Bt.map(c=>y.jsx("option",{value:c.id,children:c.label},c.id))}),y.jsx("button",{type:"button",className:"projects-page-secondary",disabled:!h.island||!!U,onClick:()=>{te("roll",h.rollWish)},children:"Ask for a wish"})]}),Ge.length>0&&y.jsxs("div",{className:"island-granted",children:[y.jsxs("button",{type:"button",className:"island-disclosure","aria-expanded":ie,onClick:()=>ee(c=>!c),children:[y.jsx(Xi,{open:ie}),"Granted · ",Ge.length]}),ie&&y.jsx("ul",{children:Ge.map(c=>y.jsxs("li",{children:[y.jsx("bdi",{children:Ke(c)})," got ",y.jsx("bdi",{children:c.text}),c.grant?.by.name&&y.jsxs("span",{className:"island-meta",children:[" · from ",y.jsx("bdi",{children:c.grant.by.name})]})]},c.id))})]}),y.jsx("h2",{className:"island-panel-sub",children:"Who lives here"}),y.jsx("ul",{className:"island-residents",children:g.map(c=>{const x=c.agent?l.find(_=>_.id===c.agent.id):void 0;return y.jsx("li",{children:y.jsxs("button",{type:"button","aria-pressed":L===c.key,onClick:()=>D(c.key),children:[y.jsx(ft,{resident:c}),y.jsx("bdi",{className:"island-resident-name",children:c.name}),y.jsx("span",{className:"island-meta",children:c.agent?Yi(x):ts(c)}),le(c)&&y.jsx("span",{className:"island-has-wish",title:"Has a wish",children:y.jsx(Ft,{})})]})},c.key)})})]})]})]})}function Ki(o){return o.length<=1?o[0]??"":`${o.slice(0,-1).join(", ")} & ${o[o.length-1]}`}function ts(o){const e=Gi[o.trait??""];return e?`${e} 波特`:"波特"}function Yi(o){switch(o?.state){case"working":return"Working";case"needs_you":return"Needs you";case"failed":return"Failed";default:return"Agent"}}function Hi({resident:o,row:e,status:t,mood:s,housemates:i,wish:n,busy:a,building:r,chatKey:d,onGrant:u,onOpenChat:p,onAsk:f,onFarewell:h,onClose:l}){const m=o.agent,b=e?.state==="needs_you"?"decide":e?.state==="failed"?"danger":void 0;return y.jsxs("div",{className:"island-card",role:"dialog","aria-label":o.name,children:[y.jsxs("div",{className:"island-card-head",children:[m?y.jsx(us,{name:m.name,id:m.id,avatar:m.avatar,size:30,decorative:!0}):y.jsx(ft,{resident:o,large:!0}),y.jsxs("div",{className:"island-card-who",children:[y.jsx("bdi",{className:"island-card-name",children:o.name}),y.jsx("span",{className:"island-meta",children:m?"Agent":ts(o)})]}),y.jsx("button",{type:"button",className:"island-close","aria-label":"Stop following",title:"Stop following",onClick:l,children:y.jsx(ss,{})})]}),t&&y.jsx("p",{className:"island-card-status","data-tone":b,children:t}),!!o.hobbies?.length&&y.jsxs("p",{className:"island-meta",children:["Interests: ",o.hobbies.join(", ")]}),o.plot?.officeName&&y.jsxs("p",{className:"island-meta",children:[o.plot.officeName," · Personal desk"]}),i.length>0&&y.jsxs("p",{className:"island-meta island-card-home",children:["Office with ",y.jsx("bdi",{children:Ki(i)})]}),s?.said&&y.jsxs("p",{className:"island-card-said",children:["“",y.jsx("bdi",{children:s.said}),"”"]}),s&&y.jsx(Zi,{boredom:s.boredom,excited:s.excited}),n&&y.jsxs("div",{className:"island-card-wish",children:[y.jsxs("p",{children:["Wishes for ",y.jsx("bdi",{children:n.text})]}),n.execution?.state==="unfinished"&&!r&&y.jsx("p",{className:"island-meta",role:"status",children:"The present is not finished. Retry to continue."}),y.jsx("button",{type:"button",className:"projects-page-primary island-grant",disabled:a||r,onClick:()=>u(n),children:r?"Building…":n.execution?"Retry":"Grant"})]}),y.jsxs("div",{className:"island-card-actions",children:[d&&y.jsx("button",{type:"button",className:"projects-page-secondary",onClick:()=>p(d),children:"Open chat"}),f&&y.jsx("button",{type:"button",className:"projects-page-secondary",onClick:f,title:"Start a chat with this agent about something to build for itself",children:"Ask to build"}),h&&y.jsx("button",{type:"button",className:"projects-page-secondary",disabled:a,onClick:h,children:"Say goodbye"})]})]})}function Zi({boredom:o,excited:e}){const t=Math.round(o*100);return y.jsxs("div",{className:"island-boredom",children:[y.jsx("span",{className:"island-meta",children:e?"Excited: work came!":"Boredom"}),y.jsx("span",{className:"island-boredom-bar",role:"meter","aria-label":"Boredom","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":t,children:y.jsx("span",{style:{width:`${t}%`}})}),y.jsxs("span",{className:"island-meta island-boredom-value",children:[t,"%"]})]})}function ft({resident:o,large:e=!1}){const t=o?{"--robot-shell":o.look.shell,"--robot-trim":o.look.trim,"--robot-glow":o.look.glow}:void 0;return y.jsx("span",{className:`island-dot${e?" is-large":""}`,style:t,"aria-hidden":"true",children:y.jsx("span",{})})}function Ft(){return y.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[y.jsx("rect",{x:"3",y:"8",width:"18",height:"4",rx:"1"}),y.jsx("path",{d:"M12 8v13M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7"}),y.jsx("path",{d:"M7.5 8a2.5 2.5 0 0 1 0-5C9 3 12 8 12 8s3-5 4.5-5a2.5 2.5 0 0 1 0 5"})]})}function qi(){return y.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[y.jsx("path",{d:"M2 18c3 0 3-1.5 5-1.5S10 18 12 18s3-1.5 5-1.5 2 1.5 5 1.5"}),y.jsx("path",{d:"M5 15c2-3 12-3 14 0"}),y.jsx("path",{d:"M12 13V6M12 6c-1.5-2-4-2-5.5-.5M12 6c1.5-2 4-2 5.5-.5M12 6c-.5-2 .5-3.5 2-4"})]})}function ss(){return y.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:y.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function Xi({open:o}){return y.jsx("svg",{className:`island-chevron${o?" is-open":""}`,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:y.jsx("path",{d:"m9 6 6 6-6 6"})})}export{Ji as default};
|
|
Binary file
|
|
Binary file
|