gaesup-world 1.0.1 → 1.0.2

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.
Files changed (37) hide show
  1. package/dist/{GrassDriver-5qlyynpq.cjs → GrassDriver-0VzddMiy.cjs} +1 -1
  2. package/dist/{GrassDriver-D3C3nNuR.js → GrassDriver-CgXNOTL2.js} +36 -37
  3. package/dist/PhysicsEntity-BpoArh5L.cjs +1 -0
  4. package/dist/{PhysicsEntity-CfUR6qfV.js → PhysicsEntity-Cy3K_czk.js} +399 -398
  5. package/dist/blueprints-editor.cjs +1 -1
  6. package/dist/blueprints-editor.js +4 -4
  7. package/dist/blueprints.cjs +1 -1
  8. package/dist/blueprints.js +2 -2
  9. package/dist/core/motions/core/system/PhysicsSystem.d.ts +1 -0
  10. package/dist/{defaultConfig-CiF9wN96.cjs → defaultConfig-BR_x-243.cjs} +1 -1
  11. package/dist/{defaultConfig-COlgACOY.js → defaultConfig-CJNbZAKY.js} +3 -3
  12. package/dist/editor.cjs +1 -1
  13. package/dist/editor.js +3 -3
  14. package/dist/{gaesupStore-c2IZvvF8.js → gaesupStore-BKIA2dFc.js} +1 -1
  15. package/dist/{gaesupStore-BUvjyYKz.cjs → gaesupStore-BoN_06sX.cjs} +1 -1
  16. package/dist/{index-CQH04fpl.cjs → index-B9921cuX.cjs} +1 -1
  17. package/dist/{index-Dgc3RSmz.cjs → index-BOmJcTCV.cjs} +1 -1
  18. package/dist/{index-BJmo08pc.cjs → index-BUONBdvH.cjs} +1 -1
  19. package/dist/{index-BEDIGqAu.js → index-BjrBeKEM.js} +149 -150
  20. package/dist/{index-DKypFCSV.js → index-BlKxYuUK.js} +3 -3
  21. package/dist/{index-gzJaPL5R.js → index-BmOFYbvk.js} +2 -2
  22. package/dist/{index-C4JG_j3y.js → index-BnACo_cG.js} +6 -7
  23. package/dist/{index-DLPhCgI6.js → index-BsAUS0-8.js} +1 -1
  24. package/dist/{index-BCc8fuy2.cjs → index-CwttQ-l-.cjs} +1 -1
  25. package/dist/{index-Dj5aHiJD.cjs → index-SFK6DuIo.cjs} +1 -1
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.js +17 -17
  28. package/dist/network.cjs +1 -1
  29. package/dist/network.js +3 -3
  30. package/dist/{registerComponents-CGbbVhvf.js → registerComponents-BfIcN9qa.js} +2 -2
  31. package/dist/{registerComponents-UboG7NXy.cjs → registerComponents-D3FUm9GA.cjs} +1 -1
  32. package/dist/runtime.cjs +1 -1
  33. package/dist/runtime.js +6 -6
  34. package/dist/{useSpawnFromBlueprint-hqIkXXNv.cjs → useSpawnFromBlueprint-1gMiylSa.cjs} +1 -1
  35. package/dist/{useSpawnFromBlueprint-DUJ0eO6H.js → useSpawnFromBlueprint-fzl4TuHG.js} +1 -1
  36. package/package.json +1 -1
  37. package/dist/PhysicsEntity-CP_HUQG-.cjs +0 -1
