@zylem/game-lib 0.8.4 → 0.8.6

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 (63) hide show
  1. package/dist/actions.d.ts +7 -5
  2. package/dist/api/game-lib.api.json +3424 -514
  3. package/dist/api/game-lib.api.md +178 -10
  4. package/dist/api/game-lib.d.ts +481 -11
  5. package/dist/api/game-lib.typedoc.json +220347 -136841
  6. package/dist/base-node-idopiSw5.d.ts +96 -0
  7. package/dist/bridge.d.ts +27 -5
  8. package/dist/bridge.js +1 -1
  9. package/dist/catalog.d.ts +77 -0
  10. package/dist/catalog.js +1 -0
  11. package/dist/{chunk-CM5YRNBJ.js → chunk-7NYP4YAG.js} +1 -1
  12. package/dist/chunk-AE3CTVHY.js +1 -0
  13. package/dist/chunk-BCFFS3FP.js +1 -0
  14. package/dist/chunk-BMRFDDMR.js +1 -0
  15. package/dist/chunk-DECK4UEC.js +1 -0
  16. package/dist/chunk-DQQA3VJH.js +1 -0
  17. package/dist/chunk-FYQNZCIP.js +1 -0
  18. package/dist/chunk-GHJQ2HKI.js +1 -0
  19. package/dist/chunk-LD4KDRYL.js +24 -0
  20. package/dist/chunk-MXO4VGDB.js +1 -0
  21. package/dist/{chunk-VIPINV7V.js → chunk-Q2YDBMVY.js} +1 -1
  22. package/dist/chunk-QDQ4QMAI.js +1 -0
  23. package/dist/{chunk-TV3AZKT4.js → chunk-QVIUZEYA.js} +1 -1
  24. package/dist/chunk-SAQA4SXW.js +1 -0
  25. package/dist/chunk-VJZMSBKP.js +1 -0
  26. package/dist/chunk-YOVE25NW.js +1 -0
  27. package/dist/{collision-builder-4TVDzXsp.d.ts → collision-builder-BckxkdmA.d.ts} +1 -1
  28. package/dist/core.d.ts +14 -11
  29. package/dist/core.js +1 -1
  30. package/dist/debug-state-B5awuDHl.d.ts +89 -0
  31. package/dist/debug.d.ts +194 -7
  32. package/dist/debug.js +1 -1
  33. package/dist/{entity-DDks47JB.d.ts → entity-BIf_a4dl.d.ts} +1 -1
  34. package/dist/{entity-BI7cSlK8.d.ts → entity-XZNGBeca.d.ts} +32 -98
  35. package/dist/{entity-type-map-COHu4fkW.d.ts → entity-type-map-CkkFMSrL.d.ts} +5 -4
  36. package/dist/entity.d.ts +9 -7
  37. package/dist/entity.js +1 -1
  38. package/dist/{game-4fsy55uN.d.ts → game-Cy8f6gJm.d.ts} +181 -17
  39. package/dist/game-default-F3KPYZ7X.js +1 -0
  40. package/dist/graphics.d.ts +6 -5
  41. package/dist/graphics.js +1 -1
  42. package/dist/{material-BKPYeBC6.d.ts → material-CxxAyJYp.d.ts} +1 -1
  43. package/dist/public.d.ts +12 -10
  44. package/dist/public.js +1 -1
  45. package/dist/runtime.d.ts +3 -3
  46. package/dist/{vector-DPbwlzgG.d.ts → simulation-body-zQw-emOr.d.ts} +1 -40
  47. package/dist/vector-D3eDzvcA.d.ts +41 -0
  48. package/dist/web-components.d.ts +12 -9
  49. package/dist/web-components.js +1 -1
  50. package/dist/{zylem-camera-B73ZNcgs.d.ts → zylem-camera-DZTpPOiD.d.ts} +12 -1
  51. package/package.json +6 -2
  52. package/dist/chunk-3I537JFL.js +0 -1
  53. package/dist/chunk-4CHZUWLF.js +0 -1
  54. package/dist/chunk-6B5JP7T5.js +0 -24
  55. package/dist/chunk-C5NEGC3S.js +0 -1
  56. package/dist/chunk-D3JO4HW2.js +0 -1
  57. package/dist/chunk-LKFF6XJC.js +0 -1
  58. package/dist/chunk-OAWK2UUY.js +0 -1
  59. package/dist/chunk-PNLNC3FA.js +0 -1
  60. package/dist/chunk-W5SXED5T.js +0 -1
  61. package/dist/debug-state-s0s-qndj.d.ts +0 -49
  62. package/dist/game-default-4PPYYGAR.js +0 -1
  63. /package/dist/{chunk-DFLI7ICU.js → chunk-MSCVL5OK.js} +0 -0
