octiqflow-darwin-arm64 0.3.13 → 0.3.19
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-Ch0SrxvK.js +8 -0
- package/bin/v2/assets/IslandPage-Ch0SrxvK.js.br +0 -0
- package/bin/v2/assets/IslandPage-Ch0SrxvK.js.gz +0 -0
- package/bin/v2/assets/IslandPage-DHBBz06A.css +1 -0
- package/bin/v2/assets/IslandPage-DHBBz06A.css.br +0 -0
- package/bin/v2/assets/IslandPage-DHBBz06A.css.gz +0 -0
- package/bin/v2/assets/{index-DgVqfi3n.js → index-53w9dbcs.js} +1 -1
- package/bin/v2/assets/index-53w9dbcs.js.br +0 -0
- package/bin/v2/assets/index-53w9dbcs.js.gz +0 -0
- package/bin/v2/assets/{index-EbE9Equf.js → index-BTym0syk.js} +1 -1
- 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 +1 -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 +1 -0
- 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 +1 -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-BtOXjqUr.js → index-CUWHqfQT.js} +204 -151
- 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-CkkiNkM6.js → index-CayFcoA2.js} +4 -4
- 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-CKZbCF5Y.js → index-CiHfu8PZ.js} +1 -1
- 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 +3 -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-9ROAFG8N.js → index-D6gUr_hW.js} +1 -1
- 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 +1 -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 +1 -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 +13 -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/orbitron-latin-700-normal-4jsRXGGJ.woff2 +0 -0
- package/bin/v2/assets/orbitron-latin-700-normal-DmYOh-W9.woff +0 -0
- package/bin/v2/assets/portrait-Bon7JcMe.js +1 -0
- 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 +4108 -0
- package/bin/v2/assets/robot-C9LkSRnk.js.br +0 -0
- package/bin/v2/assets/robot-C9LkSRnk.js.gz +0 -0
- package/bin/v2/index.html +2 -2
- package/package.json +1 -1
- package/bin/v2/assets/index-9ROAFG8N.js.br +0 -0
- package/bin/v2/assets/index-9ROAFG8N.js.gz +0 -0
- package/bin/v2/assets/index-BXVOMy73.css +0 -1
- package/bin/v2/assets/index-BXVOMy73.css.br +0 -0
- package/bin/v2/assets/index-BXVOMy73.css.gz +0 -0
- package/bin/v2/assets/index-BhWK4R0o.js +0 -1
- package/bin/v2/assets/index-BhWK4R0o.js.br +0 -0
- package/bin/v2/assets/index-BhWK4R0o.js.gz +0 -0
- package/bin/v2/assets/index-BtOXjqUr.js.br +0 -0
- package/bin/v2/assets/index-BtOXjqUr.js.gz +0 -0
- package/bin/v2/assets/index-C0op0LaU.js +0 -1
- package/bin/v2/assets/index-C0op0LaU.js.br +0 -0
- package/bin/v2/assets/index-C0op0LaU.js.gz +0 -0
- package/bin/v2/assets/index-CKZbCF5Y.js.br +0 -0
- package/bin/v2/assets/index-CKZbCF5Y.js.gz +0 -0
- package/bin/v2/assets/index-CkkiNkM6.js.br +0 -0
- package/bin/v2/assets/index-CkkiNkM6.js.gz +0 -0
- package/bin/v2/assets/index-DNdWJa_x.js +0 -13
- package/bin/v2/assets/index-DNdWJa_x.js.br +0 -0
- package/bin/v2/assets/index-DNdWJa_x.js.gz +0 -0
- package/bin/v2/assets/index-DV3dNMS1.js +0 -1
- package/bin/v2/assets/index-DV3dNMS1.js.br +0 -0
- package/bin/v2/assets/index-DV3dNMS1.js.gz +0 -0
- package/bin/v2/assets/index-DgVqfi3n.js.br +0 -0
- package/bin/v2/assets/index-DgVqfi3n.js.gz +0 -0
- package/bin/v2/assets/index-EbE9Equf.js.br +0 -0
- package/bin/v2/assets/index-EbE9Equf.js.gz +0 -0
- package/bin/v2/assets/index-RUqxFSoX.js +0 -3
- package/bin/v2/assets/index-RUqxFSoX.js.br +0 -0
- package/bin/v2/assets/index-RUqxFSoX.js.gz +0 -0
- package/bin/v2/assets/index-_HwsVN5C.js +0 -1
- package/bin/v2/assets/index-_HwsVN5C.js.br +0 -0
- package/bin/v2/assets/index-_HwsVN5C.js.gz +0 -0
package/bin/octiq-server
CHANGED
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{r as L,b as De,a as lt,T as Le,c as Ke,d as Xt,p as Ee,e as V,C as Xe,f as It,P as et,g as Qt,S as ft,o as Vt,h as Jt,u as es,i as ts,j as ss,k as is,w as nt,l as y,W as ns,A as as}from"./index-CUWHqfQT.js";import{G as ne,B as Ze,M as ke,a as O,c as Ot,p as Wt,C as dt,b as X,d as st,A as $t,S as He,e as Ut,R as it,f as os,V as Q,g as Ie,T as Ce,Q as mt,h as gt,i as ue,j as rs,P as hs,k as cs,m as ls,l as rt,n as Ne,o as ds,I as yt,q as Bt,D as ht,r as he,s as Ft,t as xt,u as us,v as ps,w as Gt,F as fs,x as ms,y as gs,W as ys,z as xs,E as ws,H as bs,J as ks,K as Ms,L as vs,N as zs,O as _s,U as Ss,X as wt,Y as Ps,Z as bt,_ as at,$ as js}from"./robot-C9LkSRnk.js";const Es=r=>String(r?.message??r);function As(r){const[e,t]=L.useState(null),[s,i]=L.useState(null),[n,a]=L.useState(null),o=L.useRef(null),l=L.useRef(0),d=L.useCallback(()=>{const p=++l.current;De.invoke("island_get").then(h=>{if(p!==l.current||!h?.island)return;const c=h.island;o.current&&o.current.rev>c.rev||(o.current=c,t(c),i(null))}).catch(h=>{p===l.current&&i(Es(h))})},[]);L.useEffect(()=>{if(!r)return;d();const p=De.on("island-changed",c=>{c&&(o.current&&c.rev<=o.current.rev||(a(c),d()))}),h=De.on("chat-status",c=>{c?.key.startsWith("chat:island-wish-")&&d()});return()=>{p(),h()}},[r,d]);const u=L.useCallback(async(p,h={})=>{await De.invoke(p,h),d()},[d]);return{island:e,error:s,change:n,reload:d,dismissWish:p=>u("island_wish_dismiss",{id:p}),grantWish:p=>u("island_wish_start",{id:p}),rollWish:()=>u("island_wish_roll"),inviteBot:()=>u("island_bot_invite"),farewell:p=>u("island_bot_farewell",{id:p}),setPace:p=>u("island_settings_set",{wishPace:p}),setBuildPace:p=>u("island_build_pace",{pace:p})}}function Ts(r,e=Date.now()){const t=new Map;for(const s of r){const i=a=>s.activities.find(o=>o.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 Rs(r,e=Date.now()){const t=Math.max(0,Math.round((e-r)/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 Yt(r,e){const t=new Map;for(const h of[...e].sort((c,m)=>c.key.localeCompare(m.key))){const c=h.agent?.teamId?`team:${h.agent.teamId}`:"general";t.set(c,[...t.get(c)??[],h])}t.has("general")||t.set("general",[]);const s=[],i=r.assets.filter(h=>h.kind==="accessory"),n=[],a=[],o=new Map,l=r.plots.filter(h=>h.owner.kind==="home"&&h.owner.id.startsWith("public:")||r.placed.some(c=>c.plot===h.id&&r.assets.some(m=>m.id===c.asset&&m.kind==="building"&&m.name!=="Workshop"))),d=[];for(let h=1;d.length<t.size+l.length;h++)d.push(...lt(h).filter(([c,m])=>(c!==-1||m!==0)&&(c!==0||m!==-1)));const u=(h,c,m)=>({shape:"box",size:h,at:c,color:m});for(const[h,[c,m]]of[...t].sort(([b],[g])=>b.localeCompare(g)).entries()){const[b,g]=d[h],x=Ke(b,g),k=`office:${c}`,z=c==="general"?"Agent Tower":`${m[0].agent?.teamName??"Team"} Office`,v={id:k,owner:{kind:"home",id:c},ring:Math.max(Math.abs(b),Math.abs(g),Math.abs(b+g)),slot:h,q:b,r:g,...x,facing:Math.atan2(-x.x,-x.z)*180/Math.PI,radius:Le,claimedAt:0,members:m.map(A=>A.owner.id),officeName:z};s.push(v);const M=Math.max(c==="general"?3:1,Math.ceil(m.length/6)),E=[];for(let A=0;A<M;A++){const T=A*2.3;E.push(u([8,.08,6],[0,T+.04,-.7],"#d6dce5")),E.push({...u([8,2,.14],[0,T+1,-3.6],"#b6c9dd"),finish:"glass"}),E.push({...u([.16,2.3,6],[-3.95,T+1.15,-.7],"#7a94b1"),finish:"glass"}),E.push({...u([.16,2.3,6],[3.95,T+1.15,-.7],"#7a94b1"),finish:"glass"});for(const K of[-2.7,0,2.7])E.push({...u([1.5,1,.025],[K,T+1.2,-3.51],"#b5e5fa"),finish:"glass"})}i.push({id:k,rev:M,name:z,kind:"building",parts:E,by:{name:"Island offices"},madeAt:0,updatedAt:0}),n.push({id:k,asset:k,plot:k,x:0,z:0,y:0,turn:0});for(const[A,T]of m.entries()){a.push({...T,plot:v});const K=`office-desk:${T.key}`,J=(A%3-1)*2.4,N=Math.floor(A%6/3)*2.5-2.4,C=Math.floor(A/6)*2.3;i.push({id:K,rev:Number.parseInt(T.look.trim.slice(1)+T.look.glow.slice(1),16),name:`${T.name}'s desk`,kind:"furniture",use:"desk",spot:{at:[0,0,.65],face:180},parts:[u([1.3,.08,.7],[0,.6,0],"#cfa783"),u([.12,.6,.12],[-.5,.3,0],T.look.trim),u([.12,.6,.12],[.5,.3,0],T.look.trim),u([.65,.42,.08],[0,.88,-.18],"#26354a"),{...u([.55,.32,.02],[0,.88,-.13],T.look.glow),finish:"glow"}],by:{name:T.name,agentId:T.owner.id},madeAt:0,updatedAt:0}),n.push({id:K,asset:K,plot:k,x:J,z:N,y:C,turn:0}),o.set(K,T.key);const B=r.placed.filter($=>$.plot===T.plot?.id).filter($=>{const F=r.assets.find(pe=>pe.id===$.asset);return F&&F.kind!=="building"&&F.name!=="Workshop"&&F.name!=="Desk"&&F.use!=="bed"});for(const[$,F]of B.entries()){const pe=r.assets.find(xe=>xe.id===F.asset);i.some(xe=>xe.id===pe.id)||i.push(pe);const ye=(A+$/Math.max(1,B.length))/m.length*Math.PI*2;n.push({...F,plot:k,x:Math.sin(ye)*4.8,z:Math.cos(ye)*4.8,y:0})}}}for(const[h,c]of l.entries()){const[m,b]=d[t.size+h],g=Ke(m,b),x=r.placed.filter(v=>v.plot===c.id&&r.assets.some(M=>M.id===v.asset&&(c.owner.kind==="home"||M.kind==="building"&&M.name!=="Workshop"))),k=r.assets.find(v=>x.some(M=>M.asset===v.id)&&v.kind==="building"),z={...c,q:m,r:b,...g,ring:Math.max(Math.abs(m),Math.abs(b),Math.abs(m+b)),facing:Math.atan2(-g.x,-g.z)*180/Math.PI,officeName:k?.name??"Public project"};s.push(z),n.push(...x);for(const v of x){const M=r.assets.find(E=>E.id===v.asset);M&&!i.some(E=>E.id===M.id)&&i.push(M)}}const p=Math.max(30,r.radius,...s.map(h=>Math.hypot(h.x,h.z)+Le+4));return{island:{...r,plots:s,assets:i,placed:n,radius:p},residents:a,deskOwners:o}}function Ds(){const r=new ne;r.name="planted-seedlings";const e=new ne;r.add(e);const t=new Ze(1,1,1),s=new ke({color:"#88674b"}),i=new ke({color:"#64a856"}),n=new O(t,s);n.scale.set(.8,.035,.45),n.position.y=.02,r.add(n);for(const o of[-.26,0,.26]){const l=new O(t,i);l.scale.set(.025,.3,.025),l.position.set(o,.17,0),e.add(l);for(const d of[-1,1]){const u=new O(t,i);u.scale.set(.17,.045,.08),u.position.set(o+d*.07,.23,0),u.rotation.z=d*.4,e.add(u)}}let a=0;return{root:r,update(o,l){l&&(a=Math.min(1,a+o/12)),e.scale.setScalar(.12+a*.88),r.visible=a>0},dispose(){t.dispose(),s.dispose(),i.dispose()}}}const re=Ke(0,-1),Ls={x:re.x,z:re.z-.8};function Cs(r){return{x:re.x+(r%4-1.5)*1.6,z:re.z+.6+Math.floor(r/4)*1}}function Ns(){const r=new ne;r.name="bot-society",r.position.set(re.x,.05,re.z);const e=new Ze(1,1,1),t=new ke({color:"#ded8c9",roughness:.8}),s=new ke({color:"#caa45c",metalness:.5,roughness:.3}),i=new ke({color:"#b8e5f0",transparent:!0,opacity:.22,depthWrite:!1}),n=(h,c,m,b,g,x,k=t)=>{const z=new O(e,k);z.position.set(h,c,m),z.scale.set(b,g,x),r.add(z)};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=Xt({id:"bot-society-statue",agent:"codex",model:"sol"}),o=Ot({...a,shell:"#d7c592",trim:"#a98642",glow:"#fff2af",antenna:"crown"});Wt(o,"raise",0,{calm:!0}),o.root.scale.setScalar(4.5),o.root.position.set(0,1.15,-3.7),r.add(o.root);const l=document.createElement("canvas");l.width=768,l.height=128;const d=l.getContext("2d");d.fillStyle="#f7e8bd",d.fillRect(0,0,768,128),d.fillStyle="#5d4828",d.font="bold 56px sans-serif",d.textAlign="center",d.fillText("BOT SOCIETY",384,80);const u=new dt(l),p=new X({map:u});return n(0,3.15,3.02,4.8,.8,.04,p),{root:r,solids:[{cx:re.x-3.9,cz:re.z,hx:.08,hz:3.5,yaw:0},{cx:re.x+3.9,cz:re.z,hx:.08,hz:3.5,yaw:0},{cx:re.x,cz:re.z-1.6,hx:1.7,hz:.45,yaw:0},{cx:re.x,cz:re.z-3.7,hx:1.4,hz:1.1,yaw:0}],dispose(){o.dispose(),e.dispose(),t.dispose(),s.dispose(),i.dispose(),u.dispose(),p.dispose()}}}function Is(r){if(r.kind==="accessory"||r.use==="none")return null;if(["read","paint","garden","perform","play","observe"].includes(r.use??""))return r.use;const e=r.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)&&!r.use?null:!r.use&&/\b(table|desk|workbench)\b|桌|工作台/.test(e)?/workbench|工作台/.test(e)?"play":"read":r.use==="desk"?/workbench|工作台/.test(e)?"play":"read":r.use==="seat"||r.use==="bed"?null:r.kind==="building"||r.kind==="furniture"||r.kind==="decor"?"observe":null}function Os(r,e,t){if(t.id.startsWith("office-desk:"))return null;const s=Is(r);if(!s||!r.parts.length)return null;const i=Math.max(...r.parts.map(h=>st(h).max[2])),n=Math.max(0,...r.parts.map(h=>st(h)).filter(h=>h.max[1]<=.35&&h.max[1]-h.min[1]<=.16).map(h=>h.max[1])),a=r.spot??(r.kind==="building"&&s!=="observe"?{at:[0,n,0],face:180}:{at:[0,0,i+.85],face:180}),o=t.turn*Math.PI/180,[l,d,u]=a.at,p=Ee(e,t.x+l*Math.cos(o)+u*Math.sin(o),t.z-l*Math.sin(o)+u*Math.cos(o));return{key:t.id,name:r.name,activity:s,...p,y:V+t.y+d,face:(e.facing+t.turn+a.face)*Math.PI/180}}function kt(r,e){const t={garden:"gardening",read:"reading",paint:"painting",perform:"music",play:"games"};return e==="observe"||!!r?.includes(t[e])}function Ws(){const r=new ne,e=new Ze(1,1,1),t=["#f1e7cb","#6b86b6","#f5a14a","#76b9a5","#71c7ff"].map(u=>new X({color:u})),s=(u,p,h)=>{const c=new ne;c.name=u;const m=new O(e,t[h]);return m.scale.set(...p),c.add(m),r.add(c),c.visible=!1,c},i=s("read",[.32,.24,.05],1),n=s("paint",[.035,.32,.035],2),a=s("garden",[.22,.16,.17],3),o=s("register",[.24,.3,.02],0),l=s("play",[.25,.1,.1],1),d=new O(e,t[4]);return d.scale.set(.18,.035,.035),d.position.x=.16,a.add(d),{root:r,show(u){for(const p of[i,n,a,o,l])p.visible=p.name===u},dispose(){e.dispose(),t.forEach(u=>u.dispose())}}}function $s(){const r=new ne;r.name="concert-stage";const e=new X({color:"#253044"}),t=new X({color:"#9d8dff"}),s=new X({color:"#c2a1ff",transparent:!0,opacity:.32,depthWrite:!1}),i=new X({color:"#b997ff",transparent:!0,opacity:.13,depthWrite:!1,blending:$t}),n=new He(.75,20,12),a=new O(n,i);a.position.y=.65,r.add(a);const o=new Ze(.5,.8,.4),l=new Ut(.16,20),d=new it(.7,1.25,40),u=new O(d,s);u.rotation.x=-Math.PI/2,u.position.y=.05,r.add(u);const p=[];for(const c of[-1,1]){const m=new ne;m.position.set(c*1.2,.4,0),m.add(new O(o,e));for(const b of[-.19,.19]){const g=new O(l,t);g.position.set(0,b,.205),m.add(g)}r.add(m),p.push(m)}r.visible=!1;let h=0;return{root:r,update(c,m,b,g){h=Math.max(0,Math.min(1,h+(c?1:-1)*m*3)),r.visible=h>0;const x=g?1:1+Math.sin(b*8)*.09;r.scale.setScalar(Math.max(.001,h)),u.scale.setScalar(x),a.scale.setScalar(x),s.opacity=.24+(g?0:(Math.sin(b*8)+1)*.1),p.forEach(k=>k.scale.set(1,x,x))},dispose(){n.dispose(),i.dispose(),o.dispose(),l.dispose(),d.dispose(),e.dispose(),t.dispose(),s.dispose()}}}const Mt={type:"change"},ut={type:"start"},Kt={type:"end"},Qe=new rs,vt=new hs,Us=Math.cos(70*cs.DEG2RAD),q=new Q,oe=2*Math.PI,U={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},ot=1e-6;class Bs extends os{constructor(e,t=null){super(e,t),this.state=U.NONE,this.target=new Q,this.cursor=new Q,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:Ie.ROTATE,MIDDLE:Ie.DOLLY,RIGHT:Ie.PAN},this.touches={ONE:Ce.ROTATE,TWO:Ce.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 Q,this._lastQuaternion=new mt,this._lastTargetPosition=new Q,this._quat=new mt().setFromUnitVectors(e.up,new Q(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new gt,this._sphericalDelta=new gt,this._scale=1,this._panOffset=new Q,this._rotateStart=new ue,this._rotateEnd=new ue,this._rotateDelta=new ue,this._panStart=new ue,this._panEnd=new ue,this._panDelta=new ue,this._dollyStart=new ue,this._dollyEnd=new ue,this._dollyDelta=new ue,this._dollyDirection=new Q,this._mouse=new ue,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Gs.bind(this),this._onPointerDown=Fs.bind(this),this._onPointerUp=Ys.bind(this),this._onContextMenu=Vs.bind(this),this._onMouseWheel=Zs.bind(this),this._onKeyDown=qs.bind(this),this._onTouchStart=Xs.bind(this),this._onTouchMove=Qs.bind(this),this._onMouseDown=Ks.bind(this),this._onMouseMove=Hs.bind(this),this._interceptControlDown=Js.bind(this),this._interceptControlUp=ei.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(Mt),this.update(),this.state=U.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===U.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+=oe:s>Math.PI&&(s-=oe),i<-Math.PI?i+=oe:i>Math.PI&&(i-=oe),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 o=q.length();a=this._clampDistance(o*this._scale);const l=o-a;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),n=!!l}else if(this.object.isOrthographicCamera){const o=new Q(this._mouse.x,this._mouse.y,0);o.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),n=l!==this.object.zoom;const d=new Q(this._mouse.x,this._mouse.y,0);d.unproject(this.object),this.object.position.sub(d).add(o),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):(Qe.origin.copy(this.object.position),Qe.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Qe.direction))<Us?this.object.lookAt(this.target):(vt.setFromNormalAndCoplanarPoint(this.object.up,this.target),Qe.intersectPlane(vt,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)>ot||8*(1-this._lastQuaternion.dot(this.object.quaternion))>ot||this._lastTargetPosition.distanceToSquared(this.target)>ot?(this.dispatchEvent(Mt),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?oe/60*this.autoRotateSpeed*e:oe/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,o=s.height;this._mouse.x=i/a*2-1,this._mouse.y=-(n/o)*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(oe*this._rotateDelta.x/t.clientHeight),this._rotateUp(oe*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(oe*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(-oe*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(oe*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(-oe*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(oe*this._rotateDelta.x/t.clientHeight),this._rotateUp(oe*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,o=(e.pageY+t.y)*.5;this._updateZoomParameters(a,o)}_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 ue,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 Fs(r){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(r.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(r)&&(this._addPointer(r),r.pointerType==="touch"?this._onTouchStart(r):this._onMouseDown(r),this._cursorStyle==="grab"&&(this.domElement.style.cursor="grabbing")))}function Gs(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchMove(r):this._onMouseMove(r))}function Ys(r){switch(this._removePointer(r),this._pointers.length){case 0:this.domElement.releasePointerCapture(r.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Kt),this.state=U.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 Ks(r){let e;switch(r.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 Ie.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(r),this.state=U.DOLLY;break;case Ie.ROTATE:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=U.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=U.ROTATE}break;case Ie.PAN:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=U.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=U.PAN}break;default:this.state=U.NONE}this.state!==U.NONE&&this.dispatchEvent(ut)}function Hs(r){switch(this.state){case U.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(r);break;case U.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(r);break;case U.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(r);break}}function Zs(r){this.enabled===!1||this.enableZoom===!1||this.state!==U.NONE||(r.preventDefault(),this.dispatchEvent(ut),this._handleMouseWheel(this._customWheelEvent(r)),this.dispatchEvent(Kt))}function qs(r){this.enabled!==!1&&this._handleKeyDown(r)}function Xs(r){switch(this._trackPointer(r),this._pointers.length){case 1:switch(this.touches.ONE){case Ce.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(r),this.state=U.TOUCH_ROTATE;break;case Ce.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(r),this.state=U.TOUCH_PAN;break;default:this.state=U.NONE}break;case 2:switch(this.touches.TWO){case Ce.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(r),this.state=U.TOUCH_DOLLY_PAN;break;case Ce.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(r),this.state=U.TOUCH_DOLLY_ROTATE;break;default:this.state=U.NONE}break;default:this.state=U.NONE}this.state!==U.NONE&&this.dispatchEvent(ut)}function Qs(r){switch(this._trackPointer(r),this.state){case U.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(r),this.update();break;case U.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(r),this.update();break;case U.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(r),this.update();break;case U.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(r),this.update();break;default:this.state=U.NONE}}function Vs(r){this.enabled!==!1&&r.preventDefault()}function Js(r){r.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function ei(r){r.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}const Pe=.4,ti=.15;class zt{constructor(e,t=[],s=1.5,i=[]){this.radius=e,this.shore=s;const n=Math.max(e,...i.map(o=>Math.hypot(o.cx,o.cz)+Math.hypot(o.hx,o.hz)));this.half=Math.ceil(n/Pe),this.size=this.half*2+1,this.blocked=new Uint8Array(this.size*this.size);const a=e-s;for(let o=0;o<this.size;o++)for(let l=0;l<this.size;l++){const{x:d,z:u}=this.center(o,l);Math.hypot(d,u)>a&&(this.blocked[l*this.size+o]=1)}for(const o of i)this.mark(o,0,0);for(const o of t)this.block(o)}radius;shore;size;half;blocked;center(e,t){return{x:(e-this.half)*Pe,z:(t-this.half)*Pe}}cellOf(e){return[Math.round(e.x/Pe)+this.half,Math.round(e.z/Pe)+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,ti,1)}mark(e,t,s){const i=e.hx+t,n=e.hz+t,a=Math.cos(e.yaw),o=Math.sin(e.yaw),l=Math.hypot(i,n),[d,u]=this.cellOf({x:e.cx-l,z:e.cz-l}),[p,h]=this.cellOf({x:e.cx+l,z:e.cz+l});for(let c=Math.max(0,d);c<=Math.min(this.size-1,p);c++)for(let m=Math.max(0,u);m<=Math.min(this.size-1,h);m++){const b=this.center(c,m),g=b.x-e.cx,x=b.z-e.cz,k=g*a-x*o,z=g*o+x*a;Math.abs(k)<=i&&Math.abs(z)<=n&&(this.blocked[m*this.size+c]=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/Pe);for(let a=1;a<=n;a++){let o=null,l=1/0;for(let d=-a;d<=a;d++)for(const u of Math.abs(d)===a?ii(-a,a):[-a,a]){const p=s+d,h=i+u;if(!this.free(p,h))continue;const c=this.center(p,h),m=Math.hypot(c.x-e.x,c.z-e.z);m<l&&(o=c,l=m)}if(o)return o}return null}clear(e,t){const s=Math.hypot(t.x-e.x,t.z-e.z),i=Math.max(1,Math.ceil(s/(Pe/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,o]=this.cellOf(i),[l,d]=this.cellOf(n),u=this.size,p=o*u+a,h=d*u+l,c=new Int32Array(u*u).fill(-1),m=new Float32Array(u*u).fill(1/0),b=new ni;m[p]=0,b.push(p,_t(a,o,l,d));let g=0,x=p===h;for(;!x&&b.size&&g++<s;){const M=b.pop();if(M===h){x=!0;break}const E=M%u,A=(M-E)/u;for(const[T,K,J]of si){const N=E+T,C=A+K;if(!this.free(N,C)||T&&K&&(!this.free(E+T,A)||!this.free(E,A+K)))continue;const B=C*u+N,$=m[M]+J;$>=m[B]||(m[B]=$,c[B]=M,b.push(B,$+_t(N,C,l,d)))}}if(!x)return null;const k=[];for(let M=h;M!==-1&&M!==p;M=c[M]){const E=M%u;k.push(this.center(E,(M-E)/u))}k.reverse();const z=this.smooth([e,...k]);z.shift();const v=z[z.length-1];return(!v||Math.hypot(v.x-t.x,v.z-t.z)>1e-6)&&z.push(t),z}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 Ge=Math.SQRT2,si=[[1,0,1],[-1,0,1],[0,1,1],[0,-1,1],[1,1,Ge],[1,-1,Ge],[-1,1,Ge],[-1,-1,Ge]];function _t(r,e,t,s){const i=Math.abs(r-t),n=Math.abs(e-s);return i+n+(Ge-2)*Math.min(i,n)}function ii(r,e){const t=[];for(let s=r;s<=e;s++)t.push(s);return t}class ni{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 o=i;if(n<this.items.length&&this.keys[n]<this.keys[o]&&(o=n),a<this.items.length&&this.keys[a]<this.keys[o]&&(o=a),o===i)break;this.swap(i,o),i=o}}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 Ht{constructor(e){this.materials=e}materials;pieces=new Map;add(e,t,s,i,n,a={}){const o=t.index?t.toNonIndexed():t.clone();for(const u of Object.keys(o.attributes))u!=="position"&&u!=="normal"&&o.deleteAttribute(u);o.scale(a.sx??1,a.sy??1,a.sz??1),a.rx&&o.rotateX(a.rx),a.rz&&o.rotateZ(a.rz),a.ry&&o.rotateY(a.ry),o.translate(s,i,n);const l=this.materials[e],d=this.pieces.get(l)??[];d.push(o),this.pieces.set(l,d)}addAt(e,t,s,i,n,a,o,l,d={}){const u=Math.cos(s),p=Math.sin(s);this.add(i,n,e+a*u+l*p,o,t-a*p+l*u,{...d,ry:(d.ry??0)+s})}build(e){const t=new ne;for(const[s,i]of this.pieces){const n=ls(i,!1);if(i.forEach(l=>l.dispose()),!n)continue;const a=new O(n,s),o=!(s instanceof X);a.castShadow=e&&o,a.receiveShadow=e&&o,t.add(a)}return this.pieces.clear(),t}}const W=(r,e=.8,t=0)=>new ke({color:r,roughness:e,metalness:t,flatShading:!0}),Ve={q:-1,r:0},Fe={x:-2.4,z:-2.4,top:2.3,rope:1.68,seats:[-.75,.75]},ai={x:-2.2,z:2.7,height:.45,half:1.45},St={x:2.6,ladderZ:-3.3,platformZ:-2.9,top:1.35,chuteFrom:-2.5,chuteTo:.45,bottom:.22};function oi(r){const e=r.facing*Math.PI/180,t=Math.cos(e),s=Math.sin(e),i=(P,I)=>({x:r.x+P*t+I*s,z:r.z-P*s+I*t}),n=(P,I,G)=>({...i(P,G),y:V+I}),a=[],o=P=>(a.push(P),P),l={frame:o(W("#5b8bd9",.6)),red:o(W("#ef7a5d",.6)),yellow:o(W("#f4b942",.5)),teal:o(W("#4fb5a5",.6)),wood:o(W("#c99a6b",.8)),darkWood:o(W("#7a563b",.8)),rope:o(W("#e9dcc0",.9))},d=o(new rt(1,1,1,2,.08)),u=o(new Ne(.5,.5,1,10)),p=new ne;p.name="playground",p.position.set(r.x,V,r.z),p.rotation.y=e;const h=new Ht(l),{x:c,z:m,top:b}=Fe;h.add("frame",u,c,b,m,{sx:.13,sy:3.3,sz:.13,rz:Math.PI/2});for(const P of[-1.6,1.6])for(const I of[-1,1]){const ee=Math.hypot(b,.75);h.add("frame",u,c+P,b/2,m+I*.75/2,{sx:.12,sy:ee,sz:.12,rx:-I*Math.atan2(.75,b)})}const g=Fe.seats.map(P=>{const I=new ne;I.position.set(c+P,b-.04,m);for(const ee of[-.22,.22]){const ie=new O(u,l.rope);ie.scale.set(.035,Fe.rope,.035),ie.position.set(ee,-1.68/2,0),I.add(ie)}const G=new O(d,l.red);return G.scale.set(.56,.06,.34),G.position.set(0,-1.68,0),G.castShadow=r.shadows,I.add(G),p.add(I),I}),{x,z:k,height:z,half:v}=ai;h.add("darkWood",d,x,z/2-.05,k,{sx:.34,sy:z-.1,sz:.5}),h.add("frame",u,x,z,k,{sx:.1,sy:.56,sz:.1,rx:Math.PI/2});const M=new ne;M.position.set(x,z,k);const E=[["yellow",0,.05,0,v*2+.5,.08,.32],["teal",-v,.12,0,.42,.07,.36],["teal",v,.12,0,.42,.07,.36],["frame",-v+.32,.3,0,.06,.4,.06],["frame",v-.32,.3,0,.06,.4,.06],["frame",-v+.32,.48,0,.06,.06,.4],["frame",v-.32,.48,0,.06,.06,.4]];for(const[P,I,G,ee,ie,Z,Se]of E){const me=new O(d,l[P]);me.scale.set(ie,Z,Se),me.position.set(I,G,ee),me.castShadow=r.shadows,M.add(me)}p.add(M);const{x:A,ladderZ:T,platformZ:K,chuteFrom:J,chuteTo:N,bottom:C}=St,B=St.top;for(const P of[-.32,.32])h.add("frame",u,A+P,B/2+.15,T,{sx:.07,sy:B+.3,sz:.07});for(let P=.25;P<B;P+=.27)h.add("yellow",u,A,P,T,{sx:.05,sy:.64,sz:.05,rz:Math.PI/2});for(const P of[[-.4,-.38],[.4,-.38],[-.4,.38],[.4,.38]])h.add("frame",u,A+P[0],B/2,K+P[1],{sx:.08,sy:B,sz:.08});h.add("wood",d,A,B,K,{sx:.95,sy:.08,sz:.85});for(const P of[-.45,.45])h.add("red",d,A+P,B+.3,K,{sx:.05,sy:.06,sz:.8});const $=B-C,F=N-J,pe=Math.hypot($,F),ye=Math.atan2($,F),xe=(J+N)/2,H=(B+C)/2;h.add("yellow",d,A,H,xe,{sx:.7,sy:.06,sz:pe,rx:ye});for(const P of[-.37,.37])h.add("red",d,A+P,H+.09,xe,{sx:.06,sy:.18,sz:pe,rx:ye});h.add("yellow",d,A,C,N+.3,{sx:.7,sy:.06,sz:.6});for(const P of[J+F*.55])h.add("frame",u,A,(C+$*.45)/2,P,{sx:.07,sy:C+$*.45,sz:.07});const ae=3.3,te=3.4;h.add("wood",d,ae,.27,te,{sx:1.6,sy:.08,sz:.45}),h.add("wood",d,ae,.52,te+.2,{sx:1.6,sy:.28,sz:.07});for(const P of[-.65,.65])h.add("darkWood",d,ae+P,.13,te,{sx:.09,sy:.26,sz:.4});const se=h.build(r.shadows);se.traverse(P=>{const I=P;I.geometry&&o(I.geometry)}),p.add(se);const le={x:s,z:t},fe=Fe.seats.map(P=>({pivot:n(c+P,b-.04,m),rope:Fe.rope+.03,face:e,stand:i(c+P,m+.75)})),_e={pivot:n(x,z,k),half:v,yaw:e,stand:[i(x-v,k+.55),i(x+v,k+.55)]},Me={queue:i(A,T-1),back:{x:-le.x,z:-le.z},foot:i(A,T-.35),top:n(A,B+.04,K),from:n(A,B+.1,J+.15),to:n(A,C+.12,N+.2),exit:i(A,N+1),face:e},we=(P,I,G,ee)=>({...ri(i(P,I)),hx:G,hz:ee,yaw:e}),$e=[...[-1.6,1.6].flatMap(P=>[-.75,.75].map(I=>we(c+P,m+I,.12,.12))),we(x,k,v+.2,.22),we(A,(T+N)/2,.42,(N-T)/2+.1),we(ae,te,.8,.25)],Ue=e+Math.PI,ce=[-.4,.4].map(P=>{const I=i(ae+P,te-.02);return{key:`playground:bench:${P}`,kind:"seat",x:I.x,z:I.z,y:V+.31,face:Ue,plot:null,name:"the playground bench"}});return{group:p,solids:$e,seats:ce,anchors:{center:i(0,0),swings:fe,seesaw:_e,slide:Me},setMotion(P){g.forEach((I,G)=>{I.rotation.x=-(P.swings[G]??0)}),M.rotation.z=P.seesaw},dispose(){a.forEach(P=>P.dispose())}}}function ri(r){return{cx:r.x,cz:r.z}}function hi(r,e,t){const s=e===0?-1:1,i=s*r.half*Math.cos(t),n=s*r.half*Math.sin(t);return{x:r.pivot.x+i*Math.cos(r.yaw),z:r.pivot.z-i*Math.sin(r.yaw),y:r.pivot.y+n+.19,face:r.yaw+(e===0?Math.PI/2:-Math.PI/2)}}function ci(r,e){const t=r.rope*Math.sin(e);return{x:r.pivot.x+Math.sin(r.face)*t,z:r.pivot.z+Math.cos(r.face)*t,y:r.pivot.y-r.rope*Math.cos(e)+.04,face:r.face}}const li=1/840,di=150,Je=1.05,ui=7,Pt=.9,pi=1.8,fi=300,jt=60,mi=["how are you?","nice day!","🌊","☕?","haha","look!","🎵","same!","really?","😄","✨","🍩","ok!","me too!","🌸","so sunny","🐚","hmm…","💡","yay!"];function gi(r){let e=r>>>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 yi(r){let e=2166136261;for(const t of r)e=Math.imul(e^(t.codePointAt(0)??0),16777619);return e>>>0}function Ae(r,e=0){const t=(r-e/60+24)%24;return t>=22.5||t<6.5}const Et={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 ge(r,e){return r.length?r[Math.floor(e()*r.length)%r.length]:void 0}function xi(r,e){const t=Object.entries(r),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 je=(r,e)=>Math.atan2(e.x-r.x,e.z-r.z),be=(r,e,t)=>r+(e-r)*t,At=new Set(["invite","swing","seesaw","slide","tag"]);class wi{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(o=>o.key));for(const o of[...this.robots.keys()])n.has(o)||this.remove(o,i);const a=new Set([...t.seats.map(o=>o.key),...(t.activities??[]).map(o=>o.key)]);for(const[o,l]of[...this.taken])if(!a.has(o)){this.taken.delete(o);const d=this.robots.get(l);d&&this.replan(d,i)}for(const o of s){const l=this.robots.get(o.key);if(l){l.resident=o;continue}this.robots.set(o.key,this.arrive(o,i))}}arrive(e,t){const s=gi(yi(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:Je,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)/di):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:je(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:je(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"||Ae(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"&&!Ae(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:Cs(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(d=>d.kind==="seat"&&d.key.startsWith(e+":"));if(!a)return null;const o=this.taken.get(a.key);if(o)return o;const l=[...this.robots.values()].filter(d=>(!t||d.key===t)&&d.mode.state==="free"&&!Ae(this.hour,d.bedtimeShift)&&!this.busyPlaying(d)&&d.plan.act.kind!=="sleep");l.sort((d,u)=>Math.hypot(d.x-a.x,d.z-a.z)-Math.hypot(u.x-a.x,u.z-a.z));for(const d of l){const u=this.nav.path(d,a);if(u)return this.release(d,this.clockNow),this.takeSeat(d,a),d.plan={label:`Sitting on ${a.name}`,goal:a,act:{kind:"sit",seat:a,seconds:25}},d.path=u,d.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"&&!Ae(this.hour,a.bedtimeShift)&&!["sleep","wish-queue","wish-register","interact"].includes(a.plan.act.kind)&&kt(a.resident.hobbies,s.activity));n.sort((a,o)=>Math.hypot(a.x-s.x,a.z-s.z)-Math.hypot(o.x-s.x,o.z-s.z));for(const a of n){const o=this.nav.path(a,s);if(o)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=o,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},o=this.nav.path(i,a);if(o&&(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=o,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:li)*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(o=>o.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,o=Math.hypot(n,a);if(o<=s){e.x=i.x,e.z=i.z,s-=o,e.stride=(e.stride+o/Pt)%1,e.path.shift();continue}e.x+=n/o*s,e.z+=a/o*s,e.stride=(e.stride+s/Pt)%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=ui*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),o=d=>a>=d,l=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 d=this.wishPatience.get(n.ticket);if(d||(d={since:s,next:s+45+e.rng()*35,gaveUp:!1},this.wishPatience.set(n.ticket,d)),n.index>0&&s>=d.next&&(d.next=s+10,e.rng()<.35)){d.gaveUp=!0,d.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:{...Ls,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 d=n.site.activity;e.pose=d==="perform"?"dance":d==="observe"?"think":d==="play"?"cheer":d==="read"?"think":"work",e.heading=n.site.face,e.bubble={text:{read:"📖",paint:"🎨",garden:a<5?"🌱":"💧",perform:"🎵",play:"🎮",observe:"✨"}[d],tone:"plain",until:s+1},e.boredom=Math.max(0,e.boredom-t/30),o(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),o(n.seconds)&&this.replan(e,s);return;case"sit":e.pose="sit",this.sigh(e,t,s),o(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}),Ae(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),o(n.seconds)&&this.replan(e,s);return;case"watch":{const d=this.robots.get(n.performer);if(!d||d.mode.state!=="free"||!this.performing(d)||d.path.length){e.chatAfter=s+30,this.replan(e,s);return}this.turn(e,je(e,d),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}),o(n.seconds)&&this.replan(e,s);return;case"tend":e.pose="think",this.turn(e,n.face,t),o(n.seconds)&&this.replan(e,s);return;case"chat":{const d=this.robots.get(n.with);if(!d||o(n.seconds)){if(e.chatAfter=s+25+e.rng()*40,d&&n.first&&l&&this.likesToPlay(e)&&e.rng()<.4&&d.plan.act.kind==="chat"){e.bubble={text:"wanna play?",tone:"plain",until:s+1.8},this.startPlay(ge(this.jointGames(),e.rng)??"tag",e,d,s);return}this.replan(e,s);return}this.turn(e,je(e,d),t);const u=Math.floor(a/1.8)%2===(n.first?0:1);e.pose=u?"talk":"stand",u&&a>1.6&&(!e.bubble||e.bubble.until<s)&&(e.bubble={text:this.chatLine(e,d),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}),!o(n.seconds))return;const d=n.then==="ask"?Te(this.partners(e,30).filter(u=>u.key!==n.from),e,e.rng):null;d?this.invite(e.key,d.key,ge(this.jointGames(),e.rng)??"tag",s):this.replan(e,s);return}case"swing":{if(!l){this.replan(e,s);return}const d=l.swings[n.swing];this.swingAmp[n.swing]=Math.min(.62,this.swingAmp[n.swing]+t*.07);const u=this.motion.swings[n.swing],p=ci(d,u);e.perched=!0,e.x=p.x,e.z=p.z,e.y=p.y,e.heading=p.face,e.pose="swing",e.lean=u,!e.bubble&&e.rng()<t*.25&&(e.bubble={text:ge(["wheee!","😄","✨","higher!"],e.rng),tone:"plain",until:s+1.5}),o(n.seconds)&&this.replan(e,s);return}case"seesaw":{if(!l){this.replan(e,s);return}const d=hi(l.seesaw,n.end,this.motion.seesaw);e.perched=!0,e.x=d.x,e.z=d.z,e.y=d.y,e.heading=d.face,e.pose="ride";const u=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}),!u&&a>2&&s>=(n.askAt??0)){n.askAt=s+3;const h=Te(this.partners(e,40).filter(c=>!n.asked?.includes(c.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}}!u&&a>16&&this.sob(e,s,"nobody came to play","leave");return}!e.bubble&&e.rng()<t*.3&&(e.bubble={text:ge(["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",l&&this.turn(e,l.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),o(n.seconds)&&this.replan(e,s);return;case"cheer":if(e.pose="cheer",!o(n.seconds))return;n.then?(e.plan=n.then,e.speed=e.excitedUntil>s?1.6:Je,this.route(e)):this.replan(e,s);return}}sigh(e,t,s){e.boredom<.72||e.bubble||e.rng()>t*.08||(e.bubble={text:ge(["🥱","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?":ge(mi,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=Je,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||At.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 Et[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 c=this.takeSeat(e,this.ownSeat(e,"desk")),m=c??(i?i.center:null);return{label:this.overrideLabel(e),goal:m&&{x:m.x,z:m.z},act:{kind:"work",seat:c}}}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 c=this.takeSeat(e,this.ownSeat(e,"desk")),m=c??(i?i.center:null);return{label:this.overrideLabel(e),goal:m&&{x:m.x,z:m.z},act:{kind:"trouble",seat:c}}}}if(Ae(this.hour,e.bedtimeShift)){const c=this.takeSeat(e,this.ownSeat(e,"bed")??this.ownSeat(e,"seat")),m=c??i?.center??null;return{label:"Asleep",goal:m&&{x:m.x,z:m.z},act:{kind:"sleep",seat:c}}}const n=(this.places.activities??[]).filter(c=>!this.taken.has(c.key)&&kt(e.resident.hobbies,c.activity));if(n.length&&s()<.4){const c=Te(n,e,s);if(c&&this.nav.path(e,c))return this.taken.set(c.key,e.key),{label:`${c.activity==="garden"?"Planting and watering":"Enjoying"} ${c.name}`,goal:c,act:{kind:"interact",site:c,seconds:c.activity==="perform"?25:14}}}const a={...Et[e.resident.trait??"agent"]},o=e.boredom;o>.5&&(a.play*=1+o*3,a.chat*=1+o*2,a.dance*=1+o,a.sit*=.5,a.gaze*=.6),!e.resident.hobbies?.includes("gardening")&&e.resident.trait!=="gardener"&&e.resident.trait!=="tinkerer"&&(a.tend=0);const l=this.freeSeats();switch(l.length||(a.sit=0),(t<e.chatAfter||this.partners(e).length===0)&&(a.chat=0),this.places.playground||(a.play=0),xi(a,s)){case"play":{const c=this.choosePlay(e,t);if(c)return c;break}case"sit":{const c=this.takeSeat(e,Te(l,e,s));if(!c)break;return{label:c.plot?`Sitting on ${c.name}`:`Resting on ${c.name}`,goal:{x:c.x,z:c.z},act:{kind:"sit",seat:c,seconds:12+s()*30}}}case"gaze":{const c=s()*Math.PI*2,m=this.places.radius-2.2,b={x:Math.sin(c)*m,z:Math.cos(c)*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 c=[...this.places.plots.entries()].filter(([b])=>b!==e.key),[,m]=ge(c,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 c=Te(this.partners(e),e,s);if(!c)break;return{label:`Going to see ${c.resident.name}`,goal:null,seek:c.key,act:{kind:"look",seconds:2}}}case"dance":{const c=s()*Math.PI*2,m=2.6+s()*1.2;return{label:"Dancing on the plaza",goal:{x:Math.sin(c)*m,z:Math.cos(c)*m},act:{kind:"dance",seconds:18+s()*10}}}case"tend":{const c=i?.center??{x:0,z:0},m={x:c.x+(s()-.5)*6,z:c.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 u=i&&s()<.55,p=u?i.center:{x:0,z:0},h=u?6:this.places.radius-4;for(let c=0;c<6;c++){const m=s()*Math.PI*2,b=Math.sqrt(s())*h,g={x:p.x+Math.sin(m)*b,z:p.z+Math.cos(m)*b};if(!(Math.hypot(g.x,g.z)>this.places.radius-2)&&this.nav.isFree(g))return{label:"Exploring",goal:g,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 At.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,o]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:o},since:s},o&&(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)>pi)continue;const o=n.key<a.key?`${n.key}|${a.key}`:`${a.key}|${n.key}`;if(!(e-(this.greeted.get(o)??-1/0)<fi)){this.greeted.set(o,e),this.helloAfter.set(n.key,e+jt),this.helloAfter.set(a.key,e+jt);for(const[l,d]of[[n,a],[a,n]])l.plan.act.kind!=="chat"&&((!l.bubble||l.bubble.tone==="plain")&&(l.bubble={text:l.rng()<.75?"hi!":"👋",tone:"plain",until:e+1.5}),l.path.length||(l.gesture={pose:"wave",until:e+1.4},l.heading=je(l,d)))}}}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 l of[0,1]){const d=l===0?1:0;if(!this.seesawRider[l]&&this.seesawRider[d]&&this.seesawSeated[d]&&i()<.8)return this.seesawPlan(e,l,this.robots.get(this.seesawRider[d])?.resident.name)}const n=this.partners(e,30);if(n.length&&t>=e.chatAfter&&i()<.6){const l=Te(n,e,i);return{label:`Asking ${l.resident.name} to play`,goal:null,seek:l.key,act:{kind:"invite",game:ge(this.jointGames(),i)??"tag",with:l.key}}}const a=[],o=this.swingRider.findIndex(l=>!l);return o>=0&&a.push(()=>this.swingPlan(e,o)),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)),ge(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),o=this.robots.get(t);return!a||!o||a.mode.state!=="free"||o.mode.state!=="free"?!1:(this.release(a,i),a.perched=!1,a.plan={label:`Asking ${o.resident.name} to play`,goal:null,seek:o.key,act:{kind:"invite",game:s,with:o.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:ge(["not now 😅","maybe later","sorry!"],t.rng),tone:"plain",until:s+2.2},t.path.length||(t.heading=je(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",o=[t.resident.name,s.resident.name];if(a==="seesaw")t.plan=this.seesawPlan(t,0,o[1]),s.plan=this.seesawPlan(s,1,o[0]);else if(a==="swings")t.plan=this.swingPlan(t,0,o[1]),s.plan=this.swingPlan(s,1,o[0]);else if(a==="slide")t.plan=this.slidePlan(3,o[1]),s.plan=this.slidePlan(3,o[0]);else{const l=`tag-${++this.games}`,d=t.rng()<.5?t.key:s.key;this.tags.set(l,{id:l,players:[t.key,s.key],it:d,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[u,p]of[[t,s],[s,t]])u.plan={label:`Playing tag with ${p.resident.name}`,goal:null,act:{kind:"tag",game:l},since:i};return}this.route(t),this.route(s)}tagTick(e,t,s,i){const n=this.tags.get(t),a=n?.players.find(l=>l!==e.key),o=a?this.robots.get(a):void 0;if(!n||!o||o.plan.act.kind!=="tag"){this.replan(e,i);return}if(i>n.until){this.tags.delete(t);for(const l of[e,o])this.release(l,i),l.plan={label:"Had fun playing tag",goal:null,act:{kind:"cheer",seconds:2},since:i},l.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,je(e,o),s);return}if(Math.hypot(o.x-e.x,o.z-e.z)<.9){n.it=o.key,n.pausedUntil=i+1.5,e.bubble={text:"tag!",tone:"plain",until:i+1.4},o.bubble={text:"😆",tone:"plain",until:i+1.4},e.path=[],o.path=[];return}(i>e.repathAt||!e.path.length)&&(e.repathAt=i+.45,e.path=this.nav.path(e,o)??[])}else if(e.speed=1.32,!e.path.length){const l=this.robots.get(n.it);let d=null,u=-1;for(let p=0;p<6;p++){const h=e.rng()*Math.PI*2,c=2+e.rng()*6,m={x:n.center.x+Math.sin(h)*c,z:n.center.z+Math.cos(h)*c};if(!this.nav.isFree(m)||Math.hypot(m.x,m.z)>this.places.radius-3)continue;const b=Math.hypot(m.x-l.x,m.z-l.z);b>u&&(d=m,u=b)}e.path=d?this.nav.path(e,d)??[]:[]}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=Je,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 p=0;p<2;p++){const h=this.swingRider[p]?this.robots.get(this.swingRider[p]):void 0;h?.plan.act.kind==="swing"&&h.plan.since!==void 0||(this.swingAmp[p]=Math.max(0,this.swingAmp[p]-e*.12)),this.swingPhase[p]+=e*2.4,this.motion.swings[p]=this.swingAmp[p]*Math.sin(this.swingPhase[p])}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 p=this.slideQueue[0]?this.robots.get(this.slideQueue[0]):void 0;p&&p.plan.act.kind==="slide"&&p.plan.since!==void 0?(this.slideQueue.shift(),this.slideRide={key:p.key,phase:"approach",since:t,from:{x:p.x,z:p.z}}):this.slideQueue[0]&&!p&&this.slideQueue.shift()}const a=this.slideRide;if(!a)return;const o=this.robots.get(a.key);if(!o||o.plan.act.kind!=="slide"){this.slideRide=null;return}const l=s.slide,d=t-a.since,u=p=>{a.phase=p,a.since=t};switch(a.phase){case"approach":{const p=Math.min(1,d/.6);o.x=be(a.from.x,l.foot.x,p),o.z=be(a.from.z,l.foot.z,p),o.perched=!1,o.pose="walk",o.stride=(o.stride+e*1.4)%1,o.heading=l.face,p>=1&&u("climb");return}case"climb":{const p=Math.min(1,d/1.8);o.perched=!0,o.x=be(l.foot.x,l.top.x,p),o.z=be(l.foot.z,l.top.z,p),o.y=be(l.top.y-1.35,l.top.y,p),o.pose="climb",o.stride=(o.stride+e*1.2)%1,o.heading=l.face,p>=1&&u("perch");return}case"perch":o.pose="stand",o.heading=l.face,d>.5&&(o.bubble={text:ge(["wheee!","here I go!","😆"],o.rng),tone:"plain",until:t+1.6},u("ride"));return;case"ride":{const p=Math.min(1,d/1.1),h=p*p;o.x=be(l.from.x,l.to.x,h),o.z=be(l.from.z,l.to.z,h),o.y=be(l.from.y,l.to.y,h),o.pose="ride",o.heading=l.face,p>=1&&u("hop");return}case"hop":{const p=Math.min(1,d/.45);if(o.x=be(l.to.x,l.exit.x,p),o.z=be(l.to.z,l.exit.z,p),o.perched=!1,o.pose="cheer",p<1)return;this.slideRide=null;const h=o.plan.act;if(h.runs-=1,h.runs>0){const c=this.slidePlan(h.runs);o.plan={...c,label:o.plan.label},this.route(o)}else o.bubble={text:"😄",tone:"plain",until:t+1.5},this.replan(o,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(o=>o!==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 Te(r,e,t){if(!r.length)return null;const s=[...r].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 Ye=-.18;function tt(r,e,t){const s=(m,b)=>{let g=Math.imul(m,374761393)^Math.imul(b,668265263)^Math.imul(t,2246822519);return g=Math.imul(g^g>>>13,1274126177),((g^g>>>16)>>>0)/4294967296},i=Math.floor(r),n=Math.floor(e),a=r-i,o=e-n,l=a*a*(3-2*a),d=o*o*(3-2*o),u=s(i,n),p=s(i+1,n),h=s(i,n+1),c=s(i+1,n+1);return u+(p-u)*l+(h-u)*d+(u-p-h+c)*l*d}const Oe=(r,e,t)=>{const s=Math.min(1,Math.max(0,(t-r)/(e-r)));return s*s*(3-2*s)};function pt(r,e){return r<=e-5?0:r<=e+.6?-.32*Oe(e-5,e+.6,r):-.32-2.4*Oe(e+.6,e+12,r)}const Re={grass:new he("#8fcb72"),grassDark:new he("#7fbe64"),sand:new he("#f0dcaa"),wetSand:new he("#dcc28a"),deep:new he("#bfa673")};function bi(r,e){const t=r+14,s=128,i=[0];for(let u=.9;u<t;u+=u<r-6?1.6:.8)i.push(u);i.push(t);const n=[],a=[],o=(u,p)=>{const h=u>r-7?(tt(Math.cos(p)*3,Math.sin(p)*3,e)-.5)*2.2:0,c=u+h*Oe(r-7,r,u),m=Math.sin(p)*c,b=Math.cos(p)*c,g=pt(u,r)+(u>r-5&&u<r+8?(tt(m*.4,b*.4,e+7)-.5)*.12:0),x=new he;return u<r-5.2?x.copy(Re.grass).lerp(Re.grassDark,tt(m*.15,b*.15,e)*.7):u<r+.4?x.copy(Re.sand).lerp(Re.wetSand,Oe(r-1.5,r+.4,u)):x.copy(Re.wetSand).lerp(Re.deep,Oe(r+.4,r+8,u)),{p:[m,g,b],c:[x.r,x.g,x.b]}};for(let u=0;u<i.length-1;u++)for(let p=0;p<s;p++){const h=p/s*Math.PI*2,c=(p+1)/s*Math.PI*2,m=o(i[u],h),b=o(i[u],c),g=o(i[u+1],h),x=o(i[u+1],c);for(const k of u===0?[[m,g,x]]:[[m,g,x],[m,x,b]]){const z=k[0].c;for(const v of k)n.push(...v.p),a.push(...z)}}const l=new Ft;l.setAttribute("position",new xt(new Float32Array(n),3)),l.setAttribute("color",new xt(new Float32Array(a),3)),l.computeVertexNormals();const d=new O(l,new ke({vertexColors:!0,flatShading:!0,roughness:.95}));return d.receiveShadow=!0,d.name="terrain",d}function ki(r){const e=new Bt(900,900,150,150);e.rotateX(-Math.PI/2);const t=new ke({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:r},n.vertexShader=n.vertexShader.replace("#include <common>",`#include <common>
|
|
2
|
+
uniform float uTime;
|
|
3
|
+
uniform float uShore;`).replace("#include <begin_vertex>",`#include <begin_vertex>
|
|
4
|
+
float away = smoothstep(uShore + 1.0, uShore + 16.0, length(position.xz));
|
|
5
|
+
transformed.y += away * (sin(position.x * 0.17 + uTime * 0.8) * 0.12
|
|
6
|
+
+ cos(position.z * 0.14 + uTime * 0.65) * 0.1
|
|
7
|
+
+ sin((position.x + position.z) * 0.33 + uTime * 1.5) * 0.04);`)};const i=new O(e,t);return i.position.y=Ye,i.name="sea",{mesh:i,material:t,time:s}}function Mi(){const r=new he("#79b8f0"),e=new he("#e8f3fb"),t=new us({side:ps,depthWrite:!1,fog:!1,uniforms:{top:{value:r},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;
|
|
8
|
+
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 O(new He(600,24,12),t);return s.name="sky",s.renderOrder=-1,{mesh:s,top:r,horizon:e}}function vi(r){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(r).width>228&&s>22;)s-=2,t.font=i();let n=r;for(;t.measureText(n).width>228&&n.length>2;)n=`${n.slice(0,-2)}…`;t.fillText(n,128,50);const a=new dt(e);return a.colorSpace=Gt,a}function zi(r){const{radius:e,seed:t,plots:s}=r,i=new ne;i.name="scenery";const n=[],a=w=>(n.push(w),w),o=bi(e,t);a(o.geometry),a(o.material),i.add(o);const l=ki(e);a(l.mesh.geometry),a(l.material),i.add(l.mesh);const d=a(new X({color:"#ffffff",transparent:!0,opacity:.32,depthWrite:!1})),u=new O(a(new it(e-.2,e+1.4,128)),d);u.rotation.x=-Math.PI/2,u.position.y=Ye+.06,i.add(u);const p=Mi();a(p.mesh.geometry),a(p.mesh.material),i.add(p.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 X({color:"#ffe3a8"})),star:a(new X({color:"#ffd56b"})),seal:a(new X({color:"#e0584f"})),light0:a(new X({color:"#ffcf7a"})),light1:a(new X({color:"#ff9f8a"})),light2:a(new X({color:"#9fe0ff"})),light3:a(new X({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))},c=new Ht(h),m=a(new rt(1,1,1,2,.12)),b=a(new Ne(.5,.5,1,12)),g=a(new ds(.5,1,9)),x=a(new yt(.5,1)),k=a(new yt(.5,0)),z=[],v=[],M=a(new Ne(1,1,1,6)),E=a(new Ne(.97,1,1,6)),A=Math.max(2,...s.map(w=>w.ring)),T=new Map(s.map(w=>[`${w.q},${w.r}`,w])),K=`${Ve.q},${Ve.r}`;for(let w=0;w<=A;w++)for(const[S,R]of lt(w)){const j=Ke(S,R);if(c.add("path",M,j.x,.01,j.z,{sx:Xe-.02,sy:.02,sz:Xe-.02}),w===0)continue;const f=T.get(`${S},${R}`),_=`${S},${R}`===K?"playTile":f?f.owner.kind==="agent"?"tileAgent":"tileBot":"tileEmpty";c.add("tileEdge",M,j.x,V/2-.005,j.z,{sx:Le,sy:V-.01,sz:Le}),c.add(_,E,j.x,V/2+.005,j.z,{sx:Le-.08,sy:V-.01,sz:Le-.08})}c.add("plaza",E,0,V/2,0,{sx:Xe-.45,sy:V,sz:Xe-.45}),c.add("plazaInner",M,0,V+.004,0,{sx:3.4,sy:.01,sz:3.4});const J=Ke(Ve.q,Ve.r),N=oi({x:J.x,z:J.z,facing:Qt(J.x,J.z),shadows:r.shadows});i.add(N.group);const C=V;c.add("stone",b,0,C+.25,0,{sx:3,sy:.5,sz:3}),c.add("trunk",b,0,C+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(([w,S,R],j)=>c.add(j%2?"pineLight":"pine",g,0,C+w+R/2,0,{sx:S,sy:R,sz:S})),c.add("star",x,0,C+6.35,0,{sx:.5,sy:.5,sz:.5}),v.push({cx:0,cz:0,hx:1.6,hz:1.6,yaw:0});const $=a(new He(.07,8,6));for(let w=0;w<44;w++){const S=w/44,R=C+1.6+S*4.4,j=(1-S)*1.65+.2,f=S*Math.PI*9;c.add(`light${w%4}`,$,Math.sin(f)*j,R,Math.cos(f)*j)}const F=new ne,pe=a(new rt(.36,.25,.05,1,.02)),ye=a(new He(.045,8,6)),xe=a(new Ne(.008,.008,.3,4));for(let w=0;w<12;w++){const S=w/12*Math.PI*2+.3,R=C+2+w%3*.75,j=1.95-w%3*.35,f=new ne;f.position.set(Math.sin(S)*j,R,Math.cos(S)*j),f.rotation.y=S;const _=new O(pe,h.paper);_.position.y=-.18;const D=new O(ye,h.seal);D.position.set(0,-.18,.03);const Y=new O(xe,h.darkWood);Y.position.y=0,f.add(_,D,Y),f.visible=!1,f.userData.swing=w*1.7,F.add(f)}i.add(F);for(let w=0;w<6;w++){const S=w*Math.PI/3,R=4.5,j=Math.cos(S)*R,f=Math.sin(S)*R,_=Math.atan2(-j,-f);c.addAt(j,f,_,"wood",m,0,C+.27,0,{sx:1.9,sy:.08,sz:.5}),c.addAt(j,f,_,"wood",m,0,C+.55,-.24,{sx:1.9,sy:.32,sz:.07});for(const D of[-.8,.8])c.addAt(j,f,_,"darkWood",m,D,C+.13,0,{sx:.1,sy:.26,sz:.44});v.push({cx:j,cz:f,hx:.95,hz:.3,yaw:_});for(const D of[-.45,.45]){const Y=j+Math.cos(_)*D,de=f-Math.sin(_)*D;z.push({key:`plaza:${w}:${D}`,kind:"seat",x:Y,z:de,y:C+.3,face:_,plot:null,name:"a bench"})}}for(let w=0;w<6;w++){const S=Math.PI/6+w*Math.PI/3,R=et-1.3,j=Math.cos(S)*R,f=Math.sin(S)*R;c.add("metal",b,j,C+1.1,f,{sx:.12,sy:2.2,sz:.12}),c.add("metal",m,j,C+2.28,f,{sx:.34,sy:.08,sz:.34});const _=new O(m,h.lamp);_.scale.set(.26,.3,.26),_.position.set(j,C+2.1,f),i.add(_),v.push({cx:j,cz:f,hx:.15,hz:.15,yaw:0})}const H=Math.PI+.35,ae=e-4,te=e+9,se=(ae+te)/2,le=Math.sin(H),fe=Math.cos(H);c.add("wood",m,le*se,.12,fe*se,{sx:2.2,sy:.14,sz:te-ae,ry:H});for(let w=ae+1;w<=te;w+=2.2)for(const S of[-1.15,1.15]){const R=le*w+Math.cos(H)*S,j=fe*w-Math.sin(H)*S;c.add("darkWood",b,R,-.4,j,{sx:.18,sy:1.3,sz:.18})}const _e=te+1.6,Me=le*_e+Math.cos(H)*2.2,we=fe*_e-Math.sin(H)*2.2;c.add("white",m,Me,Ye+.25,we,{sx:1.5,sy:.6,sz:3.6,ry:H}),c.add("red",m,Me,Ye+.42,we,{sx:1.56,sy:.1,sz:3.66,ry:H}),c.add("blue",m,Me+le*.3,Ye+.85,we+fe*.3,{sx:1,sy:.6,sz:1.2,ry:H});const $e={x:le*(te-1),z:fe*(te-1),face:H+Math.PI},Ue=[{cx:le*se,cz:fe*se,hx:.9,hz:(te-ae)/2,yaw:H}],ce=w=>tt(w*1.37,w*2.11,t+99),P=H+1.9,I=w=>{const S=R=>Math.abs(Math.atan2(Math.sin(w-R),Math.cos(w-R)))<.18;return S(H)||S(P)};for(let w=0;w<18;w++){const S=w/18*Math.PI*2+ce(w)*.3;if(I(S))continue;const R=e-2.6+ce(w+40)*1.2,j=Math.sin(S)*R,f=Math.cos(S)*R,_=(ce(w+80)-.5)*.5,D=3.4+ce(w+20)*1.6;for(let ze=0;ze<5;ze++){const ve=ze/5;c.add("trunk",b,j+Math.sin(S)*_*ve*D*.4,ve*D+D/10,f+Math.cos(S)*_*ve*D*.4,{sx:.32-ve*.1,sy:D/5+.05,sz:.32-ve*.1})}const Y=j+Math.sin(S)*_*D*.4,de=f+Math.cos(S)*_*D*.4;for(let ze=0;ze<6;ze++){const ve=ze/6*Math.PI*2+w;c.add(ze%2?"leaf":"leafLight",g,Y+Math.sin(ve)*.9,D+.05,de+Math.cos(ve)*.9,{sx:.5,sy:2,sz:.18,rx:Math.PI/2-.35,ry:ve})}c.add("leafLight",x,Y,D+.2,de,{sx:.6,sy:.4,sz:.6}),v.push({cx:j,cz:f,hx:.3,hz:.3,yaw:0})}for(let w=0;w<10;w++){const S=ce(w+200)*Math.PI*2;if(I(S))continue;const R=e-1.2+ce(w+220)*2.2,j=.4+ce(w+240)*.8;c.add("rock",k,Math.sin(S)*R,pt(R,e)+j*.25,Math.cos(S)*R,{sx:j*1.3,sy:j,sz:j,ry:w}),R<e-1&&v.push({cx:Math.sin(S)*R,cz:Math.cos(S)*R,hx:j*.6,hz:j*.6,yaw:0})}const G=Math.sin(P)*(e-2.4),ee=Math.cos(P)*(e-2.4);c.add("stone",b,G,.3,ee,{sx:2.6,sy:.6,sz:2.6});for(let w=0;w<5;w++)c.add(w%2?"red":"white",b,G,.6+w*1.1+.55,ee,{sx:1.7-w*.14,sy:1.1,sz:1.7-w*.14});c.add("metal",b,G,6.7,ee,{sx:1.3,sy:.15,sz:1.3}),c.add("red",g,G,7.75,ee,{sx:1.2,sy:.7,sz:1.2});const ie=new O(m,h.lamp);ie.scale.set(.8,.8,.8),ie.position.set(G,7.15,ee),i.add(ie),v.push({cx:G,cz:ee,hx:1.4,hz:1.4,yaw:0});const Z=a(new Bt(1.1,.42));for(const w of s){const S=It(w,r.residents);if(!S)continue;const R=w.radius*Math.sqrt(3)/2,j=Ee(w,-w.radius/2+.2,R-.45),f=w.facing*Math.PI/180;c.add("darkWood",m,j.x,C+.45,j.z,{sx:.1,sy:.9,sz:.1}),c.add("wood",m,j.x,C+.95,j.z,{sx:1.2,sy:.5,sz:.08,ry:f});const _=vi(S);if(_){a(_);const D=a(new X({map:_,side:ht})),Y=new O(Z,D);Y.position.set(j.x+Math.sin(f)*.05,C+.95,j.z+Math.cos(f)*.05),Y.rotation.y=f,i.add(Y)}v.push({cx:j.x,cz:j.z,hx:.15,hz:.15,yaw:0})}const Se=c.build(r.shadows);Se.traverse(w=>{const S=w;S.geometry&&a(S.geometry)}),i.add(Se);const me=new he("#ffe3a8"),Be=new he("#fff3d6"),qe=h.lamp;return v.push(...N.solids),z.push(...N.seats),n.push(N),{group:i,seats:z,solids:v,dock:$e,walkways:Ue,deck:.19,playground:N,update(w,S,R,j){l.time.value=w,p.top.copy(R.top),p.horizon.copy(R.horizon),l.material.color.copy(j),d.opacity=.22+Math.sin(w*.9)*.08,qe.color.copy(Be).lerp(me,S).multiplyScalar(.75+S*.5);for(const f of F.children)f.visible&&(f.rotation.z=Math.sin(w*1.3+f.userData.swing)*.08)},setLetters(w){F.children.forEach((S,R)=>{S.visible=R<w})},dispose(){n.forEach(w=>w.dispose())}}}function _i(r,e,t){return t.some(s=>{const i=r-s.cx,n=e-s.cz,a=i*Math.cos(s.yaw)-n*Math.sin(s.yaw),o=i*Math.sin(s.yaw)+n*Math.cos(s.yaw);return Math.abs(a)<=s.hx+.2&&Math.abs(o)<=s.hz+.2})}function Tt(r){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=(r%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=Oe(0,1,(t-i.h)/Math.max(1e-4,n.h-i.h)),o=(h,c)=>new he(h).lerp(new he(c),a),l=t>=6&&t<=19.5,u=(l?(t-6)/13.5:(t+24-19.5)%24/10.5)*Math.PI,p=new Q(Math.cos(u)*60,Math.max(12,Math.sin(u)*80),l?-35:35);return{top:o(i.top,n.top),horizon:o(i.horizon,n.horizon),sea:o(i.sea,n.sea),night:i.night+(n.night-i.night)*a,sun:p,sunColor:o(i.sun,n.sun),sunIntensity:i.power+(n.power-i.power)*a,hemi:i.hemi+(n.hemi-i.hemi)*a}}function Rt(r,e,t="auto"){if(t!=="auto")return t;let s=Math.imul(r^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 Si(r,e){return r==="rain"&&e!=="sleep"}function Pi(r){const e=new ne;e.name="rain-umbrella",e.visible=!1;const t=new O(new He(.72,16,8,0,Math.PI*2,0,Math.PI/2),new ke({color:r,roughness:.65,side:ht}));t.scale.y=.45,t.position.set(.26,1.46,.08),e.add(t);const s=new O(new Ne(.016,.016,.92,8),new ke({color:"#4b5967",metalness:.5}));s.position.set(.26,1,.08),e.add(s);const i=new O(new it(.58,.8,48),new X({color:"#ffd687",transparent:!0,opacity:.42,depthWrite:!1,side:ht,blending:$t}));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 ji{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 Ft;e.setAttribute("position",new fs(this.positions,3)),this.object=new ms(e,new gs({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 o=0;o<a.count;o++){const l=a.getY(o)-e*13;a.setY(o,l<.2?24:l)}a.needsUpdate=!0}dispose(){this.object.geometry.dispose(),this.object.material.dispose()}}const We=Math.PI/180;class Ei{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),o=a?"52px system-ui, 'Apple Color Emoji', 'Segoe UI Emoji', sans-serif":"700 46px Inter, system-ui, sans-serif";n.font=o;const l=Math.ceil(n.measureText(e.text).width),d=Math.max(128,Math.min(512,l+64));i.width=d,i.height=128;const{decide:u,danger:p}=this.colors(),h=e.tone==="decide"?u:e.tone==="danger"?p:e.tone==="sleep"?"#dfe9ff":"#ffffff",c=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,d-28,84,34),n.moveTo(d/2-12,94),n.lineTo(d/2,116),n.lineTo(d/2+12,94),n.fill(),n.stroke(),n.fillStyle=c,n.font=o,n.textAlign="center",n.textBaseline="middle",n.fillText(e.text,d/2,a?58:56,d-40);const m=new dt(i);m.colorSpace=Gt;const b={material:new js({map:m,depthWrite:!1,transparent:!0}),aspect:d/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 Dt(r,e){return typeof document>"u"?e:getComputedStyle(document.documentElement).getPropertyValue(r).trim()||e}class Ai{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 ys({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=xs,this.renderer.toneMapping=ws,this.renderer.toneMappingExposure=1.02,this.scene.fog=new bs("#e8f3fb",90,420),this.scene.add(this.society.root),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 Bs(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 zt(40),this.sim=new wi(this.nav,{seats:[],plots:new Map,tree:{x:0,z:0},plaza:et,radius:40}),this.sim.onWishRegister=n=>this.events.onWishRegister?.(n),this.sim.onWishGiveUp=n=>this.events.onWishGiveUp?.(n),this.bubbles=new Ei(()=>({decide:Dt("--decide","#3d7bd9"),danger:Dt("--danger","#d6544b")})),this.shadowMaterial=new X({color:"#1e2a24",transparent:!0,opacity:.22,depthWrite:!1}),this.ring=new O(new it(.55,.68,40),new X({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 ji;setWeather(e){this.weatherChoice=e,this.hourAt=-1}renderer;scene=new ks;camera=new Ms(38,1,.1,1400);controls;hemi=new vs("#eef6ff","#c8b58a",1.4);sun=new zs("#fff4e2",2.6);gardenBeds=new Map;society=Ns();scenery=null;sceneryKey="";cache=new _s;placed=new Map;robots=new Map;proxies=new ne;sim;nav;island=null;residents=[];bubbles;frame=0;last=0;clock=0;hourAt=-1;hour=12;hourOverride=null;sky=Tt(12);selected=null;following=!1;held=new Set;flight=null;labels=null;hovered=null;pointer=new ue;pointerAt=null;raycaster=new Ss;faded=new Map;fadedMaterials=new Map;ring;shadowGeometry=new Ut(.42,24);shadowMaterial;proxyGeometry=new Ze(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=Yt(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])),o=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,It(g,t)])]);if(o!==this.sceneryKey||!this.scenery){this.scenery&&(this.scene.remove(this.scenery.group),this.scenery.dispose()),this.scenery=zi({radius:e.radius,seed:e.seed,plots:e.plots,residents:t,shadows:!0}),this.scene.add(this.scenery.group),this.sceneryKey=o;const g=Math.max(2,...e.plots.map(z=>z.ring));this.tiled=new Set;for(let z=1;z<=g;z++)for(const[v,M]of lt(z))this.tiled.add(`${v},${M}`);const x=e.radius+8,k=this.sun.shadow.camera;k.left=-x,k.right=x,k.top=x,k.bottom=-x,k.near=1,k.far=260,k.updateProjectionMatrix(),this.controls.maxDistance=Math.max(60,e.radius*2.6)}const l=this.scenery;l.setLetters(e.wishes.filter(g=>g.state==="open").length);const d=new Set,u=[...l.solids,...this.society.solids],p=[],h=[...l.seats];for(const g of e.placed){const x=a.get(g.plot),k=n.get(g.asset);if(!x||!k||k.kind==="accessory")continue;d.add(g.id);const z=[k.id,k.rev,g.x,g.z,g.y,g.turn,x.x,x.z,x.facing].join(":");let v=this.placed.get(g.id);if(!v||v.signature!==z){v&&this.scene.remove(v.object);const A=wt(this.cache.get(k),{shadows:!0}),T=Ee(x,g.x,g.z);A.position.set(T.x,V+g.y,T.z),A.rotation.y=(x.facing+g.turn)*We,A.userData.placement=g.id,A.userData.kind=k.kind,this.scene.add(A),v={object:A,signature:z},this.placed.set(g.id,v)}u.push(...Di(k,x,g));const M=Os(k,x,g);M&&p.push(M);const E=Li(k,x,g);E&&(E.owner=s.deskOwners.get(g.id),E.key+=`:${E.x}:${E.z}:${E.y}:${E.face}`,h.push(E))}for(const[g,x]of[...this.placed])d.has(g)||(this.scene.remove(x.object),this.placed.delete(g));this.nav=new zt(e.radius,u,1.5,l.walkways);for(const g of p)if(!(this.nav.isFree(g)&&this.nav.path({x:0,z:0},g)))for(let x=.5;x<=7;x+=.5){let k=!1;for(let z=0;z<8;z++){const v=z*Math.PI/4,M={x:g.x+Math.sin(v)*x,z:g.z+Math.cos(v)*x};if(this.nav.isFree(M)&&this.nav.path({x:0,z:0},M)){g.face=Math.atan2(g.x-M.x,g.z-M.z),Object.assign(g,M),k=!0;break}}if(k)break}for(const[g,x]of this.gardenBeds){const k=p.find(z=>z.key===g&&z.activity==="garden");k?x.root.position.set(k.x+Math.sin(k.face)*.65,V+.02,k.z+Math.cos(k.face)*.65):(this.scene.remove(x.root),x.dispose(),this.gardenBeds.delete(g))}const c={seats:h,activities:p,plots:new Map(t.filter(g=>g.plot).map(g=>{const x=g.plot,k=Ee(x,0,0),z=Ee(x,0,x.radius*Math.sqrt(3)/2-1.2);return[g.key,{id:x.id,center:k,door:z,front:{...z,face:x.facing*We}}]})),tree:{x:0,z:0},plaza:et,radius:e.radius,playground:l.playground.anchors},m=this.clock;if(this.sim.reset(this.nav,c,t,m),this.sim.setWishQueue(e.wishes.filter(g=>g.state==="queued").sort((g,x)=>g.madeAt-x.madeAt||g.id.localeCompare(x.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,l.dock,m);this.firstLoad=!1;const b=new Set;for(const g of t){const x=JSON.stringify({...g.look,worn:void 0}),k=ft.map(v=>{const M=g.look.worn[v],E=M?n.get(M):void 0;return E&&E.kind==="accessory"&&b.add(E.id),E&&E.kind==="accessory"?`${v}:${E.id}:${E.rev}`:""}).join("|");let z=this.robots.get(g.key);if(z&&z.look!==x&&(this.dropRobot(g.key),z=void 0),z||(z=this.addRobot(g.key,g,x)),z.atmosphere.aura.visible=!!g.agent?.leader,z.worn!==k){for(const v of ft){const M=g.look.worn[v],E=M?n.get(M):void 0;z.rig.wear(v,E&&E.kind==="accessory"?this.accessory(E,v):null)}z.worn=k}}for(const g of[...this.robots.keys()])t.some(x=>x.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),...b]))}accessory(e,t){const s=wt(this.cache.get(e),{shadows:!1});return s.name=`worn-${t}`,s}addRobot(e,t,s){const i=Ot(t.look);i.root.userData.robot=e;const n=new O(this.shadowGeometry,this.shadowMaterial);n.rotation.x=-Math.PI/2;const a=new O(this.proxyGeometry,this.shadowMaterial);a.userData.robot=e;const o=new Ps;o.scale.set(.6,.6,1),o.visible=!1,this.scene.add(i.root,n,o),this.proxies.add(a);const l=Pi(t.look.trim);i.root.add(l.umbrella,l.aura);const d=$s();this.scene.add(d.root);const u=Ws();i.anchors.hand.add(u.root);const p={activity:u,concert:d,rig:i,atmosphere:l,look:s,worn:"",shadow:n,proxy:a,bubble:o,bubbleKey:""};return this.robots.set(e,p),p}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 Q(s.x,.6,s.z),13)}frameEveryone(e){const t=[{x:0,z:0},...e.map(o=>({x:o.x,z:o.z}))],s={x:t.reduce((o,l)=>o+l.x,0)/t.length,z:t.reduce((o,l)=>o+l.z,0)/t.length},i=Math.max(14,...t.map(o=>Math.hypot(o.x-s.x,o.z-s.z)+7)),n=Math.min(this.controls.maxDistance,i*1.85),a=new Q(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 Q(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 o=i.object;for(;o;){if(o===a.object)return n;o=o.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 p=new Date;this.hour=this.hourOverride??p.getHours()+p.getMinutes()/60+p.getSeconds()/3600,this.sky=Tt(this.hour),this.sun.position.copy(this.sky.sun),this.sun.color.copy(this.sky.sunColor);const h=Rt(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 he("#eef6ff").lerp(new he("#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=Rt(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 o=new Set;for(const[p,h]of this.robots){const c=this.sim.robots.get(p);if(!c)continue;const m=this.groundAt(c.x,c.z,n),b=bt.has(c.pose),g=c.perched?Math.max(c.y,m):m;h.rig.root.position.set(c.x,g,c.z),h.rig.root.rotation.y=c.heading,h.concert.root.position.set(c.x,m,c.z),h.concert.root.rotation.y=c.heading,h.concert.update(c.pose==="dance"&&this.sim.audience(p)>0,t,s,i);const x=c.plan.act;h.activity.show(x.kind==="wish-register"?"register":x.kind==="interact"&&!c.path.length?x.site.activity:null);const k=x.kind==="work"&&x.seat?.kind==="desk"&&!c.path.length;if(Wt(h.rig,c.pose,s+Lt(p)%97*.13,{stride:c.stride,calm:i,console:!k&&x.kind!=="interact",lean:c.lean,bored:c.boredom>.72}),x.kind==="interact"&&!c.path.length){if(x.site.activity==="read")h.rig.head.rotation.x=.18,h.rig.arms.forEach(M=>{M.shoulder.rotation.x=-.65,M.elbow.rotation.x=-.85});else if(x.site.activity==="garden"||x.site.activity==="paint"){if(x.site.activity==="garden"){o.add(x.site.key);let M=this.gardenBeds.get(x.site.key);M||(M=Ds(),M.root.position.set(x.site.x+Math.sin(x.site.face)*.65,V+.02,x.site.z+Math.cos(x.site.face)*.65),this.scene.add(M.root),this.gardenBeds.set(x.site.key,M))}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=x.site.activity==="garden"?-.35:0}}else h.activity.root.rotation.z=0;const z=Si(a,c.pose);h.atmosphere.umbrella.visible=z,h.atmosphere.umbrella.position.y=b?-at:0,z&&(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-g+.035,h.shadow.position.set(c.x,m+.025,c.z),h.shadow.scale.setScalar(c.perched&&g-m>.15?.7:1),h.proxy.position.set(c.x,g+(b?.45:.6),c.z),h.proxy.rotation.y=c.heading;const v=c.bubble;if(v){const M=`${v.tone}:${v.text}`;if(M!==h.bubbleKey){const T=this.bubbles.material(v);T&&(h.bubble.material=T.material,h.bubble.scale.set(.6*T.aspect,.6,1)),h.bubbleKey=M}const E=g+(b?1-at:1),A=i?0:Math.sin(s*2.4+Lt(p))*.03;h.bubble.position.set(c.x,E+.55+A,c.z),h.bubble.visible=!0}else h.bubble.visible=!1}for(const[p,h]of this.gardenBeds)h.update(t,o.has(p));if(this.scenery?.update(i?0:s,this.sky.night,this.sky,this.sky.sea),this.flight){const p=Math.min(1,(s-this.flight.start)/this.flight.seconds),h=1-Math.pow(1-p,3),c=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(c),this.camera.position.copy(c).add(b),p>=1&&(this.flight=null)}this.panByKeys(t);const l=this.selected?this.sim.robots.get(this.selected):void 0;if(l){if(this.following){const p=new Q(l.x,.6,l.z);if(this.flight)this.flight.to.copy(p);else{const h=p.sub(this.controls.target).multiplyScalar(Math.min(1,t*3));this.controls.target.add(h),this.camera.position.add(h)}}this.ring.position.set(l.x,this.groundAt(l.x,l.z,n)+.03,l.z),this.ring.scale.setScalar(i?1:1+Math.sin(s*2)*.04),Math.floor(s*8)!==Math.floor((s-t)*8)&&this.fadeOccluders(l.x,l.z)}const d=this.controls.target,u=Math.hypot(d.x,d.z);u>n+4&&d.multiplyScalar((n+4)/u),d.y=Math.max(0,Math.min(2,d.y)),this.controls.update(),this.placeLabels(),this.renderer.render(this.scene,this.camera)};onKeyDown=e=>{const t=e.key.toLowerCase();!Ti.has(t)||e.metaKey||e.ctrlKey||e.altKey||Ri(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 Q(-t.z,0,t.x),i=new Q;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&&_i(e,t,i.walkways))return i.deck;const[n,a]=Jt(e,t);return n===0&&a===0?Math.hypot(e,t)<et-.6?V:0:this.tiled.has(`${n},${a}`)&&Vt(e,t)?V:pt(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=bt.has(i.pose),o=n.rig.root.position.y-(a?at:0),l=new Q(i.x,o,i.z).project(this.camera);if(l.z>1){t.hidden=!0;return}const d=this.canvas.getBoundingClientRect(),u=(l.x*.5+.5)*d.width,p=(-l.y*.5+.5)*d.height;t.hidden=!1;const h=this.residents.find(c=>c.key===s)?.name??"";t.textContent!==h&&(t.textContent=h),t.style.transform=`translate(${u.toFixed(1)}px, ${p.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 Q(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 o=[...this.placed.values()].map(u=>u.object),l=this.raycaster.intersectObjects(o,!0);this.raycaster.far=1/0;const d=new Set;for(const u of l){const p=u.object.parent;if(p)for(const h of p.children)h instanceof O&&d.add(h)}for(const[u,p]of[...this.faded])d.has(u)||(u.material=p,this.faded.delete(u));for(const u of d)this.faded.has(u)||(this.faded.set(u,u.material),u.material=this.fadedOf(u.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.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 Ti=new Set(["w","a","s","d","shift"]);function Ri(r){const e=r;return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable]:not([contenteditable='false'])")}function Lt(r){let e=0;for(const t of r)e=e*31+(t.codePointAt(0)??0)>>>0;return e%1e3}function Di(r,e,t){const s=[],i=(e.facing+t.turn)*We,n=t.turn*We;for(const a of r.parts){const o=st(a),l=o.min[1]+t.y,d=o.max[1]+t.y;if(l>.55||d<.16)continue;const u=(o.min[0]+o.max[0])/2,p=(o.min[2]+o.max[2])/2,h=t.x+u*Math.cos(n)+p*Math.sin(n),c=t.z-u*Math.sin(n)+p*Math.cos(n),m=Ee(e,h,c);s.push({cx:m.x,cz:m.z,hx:(o.max[0]-o.min[0])/2,hz:(o.max[2]-o.min[2])/2,yaw:i})}return s}function Li(r,e,t){const s=r.name.toLowerCase(),i=r.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)||r.kind!=="furniture"&&r.kind!=="decor")return null;let n=r.spot;if(!n){const c=r.parts.map(st),m=Math.max(...c.map(x=>x.max[2])),b=c.filter(x=>x.max[1]<(i==="seat"?.65:.9)),g=b.length?Math.max(...b.map(x=>x.max[1])):.3;n=i==="desk"?{at:[0,0,m+.45],face:180}:{at:[0,g+.03,0],face:0}}const a=t.turn*We,[o,l,d]=n.at,u=t.x+o*Math.cos(a)+d*Math.sin(a),p=t.z-o*Math.sin(a)+d*Math.cos(a),h=Ee(e,u,p);return{key:`${t.id}:${r.id}`,kind:i==="desk"?"desk":i==="bed"?"bed":"seat",x:h.x,z:h.z,y:V+t.y+l,face:(e.facing+t.turn+n.face)*We,plot:e.id,name:r.name}}const Ct=[{id:"often",label:"Often"},{id:"sometimes",label:"Sometimes"},{id:"rarely",label:"Rarely"},{id:"never",label:"Never"}],Ci={cozy:"Cozy",curious:"Curious",sporty:"Sporty",artsy:"Artsy",tinkerer:"Tinkerer",dreamy:"Dreamy",foodie:"Foodie",gardener:"Gardener"};function Gi({connected:r,snapshot:e,projects:t,running:s,busy:i,waitingOn:n,held:a,chatTitle:o,chatExists:l,onAsk:d,onOpenChat:u,onClose:p}){const h=As(r),{rows:c,team:m,teams:b}=es({connected:r,snapshot:e,projects:t,running:s,busy:i,waitingOn:n,held:a,chatTitle:o,chatExists:l}),g=ts(),x=L.useMemo(()=>(m??[]).map(f=>({id:f.id,name:f.name,agent:f.agent,model:f.model,avatar:f.avatar,teamId:f.teamId,teamName:b.find(_=>_.id===f.teamId)?.name,leader:!f.reportsTo||(m??[]).some(_=>_.reportsTo===f.id)})),[m,b]),k=L.useMemo(()=>h.island?ss(h.island,x):[],[h.island,x]),z=L.useMemo(()=>h.island?Yt(h.island,k).residents:[],[h.island,k]),v=h.island?.wishes.filter(f=>f.state==="queued").length??0,M=L.useMemo(()=>h.island?is(h.island):[],[h.island]),E=L.useMemo(()=>Ts(c),[c]),A=L.useMemo(()=>JSON.stringify([...E]),[E]),T=L.useRef(null),K=L.useRef(null),J=L.useRef(null),N=L.useRef(null),[C,B]=L.useState("starting"),[$,F]=L.useState(null),[pe,ye]=L.useState(null),[xe,H]=L.useState(null),[ae,te]=L.useState(()=>typeof window<"u"&&window.innerWidth>860),[se,le]=L.useState(null),[fe,_e]=L.useState(null),[Me,we]=L.useState(!1),[$e,Ue]=L.useState(0),[ce,P]=L.useState("auto");L.useEffect(()=>{N.current?.setWeather(ce)},[ce,C]);const I=JSON.stringify([...i].filter(f=>f.startsWith("chat:island-wish-")).sort());L.useEffect(()=>{r&&h.reload()},[r,I,h.reload]),L.useEffect(()=>{const f=T.current;if(!f)return;const _=window.matchMedia?.("(prefers-reduced-motion: reduce)");let D;try{D=new Ai(f,{onPick:de=>F(de),onLost:()=>B("lost"),onWishGiveUp:de=>{De.invoke("island_wish_withdraw",{id:de}).catch(()=>{})},onWishRegister:de=>{De.invoke("island_wish_register",{id:de}).catch(()=>{})}},!!_?.matches)}catch{B("no");return}K.current&&J.current&&D.setLabels(K.current,J.current),N.current=D,B("yes");const Y=()=>D.setReducedMotion(!!_?.matches);return _?.addEventListener?.("change",Y),()=>{_?.removeEventListener?.("change",Y),D.dispose(),N.current=null}},[$e]),L.useEffect(()=>{h.island&&N.current&&N.current.setIsland(h.island,k)},[h.island,k,C]);const G=L.useRef(E);G.current=E,L.useEffect(()=>{N.current?.setModes(G.current)},[A,C,k]);const ee=L.useRef(0);L.useEffect(()=>{const f=h.change,_=h.island;if(!(!f||!_||_.rev<f.rev||ee.current>=f.rev)){if(ee.current=f.rev,f.what==="grant"&&f.id){const D=_.wishes.find(de=>de.id===f.id),Y=D&&nt(D,k);Y&&N.current?.event("gift",Y.key)}f.what==="home"&&f.id&&N.current?.homeChanged(f.id)}},[h.change,h.island,k]),L.useEffect(()=>{N.current?.select($)},[$]),L.useEffect(()=>{if(!$){ye(null),H(null);return}const f=()=>{ye(N.current?.describe($)??null);const D=N.current?.mood($)??null;H(Y=>Y&&D&&Math.round(Y.boredom*100)===Math.round(D.boredom*100)&&Y.excited===D.excited&&Y.said===D.said?Y:D)};f();const _=window.setInterval(f,500);return()=>window.clearInterval(_)},[$]),L.useEffect(()=>{const f=_=>{_.key==="Escape"&&$&&F(null)};return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[$]);const ie=async(f,_)=>{if(!se){le(f),_e(null);try{await _()}catch(D){_e(String(D?.message??D))}finally{le(null)}}},Z=$?z.find(f=>f.key===$):void 0,Se=Z?.agent?c.find(f=>f.id===Z.agent.id):void 0,me=f=>M.find(_=>_.who.kind===f.owner.kind&&_.who.id===f.owner.id),Be=L.useMemo(()=>(h.island?.wishes??[]).filter(f=>f.state==="granted").sort((f,_)=>(_.closedAt??_.madeAt)-(f.closedAt??f.madeAt)).slice(0,20),[h.island]),qe=f=>nt(f,k)?.name??"A robot who left",w=f=>{ie(`grant:${f.id}`,()=>h.grantWish(f.id))},S=f=>se===`grant:${f.id}`||i.has(`chat:island-wish-${f.id}`)||f.execution?.state==="building",R=f=>f?.activities.find(_=>_.chatKey)?.chatKey??f?.recent?.chatKey??null,j=y.jsxs(y.Fragment,{children:[y.jsxs("button",{type:"button",className:"projects-page-secondary island-wishes-button","aria-expanded":ae,"aria-controls":"island-panel",onClick:()=>te(f=>!f),title:M.length?`${M.length} open ${M.length===1?"wish":"wishes"}`:"Wishes and residents",children:[y.jsx(Nt,{}),y.jsx("span",{children:"Wishes"}),M.length>0&&y.jsx("span",{className:"island-count",children:M.length})]}),y.jsxs("button",{type:"button",className:"projects-page-secondary island-compact",onClick:()=>{F(null),N.current?.recenter()},disabled:C!=="yes","aria-label":"See the whole island",title:"See the whole island",children:[y.jsx($i,{}),y.jsx("span",{children:"Whole island"})]})]});return y.jsxs("section",{className:"projects-page island-page","aria-label":"Island",children:[y.jsx(ns,{root:!0,back:{label:"Chat",ariaLabel:"Back to chat",onClick:p},title:y.jsx("h1",{children:"Island"}),actions:j}),fe&&y.jsx("p",{className:"island-error",role:"alert",children:fe}),y.jsxs("div",{className:`island-body${ae?" has-panel":""}`,children:[y.jsxs("div",{className:"island-stage",ref:T,role:"img","aria-label":`The island in 3D, with ${k.length} robots. Use the panel's list to find someone.`,children:[y.jsx("div",{className:"island-name",ref:K,hidden:!0}),y.jsx("div",{className:"island-name is-selected",ref:J,hidden:!0}),C==="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."}),C==="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:()=>{B("starting"),Ue(f=>f+1)},children:"Draw it again"})]}),!h.island&&!h.error&&C!=="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"})]}),Z&&y.jsx(Oi,{resident:Z,row:Se,status:pe,mood:xe,housemates:Z.plot?z.filter(f=>f.plot?.id===Z.plot?.id&&f.key!==Z.key).map(f=>f.name):[],wish:me(Z),busy:!!se||!r,onGrant:w,building:!!me(Z)&&S(me(Z)),onOpenChat:f=>u(f),chatKey:R(Se),onAsk:Z.agent?()=>d(Z.agent.id,"On the OctiqFlow island, build yourself "):void 0,onFarewell:Z.owner.kind==="bot"?async()=>{await g({title:`Say goodbye to ${Z.name}?`,body:`${Z.name} sails away. Its plot, what stands on it and its open wish go with it.`,confirmLabel:"Say goodbye",danger:!0})&&(F(null),await ie("farewell",()=>h.farewell(Z.owner.id)))}:void 0,onClose:()=>F(null)})]}),ae&&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:()=>te(!1),children:y.jsx(qt,{})})]}),v>0&&y.jsxs("p",{className:"island-meta",children:[v," waiting to register at BOT Society"]}),M.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:M.map(f=>{const _=nt(f,k);return y.jsxs("li",{className:"island-wish",children:[y.jsxs("button",{type:"button",className:"island-wish-who",onClick:()=>_&&F(_.key),disabled:!_,title:_?`Show ${_.name}`:void 0,children:[y.jsx(ct,{resident:_}),y.jsx("bdi",{children:qe(f)}),y.jsx("span",{className:"island-meta",children:Rs(f.madeAt)})]}),y.jsxs("p",{className:"island-wish-text",children:["wishes for ",y.jsx("bdi",{children:f.text})]}),f.execution?.state==="unfinished"&&!S(f)&&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:()=>w(f),disabled:!!se||S(f)||!r,title:"Build this present in the background",children:S(f)?"Building…":f.execution?"Retry":"Grant"}),y.jsx("button",{type:"button",className:"projects-page-secondary",disabled:!!se,onClick:()=>{ie(`dismiss:${f.id}`,()=>h.dismissWish(f.id))},children:"Dismiss"})]})]},f.id)})}),y.jsxs("div",{className:"island-pace",children:[y.jsx("label",{htmlFor:"island-weather",children:"Island weather"}),y.jsxs("select",{id:"island-weather",value:ce,onChange:f=>P(f.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||!!se,onChange:f=>{ie("building",()=>h.setBuildPace(f.target.value))},children:Ct.map(f=>y.jsx("option",{value:f.id,children:f.label},f.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||!!se,onChange:f=>{ie("pace",()=>h.setPace(f.target.value))},children:Ct.map(f=>y.jsx("option",{value:f.id,children:f.label},f.id))}),y.jsx("button",{type:"button",className:"projects-page-secondary",disabled:!h.island||!!se,onClick:()=>{ie("roll",h.rollWish)},children:"Ask for a wish"})]}),Be.length>0&&y.jsxs("div",{className:"island-granted",children:[y.jsxs("button",{type:"button",className:"island-disclosure","aria-expanded":Me,onClick:()=>we(f=>!f),children:[y.jsx(Ui,{open:Me}),"Granted · ",Be.length]}),Me&&y.jsx("ul",{children:Be.map(f=>y.jsxs("li",{children:[y.jsx("bdi",{children:qe(f)})," got ",y.jsx("bdi",{children:f.text}),f.grant?.by.name&&y.jsxs("span",{className:"island-meta",children:[" · from ",y.jsx("bdi",{children:f.grant.by.name})]})]},f.id))})]}),y.jsx("h2",{className:"island-panel-sub",children:"Who lives here"}),y.jsx("ul",{className:"island-residents",children:k.map(f=>{const _=f.agent?c.find(D=>D.id===f.agent.id):void 0;return y.jsx("li",{children:y.jsxs("button",{type:"button","aria-pressed":$===f.key,onClick:()=>F(f.key),children:[y.jsx(ct,{resident:f}),y.jsx("bdi",{className:"island-resident-name",children:f.name}),y.jsx("span",{className:"island-meta",children:f.agent?Ii(_):Zt(f)}),me(f)&&y.jsx("span",{className:"island-has-wish",title:"Has a wish",children:y.jsx(Nt,{})})]})},f.key)})})]})]})]})}function Ni(r){return r.length<=1?r[0]??"":`${r.slice(0,-1).join(", ")} & ${r[r.length-1]}`}function Zt(r){const e=Ci[r.trait??""];return e?`${e} 波特`:"波特"}function Ii(r){switch(r?.state){case"working":return"Working";case"needs_you":return"Needs you";case"failed":return"Failed";default:return"Agent"}}function Oi({resident:r,row:e,status:t,mood:s,housemates:i,wish:n,busy:a,building:o,chatKey:l,onGrant:d,onOpenChat:u,onAsk:p,onFarewell:h,onClose:c}){const m=r.agent,b=e?.state==="needs_you"?"decide":e?.state==="failed"?"danger":void 0;return y.jsxs("div",{className:"island-card",role:"dialog","aria-label":r.name,children:[y.jsxs("div",{className:"island-card-head",children:[m?y.jsx(as,{name:m.name,id:m.id,avatar:m.avatar,size:30,decorative:!0}):y.jsx(ct,{resident:r,large:!0}),y.jsxs("div",{className:"island-card-who",children:[y.jsx("bdi",{className:"island-card-name",children:r.name}),y.jsx("span",{className:"island-meta",children:m?"Agent":Zt(r)})]}),y.jsx("button",{type:"button",className:"island-close","aria-label":"Stop following",title:"Stop following",onClick:c,children:y.jsx(qt,{})})]}),t&&y.jsx("p",{className:"island-card-status","data-tone":b,children:t}),!!r.hobbies?.length&&y.jsxs("p",{className:"island-meta",children:["Interests: ",r.hobbies.join(", ")]}),r.plot?.officeName&&y.jsxs("p",{className:"island-meta",children:[r.plot.officeName," · Personal desk"]}),i.length>0&&y.jsxs("p",{className:"island-meta island-card-home",children:["Office with ",y.jsx("bdi",{children:Ni(i)})]}),s?.said&&y.jsxs("p",{className:"island-card-said",children:["“",y.jsx("bdi",{children:s.said}),"”"]}),s&&y.jsx(Wi,{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"&&!o&&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||o,onClick:()=>d(n),children:o?"Building…":n.execution?"Retry":"Grant"})]}),y.jsxs("div",{className:"island-card-actions",children:[l&&y.jsx("button",{type:"button",className:"projects-page-secondary",onClick:()=>u(l),children:"Open chat"}),p&&y.jsx("button",{type:"button",className:"projects-page-secondary",onClick:p,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 Wi({boredom:r,excited:e}){const t=Math.round(r*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 ct({resident:r,large:e=!1}){const t=r?{"--robot-shell":r.look.shell,"--robot-trim":r.look.trim,"--robot-glow":r.look.glow}:void 0;return y.jsx("span",{className:`island-dot${e?" is-large":""}`,style:t,"aria-hidden":"true",children:y.jsx("span",{})})}function Nt(){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 $i(){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 qt(){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 Ui({open:r}){return y.jsx("svg",{className:`island-chevron${r?" 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{Gi as default};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.island-body{position:relative;display:flex;flex:1 1 auto;min-height:0}.island-stage{position:relative;flex:1 1 auto;min-width:0;overflow:hidden;background:var(--bg-1)}.island-canvas{position:absolute;inset:0;display:block;width:100%;height:100%;touch-action:none;outline:none}.island-name{position:absolute;top:0;left:0;padding:2px 9px;border-radius:var(--r-pill);background:color-mix(in srgb,var(--bg-0) 90%,transparent);box-shadow:var(--shadow-sm);color:var(--fg-0);font-size:12px;font-weight:600;line-height:18px;white-space:nowrap;pointer-events:none;will-change:transform}.island-name.is-selected{font-size:12.5px}.island-name[hidden]{display:none}.island-note{position:absolute;top:50%;left:50%;display:grid;gap:10px;justify-items:center;max-width:min(360px,calc(100% - 32px));margin:0;padding:14px 18px;border:1px solid var(--border);border-radius:var(--r-lg);background:var(--bg-0);box-shadow:var(--shadow);color:var(--fg-1);font-size:13px;line-height:1.45;text-align:center;transform:translate(-50%,-50%)}.island-note p{margin:0}.island-note.is-quiet{border-color:transparent;box-shadow:none;background:transparent;color:var(--fg-2)}.island-meta{color:var(--fg-3);font-size:11.5px;font-weight:400}.island-card{position:absolute;left:16px;bottom:16px;display:grid;gap:10px;width:min(320px,calc(100% - 32px));padding:12px 14px;border:1px solid var(--border);border-radius:var(--r-lg);background:var(--bg-0);box-shadow:var(--shadow);color:var(--fg-1);animation:island-arrive .18s var(--enter-ease, ease-out) both}@keyframes island-arrive{0%{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}.island-card-head{display:flex;align-items:center;gap:10px;min-width:0}.island-card-who{display:grid;flex:1 1 auto;min-width:0}.island-card-name{overflow:hidden;color:var(--fg-0);font-size:14px;font-weight:600;text-overflow:ellipsis;white-space:nowrap}.island-card-status{margin:0;color:var(--fg-2);font-size:13px;line-height:1.4;overflow-wrap:anywhere}.island-card-status[data-tone=decide]{color:var(--decide)}.island-card-status[data-tone=danger]{color:var(--danger)}.island-card-home{margin:-6px 0 0}.island-card-said{margin:-4px 0 0;color:var(--fg-1);font-size:13px;font-style:italic;line-height:1.4;overflow-wrap:anywhere}.island-boredom{display:grid;grid-template-columns:auto minmax(0,1fr) 3.2em;align-items:center;gap:8px}.island-boredom-bar{position:relative;height:4px;overflow:hidden;border-radius:var(--r-pill);background:var(--bg-2)}.island-boredom-bar>span{position:absolute;inset:0 auto 0 0;border-radius:inherit;background:var(--fg-3);transition:width .4s var(--enter-ease, ease-out)}.island-boredom-value{text-align:right;font-variant-numeric:tabular-nums}.island-card-wish{display:flex;align-items:center;gap:10px;padding:8px 10px;border-radius:var(--r-md);background:var(--bg-1)}.island-card-wish p{flex:1 1 auto;min-width:0;margin:0;font-size:12.5px;line-height:1.4;overflow-wrap:anywhere}.island-card-actions{display:flex;flex-wrap:wrap;gap:8px}.island-card-actions:empty{display:none}.island-grant.projects-page-primary{flex:none;border-color:color-mix(in srgb,var(--decide) 40%,transparent);background:var(--decide-tint);color:var(--decide);font-weight:600}.island-grant.projects-page-primary:hover{background:color-mix(in srgb,var(--decide) 18%,var(--bg-0))}.island-close{display:inline-grid;flex:none;width:28px;height:28px;place-items:center;border:0;border-radius:var(--r-sm);background:transparent;color:var(--fg-2);cursor:pointer}.island-close:hover{background:var(--bg-1);color:var(--fg-0)}.island-dot{display:inline-grid;flex:none;width:14px;height:14px;place-items:center;border-radius:40%;background:var(--robot-trim, var(--fg-3));box-shadow:inset 0 0 0 2px var(--robot-shell, var(--bg-2))}.island-dot>span{width:45%;height:22%;border-radius:var(--r-pill);background:var(--robot-glow, var(--bg-0))}.island-dot.is-large{width:30px;height:30px;border-radius:34%;box-shadow:inset 0 0 0 3px var(--robot-shell, var(--bg-2))}.island-panel{flex:0 0 320px;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:12px 14px 18px;border-left:1px solid var(--border);background:var(--bg-0);color:var(--fg-1)}.island-panel h2{margin:0;color:var(--fg-0);font-size:13px;font-weight:600}.island-panel-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}.island-panel-sub{margin-top:18px!important;margin-bottom:6px!important}.island-empty{margin:4px 0 8px;color:var(--fg-3);font-size:12.5px;line-height:1.45}.island-error{margin:0 0 8px;color:var(--danger);font-size:12.5px;line-height:1.4;overflow-wrap:anywhere}.island-wishes{display:grid;gap:8px;margin:0;padding:0;list-style:none}.island-wish{padding:10px;border:1px solid var(--border);border-radius:var(--r-md)}.island-wish-who{display:flex;align-items:center;gap:8px;width:100%;padding:0;border:0;background:none;color:var(--fg-0);font:inherit;font-size:13px;font-weight:600;text-align:left;cursor:pointer}.island-wish-who .island-meta{margin-left:auto}.island-wish-who:disabled{cursor:default;color:var(--fg-2)}.island-wish-text{margin:4px 0 10px;color:var(--fg-1);font-size:13px;line-height:1.45;overflow-wrap:anywhere}.island-wish-actions{display:flex;gap:8px}.island-pace{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:12px 0 4px;color:var(--fg-2);font-size:12.5px}.island-pace select{min-height:30px;padding:0 8px;border:1px solid var(--border);border-radius:var(--r-sm);background:var(--bg-0);color:var(--fg-1);font:inherit}.island-granted{margin-top:14px}.island-granted ul{display:grid;gap:6px;margin:6px 0 0;padding:0 0 0 18px;color:var(--fg-2);font-size:12.5px;line-height:1.4}.island-disclosure{display:inline-flex;align-items:center;gap:4px;padding:2px 0;border:0;background:none;color:var(--fg-2);font:inherit;font-size:12.5px;cursor:pointer}.island-disclosure:hover{color:var(--fg-0)}.island-chevron{transition:transform .16s var(--enter-ease, ease-out)}.island-chevron.is-open{transform:rotate(90deg)}.island-residents{display:grid;gap:2px;margin:0;padding:0;list-style:none}.island-residents button{display:flex;align-items:center;gap:8px;width:100%;min-height:34px;padding:4px 8px;border:0;border-radius:var(--r-sm);background:transparent;color:var(--fg-1);font:inherit;font-size:13px;text-align:left;cursor:pointer}.island-residents button:hover{background:var(--bg-1)}.island-residents button[aria-pressed=true]{background:var(--bg-2);color:var(--fg-0)}.island-resident-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.island-residents .island-meta{margin-left:auto;white-space:nowrap}.island-has-wish{display:inline-flex;color:var(--fg-2)}.island-wishes-button{position:relative}.island-count{min-width:18px;padding:0 5px;border-radius:var(--r-pill);background:var(--bg-2);color:var(--fg-1);font-size:11px;font-weight:600;line-height:18px;text-align:center}@media(max-width:600px){.island-compact>span{display:none}}@media(max-width:860px){.island-panel{position:absolute;right:0;bottom:0;left:0;z-index:3;max-height:62%;border-top:1px solid var(--border);border-left:0;border-radius:var(--r-lg) var(--r-lg) 0 0;box-shadow:var(--shadow)}.island-card{right:12px;bottom:12px;left:12px;width:auto}.island-close{width:40px;height:40px}.island-residents button{min-height:44px}}@media(prefers-reduced-motion:reduce){.island-card{animation:none}.island-chevron{transition:none}}
|
|
Binary file
|
|
Binary file
|