@@ -1,4 +1,4 @@
1
- "use strict";const t=require("react/jsx-runtime"),u=require("react"),Be=require("reactflow");;/* empty css */const At=require("./seedEvents-Dmms48tb.cjs"),Ye=require("./assetStore-BuE4mh1C.cjs"),st=require("./index-BCc8fuy2.cjs"),re=require("./gaesupStore-BUvjyYKz.cjs"),S=require("./PhysicsEntity-CP_HUQG-.cjs"),pt=require("./index-DCa_lUwq.cjs"),rt=require("zustand"),dn=require("zustand/react/shallow"),Ge=require("@react-three/drei"),ae=require("@react-three/fiber"),Yo=require("three"),Ot=require("./sfe-CpgzdMyB.cjs"),ot=require("@react-three/rapier"),gs=require("three-stdlib");require("reflect-metadata");const oi=require("./weatherStore-1unmwIen.cjs"),bs=require("simplex-noise"),Xo=require("./authStore-CrDnYNnL.cjs"),qo=require("immer"),Ko=require("zustand/middleware/immer");function Jo(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(s,n,i.get?i:{enumerable:!0,get:()=>e[n]})}}return s.default=e,Object.freeze(s)}const b=Jo(Yo);function je({label:e,min:s,max:n,step:i,value:o,suffix:r,onChange:a}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:"#fff"},children:[t.jsx("span",{style:{width:60,flexShrink:0,color:"rgba(255,255,255,0.7)"},children:e}),t.jsx("input",{type:"range",min:s,max:n,step:i,value:o,onChange:l=>a(Number(l.target.value)),style:{flex:1,accentColor:"#0078d4"}}),t.jsxs("span",{style:{width:44,textAlign:"right",fontFamily:"monospace",fontSize:11},children:[typeof i=="number"&&i<1?o.toFixed(2):o,r??""]})]})}function Dn({label:e,checked:s,onChange:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"#fff"},children:[t.jsx("input",{type:"checkbox",checked:s,onChange:i=>n(i.target.checked),style:{accentColor:"#0078d4"}}),t.jsx("span",{children:e})]})}function jt({title:e,children:s}){return t.jsxs("div",{style:{background:"rgba(0,0,0,0.2)",borderRadius:6,padding:"8px 10px",border:"1px solid rgba(255,255,255,0.08)",display:"flex",flexDirection:"column",gap:6},children:[t.jsx("div",{style:{fontSize:10,fontWeight:600,color:"rgba(255,255,255,0.5)",textTransform:"uppercase",letterSpacing:.5},children:e}),s]})}function Qo(){const e=re.useGaesupStore(a=>a.cameraOption),s=re.useGaesupStore(a=>a.setCameraOption),n=re.useGaesupStore(a=>a.mode),i=u.useCallback((a,l)=>{s({[a]:l})},[s]),o=u.useCallback((a,l)=>{s({smoothing:{...e.smoothing,[a]:l}})},[s,e.smoothing]),r=a=>e[a]??0;return t.jsxs("div",{style:{padding:10,display:"flex",flexDirection:"column",gap:10},children:[t.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.5)",marginBottom:-4},children:["Mode: ",n.control??"thirdPerson"]}),t.jsxs(jt,{title:"Distance",children:[t.jsx(je,{label:"X",min:-50,max:50,step:1,value:r("xDistance"),onChange:a=>i("xDistance",a)}),t.jsx(je,{label:"Y",min:0,max:50,step:1,value:r("yDistance"),onChange:a=>i("yDistance",a)}),t.jsx(je,{label:"Z",min:-50,max:50,step:1,value:r("zDistance"),onChange:a=>i("zDistance",a)})]}),t.jsxs(jt,{title:"FOV / Smoothing",children:[t.jsx(je,{label:"FOV",min:30,max:120,step:5,value:e.fov??75,suffix:"deg",onChange:a=>i("fov",a)}),t.jsx(je,{label:"Pos",min:.01,max:1,step:.01,value:e.smoothing?.position??.1,onChange:a=>o("position",a)}),t.jsx(je,{label:"Rot",min:.01,max:1,step:.01,value:e.smoothing?.rotation??.1,onChange:a=>o("rotation",a)}),t.jsx(je,{label:"FOV Sm",min:.01,max:1,step:.01,value:e.smoothing?.fov??.2,onChange:a=>o("fov",a)})]}),t.jsxs(jt,{title:"Zoom",children:[t.jsx(Dn,{label:"Enable Zoom",checked:e.enableZoom??!1,onChange:a=>i("enableZoom",a)}),t.jsx(je,{label:"Speed",min:1e-4,max:.01,step:1e-4,value:e.zoomSpeed??.001,onChange:a=>i("zoomSpeed",a)}),t.jsx(je,{label:"Min",min:.1,max:2,step:.1,value:e.minZoom??.5,onChange:a=>i("minZoom",a)}),t.jsx(je,{label:"Max",min:1,max:5,step:.1,value:e.maxZoom??2,onChange:a=>i("maxZoom",a)})]}),t.jsxs(jt,{title:"Options",children:[t.jsx(Dn,{label:"Collision",checked:e.enableCollision??!1,onChange:a=>i("enableCollision",a)}),t.jsx(Dn,{label:"Focus Mode",checked:e.enableFocus??!1,onChange:a=>i("enableFocus",a)}),t.jsx(je,{label:"Focus Dist",min:1,max:50,step:1,value:e.focusDistance??15,onChange:a=>i("focusDistance",a)}),t.jsx(je,{label:"Max Dist",min:5,max:100,step:1,value:e.maxDistance??50,onChange:a=>i("maxDistance",a)})]}),t.jsxs(jt,{title:"Bounds",children:[t.jsx(je,{label:"Min Y",min:-10,max:50,step:1,value:e.bounds?.minY??2,onChange:a=>s({bounds:{...e.bounds,minY:a}})}),t.jsx(je,{label:"Max Y",min:5,max:100,step:1,value:e.bounds?.maxY??50,onChange:a=>s({bounds:{...e.bounds,maxY:a}})})]})]})}const er=[{value:"thirdPerson",label:"Third Person"},{value:"firstPerson",label:"First Person"},{value:"chase",label:"Chase"},{value:"topDown",label:"Top Down"},{value:"isometric",label:"Isometric"},{value:"sideScroll",label:"Side-Scroller"},{value:"fixed",label:"Fixed"}];function tr(){const{mode:e,setMode:s}=re.useGaesupStore(dn.useShallow(i=>({mode:i.mode,setMode:i.setMode}))),n=e?.control||"thirdPerson";return t.jsx("div",{className:"cc-panel",children:t.jsx("div",{className:"cc-list",children:er.map(i=>t.jsx("button",{className:`cc-button ${n===i.value?"active":""}`,onClick:()=>s({control:i.value}),children:i.label},i.value))})})}const nr=[{key:"mode",label:"Mode",enabled:!0,format:"text"},{key:"position",label:"Position",enabled:!0,format:"vector3",precision:2},{key:"distance",label:"Distance",enabled:!0,format:"vector3",precision:2},{key:"fov",label:"FOV",enabled:!0,format:"angle",precision:1},{key:"velocity",label:"Velocity",enabled:!1,format:"vector3",precision:2},{key:"rotation",label:"Rotation",enabled:!1,format:"vector3",precision:2},{key:"zoom",label:"Zoom",enabled:!1,format:"number",precision:2},{key:"activeController",label:"Controller",enabled:!0,format:"text"}];function Fn(e){if(typeof e!="object"||e===null)return!1;const s=e;return typeof s.x=="number"&&typeof s.y=="number"&&typeof s.z=="number"}function ri(){const e={frameCount:0,averageFrameTime:0,lastUpdateTime:Date.now(),mode:"unknown",activeController:"unknown",distance:null,fov:0,position:null,targetPosition:null,velocity:null,rotation:null},[s,n]=u.useState(e),i=re.useGaesupStore(p=>p.mode),o=re.useGaesupStore(p=>p.cameraOption),{activeState:r}=S.useStateSystem(),a=u.useRef(e),l=u.useCallback((p,m)=>p===m?!1:Fn(p)?Fn(m)?p.x!==m.x||p.y!==m.y||p.z!==m.z:!0:typeof p!="object"||p===null?!0:JSON.stringify(p)!==JSON.stringify(m),[]),c=u.useCallback(p=>Fn(p)?{x:p.x,y:p.y,z:p.z}:null,[]),d=u.useCallback(()=>{const p=o?.xDistance!==void 0&&o?.yDistance!==void 0&&o?.zDistance!==void 0?{x:o.xDistance,y:o.yDistance,z:o.zDistance}:null,m={...a.current,mode:i?.control??"unknown",activeController:o?.mode??i?.control??"unknown",distance:p,fov:o?.fov??0,position:c(r?.position),targetPosition:c(o?.target),velocity:c(r?.velocity),rotation:c(r?.euler),lastUpdateTime:Date.now(),...o?.zoom!==void 0?{zoom:o.zoom}:{}};Object.keys(m).some(y=>l(m[y],a.current[y]))&&(a.current=m,n(m))},[i,o,r,l,c]);u.useEffect(()=>{d();const p=setInterval(d,100);return()=>{clearInterval(p)}},[d]);const g=u.useCallback((p,m=2)=>p==null?"N/A":typeof p=="object"&&p.x!==void 0?`X:${p.x.toFixed(m)} Y:${p.y.toFixed(m)} Z:${p.z.toFixed(m)}`:typeof p=="number"?p.toFixed(m):p.toString(),[]);return t.jsx("div",{className:"cd-panel",children:t.jsx("div",{className:"cd-grid",children:nr.map(p=>t.jsxs("div",{className:"cd-item",children:[t.jsx("span",{className:"cd-label",children:p.label}),t.jsx("span",{className:"cd-value",children:g(s[p.key])})]},p.key))})})}const sr=[{id:"classic",name:"Classic",description:"A traditional third-person view.",icon:"camera",config:{mode:"thirdPerson",distance:{x:0,y:8,z:10},fov:75,smoothing:{position:.1,rotation:.1,fov:.1}}},{id:"cinematic",name:"Cinematic",description:"Smooth, movie-like camera work.",icon:"camera",config:{mode:"chase",distance:{x:2,y:7,z:8},fov:60,smoothing:{position:.05,rotation:.05,fov:.05}}},{id:"action",name:"Action",description:"Responsive camera for fast gameplay.",icon:"camera",config:{mode:"thirdPerson",distance:{x:0,y:6,z:6},fov:85,smoothing:{position:.2,rotation:.2,fov:.2}}},{id:"strategy",name:"Strategy",description:"Top-down view for an overview.",icon:"camera",config:{mode:"topDown",distance:{x:0,y:20,z:0},fov:45,smoothing:{position:.1,rotation:.1,fov:.1}}},{id:"retro",name:"Retro",description:"Classic side-scroller style.",icon:"camera",config:{mode:"sideScroll",distance:{x:15,y:0,z:0},fov:75,smoothing:{position:.15,rotation:.15,fov:.15}}}];function ir(e,s){return!e||!s?!1:e.x===s.x&&e.y===s.y&&e.z===s.z}function or(e){const s=e?.xDistance,n=e?.yDistance,i=e?.zDistance;if(!(s===void 0||n===void 0||i===void 0))return{x:s,y:n,z:i}}function ai(){const[e]=u.useState(sr),s=re.useGaesupStore(c=>c.setMode),n=re.useGaesupStore(c=>c.setCameraOption),i=re.useGaesupStore(c=>c.mode),o=re.useGaesupStore(c=>c.cameraOption),[r,a]=u.useState(null),l=u.useCallback(c=>{s({control:c.config.mode}),n({xDistance:c.config.distance.x,yDistance:c.config.distance.y,zDistance:c.config.distance.z,fov:c.config.fov,smoothing:c.config.smoothing||{position:.1,rotation:.1,fov:.1}})},[s,n,o]);return u.useEffect(()=>{const c=e.find(d=>d.config.mode===i?.control&&ir(d.config.distance,or(o)));a(c?c.id:null)},[i,o,e]),t.jsx("div",{className:"cp-panel",children:t.jsx("div",{className:"cp-grid",children:e.map(c=>t.jsxs("button",{className:`cp-item ${r===c.id?"active":""}`,onClick:()=>l(c),children:[t.jsx("div",{className:"cp-name",children:c.name}),t.jsx("div",{className:"cp-description",children:c.description})]},c.id))})})}function li(){const[e,s]=u.useState("Settings"),n=()=>{switch(e){case"Settings":return t.jsx(Qo,{});case"Controller":return t.jsx(tr,{});case"Presets":return t.jsx(ai,{});case"Debug":return t.jsx(ri,{});default:return null}};return t.jsxs("div",{className:"tabbed-panel",children:[t.jsxs("div",{className:"panel-tabs",children:[t.jsx("button",{className:`panel-tab ${e==="Settings"?"active":""}`,onClick:()=>s("Settings"),children:"Settings"}),t.jsx("button",{className:`panel-tab ${e==="Controller"?"active":""}`,onClick:()=>s("Controller"),children:"Controller"}),t.jsx("button",{className:`panel-tab ${e==="Presets"?"active":""}`,onClick:()=>s("Presets"),children:"Presets"}),t.jsx("button",{className:`panel-tab ${e==="Debug"?"active":""}`,onClick:()=>s("Debug"),children:"Debug"})]}),t.jsx("div",{className:"panel-tab-content",children:n()})]})}const rr=[{value:"idle",label:"Idle"},{value:"walk",label:"Walk"},{value:"run",label:"Run"},{value:"jump",label:"Jump"},{value:"fall",label:"Fall"},{value:"dance",label:"Dance"},{value:"wave",label:"Wave"}];function ar(){const{playAnimation:e,currentType:s,currentAnimation:n}=S.useAnimationBridge(),i=o=>{e(s,o)};return t.jsx("div",{className:"ac-panel",children:t.jsx("div",{className:"ac-grid",children:rr.map(o=>t.jsx("button",{className:`ac-button ${o.value===n?"active":""}`,onClick:()=>i(o.value),title:o.label,children:o.label},o.value))})})}const lr=[{key:"currentAnimation",label:"현재 애니메이션",format:"text",enabled:!0},{key:"animationType",label:"애니메이션 타입",format:"text",enabled:!0},{key:"isPlaying",label:"재생 상태",format:"text",enabled:!0},{key:"weight",label:"가중치",format:"number",enabled:!0},{key:"speed",label:"속도",format:"number",enabled:!0},{key:"blendDuration",label:"블렌드 시간",format:"number",enabled:!1},{key:"activeActions",label:"활성 액션",format:"number",enabled:!0},{key:"availableAnimations",label:"사용 가능 애니메이션",format:"array",enabled:!1},{key:"frameCount",label:"프레임 카운트",format:"number",enabled:!1},{key:"averageFrameTime",label:"평균 프레임 시간",format:"number",enabled:!1}];function ci(){const{bridge:e,currentType:s}=S.useAnimationBridge(),[n,i]=u.useState({frameCount:0,averageFrameTime:0,lastUpdateTime:Date.now(),currentAnimation:"idle",animationType:"character",availableAnimations:[],isPlaying:!1,weight:1,speed:1,blendDuration:.3,activeActions:0});u.useEffect(()=>{if(!e)return;const a=()=>{const c=e.snapshot(s);if(!c)return;const d=e.getMetrics(s);i(g=>({...g,currentAnimation:c.currentAnimation,animationType:s,availableAnimations:c.availableAnimations,isPlaying:c.isPlaying,weight:c.weight,speed:c.speed,activeActions:c.metrics.activeAnimations,frameCount:d?.totalActions||0,averageFrameTime:d?.mixerTime||0,lastUpdateTime:Date.now()}))};return a(),e.subscribe((c,d)=>{d===s&&a()})},[e,s]);const o=(a,l,c=2)=>{if(a==null)return"N/A";switch(l){case"array":return Array.isArray(a)?`${a.length} animations`:String(a);case"boolean":return a?"Yes":"No";case"number":return typeof a=="number"?a.toFixed(c):String(a);default:return String(a)}},r=a=>{if(a in n)return n[a]};return t.jsx("div",{className:"ad-panel",children:t.jsx("div",{className:"ad-content",children:lr.filter(a=>a.enabled).map(a=>t.jsxs("div",{className:"ad-item",children:[t.jsx("span",{className:"ad-label",children:a.label}),t.jsx("span",{className:"ad-value",children:o(r(a.key),a.format)})]},a.key))})})}const cr=()=>t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M8 5v14l11-7z"})}),ur=()=>t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"})}),dr=()=>t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M6 6h2v12H6zm3.5 6l8.5 6V6z"})}),pr=()=>t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M6 18l8.5-6L6 6v12zM16 6v12h2V6h-2z"})});function mr(){const{bridge:e,playAnimation:s,stopAnimation:n,currentType:i,currentAnimation:o}=S.useAnimationBridge(),[r,a]=u.useState(!1),[l,c]=u.useState([]),[d,g]=u.useState(30);u.useEffect(()=>{if(!e)return;const m=()=>{const y=e.snapshot(i);y&&(a(y.isPlaying),c(y.availableAnimations))};return m(),e.subscribe((y,M)=>{M===i&&m()})},[e,i]);const p=()=>{r?n(i):s(i,o)};return t.jsxs("div",{className:"ap-panel",children:[t.jsxs("div",{className:"ap-controls",children:[t.jsx("select",{className:"ap-select",value:o,onChange:m=>s(i,m.target.value),children:l.map(m=>t.jsx("option",{value:m,children:m},m))}),t.jsxs("div",{className:"ap-buttons",children:[t.jsx("button",{className:"ap-btn","aria-label":"previous animation",children:t.jsx(dr,{})}),t.jsx("button",{className:"ap-btn-primary",onClick:p,"aria-label":r?"pause":"play",children:r?t.jsx(ur,{}):t.jsx(cr,{})}),t.jsx("button",{className:"ap-btn","aria-label":"next animation",children:t.jsx(pr,{})})]})]}),t.jsxs("div",{className:"ap-timeline",children:[t.jsx("span",{className:"ap-time",children:"0:00"}),t.jsx("input",{type:"range",className:"ap-slider",min:"0",max:"100",value:d,onChange:m=>g(Number(m.target.value))}),t.jsx("span",{className:"ap-time",children:"1:30"})]})]})}function ui(){const[e,s]=u.useState("Player"),n=()=>{switch(e){case"Player":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(mr,{})});case"Controller":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(ar,{})});case"Debug":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(ci,{})});default:return null}};return t.jsxs("div",{className:"tabbed-panel",children:[t.jsxs("div",{className:"panel-tabs",children:[t.jsx("button",{className:`panel-tab ${e==="Player"?"active":""}`,onClick:()=>s("Player"),children:"Player"}),t.jsx("button",{className:`panel-tab ${e==="Controller"?"active":""}`,onClick:()=>s("Controller"),children:"Controller"}),t.jsx("button",{className:`panel-tab ${e==="Debug"?"active":""}`,onClick:()=>s("Debug"),children:"Debug"})]}),t.jsx("div",{className:"panel-tab-content",children:n()})]})}const Ls=[{id:"slow",name:"Slow",maxSpeed:5,acceleration:8},{id:"normal",name:"Normal",maxSpeed:10,acceleration:15},{id:"fast",name:"Fast",maxSpeed:20,acceleration:25},{id:"sprint",name:"Sprint",maxSpeed:35,acceleration:40}],Gs=[{id:"eco",name:"Eco",maxSpeed:15,acceleration:10},{id:"comfort",name:"Comfort",maxSpeed:25,acceleration:20},{id:"sport",name:"Sport",maxSpeed:40,acceleration:35},{id:"turbo",name:"Turbo",maxSpeed:60,acceleration:50}];function fr(e,s){const n=e??"bottom-left",i={position:"fixed",zIndex:s??1e4};return n.includes("top")&&(i.top=12),n.includes("bottom")&&(i.bottom=12),n.includes("left")&&(i.left=12),n.includes("right")&&(i.right=12),i}function di(e){const s=fr(e.position,e.zIndex),n=re.useGaesupStore(m=>m.mode),i=re.useGaesupStore(m=>m.setMode),o=re.useGaesupStore(m=>m.setPhysics),r=n?.type==="vehicle"?"vehicle":"character",a=r==="vehicle"?Gs:Ls,[l,c]=u.useState(r==="vehicle"?"comfort":"normal"),d=u.useCallback((m,f)=>{const M=(m==="vehicle"?Gs:Ls).find(_=>_.id===f);if(M){if(m==="vehicle"){o({maxSpeed:M.maxSpeed,accelRatio:M.acceleration});return}o({walkSpeed:Math.max(1,M.maxSpeed*.5),runSpeed:M.maxSpeed,accelRatio:M.acceleration})}},[o]),g=u.useCallback(m=>{c(m),d(r,m),e.onPresetChange?.(m)},[d,r,e]),p=u.useCallback(m=>{const f=m.target.value;i({type:f});const y=f==="vehicle"?"comfort":"normal";c(y),d(f,y),e.onPresetChange?.(y)},[d,i,e]);return t.jsxs("div",{className:`mc-panel ${e.compact?"compact":""}`,style:s,children:[t.jsxs("div",{className:"mc-setting-row",children:[t.jsx("label",{htmlFor:"motion-type-select",className:"mc-label",children:"Motion Type"}),t.jsxs("select",{id:"motion-type-select",className:"mc-select",value:r,onChange:p,children:[t.jsx("option",{value:"character",children:"Character"}),t.jsx("option",{value:"vehicle",children:"Vehicle"})]})]}),t.jsxs("div",{className:"mc-setting-row",children:[t.jsx("label",{className:"mc-label",children:"Presets"}),t.jsx("div",{className:"mc-presets-grid",children:a.map(m=>t.jsx("button",{className:`mc-preset-btn ${m.id===l?"active":""}`,onClick:()=>g(m.id),title:`Max Speed: ${m.maxSpeed}, Accel: ${m.acceleration}`,children:m.name},m.id))})]})]})}const zs=[{key:"motionType",label:"Motion Type",type:"text"},{key:"position",label:"Position",type:"vector3"},{key:"velocity",label:"Velocity",type:"vector3"},{key:"speed",label:"Speed",type:"number"},{key:"direction",label:"Direction",type:"vector3"},{key:"isGrounded",label:"Grounded",type:"text"},{key:"isMoving",label:"Moving",type:"text"},{key:"acceleration",label:"Acceleration",type:"number"},{key:"jumpForce",label:"Jump Force",type:"number"},{key:"maxSpeed",label:"Max Speed",type:"number"},{key:"totalDistance",label:"Total Distance",type:"number"},{key:"gameState",label:"Game State",type:"text"}];function hr(e,s){const n=e??"top-right",i={position:"fixed",zIndex:s??1e4};return n.includes("top")&&(i.top=12),n.includes("bottom")&&(i.bottom=12),n.includes("left")&&(i.left=12),n.includes("right")&&(i.right=12),i}function pi(e){const s=e.embedded?{}:hr(e.position,e.zIndex),n=re.useGaesupStore(g=>g.mode),i=re.useGaesupStore(g=>g.physics),{activeState:o,gameStates:r}=S.useStateSystem(),a=e.precision??2,l=e.customFields?[...zs,...e.customFields]:zs,c=(g,p,m=2)=>{if(p==null)return"N/A";switch(g.type){case"vector3":if(Array.isArray(p)&&p.length===3){const[f,y,M]=p;return`X:${f.toFixed(m)} Y:${y.toFixed(m)} Z:${M.toFixed(m)}`}if(typeof p=="object"&&p!==null&&"x"in p&&"y"in p&&"z"in p){const f=p;return`X:${f.x.toFixed(m)} Y:${f.y.toFixed(m)} Z:${f.z.toFixed(m)}`}return String(p);case"number":return typeof p=="number"?p.toFixed(m):String(p);default:return String(p)}},d=g=>{if(g.value!==void 0)return g.value;switch(g.key){case"motionType":return n?.type??"character";case"position":return o?.position?{x:o.position.x,y:o.position.y,z:o.position.z}:{x:0,y:0,z:0};case"velocity":return o?.velocity?{x:o.velocity.x,y:o.velocity.y,z:o.velocity.z}:{x:0,y:0,z:0};case"speed":return o?.velocity?o.velocity.length():0;case"direction":return o?.direction?{x:o.direction.x,y:o.direction.y,z:o.direction.z}:{x:0,y:0,z:0};case"isGrounded":return r?.isOnTheGround?"Yes":"No";case"isMoving":return r?.isMoving?"Yes":"No";case"acceleration":return i?.accelRatio??0;case"jumpForce":return i?.jumpSpeed??0;case"maxSpeed":return n?.type==="character"?i?.runSpeed??0:i?.maxSpeed??0;case"totalDistance":return 0;case"gameState":return r?.isRiding?"riding":r?.isOnTheGround?"ground":"air";default:return null}};return t.jsx("div",{className:`md-panel ${e.compact?"compact":""} ${e.theme?`theme-${e.theme}`:""}`,style:s,children:t.jsx("div",{className:"md-content",children:l.map(g=>t.jsxs("div",{className:"md-item",children:[t.jsx("span",{className:"md-label",children:g.label}),t.jsx("span",{className:"md-value",children:c(g,d(g),a)})]},g.key))})})}function mi(){const[e,s]=u.useState("Controller"),n=()=>{switch(e){case"Controller":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(di,{})});case"Debug":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(pi,{embedded:!0})});default:return null}};return t.jsxs("div",{className:"tabbed-panel",children:[t.jsxs("div",{className:"panel-tabs",children:[t.jsx("button",{className:`panel-tab ${e==="Controller"?"active":""}`,onClick:()=>s("Controller"),children:"Controller"}),t.jsx("button",{className:`panel-tab ${e==="Debug"?"active":""}`,onClick:()=>s("Debug"),children:"Debug"})]}),t.jsx("div",{className:"panel-tab-content",children:n()})]})}const Yt=60,Xt=({data:e,color:s,max:n,warn:i})=>{const r=e.filter(c=>isFinite(c));if(r.length<2)return null;const a=Math.max(1,n),l=r.map((c,d)=>{const g=d/(r.length-1)*100,p=40-c/a*40;return`${d===0?"M":"L"}${g.toFixed(2)},${p.toFixed(2)}`}).join(" ");return t.jsx("div",{className:"perf-chart",children:t.jsxs("svg",{width:"100%",height:40,preserveAspectRatio:"none",viewBox:"0 0 100 40",children:[i!==void 0&&t.jsx("line",{x1:"0",y1:40-i/a*40,x2:"100",y2:40-i/a*40,stroke:"#facc15",strokeWidth:"0.5",strokeDasharray:"3,3",opacity:.5}),t.jsx("path",{d:l,fill:"none",stroke:s,strokeWidth:"2",strokeLinejoin:"round",strokeLinecap:"round"})]})})},Ln=({value:e,max:s,color:n,label:i})=>{const o=s>0?Math.min(100,e/s*100):0;return t.jsxs("div",{style:{marginBottom:4},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,marginBottom:2},children:[t.jsx("span",{className:"perf-label",children:i}),t.jsx("span",{children:e.toFixed(1)})]}),t.jsx("div",{style:{height:4,background:"#1e293b",borderRadius:2,overflow:"hidden"},children:t.jsx("div",{style:{width:`${o}%`,height:"100%",background:n,borderRadius:2,transition:"width 0.3s"}})})]})};function fi(){const e=re.useGaesupStore(dn.useShallow(P=>P.performance)),[s,n]=u.useState({current:0,min:1/0,max:0,avg:0,p1Low:0,history:Array(Yt).fill(0)}),[i,o]=u.useState({used:0,limit:0,history:Array(Yt).fill(0)}),[r,a]=u.useState(0),[l,c]=u.useState(Array(Yt).fill(0)),[d,g]=u.useState(Array(Yt).fill(0)),p=u.useRef(0),m=u.useRef(0),f=u.useRef(0),y=u.useRef([]),M=u.useRef(0),_=u.useRef(null),j=u.useRef(0),A=u.useRef(0),w=u.useRef(0),x=u.useCallback(P=>{if(P.length<5)return 0;const G=[...P].filter(h=>h>0).sort((h,k)=>h-k),z=Math.max(1,Math.floor(G.length*.01));let L=0;for(let h=0;h<z;h++)L+=G[h]??0;return L/z},[]);u.useEffect(()=>{const P=window.performance.now();p.current=P,m.current=P,M.current=P;const G=z=>{const L=z-m.current;if(m.current=z,y.current.push(L),y.current.length>300&&y.current.shift(),j.current+=L,A.current++,A.current>=10){const h=j.current/A.current;a(h),g(k=>[...k.slice(1),h]),j.current=0,A.current=0}if(f.current++,z-p.current>=500){const h=f.current*1e3/(z-p.current),k=y.current.map(Z=>Z>0?1e3/Z:0),U=z-M.current>3e3;n(Z=>{const Y=[...Z.history.slice(1),h],$=U?Math.min(Z.min===1/0?h:Z.min,h):1/0,J=U?Math.max(Z.max,h):0,ee=U?Y.filter(Q=>Q>0):[],te=ee.length>0?ee.reduce((Q,se)=>Q+se,0)/ee.length:h,X=U?x(k):h;return{current:h,min:$,max:J,avg:te,p1Low:X,history:Y}});const W=window.performance.memory;W&&o(Z=>{const Y=Math.round(W.usedJSHeapSize/1048576),$=Math.round(W.jsHeapSizeLimit/1048576);return{used:Y,limit:$,history:[...Z.history.slice(1),Y]}}),p.current=z,f.current=0}_.current=requestAnimationFrame(G)};return _.current=requestAnimationFrame(G),()=>{_.current&&cancelAnimationFrame(_.current)}},[x]),u.useEffect(()=>{const P=e.render.calls;P!==w.current&&(w.current=P,c(G=>[...G.slice(1),P]))},[e.render.calls]);const T=P=>P>=55?"#4ade80":P>=30?"#facc15":"#f87171",C=P=>P<=16.7?"#4ade80":P<=33.3?"#facc15":"#f87171",B=P=>P<=100?"#4ade80":P<=300?"#facc15":"#f87171",I=(P,G)=>{const z=G>0?P/G*100:0;return z<60?"#4ade80":z<80?"#facc15":"#f87171"},F=e.render.triangles,R=e.render.calls,D=e.engine.geometries,E=e.engine.textures;return t.jsxs("div",{className:"perf-panel",children:[t.jsxs("div",{className:"perf-stat-group",children:[t.jsxs("div",{className:"perf-header",children:[t.jsx("h4",{className:"perf-title",children:"Frame Rate"}),t.jsxs("span",{className:"perf-current",style:{color:T(s.current)},children:[s.current.toFixed(0)," FPS"]})]}),t.jsxs("div",{className:"perf-details-grid",children:[t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Avg"}),s.avg.toFixed(1)]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Min"}),isFinite(s.min)?s.min.toFixed(1):"..."]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Max"}),s.max.toFixed(1)]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"1% Low"}),t.jsx("span",{style:{color:T(s.p1Low)},children:s.p1Low.toFixed(1)})]})]}),t.jsx(Xt,{data:s.history,color:T(s.current),max:90,warn:60})]}),t.jsxs("div",{className:"perf-stat-group",children:[t.jsxs("div",{className:"perf-header",children:[t.jsx("h4",{className:"perf-title",children:"Frame Time"}),t.jsxs("span",{className:"perf-current",style:{color:C(r)},children:[r.toFixed(2)," ms"]})]}),t.jsx(Ln,{value:r,max:33.3,color:C(r),label:"Budget (16.7ms)"}),t.jsx(Xt,{data:d,color:C(r),max:33.3,warn:16.7})]}),t.jsxs("div",{className:"perf-stat-group",children:[t.jsxs("div",{className:"perf-header",children:[t.jsx("h4",{className:"perf-title",children:"GPU Pipeline"}),t.jsxs("span",{className:"perf-current",style:{color:B(R)},children:[R," calls"]})]}),t.jsxs("div",{className:"perf-details-grid",children:[t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Triangles"}),F>=1e6?(F/1e6).toFixed(2)+"M":F>=1e3?(F/1e3).toFixed(1)+"K":F]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Draw Calls"}),t.jsx("span",{style:{color:B(R)},children:R})]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Tri/Call"}),R>0?Math.round(F/R):0]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Points"}),e.render.points]})]}),t.jsx(Xt,{data:l,color:B(R),max:Math.max(200,...l)})]}),t.jsxs("div",{className:"perf-stat-group",children:[t.jsx("div",{className:"perf-header",children:t.jsx("h4",{className:"perf-title",children:"Resources"})}),t.jsxs("div",{className:"perf-details-grid",children:[t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Geometries"}),D]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Textures"}),E]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Programs"}),e.engine.programs]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Lines"}),e.render.lines]})]}),t.jsx(Ln,{value:D,max:200,color:D>150?"#f87171":"#4ade80",label:"Geometry Budget"}),t.jsx(Ln,{value:E,max:100,color:E>80?"#f87171":"#4ade80",label:"Texture Budget"})]}),t.jsxs("div",{className:"perf-stat-group",children:[t.jsxs("div",{className:"perf-header",children:[t.jsx("h4",{className:"perf-title",children:"Memory"}),t.jsxs("span",{className:"perf-current",style:{color:I(i.used,i.limit)},children:[i.used," MB"]})]}),t.jsxs("div",{className:"perf-details-grid",children:[t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Limit"}),i.limit," MB"]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Usage"}),i.limit>0?(i.used/i.limit*100).toFixed(0):0,"%"]})]}),t.jsx(Xt,{data:i.history,color:I(i.used,i.limit),max:i.limit||1})]})]})}const hi=()=>{const e=re.useGaesupStore(o=>o.mode),s=re.useGaesupStore(o=>o.setMode),n=o=>{s({type:o,controller:"keyboard",control:o==="airplane"||o==="vehicle"?"chase":"thirdPerson"})},i=[{type:"character",label:"Character",description:"Walk around as character"},{type:"vehicle",label:"Vehicle",description:"Drive a ground vehicle"},{type:"airplane",label:"Airplane",description:"Fly an airplane"}];return t.jsxs("div",{className:"vehicle-panel",children:[t.jsx("div",{className:"vehicle-panel__modes",children:i.map(o=>t.jsxs("button",{className:`vehicle-panel__mode-button ${e.type===o.type?"vehicle-panel__mode-button--active":""}`,onClick:()=>n(o.type),children:[t.jsx("span",{className:"vehicle-panel__mode-label",children:o.label}),t.jsx("span",{className:"vehicle-panel__mode-description",children:o.description})]},o.type))}),t.jsxs("div",{className:"vehicle-panel__info",children:[t.jsxs("div",{className:"vehicle-panel__info-item",children:[t.jsx("span",{className:"vehicle-panel__info-label",children:"Current Mode:"}),t.jsx("span",{className:"vehicle-panel__info-value",children:e.type})]}),t.jsxs("div",{className:"vehicle-panel__info-item",children:[t.jsx("span",{className:"vehicle-panel__info-label",children:"Controls:"}),t.jsx("span",{className:"vehicle-panel__info-value",children:e.type==="airplane"?"WASD + Space/Shift":"WASD + Space"})]})]})]})},it=[{id:"door-basic",label:"Door",category:"structure",fallbackKind:"door",defaultScale:1,defaultColor:"#8b5a2b",modelUrl:"gltf/props/door.glb"},{id:"window-basic",label:"Window",category:"structure",fallbackKind:"window",defaultScale:1,defaultColor:"#9fd3ff",modelUrl:"gltf/props/window.glb"},{id:"fence-basic",label:"Fence",category:"structure",fallbackKind:"fence",defaultScale:1,defaultColor:"#8f6a3d",modelUrl:"gltf/props/fence.glb"},{id:"lamp-basic",label:"Lamp",category:"utility",fallbackKind:"lamp",defaultScale:1,defaultColor:"#ffd166",modelUrl:"gltf/props/lamp.glb"},{id:"chair-basic",label:"Chair",category:"furniture",fallbackKind:"chair",defaultScale:1,defaultColor:"#a6784f",modelUrl:"gltf/props/chair.glb"},{id:"table-basic",label:"Table",category:"furniture",fallbackKind:"table",defaultScale:1,defaultColor:"#9b6b43",modelUrl:"gltf/props/table.glb"},{id:"bed-basic",label:"Bed",category:"furniture",fallbackKind:"bed",defaultScale:1,defaultColor:"#7aa2ff",modelUrl:"gltf/props/bed.glb"},{id:"storage-basic",label:"Storage",category:"furniture",fallbackKind:"storage",defaultScale:1,defaultColor:"#7c5c3e",modelUrl:"gltf/props/storage.glb"},{id:"mailbox-basic",label:"Mailbox",category:"utility",fallbackKind:"mailbox",defaultScale:1,defaultColor:"#d04f45",modelUrl:"gltf/props/mailbox.glb"},{id:"crafting-basic",label:"Crafting Station",category:"utility",fallbackKind:"crafting",defaultScale:1,defaultColor:"#b68553",modelUrl:"gltf/props/crafting.glb"},{id:"shop-stall-basic",label:"Shop Stall",category:"shop",fallbackKind:"shop",defaultScale:1,defaultColor:"#d88f45",modelUrl:"gltf/props/shop-stall.glb"}];function Dt(e){return it.find(s=>s.id===e)}const gr=Object.entries(S.FLAG_STYLE_META),br=[{value:"#00ff88",label:"초록"},{value:"#00aaff",label:"파랑"},{value:"#f59e0b",label:"앰버"},{value:"#ffffff",label:"흰색"},{value:"#ffdd00",label:"노랑"}],xr=e=>e.kind==="material"||e.kind==="wall"||e.kind==="tile";function Gn(e){return`${e}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function Os(e,s,n){const{mapTextureUrl:i,textureUrl:o,materialParams:r,...a}=n??{};return{...a,id:e,color:s,material:"STANDARD",materialParams:{...r??{},color:s}}}const vr=()=>{const e=S.useBuildingStore(v=>v.editMode),s=S.useBuildingStore(v=>v.setEditMode),n=S.useBuildingStore(v=>v.selectedWallId),i=S.useBuildingStore(v=>v.selectedTileId),o=S.useBuildingStore(v=>v.selectedBlockId),r=S.useBuildingStore(v=>v.selectedWallGroupId),a=S.useBuildingStore(v=>v.currentTileMultiplier),l=S.useBuildingStore(v=>v.setTileMultiplier),c=S.useBuildingStore(v=>v.currentTileHeight),d=S.useBuildingStore(v=>v.setTileHeight),g=S.useBuildingStore(v=>v.currentTileShape),p=S.useBuildingStore(v=>v.setTileShape),m=S.useBuildingStore(v=>v.currentTileRotation),f=S.useBuildingStore(v=>v.setTileRotation),y=S.useBuildingStore(v=>v.currentTileMaterialId),M=S.useBuildingStore(v=>v.setCurrentTileMaterialId),_=S.useBuildingStore(v=>v.currentWallRotation),j=S.useBuildingStore(v=>v.setWallRotation),A=S.useBuildingStore(v=>v.selectedTileObjectType),w=S.useBuildingStore(v=>v.setSelectedTileObjectType),x=S.useBuildingStore(v=>v.currentTerrainColor),T=S.useBuildingStore(v=>v.currentTerrainAccentColor),C=S.useBuildingStore(v=>v.setTerrainColors),B=S.useBuildingStore(v=>v.selectedPlacedObjectType),I=S.useBuildingStore(v=>v.setSelectedPlacedObjectType),F=S.useBuildingStore(v=>v.selectedModelObjectId),R=S.useBuildingStore(v=>v.setSelectedModelObjectId),D=S.useBuildingStore(v=>v.currentModelUrl),E=S.useBuildingStore(v=>v.setModelUrl),P=S.useBuildingStore(v=>v.currentModelScale),G=S.useBuildingStore(v=>v.setModelScale),z=S.useBuildingStore(v=>v.currentModelColor),L=S.useBuildingStore(v=>v.setModelColor),h=S.useBuildingStore(v=>v.snapToGrid),k=S.useBuildingStore(v=>v.setSnapToGrid),U=S.useBuildingStore(v=>v.currentFlagWidth),W=S.useBuildingStore(v=>v.currentFlagHeight),Z=S.useBuildingStore(v=>v.currentFlagImageUrl),Y=S.useBuildingStore(v=>v.setFlagWidth),$=S.useBuildingStore(v=>v.setFlagHeight),J=S.useBuildingStore(v=>v.setFlagImageUrl),ee=S.useBuildingStore(v=>v.currentFlagStyle),te=S.useBuildingStore(v=>v.setFlagStyle),X=S.useBuildingStore(v=>v.currentFireIntensity),Q=S.useBuildingStore(v=>v.currentFireWidth),se=S.useBuildingStore(v=>v.currentFireHeight),q=S.useBuildingStore(v=>v.currentFireColor),ie=S.useBuildingStore(v=>v.setFireIntensity),ue=S.useBuildingStore(v=>v.setFireWidth),O=S.useBuildingStore(v=>v.setFireHeight),me=S.useBuildingStore(v=>v.setFireColor),fe=S.useBuildingStore(v=>v.currentObjectRotation),xe=S.useBuildingStore(v=>v.setObjectRotation),Me=S.useBuildingStore(v=>v.selectedTileGroupId),Ie=S.useBuildingStore(v=>v.tileGroups),le=S.useBuildingStore(v=>v.wallGroups),Qe=S.useBuildingStore(v=>v.blocks),Ae=S.useBuildingStore(v=>v.meshes),bt=S.useBuildingStore(v=>v.addMesh),Oe=S.useBuildingStore(v=>v.updateMesh),at=S.useBuildingStore(v=>v.updateWall),Ce=S.useBuildingStore(v=>v.updateTile),He=S.useBuildingStore(v=>v.setCurrentWallMaterialId),Te=S.useBuildingStore(v=>v.removeWall),lt=S.useBuildingStore(v=>v.removeTile),In=S.useBuildingStore(v=>v.removeBlock),An=S.useBuildingStore(v=>v.currentBillboardText),Bn=S.useBuildingStore(v=>v.currentBillboardImageUrl),En=S.useBuildingStore(v=>v.currentBillboardColor),kn=S.useBuildingStore(v=>v.setBillboardText),Wt=S.useBuildingStore(v=>v.setBillboardImageUrl),xt=S.useBuildingStore(v=>v.setBillboardColor),et=S.useBuildingStore(v=>v.currentObjectPrimaryColor),Ht=S.useBuildingStore(v=>v.currentObjectSecondaryColor),Rn=S.useBuildingStore(v=>v.setObjectPrimaryColor),$t=S.useBuildingStore(v=>v.setObjectSecondaryColor),N=S.useBuildingStore(v=>v.showSnow),H=S.useBuildingStore(v=>v.setShowSnow),de=Ye.useAssetStore(v=>v.ids),ve=Ye.useAssetStore(v=>v.records),vt=u.useMemo(()=>de.map(v=>ve[v]).filter(v=>!!v).filter(xr),[de,ve]),Zt=[{type:"none",label:"없음",description:"건축 편집을 끕니다"},{type:"wall",label:"벽",description:"벽 조각을 배치합니다"},{type:"tile",label:"타일",description:"바닥 타일을 배치합니다"},{type:"block",label:"박스",description:"복셀 박스를 쌓습니다"},{type:"object",label:"오브젝트",description:"타일 위에 장식을 배치합니다"},{type:"npc",label:"NPC",description:"NPC를 배치합니다"}],yt=[{type:"none",label:"없음"},{type:"grass",label:"잔디"},{type:"sand",label:"모래"},{type:"snowfield",label:"눈밭"}],ks=[{type:"none",label:"없음"},{type:"sakura",label:"벚꽃나무"},{type:"flag",label:"깃발"},{type:"fire",label:"불"},{type:"billboard",label:"간판"},{type:"model",label:"기본 기물"}],Rs=[{type:"box",label:"박스"},{type:"stairs",label:"계단"},{type:"round",label:"원형"},{type:"ramp",label:"경사"}],Ps=[{value:0,label:"0도"},{value:Math.PI/2,label:"90도"},{value:Math.PI,label:"180도"},{value:Math.PI*1.5,label:"270도"}],Re=n?Array.from(le.values()).find(v=>v.walls.some(pe=>pe.id===n)):le.get(r??""),be=i?Array.from(Ie.values()).find(v=>v.tiles.some(pe=>pe.id===i)):Ie.get(Me??""),Pn=i?be?.tiles.find(v=>v.id===i):void 0,Ds=o?Qe.find(v=>v.id===o):void 0,Lo=Zt.find(v=>v.type===e)?.label??e,Go=yt.find(v=>v.type===A)?.label??A,zo=ks.find(v=>v.type===B)?.label??B,Oo=Rs.find(v=>v.type===g)?.label??g,St=Dt(F)??it[0],Uo=()=>{!n||!Re||Te(Re.id,n)},Wo=()=>{!i||!be||lt(be.id,i)},Ho=()=>{o&&In(o)},Vt=(v,pe,he,Pe)=>{const De=pt.createScopedBuildingMeshId(pe,he,Pe.id),ct=v?Ae.get(v):void 0,Mt=pt.createScopedAssetMeshConfig(De,Pe,ct);return Ae.has(De)?Oe(De,Mt):bt(Mt),De},$o=v=>{if(!Re)return;const he=(n?Re.walls.find(De=>De.id===n):void 0)?.materialId??Re.frontMeshId;if(n){const De=Vt(he,n,"wall",v);at(Re.id,n,{materialId:De});return}const Pe=Vt(Re.frontMeshId,Gn("placement-wall"),"wall",v);He(Pe)},Zo=v=>{if(!be)return;if(i){const he=Vt(Pn?.materialId??be.floorMeshId,i,"tile",v);Ce(be.id,i,{materialId:he});return}const pe=Vt(be.floorMeshId,Gn("placement-tile"),"tile",v);M(pe)},Vo=v=>{if(!be)return;if(i){const De=Pn?.materialId??be.floorMeshId,ct=pt.createScopedBuildingMeshId(i,"tile-color",v),Mt=Os(ct,v,Ae.get(De));Ae.has(ct)?Oe(ct,Mt):bt(Mt),Ce(be.id,i,{materialId:ct});return}const pe=y??be.floorMeshId,he=pt.createScopedBuildingMeshId(Gn("placement-tile-color"),"tile",v),Pe=Os(he,v,Ae.get(pe));bt(Pe),M(he)},Fs=(v,pe=T)=>{if(C(v,pe),!i||!be)return;const he=be.tiles.find(Pe=>Pe.id===i);!he||!he.objectType||he.objectType==="none"||he.objectType==="water"||Ce(be.id,i,{objectConfig:{...he.objectConfig??{},terrainColor:v,terrainAccentColor:pe}})};return t.jsxs("div",{className:"building-panel",children:[t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"편집 모드"}),t.jsx("div",{className:"building-panel__modes",children:Zt.map(v=>t.jsxs("button",{className:`building-panel__mode-btn ${e===v.type?"building-panel__mode-btn--active":""}`,onClick:()=>s(v.type),children:[t.jsx("span",{className:"building-panel__mode-label",children:v.label}),t.jsx("span",{className:"building-panel__mode-desc",children:v.description})]},v.type))})]}),(e==="wall"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"벽 회전 / 삭제"}),t.jsx("div",{className:"building-panel__segmented",children:Ps.map(v=>t.jsx("button",{className:`building-panel__segment-btn ${Math.abs(_-v.value)<1e-4?"building-panel__segment-btn--active":""}`,onClick:()=>j(v.value),children:v.label},v.value))}),t.jsxs("div",{className:"building-panel__delete-card",children:[t.jsxs("div",{children:[t.jsx("strong",{children:"선택한 벽"}),t.jsx("span",{children:n?`ID: ${n}`:"벽 마커를 클릭해 선택하세요"})]}),t.jsx("button",{className:"building-panel__delete-button",disabled:!n||!Re,onClick:Uo,children:"선택 벽 삭제"})]})]}),(e==="wall"||e==="tile"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"에셋 재질"}),t.jsxs("div",{className:"building-panel__asset-targets",children:[t.jsxs("span",{children:["벽: ",Re?.name??"선택 없음"]}),t.jsxs("span",{children:["타일: ",i?`선택 타일 ${i}`:"다음 생성 타일"]}),t.jsxs("span",{children:["현재 생성 재질: ",y??be?.floorMeshId??"기본값"]})]}),t.jsxs("div",{className:"building-panel__asset-list",children:[vt.map(v=>t.jsxs("div",{className:"building-panel__asset-card",children:[t.jsx(pt.AssetPreviewCanvas,{asset:v,size:54}),t.jsxs("div",{className:"building-panel__asset-info",children:[t.jsx("strong",{children:v.name}),t.jsx("span",{children:v.kind})]}),t.jsxs("div",{className:"building-panel__asset-actions",children:[t.jsx("button",{className:"building-panel__asset-action",disabled:!Re,onClick:()=>$o(v),children:"벽"}),t.jsx("button",{className:"building-panel__asset-action",disabled:!be,onClick:()=>Zo(v),children:"타일"})]})]},v.id)),vt.length===0&&t.jsx("div",{className:"building-panel__empty",children:"사용 가능한 빌딩 에셋이 없습니다."})]})]}),(e==="tile"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"지형 덮개"}),t.jsx("div",{className:"building-panel__grid",children:yt.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${A===v.type?"building-panel__grid-btn--active":""}`,onClick:()=>w(v.type),children:v.label},v.type))}),t.jsxs("div",{className:"building-panel__terrain-colors",children:[t.jsxs("label",{children:[t.jsx("span",{children:"기본색"}),t.jsx("input",{type:"color",value:x,onChange:v=>Fs(v.target.value)})]}),t.jsxs("label",{children:[t.jsx("span",{children:"강조색"}),t.jsx("input",{type:"color",value:T,onChange:v=>Fs(x,v.target.value)})]})]})]}),(e==="object"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"배치 오브젝트"}),t.jsx("div",{className:"building-panel__grid",children:ks.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${B===v.type?"building-panel__grid-btn--active":""}`,onClick:()=>{I(v.type),v.type==="model"&&St&&(G(St.defaultScale),L(St.defaultColor),E(St.modelUrl??""))},children:v.label},v.type))})]}),e==="object"&&B==="model"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"기본 기물 GLB"}),t.jsx("div",{className:"building-panel__grid",children:it.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${F===v.id?"building-panel__grid-btn--active":""}`,onClick:()=>{R(v.id),G(v.defaultScale),L(v.defaultColor),E(v.modelUrl??"")},children:v.label},v.id))}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("label",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"GLB URL"}),t.jsx("input",{type:"text",value:D,onChange:v=>E(v.target.value),placeholder:"gltf/props/door.glb",className:"building-panel__text-input"})]}),t.jsxs("label",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"스케일"}),t.jsx("input",{type:"number",min:"0.1",max:"10",step:"0.1",value:P,onChange:v=>G(Number(v.target.value)||1),className:"building-panel__number-input"})]}),t.jsxs("label",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"색상"}),t.jsx("input",{type:"color",value:z,onChange:v=>L(v.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:z})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"Fallback"}),t.jsx("span",{className:"building-panel__info-value",children:St?.fallbackKind??"generic"})]})]})]}),t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"타일 설정"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"크기"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>l(Math.max(1,a-1)),children:"-"}),t.jsx("span",{className:"building-panel__stepper-value",children:a}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>l(Math.min(4,a+1)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"격자 맞춤"}),t.jsx("button",{className:`building-panel__toggle ${h?"building-panel__toggle--on":""}`,onClick:()=>k(!h),children:h?"ON":"OFF"})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"높이"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>d(Math.max(0,c-1)),children:"-"}),t.jsx("span",{className:"building-panel__stepper-value",children:c}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>d(Math.min(6,c+1)),children:"+"})]})]})]}),t.jsx("div",{className:"building-panel__section-subtitle",children:"타일 형태"}),t.jsx("div",{className:"building-panel__grid",children:Rs.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${g===v.type?"building-panel__grid-btn--active":""}`,onClick:()=>p(v.type),children:v.label},v.type))}),t.jsx("div",{className:"building-panel__section-subtitle",children:"타일 회전"}),t.jsx("div",{className:"building-panel__segmented",children:Ps.map(v=>t.jsx("button",{className:`building-panel__segment-btn ${Math.abs(m-v.value)<1e-4?"building-panel__segment-btn--active":""}`,onClick:()=>f(v.value),children:v.label},v.value))}),t.jsxs("div",{className:"building-panel__delete-card",children:[t.jsxs("div",{children:[t.jsx("strong",{children:"선택한 타일"}),t.jsx("span",{children:i?`ID: ${i}`:"타일 하이라이트를 클릭해 선택하세요"})]}),t.jsx("button",{className:"building-panel__delete-button",disabled:!i||!be,onClick:Wo,children:"선택 타일 삭제"})]})]}),(e==="block"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"박스 편집"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"박스 크기"}),t.jsxs("span",{className:"building-panel__info-value",children:[a," x ",a]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"쌓기 높이"}),t.jsx("span",{className:"building-panel__info-value",children:c})]})]}),t.jsxs("div",{className:"building-panel__delete-card",children:[t.jsxs("div",{children:[t.jsx("strong",{children:"선택한 박스"}),t.jsx("span",{children:Ds?`ID: ${Ds.id}`:"박스 하이라이트를 클릭해 선택하세요"})]}),t.jsx("button",{className:"building-panel__delete-button",disabled:!o,onClick:Ho,children:"선택 박스 삭제"})]})]}),e==="tile"&&Me&&(()=>{const v=Ie.get(Me),pe=Pn?.materialId??y??v?.floorMeshId,he=pe?Ae.get(pe):void 0;return he?t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"타일 색상"}),t.jsx("div",{className:"building-panel__info",children:t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"색상"}),t.jsx("input",{type:"color",value:he.color||"#888888",onChange:Pe=>Vo(Pe.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:he.color||"#888888"})]})})]}):null})(),t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"효과"}),t.jsx("div",{className:"building-panel__info",children:t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"눈"}),t.jsx("button",{className:`building-panel__toggle ${N?"building-panel__toggle--on":""}`,onClick:()=>H(!N),children:N?"ON":"OFF"})]})})]}),e==="object"&&B!=="none"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"오브젝트 회전"}),t.jsx("div",{className:"building-panel__grid",children:[0,Math.PI/4,Math.PI/2,Math.PI*.75,Math.PI,Math.PI*1.25,Math.PI*1.5,Math.PI*1.75].map((v,pe)=>t.jsx("button",{className:`building-panel__grid-btn ${Math.abs(fe-v)<.01?"building-panel__grid-btn--active":""}`,onClick:()=>xe(v),children:pe*45},v))})]}),e==="object"&&B==="sakura"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"벚꽃나무 색상"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"꽃잎"}),t.jsx("input",{type:"color",value:et,onChange:v=>Rn(v.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:et})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"나무껍질"}),t.jsx("input",{type:"color",value:Ht,onChange:v=>$t(v.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:Ht})]})]})]}),B==="fire"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"불 설정"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"강도"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>ie(Math.max(.5,X-.5)),children:"-"}),t.jsx("span",{className:"building-panel__stepper-value",children:X.toFixed(1)}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>ie(Math.min(3,X+.5)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"너비"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>ue(Math.max(.3,Q-.2)),children:"-"}),t.jsxs("span",{className:"building-panel__stepper-value",children:[Q.toFixed(1),"m"]}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>ue(Math.min(4,Q+.2)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"높이"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>O(Math.max(.5,se-.3)),children:"-"}),t.jsxs("span",{className:"building-panel__stepper-value",children:[se.toFixed(1),"m"]}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>O(Math.min(5,se+.3)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"색상"}),t.jsx("input",{type:"color",value:q,onChange:v=>me(v.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:q})]})]})]}),B==="billboard"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"간판 설정"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"문구"}),t.jsx("input",{type:"text",value:An,onChange:v=>kn(v.target.value),placeholder:"표시할 문구...",style:{width:"100%",padding:"4px 6px",fontSize:"11px",background:"var(--panel-bg, #1a1a2e)",border:"1px solid var(--border-color, #333)",borderRadius:"3px",color:"inherit",boxSizing:"border-box"}})]}),t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"이미지 URL"}),t.jsx("input",{type:"text",value:Bn,onChange:v=>Wt(v.target.value),placeholder:"https://...",style:{width:"100%",padding:"4px 6px",fontSize:"11px",background:"var(--panel-bg, #1a1a2e)",border:"1px solid var(--border-color, #333)",borderRadius:"3px",color:"inherit",boxSizing:"border-box"}})]}),t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"색상"}),t.jsx("div",{className:"building-panel__grid",children:br.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${En===v.value?"building-panel__grid-btn--active":""}`,onClick:()=>xt(v.value),style:{borderBottom:`3px solid ${v.value}`},children:v.label},v.value))})]})]})]}),B==="flag"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"깃발 설정"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"스타일"}),t.jsx("div",{className:"building-panel__grid",children:gr.map(([v,pe])=>t.jsx("button",{className:`building-panel__grid-btn ${ee===v?"building-panel__grid-btn--active":""}`,onClick:()=>te(v),children:pe.label},v))})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"너비"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>Y(Math.max(.5,U-.5)),children:"-"}),t.jsxs("span",{className:"building-panel__stepper-value",children:[U,"m"]}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>Y(Math.min(8,U+.5)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"높이"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>$(Math.max(.5,W-.5)),children:"-"}),t.jsxs("span",{className:"building-panel__stepper-value",children:[W,"m"]}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>$(Math.min(6,W+.5)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"이미지 URL"}),t.jsx("input",{type:"text",value:Z,onChange:v=>J(v.target.value),placeholder:"https://...",style:{width:"100%",padding:"4px 6px",fontSize:"11px",background:"var(--panel-bg, #1a1a2e)",border:"1px solid var(--border-color, #333)",borderRadius:"3px",color:"inherit",boxSizing:"border-box"}})]})]})]}),t.jsxs("div",{className:"building-panel__info",style:{marginTop:"auto"},children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"현재 모드"}),t.jsx("span",{className:"building-panel__info-value",children:Lo})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"지형 덮개"}),t.jsx("span",{className:"building-panel__info-value",children:Go})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"오브젝트"}),t.jsx("span",{className:"building-panel__info-value",children:zo})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"타일 높이"}),t.jsx("span",{className:"building-panel__info-value",children:c})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"타일 형태"}),t.jsx("span",{className:"building-panel__info-value",children:Oo})]})]})]})},ut={name:"플레이어",colors:{body:"#ffd9b8",hair:"#3a2a1a",hat:"#5a8acf",top:"#f0e0c8",bottom:"#3a4a6a",shoes:"#3a2a1a"},face:"default",hair:"short"},gi={hat:"모자",top:"상의",bottom:"하의",shoes:"신발",face:"표정",weapon:"무기",accessory:"액세서리"},yr={short:"단발",long:"긴머리",cap:"모자머리",bun:"쪽머리",spiky:"뻗친머리"},Sr={default:"기본",smile:"미소",wink:"윙크",sleepy:"졸림",surprised:"놀람"},zn={hat:null,top:null,bottom:null,shoes:null,face:null,weapon:null,accessory:null},an=rt.create((e,s)=>({appearance:{...ut,colors:{...ut.colors}},outfits:{...zn},setName:n=>e(i=>({appearance:{...i.appearance,name:n.slice(0,16)||"플레이어"}})),setColor:(n,i)=>e(o=>({appearance:{...o.appearance,colors:{...o.appearance.colors,[n]:i}}})),setFace:n=>e(i=>({appearance:{...i.appearance,face:n}})),setHair:n=>e(i=>({appearance:{...i.appearance,hair:n}})),equipOutfit:(n,i)=>e(o=>({outfits:{...o.outfits,[n]:i}})),resetAppearance:()=>e({appearance:{...ut,colors:{...ut.colors}},outfits:{...zn}}),getEquippedAssetIds:()=>Object.values(s().outfits).filter(n=>typeof n=="string"&&n.length>0),serialize:()=>{const n=s();return{version:2,appearance:{...n.appearance,colors:{...n.appearance.colors}},outfits:{...n.outfits}}},hydrate:n=>{!n||n.version!==1&&n.version!==2||e({appearance:{...ut,...n.appearance,colors:{...ut.colors,...n.appearance.colors}},outfits:{...zn,...n.outfits}})}})),Mr=["hat","top","bottom","shoes","face","weapon","accessory"],jr=(e,s)=>s==="weapon"?e.kind==="weapon"||e.slot==="weapon":e.slot===s&&(e.kind==="characterPart"||e.kind==="weapon"),wr=()=>{const e=an(y=>y.outfits),s=an(y=>y.equipOutfit),n=an(y=>y.resetAppearance),i=Ye.useAssetStore(y=>y.ids),o=Ye.useAssetStore(y=>y.records),r=Ye.useAssetStore(y=>y.isLoading),a=Ye.useAssetStore(y=>y.error),[l,c]=u.useState("top"),[d,g]=u.useState(""),[p,m]=u.useState(!1),f=u.useMemo(()=>{const y=d.trim().toLowerCase();return i.map(M=>o[M]).filter(M=>!!M).filter(M=>jr(M,l)).filter(M=>y?M.tags?.some(_=>_.toLowerCase().includes(y))??!1:!0).filter(M=>!p||M.metadata?.owned!==!1)},[i,o,p,l,d]);return t.jsxs("div",{className:"character-asset-panel",children:[t.jsxs("section",{className:"character-asset-panel__section",children:[t.jsxs("div",{className:"character-asset-panel__header",children:[t.jsx("span",{className:"character-asset-panel__section-title",children:"캐릭터 에셋"}),t.jsx("button",{className:"character-asset-panel__ghost-btn",onClick:n,type:"button",children:"초기화"})]}),t.jsx("div",{className:"character-asset-panel__slot-grid",children:Mr.map(y=>t.jsxs("button",{type:"button",className:`character-asset-panel__slot-btn ${l===y?"character-asset-panel__slot-btn--active":""}`,onClick:()=>c(y),children:[t.jsx("span",{children:gi[y]}),t.jsx("small",{children:e[y]??"비어있음"})]},y))})]}),t.jsxs("section",{className:"character-asset-panel__section",children:[t.jsxs("div",{className:"character-asset-panel__filters",children:[t.jsx("input",{value:d,onChange:y=>g(y.target.value),placeholder:"태그 검색",className:"character-asset-panel__input"}),t.jsxs("label",{className:"character-asset-panel__check",children:[t.jsx("input",{type:"checkbox",checked:p,onChange:y=>m(y.target.checked)}),"보유만"]})]}),a&&t.jsx("p",{className:"character-asset-panel__notice",children:a}),r&&t.jsx("p",{className:"character-asset-panel__notice",children:"에셋 로딩 중"}),t.jsxs("div",{className:"character-asset-panel__asset-list",children:[t.jsxs("button",{type:"button",className:`character-asset-panel__asset-card ${e[l]===null?"character-asset-panel__asset-card--active":""}`,onClick:()=>s(l,null),children:[t.jsx("div",{className:"character-asset-panel__empty-preview"}),t.jsx("span",{children:"비우기"})]}),f.map(y=>t.jsxs("button",{type:"button",className:`character-asset-panel__asset-card ${e[l]===y.id?"character-asset-panel__asset-card--active":""}`,onClick:()=>s(l,y.id),children:[t.jsx(pt.AssetPreviewCanvas,{asset:y,size:58}),t.jsx("span",{children:y.name})]},y.id)),f.length===0&&t.jsx("p",{className:"character-asset-panel__notice",children:"선택한 슬롯에 사용할 에셋이 없습니다."})]})]})]})},_r=e=>{const s=e.trigger;switch(s.type){case"manual":return{type:"manual",key:s.key};case"interaction":return{type:"interaction",targetId:s.targetId,...s.action?{action:s.action}:{}};case"enterArea":return{type:"enterArea",areaId:s.areaId};case"itemCollected":return{type:"itemCollected",itemId:s.itemId};case"timeChanged":return{type:"timeChanged",...s.hour!==void 0?{hour:s.hour}:{}};case"calendarEventStarted":return{type:"calendarEventStarted",eventId:s.eventId};case"questChanged":return{type:"questChanged",questId:s.questId,...s.status?{status:s.status}:{}};case"custom":return{type:"custom",key:s.key};default:return s}},Cr=({data:e,id:s})=>{const[n,i]=u.useState(null),[o,r]=u.useState(""),a=l=>{e.onEdit?.(s,l,ln(o)),i(null)};return t.jsxs("div",{className:"gameplay-event-node",children:[t.jsx(Be.Handle,{type:"target",position:Be.Position.Top,className:"gameplay-event-node__handle"}),t.jsxs("div",{className:"gameplay-event-node__header",children:[t.jsx("span",{children:e.title}),s!=="root"&&s!=="trigger"&&s!=="policy"&&t.jsx("button",{type:"button",className:"gameplay-event-node__delete",onClick:()=>e.onDelete?.(s),children:"Delete"})]}),e.fields&&Object.entries(e.fields).map(([l,c])=>t.jsx("div",{className:"gameplay-event-node__field",children:n===l?t.jsxs("div",{className:"gameplay-event-node__edit",children:[t.jsx("input",{value:o,onChange:d=>r(d.target.value),onKeyDown:d=>{d.key==="Enter"&&a(l),d.key==="Escape"&&i(null)},autoFocus:!0}),t.jsx("button",{type:"button",onClick:()=>a(l),children:"Save"}),t.jsx("button",{type:"button",onClick:()=>i(null),children:"Cancel"})]}):t.jsxs("button",{type:"button",className:"gameplay-event-node__value",onClick:()=>{l!=="type"&&(i(l),r(String(c)))},children:[t.jsx("span",{children:l}),t.jsx("strong",{children:String(c)})]})},l)),t.jsx(Be.Handle,{type:"source",position:Be.Position.Bottom,className:"gameplay-event-node__handle"})]})},Tr=e=>{switch(e){case"manual":return{type:e,key:"custom.run"};case"interaction":return{type:e,targetId:"npc:tommy",action:"talk"};case"enterArea":return{type:e,areaId:"meadow"};case"itemCollected":return{type:e,itemId:"apple"};case"timeChanged":return{type:e,hour:9};case"calendarEventStarted":return{type:e,eventId:"event.cherryblossom"};case"questChanged":return{type:e,questId:"welcome",status:"active"};case"custom":return{type:e,key:"custom.event"};default:return e}},Nr=e=>{switch(e){case"always":return{type:e};case"hasItem":return{type:e,itemId:"apple",count:1};case"questStatus":return{type:e,questId:"welcome",status:"active"};case"eventActive":return{type:e,eventId:"event.cherryblossom"};case"flagEquals":return{type:e,key:"gameplayReady",value:!0};case"custom":return{type:e,key:"custom.condition"};default:return e}},Ir=e=>{switch(e){case"giveItem":return{type:e,itemId:"apple",count:1};case"removeItem":return{type:e,itemId:"apple",count:1};case"startQuest":return{type:e,questId:"welcome"};case"completeQuest":return{type:e,questId:"welcome"};case"showDialog":return{type:e,dialogTreeId:"npc.villager",npcId:"mei"};case"toast":return{type:e,kind:"success",text:"이벤트 실행"};case"setFlag":return{type:e,key:"customFlag",value:!0};case"notifyQuestFlag":return{type:e,key:"customFlag",value:!0};case"emit":return{type:e,eventName:"gameplay.custom"};case"custom":return{type:e,key:"custom.action"};default:return e}},ln=e=>{if(e==="true")return!0;if(e==="false")return!1;const s=Number(e);return Number.isFinite(s)&&e.trim()!==""?s:e},Ar=e=>Array.isArray(e)||typeof e=="object"&&e!==null?JSON.stringify(e):e,qt={stroke:"#7a86a8",strokeWidth:2},Kt={type:Be.MarkerType.ArrowClosed,color:"#7a86a8",width:20,height:20},Br={editable:Cr},Er=(e,s,n)=>{const i=[{id:"root",type:"editable",position:{x:260,y:20},data:{title:e.name,fields:{id:e.id,name:e.name,description:e.description??""},onEdit:s,onDelete:n}},{id:"trigger",type:"editable",position:{x:260,y:180},data:{title:`Trigger: ${e.trigger.type}`,fields:{...e.trigger},onEdit:s,onDelete:n}},{id:"policy",type:"editable",position:{x:560,y:180},data:{title:"Policy",fields:{run:e.policy?.run??"repeat",cooldownMs:e.policy?.cooldownMs??0,requiresServer:e.policy?.requiresServer??!1},onEdit:s,onDelete:n}}],o=[{id:"root-trigger",source:"root",target:"trigger",style:qt,markerEnd:Kt},{id:"root-policy",source:"root",target:"policy",style:qt,markerEnd:Kt}];return(e.conditions??[]).forEach((r,a)=>{const l=`condition:${a}`;i.push({id:l,type:"editable",position:{x:40,y:360+a*150},data:{title:`Condition: ${r.type}`,fields:{...r},onEdit:s,onDelete:n}}),o.push({id:`trigger-${l}`,source:"trigger",target:l,style:qt,markerEnd:Kt})}),e.actions.forEach((r,a)=>{const l=`action:${a}`;i.push({id:l,type:"editable",position:{x:420,y:360+a*150},data:{title:`Action: ${r.type}`,fields:{...r},onEdit:s,onDelete:n}}),o.push({id:`${a===0?"trigger":`action:${a-1}`}-${l}`,source:a===0?"trigger":`action:${a-1}`,target:l,style:qt,markerEnd:Kt})}),{nodes:i,edges:o}};function kr({blueprints:e,onCreate:s,onUpdate:n,onDelete:i,onRun:o}){const r=u.useMemo(()=>new At.GameplayEventEngine({blueprints:e}),[e]),[a,l]=u.useState("custom-toast"),[c,d]=u.useState("Custom Toast Event"),[g,p]=u.useState("custom.run"),[m,f]=u.useState("커스텀 이벤트 실행"),[y,M]=u.useState(e[0]?.id??null),_=u.useMemo(()=>e.find(h=>h.id===y)??e[0]??null,[e,y]),[j,A]=u.useState({kind:"idle",message:"Ready"}),[w,x,T]=Be.useNodesState([]),[C,B,I]=Be.useEdgesState([]),F=()=>{const h={id:a.trim()||`event-${Date.now()}`,name:c.trim()||"Untitled Event",trigger:{type:"manual",key:g.trim()||"custom.run"},conditions:[{type:"always"}],actions:[{type:"toast",kind:"success",text:m.trim()||"이벤트 실행"},{type:"setFlag",key:a.trim()||"customEvent",value:!0}],policy:{run:"repeat"},tags:["editor"]};s?.(h),M(h.id),A({kind:"success",message:`Created ${h.id}`})},R=u.useCallback(h=>{if(!_)return;const k={..._,...h};n?.(k),M(k.id),A({kind:"success",message:`Updated ${k.id}`})},[n,_]),D=()=>{if(!_)return;i?.(_.id);const h=e.find(k=>k.id!==_.id)??null;M(h?.id??null),A({kind:"success",message:`Deleted ${_.id}`})},E=async h=>{const k=_r(h);o?await o(k):await r.dispatch(k),A({kind:"success",message:`Ran ${h.id}`})},P=u.useCallback((h,k)=>{if(!_)return;const U=[..._.conditions??[]];U[h]=k,R({conditions:U})},[_,R]),G=u.useCallback((h,k)=>{if(!_)return;const U=[..._.actions];U[h]=k,R({actions:U})},[_,R]),z=u.useCallback((h,k,U)=>{if(!_||k==="type")return;const W=Ar(U);if(h==="root"){R({[k]:W});return}if(h==="policy"){k==="run"&&(W==="once"||W==="repeat")&&R({policy:{..._.policy,run:W}}),k==="cooldownMs"&&R({policy:{..._.policy,cooldownMs:Number(W)}}),k==="requiresServer"&&R({policy:{..._.policy,requiresServer:ln(String(W))===!0}});return}if(h==="trigger"){const Z=_.trigger;Z.type==="manual"&&k==="key"&&R({trigger:{type:"manual",key:String(W)}}),Z.type==="interaction"&&(k==="targetId"||k==="action")&&R({trigger:{...Z,[k]:String(W)}}),Z.type==="enterArea"&&k==="areaId"&&R({trigger:{type:"enterArea",areaId:String(W)}}),Z.type==="itemCollected"&&k==="itemId"&&R({trigger:{type:"itemCollected",itemId:String(W)}}),Z.type==="timeChanged"&&k==="hour"&&R({trigger:{type:"timeChanged",hour:Number(W)}}),Z.type==="calendarEventStarted"&&k==="eventId"&&R({trigger:{type:"calendarEventStarted",eventId:String(W)}}),Z.type==="questChanged"&&(k==="questId"||k==="status")&&R({trigger:{...Z,[k]:String(W)}}),Z.type==="custom"&&k==="key"&&R({trigger:{type:"custom",key:String(W)}});return}if(h.startsWith("condition:")){const Z=Number(h.split(":")[1]),Y=_.conditions?.[Z];if(!Y)return;P(Z,{...Y,[k]:k==="value"?ln(String(W)):W});return}if(h.startsWith("action:")){const Z=Number(h.split(":")[1]),Y=_.actions[Z];if(!Y)return;G(Z,{...Y,[k]:k==="value"?ln(String(W)):W})}},[_,G,P,R]),L=u.useCallback(h=>{if(_){if(h.startsWith("condition:")){const k=Number(h.split(":")[1]);R({conditions:(_.conditions??[]).filter((U,W)=>W!==k)});return}if(h.startsWith("action:")){const k=Number(h.split(":")[1]);R({actions:_.actions.filter((U,W)=>W!==k)})}}},[_,R]);return u.useEffect(()=>{if(!_){x([]),B([]);return}const h=Er(_,z,L);x(h.nodes),B(h.edges)},[L,z,_,B,x]),t.jsxs("div",{className:"gameplay-event-panel",children:[t.jsxs("section",{className:"gameplay-event-panel__section",children:[t.jsx("div",{className:"gameplay-event-panel__title",children:"Create Manual Event"}),t.jsxs("label",{className:"gameplay-event-panel__field",children:[t.jsx("span",{children:"ID"}),t.jsx("input",{value:a,onChange:h=>l(h.target.value)})]}),t.jsxs("label",{className:"gameplay-event-panel__field",children:[t.jsx("span",{children:"Name"}),t.jsx("input",{value:c,onChange:h=>d(h.target.value)})]}),t.jsxs("label",{className:"gameplay-event-panel__field",children:[t.jsx("span",{children:"Trigger Key"}),t.jsx("input",{value:g,onChange:h=>p(h.target.value)})]}),t.jsxs("label",{className:"gameplay-event-panel__field",children:[t.jsx("span",{children:"Toast Message"}),t.jsx("input",{value:m,onChange:h=>f(h.target.value)})]}),t.jsx("button",{type:"button",className:"gameplay-event-panel__primary",onClick:F,children:"Create Event Blueprint"})]}),t.jsxs("section",{className:"gameplay-event-panel__section",children:[t.jsx("div",{className:"gameplay-event-panel__title",children:"Blueprint Library"}),t.jsx("div",{className:"gameplay-event-panel__list",children:e.map(h=>t.jsxs("article",{className:"gameplay-event-panel__card",children:[t.jsxs("div",{children:[t.jsx("div",{className:"gameplay-event-panel__card-title",children:h.name}),t.jsxs("div",{className:"gameplay-event-panel__card-meta",children:[h.id," · ",h.trigger.type," · ",h.actions.length," action(s)"]})]}),t.jsxs("div",{className:"gameplay-event-panel__card-actions",children:[t.jsx("button",{type:"button",onClick:()=>M(h.id),children:"Edit"}),t.jsx("button",{type:"button",onClick:()=>{E(h)},children:"Run"})]})]},h.id))})]}),_&&t.jsxs("section",{className:"gameplay-event-panel__section gameplay-event-panel__detail",children:[t.jsxs("div",{className:"gameplay-event-panel__editor-head",children:[t.jsxs("div",{children:[t.jsx("div",{className:"gameplay-event-panel__title",children:"Blueprint Node Editor"}),t.jsx("div",{className:"gameplay-event-panel__hint",children:"노드 필드를 클릭해서 값을 수정합니다. 타입 변경은 아래 노드 추가/변경 액션에서 처리합니다."})]}),t.jsxs("label",{className:"gameplay-event-panel__type-select",children:[t.jsx("span",{children:"Trigger"}),t.jsx("select",{value:_.trigger.type,onChange:h=>R({trigger:Tr(h.target.value)}),children:["manual","interaction","enterArea","itemCollected","timeChanged","calendarEventStarted","questChanged","custom"].map(h=>t.jsx("option",{value:h,children:h},h))})]})]}),t.jsx("div",{className:"gameplay-event-panel__flow",children:t.jsxs(Be,{nodes:w,edges:C,nodeTypes:Br,onNodesChange:T,onEdgesChange:I,fitView:!0,children:[t.jsx(Be.Background,{variant:Be.BackgroundVariant.Dots,gap:18,size:1}),t.jsx(Be.Controls,{})]})}),t.jsxs("div",{className:"gameplay-event-panel__node-toolbar",children:[t.jsxs("select",{"aria-label":"Condition type",onChange:h=>{R({conditions:[..._.conditions??[],Nr(h.target.value)]}),h.currentTarget.value=""},defaultValue:"",children:[t.jsx("option",{value:"",disabled:!0,children:"Add Condition Node"}),["always","hasItem","questStatus","eventActive","flagEquals","custom"].map(h=>t.jsx("option",{value:h,children:h},h))]}),t.jsxs("select",{"aria-label":"Action type",onChange:h=>{R({actions:[..._.actions,Ir(h.target.value)]}),h.currentTarget.value=""},defaultValue:"",children:[t.jsx("option",{value:"",disabled:!0,children:"Add Action Node"}),["giveItem","removeItem","startQuest","completeQuest","showDialog","toast","setFlag","notifyQuestFlag","emit","custom"].map(h=>t.jsx("option",{value:h,children:h},h))]})]}),t.jsxs("div",{className:"gameplay-event-panel__actions",children:[t.jsx("button",{type:"button",onClick:D,children:"Delete Blueprint"}),t.jsx("button",{type:"button",onClick:()=>{E(_)},children:"Run Selected"})]})]}),t.jsx("section",{className:"gameplay-event-panel__section",children:t.jsx("div",{className:`gameplay-event-panel__status gameplay-event-panel__status--${j.kind}`,children:j.message})})]})}const Rr="studio-social-world",Pr="Studio Social World",Dr="1.0.0",Fr=(e,s)=>{if(typeof window>"u"||typeof document>"u")return;const n=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),i=window.URL.createObjectURL(n),o=document.createElement("a");o.href=i,o.download=e,o.click(),window.URL.revokeObjectURL(i)};function Lr({gameplayEvents:e=At.SEED_GAMEPLAY_EVENTS}){const s=Ye.useAssetStore(I=>I.ids),n=Ye.useAssetStore(I=>I.records),i=u.useMemo(()=>s.map(I=>n[I]).filter(I=>!!I),[s,n]),[o,r]=u.useState("main"),[a,l]=u.useState(Rr),[c,d]=u.useState(Pr),[g,p]=u.useState(Dr),[m,f]=u.useState([]),[y,M]=u.useState({kind:"idle",message:"Ready"}),[_,j]=u.useState(null),A=u.useCallback(()=>At.createContentBundleFromSaveSystem(st.getSaveSystem(),i,{id:a,name:c,version:g,gameplayEvents:e}),[i,a,c,e,g]),w=u.useCallback(async()=>{const I=await st.getSaveSystem().list();f(I),M({kind:"success",message:`Loaded ${I.length} save slot(s)`})},[]),x=u.useCallback(async()=>{await st.getSaveSystem().save(o),M({kind:"success",message:`Saved slot "${o}"`}),await w()},[w,o]),T=u.useCallback(async()=>{const I=await st.getSaveSystem().load(o);M({kind:I?"success":"error",message:I?`Loaded slot "${o}"`:`No save data in slot "${o}"`})},[o]),C=u.useCallback(()=>{const I=At.validateContentBundle(A());j(I),M({kind:I.ok?"success":"error",message:I.ok?"Bundle is valid":`Bundle has ${I.errors.length} error(s)`})},[A]),B=u.useCallback(()=>{const I=A(),F=At.validateContentBundle(I);if(j(F),!F.ok){M({kind:"error",message:"Fix bundle validation before export"});return}Fr(`${I.id}-${I.version}.bundle.json`,I),M({kind:"success",message:"Exported content bundle JSON"})},[A]);return t.jsxs("div",{className:"studio-panel",children:[t.jsxs("section",{className:"studio-panel__section",children:[t.jsx("div",{className:"studio-panel__title",children:"World Save"}),t.jsxs("label",{className:"studio-panel__field",children:[t.jsx("span",{children:"Slot"}),t.jsx("input",{value:o,onChange:I=>r(I.target.value||"main")})]}),t.jsxs("div",{className:"studio-panel__actions",children:[t.jsx("button",{type:"button",onClick:()=>{x()},children:"Save"}),t.jsx("button",{type:"button",onClick:()=>{T()},children:"Load"}),t.jsx("button",{type:"button",onClick:()=>{w()},children:"Refresh"})]}),m.length>0&&t.jsx("div",{className:"studio-panel__chips",children:m.map(I=>t.jsx("button",{type:"button",onClick:()=>r(I),children:I},I))})]}),t.jsxs("section",{className:"studio-panel__section",children:[t.jsx("div",{className:"studio-panel__title",children:"Content Bundle"}),t.jsxs("label",{className:"studio-panel__field",children:[t.jsx("span",{children:"Bundle ID"}),t.jsx("input",{value:a,onChange:I=>l(I.target.value)})]}),t.jsxs("label",{className:"studio-panel__field",children:[t.jsx("span",{children:"Name"}),t.jsx("input",{value:c,onChange:I=>d(I.target.value)})]}),t.jsxs("label",{className:"studio-panel__field",children:[t.jsx("span",{children:"Version"}),t.jsx("input",{value:g,onChange:I=>p(I.target.value)})]}),t.jsxs("div",{className:"studio-panel__meta",children:[i.length," asset(s), ",e.length," gameplay event(s),"," ",Array.from(st.getSaveSystem().getBindings()).length," save domain(s)"]}),t.jsxs("div",{className:"studio-panel__actions",children:[t.jsx("button",{type:"button",onClick:C,children:"Validate"}),t.jsx("button",{type:"button",onClick:B,children:"Export JSON"})]})]}),t.jsxs("section",{className:"studio-panel__section",children:[t.jsx("div",{className:"studio-panel__title",children:"Status"}),t.jsx("div",{className:`studio-panel__status studio-panel__status--${y.kind}`,children:y.message}),_&&!_.ok&&t.jsx("ul",{className:"studio-panel__errors",children:_.errors.map(I=>t.jsx("li",{children:I},I))})]})]})}const Gr=()=>t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})}),zr=()=>t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),cn=({children:e,title:s,initialWidth:n=280,initialHeight:i=400,minWidth:o=200,minHeight:r=150,maxWidth:a=600,maxHeight:l=800,resizeHandles:c=["right"],className:d="",style:g={},onClose:p,onMinimize:m,draggable:f=!0,onDrop:y})=>{const[M,_]=u.useState({width:n,height:i}),[j,A]=u.useState({x:0,y:0}),[w,x]=u.useState(!1),[T,C]=u.useState(!1),[B,I]=u.useState(""),[F,R]=u.useState({x:0,y:0}),D=u.useRef(null),E=u.useRef(null),P=u.useCallback(h=>k=>{k.preventDefault(),x(!0),I(h)},[]),G=u.useCallback(h=>{if(D.current)if(w){const k=D.current.getBoundingClientRect();let U=M.width,W=M.height;B.includes("right")&&(U=Math.min(a,Math.max(o,h.clientX-k.left))),B.includes("bottom")&&(W=Math.min(l,Math.max(r,h.clientY-k.top))),_({width:U,height:W})}else T&&A({x:h.clientX-F.x,y:h.clientY-F.y})},[w,T,B,M,o,a,r,l,F]),z=u.useCallback(()=>{T&&y&&y(j.x,j.y),x(!1),C(!1),I("")},[T,y,j]),L=u.useCallback(h=>{if(!f||w)return;h.preventDefault(),C(!0);const k=D.current?.getBoundingClientRect();k&&R({x:h.clientX-k.left,y:h.clientY-k.top})},[f,w]);return u.useEffect(()=>{if(w||T)return document.addEventListener("mousemove",G),document.addEventListener("mouseup",z),()=>{document.removeEventListener("mousemove",G),document.removeEventListener("mouseup",z)}},[w,T,G,z]),t.jsxs("div",{ref:D,className:`rp-panel ${d} ${T?"dragging":""}`,style:{width:`${M.width}px`,height:`${M.height}px`,...T?{position:"fixed",left:`${j.x}px`,top:`${j.y}px`,zIndex:10003}:{},...g},children:[t.jsxs("div",{ref:E,className:"rp-header",onMouseDown:L,children:[t.jsx("h3",{className:"rp-title",children:s}),t.jsxs("div",{className:"rp-controls",onMouseDown:h=>h.stopPropagation(),children:[m&&t.jsx("button",{className:"rp-btn rp-btn--minimize",onClick:m,title:"최소화",children:t.jsx(Gr,{})}),p&&t.jsx("button",{className:"rp-btn rp-btn--close",onClick:p,title:"닫기",children:t.jsx(zr,{})})]})]}),t.jsx("div",{className:"rp-content",children:e}),c.map(h=>t.jsx("div",{className:`rp-resize-handle handle-${h}`,onMouseDown:P(h.replace("corner","right bottom"))},h))]})},bi=({children:e,panels:s=[],defaultActivePanels:n=["building","character","camera"],actions:i=[]})=>{const[o,r]=u.useState(n),[a,l]=u.useState([]),[c,d]=u.useState([]),g=[{id:"building",title:"건축",component:t.jsx(vr,{}),defaultSide:"left"},{id:"character",title:"캐릭터",component:t.jsx(wr,{}),defaultSide:"left"},{id:"vehicle",title:"탑승체",component:t.jsx(hi,{}),defaultSide:"left"},{id:"animation",title:"애니메이션",component:t.jsx(ui,{}),defaultSide:"left"},{id:"camera",title:"카메라",component:t.jsx(li,{}),defaultSide:"right"},{id:"motion",title:"모션",component:t.jsx(mi,{}),defaultSide:"right"},{id:"performance",title:"성능",component:t.jsx(fi,{}),defaultSide:"right"}],p=u.useMemo(()=>[...g,...s],[s]),m=x=>{r(T=>T.includes(x)?T.filter(C=>C!==x):[...T,x]),d(T=>T.filter(C=>C!==x))},f=x=>{r(T=>T.filter(C=>C!==x)),l(T=>T.filter(C=>C.id!==x)),d(T=>T.filter(C=>C!==x))},y=x=>{d(T=>[...T,x]),r(T=>T.filter(C=>C!==x)),l(T=>T.filter(C=>C.id!==x))},M=x=>{d(T=>T.filter(C=>C!==x)),r(T=>[...T,x])},_=(x,T,C)=>{const B=a.find(I=>I.id===x);l(B?I=>I.map(F=>F.id===x?{...F,x:T,y:C}:F):I=>[...I,{id:x,x:T,y:C,width:300,height:400}])},j=()=>p.filter(x=>o.includes(x.id)&&x.defaultSide==="left"&&!a.some(T=>T.id===x.id)),A=()=>p.filter(x=>o.includes(x.id)&&x.defaultSide==="right"&&!a.some(T=>T.id===x.id)),w=()=>a.filter(x=>o.includes(x.id));return t.jsxs("div",{className:"editor-root",children:[t.jsxs("div",{className:"editor-panel-bar",children:[p.map(x=>t.jsx("button",{onClick:()=>m(x.id),className:`editor-panel-toggle ${o.includes(x.id)?"active":""}`,title:x.title,children:x.title},x.id)),i.map(x=>t.jsx("button",{onClick:()=>{x.onClick()},className:"editor-panel-toggle",disabled:x.disabled,title:x.label,children:x.label},x.id))]}),j().length>0&&t.jsx("div",{className:"editor-left-stack",children:j().map((x,T)=>t.jsx(cn,{title:x.title,initialWidth:320,initialHeight:Math.min(640,Math.max(420,window.innerHeight-120)),minWidth:260,maxWidth:500,resizeHandles:["right"],className:"editor-glass-panel",style:{marginBottom:T<j().length-1?"8px":"0"},onClose:()=>f(x.id),onMinimize:()=>y(x.id),onDrop:(C,B)=>_(x.id,C,B),children:x.component},x.id))}),A().length>0&&t.jsx("div",{className:"editor-right-stack",children:A().map((x,T)=>t.jsx(cn,{title:x.title,initialWidth:300,initialHeight:Math.min(520,Math.max(360,window.innerHeight-120)),minWidth:260,maxWidth:500,resizeHandles:["corner"],className:"editor-glass-panel",style:{marginBottom:T<A().length-1?"8px":"0"},onClose:()=>f(x.id),onMinimize:()=>y(x.id),onDrop:(C,B)=>_(x.id,C,B),children:x.component},x.id))}),w().map(x=>{const T=p.find(C=>C.id===x.id);return T?t.jsx(cn,{title:T.title,initialWidth:x.width,initialHeight:x.height,minWidth:200,maxWidth:800,resizeHandles:["right","bottom","corner"],className:"editor-glass-panel",style:{position:"fixed",left:`${x.x}px`,top:`${x.y}px`,zIndex:1001},onClose:()=>f(T.id),onMinimize:()=>y(T.id),onDrop:(C,B)=>_(T.id,C,B),children:T.component},x.id):null}),c.length>0&&t.jsx("div",{className:"editor-minimized-dock",children:c.map(x=>{const T=p.find(C=>C.id===x);return T?t.jsx("button",{onClick:()=>M(x),className:"editor-minimized-item",title:`${T.title} 복원`,children:T.title},x):null})}),e]})},Or={xDistance:10,yDistance:22,zDistance:30,fov:58,zoom:1,enableZoom:!0,minZoom:.35,maxZoom:2.4,zoomSpeed:.001,enableCollision:!1,smoothing:{position:.12,rotation:.12,fov:.12}},Ur=({children:e,className:s="",style:n={},shell:i})=>{const o=u.useRef(null);return u.useEffect(()=>{const r=re.useGaesupStore.getState();return o.current={mode:r.mode,cameraOption:r.cameraOption},r.setMode({control:"thirdPerson"}),r.setCameraOption(Or),()=>{const a=o.current;a&&(re.useGaesupStore.getState().setMode(a.mode),re.useGaesupStore.getState().setCameraOption(a.cameraOption))}},[]),t.jsx("div",{className:`gaesup-editor ${s}`,style:{...n},children:t.jsx(bi,{...i?.panels?{panels:i.panels}:{},...i?.defaultActivePanels?{defaultActivePanels:i.defaultActivePanels}:{},...i?.actions?{actions:i.actions}:{},children:e})})},xs=e=>({selectedObjectIds:[],setSelectedObjectIds:s=>e({selectedObjectIds:s}),layoutConfig:null,setLayoutConfig:s=>e({layoutConfig:s}),activeNodeGraph:null,setActiveNodeGraph:s=>e({activeNodeGraph:s}),clipboard:null,setClipboard:s=>e({clipboard:s})}),Wr=xs,xi=rt.create(xs),Hr=()=>{const e=xi();return{...e,selectObject:s=>e.setSelectedObjectIds([s]),selectMultiple:s=>e.setSelectedObjectIds(s),clearSelection:()=>e.setSelectedObjectIds([])}};function $r(e={}){const s={panels:e.panels??[],actions:(e.commands??[]).map(n=>({id:n.id,label:n.label,onClick:n.run}))};return e.defaultActivePanels&&(s.defaultActivePanels=e.defaultActivePanels),e.validate&&(s.validate=e.validate),s}function Zr(){const e=[],s=[];return{execute:async n=>{await n.run(),n.undo&&(e.push(n),s.length=0)},undo:async()=>{const n=e.pop();n?.undo&&(await n.undo(),s.push(n))},redo:async()=>{const n=s.pop();n&&(await n.run(),e.push(n))},canUndo:()=>e.length>0,canRedo:()=>s.length>0,clear:()=>{e.length=0,s.length=0}}}const Vr=["intel","mali","adreno 3","adreno 4","powervr"],Yr=["swiftshader","llvmpipe","software"],Us=["rtx","radeon rx","apple m","apple a1","apple a2"];function vi(){if(typeof window>"u"||typeof document>"u")return{webgl2:!1,maxTextureSize:0,rendererName:"",vendorName:"",cores:4,memory:4,isMobile:!1,pixelRatio:1};const e=document.createElement("canvas"),s=e.getContext("webgl2")??e.getContext("webgl");let n="",i="",o=0,r=!1;if(s){r=typeof WebGL2RenderingContext<"u"&&s instanceof WebGL2RenderingContext,o=s.getParameter(s.MAX_TEXTURE_SIZE)||0;const g=s.getExtension("WEBGL_debug_renderer_info");g&&(n=String(s.getParameter(g.UNMASKED_RENDERER_WEBGL)||""),i=String(s.getParameter(g.UNMASKED_VENDOR_WEBGL)||""))}const a=navigator.hardwareConcurrency??4,l=navigator.deviceMemory??4,c=/android|iphone|ipad|ipod|mobile|opera mini/i.test(navigator.userAgent),d=Math.min(window.devicePixelRatio||1,2);return{webgl2:r,maxTextureSize:o,rendererName:n,vendorName:i,cores:a,memory:l,isMobile:c,pixelRatio:d}}function yi(e){const s=e.rendererName.toLowerCase();return Yr.some(n=>s.includes(n))?"low":e.isMobile?Us.some(n=>s.includes(n))?"medium":"low":Vr.some(n=>s.includes(n))?e.cores>=8&&e.memory>=8?"medium":"low":Us.some(n=>s.includes(n))||e.cores>=8&&e.memory>=8&&e.webgl2?"high":e.cores>=4&&e.memory>=4?"medium":"low"}function vn(e){return e==="high"?{tier:e,instanceScale:1,pixelRatio:2,shadowMapSize:2048,postprocess:!0,outline:!0}:e==="medium"?{tier:e,instanceScale:.7,pixelRatio:1.5,shadowMapSize:1024,postprocess:!0,outline:!0}:{tier:e,instanceScale:.4,pixelRatio:1,shadowMapSize:512,postprocess:!1,outline:!1}}function ls(){const e=vi(),s=yi(e);return{profile:vn(s),capabilities:e}}const Xr=vn("medium"),Si=rt.create(e=>({profile:Xr,capabilities:null,manualOverride:!1,detect:()=>{const{profile:s,capabilities:n}=ls();e({profile:s,capabilities:n,manualOverride:!1})},setTier:s=>{e({profile:vn(s),manualOverride:!0})},resetAuto:()=>{const{profile:s,capabilities:n}=ls();e({profile:s,capabilities:n,manualOverride:!1})}}));qo.enableMapSet();const oe=rt.create()(Ko.immer((e,s)=>({initialized:!1,templates:new Map,instances:new Map,categories:new Map,clothingSets:new Map,clothingCategories:new Map,animations:new Map,editMode:!1,previewAccessories:{},initializeDefaults:()=>e(n=>{n.initialized||(n.animations.set("idle",{id:"idle",name:"Idle",loop:!0,speed:1}),n.animations.set("walk",{id:"walk",name:"Walk",loop:!0,speed:1}),n.animations.set("greet",{id:"greet",name:"Greet",loop:!1,speed:1}),n.animations.set("jump",{id:"jump",name:"Jump",loop:!1,speed:1}),n.animations.set("run",{id:"run",name:"Run",loop:!0,speed:1.5}),n.clothingCategories.set("basic",{id:"basic",name:"기본 의상",description:"Basic clothing sets",clothingSetIds:["rabbit-outfit","basic-suit","formal-suit"]}),n.clothingCategories.set("accessories",{id:"accessories",name:"액세서리",description:"Hats and glasses",clothingSetIds:["hat-set-a","hat-set-b","hat-set-c","glass-set-a","glass-set-b"]}),n.clothingSets.set("rabbit-outfit",{id:"rabbit-outfit",name:"토끼옷",category:"casual",parts:[{id:"rabbit-cloth",type:"top",url:"gltf/ally_cloth_rabbit.glb",position:[0,0,0]}]}),n.clothingSets.set("basic-suit",{id:"basic-suit",name:"양복",category:"formal",parts:[{id:"basic-suit-cloth",type:"top",url:"gltf/ally_cloth.glb",position:[0,0,0]}]}),n.clothingSets.set("formal-suit",{id:"formal-suit",name:"양복 2",category:"formal",parts:[{id:"formal-suit-cloth",type:"top",url:"gltf/formal.glb",position:[0,0,0]}]}),n.clothingSets.set("hat-set-a",{id:"hat-set-a",name:"모자 A",category:"casual",parts:[{id:"hat-a",type:"hat",url:"gltf/hat_a.glb",position:[0,0,0]}]}),n.clothingSets.set("hat-set-b",{id:"hat-set-b",name:"모자 B",category:"casual",parts:[{id:"hat-b",type:"hat",url:"gltf/hat_b.glb",position:[0,0,0]}]}),n.clothingSets.set("hat-set-c",{id:"hat-set-c",name:"모자 C",category:"casual",parts:[{id:"hat-c",type:"hat",url:"gltf/hat_c.glb",position:[0,0,0]}]}),n.clothingSets.set("glass-set-a",{id:"glass-set-a",name:"안경 A",category:"casual",parts:[{id:"glass-a",type:"glasses",url:"gltf/glass_a.glb",position:[0,0,0]}]}),n.clothingSets.set("glass-set-b",{id:"glass-set-b",name:"슈퍼 안경",category:"casual",parts:[{id:"super-glass",type:"glasses",url:"gltf/super_glass.glb",position:[0,0,0]}]}),n.categories.set("humanoid",{id:"humanoid",name:"캐릭터",description:"Human-like characters",templateIds:["ally","oneyee"]}),n.templates.set("ally",{id:"ally",name:"올춘삼",description:"Ally character",category:"humanoid",baseParts:[{id:"ally-body",type:"body",url:"gltf/ally_body.glb",position:[0,0,0]}],clothingParts:[],defaultAnimation:"idle",defaultClothingSet:"rabbit-outfit"}),n.templates.set("oneyee",{id:"oneyee",name:"원덕배",description:"Oneyee character",category:"humanoid",baseParts:[{id:"oneyee-body",type:"body",url:"gltf/oneyee.glb",position:[0,0,0]}],clothingParts:[],defaultAnimation:"idle",defaultClothingSet:"basic-suit"}),n.selectedCategoryId="humanoid",n.selectedTemplateId="ally",n.selectedClothingCategoryId="basic",n.selectedClothingSetId="rabbit-outfit",n.initialized=!0)}),addTemplate:n=>e(i=>{i.templates.set(n.id,n)}),updateTemplate:(n,i)=>e(o=>{const r=o.templates.get(n);r&&o.templates.set(n,{...r,...i})}),removeTemplate:n=>e(i=>{i.templates.delete(n)}),addInstance:n=>e(i=>{i.instances.set(n.id,n)}),updateInstance:(n,i)=>e(o=>{const r=o.instances.get(n);r&&o.instances.set(n,{...r,...i})}),removeInstance:n=>e(i=>{i.instances.delete(n)}),addCategory:n=>e(i=>{i.categories.set(n.id,n)}),updateCategory:(n,i)=>e(o=>{const r=o.categories.get(n);r&&o.categories.set(n,{...r,...i})}),removeCategory:n=>e(i=>{i.categories.delete(n)}),addClothingSet:n=>e(i=>{i.clothingSets.set(n.id,n)}),updateClothingSet:(n,i)=>e(o=>{const r=o.clothingSets.get(n);r&&o.clothingSets.set(n,{...r,...i})}),removeClothingSet:n=>e(i=>{i.clothingSets.delete(n)}),addClothingCategory:n=>e(i=>{i.clothingCategories.set(n.id,n)}),updateClothingCategory:(n,i)=>e(o=>{const r=o.clothingCategories.get(n);r&&o.clothingCategories.set(n,{...r,...i})}),removeClothingCategory:n=>e(i=>{i.clothingCategories.delete(n)}),addAnimation:n=>e(i=>{i.animations.set(n.id,n)}),updateAnimation:(n,i)=>e(o=>{const r=o.animations.get(n);r&&o.animations.set(n,{...r,...i})}),removeAnimation:n=>e(i=>{i.animations.delete(n)}),setSelectedTemplate:n=>e(i=>{i.selectedTemplateId=n}),setSelectedCategory:n=>e(i=>{i.selectedCategoryId=n;const o=i.categories.get(n);if(o&&o.templateIds.length>0){const r=o.templateIds[0];r&&(i.selectedTemplateId=r)}else delete i.selectedTemplateId}),setSelectedInstance:n=>e(i=>{i.selectedInstanceId=n}),setSelectedClothingSet:n=>e(i=>{i.selectedClothingSetId=n}),setSelectedClothingCategory:n=>e(i=>{i.selectedClothingCategoryId=n;const o=i.clothingCategories.get(n);if(o&&o.clothingSetIds.length>0){const r=o.clothingSetIds[0];r&&(i.selectedClothingSetId=r)}else delete i.selectedClothingSetId}),setEditMode:n=>e(i=>{i.editMode=n}),createInstanceFromTemplate:(n,i)=>{const o=s().templates.get(n);if(!o)return;const r=`npc-${Date.now()}`,a=s().selectedClothingSetId||o.defaultClothingSet,l=[],c=s().previewAccessories.hat;if(c){const m=s().clothingSets.get(c)?.parts[0];m&&l.push(m)}const d=s().previewAccessories.glasses;if(d){const m=s().clothingSets.get(d)?.parts[0];m&&l.push(m)}const g={id:r,templateId:n,name:`${o.name} ${Date.now()}`,position:i,rotation:[0,0,0],scale:[1,1,1],...o.defaultAnimation?{currentAnimation:o.defaultAnimation}:{},...a?{currentClothingSetId:a}:{},...l.length>0?{customParts:l}:{},events:[]};s().addInstance(g),s().setSelectedInstance(r)},updateInstancePart:(n,i,o)=>e(r=>{const a=r.instances.get(n);if(!a)return;const l=a.customParts||[],c=l.findIndex(d=>d.id===i);if(c>=0){const d=l[c];l[c]={...d,...o,id:d.id,type:d.type,url:d.url}}else{const d=o.type??"accessory",g=o.url??"";l.push({id:i,type:d,url:g,...o.category!==void 0?{category:o.category}:{},...o.position!==void 0?{position:o.position}:{},...o.rotation!==void 0?{rotation:o.rotation}:{},...o.scale!==void 0?{scale:o.scale}:{},...o.color!==void 0?{color:o.color}:{},...o.metadata!==void 0?{metadata:o.metadata}:{}})}r.instances.set(n,{...a,customParts:l})}),changeInstanceClothing:(n,i)=>e(o=>{const r=o.instances.get(n);r&&o.instances.set(n,{...r,currentClothingSetId:i})}),addInstanceEvent:(n,i)=>e(o=>{const r=o.instances.get(n);if(r){const a=r.events||[];a.push(i),o.instances.set(n,{...r,events:a})}}),removeInstanceEvent:(n,i)=>e(o=>{const r=o.instances.get(n);if(r&&r.events){const a=r.events.filter(l=>l.id!==i);o.instances.set(n,{...r,events:a})}}),setPreviewAccessory:(n,i)=>e(o=>{i?o.previewAccessories[n]=i:delete o.previewAccessories[n]}),setNavigation:(n,i,o=3)=>e(r=>{const a=r.instances.get(n);if(!a||i.length===0)return;const l={waypoints:i,currentIndex:0,speed:o,state:"moving"};r.instances.set(n,{...a,navigation:l,currentAnimation:"walk"})}),advanceNavigation:n=>e(i=>{const o=i.instances.get(n);if(!o?.navigation||o.navigation.state!=="moving")return;const r=o.navigation,a=r.currentIndex+1;a>=r.waypoints.length?i.instances.set(n,{...o,navigation:{...r,state:"arrived",currentIndex:a},currentAnimation:"idle"}):i.instances.set(n,{...o,navigation:{...r,currentIndex:a}})}),clearNavigation:n=>e(i=>{const o=i.instances.get(n);if(!o)return;const r={...o,currentAnimation:"idle"};delete r.navigation,i.instances.set(n,r)}),updateNavigationPosition:(n,i)=>e(o=>{const r=o.instances.get(n);r&&o.instances.set(n,{...r,position:i})})})));function qr({part:e}){return t.jsxs("mesh",{position:e.position||[0,0,0],rotation:e.rotation||[0,0,0],scale:e.scale||[1,1,1],children:[t.jsx("boxGeometry",{args:[.5,1.8,.5]}),t.jsx("meshStandardMaterial",{color:"royalblue",transparent:!0,opacity:.7})]})}function Kr(){const e=S.useBuildingStore(d=>d.editMode),s=S.useBuildingStore(d=>d.hoverPosition),n=oe(d=>d.templates),i=oe(d=>d.clothingSets),o=oe(d=>d.selectedTemplateId),r=oe(d=>d.selectedClothingSetId),a=oe(d=>d.previewAccessories);if(e!=="npc"||!s||!o)return null;const l=n.get(o);if(!l)return null;const c=[];if(c.push(...l.baseParts),r){const d=i.get(r);d&&c.push(...d.parts)}if(a.hat){const d=i.get(a.hat);if(d&&d.parts.length>0){const g=d.parts[0];g&&c.push(g)}}if(a.glasses){const d=i.get(a.glasses);if(d&&d.parts.length>0){const g=d.parts[0];g&&c.push(g)}}return t.jsxs("group",{position:[s.x,s.y,s.z],children:[c.map(d=>t.jsx(qr,{part:d},d.id)),t.jsxs("mesh",{position:[0,.01,0],rotation:[-Math.PI/2,0,0],children:[t.jsx("circleGeometry",{args:[1,32]}),t.jsx("meshStandardMaterial",{color:"#00ff00",transparent:!0,opacity:.3,emissive:"#00ff00",emissiveIntensity:.3})]})]})}const Ue=new Set,_e=rt.create(e=>({active:!1,version:0,visibleTileGroupIds:Ue,visibleWallGroupIds:Ue,visibleBlockIds:Ue,visibleObjectIds:Ue,clusterCounts:new Uint32Array(0),setResult:({version:s,tileIds:n,wallIds:i,blockIds:o,objectIds:r,clusterCounts:a})=>e({active:!0,version:s,visibleTileGroupIds:n,visibleWallGroupIds:i,visibleBlockIds:o??Ue,visibleObjectIds:r,clusterCounts:a}),reset:()=>e({active:!1,version:0,visibleTileGroupIds:Ue,visibleWallGroupIds:Ue,visibleBlockIds:Ue,visibleObjectIds:Ue,clusterCounts:new Uint32Array(0)})})),ze=18,Le=140,Jr=.12,Qr=8,ea=3.2,Ws=2.4,ta=.985;function Ke(e,s){return Math.floor(e/s)}function Mi(e,s){return`${e}:${s}`}function na(e,s,n,i,o=ze,r=Qr){const a=Ke(e,o),l=Ke(s,o),c=Math.atan2(i,n),d=c<0?c+Math.PI*2:c,g=Math.floor(d/(Math.PI*2)*r)%r;return`${a}:${l}:${g}`}function un(e,s,n,i=ze){const o=Math.max(0,Math.ceil(s.radius/i));for(let r=s.cellZ-o;r<=s.cellZ+o;r+=1)for(let a=s.cellX-o;a<=s.cellX+o;a+=1)sa(e,a,r,n)}function Jt(e,s,n=ze){un(e,s,s.id,n)}function sa(e,s,n,i){const o=Mi(s,n),r=e.get(o);if(r){r.push(i);return}e.set(o,[i])}function vs(e,s,n,i,o,r,a,l){const c=(s+n)*.5,d=(i+o)*.5,g=(r+a)*.5,p=n-s,m=o-i,f=a-r;return{id:e,centerX:c,centerY:d,centerZ:g,radius:Math.max(1,Math.hypot(p,m,f)*.5),cellX:Ke(c,l),cellZ:Ke(g,l)}}function ji(e,s=ze){if(e.tiles.length===0)return null;let n=1/0,i=-1/0,o=0,r=.2,a=1/0,l=-1/0;for(const c of e.tiles){const g=(c.size??1)*.5;n=Math.min(n,c.position.x-g),i=Math.max(i,c.position.x+g),o=Math.min(o,0),r=Math.max(r,Math.max(c.position.y,.2)+1.5),a=Math.min(a,c.position.z-g),l=Math.max(l,c.position.z+g)}return vs(e.id,n,i,o,r,a,l,s)}function wi(e,s=ze){if(e.walls.length===0)return null;let n=1/0,i=-1/0,o=0,r=2.5,a=1/0,l=-1/0;for(const c of e.walls)n=Math.min(n,c.position.x-1.1),i=Math.max(i,c.position.x+1.1),o=Math.min(o,c.position.y),r=Math.max(r,c.position.y+3.5),a=Math.min(a,c.position.z-1.1),l=Math.max(l,c.position.z+1.1);return vs(e.id,n,i,o,r,a,l,s)}function _i(e,s=ze){const n=Math.max(1,Math.round(e.size?.x??1))*S.TILE_CONSTANTS.GRID_CELL_SIZE,i=Math.max(1,Math.round(e.size?.y??1))*S.TILE_CONSTANTS.HEIGHT_STEP,o=Math.max(1,Math.round(e.size?.z??1))*S.TILE_CONSTANTS.GRID_CELL_SIZE,r=S.TILE_CONSTANTS.GRID_CELL_SIZE*.5;return vs(e.id,e.position.x-r,e.position.x-r+n,e.position.y,e.position.y+i,e.position.z-r,e.position.z-r+o,s)}function ia(e){const s=e.config?.size??1;switch(e.type){case"sakura":return Math.max(2.2,s*.8);case"flag":return Math.max(1.4,(e.config?.flagWidth??1.5)*.8);case"fire":return Math.max(1.2,e.config?.fireWidth??1);case"billboard":return 1.8;default:return 1.5}}function Ci(e,s=ze){const n=ia(e);return{id:e.id,centerX:e.position.x,centerY:e.position.y+n*.5,centerZ:e.position.z,radius:n,cellX:Ke(e.position.x,s),cellZ:Ke(e.position.z,s)}}function oa(e,s,n,i=[],o=ze){const r=Array.isArray(i)?i:[],a=typeof i=="number"?i:o,l={tileById:new Map,wallById:new Map,blockById:new Map,objectById:new Map,tileBuckets:new Map,wallBuckets:new Map,blockBuckets:new Map,objectBuckets:new Map,occluderByKey:new Map,occluderBuckets:new Map};for(const c of s){const d=ji(c,a);if(d&&(l.tileById.set(d.id,d),Jt(l.tileBuckets,d,a),d.radius>=ea)){const g={...d,key:`tile:${d.id}`,kind:"tile",strength:d.radius};l.occluderByKey.set(g.key,g),un(l.occluderBuckets,g,g.key,a)}}for(const c of e){const d=wi(c,a);if(d&&(l.wallById.set(d.id,d),Jt(l.wallBuckets,d,a),d.radius>=Ws||c.walls.length>=4)){const g={...d,key:`wall:${d.id}`,kind:"wall",strength:d.radius*1.15};l.occluderByKey.set(g.key,g),un(l.occluderBuckets,g,g.key,a)}}for(const c of r){const d=_i(c,a);if(l.blockById.set(d.id,d),Jt(l.blockBuckets,d,a),d.radius>=Ws||(c.size?.y??1)>=2){const g={...d,key:`block:${d.id}`,kind:"block",strength:d.radius*1.1};l.occluderByKey.set(g.key,g),un(l.occluderBuckets,g,g.key,a)}}for(const c of n){const d=Ci(c,a);l.objectById.set(d.id,d),Jt(l.objectBuckets,d,a)}return l}function Bt(e,s,n,i=Le,o=ze){const r=Ke(s,o),a=Ke(n,o),l=Math.ceil(i/o),c=new Set;for(let d=a-l;d<=a+l;d+=1)for(let g=r-l;g<=r+l;g+=1){const p=e.get(Mi(g,d));if(p)for(const m of p)c.add(m)}return c}function ra(e,s,n,i=Le,o=ze){const r=Bt(e.occluderBuckets,s,n,i,o),a=[];for(const l of r){const c=e.occluderByKey.get(l);c&&a.push(c)}return a}function aa(e,s,n,i,o){const r=e.centerX-n.x,a=e.centerY-n.y,l=e.centerZ-n.z,c=Math.sqrt(r*r+a*a+l*l);if(c<10)return!1;o.targetDir.set(r,a,l).normalize();for(const d of i){if(d.kind===s&&d.id===e.id)continue;const g=d.centerX-n.x,p=d.centerY-n.y,m=d.centerZ-n.z,f=Math.sqrt(g*g+p*p+m*m);if(f<=1||f>=c-Math.max(e.radius,1.2)||(o.occDir.set(g,p,m).normalize(),o.targetDir.dot(o.occDir)<ta))continue;const M=o.cross.crossVectors(o.targetDir,o.occDir).length()*f,_=d.strength+Math.min(e.radius*.45,1.8);if(!(M>_))return!0}return!1}const ys=0,Ss=1,Ms=2,js=3,la=0,Ti=1,Ni=2,Ii=3,Ai=4,ca=10,Bi=20,Ei=21,cs=22,ki=23,Ri=24,ua=30;function Pi(){return{version:0,ids:[],kinds:new Uint8Array(0),subKinds:new Uint8Array(0),centerX:new Float32Array(0),centerY:new Float32Array(0),centerZ:new Float32Array(0),radius:new Float32Array(0),cellX:new Int16Array(0),cellZ:new Int16Array(0),memberCount:new Uint16Array(0)}}function da(e,s,n,i){let o=n.length+i.length;for(const r of e)r.walls.length>0&&(o+=1);for(const r of s)r.tiles.length>0&&(o+=1);return o}function pa(e){const s=e.blocks??[],n=da(e.wallGroups,e.tileGroups,e.objects,s);if(n===0)return{...Pi(),version:e.version};const i=new Array(n),o=new Uint8Array(n),r=new Uint8Array(n),a=new Float32Array(n),l=new Float32Array(n),c=new Float32Array(n),d=new Float32Array(n),g=new Int16Array(n),p=new Int16Array(n),m=new Uint16Array(n);let f=0;const y=(M,_,j,A,w)=>{i[f]=M,o[f]=_,r[f]=j,a[f]=A.centerX,l[f]=A.centerY,c[f]=A.centerZ,d[f]=A.radius,g[f]=A.cellX,p[f]=A.cellZ,m[f]=w,f+=1};for(const M of e.tileGroups){const _=ji(M);if(!_)continue;const j=M.tiles.find(w=>w.objectType&&w.objectType!=="none")?.objectType??"none",A=j==="grass"?Ti:j==="water"?Ni:j==="sand"?Ii:j==="snowfield"?Ai:la;y(M.id,ys,A,_,M.tiles.length)}for(const M of e.wallGroups){const _=wi(M);_&&y(M.id,Ss,ca,_,M.walls.length)}for(const M of s)y(M.id,js,ua,_i(M),1);for(const M of e.objects){const _=M.type==="sakura"?Bi:M.type==="flag"?Ei:M.type==="fire"?cs:M.type==="billboard"?ki:M.type==="model"?Ri:cs;y(M.id,Ms,_,Ci(M),1)}return{version:e.version,ids:i,kinds:o,subKinds:r,centerX:a,centerY:l,centerZ:c,radius:d,cellX:g,cellZ:p,memberCount:m}}const mt=0,ws=1,ft=2,ht=3,gt=4,yn=5,Sn=6,Mn=7,jn=8,wn=9,_n=10,Cn=11,Tn=12;function Di(e,s){const n=e.kinds[s],i=e.subKinds[s];if(n===ys)return i===Ti?ws:i===Ni?ft:i===Ii?ht:i===Ai?gt:mt;if(n===Ss)return yn;if(n===js)return _n;if(n===Ms){if(i===Bi)return Sn;if(i===Ei)return Mn;if(i===cs)return jn;if(i===ki)return wn;if(i===Ri)return Cn}return mt}function Fi(e,s){const n=new Set,i=new Set,o=new Set,r=new Set,a=new Uint32Array(Tn),l=Math.min(e.ids.length,s.length);for(let c=0;c<l;c+=1){if((s[c]??0)===0)continue;const d=e.ids[c];if(!d)continue;const g=e.kinds[c];g===ys?n.add(d):g===Ss?i.add(d):g===js?o.add(d):g===Ms&&r.add(d);const p=Di(e,c);a[p]=(a[p]??0)+1}return{version:e.version,tileIds:n,wallIds:i,blockIds:o,objectIds:r,clusterCounts:a}}const ke=4;function Ne(e,s){const n=s*ke;return e.args[n+1]??0}const Li=[{id:mt,label:"tile",vertexCountHint:36},{id:ws,label:"grass",vertexCountHint:36},{id:ft,label:"water",vertexCountHint:36},{id:ht,label:"sand",vertexCountHint:36},{id:gt,label:"snowfield",vertexCountHint:36},{id:yn,label:"wall",vertexCountHint:36},{id:Sn,label:"sakura",vertexCountHint:12},{id:Mn,label:"flag",vertexCountHint:12},{id:jn,label:"fire",vertexCountHint:6},{id:wn,label:"billboard",vertexCountHint:6},{id:_n,label:"block",vertexCountHint:36},{id:Cn,label:"model",vertexCountHint:36}];function _s(){return{version:0,args:new Uint32Array(Tn*ke),dirtyRanges:[]}}function ma(e,s){if(e.length!==s.length)return s.length>0?[{start:0,end:s.length/ke}]:[];const n=[];let i=-1;const o=s.length/ke;for(let r=0;r<o;r+=1){const a=r*ke;let l=!1;for(let c=0;c<ke;c+=1)if((e[a+c]??0)!==(s[a+c]??0)){l=!0;break}if(l){i<0&&(i=r);continue}i>=0&&(n.push({start:i,end:r}),i=-1)}return i>=0&&n.push({start:i,end:o}),n}function Gi(e,s,n){const i=new Uint32Array(Tn*ke);for(const r of Li){const a=r.id*ke;i[a]=r.vertexCountHint,i[a+1]=s[r.id]??0,i[a+2]=0,i[a+3]=0}const o=n??_s();return{version:e,args:i,dirtyRanges:ma(o.args,i)}}function zi(e){return{version:e.version,slices:e.dirtyRanges.map(s=>{const n=s.start*ke,i=(s.end-s.start)*ke;return{byteOffset:n*e.args.BYTES_PER_ELEMENT,elementOffset:n,elementCount:i,data:e.args.subarray(n,n+i)}})}}const Ft=4,Lt=5;function Cs(){return{version:0,count:0,spatial:new Float32Array(0),meta:new Int32Array(0),spatialDirty:[],metaDirty:[]}}function fa(e){const s=new Float32Array(e.ids.length*Ft);for(let n=0;n<e.ids.length;n+=1){const i=n*Ft;s[i]=e.centerX[n]??0,s[i+1]=e.centerY[n]??0,s[i+2]=e.centerZ[n]??0,s[i+3]=e.radius[n]??0}return s}function ha(e){const s=new Int32Array(e.ids.length*Lt);for(let n=0;n<e.ids.length;n+=1){const i=n*Lt;s[i]=e.cellX[n]??0,s[i+1]=e.cellZ[n]??0,s[i+2]=e.kinds[n]??0,s[i+3]=e.subKinds[n]??0,s[i+4]=e.memberCount[n]??0}return s}function Hs(e,s,n){if(e.length!==s.length)return s.length>0?[{start:0,end:Math.ceil(s.length/n)}]:[];const i=[];let o=-1;const r=Math.ceil(s.length/n);for(let a=0;a<r;a+=1){const l=a*n;let c=!1;for(let d=0;d<n;d+=1)if((e[l+d]??0)!==(s[l+d]??0)){c=!0;break}if(c){o<0&&(o=a);continue}o>=0&&(i.push({start:o,end:a}),o=-1)}return o>=0&&i.push({start:o,end:r}),i}function Oi(e,s){const n=fa(e),i=ha(e),o=s??Cs();return{version:e.version,count:e.ids.length,spatial:n,meta:i,spatialDirty:Hs(o.spatial,n,Ft),metaDirty:Hs(o.meta,i,Lt)}}function $s(e,s,n){return n.map(i=>{const o=i.start*s,r=(i.end-i.start)*s;return{byteOffset:o*e.BYTES_PER_ELEMENT,elementOffset:o,elementCount:r,data:e.subarray(o,o+r)}})}function Ui(e){return{version:e.version,count:e.count,spatial:$s(e.spatial,Ft,e.spatialDirty),meta:$s(e.meta,Lt,e.metaDirty)}}const ga=8,ba=128;function Gt(){return{backend:"none",uploadedVersion:0,spatialBuffer:null,metaBuffer:null,indirectArgsBuffer:null,spatialBytes:0,metaBytes:0,indirectArgsBytes:0}}function Nn(e){if(typeof e!="object"||e===null)return null;const s=e,n=s.backend?.device??s.device??null;return!n||typeof n.createBuffer!="function"||typeof n.queue?.writeBuffer!="function"?null:n}function kt(e){e?.destroy&&e.destroy()}function Wi(e){kt(e.spatialBuffer),kt(e.metaBuffer),kt(e.indirectArgsBuffer)}function us(e,s,n,i,o){return i<=0?(kt(s),null):s&&n===i?s:(kt(s),e.createBuffer({label:o,size:i,usage:ba|ga}))}function Hi(e,s,n){const i=Ui(n),o=n.spatial.byteLength,r=n.meta.byteLength,a=us(e,s.spatialBuffer,s.spatialBytes,o,"building-spatial"),l=us(e,s.metaBuffer,s.metaBytes,r,"building-meta");if(a)for(const c of i.spatial)e.queue.writeBuffer(a,c.byteOffset,c.data);if(l)for(const c of i.meta)e.queue.writeBuffer(l,c.byteOffset,c.data);return{backend:"webgpu",uploadedVersion:n.version,spatialBuffer:a,metaBuffer:l,indirectArgsBuffer:s.indirectArgsBuffer,spatialBytes:o,metaBytes:r,indirectArgsBytes:s.indirectArgsBytes}}function $i(e,s,n){const i=zi(n),o=n.args.byteLength,r=us(e,s.indirectArgsBuffer,s.indirectArgsBytes,o,"building-indirect-args");if(r)for(const a of i.slices)e.queue.writeBuffer(r,a.byteOffset,a.data);return{...s,backend:"webgpu",uploadedVersion:Math.max(s.uploadedVersion,n.version),indirectArgsBuffer:r,indirectArgsBytes:o}}const Zs=Pi(),Vs=Cs(),Ys=Gt(),Xs=_s(),ge=rt.create(e=>({snapshot:Zs,gpuMirror:Vs,uploadResources:Ys,drawMirror:Xs,setSnapshot:s=>e({snapshot:s}),setGpuMirror:s=>e({gpuMirror:s}),setUploadResources:s=>e({uploadResources:s}),setDrawMirror:s=>e({drawMirror:s}),reset:()=>e({snapshot:Zs,gpuMirror:Vs,uploadResources:Ys,drawMirror:Xs})}));function Qt(e,s){if(e===s)return!0;if(e.size!==s.size)return!1;for(const n of e)if(!s.has(n))return!1;return!0}const We=new Set,Ze=rt.create(e=>({initialized:!1,visibleTileGroupIds:We,visibleWallGroupIds:We,visibleBlockIds:We,visibleObjectIds:We,setVisible:({tileIds:s,wallIds:n,blockIds:i,objectIds:o})=>e(r=>{const a=!Qt(r.visibleTileGroupIds,s),l=!Qt(r.visibleWallGroupIds,n),c=i??We,d=!Qt(r.visibleBlockIds,c),g=!Qt(r.visibleObjectIds,o);return!a&&!l&&!d&&!g&&r.initialized?r:{initialized:!0,visibleTileGroupIds:a?s:r.visibleTileGroupIds,visibleWallGroupIds:l?n:r.visibleWallGroupIds,visibleBlockIds:d?c:r.visibleBlockIds,visibleObjectIds:g?o:r.visibleObjectIds}}),reset:()=>e({initialized:!1,visibleTileGroupIds:We,visibleWallGroupIds:We,visibleBlockIds:We,visibleObjectIds:We})}));var xa=Object.defineProperty,va=Object.getOwnPropertyDescriptor,Ut=(e,s,n,i)=>{for(var o=va(s,n),r=e.length-1,a;r>=0;r--)(a=e[r])&&(o=a(s,n,o)||o);return o&&xa(s,n,o),o};class Je{materials=new Map;textures=new Map;textureLoader;constructor(){this.textureLoader=new b.TextureLoader}getMaterial(s){const n=this.createMaterialKey(s),i=this.materials.get(n);if(i)return i;const o=this.createMaterial(s);return this.materials.set(n,o),o}createMaterialKey(s){return[s.id,s.assetId??"",s.color??s.materialParams?.color??"",s.material??"",s.textureUrl??"",s.mapTextureUrl??s.materialParams?.mapTextureUrl??"",s.normalTextureUrl??s.materialParams?.normalTextureUrl??"",s.roughness??s.materialParams?.roughness??"",s.metalness??s.materialParams?.metalness??"",s.opacity??s.materialParams?.opacity??"",s.transparent??s.materialParams?.transparent??""].join("|")}createMaterial(s){const n=s.color??s.materialParams?.color??"#ffffff",i=s.roughness??s.materialParams?.roughness??.5,o=s.metalness??s.materialParams?.metalness??0,r=s.opacity??s.materialParams?.opacity??1,a=s.transparent??s.materialParams?.transparent??!1,l=s.mapTextureUrl??s.textureUrl??s.materialParams?.mapTextureUrl,c=s.normalTextureUrl??s.materialParams?.normalTextureUrl,d={color:n,roughness:i,metalness:o,opacity:r,transparent:a};if(S.getDefaultToonMode()){const g=s.material==="GLASS",p=new b.MeshToonMaterial({color:n,opacity:g?.45:r,transparent:g?!0:a,gradientMap:S.getToonGradient(g?2:4)});return l&&(p.map=this.loadTexture(l)),c&&(p.normalMap=this.loadTexture(c)),p}return s.material==="GLASS"?new b.MeshPhysicalMaterial({...d,transmission:.98,roughness:.1,envMapIntensity:1}):(l&&(d.map=this.loadTexture(l)),c&&(d.normalMap=this.loadTexture(c)),new b.MeshStandardMaterial(d))}loadTexture(s){const n=this.textures.get(s);if(n)return n;const i=this.textureLoader.load(s);return i.wrapS=b.RepeatWrapping,i.wrapT=b.RepeatWrapping,i.needsUpdate=!0,this.textures.set(s,i),i}updateMaterial(s,n){const i=this.materials.get(s);i&&(i instanceof b.MeshStandardMaterial?(n.color&&i.color.set(n.color),n.roughness!==void 0&&(i.roughness=n.roughness),n.metalness!==void 0&&(i.metalness=n.metalness),n.opacity!==void 0&&(i.opacity=n.opacity),i.needsUpdate=!0):i instanceof b.MeshToonMaterial&&(n.color&&i.color.set(n.color),n.opacity!==void 0&&(i.opacity=n.opacity),i.needsUpdate=!0))}dispose(){this.materials.forEach(s=>s.dispose()),this.materials.clear(),this.textures.forEach(s=>s.dispose()),this.textures.clear()}}Ut([re.HandleError(),re.Profile()],Je.prototype,"getMaterial");Ut([re.HandleError(),re.Profile()],Je.prototype,"createMaterial");Ut([re.HandleError(),re.MonitorMemory(20)],Je.prototype,"loadTexture");Ut([re.HandleError(),re.Profile()],Je.prototype,"updateMaterial");Ut([re.HandleError()],Je.prototype,"dispose");const qs={id:"default-block",color:"#8b8174",material:"STANDARD",roughness:.92};function ya(e){return{width:Math.max(1,Math.round(e.size?.x??1))*S.TILE_CONSTANTS.GRID_CELL_SIZE,height:Math.max(1,Math.round(e.size?.y??1))*S.TILE_CONSTANTS.HEIGHT_STEP,depth:Math.max(1,Math.round(e.size?.z??1))*S.TILE_CONSTANTS.GRID_CELL_SIZE}}function ds(e){const{width:s,height:n,depth:i}=ya(e);return{position:[e.position.x-S.TILE_CONSTANTS.GRID_CELL_SIZE*.5+s*.5,e.position.y+n*.5,e.position.z-S.TILE_CONSTANTS.GRID_CELL_SIZE*.5+i*.5],scale:[s,n,i]}}function Zi({blocks:e,meshes:s,isEditMode:n=!1,selectedBlockId:i=null,onBlockClick:o}){const r=u.useRef(new Je),a=u.useMemo(()=>new b.Object3D,[]),l=u.useMemo(()=>new b.BoxGeometry(1,1,1),[]),c=u.useMemo(()=>new b.MeshStandardMaterial({color:"#60a5fa",transparent:!0,opacity:.16,emissive:new b.Color("#2563eb"),emissiveIntensity:.08,wireframe:!0,depthWrite:!1}),[]),d=u.useMemo(()=>new b.MeshStandardMaterial({color:"#bae6fd",transparent:!0,opacity:.28,emissive:new b.Color("#60a5fa"),emissiveIntensity:.2,wireframe:!0,depthWrite:!1}),[]),g=u.useMemo(()=>{const p=new Map;for(const f of e){const y=f.materialId??qs.id,M=p.get(y)??[];M.push(f),p.set(y,M)}const m=r.current;return Array.from(p.entries()).map(([f,y])=>({key:f,blocks:y,material:m.getMaterial(s.get(f)??{...qs,id:f})}))},[e,s]);return u.useEffect(()=>()=>{r.current.dispose(),l.dispose(),c.dispose(),d.dispose()},[c,l,d]),t.jsxs(t.Fragment,{children:[!n&&e.length>0&&t.jsx(ot.RigidBody,{type:"fixed",colliders:!1,children:e.map(p=>{const m=ds(p);return t.jsx(ot.CuboidCollider,{position:m.position,args:[m.scale[0]*.5,m.scale[1]*.5,m.scale[2]*.5]},p.id)})}),g.map(p=>t.jsx(Sa,{batch:p,geometry:l,dummy:a},p.key)),n&&e.map(p=>{const m=ds(p),f=p.id===i;return t.jsx("mesh",{name:`block-edit-${p.id}`,position:m.position,scale:[m.scale[0]*.82,m.scale[1]*.82,m.scale[2]*.82],geometry:l,material:f?d:c,onClick:()=>o?.(p.id)},`${p.id}-edit`)})]})}function Sa({batch:e,geometry:s,dummy:n}){const i=u.useRef(null);return u.useLayoutEffect(()=>{const o=i.current;if(o){o.count=e.blocks.length;for(let r=0;r<e.blocks.length;r+=1){const a=e.blocks[r];if(!a)continue;const l=ds(a);n.position.set(...l.position),n.scale.set(...l.scale),n.rotation.set(0,0,0),n.updateMatrix(),o.setMatrixAt(r,n.matrix)}o.instanceMatrix.needsUpdate=!0,e.blocks.length>0&&(o.computeBoundingBox(),o.computeBoundingSphere())}},[e.blocks,n]),t.jsx("instancedMesh",{ref:i,name:`block-system-${e.key}`,args:[s,e.material,Math.max(1,e.blocks.length)],castShadow:!0,receiveShadow:!0})}function Vi({size:e=S.TILE_CONSTANTS.DEFAULT_GRID_SIZE,divisions:s=e/S.TILE_CONSTANTS.GRID_CELL_SIZE,color1:n="#888888",color2:i="#444444"}){return t.jsx("gridHelper",{args:[e,s,n,i],position:[0,.01,0]})}function Ma(e,s,n,i){const o=document.createElement("canvas"),r=512,a=Math.round(r*(n/s));o.width=r,o.height=a;const l=o.getContext("2d");l.fillStyle="#0a0a0a",l.fillRect(0,0,r,a),l.strokeStyle="#333",l.lineWidth=4,l.strokeRect(2,2,r-4,a-4),l.fillStyle=i;const c=Math.floor(a*.25);l.font=`bold ${c}px monospace`,l.textAlign="center",l.textBaseline="middle";const d=e.split(`
1
+ "use strict";const t=require("react/jsx-runtime"),u=require("react"),Be=require("reactflow");;/* empty css */const At=require("./seedEvents-Dmms48tb.cjs"),Ye=require("./assetStore-BuE4mh1C.cjs"),st=require("./index-CwttQ-l-.cjs"),re=require("./gaesupStore-BoN_06sX.cjs"),S=require("./PhysicsEntity-BpoArh5L.cjs"),pt=require("./index-DCa_lUwq.cjs"),rt=require("zustand"),dn=require("zustand/react/shallow"),Ge=require("@react-three/drei"),ae=require("@react-three/fiber"),Yo=require("three"),Ot=require("./sfe-CpgzdMyB.cjs"),ot=require("@react-three/rapier"),gs=require("three-stdlib");require("reflect-metadata");const oi=require("./weatherStore-1unmwIen.cjs"),bs=require("simplex-noise"),Xo=require("./authStore-CrDnYNnL.cjs"),qo=require("immer"),Ko=require("zustand/middleware/immer");function Jo(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(s,n,i.get?i:{enumerable:!0,get:()=>e[n]})}}return s.default=e,Object.freeze(s)}const b=Jo(Yo);function je({label:e,min:s,max:n,step:i,value:o,suffix:r,onChange:a}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:"#fff"},children:[t.jsx("span",{style:{width:60,flexShrink:0,color:"rgba(255,255,255,0.7)"},children:e}),t.jsx("input",{type:"range",min:s,max:n,step:i,value:o,onChange:l=>a(Number(l.target.value)),style:{flex:1,accentColor:"#0078d4"}}),t.jsxs("span",{style:{width:44,textAlign:"right",fontFamily:"monospace",fontSize:11},children:[typeof i=="number"&&i<1?o.toFixed(2):o,r??""]})]})}function Dn({label:e,checked:s,onChange:n}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:11,color:"#fff"},children:[t.jsx("input",{type:"checkbox",checked:s,onChange:i=>n(i.target.checked),style:{accentColor:"#0078d4"}}),t.jsx("span",{children:e})]})}function jt({title:e,children:s}){return t.jsxs("div",{style:{background:"rgba(0,0,0,0.2)",borderRadius:6,padding:"8px 10px",border:"1px solid rgba(255,255,255,0.08)",display:"flex",flexDirection:"column",gap:6},children:[t.jsx("div",{style:{fontSize:10,fontWeight:600,color:"rgba(255,255,255,0.5)",textTransform:"uppercase",letterSpacing:.5},children:e}),s]})}function Qo(){const e=re.useGaesupStore(a=>a.cameraOption),s=re.useGaesupStore(a=>a.setCameraOption),n=re.useGaesupStore(a=>a.mode),i=u.useCallback((a,l)=>{s({[a]:l})},[s]),o=u.useCallback((a,l)=>{s({smoothing:{...e.smoothing,[a]:l}})},[s,e.smoothing]),r=a=>e[a]??0;return t.jsxs("div",{style:{padding:10,display:"flex",flexDirection:"column",gap:10},children:[t.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.5)",marginBottom:-4},children:["Mode: ",n.control??"thirdPerson"]}),t.jsxs(jt,{title:"Distance",children:[t.jsx(je,{label:"X",min:-50,max:50,step:1,value:r("xDistance"),onChange:a=>i("xDistance",a)}),t.jsx(je,{label:"Y",min:0,max:50,step:1,value:r("yDistance"),onChange:a=>i("yDistance",a)}),t.jsx(je,{label:"Z",min:-50,max:50,step:1,value:r("zDistance"),onChange:a=>i("zDistance",a)})]}),t.jsxs(jt,{title:"FOV / Smoothing",children:[t.jsx(je,{label:"FOV",min:30,max:120,step:5,value:e.fov??75,suffix:"deg",onChange:a=>i("fov",a)}),t.jsx(je,{label:"Pos",min:.01,max:1,step:.01,value:e.smoothing?.position??.1,onChange:a=>o("position",a)}),t.jsx(je,{label:"Rot",min:.01,max:1,step:.01,value:e.smoothing?.rotation??.1,onChange:a=>o("rotation",a)}),t.jsx(je,{label:"FOV Sm",min:.01,max:1,step:.01,value:e.smoothing?.fov??.2,onChange:a=>o("fov",a)})]}),t.jsxs(jt,{title:"Zoom",children:[t.jsx(Dn,{label:"Enable Zoom",checked:e.enableZoom??!1,onChange:a=>i("enableZoom",a)}),t.jsx(je,{label:"Speed",min:1e-4,max:.01,step:1e-4,value:e.zoomSpeed??.001,onChange:a=>i("zoomSpeed",a)}),t.jsx(je,{label:"Min",min:.1,max:2,step:.1,value:e.minZoom??.5,onChange:a=>i("minZoom",a)}),t.jsx(je,{label:"Max",min:1,max:5,step:.1,value:e.maxZoom??2,onChange:a=>i("maxZoom",a)})]}),t.jsxs(jt,{title:"Options",children:[t.jsx(Dn,{label:"Collision",checked:e.enableCollision??!1,onChange:a=>i("enableCollision",a)}),t.jsx(Dn,{label:"Focus Mode",checked:e.enableFocus??!1,onChange:a=>i("enableFocus",a)}),t.jsx(je,{label:"Focus Dist",min:1,max:50,step:1,value:e.focusDistance??15,onChange:a=>i("focusDistance",a)}),t.jsx(je,{label:"Max Dist",min:5,max:100,step:1,value:e.maxDistance??50,onChange:a=>i("maxDistance",a)})]}),t.jsxs(jt,{title:"Bounds",children:[t.jsx(je,{label:"Min Y",min:-10,max:50,step:1,value:e.bounds?.minY??2,onChange:a=>s({bounds:{...e.bounds,minY:a}})}),t.jsx(je,{label:"Max Y",min:5,max:100,step:1,value:e.bounds?.maxY??50,onChange:a=>s({bounds:{...e.bounds,maxY:a}})})]})]})}const er=[{value:"thirdPerson",label:"Third Person"},{value:"firstPerson",label:"First Person"},{value:"chase",label:"Chase"},{value:"topDown",label:"Top Down"},{value:"isometric",label:"Isometric"},{value:"sideScroll",label:"Side-Scroller"},{value:"fixed",label:"Fixed"}];function tr(){const{mode:e,setMode:s}=re.useGaesupStore(dn.useShallow(i=>({mode:i.mode,setMode:i.setMode}))),n=e?.control||"thirdPerson";return t.jsx("div",{className:"cc-panel",children:t.jsx("div",{className:"cc-list",children:er.map(i=>t.jsx("button",{className:`cc-button ${n===i.value?"active":""}`,onClick:()=>s({control:i.value}),children:i.label},i.value))})})}const nr=[{key:"mode",label:"Mode",enabled:!0,format:"text"},{key:"position",label:"Position",enabled:!0,format:"vector3",precision:2},{key:"distance",label:"Distance",enabled:!0,format:"vector3",precision:2},{key:"fov",label:"FOV",enabled:!0,format:"angle",precision:1},{key:"velocity",label:"Velocity",enabled:!1,format:"vector3",precision:2},{key:"rotation",label:"Rotation",enabled:!1,format:"vector3",precision:2},{key:"zoom",label:"Zoom",enabled:!1,format:"number",precision:2},{key:"activeController",label:"Controller",enabled:!0,format:"text"}];function Fn(e){if(typeof e!="object"||e===null)return!1;const s=e;return typeof s.x=="number"&&typeof s.y=="number"&&typeof s.z=="number"}function ri(){const e={frameCount:0,averageFrameTime:0,lastUpdateTime:Date.now(),mode:"unknown",activeController:"unknown",distance:null,fov:0,position:null,targetPosition:null,velocity:null,rotation:null},[s,n]=u.useState(e),i=re.useGaesupStore(p=>p.mode),o=re.useGaesupStore(p=>p.cameraOption),{activeState:r}=S.useStateSystem(),a=u.useRef(e),l=u.useCallback((p,m)=>p===m?!1:Fn(p)?Fn(m)?p.x!==m.x||p.y!==m.y||p.z!==m.z:!0:typeof p!="object"||p===null?!0:JSON.stringify(p)!==JSON.stringify(m),[]),c=u.useCallback(p=>Fn(p)?{x:p.x,y:p.y,z:p.z}:null,[]),d=u.useCallback(()=>{const p=o?.xDistance!==void 0&&o?.yDistance!==void 0&&o?.zDistance!==void 0?{x:o.xDistance,y:o.yDistance,z:o.zDistance}:null,m={...a.current,mode:i?.control??"unknown",activeController:o?.mode??i?.control??"unknown",distance:p,fov:o?.fov??0,position:c(r?.position),targetPosition:c(o?.target),velocity:c(r?.velocity),rotation:c(r?.euler),lastUpdateTime:Date.now(),...o?.zoom!==void 0?{zoom:o.zoom}:{}};Object.keys(m).some(y=>l(m[y],a.current[y]))&&(a.current=m,n(m))},[i,o,r,l,c]);u.useEffect(()=>{d();const p=setInterval(d,100);return()=>{clearInterval(p)}},[d]);const g=u.useCallback((p,m=2)=>p==null?"N/A":typeof p=="object"&&p.x!==void 0?`X:${p.x.toFixed(m)} Y:${p.y.toFixed(m)} Z:${p.z.toFixed(m)}`:typeof p=="number"?p.toFixed(m):p.toString(),[]);return t.jsx("div",{className:"cd-panel",children:t.jsx("div",{className:"cd-grid",children:nr.map(p=>t.jsxs("div",{className:"cd-item",children:[t.jsx("span",{className:"cd-label",children:p.label}),t.jsx("span",{className:"cd-value",children:g(s[p.key])})]},p.key))})})}const sr=[{id:"classic",name:"Classic",description:"A traditional third-person view.",icon:"camera",config:{mode:"thirdPerson",distance:{x:0,y:8,z:10},fov:75,smoothing:{position:.1,rotation:.1,fov:.1}}},{id:"cinematic",name:"Cinematic",description:"Smooth, movie-like camera work.",icon:"camera",config:{mode:"chase",distance:{x:2,y:7,z:8},fov:60,smoothing:{position:.05,rotation:.05,fov:.05}}},{id:"action",name:"Action",description:"Responsive camera for fast gameplay.",icon:"camera",config:{mode:"thirdPerson",distance:{x:0,y:6,z:6},fov:85,smoothing:{position:.2,rotation:.2,fov:.2}}},{id:"strategy",name:"Strategy",description:"Top-down view for an overview.",icon:"camera",config:{mode:"topDown",distance:{x:0,y:20,z:0},fov:45,smoothing:{position:.1,rotation:.1,fov:.1}}},{id:"retro",name:"Retro",description:"Classic side-scroller style.",icon:"camera",config:{mode:"sideScroll",distance:{x:15,y:0,z:0},fov:75,smoothing:{position:.15,rotation:.15,fov:.15}}}];function ir(e,s){return!e||!s?!1:e.x===s.x&&e.y===s.y&&e.z===s.z}function or(e){const s=e?.xDistance,n=e?.yDistance,i=e?.zDistance;if(!(s===void 0||n===void 0||i===void 0))return{x:s,y:n,z:i}}function ai(){const[e]=u.useState(sr),s=re.useGaesupStore(c=>c.setMode),n=re.useGaesupStore(c=>c.setCameraOption),i=re.useGaesupStore(c=>c.mode),o=re.useGaesupStore(c=>c.cameraOption),[r,a]=u.useState(null),l=u.useCallback(c=>{s({control:c.config.mode}),n({xDistance:c.config.distance.x,yDistance:c.config.distance.y,zDistance:c.config.distance.z,fov:c.config.fov,smoothing:c.config.smoothing||{position:.1,rotation:.1,fov:.1}})},[s,n,o]);return u.useEffect(()=>{const c=e.find(d=>d.config.mode===i?.control&&ir(d.config.distance,or(o)));a(c?c.id:null)},[i,o,e]),t.jsx("div",{className:"cp-panel",children:t.jsx("div",{className:"cp-grid",children:e.map(c=>t.jsxs("button",{className:`cp-item ${r===c.id?"active":""}`,onClick:()=>l(c),children:[t.jsx("div",{className:"cp-name",children:c.name}),t.jsx("div",{className:"cp-description",children:c.description})]},c.id))})})}function li(){const[e,s]=u.useState("Settings"),n=()=>{switch(e){case"Settings":return t.jsx(Qo,{});case"Controller":return t.jsx(tr,{});case"Presets":return t.jsx(ai,{});case"Debug":return t.jsx(ri,{});default:return null}};return t.jsxs("div",{className:"tabbed-panel",children:[t.jsxs("div",{className:"panel-tabs",children:[t.jsx("button",{className:`panel-tab ${e==="Settings"?"active":""}`,onClick:()=>s("Settings"),children:"Settings"}),t.jsx("button",{className:`panel-tab ${e==="Controller"?"active":""}`,onClick:()=>s("Controller"),children:"Controller"}),t.jsx("button",{className:`panel-tab ${e==="Presets"?"active":""}`,onClick:()=>s("Presets"),children:"Presets"}),t.jsx("button",{className:`panel-tab ${e==="Debug"?"active":""}`,onClick:()=>s("Debug"),children:"Debug"})]}),t.jsx("div",{className:"panel-tab-content",children:n()})]})}const rr=[{value:"idle",label:"Idle"},{value:"walk",label:"Walk"},{value:"run",label:"Run"},{value:"jump",label:"Jump"},{value:"fall",label:"Fall"},{value:"dance",label:"Dance"},{value:"wave",label:"Wave"}];function ar(){const{playAnimation:e,currentType:s,currentAnimation:n}=S.useAnimationBridge(),i=o=>{e(s,o)};return t.jsx("div",{className:"ac-panel",children:t.jsx("div",{className:"ac-grid",children:rr.map(o=>t.jsx("button",{className:`ac-button ${o.value===n?"active":""}`,onClick:()=>i(o.value),title:o.label,children:o.label},o.value))})})}const lr=[{key:"currentAnimation",label:"현재 애니메이션",format:"text",enabled:!0},{key:"animationType",label:"애니메이션 타입",format:"text",enabled:!0},{key:"isPlaying",label:"재생 상태",format:"text",enabled:!0},{key:"weight",label:"가중치",format:"number",enabled:!0},{key:"speed",label:"속도",format:"number",enabled:!0},{key:"blendDuration",label:"블렌드 시간",format:"number",enabled:!1},{key:"activeActions",label:"활성 액션",format:"number",enabled:!0},{key:"availableAnimations",label:"사용 가능 애니메이션",format:"array",enabled:!1},{key:"frameCount",label:"프레임 카운트",format:"number",enabled:!1},{key:"averageFrameTime",label:"평균 프레임 시간",format:"number",enabled:!1}];function ci(){const{bridge:e,currentType:s}=S.useAnimationBridge(),[n,i]=u.useState({frameCount:0,averageFrameTime:0,lastUpdateTime:Date.now(),currentAnimation:"idle",animationType:"character",availableAnimations:[],isPlaying:!1,weight:1,speed:1,blendDuration:.3,activeActions:0});u.useEffect(()=>{if(!e)return;const a=()=>{const c=e.snapshot(s);if(!c)return;const d=e.getMetrics(s);i(g=>({...g,currentAnimation:c.currentAnimation,animationType:s,availableAnimations:c.availableAnimations,isPlaying:c.isPlaying,weight:c.weight,speed:c.speed,activeActions:c.metrics.activeAnimations,frameCount:d?.totalActions||0,averageFrameTime:d?.mixerTime||0,lastUpdateTime:Date.now()}))};return a(),e.subscribe((c,d)=>{d===s&&a()})},[e,s]);const o=(a,l,c=2)=>{if(a==null)return"N/A";switch(l){case"array":return Array.isArray(a)?`${a.length} animations`:String(a);case"boolean":return a?"Yes":"No";case"number":return typeof a=="number"?a.toFixed(c):String(a);default:return String(a)}},r=a=>{if(a in n)return n[a]};return t.jsx("div",{className:"ad-panel",children:t.jsx("div",{className:"ad-content",children:lr.filter(a=>a.enabled).map(a=>t.jsxs("div",{className:"ad-item",children:[t.jsx("span",{className:"ad-label",children:a.label}),t.jsx("span",{className:"ad-value",children:o(r(a.key),a.format)})]},a.key))})})}const cr=()=>t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M8 5v14l11-7z"})}),ur=()=>t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"})}),dr=()=>t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M6 6h2v12H6zm3.5 6l8.5 6V6z"})}),pr=()=>t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:t.jsx("path",{d:"M6 18l8.5-6L6 6v12zM16 6v12h2V6h-2z"})});function mr(){const{bridge:e,playAnimation:s,stopAnimation:n,currentType:i,currentAnimation:o}=S.useAnimationBridge(),[r,a]=u.useState(!1),[l,c]=u.useState([]),[d,g]=u.useState(30);u.useEffect(()=>{if(!e)return;const m=()=>{const y=e.snapshot(i);y&&(a(y.isPlaying),c(y.availableAnimations))};return m(),e.subscribe((y,M)=>{M===i&&m()})},[e,i]);const p=()=>{r?n(i):s(i,o)};return t.jsxs("div",{className:"ap-panel",children:[t.jsxs("div",{className:"ap-controls",children:[t.jsx("select",{className:"ap-select",value:o,onChange:m=>s(i,m.target.value),children:l.map(m=>t.jsx("option",{value:m,children:m},m))}),t.jsxs("div",{className:"ap-buttons",children:[t.jsx("button",{className:"ap-btn","aria-label":"previous animation",children:t.jsx(dr,{})}),t.jsx("button",{className:"ap-btn-primary",onClick:p,"aria-label":r?"pause":"play",children:r?t.jsx(ur,{}):t.jsx(cr,{})}),t.jsx("button",{className:"ap-btn","aria-label":"next animation",children:t.jsx(pr,{})})]})]}),t.jsxs("div",{className:"ap-timeline",children:[t.jsx("span",{className:"ap-time",children:"0:00"}),t.jsx("input",{type:"range",className:"ap-slider",min:"0",max:"100",value:d,onChange:m=>g(Number(m.target.value))}),t.jsx("span",{className:"ap-time",children:"1:30"})]})]})}function ui(){const[e,s]=u.useState("Player"),n=()=>{switch(e){case"Player":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(mr,{})});case"Controller":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(ar,{})});case"Debug":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(ci,{})});default:return null}};return t.jsxs("div",{className:"tabbed-panel",children:[t.jsxs("div",{className:"panel-tabs",children:[t.jsx("button",{className:`panel-tab ${e==="Player"?"active":""}`,onClick:()=>s("Player"),children:"Player"}),t.jsx("button",{className:`panel-tab ${e==="Controller"?"active":""}`,onClick:()=>s("Controller"),children:"Controller"}),t.jsx("button",{className:`panel-tab ${e==="Debug"?"active":""}`,onClick:()=>s("Debug"),children:"Debug"})]}),t.jsx("div",{className:"panel-tab-content",children:n()})]})}const Ls=[{id:"slow",name:"Slow",maxSpeed:5,acceleration:8},{id:"normal",name:"Normal",maxSpeed:10,acceleration:15},{id:"fast",name:"Fast",maxSpeed:20,acceleration:25},{id:"sprint",name:"Sprint",maxSpeed:35,acceleration:40}],Gs=[{id:"eco",name:"Eco",maxSpeed:15,acceleration:10},{id:"comfort",name:"Comfort",maxSpeed:25,acceleration:20},{id:"sport",name:"Sport",maxSpeed:40,acceleration:35},{id:"turbo",name:"Turbo",maxSpeed:60,acceleration:50}];function fr(e,s){const n=e??"bottom-left",i={position:"fixed",zIndex:s??1e4};return n.includes("top")&&(i.top=12),n.includes("bottom")&&(i.bottom=12),n.includes("left")&&(i.left=12),n.includes("right")&&(i.right=12),i}function di(e){const s=fr(e.position,e.zIndex),n=re.useGaesupStore(m=>m.mode),i=re.useGaesupStore(m=>m.setMode),o=re.useGaesupStore(m=>m.setPhysics),r=n?.type==="vehicle"?"vehicle":"character",a=r==="vehicle"?Gs:Ls,[l,c]=u.useState(r==="vehicle"?"comfort":"normal"),d=u.useCallback((m,f)=>{const M=(m==="vehicle"?Gs:Ls).find(_=>_.id===f);if(M){if(m==="vehicle"){o({maxSpeed:M.maxSpeed,accelRatio:M.acceleration});return}o({walkSpeed:Math.max(1,M.maxSpeed*.5),runSpeed:M.maxSpeed,accelRatio:M.acceleration})}},[o]),g=u.useCallback(m=>{c(m),d(r,m),e.onPresetChange?.(m)},[d,r,e]),p=u.useCallback(m=>{const f=m.target.value;i({type:f});const y=f==="vehicle"?"comfort":"normal";c(y),d(f,y),e.onPresetChange?.(y)},[d,i,e]);return t.jsxs("div",{className:`mc-panel ${e.compact?"compact":""}`,style:s,children:[t.jsxs("div",{className:"mc-setting-row",children:[t.jsx("label",{htmlFor:"motion-type-select",className:"mc-label",children:"Motion Type"}),t.jsxs("select",{id:"motion-type-select",className:"mc-select",value:r,onChange:p,children:[t.jsx("option",{value:"character",children:"Character"}),t.jsx("option",{value:"vehicle",children:"Vehicle"})]})]}),t.jsxs("div",{className:"mc-setting-row",children:[t.jsx("label",{className:"mc-label",children:"Presets"}),t.jsx("div",{className:"mc-presets-grid",children:a.map(m=>t.jsx("button",{className:`mc-preset-btn ${m.id===l?"active":""}`,onClick:()=>g(m.id),title:`Max Speed: ${m.maxSpeed}, Accel: ${m.acceleration}`,children:m.name},m.id))})]})]})}const zs=[{key:"motionType",label:"Motion Type",type:"text"},{key:"position",label:"Position",type:"vector3"},{key:"velocity",label:"Velocity",type:"vector3"},{key:"speed",label:"Speed",type:"number"},{key:"direction",label:"Direction",type:"vector3"},{key:"isGrounded",label:"Grounded",type:"text"},{key:"isMoving",label:"Moving",type:"text"},{key:"acceleration",label:"Acceleration",type:"number"},{key:"jumpForce",label:"Jump Force",type:"number"},{key:"maxSpeed",label:"Max Speed",type:"number"},{key:"totalDistance",label:"Total Distance",type:"number"},{key:"gameState",label:"Game State",type:"text"}];function hr(e,s){const n=e??"top-right",i={position:"fixed",zIndex:s??1e4};return n.includes("top")&&(i.top=12),n.includes("bottom")&&(i.bottom=12),n.includes("left")&&(i.left=12),n.includes("right")&&(i.right=12),i}function pi(e){const s=e.embedded?{}:hr(e.position,e.zIndex),n=re.useGaesupStore(g=>g.mode),i=re.useGaesupStore(g=>g.physics),{activeState:o,gameStates:r}=S.useStateSystem(),a=e.precision??2,l=e.customFields?[...zs,...e.customFields]:zs,c=(g,p,m=2)=>{if(p==null)return"N/A";switch(g.type){case"vector3":if(Array.isArray(p)&&p.length===3){const[f,y,M]=p;return`X:${f.toFixed(m)} Y:${y.toFixed(m)} Z:${M.toFixed(m)}`}if(typeof p=="object"&&p!==null&&"x"in p&&"y"in p&&"z"in p){const f=p;return`X:${f.x.toFixed(m)} Y:${f.y.toFixed(m)} Z:${f.z.toFixed(m)}`}return String(p);case"number":return typeof p=="number"?p.toFixed(m):String(p);default:return String(p)}},d=g=>{if(g.value!==void 0)return g.value;switch(g.key){case"motionType":return n?.type??"character";case"position":return o?.position?{x:o.position.x,y:o.position.y,z:o.position.z}:{x:0,y:0,z:0};case"velocity":return o?.velocity?{x:o.velocity.x,y:o.velocity.y,z:o.velocity.z}:{x:0,y:0,z:0};case"speed":return o?.velocity?o.velocity.length():0;case"direction":return o?.direction?{x:o.direction.x,y:o.direction.y,z:o.direction.z}:{x:0,y:0,z:0};case"isGrounded":return r?.isOnTheGround?"Yes":"No";case"isMoving":return r?.isMoving?"Yes":"No";case"acceleration":return i?.accelRatio??0;case"jumpForce":return i?.jumpSpeed??0;case"maxSpeed":return n?.type==="character"?i?.runSpeed??0:i?.maxSpeed??0;case"totalDistance":return 0;case"gameState":return r?.isRiding?"riding":r?.isOnTheGround?"ground":"air";default:return null}};return t.jsx("div",{className:`md-panel ${e.compact?"compact":""} ${e.theme?`theme-${e.theme}`:""}`,style:s,children:t.jsx("div",{className:"md-content",children:l.map(g=>t.jsxs("div",{className:"md-item",children:[t.jsx("span",{className:"md-label",children:g.label}),t.jsx("span",{className:"md-value",children:c(g,d(g),a)})]},g.key))})})}function mi(){const[e,s]=u.useState("Controller"),n=()=>{switch(e){case"Controller":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(di,{})});case"Debug":return t.jsx("div",{className:"panel-content-wrapper",children:t.jsx(pi,{embedded:!0})});default:return null}};return t.jsxs("div",{className:"tabbed-panel",children:[t.jsxs("div",{className:"panel-tabs",children:[t.jsx("button",{className:`panel-tab ${e==="Controller"?"active":""}`,onClick:()=>s("Controller"),children:"Controller"}),t.jsx("button",{className:`panel-tab ${e==="Debug"?"active":""}`,onClick:()=>s("Debug"),children:"Debug"})]}),t.jsx("div",{className:"panel-tab-content",children:n()})]})}const Yt=60,Xt=({data:e,color:s,max:n,warn:i})=>{const r=e.filter(c=>isFinite(c));if(r.length<2)return null;const a=Math.max(1,n),l=r.map((c,d)=>{const g=d/(r.length-1)*100,p=40-c/a*40;return`${d===0?"M":"L"}${g.toFixed(2)},${p.toFixed(2)}`}).join(" ");return t.jsx("div",{className:"perf-chart",children:t.jsxs("svg",{width:"100%",height:40,preserveAspectRatio:"none",viewBox:"0 0 100 40",children:[i!==void 0&&t.jsx("line",{x1:"0",y1:40-i/a*40,x2:"100",y2:40-i/a*40,stroke:"#facc15",strokeWidth:"0.5",strokeDasharray:"3,3",opacity:.5}),t.jsx("path",{d:l,fill:"none",stroke:s,strokeWidth:"2",strokeLinejoin:"round",strokeLinecap:"round"})]})})},Ln=({value:e,max:s,color:n,label:i})=>{const o=s>0?Math.min(100,e/s*100):0;return t.jsxs("div",{style:{marginBottom:4},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,marginBottom:2},children:[t.jsx("span",{className:"perf-label",children:i}),t.jsx("span",{children:e.toFixed(1)})]}),t.jsx("div",{style:{height:4,background:"#1e293b",borderRadius:2,overflow:"hidden"},children:t.jsx("div",{style:{width:`${o}%`,height:"100%",background:n,borderRadius:2,transition:"width 0.3s"}})})]})};function fi(){const e=re.useGaesupStore(dn.useShallow(P=>P.performance)),[s,n]=u.useState({current:0,min:1/0,max:0,avg:0,p1Low:0,history:Array(Yt).fill(0)}),[i,o]=u.useState({used:0,limit:0,history:Array(Yt).fill(0)}),[r,a]=u.useState(0),[l,c]=u.useState(Array(Yt).fill(0)),[d,g]=u.useState(Array(Yt).fill(0)),p=u.useRef(0),m=u.useRef(0),f=u.useRef(0),y=u.useRef([]),M=u.useRef(0),_=u.useRef(null),j=u.useRef(0),A=u.useRef(0),w=u.useRef(0),x=u.useCallback(P=>{if(P.length<5)return 0;const G=[...P].filter(h=>h>0).sort((h,k)=>h-k),z=Math.max(1,Math.floor(G.length*.01));let L=0;for(let h=0;h<z;h++)L+=G[h]??0;return L/z},[]);u.useEffect(()=>{const P=window.performance.now();p.current=P,m.current=P,M.current=P;const G=z=>{const L=z-m.current;if(m.current=z,y.current.push(L),y.current.length>300&&y.current.shift(),j.current+=L,A.current++,A.current>=10){const h=j.current/A.current;a(h),g(k=>[...k.slice(1),h]),j.current=0,A.current=0}if(f.current++,z-p.current>=500){const h=f.current*1e3/(z-p.current),k=y.current.map(Z=>Z>0?1e3/Z:0),U=z-M.current>3e3;n(Z=>{const Y=[...Z.history.slice(1),h],$=U?Math.min(Z.min===1/0?h:Z.min,h):1/0,J=U?Math.max(Z.max,h):0,ee=U?Y.filter(Q=>Q>0):[],te=ee.length>0?ee.reduce((Q,se)=>Q+se,0)/ee.length:h,X=U?x(k):h;return{current:h,min:$,max:J,avg:te,p1Low:X,history:Y}});const W=window.performance.memory;W&&o(Z=>{const Y=Math.round(W.usedJSHeapSize/1048576),$=Math.round(W.jsHeapSizeLimit/1048576);return{used:Y,limit:$,history:[...Z.history.slice(1),Y]}}),p.current=z,f.current=0}_.current=requestAnimationFrame(G)};return _.current=requestAnimationFrame(G),()=>{_.current&&cancelAnimationFrame(_.current)}},[x]),u.useEffect(()=>{const P=e.render.calls;P!==w.current&&(w.current=P,c(G=>[...G.slice(1),P]))},[e.render.calls]);const T=P=>P>=55?"#4ade80":P>=30?"#facc15":"#f87171",C=P=>P<=16.7?"#4ade80":P<=33.3?"#facc15":"#f87171",B=P=>P<=100?"#4ade80":P<=300?"#facc15":"#f87171",I=(P,G)=>{const z=G>0?P/G*100:0;return z<60?"#4ade80":z<80?"#facc15":"#f87171"},F=e.render.triangles,R=e.render.calls,D=e.engine.geometries,E=e.engine.textures;return t.jsxs("div",{className:"perf-panel",children:[t.jsxs("div",{className:"perf-stat-group",children:[t.jsxs("div",{className:"perf-header",children:[t.jsx("h4",{className:"perf-title",children:"Frame Rate"}),t.jsxs("span",{className:"perf-current",style:{color:T(s.current)},children:[s.current.toFixed(0)," FPS"]})]}),t.jsxs("div",{className:"perf-details-grid",children:[t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Avg"}),s.avg.toFixed(1)]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Min"}),isFinite(s.min)?s.min.toFixed(1):"..."]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Max"}),s.max.toFixed(1)]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"1% Low"}),t.jsx("span",{style:{color:T(s.p1Low)},children:s.p1Low.toFixed(1)})]})]}),t.jsx(Xt,{data:s.history,color:T(s.current),max:90,warn:60})]}),t.jsxs("div",{className:"perf-stat-group",children:[t.jsxs("div",{className:"perf-header",children:[t.jsx("h4",{className:"perf-title",children:"Frame Time"}),t.jsxs("span",{className:"perf-current",style:{color:C(r)},children:[r.toFixed(2)," ms"]})]}),t.jsx(Ln,{value:r,max:33.3,color:C(r),label:"Budget (16.7ms)"}),t.jsx(Xt,{data:d,color:C(r),max:33.3,warn:16.7})]}),t.jsxs("div",{className:"perf-stat-group",children:[t.jsxs("div",{className:"perf-header",children:[t.jsx("h4",{className:"perf-title",children:"GPU Pipeline"}),t.jsxs("span",{className:"perf-current",style:{color:B(R)},children:[R," calls"]})]}),t.jsxs("div",{className:"perf-details-grid",children:[t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Triangles"}),F>=1e6?(F/1e6).toFixed(2)+"M":F>=1e3?(F/1e3).toFixed(1)+"K":F]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Draw Calls"}),t.jsx("span",{style:{color:B(R)},children:R})]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Tri/Call"}),R>0?Math.round(F/R):0]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Points"}),e.render.points]})]}),t.jsx(Xt,{data:l,color:B(R),max:Math.max(200,...l)})]}),t.jsxs("div",{className:"perf-stat-group",children:[t.jsx("div",{className:"perf-header",children:t.jsx("h4",{className:"perf-title",children:"Resources"})}),t.jsxs("div",{className:"perf-details-grid",children:[t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Geometries"}),D]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Textures"}),E]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Programs"}),e.engine.programs]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Lines"}),e.render.lines]})]}),t.jsx(Ln,{value:D,max:200,color:D>150?"#f87171":"#4ade80",label:"Geometry Budget"}),t.jsx(Ln,{value:E,max:100,color:E>80?"#f87171":"#4ade80",label:"Texture Budget"})]}),t.jsxs("div",{className:"perf-stat-group",children:[t.jsxs("div",{className:"perf-header",children:[t.jsx("h4",{className:"perf-title",children:"Memory"}),t.jsxs("span",{className:"perf-current",style:{color:I(i.used,i.limit)},children:[i.used," MB"]})]}),t.jsxs("div",{className:"perf-details-grid",children:[t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Limit"}),i.limit," MB"]}),t.jsxs("div",{children:[t.jsx("span",{className:"perf-label",children:"Usage"}),i.limit>0?(i.used/i.limit*100).toFixed(0):0,"%"]})]}),t.jsx(Xt,{data:i.history,color:I(i.used,i.limit),max:i.limit||1})]})]})}const hi=()=>{const e=re.useGaesupStore(o=>o.mode),s=re.useGaesupStore(o=>o.setMode),n=o=>{s({type:o,controller:"keyboard",control:o==="airplane"||o==="vehicle"?"chase":"thirdPerson"})},i=[{type:"character",label:"Character",description:"Walk around as character"},{type:"vehicle",label:"Vehicle",description:"Drive a ground vehicle"},{type:"airplane",label:"Airplane",description:"Fly an airplane"}];return t.jsxs("div",{className:"vehicle-panel",children:[t.jsx("div",{className:"vehicle-panel__modes",children:i.map(o=>t.jsxs("button",{className:`vehicle-panel__mode-button ${e.type===o.type?"vehicle-panel__mode-button--active":""}`,onClick:()=>n(o.type),children:[t.jsx("span",{className:"vehicle-panel__mode-label",children:o.label}),t.jsx("span",{className:"vehicle-panel__mode-description",children:o.description})]},o.type))}),t.jsxs("div",{className:"vehicle-panel__info",children:[t.jsxs("div",{className:"vehicle-panel__info-item",children:[t.jsx("span",{className:"vehicle-panel__info-label",children:"Current Mode:"}),t.jsx("span",{className:"vehicle-panel__info-value",children:e.type})]}),t.jsxs("div",{className:"vehicle-panel__info-item",children:[t.jsx("span",{className:"vehicle-panel__info-label",children:"Controls:"}),t.jsx("span",{className:"vehicle-panel__info-value",children:e.type==="airplane"?"WASD + Space/Shift":"WASD + Space"})]})]})]})},it=[{id:"door-basic",label:"Door",category:"structure",fallbackKind:"door",defaultScale:1,defaultColor:"#8b5a2b",modelUrl:"gltf/props/door.glb"},{id:"window-basic",label:"Window",category:"structure",fallbackKind:"window",defaultScale:1,defaultColor:"#9fd3ff",modelUrl:"gltf/props/window.glb"},{id:"fence-basic",label:"Fence",category:"structure",fallbackKind:"fence",defaultScale:1,defaultColor:"#8f6a3d",modelUrl:"gltf/props/fence.glb"},{id:"lamp-basic",label:"Lamp",category:"utility",fallbackKind:"lamp",defaultScale:1,defaultColor:"#ffd166",modelUrl:"gltf/props/lamp.glb"},{id:"chair-basic",label:"Chair",category:"furniture",fallbackKind:"chair",defaultScale:1,defaultColor:"#a6784f",modelUrl:"gltf/props/chair.glb"},{id:"table-basic",label:"Table",category:"furniture",fallbackKind:"table",defaultScale:1,defaultColor:"#9b6b43",modelUrl:"gltf/props/table.glb"},{id:"bed-basic",label:"Bed",category:"furniture",fallbackKind:"bed",defaultScale:1,defaultColor:"#7aa2ff",modelUrl:"gltf/props/bed.glb"},{id:"storage-basic",label:"Storage",category:"furniture",fallbackKind:"storage",defaultScale:1,defaultColor:"#7c5c3e",modelUrl:"gltf/props/storage.glb"},{id:"mailbox-basic",label:"Mailbox",category:"utility",fallbackKind:"mailbox",defaultScale:1,defaultColor:"#d04f45",modelUrl:"gltf/props/mailbox.glb"},{id:"crafting-basic",label:"Crafting Station",category:"utility",fallbackKind:"crafting",defaultScale:1,defaultColor:"#b68553",modelUrl:"gltf/props/crafting.glb"},{id:"shop-stall-basic",label:"Shop Stall",category:"shop",fallbackKind:"shop",defaultScale:1,defaultColor:"#d88f45",modelUrl:"gltf/props/shop-stall.glb"}];function Dt(e){return it.find(s=>s.id===e)}const gr=Object.entries(S.FLAG_STYLE_META),br=[{value:"#00ff88",label:"초록"},{value:"#00aaff",label:"파랑"},{value:"#f59e0b",label:"앰버"},{value:"#ffffff",label:"흰색"},{value:"#ffdd00",label:"노랑"}],xr=e=>e.kind==="material"||e.kind==="wall"||e.kind==="tile";function Gn(e){return`${e}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function Os(e,s,n){const{mapTextureUrl:i,textureUrl:o,materialParams:r,...a}=n??{};return{...a,id:e,color:s,material:"STANDARD",materialParams:{...r??{},color:s}}}const vr=()=>{const e=S.useBuildingStore(v=>v.editMode),s=S.useBuildingStore(v=>v.setEditMode),n=S.useBuildingStore(v=>v.selectedWallId),i=S.useBuildingStore(v=>v.selectedTileId),o=S.useBuildingStore(v=>v.selectedBlockId),r=S.useBuildingStore(v=>v.selectedWallGroupId),a=S.useBuildingStore(v=>v.currentTileMultiplier),l=S.useBuildingStore(v=>v.setTileMultiplier),c=S.useBuildingStore(v=>v.currentTileHeight),d=S.useBuildingStore(v=>v.setTileHeight),g=S.useBuildingStore(v=>v.currentTileShape),p=S.useBuildingStore(v=>v.setTileShape),m=S.useBuildingStore(v=>v.currentTileRotation),f=S.useBuildingStore(v=>v.setTileRotation),y=S.useBuildingStore(v=>v.currentTileMaterialId),M=S.useBuildingStore(v=>v.setCurrentTileMaterialId),_=S.useBuildingStore(v=>v.currentWallRotation),j=S.useBuildingStore(v=>v.setWallRotation),A=S.useBuildingStore(v=>v.selectedTileObjectType),w=S.useBuildingStore(v=>v.setSelectedTileObjectType),x=S.useBuildingStore(v=>v.currentTerrainColor),T=S.useBuildingStore(v=>v.currentTerrainAccentColor),C=S.useBuildingStore(v=>v.setTerrainColors),B=S.useBuildingStore(v=>v.selectedPlacedObjectType),I=S.useBuildingStore(v=>v.setSelectedPlacedObjectType),F=S.useBuildingStore(v=>v.selectedModelObjectId),R=S.useBuildingStore(v=>v.setSelectedModelObjectId),D=S.useBuildingStore(v=>v.currentModelUrl),E=S.useBuildingStore(v=>v.setModelUrl),P=S.useBuildingStore(v=>v.currentModelScale),G=S.useBuildingStore(v=>v.setModelScale),z=S.useBuildingStore(v=>v.currentModelColor),L=S.useBuildingStore(v=>v.setModelColor),h=S.useBuildingStore(v=>v.snapToGrid),k=S.useBuildingStore(v=>v.setSnapToGrid),U=S.useBuildingStore(v=>v.currentFlagWidth),W=S.useBuildingStore(v=>v.currentFlagHeight),Z=S.useBuildingStore(v=>v.currentFlagImageUrl),Y=S.useBuildingStore(v=>v.setFlagWidth),$=S.useBuildingStore(v=>v.setFlagHeight),J=S.useBuildingStore(v=>v.setFlagImageUrl),ee=S.useBuildingStore(v=>v.currentFlagStyle),te=S.useBuildingStore(v=>v.setFlagStyle),X=S.useBuildingStore(v=>v.currentFireIntensity),Q=S.useBuildingStore(v=>v.currentFireWidth),se=S.useBuildingStore(v=>v.currentFireHeight),q=S.useBuildingStore(v=>v.currentFireColor),ie=S.useBuildingStore(v=>v.setFireIntensity),ue=S.useBuildingStore(v=>v.setFireWidth),O=S.useBuildingStore(v=>v.setFireHeight),me=S.useBuildingStore(v=>v.setFireColor),fe=S.useBuildingStore(v=>v.currentObjectRotation),xe=S.useBuildingStore(v=>v.setObjectRotation),Me=S.useBuildingStore(v=>v.selectedTileGroupId),Ie=S.useBuildingStore(v=>v.tileGroups),le=S.useBuildingStore(v=>v.wallGroups),Qe=S.useBuildingStore(v=>v.blocks),Ae=S.useBuildingStore(v=>v.meshes),bt=S.useBuildingStore(v=>v.addMesh),Oe=S.useBuildingStore(v=>v.updateMesh),at=S.useBuildingStore(v=>v.updateWall),Ce=S.useBuildingStore(v=>v.updateTile),He=S.useBuildingStore(v=>v.setCurrentWallMaterialId),Te=S.useBuildingStore(v=>v.removeWall),lt=S.useBuildingStore(v=>v.removeTile),In=S.useBuildingStore(v=>v.removeBlock),An=S.useBuildingStore(v=>v.currentBillboardText),Bn=S.useBuildingStore(v=>v.currentBillboardImageUrl),En=S.useBuildingStore(v=>v.currentBillboardColor),kn=S.useBuildingStore(v=>v.setBillboardText),Wt=S.useBuildingStore(v=>v.setBillboardImageUrl),xt=S.useBuildingStore(v=>v.setBillboardColor),et=S.useBuildingStore(v=>v.currentObjectPrimaryColor),Ht=S.useBuildingStore(v=>v.currentObjectSecondaryColor),Rn=S.useBuildingStore(v=>v.setObjectPrimaryColor),$t=S.useBuildingStore(v=>v.setObjectSecondaryColor),N=S.useBuildingStore(v=>v.showSnow),H=S.useBuildingStore(v=>v.setShowSnow),de=Ye.useAssetStore(v=>v.ids),ve=Ye.useAssetStore(v=>v.records),vt=u.useMemo(()=>de.map(v=>ve[v]).filter(v=>!!v).filter(xr),[de,ve]),Zt=[{type:"none",label:"없음",description:"건축 편집을 끕니다"},{type:"wall",label:"벽",description:"벽 조각을 배치합니다"},{type:"tile",label:"타일",description:"바닥 타일을 배치합니다"},{type:"block",label:"박스",description:"복셀 박스를 쌓습니다"},{type:"object",label:"오브젝트",description:"타일 위에 장식을 배치합니다"},{type:"npc",label:"NPC",description:"NPC를 배치합니다"}],yt=[{type:"none",label:"없음"},{type:"grass",label:"잔디"},{type:"sand",label:"모래"},{type:"snowfield",label:"눈밭"}],ks=[{type:"none",label:"없음"},{type:"sakura",label:"벚꽃나무"},{type:"flag",label:"깃발"},{type:"fire",label:"불"},{type:"billboard",label:"간판"},{type:"model",label:"기본 기물"}],Rs=[{type:"box",label:"박스"},{type:"stairs",label:"계단"},{type:"round",label:"원형"},{type:"ramp",label:"경사"}],Ps=[{value:0,label:"0도"},{value:Math.PI/2,label:"90도"},{value:Math.PI,label:"180도"},{value:Math.PI*1.5,label:"270도"}],Re=n?Array.from(le.values()).find(v=>v.walls.some(pe=>pe.id===n)):le.get(r??""),be=i?Array.from(Ie.values()).find(v=>v.tiles.some(pe=>pe.id===i)):Ie.get(Me??""),Pn=i?be?.tiles.find(v=>v.id===i):void 0,Ds=o?Qe.find(v=>v.id===o):void 0,Lo=Zt.find(v=>v.type===e)?.label??e,Go=yt.find(v=>v.type===A)?.label??A,zo=ks.find(v=>v.type===B)?.label??B,Oo=Rs.find(v=>v.type===g)?.label??g,St=Dt(F)??it[0],Uo=()=>{!n||!Re||Te(Re.id,n)},Wo=()=>{!i||!be||lt(be.id,i)},Ho=()=>{o&&In(o)},Vt=(v,pe,he,Pe)=>{const De=pt.createScopedBuildingMeshId(pe,he,Pe.id),ct=v?Ae.get(v):void 0,Mt=pt.createScopedAssetMeshConfig(De,Pe,ct);return Ae.has(De)?Oe(De,Mt):bt(Mt),De},$o=v=>{if(!Re)return;const he=(n?Re.walls.find(De=>De.id===n):void 0)?.materialId??Re.frontMeshId;if(n){const De=Vt(he,n,"wall",v);at(Re.id,n,{materialId:De});return}const Pe=Vt(Re.frontMeshId,Gn("placement-wall"),"wall",v);He(Pe)},Zo=v=>{if(!be)return;if(i){const he=Vt(Pn?.materialId??be.floorMeshId,i,"tile",v);Ce(be.id,i,{materialId:he});return}const pe=Vt(be.floorMeshId,Gn("placement-tile"),"tile",v);M(pe)},Vo=v=>{if(!be)return;if(i){const De=Pn?.materialId??be.floorMeshId,ct=pt.createScopedBuildingMeshId(i,"tile-color",v),Mt=Os(ct,v,Ae.get(De));Ae.has(ct)?Oe(ct,Mt):bt(Mt),Ce(be.id,i,{materialId:ct});return}const pe=y??be.floorMeshId,he=pt.createScopedBuildingMeshId(Gn("placement-tile-color"),"tile",v),Pe=Os(he,v,Ae.get(pe));bt(Pe),M(he)},Fs=(v,pe=T)=>{if(C(v,pe),!i||!be)return;const he=be.tiles.find(Pe=>Pe.id===i);!he||!he.objectType||he.objectType==="none"||he.objectType==="water"||Ce(be.id,i,{objectConfig:{...he.objectConfig??{},terrainColor:v,terrainAccentColor:pe}})};return t.jsxs("div",{className:"building-panel",children:[t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"편집 모드"}),t.jsx("div",{className:"building-panel__modes",children:Zt.map(v=>t.jsxs("button",{className:`building-panel__mode-btn ${e===v.type?"building-panel__mode-btn--active":""}`,onClick:()=>s(v.type),children:[t.jsx("span",{className:"building-panel__mode-label",children:v.label}),t.jsx("span",{className:"building-panel__mode-desc",children:v.description})]},v.type))})]}),(e==="wall"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"벽 회전 / 삭제"}),t.jsx("div",{className:"building-panel__segmented",children:Ps.map(v=>t.jsx("button",{className:`building-panel__segment-btn ${Math.abs(_-v.value)<1e-4?"building-panel__segment-btn--active":""}`,onClick:()=>j(v.value),children:v.label},v.value))}),t.jsxs("div",{className:"building-panel__delete-card",children:[t.jsxs("div",{children:[t.jsx("strong",{children:"선택한 벽"}),t.jsx("span",{children:n?`ID: ${n}`:"벽 마커를 클릭해 선택하세요"})]}),t.jsx("button",{className:"building-panel__delete-button",disabled:!n||!Re,onClick:Uo,children:"선택 벽 삭제"})]})]}),(e==="wall"||e==="tile"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"에셋 재질"}),t.jsxs("div",{className:"building-panel__asset-targets",children:[t.jsxs("span",{children:["벽: ",Re?.name??"선택 없음"]}),t.jsxs("span",{children:["타일: ",i?`선택 타일 ${i}`:"다음 생성 타일"]}),t.jsxs("span",{children:["현재 생성 재질: ",y??be?.floorMeshId??"기본값"]})]}),t.jsxs("div",{className:"building-panel__asset-list",children:[vt.map(v=>t.jsxs("div",{className:"building-panel__asset-card",children:[t.jsx(pt.AssetPreviewCanvas,{asset:v,size:54}),t.jsxs("div",{className:"building-panel__asset-info",children:[t.jsx("strong",{children:v.name}),t.jsx("span",{children:v.kind})]}),t.jsxs("div",{className:"building-panel__asset-actions",children:[t.jsx("button",{className:"building-panel__asset-action",disabled:!Re,onClick:()=>$o(v),children:"벽"}),t.jsx("button",{className:"building-panel__asset-action",disabled:!be,onClick:()=>Zo(v),children:"타일"})]})]},v.id)),vt.length===0&&t.jsx("div",{className:"building-panel__empty",children:"사용 가능한 빌딩 에셋이 없습니다."})]})]}),(e==="tile"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"지형 덮개"}),t.jsx("div",{className:"building-panel__grid",children:yt.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${A===v.type?"building-panel__grid-btn--active":""}`,onClick:()=>w(v.type),children:v.label},v.type))}),t.jsxs("div",{className:"building-panel__terrain-colors",children:[t.jsxs("label",{children:[t.jsx("span",{children:"기본색"}),t.jsx("input",{type:"color",value:x,onChange:v=>Fs(v.target.value)})]}),t.jsxs("label",{children:[t.jsx("span",{children:"강조색"}),t.jsx("input",{type:"color",value:T,onChange:v=>Fs(x,v.target.value)})]})]})]}),(e==="object"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"배치 오브젝트"}),t.jsx("div",{className:"building-panel__grid",children:ks.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${B===v.type?"building-panel__grid-btn--active":""}`,onClick:()=>{I(v.type),v.type==="model"&&St&&(G(St.defaultScale),L(St.defaultColor),E(St.modelUrl??""))},children:v.label},v.type))})]}),e==="object"&&B==="model"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"기본 기물 GLB"}),t.jsx("div",{className:"building-panel__grid",children:it.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${F===v.id?"building-panel__grid-btn--active":""}`,onClick:()=>{R(v.id),G(v.defaultScale),L(v.defaultColor),E(v.modelUrl??"")},children:v.label},v.id))}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("label",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"GLB URL"}),t.jsx("input",{type:"text",value:D,onChange:v=>E(v.target.value),placeholder:"gltf/props/door.glb",className:"building-panel__text-input"})]}),t.jsxs("label",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"스케일"}),t.jsx("input",{type:"number",min:"0.1",max:"10",step:"0.1",value:P,onChange:v=>G(Number(v.target.value)||1),className:"building-panel__number-input"})]}),t.jsxs("label",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"색상"}),t.jsx("input",{type:"color",value:z,onChange:v=>L(v.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:z})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"Fallback"}),t.jsx("span",{className:"building-panel__info-value",children:St?.fallbackKind??"generic"})]})]})]}),t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"타일 설정"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"크기"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>l(Math.max(1,a-1)),children:"-"}),t.jsx("span",{className:"building-panel__stepper-value",children:a}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>l(Math.min(4,a+1)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"격자 맞춤"}),t.jsx("button",{className:`building-panel__toggle ${h?"building-panel__toggle--on":""}`,onClick:()=>k(!h),children:h?"ON":"OFF"})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"높이"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>d(Math.max(0,c-1)),children:"-"}),t.jsx("span",{className:"building-panel__stepper-value",children:c}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>d(Math.min(6,c+1)),children:"+"})]})]})]}),t.jsx("div",{className:"building-panel__section-subtitle",children:"타일 형태"}),t.jsx("div",{className:"building-panel__grid",children:Rs.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${g===v.type?"building-panel__grid-btn--active":""}`,onClick:()=>p(v.type),children:v.label},v.type))}),t.jsx("div",{className:"building-panel__section-subtitle",children:"타일 회전"}),t.jsx("div",{className:"building-panel__segmented",children:Ps.map(v=>t.jsx("button",{className:`building-panel__segment-btn ${Math.abs(m-v.value)<1e-4?"building-panel__segment-btn--active":""}`,onClick:()=>f(v.value),children:v.label},v.value))}),t.jsxs("div",{className:"building-panel__delete-card",children:[t.jsxs("div",{children:[t.jsx("strong",{children:"선택한 타일"}),t.jsx("span",{children:i?`ID: ${i}`:"타일 하이라이트를 클릭해 선택하세요"})]}),t.jsx("button",{className:"building-panel__delete-button",disabled:!i||!be,onClick:Wo,children:"선택 타일 삭제"})]})]}),(e==="block"||e==="none")&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"박스 편집"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"박스 크기"}),t.jsxs("span",{className:"building-panel__info-value",children:[a," x ",a]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"쌓기 높이"}),t.jsx("span",{className:"building-panel__info-value",children:c})]})]}),t.jsxs("div",{className:"building-panel__delete-card",children:[t.jsxs("div",{children:[t.jsx("strong",{children:"선택한 박스"}),t.jsx("span",{children:Ds?`ID: ${Ds.id}`:"박스 하이라이트를 클릭해 선택하세요"})]}),t.jsx("button",{className:"building-panel__delete-button",disabled:!o,onClick:Ho,children:"선택 박스 삭제"})]})]}),e==="tile"&&Me&&(()=>{const v=Ie.get(Me),pe=Pn?.materialId??y??v?.floorMeshId,he=pe?Ae.get(pe):void 0;return he?t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"타일 색상"}),t.jsx("div",{className:"building-panel__info",children:t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"색상"}),t.jsx("input",{type:"color",value:he.color||"#888888",onChange:Pe=>Vo(Pe.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:he.color||"#888888"})]})})]}):null})(),t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"효과"}),t.jsx("div",{className:"building-panel__info",children:t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"눈"}),t.jsx("button",{className:`building-panel__toggle ${N?"building-panel__toggle--on":""}`,onClick:()=>H(!N),children:N?"ON":"OFF"})]})})]}),e==="object"&&B!=="none"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"오브젝트 회전"}),t.jsx("div",{className:"building-panel__grid",children:[0,Math.PI/4,Math.PI/2,Math.PI*.75,Math.PI,Math.PI*1.25,Math.PI*1.5,Math.PI*1.75].map((v,pe)=>t.jsx("button",{className:`building-panel__grid-btn ${Math.abs(fe-v)<.01?"building-panel__grid-btn--active":""}`,onClick:()=>xe(v),children:pe*45},v))})]}),e==="object"&&B==="sakura"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"벚꽃나무 색상"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"꽃잎"}),t.jsx("input",{type:"color",value:et,onChange:v=>Rn(v.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:et})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"나무껍질"}),t.jsx("input",{type:"color",value:Ht,onChange:v=>$t(v.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:Ht})]})]})]}),B==="fire"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"불 설정"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"강도"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>ie(Math.max(.5,X-.5)),children:"-"}),t.jsx("span",{className:"building-panel__stepper-value",children:X.toFixed(1)}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>ie(Math.min(3,X+.5)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"너비"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>ue(Math.max(.3,Q-.2)),children:"-"}),t.jsxs("span",{className:"building-panel__stepper-value",children:[Q.toFixed(1),"m"]}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>ue(Math.min(4,Q+.2)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"높이"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>O(Math.max(.5,se-.3)),children:"-"}),t.jsxs("span",{className:"building-panel__stepper-value",children:[se.toFixed(1),"m"]}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>O(Math.min(5,se+.3)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"색상"}),t.jsx("input",{type:"color",value:q,onChange:v=>me(v.target.value),style:{width:"36px",height:"24px",border:"none",cursor:"pointer",background:"none"}}),t.jsx("span",{className:"building-panel__info-value",style:{fontSize:"10px"},children:q})]})]})]}),B==="billboard"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"간판 설정"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"문구"}),t.jsx("input",{type:"text",value:An,onChange:v=>kn(v.target.value),placeholder:"표시할 문구...",style:{width:"100%",padding:"4px 6px",fontSize:"11px",background:"var(--panel-bg, #1a1a2e)",border:"1px solid var(--border-color, #333)",borderRadius:"3px",color:"inherit",boxSizing:"border-box"}})]}),t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"이미지 URL"}),t.jsx("input",{type:"text",value:Bn,onChange:v=>Wt(v.target.value),placeholder:"https://...",style:{width:"100%",padding:"4px 6px",fontSize:"11px",background:"var(--panel-bg, #1a1a2e)",border:"1px solid var(--border-color, #333)",borderRadius:"3px",color:"inherit",boxSizing:"border-box"}})]}),t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"색상"}),t.jsx("div",{className:"building-panel__grid",children:br.map(v=>t.jsx("button",{className:`building-panel__grid-btn ${En===v.value?"building-panel__grid-btn--active":""}`,onClick:()=>xt(v.value),style:{borderBottom:`3px solid ${v.value}`},children:v.label},v.value))})]})]})]}),B==="flag"&&t.jsxs("div",{className:"building-panel__section",children:[t.jsx("div",{className:"building-panel__section-title",children:"깃발 설정"}),t.jsxs("div",{className:"building-panel__info",children:[t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"스타일"}),t.jsx("div",{className:"building-panel__grid",children:gr.map(([v,pe])=>t.jsx("button",{className:`building-panel__grid-btn ${ee===v?"building-panel__grid-btn--active":""}`,onClick:()=>te(v),children:pe.label},v))})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"너비"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>Y(Math.max(.5,U-.5)),children:"-"}),t.jsxs("span",{className:"building-panel__stepper-value",children:[U,"m"]}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>Y(Math.min(8,U+.5)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"높이"}),t.jsxs("div",{className:"building-panel__stepper",children:[t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>$(Math.max(.5,W-.5)),children:"-"}),t.jsxs("span",{className:"building-panel__stepper-value",children:[W,"m"]}),t.jsx("button",{className:"building-panel__stepper-btn",onClick:()=>$(Math.min(6,W+.5)),children:"+"})]})]}),t.jsxs("div",{className:"building-panel__info-item",style:{flexDirection:"column",alignItems:"stretch",gap:"4px"},children:[t.jsx("span",{className:"building-panel__info-label",children:"이미지 URL"}),t.jsx("input",{type:"text",value:Z,onChange:v=>J(v.target.value),placeholder:"https://...",style:{width:"100%",padding:"4px 6px",fontSize:"11px",background:"var(--panel-bg, #1a1a2e)",border:"1px solid var(--border-color, #333)",borderRadius:"3px",color:"inherit",boxSizing:"border-box"}})]})]})]}),t.jsxs("div",{className:"building-panel__info",style:{marginTop:"auto"},children:[t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"현재 모드"}),t.jsx("span",{className:"building-panel__info-value",children:Lo})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"지형 덮개"}),t.jsx("span",{className:"building-panel__info-value",children:Go})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"오브젝트"}),t.jsx("span",{className:"building-panel__info-value",children:zo})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"타일 높이"}),t.jsx("span",{className:"building-panel__info-value",children:c})]}),t.jsxs("div",{className:"building-panel__info-item",children:[t.jsx("span",{className:"building-panel__info-label",children:"타일 형태"}),t.jsx("span",{className:"building-panel__info-value",children:Oo})]})]})]})},ut={name:"플레이어",colors:{body:"#ffd9b8",hair:"#3a2a1a",hat:"#5a8acf",top:"#f0e0c8",bottom:"#3a4a6a",shoes:"#3a2a1a"},face:"default",hair:"short"},gi={hat:"모자",top:"상의",bottom:"하의",shoes:"신발",face:"표정",weapon:"무기",accessory:"액세서리"},yr={short:"단발",long:"긴머리",cap:"모자머리",bun:"쪽머리",spiky:"뻗친머리"},Sr={default:"기본",smile:"미소",wink:"윙크",sleepy:"졸림",surprised:"놀람"},zn={hat:null,top:null,bottom:null,shoes:null,face:null,weapon:null,accessory:null},an=rt.create((e,s)=>({appearance:{...ut,colors:{...ut.colors}},outfits:{...zn},setName:n=>e(i=>({appearance:{...i.appearance,name:n.slice(0,16)||"플레이어"}})),setColor:(n,i)=>e(o=>({appearance:{...o.appearance,colors:{...o.appearance.colors,[n]:i}}})),setFace:n=>e(i=>({appearance:{...i.appearance,face:n}})),setHair:n=>e(i=>({appearance:{...i.appearance,hair:n}})),equipOutfit:(n,i)=>e(o=>({outfits:{...o.outfits,[n]:i}})),resetAppearance:()=>e({appearance:{...ut,colors:{...ut.colors}},outfits:{...zn}}),getEquippedAssetIds:()=>Object.values(s().outfits).filter(n=>typeof n=="string"&&n.length>0),serialize:()=>{const n=s();return{version:2,appearance:{...n.appearance,colors:{...n.appearance.colors}},outfits:{...n.outfits}}},hydrate:n=>{!n||n.version!==1&&n.version!==2||e({appearance:{...ut,...n.appearance,colors:{...ut.colors,...n.appearance.colors}},outfits:{...zn,...n.outfits}})}})),Mr=["hat","top","bottom","shoes","face","weapon","accessory"],jr=(e,s)=>s==="weapon"?e.kind==="weapon"||e.slot==="weapon":e.slot===s&&(e.kind==="characterPart"||e.kind==="weapon"),wr=()=>{const e=an(y=>y.outfits),s=an(y=>y.equipOutfit),n=an(y=>y.resetAppearance),i=Ye.useAssetStore(y=>y.ids),o=Ye.useAssetStore(y=>y.records),r=Ye.useAssetStore(y=>y.isLoading),a=Ye.useAssetStore(y=>y.error),[l,c]=u.useState("top"),[d,g]=u.useState(""),[p,m]=u.useState(!1),f=u.useMemo(()=>{const y=d.trim().toLowerCase();return i.map(M=>o[M]).filter(M=>!!M).filter(M=>jr(M,l)).filter(M=>y?M.tags?.some(_=>_.toLowerCase().includes(y))??!1:!0).filter(M=>!p||M.metadata?.owned!==!1)},[i,o,p,l,d]);return t.jsxs("div",{className:"character-asset-panel",children:[t.jsxs("section",{className:"character-asset-panel__section",children:[t.jsxs("div",{className:"character-asset-panel__header",children:[t.jsx("span",{className:"character-asset-panel__section-title",children:"캐릭터 에셋"}),t.jsx("button",{className:"character-asset-panel__ghost-btn",onClick:n,type:"button",children:"초기화"})]}),t.jsx("div",{className:"character-asset-panel__slot-grid",children:Mr.map(y=>t.jsxs("button",{type:"button",className:`character-asset-panel__slot-btn ${l===y?"character-asset-panel__slot-btn--active":""}`,onClick:()=>c(y),children:[t.jsx("span",{children:gi[y]}),t.jsx("small",{children:e[y]??"비어있음"})]},y))})]}),t.jsxs("section",{className:"character-asset-panel__section",children:[t.jsxs("div",{className:"character-asset-panel__filters",children:[t.jsx("input",{value:d,onChange:y=>g(y.target.value),placeholder:"태그 검색",className:"character-asset-panel__input"}),t.jsxs("label",{className:"character-asset-panel__check",children:[t.jsx("input",{type:"checkbox",checked:p,onChange:y=>m(y.target.checked)}),"보유만"]})]}),a&&t.jsx("p",{className:"character-asset-panel__notice",children:a}),r&&t.jsx("p",{className:"character-asset-panel__notice",children:"에셋 로딩 중"}),t.jsxs("div",{className:"character-asset-panel__asset-list",children:[t.jsxs("button",{type:"button",className:`character-asset-panel__asset-card ${e[l]===null?"character-asset-panel__asset-card--active":""}`,onClick:()=>s(l,null),children:[t.jsx("div",{className:"character-asset-panel__empty-preview"}),t.jsx("span",{children:"비우기"})]}),f.map(y=>t.jsxs("button",{type:"button",className:`character-asset-panel__asset-card ${e[l]===y.id?"character-asset-panel__asset-card--active":""}`,onClick:()=>s(l,y.id),children:[t.jsx(pt.AssetPreviewCanvas,{asset:y,size:58}),t.jsx("span",{children:y.name})]},y.id)),f.length===0&&t.jsx("p",{className:"character-asset-panel__notice",children:"선택한 슬롯에 사용할 에셋이 없습니다."})]})]})]})},_r=e=>{const s=e.trigger;switch(s.type){case"manual":return{type:"manual",key:s.key};case"interaction":return{type:"interaction",targetId:s.targetId,...s.action?{action:s.action}:{}};case"enterArea":return{type:"enterArea",areaId:s.areaId};case"itemCollected":return{type:"itemCollected",itemId:s.itemId};case"timeChanged":return{type:"timeChanged",...s.hour!==void 0?{hour:s.hour}:{}};case"calendarEventStarted":return{type:"calendarEventStarted",eventId:s.eventId};case"questChanged":return{type:"questChanged",questId:s.questId,...s.status?{status:s.status}:{}};case"custom":return{type:"custom",key:s.key};default:return s}},Cr=({data:e,id:s})=>{const[n,i]=u.useState(null),[o,r]=u.useState(""),a=l=>{e.onEdit?.(s,l,ln(o)),i(null)};return t.jsxs("div",{className:"gameplay-event-node",children:[t.jsx(Be.Handle,{type:"target",position:Be.Position.Top,className:"gameplay-event-node__handle"}),t.jsxs("div",{className:"gameplay-event-node__header",children:[t.jsx("span",{children:e.title}),s!=="root"&&s!=="trigger"&&s!=="policy"&&t.jsx("button",{type:"button",className:"gameplay-event-node__delete",onClick:()=>e.onDelete?.(s),children:"Delete"})]}),e.fields&&Object.entries(e.fields).map(([l,c])=>t.jsx("div",{className:"gameplay-event-node__field",children:n===l?t.jsxs("div",{className:"gameplay-event-node__edit",children:[t.jsx("input",{value:o,onChange:d=>r(d.target.value),onKeyDown:d=>{d.key==="Enter"&&a(l),d.key==="Escape"&&i(null)},autoFocus:!0}),t.jsx("button",{type:"button",onClick:()=>a(l),children:"Save"}),t.jsx("button",{type:"button",onClick:()=>i(null),children:"Cancel"})]}):t.jsxs("button",{type:"button",className:"gameplay-event-node__value",onClick:()=>{l!=="type"&&(i(l),r(String(c)))},children:[t.jsx("span",{children:l}),t.jsx("strong",{children:String(c)})]})},l)),t.jsx(Be.Handle,{type:"source",position:Be.Position.Bottom,className:"gameplay-event-node__handle"})]})},Tr=e=>{switch(e){case"manual":return{type:e,key:"custom.run"};case"interaction":return{type:e,targetId:"npc:tommy",action:"talk"};case"enterArea":return{type:e,areaId:"meadow"};case"itemCollected":return{type:e,itemId:"apple"};case"timeChanged":return{type:e,hour:9};case"calendarEventStarted":return{type:e,eventId:"event.cherryblossom"};case"questChanged":return{type:e,questId:"welcome",status:"active"};case"custom":return{type:e,key:"custom.event"};default:return e}},Nr=e=>{switch(e){case"always":return{type:e};case"hasItem":return{type:e,itemId:"apple",count:1};case"questStatus":return{type:e,questId:"welcome",status:"active"};case"eventActive":return{type:e,eventId:"event.cherryblossom"};case"flagEquals":return{type:e,key:"gameplayReady",value:!0};case"custom":return{type:e,key:"custom.condition"};default:return e}},Ir=e=>{switch(e){case"giveItem":return{type:e,itemId:"apple",count:1};case"removeItem":return{type:e,itemId:"apple",count:1};case"startQuest":return{type:e,questId:"welcome"};case"completeQuest":return{type:e,questId:"welcome"};case"showDialog":return{type:e,dialogTreeId:"npc.villager",npcId:"mei"};case"toast":return{type:e,kind:"success",text:"이벤트 실행"};case"setFlag":return{type:e,key:"customFlag",value:!0};case"notifyQuestFlag":return{type:e,key:"customFlag",value:!0};case"emit":return{type:e,eventName:"gameplay.custom"};case"custom":return{type:e,key:"custom.action"};default:return e}},ln=e=>{if(e==="true")return!0;if(e==="false")return!1;const s=Number(e);return Number.isFinite(s)&&e.trim()!==""?s:e},Ar=e=>Array.isArray(e)||typeof e=="object"&&e!==null?JSON.stringify(e):e,qt={stroke:"#7a86a8",strokeWidth:2},Kt={type:Be.MarkerType.ArrowClosed,color:"#7a86a8",width:20,height:20},Br={editable:Cr},Er=(e,s,n)=>{const i=[{id:"root",type:"editable",position:{x:260,y:20},data:{title:e.name,fields:{id:e.id,name:e.name,description:e.description??""},onEdit:s,onDelete:n}},{id:"trigger",type:"editable",position:{x:260,y:180},data:{title:`Trigger: ${e.trigger.type}`,fields:{...e.trigger},onEdit:s,onDelete:n}},{id:"policy",type:"editable",position:{x:560,y:180},data:{title:"Policy",fields:{run:e.policy?.run??"repeat",cooldownMs:e.policy?.cooldownMs??0,requiresServer:e.policy?.requiresServer??!1},onEdit:s,onDelete:n}}],o=[{id:"root-trigger",source:"root",target:"trigger",style:qt,markerEnd:Kt},{id:"root-policy",source:"root",target:"policy",style:qt,markerEnd:Kt}];return(e.conditions??[]).forEach((r,a)=>{const l=`condition:${a}`;i.push({id:l,type:"editable",position:{x:40,y:360+a*150},data:{title:`Condition: ${r.type}`,fields:{...r},onEdit:s,onDelete:n}}),o.push({id:`trigger-${l}`,source:"trigger",target:l,style:qt,markerEnd:Kt})}),e.actions.forEach((r,a)=>{const l=`action:${a}`;i.push({id:l,type:"editable",position:{x:420,y:360+a*150},data:{title:`Action: ${r.type}`,fields:{...r},onEdit:s,onDelete:n}}),o.push({id:`${a===0?"trigger":`action:${a-1}`}-${l}`,source:a===0?"trigger":`action:${a-1}`,target:l,style:qt,markerEnd:Kt})}),{nodes:i,edges:o}};function kr({blueprints:e,onCreate:s,onUpdate:n,onDelete:i,onRun:o}){const r=u.useMemo(()=>new At.GameplayEventEngine({blueprints:e}),[e]),[a,l]=u.useState("custom-toast"),[c,d]=u.useState("Custom Toast Event"),[g,p]=u.useState("custom.run"),[m,f]=u.useState("커스텀 이벤트 실행"),[y,M]=u.useState(e[0]?.id??null),_=u.useMemo(()=>e.find(h=>h.id===y)??e[0]??null,[e,y]),[j,A]=u.useState({kind:"idle",message:"Ready"}),[w,x,T]=Be.useNodesState([]),[C,B,I]=Be.useEdgesState([]),F=()=>{const h={id:a.trim()||`event-${Date.now()}`,name:c.trim()||"Untitled Event",trigger:{type:"manual",key:g.trim()||"custom.run"},conditions:[{type:"always"}],actions:[{type:"toast",kind:"success",text:m.trim()||"이벤트 실행"},{type:"setFlag",key:a.trim()||"customEvent",value:!0}],policy:{run:"repeat"},tags:["editor"]};s?.(h),M(h.id),A({kind:"success",message:`Created ${h.id}`})},R=u.useCallback(h=>{if(!_)return;const k={..._,...h};n?.(k),M(k.id),A({kind:"success",message:`Updated ${k.id}`})},[n,_]),D=()=>{if(!_)return;i?.(_.id);const h=e.find(k=>k.id!==_.id)??null;M(h?.id??null),A({kind:"success",message:`Deleted ${_.id}`})},E=async h=>{const k=_r(h);o?await o(k):await r.dispatch(k),A({kind:"success",message:`Ran ${h.id}`})},P=u.useCallback((h,k)=>{if(!_)return;const U=[..._.conditions??[]];U[h]=k,R({conditions:U})},[_,R]),G=u.useCallback((h,k)=>{if(!_)return;const U=[..._.actions];U[h]=k,R({actions:U})},[_,R]),z=u.useCallback((h,k,U)=>{if(!_||k==="type")return;const W=Ar(U);if(h==="root"){R({[k]:W});return}if(h==="policy"){k==="run"&&(W==="once"||W==="repeat")&&R({policy:{..._.policy,run:W}}),k==="cooldownMs"&&R({policy:{..._.policy,cooldownMs:Number(W)}}),k==="requiresServer"&&R({policy:{..._.policy,requiresServer:ln(String(W))===!0}});return}if(h==="trigger"){const Z=_.trigger;Z.type==="manual"&&k==="key"&&R({trigger:{type:"manual",key:String(W)}}),Z.type==="interaction"&&(k==="targetId"||k==="action")&&R({trigger:{...Z,[k]:String(W)}}),Z.type==="enterArea"&&k==="areaId"&&R({trigger:{type:"enterArea",areaId:String(W)}}),Z.type==="itemCollected"&&k==="itemId"&&R({trigger:{type:"itemCollected",itemId:String(W)}}),Z.type==="timeChanged"&&k==="hour"&&R({trigger:{type:"timeChanged",hour:Number(W)}}),Z.type==="calendarEventStarted"&&k==="eventId"&&R({trigger:{type:"calendarEventStarted",eventId:String(W)}}),Z.type==="questChanged"&&(k==="questId"||k==="status")&&R({trigger:{...Z,[k]:String(W)}}),Z.type==="custom"&&k==="key"&&R({trigger:{type:"custom",key:String(W)}});return}if(h.startsWith("condition:")){const Z=Number(h.split(":")[1]),Y=_.conditions?.[Z];if(!Y)return;P(Z,{...Y,[k]:k==="value"?ln(String(W)):W});return}if(h.startsWith("action:")){const Z=Number(h.split(":")[1]),Y=_.actions[Z];if(!Y)return;G(Z,{...Y,[k]:k==="value"?ln(String(W)):W})}},[_,G,P,R]),L=u.useCallback(h=>{if(_){if(h.startsWith("condition:")){const k=Number(h.split(":")[1]);R({conditions:(_.conditions??[]).filter((U,W)=>W!==k)});return}if(h.startsWith("action:")){const k=Number(h.split(":")[1]);R({actions:_.actions.filter((U,W)=>W!==k)})}}},[_,R]);return u.useEffect(()=>{if(!_){x([]),B([]);return}const h=Er(_,z,L);x(h.nodes),B(h.edges)},[L,z,_,B,x]),t.jsxs("div",{className:"gameplay-event-panel",children:[t.jsxs("section",{className:"gameplay-event-panel__section",children:[t.jsx("div",{className:"gameplay-event-panel__title",children:"Create Manual Event"}),t.jsxs("label",{className:"gameplay-event-panel__field",children:[t.jsx("span",{children:"ID"}),t.jsx("input",{value:a,onChange:h=>l(h.target.value)})]}),t.jsxs("label",{className:"gameplay-event-panel__field",children:[t.jsx("span",{children:"Name"}),t.jsx("input",{value:c,onChange:h=>d(h.target.value)})]}),t.jsxs("label",{className:"gameplay-event-panel__field",children:[t.jsx("span",{children:"Trigger Key"}),t.jsx("input",{value:g,onChange:h=>p(h.target.value)})]}),t.jsxs("label",{className:"gameplay-event-panel__field",children:[t.jsx("span",{children:"Toast Message"}),t.jsx("input",{value:m,onChange:h=>f(h.target.value)})]}),t.jsx("button",{type:"button",className:"gameplay-event-panel__primary",onClick:F,children:"Create Event Blueprint"})]}),t.jsxs("section",{className:"gameplay-event-panel__section",children:[t.jsx("div",{className:"gameplay-event-panel__title",children:"Blueprint Library"}),t.jsx("div",{className:"gameplay-event-panel__list",children:e.map(h=>t.jsxs("article",{className:"gameplay-event-panel__card",children:[t.jsxs("div",{children:[t.jsx("div",{className:"gameplay-event-panel__card-title",children:h.name}),t.jsxs("div",{className:"gameplay-event-panel__card-meta",children:[h.id," · ",h.trigger.type," · ",h.actions.length," action(s)"]})]}),t.jsxs("div",{className:"gameplay-event-panel__card-actions",children:[t.jsx("button",{type:"button",onClick:()=>M(h.id),children:"Edit"}),t.jsx("button",{type:"button",onClick:()=>{E(h)},children:"Run"})]})]},h.id))})]}),_&&t.jsxs("section",{className:"gameplay-event-panel__section gameplay-event-panel__detail",children:[t.jsxs("div",{className:"gameplay-event-panel__editor-head",children:[t.jsxs("div",{children:[t.jsx("div",{className:"gameplay-event-panel__title",children:"Blueprint Node Editor"}),t.jsx("div",{className:"gameplay-event-panel__hint",children:"노드 필드를 클릭해서 값을 수정합니다. 타입 변경은 아래 노드 추가/변경 액션에서 처리합니다."})]}),t.jsxs("label",{className:"gameplay-event-panel__type-select",children:[t.jsx("span",{children:"Trigger"}),t.jsx("select",{value:_.trigger.type,onChange:h=>R({trigger:Tr(h.target.value)}),children:["manual","interaction","enterArea","itemCollected","timeChanged","calendarEventStarted","questChanged","custom"].map(h=>t.jsx("option",{value:h,children:h},h))})]})]}),t.jsx("div",{className:"gameplay-event-panel__flow",children:t.jsxs(Be,{nodes:w,edges:C,nodeTypes:Br,onNodesChange:T,onEdgesChange:I,fitView:!0,children:[t.jsx(Be.Background,{variant:Be.BackgroundVariant.Dots,gap:18,size:1}),t.jsx(Be.Controls,{})]})}),t.jsxs("div",{className:"gameplay-event-panel__node-toolbar",children:[t.jsxs("select",{"aria-label":"Condition type",onChange:h=>{R({conditions:[..._.conditions??[],Nr(h.target.value)]}),h.currentTarget.value=""},defaultValue:"",children:[t.jsx("option",{value:"",disabled:!0,children:"Add Condition Node"}),["always","hasItem","questStatus","eventActive","flagEquals","custom"].map(h=>t.jsx("option",{value:h,children:h},h))]}),t.jsxs("select",{"aria-label":"Action type",onChange:h=>{R({actions:[..._.actions,Ir(h.target.value)]}),h.currentTarget.value=""},defaultValue:"",children:[t.jsx("option",{value:"",disabled:!0,children:"Add Action Node"}),["giveItem","removeItem","startQuest","completeQuest","showDialog","toast","setFlag","notifyQuestFlag","emit","custom"].map(h=>t.jsx("option",{value:h,children:h},h))]})]}),t.jsxs("div",{className:"gameplay-event-panel__actions",children:[t.jsx("button",{type:"button",onClick:D,children:"Delete Blueprint"}),t.jsx("button",{type:"button",onClick:()=>{E(_)},children:"Run Selected"})]})]}),t.jsx("section",{className:"gameplay-event-panel__section",children:t.jsx("div",{className:`gameplay-event-panel__status gameplay-event-panel__status--${j.kind}`,children:j.message})})]})}const Rr="studio-social-world",Pr="Studio Social World",Dr="1.0.0",Fr=(e,s)=>{if(typeof window>"u"||typeof document>"u")return;const n=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),i=window.URL.createObjectURL(n),o=document.createElement("a");o.href=i,o.download=e,o.click(),window.URL.revokeObjectURL(i)};function Lr({gameplayEvents:e=At.SEED_GAMEPLAY_EVENTS}){const s=Ye.useAssetStore(I=>I.ids),n=Ye.useAssetStore(I=>I.records),i=u.useMemo(()=>s.map(I=>n[I]).filter(I=>!!I),[s,n]),[o,r]=u.useState("main"),[a,l]=u.useState(Rr),[c,d]=u.useState(Pr),[g,p]=u.useState(Dr),[m,f]=u.useState([]),[y,M]=u.useState({kind:"idle",message:"Ready"}),[_,j]=u.useState(null),A=u.useCallback(()=>At.createContentBundleFromSaveSystem(st.getSaveSystem(),i,{id:a,name:c,version:g,gameplayEvents:e}),[i,a,c,e,g]),w=u.useCallback(async()=>{const I=await st.getSaveSystem().list();f(I),M({kind:"success",message:`Loaded ${I.length} save slot(s)`})},[]),x=u.useCallback(async()=>{await st.getSaveSystem().save(o),M({kind:"success",message:`Saved slot "${o}"`}),await w()},[w,o]),T=u.useCallback(async()=>{const I=await st.getSaveSystem().load(o);M({kind:I?"success":"error",message:I?`Loaded slot "${o}"`:`No save data in slot "${o}"`})},[o]),C=u.useCallback(()=>{const I=At.validateContentBundle(A());j(I),M({kind:I.ok?"success":"error",message:I.ok?"Bundle is valid":`Bundle has ${I.errors.length} error(s)`})},[A]),B=u.useCallback(()=>{const I=A(),F=At.validateContentBundle(I);if(j(F),!F.ok){M({kind:"error",message:"Fix bundle validation before export"});return}Fr(`${I.id}-${I.version}.bundle.json`,I),M({kind:"success",message:"Exported content bundle JSON"})},[A]);return t.jsxs("div",{className:"studio-panel",children:[t.jsxs("section",{className:"studio-panel__section",children:[t.jsx("div",{className:"studio-panel__title",children:"World Save"}),t.jsxs("label",{className:"studio-panel__field",children:[t.jsx("span",{children:"Slot"}),t.jsx("input",{value:o,onChange:I=>r(I.target.value||"main")})]}),t.jsxs("div",{className:"studio-panel__actions",children:[t.jsx("button",{type:"button",onClick:()=>{x()},children:"Save"}),t.jsx("button",{type:"button",onClick:()=>{T()},children:"Load"}),t.jsx("button",{type:"button",onClick:()=>{w()},children:"Refresh"})]}),m.length>0&&t.jsx("div",{className:"studio-panel__chips",children:m.map(I=>t.jsx("button",{type:"button",onClick:()=>r(I),children:I},I))})]}),t.jsxs("section",{className:"studio-panel__section",children:[t.jsx("div",{className:"studio-panel__title",children:"Content Bundle"}),t.jsxs("label",{className:"studio-panel__field",children:[t.jsx("span",{children:"Bundle ID"}),t.jsx("input",{value:a,onChange:I=>l(I.target.value)})]}),t.jsxs("label",{className:"studio-panel__field",children:[t.jsx("span",{children:"Name"}),t.jsx("input",{value:c,onChange:I=>d(I.target.value)})]}),t.jsxs("label",{className:"studio-panel__field",children:[t.jsx("span",{children:"Version"}),t.jsx("input",{value:g,onChange:I=>p(I.target.value)})]}),t.jsxs("div",{className:"studio-panel__meta",children:[i.length," asset(s), ",e.length," gameplay event(s),"," ",Array.from(st.getSaveSystem().getBindings()).length," save domain(s)"]}),t.jsxs("div",{className:"studio-panel__actions",children:[t.jsx("button",{type:"button",onClick:C,children:"Validate"}),t.jsx("button",{type:"button",onClick:B,children:"Export JSON"})]})]}),t.jsxs("section",{className:"studio-panel__section",children:[t.jsx("div",{className:"studio-panel__title",children:"Status"}),t.jsx("div",{className:`studio-panel__status studio-panel__status--${y.kind}`,children:y.message}),_&&!_.ok&&t.jsx("ul",{className:"studio-panel__errors",children:_.errors.map(I=>t.jsx("li",{children:I},I))})]})]})}const Gr=()=>t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})}),zr=()=>t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),cn=({children:e,title:s,initialWidth:n=280,initialHeight:i=400,minWidth:o=200,minHeight:r=150,maxWidth:a=600,maxHeight:l=800,resizeHandles:c=["right"],className:d="",style:g={},onClose:p,onMinimize:m,draggable:f=!0,onDrop:y})=>{const[M,_]=u.useState({width:n,height:i}),[j,A]=u.useState({x:0,y:0}),[w,x]=u.useState(!1),[T,C]=u.useState(!1),[B,I]=u.useState(""),[F,R]=u.useState({x:0,y:0}),D=u.useRef(null),E=u.useRef(null),P=u.useCallback(h=>k=>{k.preventDefault(),x(!0),I(h)},[]),G=u.useCallback(h=>{if(D.current)if(w){const k=D.current.getBoundingClientRect();let U=M.width,W=M.height;B.includes("right")&&(U=Math.min(a,Math.max(o,h.clientX-k.left))),B.includes("bottom")&&(W=Math.min(l,Math.max(r,h.clientY-k.top))),_({width:U,height:W})}else T&&A({x:h.clientX-F.x,y:h.clientY-F.y})},[w,T,B,M,o,a,r,l,F]),z=u.useCallback(()=>{T&&y&&y(j.x,j.y),x(!1),C(!1),I("")},[T,y,j]),L=u.useCallback(h=>{if(!f||w)return;h.preventDefault(),C(!0);const k=D.current?.getBoundingClientRect();k&&R({x:h.clientX-k.left,y:h.clientY-k.top})},[f,w]);return u.useEffect(()=>{if(w||T)return document.addEventListener("mousemove",G),document.addEventListener("mouseup",z),()=>{document.removeEventListener("mousemove",G),document.removeEventListener("mouseup",z)}},[w,T,G,z]),t.jsxs("div",{ref:D,className:`rp-panel ${d} ${T?"dragging":""}`,style:{width:`${M.width}px`,height:`${M.height}px`,...T?{position:"fixed",left:`${j.x}px`,top:`${j.y}px`,zIndex:10003}:{},...g},children:[t.jsxs("div",{ref:E,className:"rp-header",onMouseDown:L,children:[t.jsx("h3",{className:"rp-title",children:s}),t.jsxs("div",{className:"rp-controls",onMouseDown:h=>h.stopPropagation(),children:[m&&t.jsx("button",{className:"rp-btn rp-btn--minimize",onClick:m,title:"최소화",children:t.jsx(Gr,{})}),p&&t.jsx("button",{className:"rp-btn rp-btn--close",onClick:p,title:"닫기",children:t.jsx(zr,{})})]})]}),t.jsx("div",{className:"rp-content",children:e}),c.map(h=>t.jsx("div",{className:`rp-resize-handle handle-${h}`,onMouseDown:P(h.replace("corner","right bottom"))},h))]})},bi=({children:e,panels:s=[],defaultActivePanels:n=["building","character","camera"],actions:i=[]})=>{const[o,r]=u.useState(n),[a,l]=u.useState([]),[c,d]=u.useState([]),g=[{id:"building",title:"건축",component:t.jsx(vr,{}),defaultSide:"left"},{id:"character",title:"캐릭터",component:t.jsx(wr,{}),defaultSide:"left"},{id:"vehicle",title:"탑승체",component:t.jsx(hi,{}),defaultSide:"left"},{id:"animation",title:"애니메이션",component:t.jsx(ui,{}),defaultSide:"left"},{id:"camera",title:"카메라",component:t.jsx(li,{}),defaultSide:"right"},{id:"motion",title:"모션",component:t.jsx(mi,{}),defaultSide:"right"},{id:"performance",title:"성능",component:t.jsx(fi,{}),defaultSide:"right"}],p=u.useMemo(()=>[...g,...s],[s]),m=x=>{r(T=>T.includes(x)?T.filter(C=>C!==x):[...T,x]),d(T=>T.filter(C=>C!==x))},f=x=>{r(T=>T.filter(C=>C!==x)),l(T=>T.filter(C=>C.id!==x)),d(T=>T.filter(C=>C!==x))},y=x=>{d(T=>[...T,x]),r(T=>T.filter(C=>C!==x)),l(T=>T.filter(C=>C.id!==x))},M=x=>{d(T=>T.filter(C=>C!==x)),r(T=>[...T,x])},_=(x,T,C)=>{const B=a.find(I=>I.id===x);l(B?I=>I.map(F=>F.id===x?{...F,x:T,y:C}:F):I=>[...I,{id:x,x:T,y:C,width:300,height:400}])},j=()=>p.filter(x=>o.includes(x.id)&&x.defaultSide==="left"&&!a.some(T=>T.id===x.id)),A=()=>p.filter(x=>o.includes(x.id)&&x.defaultSide==="right"&&!a.some(T=>T.id===x.id)),w=()=>a.filter(x=>o.includes(x.id));return t.jsxs("div",{className:"editor-root",children:[t.jsxs("div",{className:"editor-panel-bar",children:[p.map(x=>t.jsx("button",{onClick:()=>m(x.id),className:`editor-panel-toggle ${o.includes(x.id)?"active":""}`,title:x.title,children:x.title},x.id)),i.map(x=>t.jsx("button",{onClick:()=>{x.onClick()},className:"editor-panel-toggle",disabled:x.disabled,title:x.label,children:x.label},x.id))]}),j().length>0&&t.jsx("div",{className:"editor-left-stack",children:j().map((x,T)=>t.jsx(cn,{title:x.title,initialWidth:320,initialHeight:Math.min(640,Math.max(420,window.innerHeight-120)),minWidth:260,maxWidth:500,resizeHandles:["right"],className:"editor-glass-panel",style:{marginBottom:T<j().length-1?"8px":"0"},onClose:()=>f(x.id),onMinimize:()=>y(x.id),onDrop:(C,B)=>_(x.id,C,B),children:x.component},x.id))}),A().length>0&&t.jsx("div",{className:"editor-right-stack",children:A().map((x,T)=>t.jsx(cn,{title:x.title,initialWidth:300,initialHeight:Math.min(520,Math.max(360,window.innerHeight-120)),minWidth:260,maxWidth:500,resizeHandles:["corner"],className:"editor-glass-panel",style:{marginBottom:T<A().length-1?"8px":"0"},onClose:()=>f(x.id),onMinimize:()=>y(x.id),onDrop:(C,B)=>_(x.id,C,B),children:x.component},x.id))}),w().map(x=>{const T=p.find(C=>C.id===x.id);return T?t.jsx(cn,{title:T.title,initialWidth:x.width,initialHeight:x.height,minWidth:200,maxWidth:800,resizeHandles:["right","bottom","corner"],className:"editor-glass-panel",style:{position:"fixed",left:`${x.x}px`,top:`${x.y}px`,zIndex:1001},onClose:()=>f(T.id),onMinimize:()=>y(T.id),onDrop:(C,B)=>_(T.id,C,B),children:T.component},x.id):null}),c.length>0&&t.jsx("div",{className:"editor-minimized-dock",children:c.map(x=>{const T=p.find(C=>C.id===x);return T?t.jsx("button",{onClick:()=>M(x),className:"editor-minimized-item",title:`${T.title} 복원`,children:T.title},x):null})}),e]})},Or={xDistance:10,yDistance:22,zDistance:30,fov:58,zoom:1,enableZoom:!0,minZoom:.35,maxZoom:2.4,zoomSpeed:.001,enableCollision:!1,smoothing:{position:.12,rotation:.12,fov:.12}},Ur=({children:e,className:s="",style:n={},shell:i})=>{const o=u.useRef(null);return u.useEffect(()=>{const r=re.useGaesupStore.getState();return o.current={mode:r.mode,cameraOption:r.cameraOption},r.setMode({control:"thirdPerson"}),r.setCameraOption(Or),()=>{const a=o.current;a&&(re.useGaesupStore.getState().setMode(a.mode),re.useGaesupStore.getState().setCameraOption(a.cameraOption))}},[]),t.jsx("div",{className:`gaesup-editor ${s}`,style:{...n},children:t.jsx(bi,{...i?.panels?{panels:i.panels}:{},...i?.defaultActivePanels?{defaultActivePanels:i.defaultActivePanels}:{},...i?.actions?{actions:i.actions}:{},children:e})})},xs=e=>({selectedObjectIds:[],setSelectedObjectIds:s=>e({selectedObjectIds:s}),layoutConfig:null,setLayoutConfig:s=>e({layoutConfig:s}),activeNodeGraph:null,setActiveNodeGraph:s=>e({activeNodeGraph:s}),clipboard:null,setClipboard:s=>e({clipboard:s})}),Wr=xs,xi=rt.create(xs),Hr=()=>{const e=xi();return{...e,selectObject:s=>e.setSelectedObjectIds([s]),selectMultiple:s=>e.setSelectedObjectIds(s),clearSelection:()=>e.setSelectedObjectIds([])}};function $r(e={}){const s={panels:e.panels??[],actions:(e.commands??[]).map(n=>({id:n.id,label:n.label,onClick:n.run}))};return e.defaultActivePanels&&(s.defaultActivePanels=e.defaultActivePanels),e.validate&&(s.validate=e.validate),s}function Zr(){const e=[],s=[];return{execute:async n=>{await n.run(),n.undo&&(e.push(n),s.length=0)},undo:async()=>{const n=e.pop();n?.undo&&(await n.undo(),s.push(n))},redo:async()=>{const n=s.pop();n&&(await n.run(),e.push(n))},canUndo:()=>e.length>0,canRedo:()=>s.length>0,clear:()=>{e.length=0,s.length=0}}}const Vr=["intel","mali","adreno 3","adreno 4","powervr"],Yr=["swiftshader","llvmpipe","software"],Us=["rtx","radeon rx","apple m","apple a1","apple a2"];function vi(){if(typeof window>"u"||typeof document>"u")return{webgl2:!1,maxTextureSize:0,rendererName:"",vendorName:"",cores:4,memory:4,isMobile:!1,pixelRatio:1};const e=document.createElement("canvas"),s=e.getContext("webgl2")??e.getContext("webgl");let n="",i="",o=0,r=!1;if(s){r=typeof WebGL2RenderingContext<"u"&&s instanceof WebGL2RenderingContext,o=s.getParameter(s.MAX_TEXTURE_SIZE)||0;const g=s.getExtension("WEBGL_debug_renderer_info");g&&(n=String(s.getParameter(g.UNMASKED_RENDERER_WEBGL)||""),i=String(s.getParameter(g.UNMASKED_VENDOR_WEBGL)||""))}const a=navigator.hardwareConcurrency??4,l=navigator.deviceMemory??4,c=/android|iphone|ipad|ipod|mobile|opera mini/i.test(navigator.userAgent),d=Math.min(window.devicePixelRatio||1,2);return{webgl2:r,maxTextureSize:o,rendererName:n,vendorName:i,cores:a,memory:l,isMobile:c,pixelRatio:d}}function yi(e){const s=e.rendererName.toLowerCase();return Yr.some(n=>s.includes(n))?"low":e.isMobile?Us.some(n=>s.includes(n))?"medium":"low":Vr.some(n=>s.includes(n))?e.cores>=8&&e.memory>=8?"medium":"low":Us.some(n=>s.includes(n))||e.cores>=8&&e.memory>=8&&e.webgl2?"high":e.cores>=4&&e.memory>=4?"medium":"low"}function vn(e){return e==="high"?{tier:e,instanceScale:1,pixelRatio:2,shadowMapSize:2048,postprocess:!0,outline:!0}:e==="medium"?{tier:e,instanceScale:.7,pixelRatio:1.5,shadowMapSize:1024,postprocess:!0,outline:!0}:{tier:e,instanceScale:.4,pixelRatio:1,shadowMapSize:512,postprocess:!1,outline:!1}}function ls(){const e=vi(),s=yi(e);return{profile:vn(s),capabilities:e}}const Xr=vn("medium"),Si=rt.create(e=>({profile:Xr,capabilities:null,manualOverride:!1,detect:()=>{const{profile:s,capabilities:n}=ls();e({profile:s,capabilities:n,manualOverride:!1})},setTier:s=>{e({profile:vn(s),manualOverride:!0})},resetAuto:()=>{const{profile:s,capabilities:n}=ls();e({profile:s,capabilities:n,manualOverride:!1})}}));qo.enableMapSet();const oe=rt.create()(Ko.immer((e,s)=>({initialized:!1,templates:new Map,instances:new Map,categories:new Map,clothingSets:new Map,clothingCategories:new Map,animations:new Map,editMode:!1,previewAccessories:{},initializeDefaults:()=>e(n=>{n.initialized||(n.animations.set("idle",{id:"idle",name:"Idle",loop:!0,speed:1}),n.animations.set("walk",{id:"walk",name:"Walk",loop:!0,speed:1}),n.animations.set("greet",{id:"greet",name:"Greet",loop:!1,speed:1}),n.animations.set("jump",{id:"jump",name:"Jump",loop:!1,speed:1}),n.animations.set("run",{id:"run",name:"Run",loop:!0,speed:1.5}),n.clothingCategories.set("basic",{id:"basic",name:"기본 의상",description:"Basic clothing sets",clothingSetIds:["rabbit-outfit","basic-suit","formal-suit"]}),n.clothingCategories.set("accessories",{id:"accessories",name:"액세서리",description:"Hats and glasses",clothingSetIds:["hat-set-a","hat-set-b","hat-set-c","glass-set-a","glass-set-b"]}),n.clothingSets.set("rabbit-outfit",{id:"rabbit-outfit",name:"토끼옷",category:"casual",parts:[{id:"rabbit-cloth",type:"top",url:"gltf/ally_cloth_rabbit.glb",position:[0,0,0]}]}),n.clothingSets.set("basic-suit",{id:"basic-suit",name:"양복",category:"formal",parts:[{id:"basic-suit-cloth",type:"top",url:"gltf/ally_cloth.glb",position:[0,0,0]}]}),n.clothingSets.set("formal-suit",{id:"formal-suit",name:"양복 2",category:"formal",parts:[{id:"formal-suit-cloth",type:"top",url:"gltf/formal.glb",position:[0,0,0]}]}),n.clothingSets.set("hat-set-a",{id:"hat-set-a",name:"모자 A",category:"casual",parts:[{id:"hat-a",type:"hat",url:"gltf/hat_a.glb",position:[0,0,0]}]}),n.clothingSets.set("hat-set-b",{id:"hat-set-b",name:"모자 B",category:"casual",parts:[{id:"hat-b",type:"hat",url:"gltf/hat_b.glb",position:[0,0,0]}]}),n.clothingSets.set("hat-set-c",{id:"hat-set-c",name:"모자 C",category:"casual",parts:[{id:"hat-c",type:"hat",url:"gltf/hat_c.glb",position:[0,0,0]}]}),n.clothingSets.set("glass-set-a",{id:"glass-set-a",name:"안경 A",category:"casual",parts:[{id:"glass-a",type:"glasses",url:"gltf/glass_a.glb",position:[0,0,0]}]}),n.clothingSets.set("glass-set-b",{id:"glass-set-b",name:"슈퍼 안경",category:"casual",parts:[{id:"super-glass",type:"glasses",url:"gltf/super_glass.glb",position:[0,0,0]}]}),n.categories.set("humanoid",{id:"humanoid",name:"캐릭터",description:"Human-like characters",templateIds:["ally","oneyee"]}),n.templates.set("ally",{id:"ally",name:"올춘삼",description:"Ally character",category:"humanoid",baseParts:[{id:"ally-body",type:"body",url:"gltf/ally_body.glb",position:[0,0,0]}],clothingParts:[],defaultAnimation:"idle",defaultClothingSet:"rabbit-outfit"}),n.templates.set("oneyee",{id:"oneyee",name:"원덕배",description:"Oneyee character",category:"humanoid",baseParts:[{id:"oneyee-body",type:"body",url:"gltf/oneyee.glb",position:[0,0,0]}],clothingParts:[],defaultAnimation:"idle",defaultClothingSet:"basic-suit"}),n.selectedCategoryId="humanoid",n.selectedTemplateId="ally",n.selectedClothingCategoryId="basic",n.selectedClothingSetId="rabbit-outfit",n.initialized=!0)}),addTemplate:n=>e(i=>{i.templates.set(n.id,n)}),updateTemplate:(n,i)=>e(o=>{const r=o.templates.get(n);r&&o.templates.set(n,{...r,...i})}),removeTemplate:n=>e(i=>{i.templates.delete(n)}),addInstance:n=>e(i=>{i.instances.set(n.id,n)}),updateInstance:(n,i)=>e(o=>{const r=o.instances.get(n);r&&o.instances.set(n,{...r,...i})}),removeInstance:n=>e(i=>{i.instances.delete(n)}),addCategory:n=>e(i=>{i.categories.set(n.id,n)}),updateCategory:(n,i)=>e(o=>{const r=o.categories.get(n);r&&o.categories.set(n,{...r,...i})}),removeCategory:n=>e(i=>{i.categories.delete(n)}),addClothingSet:n=>e(i=>{i.clothingSets.set(n.id,n)}),updateClothingSet:(n,i)=>e(o=>{const r=o.clothingSets.get(n);r&&o.clothingSets.set(n,{...r,...i})}),removeClothingSet:n=>e(i=>{i.clothingSets.delete(n)}),addClothingCategory:n=>e(i=>{i.clothingCategories.set(n.id,n)}),updateClothingCategory:(n,i)=>e(o=>{const r=o.clothingCategories.get(n);r&&o.clothingCategories.set(n,{...r,...i})}),removeClothingCategory:n=>e(i=>{i.clothingCategories.delete(n)}),addAnimation:n=>e(i=>{i.animations.set(n.id,n)}),updateAnimation:(n,i)=>e(o=>{const r=o.animations.get(n);r&&o.animations.set(n,{...r,...i})}),removeAnimation:n=>e(i=>{i.animations.delete(n)}),setSelectedTemplate:n=>e(i=>{i.selectedTemplateId=n}),setSelectedCategory:n=>e(i=>{i.selectedCategoryId=n;const o=i.categories.get(n);if(o&&o.templateIds.length>0){const r=o.templateIds[0];r&&(i.selectedTemplateId=r)}else delete i.selectedTemplateId}),setSelectedInstance:n=>e(i=>{i.selectedInstanceId=n}),setSelectedClothingSet:n=>e(i=>{i.selectedClothingSetId=n}),setSelectedClothingCategory:n=>e(i=>{i.selectedClothingCategoryId=n;const o=i.clothingCategories.get(n);if(o&&o.clothingSetIds.length>0){const r=o.clothingSetIds[0];r&&(i.selectedClothingSetId=r)}else delete i.selectedClothingSetId}),setEditMode:n=>e(i=>{i.editMode=n}),createInstanceFromTemplate:(n,i)=>{const o=s().templates.get(n);if(!o)return;const r=`npc-${Date.now()}`,a=s().selectedClothingSetId||o.defaultClothingSet,l=[],c=s().previewAccessories.hat;if(c){const m=s().clothingSets.get(c)?.parts[0];m&&l.push(m)}const d=s().previewAccessories.glasses;if(d){const m=s().clothingSets.get(d)?.parts[0];m&&l.push(m)}const g={id:r,templateId:n,name:`${o.name} ${Date.now()}`,position:i,rotation:[0,0,0],scale:[1,1,1],...o.defaultAnimation?{currentAnimation:o.defaultAnimation}:{},...a?{currentClothingSetId:a}:{},...l.length>0?{customParts:l}:{},events:[]};s().addInstance(g),s().setSelectedInstance(r)},updateInstancePart:(n,i,o)=>e(r=>{const a=r.instances.get(n);if(!a)return;const l=a.customParts||[],c=l.findIndex(d=>d.id===i);if(c>=0){const d=l[c];l[c]={...d,...o,id:d.id,type:d.type,url:d.url}}else{const d=o.type??"accessory",g=o.url??"";l.push({id:i,type:d,url:g,...o.category!==void 0?{category:o.category}:{},...o.position!==void 0?{position:o.position}:{},...o.rotation!==void 0?{rotation:o.rotation}:{},...o.scale!==void 0?{scale:o.scale}:{},...o.color!==void 0?{color:o.color}:{},...o.metadata!==void 0?{metadata:o.metadata}:{}})}r.instances.set(n,{...a,customParts:l})}),changeInstanceClothing:(n,i)=>e(o=>{const r=o.instances.get(n);r&&o.instances.set(n,{...r,currentClothingSetId:i})}),addInstanceEvent:(n,i)=>e(o=>{const r=o.instances.get(n);if(r){const a=r.events||[];a.push(i),o.instances.set(n,{...r,events:a})}}),removeInstanceEvent:(n,i)=>e(o=>{const r=o.instances.get(n);if(r&&r.events){const a=r.events.filter(l=>l.id!==i);o.instances.set(n,{...r,events:a})}}),setPreviewAccessory:(n,i)=>e(o=>{i?o.previewAccessories[n]=i:delete o.previewAccessories[n]}),setNavigation:(n,i,o=3)=>e(r=>{const a=r.instances.get(n);if(!a||i.length===0)return;const l={waypoints:i,currentIndex:0,speed:o,state:"moving"};r.instances.set(n,{...a,navigation:l,currentAnimation:"walk"})}),advanceNavigation:n=>e(i=>{const o=i.instances.get(n);if(!o?.navigation||o.navigation.state!=="moving")return;const r=o.navigation,a=r.currentIndex+1;a>=r.waypoints.length?i.instances.set(n,{...o,navigation:{...r,state:"arrived",currentIndex:a},currentAnimation:"idle"}):i.instances.set(n,{...o,navigation:{...r,currentIndex:a}})}),clearNavigation:n=>e(i=>{const o=i.instances.get(n);if(!o)return;const r={...o,currentAnimation:"idle"};delete r.navigation,i.instances.set(n,r)}),updateNavigationPosition:(n,i)=>e(o=>{const r=o.instances.get(n);r&&o.instances.set(n,{...r,position:i})})})));function qr({part:e}){return t.jsxs("mesh",{position:e.position||[0,0,0],rotation:e.rotation||[0,0,0],scale:e.scale||[1,1,1],children:[t.jsx("boxGeometry",{args:[.5,1.8,.5]}),t.jsx("meshStandardMaterial",{color:"royalblue",transparent:!0,opacity:.7})]})}function Kr(){const e=S.useBuildingStore(d=>d.editMode),s=S.useBuildingStore(d=>d.hoverPosition),n=oe(d=>d.templates),i=oe(d=>d.clothingSets),o=oe(d=>d.selectedTemplateId),r=oe(d=>d.selectedClothingSetId),a=oe(d=>d.previewAccessories);if(e!=="npc"||!s||!o)return null;const l=n.get(o);if(!l)return null;const c=[];if(c.push(...l.baseParts),r){const d=i.get(r);d&&c.push(...d.parts)}if(a.hat){const d=i.get(a.hat);if(d&&d.parts.length>0){const g=d.parts[0];g&&c.push(g)}}if(a.glasses){const d=i.get(a.glasses);if(d&&d.parts.length>0){const g=d.parts[0];g&&c.push(g)}}return t.jsxs("group",{position:[s.x,s.y,s.z],children:[c.map(d=>t.jsx(qr,{part:d},d.id)),t.jsxs("mesh",{position:[0,.01,0],rotation:[-Math.PI/2,0,0],children:[t.jsx("circleGeometry",{args:[1,32]}),t.jsx("meshStandardMaterial",{color:"#00ff00",transparent:!0,opacity:.3,emissive:"#00ff00",emissiveIntensity:.3})]})]})}const Ue=new Set,_e=rt.create(e=>({active:!1,version:0,visibleTileGroupIds:Ue,visibleWallGroupIds:Ue,visibleBlockIds:Ue,visibleObjectIds:Ue,clusterCounts:new Uint32Array(0),setResult:({version:s,tileIds:n,wallIds:i,blockIds:o,objectIds:r,clusterCounts:a})=>e({active:!0,version:s,visibleTileGroupIds:n,visibleWallGroupIds:i,visibleBlockIds:o??Ue,visibleObjectIds:r,clusterCounts:a}),reset:()=>e({active:!1,version:0,visibleTileGroupIds:Ue,visibleWallGroupIds:Ue,visibleBlockIds:Ue,visibleObjectIds:Ue,clusterCounts:new Uint32Array(0)})})),ze=18,Le=140,Jr=.12,Qr=8,ea=3.2,Ws=2.4,ta=.985;function Ke(e,s){return Math.floor(e/s)}function Mi(e,s){return`${e}:${s}`}function na(e,s,n,i,o=ze,r=Qr){const a=Ke(e,o),l=Ke(s,o),c=Math.atan2(i,n),d=c<0?c+Math.PI*2:c,g=Math.floor(d/(Math.PI*2)*r)%r;return`${a}:${l}:${g}`}function un(e,s,n,i=ze){const o=Math.max(0,Math.ceil(s.radius/i));for(let r=s.cellZ-o;r<=s.cellZ+o;r+=1)for(let a=s.cellX-o;a<=s.cellX+o;a+=1)sa(e,a,r,n)}function Jt(e,s,n=ze){un(e,s,s.id,n)}function sa(e,s,n,i){const o=Mi(s,n),r=e.get(o);if(r){r.push(i);return}e.set(o,[i])}function vs(e,s,n,i,o,r,a,l){const c=(s+n)*.5,d=(i+o)*.5,g=(r+a)*.5,p=n-s,m=o-i,f=a-r;return{id:e,centerX:c,centerY:d,centerZ:g,radius:Math.max(1,Math.hypot(p,m,f)*.5),cellX:Ke(c,l),cellZ:Ke(g,l)}}function ji(e,s=ze){if(e.tiles.length===0)return null;let n=1/0,i=-1/0,o=0,r=.2,a=1/0,l=-1/0;for(const c of e.tiles){const g=(c.size??1)*.5;n=Math.min(n,c.position.x-g),i=Math.max(i,c.position.x+g),o=Math.min(o,0),r=Math.max(r,Math.max(c.position.y,.2)+1.5),a=Math.min(a,c.position.z-g),l=Math.max(l,c.position.z+g)}return vs(e.id,n,i,o,r,a,l,s)}function wi(e,s=ze){if(e.walls.length===0)return null;let n=1/0,i=-1/0,o=0,r=2.5,a=1/0,l=-1/0;for(const c of e.walls)n=Math.min(n,c.position.x-1.1),i=Math.max(i,c.position.x+1.1),o=Math.min(o,c.position.y),r=Math.max(r,c.position.y+3.5),a=Math.min(a,c.position.z-1.1),l=Math.max(l,c.position.z+1.1);return vs(e.id,n,i,o,r,a,l,s)}function _i(e,s=ze){const n=Math.max(1,Math.round(e.size?.x??1))*S.TILE_CONSTANTS.GRID_CELL_SIZE,i=Math.max(1,Math.round(e.size?.y??1))*S.TILE_CONSTANTS.HEIGHT_STEP,o=Math.max(1,Math.round(e.size?.z??1))*S.TILE_CONSTANTS.GRID_CELL_SIZE,r=S.TILE_CONSTANTS.GRID_CELL_SIZE*.5;return vs(e.id,e.position.x-r,e.position.x-r+n,e.position.y,e.position.y+i,e.position.z-r,e.position.z-r+o,s)}function ia(e){const s=e.config?.size??1;switch(e.type){case"sakura":return Math.max(2.2,s*.8);case"flag":return Math.max(1.4,(e.config?.flagWidth??1.5)*.8);case"fire":return Math.max(1.2,e.config?.fireWidth??1);case"billboard":return 1.8;default:return 1.5}}function Ci(e,s=ze){const n=ia(e);return{id:e.id,centerX:e.position.x,centerY:e.position.y+n*.5,centerZ:e.position.z,radius:n,cellX:Ke(e.position.x,s),cellZ:Ke(e.position.z,s)}}function oa(e,s,n,i=[],o=ze){const r=Array.isArray(i)?i:[],a=typeof i=="number"?i:o,l={tileById:new Map,wallById:new Map,blockById:new Map,objectById:new Map,tileBuckets:new Map,wallBuckets:new Map,blockBuckets:new Map,objectBuckets:new Map,occluderByKey:new Map,occluderBuckets:new Map};for(const c of s){const d=ji(c,a);if(d&&(l.tileById.set(d.id,d),Jt(l.tileBuckets,d,a),d.radius>=ea)){const g={...d,key:`tile:${d.id}`,kind:"tile",strength:d.radius};l.occluderByKey.set(g.key,g),un(l.occluderBuckets,g,g.key,a)}}for(const c of e){const d=wi(c,a);if(d&&(l.wallById.set(d.id,d),Jt(l.wallBuckets,d,a),d.radius>=Ws||c.walls.length>=4)){const g={...d,key:`wall:${d.id}`,kind:"wall",strength:d.radius*1.15};l.occluderByKey.set(g.key,g),un(l.occluderBuckets,g,g.key,a)}}for(const c of r){const d=_i(c,a);if(l.blockById.set(d.id,d),Jt(l.blockBuckets,d,a),d.radius>=Ws||(c.size?.y??1)>=2){const g={...d,key:`block:${d.id}`,kind:"block",strength:d.radius*1.1};l.occluderByKey.set(g.key,g),un(l.occluderBuckets,g,g.key,a)}}for(const c of n){const d=Ci(c,a);l.objectById.set(d.id,d),Jt(l.objectBuckets,d,a)}return l}function Bt(e,s,n,i=Le,o=ze){const r=Ke(s,o),a=Ke(n,o),l=Math.ceil(i/o),c=new Set;for(let d=a-l;d<=a+l;d+=1)for(let g=r-l;g<=r+l;g+=1){const p=e.get(Mi(g,d));if(p)for(const m of p)c.add(m)}return c}function ra(e,s,n,i=Le,o=ze){const r=Bt(e.occluderBuckets,s,n,i,o),a=[];for(const l of r){const c=e.occluderByKey.get(l);c&&a.push(c)}return a}function aa(e,s,n,i,o){const r=e.centerX-n.x,a=e.centerY-n.y,l=e.centerZ-n.z,c=Math.sqrt(r*r+a*a+l*l);if(c<10)return!1;o.targetDir.set(r,a,l).normalize();for(const d of i){if(d.kind===s&&d.id===e.id)continue;const g=d.centerX-n.x,p=d.centerY-n.y,m=d.centerZ-n.z,f=Math.sqrt(g*g+p*p+m*m);if(f<=1||f>=c-Math.max(e.radius,1.2)||(o.occDir.set(g,p,m).normalize(),o.targetDir.dot(o.occDir)<ta))continue;const M=o.cross.crossVectors(o.targetDir,o.occDir).length()*f,_=d.strength+Math.min(e.radius*.45,1.8);if(!(M>_))return!0}return!1}const ys=0,Ss=1,Ms=2,js=3,la=0,Ti=1,Ni=2,Ii=3,Ai=4,ca=10,Bi=20,Ei=21,cs=22,ki=23,Ri=24,ua=30;function Pi(){return{version:0,ids:[],kinds:new Uint8Array(0),subKinds:new Uint8Array(0),centerX:new Float32Array(0),centerY:new Float32Array(0),centerZ:new Float32Array(0),radius:new Float32Array(0),cellX:new Int16Array(0),cellZ:new Int16Array(0),memberCount:new Uint16Array(0)}}function da(e,s,n,i){let o=n.length+i.length;for(const r of e)r.walls.length>0&&(o+=1);for(const r of s)r.tiles.length>0&&(o+=1);return o}function pa(e){const s=e.blocks??[],n=da(e.wallGroups,e.tileGroups,e.objects,s);if(n===0)return{...Pi(),version:e.version};const i=new Array(n),o=new Uint8Array(n),r=new Uint8Array(n),a=new Float32Array(n),l=new Float32Array(n),c=new Float32Array(n),d=new Float32Array(n),g=new Int16Array(n),p=new Int16Array(n),m=new Uint16Array(n);let f=0;const y=(M,_,j,A,w)=>{i[f]=M,o[f]=_,r[f]=j,a[f]=A.centerX,l[f]=A.centerY,c[f]=A.centerZ,d[f]=A.radius,g[f]=A.cellX,p[f]=A.cellZ,m[f]=w,f+=1};for(const M of e.tileGroups){const _=ji(M);if(!_)continue;const j=M.tiles.find(w=>w.objectType&&w.objectType!=="none")?.objectType??"none",A=j==="grass"?Ti:j==="water"?Ni:j==="sand"?Ii:j==="snowfield"?Ai:la;y(M.id,ys,A,_,M.tiles.length)}for(const M of e.wallGroups){const _=wi(M);_&&y(M.id,Ss,ca,_,M.walls.length)}for(const M of s)y(M.id,js,ua,_i(M),1);for(const M of e.objects){const _=M.type==="sakura"?Bi:M.type==="flag"?Ei:M.type==="fire"?cs:M.type==="billboard"?ki:M.type==="model"?Ri:cs;y(M.id,Ms,_,Ci(M),1)}return{version:e.version,ids:i,kinds:o,subKinds:r,centerX:a,centerY:l,centerZ:c,radius:d,cellX:g,cellZ:p,memberCount:m}}const mt=0,ws=1,ft=2,ht=3,gt=4,yn=5,Sn=6,Mn=7,jn=8,wn=9,_n=10,Cn=11,Tn=12;function Di(e,s){const n=e.kinds[s],i=e.subKinds[s];if(n===ys)return i===Ti?ws:i===Ni?ft:i===Ii?ht:i===Ai?gt:mt;if(n===Ss)return yn;if(n===js)return _n;if(n===Ms){if(i===Bi)return Sn;if(i===Ei)return Mn;if(i===cs)return jn;if(i===ki)return wn;if(i===Ri)return Cn}return mt}function Fi(e,s){const n=new Set,i=new Set,o=new Set,r=new Set,a=new Uint32Array(Tn),l=Math.min(e.ids.length,s.length);for(let c=0;c<l;c+=1){if((s[c]??0)===0)continue;const d=e.ids[c];if(!d)continue;const g=e.kinds[c];g===ys?n.add(d):g===Ss?i.add(d):g===js?o.add(d):g===Ms&&r.add(d);const p=Di(e,c);a[p]=(a[p]??0)+1}return{version:e.version,tileIds:n,wallIds:i,blockIds:o,objectIds:r,clusterCounts:a}}const ke=4;function Ne(e,s){const n=s*ke;return e.args[n+1]??0}const Li=[{id:mt,label:"tile",vertexCountHint:36},{id:ws,label:"grass",vertexCountHint:36},{id:ft,label:"water",vertexCountHint:36},{id:ht,label:"sand",vertexCountHint:36},{id:gt,label:"snowfield",vertexCountHint:36},{id:yn,label:"wall",vertexCountHint:36},{id:Sn,label:"sakura",vertexCountHint:12},{id:Mn,label:"flag",vertexCountHint:12},{id:jn,label:"fire",vertexCountHint:6},{id:wn,label:"billboard",vertexCountHint:6},{id:_n,label:"block",vertexCountHint:36},{id:Cn,label:"model",vertexCountHint:36}];function _s(){return{version:0,args:new Uint32Array(Tn*ke),dirtyRanges:[]}}function ma(e,s){if(e.length!==s.length)return s.length>0?[{start:0,end:s.length/ke}]:[];const n=[];let i=-1;const o=s.length/ke;for(let r=0;r<o;r+=1){const a=r*ke;let l=!1;for(let c=0;c<ke;c+=1)if((e[a+c]??0)!==(s[a+c]??0)){l=!0;break}if(l){i<0&&(i=r);continue}i>=0&&(n.push({start:i,end:r}),i=-1)}return i>=0&&n.push({start:i,end:o}),n}function Gi(e,s,n){const i=new Uint32Array(Tn*ke);for(const r of Li){const a=r.id*ke;i[a]=r.vertexCountHint,i[a+1]=s[r.id]??0,i[a+2]=0,i[a+3]=0}const o=n??_s();return{version:e,args:i,dirtyRanges:ma(o.args,i)}}function zi(e){return{version:e.version,slices:e.dirtyRanges.map(s=>{const n=s.start*ke,i=(s.end-s.start)*ke;return{byteOffset:n*e.args.BYTES_PER_ELEMENT,elementOffset:n,elementCount:i,data:e.args.subarray(n,n+i)}})}}const Ft=4,Lt=5;function Cs(){return{version:0,count:0,spatial:new Float32Array(0),meta:new Int32Array(0),spatialDirty:[],metaDirty:[]}}function fa(e){const s=new Float32Array(e.ids.length*Ft);for(let n=0;n<e.ids.length;n+=1){const i=n*Ft;s[i]=e.centerX[n]??0,s[i+1]=e.centerY[n]??0,s[i+2]=e.centerZ[n]??0,s[i+3]=e.radius[n]??0}return s}function ha(e){const s=new Int32Array(e.ids.length*Lt);for(let n=0;n<e.ids.length;n+=1){const i=n*Lt;s[i]=e.cellX[n]??0,s[i+1]=e.cellZ[n]??0,s[i+2]=e.kinds[n]??0,s[i+3]=e.subKinds[n]??0,s[i+4]=e.memberCount[n]??0}return s}function Hs(e,s,n){if(e.length!==s.length)return s.length>0?[{start:0,end:Math.ceil(s.length/n)}]:[];const i=[];let o=-1;const r=Math.ceil(s.length/n);for(let a=0;a<r;a+=1){const l=a*n;let c=!1;for(let d=0;d<n;d+=1)if((e[l+d]??0)!==(s[l+d]??0)){c=!0;break}if(c){o<0&&(o=a);continue}o>=0&&(i.push({start:o,end:a}),o=-1)}return o>=0&&i.push({start:o,end:r}),i}function Oi(e,s){const n=fa(e),i=ha(e),o=s??Cs();return{version:e.version,count:e.ids.length,spatial:n,meta:i,spatialDirty:Hs(o.spatial,n,Ft),metaDirty:Hs(o.meta,i,Lt)}}function $s(e,s,n){return n.map(i=>{const o=i.start*s,r=(i.end-i.start)*s;return{byteOffset:o*e.BYTES_PER_ELEMENT,elementOffset:o,elementCount:r,data:e.subarray(o,o+r)}})}function Ui(e){return{version:e.version,count:e.count,spatial:$s(e.spatial,Ft,e.spatialDirty),meta:$s(e.meta,Lt,e.metaDirty)}}const ga=8,ba=128;function Gt(){return{backend:"none",uploadedVersion:0,spatialBuffer:null,metaBuffer:null,indirectArgsBuffer:null,spatialBytes:0,metaBytes:0,indirectArgsBytes:0}}function Nn(e){if(typeof e!="object"||e===null)return null;const s=e,n=s.backend?.device??s.device??null;return!n||typeof n.createBuffer!="function"||typeof n.queue?.writeBuffer!="function"?null:n}function kt(e){e?.destroy&&e.destroy()}function Wi(e){kt(e.spatialBuffer),kt(e.metaBuffer),kt(e.indirectArgsBuffer)}function us(e,s,n,i,o){return i<=0?(kt(s),null):s&&n===i?s:(kt(s),e.createBuffer({label:o,size:i,usage:ba|ga}))}function Hi(e,s,n){const i=Ui(n),o=n.spatial.byteLength,r=n.meta.byteLength,a=us(e,s.spatialBuffer,s.spatialBytes,o,"building-spatial"),l=us(e,s.metaBuffer,s.metaBytes,r,"building-meta");if(a)for(const c of i.spatial)e.queue.writeBuffer(a,c.byteOffset,c.data);if(l)for(const c of i.meta)e.queue.writeBuffer(l,c.byteOffset,c.data);return{backend:"webgpu",uploadedVersion:n.version,spatialBuffer:a,metaBuffer:l,indirectArgsBuffer:s.indirectArgsBuffer,spatialBytes:o,metaBytes:r,indirectArgsBytes:s.indirectArgsBytes}}function $i(e,s,n){const i=zi(n),o=n.args.byteLength,r=us(e,s.indirectArgsBuffer,s.indirectArgsBytes,o,"building-indirect-args");if(r)for(const a of i.slices)e.queue.writeBuffer(r,a.byteOffset,a.data);return{...s,backend:"webgpu",uploadedVersion:Math.max(s.uploadedVersion,n.version),indirectArgsBuffer:r,indirectArgsBytes:o}}const Zs=Pi(),Vs=Cs(),Ys=Gt(),Xs=_s(),ge=rt.create(e=>({snapshot:Zs,gpuMirror:Vs,uploadResources:Ys,drawMirror:Xs,setSnapshot:s=>e({snapshot:s}),setGpuMirror:s=>e({gpuMirror:s}),setUploadResources:s=>e({uploadResources:s}),setDrawMirror:s=>e({drawMirror:s}),reset:()=>e({snapshot:Zs,gpuMirror:Vs,uploadResources:Ys,drawMirror:Xs})}));function Qt(e,s){if(e===s)return!0;if(e.size!==s.size)return!1;for(const n of e)if(!s.has(n))return!1;return!0}const We=new Set,Ze=rt.create(e=>({initialized:!1,visibleTileGroupIds:We,visibleWallGroupIds:We,visibleBlockIds:We,visibleObjectIds:We,setVisible:({tileIds:s,wallIds:n,blockIds:i,objectIds:o})=>e(r=>{const a=!Qt(r.visibleTileGroupIds,s),l=!Qt(r.visibleWallGroupIds,n),c=i??We,d=!Qt(r.visibleBlockIds,c),g=!Qt(r.visibleObjectIds,o);return!a&&!l&&!d&&!g&&r.initialized?r:{initialized:!0,visibleTileGroupIds:a?s:r.visibleTileGroupIds,visibleWallGroupIds:l?n:r.visibleWallGroupIds,visibleBlockIds:d?c:r.visibleBlockIds,visibleObjectIds:g?o:r.visibleObjectIds}}),reset:()=>e({initialized:!1,visibleTileGroupIds:We,visibleWallGroupIds:We,visibleBlockIds:We,visibleObjectIds:We})}));var xa=Object.defineProperty,va=Object.getOwnPropertyDescriptor,Ut=(e,s,n,i)=>{for(var o=va(s,n),r=e.length-1,a;r>=0;r--)(a=e[r])&&(o=a(s,n,o)||o);return o&&xa(s,n,o),o};class Je{materials=new Map;textures=new Map;textureLoader;constructor(){this.textureLoader=new b.TextureLoader}getMaterial(s){const n=this.createMaterialKey(s),i=this.materials.get(n);if(i)return i;const o=this.createMaterial(s);return this.materials.set(n,o),o}createMaterialKey(s){return[s.id,s.assetId??"",s.color??s.materialParams?.color??"",s.material??"",s.textureUrl??"",s.mapTextureUrl??s.materialParams?.mapTextureUrl??"",s.normalTextureUrl??s.materialParams?.normalTextureUrl??"",s.roughness??s.materialParams?.roughness??"",s.metalness??s.materialParams?.metalness??"",s.opacity??s.materialParams?.opacity??"",s.transparent??s.materialParams?.transparent??""].join("|")}createMaterial(s){const n=s.color??s.materialParams?.color??"#ffffff",i=s.roughness??s.materialParams?.roughness??.5,o=s.metalness??s.materialParams?.metalness??0,r=s.opacity??s.materialParams?.opacity??1,a=s.transparent??s.materialParams?.transparent??!1,l=s.mapTextureUrl??s.textureUrl??s.materialParams?.mapTextureUrl,c=s.normalTextureUrl??s.materialParams?.normalTextureUrl,d={color:n,roughness:i,metalness:o,opacity:r,transparent:a};if(S.getDefaultToonMode()){const g=s.material==="GLASS",p=new b.MeshToonMaterial({color:n,opacity:g?.45:r,transparent:g?!0:a,gradientMap:S.getToonGradient(g?2:4)});return l&&(p.map=this.loadTexture(l)),c&&(p.normalMap=this.loadTexture(c)),p}return s.material==="GLASS"?new b.MeshPhysicalMaterial({...d,transmission:.98,roughness:.1,envMapIntensity:1}):(l&&(d.map=this.loadTexture(l)),c&&(d.normalMap=this.loadTexture(c)),new b.MeshStandardMaterial(d))}loadTexture(s){const n=this.textures.get(s);if(n)return n;const i=this.textureLoader.load(s);return i.wrapS=b.RepeatWrapping,i.wrapT=b.RepeatWrapping,i.needsUpdate=!0,this.textures.set(s,i),i}updateMaterial(s,n){const i=this.materials.get(s);i&&(i instanceof b.MeshStandardMaterial?(n.color&&i.color.set(n.color),n.roughness!==void 0&&(i.roughness=n.roughness),n.metalness!==void 0&&(i.metalness=n.metalness),n.opacity!==void 0&&(i.opacity=n.opacity),i.needsUpdate=!0):i instanceof b.MeshToonMaterial&&(n.color&&i.color.set(n.color),n.opacity!==void 0&&(i.opacity=n.opacity),i.needsUpdate=!0))}dispose(){this.materials.forEach(s=>s.dispose()),this.materials.clear(),this.textures.forEach(s=>s.dispose()),this.textures.clear()}}Ut([re.HandleError(),re.Profile()],Je.prototype,"getMaterial");Ut([re.HandleError(),re.Profile()],Je.prototype,"createMaterial");Ut([re.HandleError(),re.MonitorMemory(20)],Je.prototype,"loadTexture");Ut([re.HandleError(),re.Profile()],Je.prototype,"updateMaterial");Ut([re.HandleError()],Je.prototype,"dispose");const qs={id:"default-block",color:"#8b8174",material:"STANDARD",roughness:.92};function ya(e){return{width:Math.max(1,Math.round(e.size?.x??1))*S.TILE_CONSTANTS.GRID_CELL_SIZE,height:Math.max(1,Math.round(e.size?.y??1))*S.TILE_CONSTANTS.HEIGHT_STEP,depth:Math.max(1,Math.round(e.size?.z??1))*S.TILE_CONSTANTS.GRID_CELL_SIZE}}function ds(e){const{width:s,height:n,depth:i}=ya(e);return{position:[e.position.x-S.TILE_CONSTANTS.GRID_CELL_SIZE*.5+s*.5,e.position.y+n*.5,e.position.z-S.TILE_CONSTANTS.GRID_CELL_SIZE*.5+i*.5],scale:[s,n,i]}}function Zi({blocks:e,meshes:s,isEditMode:n=!1,selectedBlockId:i=null,onBlockClick:o}){const r=u.useRef(new Je),a=u.useMemo(()=>new b.Object3D,[]),l=u.useMemo(()=>new b.BoxGeometry(1,1,1),[]),c=u.useMemo(()=>new b.MeshStandardMaterial({color:"#60a5fa",transparent:!0,opacity:.16,emissive:new b.Color("#2563eb"),emissiveIntensity:.08,wireframe:!0,depthWrite:!1}),[]),d=u.useMemo(()=>new b.MeshStandardMaterial({color:"#bae6fd",transparent:!0,opacity:.28,emissive:new b.Color("#60a5fa"),emissiveIntensity:.2,wireframe:!0,depthWrite:!1}),[]),g=u.useMemo(()=>{const p=new Map;for(const f of e){const y=f.materialId??qs.id,M=p.get(y)??[];M.push(f),p.set(y,M)}const m=r.current;return Array.from(p.entries()).map(([f,y])=>({key:f,blocks:y,material:m.getMaterial(s.get(f)??{...qs,id:f})}))},[e,s]);return u.useEffect(()=>()=>{r.current.dispose(),l.dispose(),c.dispose(),d.dispose()},[c,l,d]),t.jsxs(t.Fragment,{children:[!n&&e.length>0&&t.jsx(ot.RigidBody,{type:"fixed",colliders:!1,children:e.map(p=>{const m=ds(p);return t.jsx(ot.CuboidCollider,{position:m.position,args:[m.scale[0]*.5,m.scale[1]*.5,m.scale[2]*.5]},p.id)})}),g.map(p=>t.jsx(Sa,{batch:p,geometry:l,dummy:a},p.key)),n&&e.map(p=>{const m=ds(p),f=p.id===i;return t.jsx("mesh",{name:`block-edit-${p.id}`,position:m.position,scale:[m.scale[0]*.82,m.scale[1]*.82,m.scale[2]*.82],geometry:l,material:f?d:c,onClick:()=>o?.(p.id)},`${p.id}-edit`)})]})}function Sa({batch:e,geometry:s,dummy:n}){const i=u.useRef(null);return u.useLayoutEffect(()=>{const o=i.current;if(o){o.count=e.blocks.length;for(let r=0;r<e.blocks.length;r+=1){const a=e.blocks[r];if(!a)continue;const l=ds(a);n.position.set(...l.position),n.scale.set(...l.scale),n.rotation.set(0,0,0),n.updateMatrix(),o.setMatrixAt(r,n.matrix)}o.instanceMatrix.needsUpdate=!0,e.blocks.length>0&&(o.computeBoundingBox(),o.computeBoundingSphere())}},[e.blocks,n]),t.jsx("instancedMesh",{ref:i,name:`block-system-${e.key}`,args:[s,e.material,Math.max(1,e.blocks.length)],castShadow:!0,receiveShadow:!0})}function Vi({size:e=S.TILE_CONSTANTS.DEFAULT_GRID_SIZE,divisions:s=e/S.TILE_CONSTANTS.GRID_CELL_SIZE,color1:n="#888888",color2:i="#444444"}){return t.jsx("gridHelper",{args:[e,s,n,i],position:[0,.01,0]})}function Ma(e,s,n,i){const o=document.createElement("canvas"),r=512,a=Math.round(r*(n/s));o.width=r,o.height=a;const l=o.getContext("2d");l.fillStyle="#0a0a0a",l.fillRect(0,0,r,a),l.strokeStyle="#333",l.lineWidth=4,l.strokeRect(2,2,r-4,a-4),l.fillStyle=i;const c=Math.floor(a*.25);l.font=`bold ${c}px monospace`,l.textAlign="center",l.textBaseline="middle";const d=e.split(`
2
2
  `),g=c*1.3,p=a/2-(d.length-1)*g/2;d.forEach((f,y)=>{l.fillText(f,r/2,p+y*g,r-20)});const m=new b.CanvasTexture(o);return m.needsUpdate=!0,m}const Yi=20,Xi=100,qi=3;function ja({imageUrl:e,width:s,height:n,color:i,toon:o}){const r=u.useRef(null),a=u.useRef(null),l=u.useRef(null),c=u.useMemo(()=>new b.Vector3,[]),g=o??S.getDefaultToonMode()?S.getToonGradient(3):null,p=Ge.useTexture(e),m=s??2,f=n??1.5,y=u.useMemo(()=>new b.Color(i||"#00ff88"),[i]),M=u.useMemo(()=>new b.PlaneGeometry(m,f),[m,f]),_=u.useMemo(()=>new b.PlaneGeometry(m*1.15,f*1.15),[m,f]);return ae.useFrame(j=>{r.current.getWorldPosition(c);const A=j.camera.position.distanceTo(c),w=Ot.weightFromDistance(A,Yi,Xi,qi);a.current.emissiveIntensity=2*w,l.current.opacity=(.2+.05*Math.sin(j.clock.elapsedTime*2))*w}),u.useEffect(()=>()=>{M.dispose(),_.dispose()},[M,_]),t.jsxs("group",{position:[0,f/2+1,0],children:[t.jsx("mesh",{geometry:_,position:[0,0,-.01],children:t.jsx("meshBasicMaterial",{ref:l,color:y,transparent:!0,opacity:.25,blending:b.AdditiveBlending,depthWrite:!1,side:b.DoubleSide})}),t.jsx("mesh",{ref:r,geometry:M,children:g?t.jsx("meshToonMaterial",{ref:a,map:p,emissive:y,emissiveIntensity:2,gradientMap:g,side:b.DoubleSide}):t.jsx("meshStandardMaterial",{ref:a,map:p,emissive:y,emissiveIntensity:2,side:b.DoubleSide})})]})}function wa({text:e,width:s,height:n,color:i,toon:o}){const r=u.useRef(null),a=u.useRef(null),l=u.useRef(null),c=u.useMemo(()=>new b.Vector3,[]),g=o??S.getDefaultToonMode()?S.getToonGradient(3):null,p=s??2,m=n??1.5,f=i||"#00ff88",y=u.useMemo(()=>Ma(e||"HELLO",p,m,f),[e,p,m,f]),M=u.useMemo(()=>new b.Color(f),[f]),_=u.useMemo(()=>new b.PlaneGeometry(p,m),[p,m]),j=u.useMemo(()=>new b.PlaneGeometry(p*1.15,m*1.15),[p,m]);return ae.useFrame(A=>{r.current.getWorldPosition(c);const w=A.camera.position.distanceTo(c),x=Ot.weightFromDistance(w,Yi,Xi,qi);a.current.emissiveIntensity=2*x,l.current.opacity=(.2+.05*Math.sin(A.clock.elapsedTime*2))*x}),u.useEffect(()=>()=>{_.dispose(),j.dispose(),y.dispose()},[_,j,y]),t.jsxs("group",{position:[0,m/2+1,0],children:[t.jsx("mesh",{geometry:j,position:[0,0,-.01],children:t.jsx("meshBasicMaterial",{ref:l,color:M,transparent:!0,opacity:.25,blending:b.AdditiveBlending,depthWrite:!1,side:b.DoubleSide})}),t.jsx("mesh",{ref:r,geometry:_,children:g?t.jsx("meshToonMaterial",{ref:a,map:y,emissive:M,emissiveIntensity:2,gradientMap:g,side:b.DoubleSide}):t.jsx("meshStandardMaterial",{ref:a,map:y,emissive:M,emissiveIntensity:2,side:b.DoubleSide})})]})}const _a=e=>e.imageUrl?t.jsx(ja,{...e,imageUrl:e.imageUrl}):t.jsx(wa,{...e}),Ki=u.memo(_a);var Ca=`varying vec2 vUv;
3
3
  uniform float time;
4
4
  uniform float intensity;