@@ -1 +0,0 @@
1
- import{a as P}from"./chunk-PNLNC3FA.js";import{a as Dt,b as Z,c as Y,d as N,e as W,f as X,g as U,h as j,j as q,p as m,q as w,r as c,t as x,u as R,v as $,w as K,x as D}from"./chunk-3I537JFL.js";import{j as kt}from"./chunk-CM5YRNBJ.js";import{d as V,j as Rt}from"./chunk-4QLJUQSJ.js";import{a as It,b as gt,c as zt,d as Lt,g as Bt,h as xt,i as E,j as Ht}from"./chunk-7WRQ2UAN.js";import{Vector3 as Fe}from"three";import{BoxGeometry as ze,CapsuleGeometry as Le,ConeGeometry as Ft,CylinderGeometry as Be,Mesh as I,MeshStandardMaterial as He,SphereGeometry as ke}from"three";function z(i,t=Symbol("mesh")){if(i.material||i.color){let e=new kt;if(e.build({...i.material,color:i.color??i.material?.color},t),e.materials.length>0)return e.materials}return[new He]}function L(i,t){if(t.position){let e=xt(t.position,zt);i.position.set(e.x,e.y,e.z)}return i.castShadow=!0,i.receiveShadow=!0,i}function Q(i={}){let t=xt(i.size,Lt),e=new ze(t.x,t.y,t.z),o=z(i);return L(new I(e,o.at(-1)),i)}function J(i={}){let t=new ke(i.radius??1),e=z(i);return L(new I(t,e.at(-1)),i)}function tt(i={}){let t=new Ft(i.radius??1,i.height??2,i.radialSegments??32),e=z(i);return L(new I(t,e.at(-1)),i)}function et(i={}){let t=new Ft(i.radius??1,i.height??2,4),e=z(i);return L(new I(t,e.at(-1)),i)}function it(i={}){let t=new Be(i.radiusTop??1,i.radiusBottom??1,i.height??2,i.radialSegments??32),e=z(i);return L(new I(t,e.at(-1)),i)}function ot(i={}){let t=new Le(i.radius??.5,i.length??1,i.capSegments??10,i.radialSegments??20),e=z(i);return L(new I(t,e.at(-1)),i)}var Gt={...m,size:new Fe(1,1,1)},At=Symbol("Box"),nt=class i extends c{static type=At;constructor(t){super(),this.options={...Gt,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),{x:o,y:n,z:s}=this.options.size??{x:1,y:1,z:1};return{...e,type:String(i.type),size:`${o}, ${n}, ${s}`}}};function Vt(...i){let t=w(i,Gt),e=new nt(t);return e.add(Q({size:t.size,material:t.material,color:t.color}),Y({size:t.size,static:t.collision?.static,sensor:t.collision?.sensor,canSleep:t.collision?.canSleep,ccdEnabled:t.collision?.ccdEnabled,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Vt(o??{}))}var Yt={...m,radius:1},Nt=Symbol("Sphere"),st=class i extends c{static type=Nt;constructor(t){super(),this.options={...Yt,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1;return{...e,type:String(i.type),radius:o.toFixed(2)}}};function Wt(...i){let t=w(i,Yt),e=new st(t);return e.add(J({radius:t.radius,material:t.material,color:t.color}),N({radius:t.radius,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Wt(o??{}))}import{PlaneGeometry as Ae,Vector2 as Xt,Vector3 as Ut}from"three";import{BufferGeometry as Ge,Float32BufferAttribute as bt}from"three";var rt=class i extends Ge{constructor(t=1,e=1,o=1,n=1){super(),this.type="XZPlaneGeometry",this.parameters={width:t,height:e,widthSegments:o,heightSegments:n};let s=t/2,a=e/2,r=Math.floor(o),l=Math.floor(n),p=r+1,O=l+1,u=t/r,d=e/l,b=[],f=[],y=[],_=[];for(let g=0;g<O;g++){let h=g*d-a;for(let C=0;C<p;C++){let T=C*u-s;f.push(T,0,h),y.push(0,1,0),_.push(C/r),_.push(1-g/l)}}for(let g=0;g<l;g++)for(let h=0;h<r;h++){let C=h+p*g,T=h+p*(g+1),S=h+1+p*(g+1),v=h+1+p*g;b.push(C,T,v),b.push(T,S,v)}this.setIndex(b),this.setAttribute("position",new bt(f,3)),this.setAttribute("normal",new bt(y,3)),this.setAttribute("uv",new bt(_,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new i(t.width,t.height,t.widthSegments,t.heightSegments)}};var at=4,jt={...m,tile:new Xt(10,10),repeat:new Xt(1,1),collision:{static:!0},subdivisions:at,randomizeHeight:!1,heightScale:1};function qt(i){let t=i.subdivisions??at,e=i.heightMap2D,o=i.heightMap,n=i.subdivisionsX??t,s=i.subdivisionsZ??t;return e&&e.length>0&&e[0]?.length>0?(s=e.length-1,n=e[0].length-1):o&&o.length>0&&(n=o.length-1),{subdivisionsX:n,subdivisionsZ:s}}var Ot=class extends ${collider(t){let e=E(t.tile,gt),{subdivisionsX:o,subdivisionsZ:n}=qt(t),s=new Ut(e.x,1,e.y),a=t._builders?.meshBuilder?.heightData??new Float32Array((o+1)*(n+1));return{shape:{type:"heightfield",rows:o,cols:n,heights:a,scale:[s.x,1,s.z]}}}},Pt=class extends K{heightData=new Float32Array;columnsRows=new Map;subdivisionsX=at;subdivisionsZ=at;build(t){let e=E(t.tile,gt),{subdivisionsX:o,subdivisionsZ:n}=qt(t);this.subdivisionsX=o,this.subdivisionsZ=n;let s=new Ut(e.x,1,e.y),a=t.heightScale??1,r=new rt(s.x,s.z,o,n),l=new Ae(s.x,s.z,o,n),p=o>0?s.x/o:1,O=n>0?s.z/n:1,u=r.attributes.position.array,d=l.attributes.position.array,b=new Map,f=t.heightMap2D,y=t.heightMap,_=t.randomizeHeight??!1,g=(h,C)=>h<0?0:h>C?C:h;for(let h=0;h<d.length;h+=3){let C=d[h],T=d[h+1],S=g(Math.round((C+s.x/2)/p),o),v=g(Math.round((s.z/2-T)/O),n),M=0;if(f){let Mt=f[v];Mt&&(M=Mt[S]??0)}else y&&y.length>0?M=y[S]??0:_&&(M=Math.random()*4);let G=M*a;d[h+2]=G,u[h+1]=G,b.get(v)||b.set(v,new Map),b.get(v).set(S,G)}return this.columnsRows=b,r}postBuild(){let t=[];for(let e=0;e<=this.subdivisionsX;++e)for(let o=0;o<=this.subdivisionsZ;++o){let n=this.columnsRows.get(o);t.push(n?.get(e)??0)}this.heightData=new Float32Array(t)}},St=class extends D{createEntity(t){return new B(t)}},$t=Symbol("Plane"),B=class extends c{static type=$t;constructor(t){super(),this.options=Z(jt,t)}};function Kt(...i){return R({args:i,defaultConfig:jt,EntityClass:B,BuilderClass:St,MeshBuilderClass:Pt,CollisionBuilderClass:Ot,entityType:B.type,cloneFactory:t=>Kt(t??{})})}import{Vector3 as Ve}from"three";var Qt={...m,size:new Ve(1,1,1),collision:{static:!0}},Jt=Symbol("Zone"),lt=class extends c{static type=Jt;_enteredZone=new Map;_exitedZone=new Map;_zoneEntities=new Map;constructor(t){super(),this.options=Z(Qt,t)}handlePostCollision({delta:t}){return this._enteredZone.forEach((e,o)=>{this.exited(t,o)}),this._enteredZone.size>0}handleIntersectionEvent({other:t,delta:e}){this._enteredZone.get(t.uuid)?this.held(e,t):(this.entered(t),this._zoneEntities.set(t.uuid,t))}onEnter(t){return this.options.onEnter=t,this}onHeld(t){return this.options.onHeld=t,this}onExit(t){return this.options.onExit=t,this}entered(t){this._enteredZone.set(t.uuid,1),this.options.onEnter&&this.options.onEnter({self:this,visitor:t,globals:V.globals})}exited(t,e){let o=this._exitedZone.get(e);if(o&&o>1+t){this._exitedZone.delete(e),this._enteredZone.delete(e);let n=this._zoneEntities.get(e);this.options.onExit&&this.options.onExit({self:this,visitor:n,globals:V.globals});return}this._exitedZone.set(e,1+t)}held(t,e){let o=this._enteredZone.get(e.uuid)??0;this._enteredZone.set(e.uuid,o+t),this._exitedZone.set(e.uuid,1),this.options.onHeld&&this.options.onHeld({delta:t,self:this,visitor:e,globals:V.globals,heldTime:o})}};function te(...i){let t=w(i,Qt),e=new lt(t);return e.add(q({size:t.size,static:t.collision?.static??!0,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>te(o??{}))}import{Color as ee,Group as Ye,Sprite as Ne,SpriteMaterial as We,CanvasTexture as ie,LinearFilter as ct,Vector2 as pt,ClampToEdgeWrapping as oe,ShaderMaterial as ne,Mesh as Xe,PlaneGeometry as Ue,Vector3 as se}from"three";var H={position:void 0,width:120,height:48,fillColor:"#FFFFFF",strokeColor:null,strokeWidth:0,radius:0,padding:0,stickToViewport:!0,screenPosition:new pt(24,24),zDistance:1,anchor:new pt(0,0)},wt=class extends D{createEntity(t){return new k(t)}},re=Symbol("Rect"),k=class i extends c{static type=re;_sprite=null;_mesh=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=Z(H,t),this.options.screenPosition=E(this.options.screenPosition,H.screenPosition),this.options.anchor=E(this.options.anchor,H.anchor),this.group=new Ye,this.createSprite(),this.prependSetup(this.rectSetup.bind(this)),this.prependUpdate(this.rectUpdate.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new ie(this._canvas),this._texture.minFilter=ct,this._texture.magFilter=ct;let t=new We({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new Ne(t),this.group?.add(this._sprite),this.redrawRect()}redrawRect(){if(!this._canvas||!this._ctx)return;let t=Math.max(2,Math.floor(this.options.width??120)),e=Math.max(2,Math.floor(this.options.height??48)),o=this.options.padding??0,n=this.options.strokeWidth??0,s=t+o*2+n,a=e+o*2+n,r=Math.max(2,s),l=Math.max(2,a),p=r!==this._lastCanvasW||l!==this._lastCanvasH;this._canvas.width=r,this._canvas.height=l,this._lastCanvasW=r,this._lastCanvasH=l,this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height);let O=Math.max(0,this.options.radius??0),u=Math.floor(o+n/2),d=Math.floor(o+n/2),b=Math.floor(t),f=Math.floor(e);if(this._ctx.beginPath(),O>0?this.roundedRectPath(this._ctx,u,d,b,f,O):this._ctx.rect(u,d,b,f),this.options.fillColor&&(this._ctx.fillStyle=this.toCssColor(this.options.fillColor),this._ctx.fill()),this.options.strokeColor&&n>0&&(this._ctx.lineWidth=n,this._ctx.strokeStyle=this.toCssColor(this.options.strokeColor),this._ctx.stroke()),this._texture){if(p&&(this._texture.dispose(),this._texture=new ie(this._canvas),this._texture.minFilter=ct,this._texture.magFilter=ct,this._texture.wrapS=oe,this._texture.wrapT=oe,this._sprite&&this._sprite.material instanceof ne)){let y=this._sprite.material;y.uniforms?.tDiffuse&&(y.uniforms.tDiffuse.value=this._texture),y.uniforms?.iResolution&&y.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)}this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0)}}getWidth(){return this.options.width??0}getHeight(){return this.options.height??0}roundedRectPath(t,e,o,n,s,a){let r=Math.min(a,Math.floor(Math.min(n,s)/2));t.moveTo(e+r,o),t.lineTo(e+n-r,o),t.quadraticCurveTo(e+n,o,e+n,o+r),t.lineTo(e+n,o+s-r),t.quadraticCurveTo(e+n,o+s,e+n-r,o+s),t.lineTo(e+r,o+s),t.quadraticCurveTo(e,o+s,e,o+s-r),t.lineTo(e,o+r),t.quadraticCurveTo(e,o,e+r,o)}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof ee?t:new ee(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}rectSetup(t){if(this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&this._cameraRef.camera.add(this.group),this.materials?.length&&this._sprite){let e=this.materials[0];e instanceof ne&&(e.transparent=!0,e.depthTest=!1,e.depthWrite=!1,this._texture&&(e.uniforms?.tDiffuse&&(e.uniforms.tDiffuse.value=this._texture),e.uniforms?.iResolution&&this._canvas&&e.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)),this._mesh=new Xe(new Ue(1,1),e),this.group?.add(this._mesh),this._sprite.visible=!1)}}rectUpdate(t){if(this._sprite){if(this._cameraRef&&this.options.bounds){let e=this.computeScreenBoundsFromOptions(this.options.bounds);if(e){let{x:o,y:n,width:s,height:a}=e,r=Math.max(2,Math.floor(s)),l=Math.max(2,Math.floor(a)),p=r!==(this.options.width??0)||l!==(this.options.height??0);this.options.screenPosition=new pt(Math.floor(o),Math.floor(n)),this.options.width=r,this.options.height=l,this.options.anchor=new pt(0,0),p&&this.redrawRect()}}this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:o}=this.getResolution(),n=E(this.options.screenPosition,H.screenPosition),s=n.x,a=n.y,r=Math.max(.001,this.options.zDistance??1),l=1,p=1;if(t.isPerspectiveCamera){let S=t,v=Math.tan(S.fov*Math.PI/180/2)*r;l=v*S.aspect,p=v}else if(t.isOrthographicCamera){let S=t;l=(S.right-S.left)/2,p=(S.top-S.bottom)/2}let O=s/e*2-1,u=1-a/o*2,d=O*l,b=u*p,f=1,y=1;if(this._canvas){let v=p*2/o,M=this._canvas.height;y=Math.max(1e-4,M*v);let G=this._canvas.width/this._canvas.height;f=y*G,this._sprite.scale.set(f,y,1),this._mesh&&this._mesh.scale.set(f,y,1)}let _=E(this.options.anchor,H.anchor),g=Math.min(100,Math.max(0,_.x))/100,h=Math.min(100,Math.max(0,_.y))/100,C=(.5-g)*f,T=(h-.5)*y;this.group?.position.set(d+C,b+T,-r)}worldToScreen(t){if(!this._cameraRef)return{x:0,y:0};let e=this._cameraRef.camera,{width:o,height:n}=this.getResolution(),s=t.clone().project(e),a=(s.x+1)/2*o,r=(1-s.y)/2*n;return{x:a,y:r}}computeScreenBoundsFromOptions(t){if(!this._cameraRef)return null;if(t.screen)return{...t.screen};if(t.world){let{left:e,right:o,top:n,bottom:s,z:a=0}=t.world,r=this.worldToScreen(new se(e,n,a)),l=this.worldToScreen(new se(o,s,a)),p=Math.min(r.x,l.x),O=Math.min(r.y,l.y),u=Math.abs(l.x-r.x),d=Math.abs(l.y-r.y);return{x:p,y:O,width:u,height:d}}return null}updateRect(t){this.options={...this.options,...t},this.redrawRect(),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new P(this).buildDebugInfo(),type:String(i.type),width:this.options.width??0,height:this.options.height??0,sticky:this.options.stickToViewport}}};function ae(...i){return R({args:i,defaultConfig:{...H},EntityClass:k,BuilderClass:wt,entityType:k.type,cloneFactory:t=>ae(t??{})})}import{Group as je,RingGeometry as qe}from"three";var le={...m,innerRadius:0,outerRadius:1,thetaSegments:32},Ct=class extends ${collider(t){let e=t.outerRadius??1;return{shape:{type:"cylinder",halfHeight:.1/2,radius:e}}}},vt=class extends K{build(t){let e=t.innerRadius??0,o=t.outerRadius??1,n=t.thetaSegments??32,s=new qe(e,o,n);return s.rotateX(-Math.PI/2),s}},_t=class extends D{createEntity(t){return new F(t)}build(){let t=super.build();return t.mesh&&!t.group&&(t.group=new je,t.group.add(t.mesh)),t}},ce=Symbol("Disk"),F=class i extends c{static type=ce;constructor(t){super(),this.options={...le,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.innerRadius??0,n=this.options.outerRadius??1;return{...e,type:String(i.type),innerRadius:o.toFixed(2),outerRadius:n.toFixed(2)}}};function pe(...i){return R({args:i,defaultConfig:le,EntityClass:F,BuilderClass:_t,MeshBuilderClass:vt,CollisionBuilderClass:Ct,entityType:F.type,cloneFactory:t=>pe(t??{})})}var he={...m,radius:1,height:2,radialSegments:32},me=Symbol("Cone"),ht=class i extends c{static type=me;constructor(t){super(),this.options={...he,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1,n=this.options.height??2;return{...e,type:String(i.type),radius:o.toFixed(2),height:n.toFixed(2)}}};function ue(...i){let t=w(i,he),e=new ht(t);return e.add(tt({radius:t.radius,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),W({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>ue(o??{}))}var de={...m,radius:1,height:2},ye=Symbol("Pyramid"),mt=class i extends c{static type=ye;constructor(t){super(),this.options={...de,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1,n=this.options.height??2;return{...e,type:String(i.type),radius:o.toFixed(2),height:n.toFixed(2)}}};function fe(...i){let t=w(i,de),e=new mt(t);return e.add(et({radius:t.radius,height:t.height,material:t.material,color:t.color}),X({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>fe(o??{}))}var ge={...m,radiusTop:1,radiusBottom:1,height:2,radialSegments:32},xe=Symbol("Cylinder"),ut=class i extends c{static type=xe;constructor(t){super(),this.options={...ge,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radiusTop??1,n=this.options.radiusBottom??1,s=this.options.height??2;return{...e,type:String(i.type),radiusTop:o.toFixed(2),radiusBottom:n.toFixed(2),height:s.toFixed(2)}}};function be(...i){let t=w(i,ge),e=new ut(t);return e.add(it({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),U({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>be(o??{}))}var Oe={...m,radius:.5,length:1,capSegments:10,radialSegments:20},Pe=Symbol("Pill"),dt=class i extends c{static type=Pe;constructor(t){super(),this.options={...Oe,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??.5,n=this.options.length??1;return{...e,type:String(i.type),radius:o.toFixed(2),length:n.toFixed(2)}}};function Se(...i){let t=w(i,Oe),e=new dt(t);return e.add(ot({radius:t.radius,length:t.length,capSegments:t.capSegments,radialSegments:t.radialSegments,material:t.material,color:t.color}),j({radius:t.radius,length:t.length,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Se(o??{}))}import{Group as $e,Quaternion as Ke,Vector3 as Qe}from"three";import{ParticleEmitterBehavior as Et}from"@zylem/behaviors/particle-emitter";var Je={...m,effect:{create(){throw new Error("createParticleSystem(...) requires an effect or preset definition.")}},preset:void 0,autoplay:!0,localOffset:void 0,followPosition:!0,followRotation:!0,autoDestroy:!1},we=Symbol("ParticleSystem");function ti(i){return{effect:i.preset??i.effect,autoplay:i.autoplay,localOffset:i.localOffset,followPosition:i.followPosition,followRotation:i.followRotation,autoDestroy:i.autoDestroy}}var yt=class i extends c{static type=we;particleHandle=null;constructor(t,e=!0){super(),this.options=Z(Je,t),this.group=new $e;let o=this.options.position;o&&this.group.position.copy(Ht(o)),this.__zylemParticleSystemEntity=!0,this.bindStandaloneTransforms(),e&&(this.particleHandle=this.use(Et,ti(this.options)))}bindStandaloneTransforms(){let t=()=>{this.options.position=new Qe(this.group?.position.x??0,this.group?.position.y??0,this.group?.position.z??0)},e=()=>{this.group&&(this._rotation2DAngle=this.group.rotation.z)};this.setPosition=(o,n,s)=>{this.group?.position.set(o,n,s),t()},this.setPositionX=o=>{this.group&&(this.group.position.x=o,t())},this.setPositionY=o=>{this.group&&(this.group.position.y=o,t())},this.setPositionZ=o=>{this.group&&(this.group.position.z=o,t())},this.getPosition=()=>this.group?{x:this.group.position.x,y:this.group.position.y,z:this.group.position.z}:null,this.setRotation=(o,n,s)=>{this.group?.rotation.set(o,n,s),e()},this.setRotationX=o=>{this.group&&(this.group.rotation.x=o,e())},this.setRotationY=o=>{this.group&&(this.group.rotation.y=o,e())},this.setRotationZ=o=>{this.group&&(this.group.rotation.z=o,e())},this.setRotationDegrees=(o,n,s)=>{this.group?.rotation.set(o*Math.PI/180,n*Math.PI/180,s*Math.PI/180),e()},this.setRotationDegreesX=o=>{this.group&&(this.group.rotation.x=o*Math.PI/180,e())},this.setRotationDegreesY=o=>{this.group&&(this.group.rotation.y=o*Math.PI/180,e())},this.setRotationDegreesZ=o=>{this.group&&(this.group.rotation.z=o*Math.PI/180,e())},this.rotateX=o=>{this.group?.rotateX(o),e()},this.rotateY=o=>{this.group?.rotateY(o),e()},this.rotateZ=o=>{this.group?.rotateZ(o),e()},this.getRotation=()=>{if(!this.group)return null;let o=new Ke;return this.group.getWorldQuaternion(o),o}}resolveParticleHandle(){if(this.particleHandle)return this.particleHandle;let t=this.getBehaviorRefs().find(n=>n.descriptor.key===Et.key);if(!t)return null;let e={getFSM:()=>t.fsm??null,getOptions:()=>t.options,ref:t},o=Et.createHandle?.(t)??{};return this.particleHandle={...e,...o},this.particleHandle}play(){this.resolveParticleHandle()?.play()}stop(){this.resolveParticleHandle()?.stop()}pause(){this.resolveParticleHandle()?.pause()}restart(){this.resolveParticleHandle()?.restart()}burst(){this.resolveParticleHandle()?.burst()}isPlaying(){return this.resolveParticleHandle()?.isPlaying()??!1}getSystem(){return this.resolveParticleHandle()?.getSystem()}buildInfo(){return{...super.buildInfo(),type:String(i.type)}}};function Ce(i,t=!0){let e=new yt(i,t);return x(e,o=>Ce(o,!1))}function ei(i){return Ce(i,!0)}import{AmbientLight as ii,DirectionalLight as oi,Group as ni,HemisphereLight as si,Object3D as ri,PointLight as ai,SpotLight as li}from"three";var ve=Symbol("Light"),ci={x:0,y:0,z:0},A=16777215,pi={mapSize:2048,near:.1,far:500,bias:0,radius:1,left:-100,right:100,top:100,bottom:-100},hi={mapSize:1024,near:.1,far:500,bias:0,radius:1},ft=class extends c{static type=ve;light=null;lightTarget=null;constructor(t){super(),this.options={...t}}create(){super.create();let t=new ni,{light:e,target:o}=mi(this.options);return t.add(e),o&&t.add(o),this.group=t,this.light=e,this.lightTarget=o,this}_cleanup(t){this.light?.shadow?.map?.dispose?.(),this.light=null,this.lightTarget=null,super._cleanup(t)}};function mi(i){switch(i.type){case"ambient":return{light:ui(i),target:null};case"hemisphere":return{light:di(i),target:null};case"directional":return yi(i);case"point":return{light:fi(i),target:null};case"spot":return gi(i)}}function ui(i){let t=new ii(i.color??A,i.intensity??1);return i.name&&(t.name=i.name),t}function di(i){let t=i.skyColor??i.color??A,e=i.groundColor??0,o=new si(t,e,i.intensity??1);return i.name&&(o.name=i.name),o}function yi(i){let t=new oi(i.color??A,i.intensity??1);i.name&&(t.name=i.name),xi(t,i.castShadow??!1,i.shadow);let e=_e(i.position,i.target);return e&&(t.target=e),{light:t,target:e}}function fi(i){let t=new ai(i.color??A,i.intensity??1,i.distance,i.decay);return i.name&&(t.name=i.name),Ee(t,i.castShadow??!1,i.shadow),t}function gi(i){let t=new li(i.color??A,i.intensity??1,i.distance,i.angle,i.penumbra,i.decay);i.name&&(t.name=i.name),Ee(t,i.castShadow??!1,i.shadow);let e=_e(i.position,i.target);return e&&(t.target=e),{light:t,target:e}}function _e(i,t){if(!t)return null;let e=i??ci,o=new ri;return o.position.set(t.x-e.x,t.y-e.y,t.z-e.z),o}function xi(i,t,e){if(!t){i.castShadow=!1;return}i.castShadow=!0;let o={...pi,...e??{}};i.shadow.mapSize.set(o.mapSize,o.mapSize),i.shadow.camera.near=o.near,i.shadow.camera.far=o.far,i.shadow.camera.left=o.left,i.shadow.camera.right=o.right,i.shadow.camera.top=o.top,i.shadow.camera.bottom=o.bottom,i.shadow.bias=o.bias,i.shadow.radius=o.radius,i.shadow.camera.updateProjectionMatrix()}function Ee(i,t,e){if(!t){i.castShadow=!1;return}i.castShadow=!0;let o={...hi,...e??{}};i.shadow.mapSize.set(o.mapSize,o.mapSize),i.shadow.camera.near=o.near,i.shadow.camera.far=o.far,i.shadow.bias=o.bias,i.shadow.radius=o.radius,i.shadow.camera.updateProjectionMatrix()}function bi(i){return new ft(i)}import{Group as Oi,Sprite as Pi,SpriteMaterial as Si,CanvasTexture as wi,LinearFilter as Ze,Color as Te,ClampToEdgeWrapping as Me}from"three";import{getCooldown as Re}from"@zylem/behaviors/cooldown";var Ci={"top-left":{fx:0,fy:0},"top-center":{fx:.5,fy:0},"top-right":{fx:1,fy:0},"center-left":{fx:0,fy:.5},center:{fx:.5,fy:.5},"center-right":{fx:1,fy:.5},"bottom-left":{fx:0,fy:1},"bottom-center":{fx:.5,fy:1},"bottom-right":{fx:1,fy:1}},De=192,vi={xs:8,sm:16,md:32,lg:48,xl:64},Zt={position:void 0,cooldown:"",iconSize:"md",fillColor:"#333333",showTimer:!0,stickToViewport:!0,screenAnchor:"top-left",screenPosition:{x:0,y:0},zDistance:1,overlayColor:"rgba(0, 0, 0, 0.65)"},_i=Symbol("CooldownIcon"),Tt=class extends c{static type=_i;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_iconTexture=null;_iconImage=null;_lastRenderedProgress=-1;constructor(t){super(),this.options=Z(Zt,t),this.options.screenPosition=E(this.options.screenPosition,Zt.screenPosition),this.group=new Oi,this.createSprite(),this.prependSetup(this.iconSetup.bind(this)),this.prependUpdate(this.iconUpdate.bind(this)),this.onCleanup(this.iconDestroy.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._canvas.width=256,this._canvas.height=256,this._ctx=this._canvas.getContext("2d"),this._texture=new wi(this._canvas),this._texture.minFilter=Ze,this._texture.magFilter=Ze,this._texture.wrapS=Me,this._texture.wrapT=Me;let e=new Si({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1});if(this._sprite=new Pi(e),this.group?.add(this._sprite),this.options.icon){let o=new Image;o.crossOrigin="anonymous",o.onload=()=>{this._iconImage=o,this.redraw(this._lastRenderedProgress>=0?this._lastRenderedProgress:1)},o.src=this.options.icon}this.redraw(1)}redraw(t){if(!this._canvas||!this._ctx)return;let e=this._ctx,o=this._canvas.width,n=this._canvas.height,s=o/2,a=n/2,r=Math.min(s,a);if(e.clearRect(0,0,o,n),this._iconImage?e.drawImage(this._iconImage,0,0,o,n):(e.fillStyle=this.toCssColor(this.options.fillColor??"#333333"),e.fillRect(0,0,o,n)),t<1){let l=(1-t)*Math.PI*2,p=-Math.PI/2,O=p+l;if(e.save(),e.fillStyle=this.options.overlayColor??"rgba(0, 0, 0, 0.65)",e.beginPath(),e.moveTo(s,a),e.arc(s,a,r+1,p,O,!1),e.closePath(),e.fill(),e.restore(),this.options.showTimer){let u=Re(this.options.cooldown);if(u){let d=Math.max(0,u.duration-u.elapsed),b=d>=10?Math.ceil(d).toString():d.toFixed(1),f=Math.floor(o*.3);e.font=`bold ${f}px sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillStyle="#FFFFFF",e.strokeStyle="#000000",e.lineWidth=2,e.strokeText(b,s,a),e.fillText(b,s,a)}}}this._texture&&(this._texture.needsUpdate=!0),this._lastRenderedProgress=t}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof Te?t:new Te(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}iconSetup(t){this._sprite||this.createSprite(),this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}iconUpdate(t){let o=Re(this.options.cooldown)?.progress??1;(Math.abs(o-this._lastRenderedProgress)>.02||o===1&&this._lastRenderedProgress!==1)&&this.redraw(o),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}resolveScreenPosition(t,e){let o=this.options.screenAnchor??"top-left",n=Bt(this.options.screenPosition,It),s=n.x,a=n.y,{fx:r,fy:l}=Ci[o],p=r*t,O=l*e,u=e/De;return{px:p+s*u,py:O+a*u}}resolveIconSize(t){let e=this.options.iconSize??"md",o,n;typeof e=="string"?o=n=vi[e]:typeof e=="number"?o=n=e:(o=e.width,n=e.height);let s=t/De;return{widthPx:o*s,heightPx:n*s}}computeWorldExtents(t,e){let o=1,n=1;if(t.isPerspectiveCamera){let s=t,a=Math.tan(s.fov*Math.PI/180/2)*e;o=a*s.aspect,n=a}else if(t.isOrthographicCamera){let s=t;o=(s.right-s.left)/2,n=(s.top-s.bottom)/2}return{worldHalfW:o,worldHalfH:n}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:o}=this.getResolution(),{px:n,py:s}=this.resolveScreenPosition(e,o),a=Math.max(.001,this.options.zDistance??1),{worldHalfW:r,worldHalfH:l}=this.computeWorldExtents(t,a),p=n/e*2-1,O=1-s/o*2,u=p*r,d=O*l;{let f=l*2/o,{widthPx:y,heightPx:_}=this.resolveIconSize(o),g=Math.max(1e-4,y*f),h=Math.max(1e-4,_*f);this._sprite.scale.set(g,h,1)}this.group?.position.set(u,d,-a)}iconDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._iconTexture?.dispose(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null,this._iconTexture=null,this._iconImage=null}};function Ie(...i){let t=i.filter(o=>!(o instanceof Dt)),e={...Zt};for(let o of t)e={...e,...o};return x(new Tt(e),o=>Ie(o??{}))}function Ei(i,t,e){e({me:i,globals:t})}function Zi(i,t){let e=t??Rt();Ei(i,e,i.nodeDestroy.bind(i))}export{Q as a,J as b,tt as c,et as d,it as e,ot as f,At as g,nt as h,Vt as i,Nt as j,st as k,Wt as l,$t as m,B as n,Kt as o,Jt as p,lt as q,te as r,re as s,k as t,ae as u,ce as v,F as w,pe as x,me as y,ht as z,ue as A,ye as B,mt as C,fe as D,xe as E,ut as F,be as G,Pe as H,dt as I,Se as J,we as K,yt as L,ei as M,ve as N,ft as O,bi as P,Ie as Q,Zi as R};
@@ -1 +0,0 @@
1
- import{b as d,p as b,q as V,r as y,t as D,u as C,v as B,x as v}from"./chunk-3I537JFL.js";import{c as k}from"./chunk-CM5YRNBJ.js";import{c as m,d as f,h as u,i as E,j as x}from"./chunk-7WRQ2UAN.js";import{Color as $,Group as lt,Sprite as ct,SpriteMaterial as ht,CanvasTexture as U,LinearFilter as w,Vector2 as mt,ClampToEdgeWrapping as H}from"three";import{MeshStandardMaterial as rt,MeshBasicMaterial as ot,MeshPhongMaterial as at}from"three";function pt(i){return i&&typeof i.getDebugInfo=="function"}var c=class{entity;constructor(t){this.entity=t}getPositionString(){if(this.entity.mesh){let{x:r,y:s,z:o}=this.entity.mesh.position;return`${r.toFixed(2)}, ${s.toFixed(2)}, ${o.toFixed(2)}`}let{x:t,y:e,z:n}=this.entity.options.position||{x:0,y:0,z:0};return`${t.toFixed(2)}, ${e.toFixed(2)}, ${n.toFixed(2)}`}getRotationString(){if(this.entity.mesh){let{x:s,y:o,z:a}=this.entity.mesh.rotation,p=l=>(l*180/Math.PI).toFixed(1);return`${p(s)}\xB0, ${p(o)}\xB0, ${p(a)}\xB0`}let{x:t,y:e,z:n}=this.entity.options.rotation||{x:0,y:0,z:0},r=s=>(s*180/Math.PI).toFixed(1);return`${r(t)}\xB0, ${r(e)}\xB0, ${r(n)}\xB0`}getMaterialInfo(){if(!this.entity.mesh||!this.entity.mesh.material)return{type:"none"};let t=Array.isArray(this.entity.mesh.material)?this.entity.mesh.material[0]:this.entity.mesh.material,e={type:t.type};return(t instanceof rt||t instanceof ot||t instanceof at)&&(e.color=`#${t.color.getHexString()}`,e.opacity=t.opacity,e.transparent=t.transparent),"roughness"in t&&(e.roughness=t.roughness),"metalness"in t&&(e.metalness=t.metalness),e}getPhysicsInfo(){if(!this.entity.body)return null;let t={type:this.entity.body.bodyType(),mass:this.entity.body.mass(),isEnabled:this.entity.body.isEnabled(),isSleeping:this.entity.body.isSleeping()},e=this.entity.body.linvel();return t.velocity=`${e.x.toFixed(2)}, ${e.y.toFixed(2)}, ${e.z.toFixed(2)}`,t}buildDebugInfo(){let t={name:this.entity.name||this.entity.uuid,uuid:this.entity.uuid,position:this.getPositionString(),rotation:this.getRotationString(),material:this.getMaterialInfo()},e=this.getPhysicsInfo();if(e&&(t.physics=e),pt(this.entity)){let n=this.entity.getDebugInfo();return{...t,...n}}return t}};var g={position:void 0,text:"",fontFamily:'Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',fontSize:18,fontColor:"#FFFFFF",backgroundColor:null,padding:4,stickToViewport:!0,screenPosition:new mt(24,24),zDistance:1},O=class extends v{createEntity(t){return new S(t)}},ut=Symbol("Text"),S=class i extends y{static type=ut;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=d(g,t),this.options.screenPosition=E(this.options.screenPosition,g.screenPosition),this.prependSetup(this.textSetup.bind(this)),this.prependUpdate(this.textUpdate.bind(this)),this.onCleanup(this.textDestroy.bind(this))}create(){return this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._lastCanvasW=0,this._lastCanvasH=0,this.group=new lt,this.createSprite(),super.create()}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new U(this._canvas),this._texture.minFilter=w,this._texture.magFilter=w;let t=new ht({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new ct(t),this.group?.add(this._sprite),this.redrawText(this.options.text??"")}measureAndResizeCanvas(t,e,n,r){if(!this._canvas||!this._ctx)return{sizeChanged:!1};this._ctx.font=`${e}px ${n}`;let s=this._ctx.measureText(t),o=Math.ceil(s.width),a=Math.ceil(e*1.4),p=Math.max(2,o+r*2),l=Math.max(2,a+r*2),T=p!==this._lastCanvasW||l!==this._lastCanvasH;return this._canvas.width=p,this._canvas.height=l,this._lastCanvasW=p,this._lastCanvasH=l,{sizeChanged:T}}drawCenteredText(t,e,n){!this._canvas||!this._ctx||(this._ctx.font=`${e}px ${n}`,this._ctx.textAlign="center",this._ctx.textBaseline="middle",this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this.options.backgroundColor&&(this._ctx.fillStyle=this.toCssColor(this.options.backgroundColor),this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height)),this._ctx.fillStyle=this.toCssColor(this.options.fontColor??"#FFFFFF"),this._ctx.fillText(t,this._canvas.width/2,this._canvas.height/2))}updateTexture(t){!this._texture||!this._canvas||(t&&(this._texture.dispose(),this._texture=new U(this._canvas),this._texture.minFilter=w,this._texture.magFilter=w,this._texture.wrapS=H,this._texture.wrapT=H),this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0))}redrawText(t){if(!this._canvas||!this._ctx)return;let e=this.options.fontSize??18,n=this.options.fontFamily??g.fontFamily,r=this.options.padding??4,{sizeChanged:s}=this.measureAndResizeCanvas(t,e,n,r);this.drawCenteredText(t,e,n),this.updateTexture(!!s),this.options.stickToViewport&&this._cameraRef?this.updateStickyTransform():this.updateWorldSpriteScale()}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof $?t:new $(t)).getHexString()}`}textSetup(t){this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}textUpdate(t){this._sprite&&this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}getResolution(){return{width:this._cameraRef?.screenResolution.x??1,height:this._cameraRef?.screenResolution.y??1}}getScreenPixels(t,e,n){let r=t.x>=0&&t.x<=1,s=t.y>=0&&t.y<=1;return{px:r?t.x*e:t.x,py:s?t.y*n:t.y}}computeWorldExtents(t,e){let n=1,r=1;if(t.isPerspectiveCamera){let s=t,o=Math.tan(s.fov*Math.PI/180/2)*e;n=o*s.aspect,r=o}else if(t.isOrthographicCamera){let s=t;n=(s.right-s.left)/2,r=(s.top-s.bottom)/2}return{worldHalfW:n,worldHalfH:r}}updateSpriteScale(t,e){if(!this._canvas||!this._sprite)return;let r=t*2/e,s=this._canvas.height,o=Math.max(1e-4,s*r),a=this._canvas.width/this._canvas.height,p=o*a;this._sprite.scale.set(p,o,1)}updateWorldSpriteScale(){if(!this._canvas||!this._sprite)return;let t=this._canvas.width/Math.max(1,this._canvas.height),e=Math.max(1,this.options.fontSize??18),n=Math.max(.25,e/32),r=n*t;this._sprite.scale.set(r,n,1)}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:n}=this.getResolution(),r=E(this.options.screenPosition,g.screenPosition),{px:s,py:o}=this.getScreenPixels(r,e,n),a=Math.max(.001,this.options.zDistance??1),{worldHalfW:p,worldHalfH:l}=this.computeWorldExtents(t,a),T=s/e*2-1,it=1-o/n*2,nt=T*p,st=it*l;this.group?.position.set(nt,st,-a),this.updateSpriteScale(l,n)}updateText(t){this.options.text=t,this.redrawText(t),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),text:this.options.text??"",sticky:this.options.stickToViewport}}textDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null}};function F(...i){return C({args:i,defaultConfig:{...g},EntityClass:S,BuilderClass:O,entityType:S.type,cloneFactory:t=>F(t??{})})}import{Euler as dt,Group as W,Quaternion as yt,Vector3 as ft}from"three";import{TextureLoader as X,SpriteMaterial as N,Sprite as Y,SRGBColorSpace as j}from"three";import{ClampToEdgeWrapping as Q,LinearFilter as xt,NearestFilter as gt}from"three";var q={...b,size:new ft(1,1,1),images:[],animations:[]},I=class extends B{collider(t){let e=x(t.collisionSize,t.size??f);return{shape:{type:"box",halfExtents:[e.x/2,e.y/2,e.z/2]}}}},R=class extends v{createEntity(t){return new _(t)}},St=Symbol("Sprite"),_=class i extends y{static type=St;sprites=[];spriteMap=new Map;currentSpriteIndex=0;animations=new Map;currentAnimation=null;currentAnimationFrame="";currentAnimationIndex=0;currentAnimationTime=0;sheetTexture=null;flippedX=!1;constructor(t){super(),this.options=d(q,t),this.prependSetup(this.spriteSetup.bind(this)),this.prependUpdate(this.spriteUpdate.bind(this)),this.onCleanup(this.spriteDestroy.bind(this))}create(){return this.sprites=[],this.spriteMap.clear(),this.animations.clear(),this.currentAnimation=null,this.currentAnimationFrame="",this.currentAnimationIndex=0,this.currentAnimationTime=0,this.sheetTexture=null,this.group=void 0,this.options?.sheet?this.createSpriteFromSheet(this.options.sheet):this.createSpritesFromImages(this.options?.images||[]),this.createAnimations(this.options?.animations||[]),super.create()}createSpritesFromImages(t){let e=new X,n=x(this.options.size,f);t.forEach((r,s)=>{let o=e.load(r.file);o.colorSpace=j,o.anisotropy=k;let a=new N({map:o,transparent:!0}),p=new Y(a);p.position.normalize(),p.scale.set(n.x,n.y,n.z),p.visible=s===0,this.sprites.push(p),this.spriteMap.set(r.name,s)}),this.group=new W,this.group.add(...this.sprites)}createSpriteFromSheet(t){let e=x(this.options.size,f),n=new X().load(t.file);n.colorSpace=j,n.wrapS=Q,n.wrapT=Q;let r=t.filter==="linear"?xt:gt;n.magFilter=r,n.minFilter=r,n.generateMipmaps=!1,n.repeat.set(1/t.columns,1/t.rows);let s=new N({map:n,transparent:!0}),o=new Y(s);o.position.normalize(),o.scale.set(e.x,e.y,e.z),this.sheetTexture=n,this.sprites.push(o),t.frames.forEach((p,l)=>{p&&this.spriteMap.set(p,l)}),this.group=new W,this.group.add(o);let a=t.frames.find(p=>!!p);a&&this.setSprite(a)}createAnimations(t){t.forEach(e=>{let{name:n,frames:r,loop:s=!1,speed:o=1}=e,a={frames:r.map((p,l)=>({key:p,index:l,duration:typeof o=="number"?o:o[l]})),loop:s};this.animations.set(n,a)})}setSprite(t){let n=this.spriteMap.get(t)??0;if(this.currentSpriteIndex=n,this.sheetTexture){this.applySheetFrame(n);return}this.sprites.forEach((r,s)=>{r.visible=this.currentSpriteIndex===s})}setFlipX(t){if(this.flippedX!==t){if(this.flippedX=t,this.sheetTexture){this.applySheetFrame(this.currentSpriteIndex);return}this.sprites.forEach(e=>{e.material.map?.repeat.setX(t?-1:1),e.material.map?.offset.setX(t?1:0)})}}isFlippedX(){return this.flippedX}applySheetFrame(t){let e=this.options.sheet,n=this.sheetTexture;if(!e||!n)return;let r=t%e.columns,s=Math.floor(t/e.columns),o=1/e.columns,a=1/e.rows;n.repeat.x=this.flippedX?-o:o,n.offset.x=this.flippedX?(r+1)*o:r*o,n.offset.y=1-(s+1)*a}setAnimation(t,e){let n=this.animations.get(t);if(!n)return;let{loop:r,frames:s}=n;if(s.length!==0){for(t!==this.currentAnimation?(this.currentAnimation=t,this.currentAnimationIndex=0,this.currentAnimationTime=0):this.currentAnimationTime+=e;;){let o=s[this.currentAnimationIndex].duration;if(!(o>0)||this.currentAnimationTime<o)break;if(this.currentAnimationTime-=o,this.currentAnimationIndex+1<s.length)this.currentAnimationIndex++;else if(r)this.currentAnimationIndex=0;else{this.currentAnimationTime=0;break}}this.currentAnimationFrame=s[this.currentAnimationIndex].key,this.setSprite(this.currentAnimationFrame)}}getCurrentRotationQuaternion(){return this.transformStore?.dirty.rotation?this.transformStore.rotation:this.body?.rotation?.()??null}syncSpriteMaterials(){let t=this.getCurrentRotationQuaternion();this.sprites.forEach(e=>{if(e.material&&t){let r=new yt(t.x,t.y,t.z,t.w),s=new dt().setFromQuaternion(r,"XYZ");e.material.rotation=s.z}let n=x(this.options.size,f);e.scale.set(n.x,n.y,n.z)})}spriteSetup(t){this.syncSpriteMaterials()}spriteUpdate(t){this.syncSpriteMaterials()}spriteDestroy(t){this.sprites.forEach(e=>{e.removeFromParent()}),this.group?.remove(...this.sprites),this.group?.removeFromParent(),this.sheetTexture?.dispose(),this.sheetTexture=null}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type)}}};function z(...i){return C({args:i,defaultConfig:q,EntityClass:_,BuilderClass:R,CollisionBuilderClass:I,entityType:_.type,cloneFactory:t=>z(t??{})})}import{Color as tt,Group as bt}from"three";import{Line2NodeMaterial as Ct}from"three/webgpu";import{Line2 as vt}from"three/addons/lines/webgpu/Line2.js";import{Color as J}from"three";import{LineGeometry as _t}from"three/addons/lines/LineGeometry.js";function P(i){let t=[];for(let e of i){let{x:n,y:r,z:s}=u(e,m);t.push(n,r,s)}return t}function L(i,t,e){if(!i||i.length===0)return;let n=[],r=new J(e);for(let s=0;s<t;s++){let o=i[s]??i[i.length-1]??e,a=new J(o??r);n.push(a.r,a.g,a.b)}return n}function K(i){let t=new _t,e=P(i.points);t.setPositions(e);let n=L(i.colors,i.points.length,"#ffffff");return n&&t.setColors(n),t}var h={...b,points:[{x:0,y:0,z:0},{x:1,y:0,z:0}],linewidth:1,worldUnits:!0,alphaToCoverage:!1,opacity:1,transparent:!1,dashed:!1,dashSize:1,gapSize:1,pickThreshold:0},wt=Symbol("Line");function M(i,t){if(!i||i.length<2)throw new Error(`${t}: at least two points are required`);return i}function et(i){return i instanceof tt?i.clone():new tt(i??"#ffffff")}function Tt(i){let t=!!i.colors?.length,e=new Ct({color:et(i.color).getHex(),linewidth:i.linewidth??h.linewidth,worldUnits:i.worldUnits??h.worldUnits,vertexColors:t,dashed:i.dashed??!1,dashSize:i.dashSize??h.dashSize,gapSize:i.gapSize??h.gapSize,transparent:i.transparent??!1,opacity:i.opacity??1});return e.alphaToCoverage=i.alphaToCoverage??!1,e}function Et(i){return!i.point||!i.pointOnLine||i.faceIndex==null?null:{point:i.point.clone(),pointOnLine:i.pointOnLine.clone(),faceIndex:i.faceIndex,distance:i.distance}}function Ot(i,t,e={}){let n=t.getLineObject();if(!n)return null;let r=e.threshold??t.options.pickThreshold??0,s=i.params.Line2??{threshold:0};s.threshold=r,i.params.Line2=s;let a=i.intersectObject(n,!1)[0];return a?Et(a):null}var Z=class i extends y{static type=wt;_line=null;_geometry=null;_material=null;constructor(t){super();let e=d(h,t);e.points=M(e.points,"ZylemLine").map(n=>u(n,m)),this.options=e}create(){return this.disposeLineResources(),this.group=new bt,this.rebuildLine(),this.applyGroupPosition(),super.create()}setPoints(t,e){if(M(t,"setPoints"),this.options.points=t.map(r=>u(r,m)),e&&(this.options.colors=e),!this._line||!this._geometry||!this._material)return this;this._geometry.setPositions(P(this.options.points));let n=L(this.options.colors,this.options.points.length,et(this.options.color));return n&&this._geometry.setColors(n),this._material.vertexColors=!!this.options.colors?.length,this.options.dashed&&this._line.computeLineDistances(),this._geometry.computeBoundingBox(),this._geometry.computeBoundingSphere(),this}getLineObject(){return this._line}pickFromRaycaster(t,e={}){return Ot(t,this,e)}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),points:this.options.points.length,linewidth:this.options.linewidth??h.linewidth,worldUnits:this.options.worldUnits??h.worldUnits}}rebuildLine(){this._geometry=K({points:this.options.points,colors:this.options.colors}),this._material=Tt(this.options),this._line=new vt(this._geometry,this._material),this.options.dashed&&this._line.computeLineDistances(),this.group?.add(this._line)}applyGroupPosition(){if(!this.group)return;let t=u(this.options.position,m);this.group.position.set(t.x,t.y,t.z)}_cleanup(t){this.disposeLineResources(),super._cleanup(t)}disposeLineResources(){this._line?.removeFromParent(),this._geometry?.dispose(),this._material?.dispose(),this._line=null,this._geometry=null,this._material=null}};function A(...i){let t=V(i,h);M(t.points,"createLine");let e=new Z(t);return D(e,n=>A(n??{}))}var G={registry:new Map,register(i,t){this.registry.set(i,t)},createFromBlueprint(i){let t=this.registry.get(i.type);if(!t)throw new Error(`Unknown entity type: ${i.type}`);let e={...i.data,position:i.position?{x:i.position[0],y:i.position[1],z:0}:void 0,name:i.id};return t(e)}};G.register("text",i=>F(i));G.register("sprite",i=>z(i));G.register("line",i=>A(i));function we(i){return{template:i,generate(t){let e=[];for(let n=0;n<t;n++)e.push(i.clone());return e}}}export{c as a,ut as b,S as c,F as d,St as e,_ as f,z as g,wt as h,Ot as i,Z as j,A as k,G as l,we as m};
@@ -1 +0,0 @@
1
- import{proxy as u}from"valtio/vanilla";var e=u({enabled:!1,paused:!1,tool:"none",selectedEntityId:null,hoveredEntityId:null,flags:new Set}),o=null;function a(t){return o=t,()=>{o===t&&(o=null)}}function l(t){return!t||!o?null:o(t)}function i(t,n){if(t==null)return null;if(typeof t=="string")return t;let r=t.uuid;if(typeof r=="string")return console.warn(`${n}: received a live entity. Pass the UUID instead \u2014 storing entities in debugState makes valtio deep-proxy the scene graph.`),r;throw new TypeError(`${n} expects an entity UUID string or null, received ${typeof t}.`)}function g(){return e.paused}function c(t){e.paused=t}function E(){return e.tool}function p(t){e.tool=t}function f(){return e.selectedEntityId}function d(t){let n=i(t,"setSelectedEntityId");e.selectedEntityId!==n&&(e.selectedEntityId=n)}function v(){return e.hoveredEntityId}function s(t){let n=i(t,"setHoveredEntityId");e.hoveredEntityId!==n&&(e.hoveredEntityId=n)}function x(){s(null)}function b(){return l(e.selectedEntityId)}function I(){return l(e.hoveredEntityId)}function D(t){d(i(t,"setSelectedEntity"))}export{e as a,a as b,l as c,g as d,c as e,E as f,p as g,f as h,d as i,v as j,s as k,x as l,b as m,I as n,D as o};
@@ -1,49 +0,0 @@
1
- import { G as GameEntity } from './entity-BI7cSlK8.js';
2
-
3
- type DebugTools = 'select' | 'translate' | 'rotate' | 'scale' | 'delete' | 'add' | 'none';
4
- interface DebugState {
5
- enabled: boolean;
6
- paused: boolean;
7
- tool: DebugTools;
8
- /**
9
- * UUID of the selected entity, never the entity itself. Valtio deep-proxies
10
- * any object assigned into a proxy, so storing a live `GameEntity` here
11
- * would walk `group.parent` into the entire THREE scene graph and
12
- * `physicsWorldRef` into the Rapier world, freezing the tab and handing
13
- * Proxy wrappers to engine code that expects real instances.
14
- */
15
- selectedEntityId: string | null;
16
- /** UUID of the hovered entity. Same constraint as `selectedEntityId`. */
17
- hoveredEntityId: string | null;
18
- flags: Set<string>;
19
- }
20
- declare const debugState: DebugState;
21
- /** Resolves a UUID to the live entity owned by the active stage. */
22
- type DebugEntityResolver = (uuid: string) => GameEntity<any> | null;
23
- /**
24
- * Register the active stage's entity resolver so `getSelectedEntity` /
25
- * `getHoveredEntity` can hand back live entities without the reactive store
26
- * ever holding one.
27
- *
28
- * @returns An unregister function.
29
- */
30
- declare function registerDebugEntityResolver(resolver: DebugEntityResolver): () => void;
31
- /** Resolve a UUID through the active stage, or null when unavailable. */
32
- declare function resolveDebugEntity(uuid: string | null): GameEntity<any> | null;
33
- declare function setPaused(paused: boolean): void;
34
- declare function setDebugTool(tool: DebugTools): void;
35
- declare function getSelectedEntityId(): string | null;
36
- declare function setSelectedEntityId(uuid: string | null): void;
37
- declare function getHoveredEntityId(): string | null;
38
- declare function setHoveredEntityId(uuid: string | null): void;
39
- /** The live selected entity, resolved on demand through the active stage. */
40
- declare function getSelectedEntity(): GameEntity<any> | null;
41
- /** The live hovered entity, resolved on demand through the active stage. */
42
- declare function getHoveredEntity(): GameEntity<any> | null;
43
- /**
44
- * @deprecated Pass a UUID to {@link setSelectedEntityId} instead. Accepts a
45
- * live entity only to keep the previous public API working.
46
- */
47
- declare function setSelectedEntity(entity: GameEntity<any> | string | null): void;
48
-
49
- export { type DebugTools as D, setPaused as a, setSelectedEntity as b, setSelectedEntityId as c, debugState as d, getSelectedEntity as e, setHoveredEntityId as f, getSelectedEntityId as g, getHoveredEntityId as h, getHoveredEntity as i, resolveDebugEntity as j, type DebugEntityResolver as k, registerDebugEntityResolver as r, setDebugTool as s };
@@ -1 +0,0 @@
1
- import{v as e}from"./chunk-4CHZUWLF.js";import"./chunk-C5NEGC3S.js";import"./chunk-D3JO4HW2.js";import"./chunk-LKFF6XJC.js";import"./chunk-W5SXED5T.js";import"./chunk-WBQ5TNRZ.js";import"./chunk-3I537JFL.js";import"./chunk-CM5YRNBJ.js";import"./chunk-AIQ6IVT5.js";import"./chunk-QXVH6POE.js";import"./chunk-EVYHPR3J.js";import"./chunk-D2PATZCC.js";import"./chunk-4QLJUQSJ.js";import"./chunk-7WRQ2UAN.js";import"./chunk-BH53MBAZ.js";import"./chunk-XRP4JJXL.js";import"./chunk-UG22Z42P.js";import{proxy as t}from"valtio/vanilla";var s=()=>({id:"zylem",globals:{},stages:[e()],debug:!1,time:0,input:void 0}),a=t({...s()});function o(){return{id:a.id??"zylem",globals:a.globals??{},stages:a.stages??[e()],debug:a.debug,time:a.time,input:a.input}}export{o as getGameDefaultConfig};
File without changes