@zylem/game-lib 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/game-lib.api.json +229 -137
- package/dist/api/game-lib.api.md +11 -8
- package/dist/api/game-lib.d.ts +115 -44
- package/dist/api/game-lib.typedoc.json +45344 -45119
- package/dist/bridge.d.ts +25 -0
- package/dist/bridge.js +1 -1
- package/dist/{chunk-CGHGVX4T.js → chunk-2IJLXFWY.js} +2 -2
- package/dist/chunk-3CLQWJ2I.js +1 -0
- package/dist/chunk-47HAZZWF.js +1 -0
- package/dist/chunk-NK4IXK5V.js +1 -0
- package/dist/{chunk-Q2YDBMVY.js → chunk-OCQ7A5IK.js} +1 -1
- package/dist/cinematics.d.ts +2 -2
- package/dist/core.d.ts +6 -6
- package/dist/core.js +1 -1
- package/dist/debug.d.ts +3 -2
- package/dist/debug.js +1 -1
- package/dist/{game-D8KTP3fD.d.ts → game-DBt7iVu4.d.ts} +2 -2
- package/dist/{game-default-UPRL345L.js → game-default-BAZPDNPS.js} +1 -1
- package/dist/graphics.d.ts +1 -1
- package/dist/public.d.ts +3 -3
- package/dist/public.js +1 -1
- package/dist/{stage-CAPlk_cN.d.ts → stage-PBmwT5-Y.d.ts} +76 -43
- package/dist/web-components.d.ts +3 -3
- package/dist/{zylem-camera-CYDtrVgi.d.ts → zylem-camera-CWhIGXlW.d.ts} +12 -0
- package/package.json +3 -3
- package/dist/chunk-BCFFS3FP.js +0 -1
- package/dist/chunk-EA52VY4B.js +0 -1
- package/dist/chunk-G5IJBJ4E.js +0 -1
package/dist/chunk-G5IJBJ4E.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as V,c as k,d as D}from"./chunk-BQRMYLYD.js";import{d as a,h as f,j as b,l as g,o as S,q as u,r as v,s as w,t as P,v as E,w as x,x as C}from"./chunk-GPCSX3M6.js";function B(){return new Promise(t=>{let e=new MessageChannel;e.port1.onmessage=()=>t(),e.port2.postMessage(void 0)})}async function I(t,e,i={}){let n=Math.max(1,i.batchSize??5),o=0;for(let s of t.entries)await e(s),o+=1,o%n===0&&await B();return o%n!==0&&await B(),{spawned:o}}import{subscribe as R}from"valtio/vanilla";import{announceBridgeReady as M,getZylemBridge as d}from"@zylem/bridge";var c="custom",p=new Set;function O(t){if(t!==c){c=t;for(let e of p)e(c)}}function Y(t){return p.add(t),t(c),()=>{p.delete(t)}}function h(t,e){return[t[0]*e.x,t[1]*e.y,t[2]*e.z]}function z(t,e){let i=new Float32Array(t.length);for(let n=0;n<t.length;n+=3)i[n]=t[n]*e.x,i[n+1]=t[n+1]*e.y,i[n+2]=t[n+2]*e.z;return i}function K(t,e){let{shape:i}=t,n=t.offset?h(t.offset,e):t.offset,o;switch(i.type){case"box":o={type:"box",halfExtents:h(i.halfExtents,e)};break;case"sphere":o={type:"sphere",radius:i.radius*Math.max(e.x,e.y,e.z)};break;case"capsule":case"cylinder":case"cone":o={type:i.type,halfHeight:i.halfHeight*e.y,radius:i.radius*Math.max(e.x,e.z)};break;case"convexHull":o={type:"convexHull",vertices:z(i.vertices,e)};break;case"trimesh":o={type:"trimesh",vertices:z(i.vertices,e),indices:i.indices};break;case"heightfield":o={...i,scale:h(i.scale,e)};break;default:o=i;break}return{...t,shape:o,offset:n}}function G(t){if(!t.colliderBaseline){let e=t.colliderDescs.length?t.colliderDescs:t.colliderDesc?[t.colliderDesc]:[];t.colliderBaseline=e.map(i=>({...i}))}return t.colliderBaseline}function L(t){if(!t.colliderScaleDirty)return!1;t.colliderScaleDirty=!1;let e=G(t);if(!e.length)return!1;let i=t.getScale(),n=e.map(r=>K(r,i));t.colliderDescs=n,t.colliderDesc=n[0];let o=t.physicsWorldRef;if(!o)return!0;let s=t.getPose();return o.destroyEntity(t),s&&t.bodyDesc&&(t.bodyDesc.position=[s.position.x,s.position.y,s.position.z],t.bodyDesc.rotation=[s.rotation.x,s.rotation.y,s.rotation.z,s.rotation.w]),o.addEntity(t),!0}function U(t){return(t?.group??t?.mesh)?.scale}function H(t){let i=(typeof t?.getScale=="function"?t.getScale():void 0)??t?.scale??U(t)??{};return{x:i.x??1,y:i.y??1,z:i.z??1}}function de(t){let e=typeof t?.getPose=="function"?t.getPose():null;if(!e?.rotation)return;let{x:i,y:n,z:o,w:s}=e.rotation;return{x:i,y:n,z:o,w:s}}function y(t){let e=typeof t?.getPose=="function"?t.getPose():null,i=e?.position??{x:0,y:0,z:0},n=e?.rotation??{x:0,y:0,z:0,w:1};return{position:{x:i.x,y:i.y,z:i.z},rotation:D(n),quaternion:{x:n.x,y:n.y,z:n.z,w:n.w},scale:H(t)}}function N(t,e){if(typeof t?.setScale=="function"){t.setScale(e.x,e.y,e.z);return}U(t)?.set?.(e.x,e.y,e.z)}function $(t){!t||typeof t.getScale!="function"||L(t)}function Q(t,e){if(!t)return!1;let i=e.quaternion??(e.rotation?k(e.rotation):void 0),n=!1;return(e.position||i)&&typeof t.setPose=="function"&&(n=t.setPose({position:e.position,rotation:i})),e.scale&&(N(t,e.scale),n=!0),n}function W(t){let e=t?.constructor?.type;return e?String(e).replace("Symbol(","").replace(")",""):"Unknown"}function j(t){let e=t;if(!e?.uuid)return;let i=d().channel;if(!i.hasSubscribers("entity:upsert"))return;let n=y(t);i.queue("entity:upsert",[{uuid:e.uuid,name:e.name||"Unnamed",type:W(t),position:n.position,rotation:n.rotation,scale:n.scale,quaternion:n.quaternion}])}function ue(t,e){d().channel.send("game:notice",{level:t,message:e})}function F(t,e,i){let n=[...new Set(t.swatches.map(r=>r.source))],o=[...new Set(e.map(r=>r.uuid))],s=o.length===1?i(o[0])||"entity":`${o.length} entities`;return`Apply ${n.join(", ")} to ${s}`}function Z(t,e){return!e||t.length!==e.length?!1:t.every((i,n)=>i===e[n])}function _(t,e){switch(e){case"add":v(t);break;case"subtract":w(t);break;case"toggle":for(let i of t)P(i);break;default:u(t);break}}function J(t,e){return t.on.bind(t)("camera:view:set",({preset:n})=>e(n))}var A=class{channel;unsubscribes=[];host=null;editorKnown={};applyingSceneOperation=!1;constructor(){this.channel=d().channel}connect(e,i){this.disconnect(),this.host=e,this.unsubscribes.push(this.channel.on("debug:set",({enabled:n})=>{this.editorKnown.debug=n,a.enabled=n}),this.channel.on("tool:set",({tool:n})=>{b(n)}),this.channel.on("playback:set",({paused:n})=>{this.editorKnown.paused=n,f(n)}),this.channel.on("entity:select",({uuid:n,uuids:o,mode:s})=>{o?_(o,s??"replace"):S(n),this.editorKnown.selectedUuid=a.selectedEntityId,this.editorKnown.selectedUuids=[...a.selectedEntityIds]}),this.channel.on("entity:focus",({uuid:n})=>{V(n)}),this.channel.on("entity:transform",({uuid:n,position:o,rotation:s,quaternion:r,scale:m})=>{let l=this.host?.resolveEntity(n);if(!l)return;let q=y(l);if(Q(l,{position:o,rotation:s,quaternion:r,scale:m}),m&&$(l),j(l),this.applyingSceneOperation)return;let T=y(l);this.channel.send("scene:operation",{opId:`tx-${n}-${Date.now().toString(36)}`,kind:"transform",label:`Set ${l.name||"entity"} transform`,entries:[{uuid:n,before:q,after:T}]})}),this.channel.on("entity:create",({typeId:n,props:o,pose:s})=>{this.host?.createEntity?.(n,o,s)}),this.channel.on("level:load",({buffer:n})=>{this.loadLevel(n)}),this.channel.on("scene:operation:apply",({op:n,direction:o})=>{this.applyingSceneOperation=!0;try{this.host?.applySceneOperation?.(n,o)}finally{this.applyingSceneOperation=!1}}),this.channel.on("add:type:set",({typeId:n,props:o})=>{C(n,o??null)}),this.channel.on("snap:set",n=>{E(n)}),this.channel.on("grid:set",({visible:n})=>{x(n)}),this.channel.on("stage:variable:set",({key:n,value:o})=>{this.host?.setStageVariable?.(n,o)}),this.channel.on("pick:mode:set",({enabled:n})=>{g(n)}),this.channel.on("entity:pick",({requestId:n,ndc:o})=>{let s=this.host?.pickEntity?.(o)??null;this.channel.send("entity:pick:result",{requestId:n,hit:s})}),this.channel.on("entity:apply-swatch",n=>{this.handleApplySwatch(n)}),this.channel.on("cutscene:load",n=>this.host?.cutscene?.load(n)),this.channel.on("cutscene:play",({from:n})=>this.host?.cutscene?.play(n)),this.channel.on("cutscene:pause",()=>this.host?.cutscene?.pause()),this.channel.on("cutscene:stop",()=>this.host?.cutscene?.stop()),this.channel.on("cutscene:seek",({time:n})=>this.host?.cutscene?.seek(n)),this.channel.on("cutscene:unload",()=>this.host?.cutscene?.unload()),this.channel.on("camera:pose:get",({requestId:n})=>{let o=this.host?.cameraPose?.();o&&this.channel.send("camera:pose",{requestId:n,...o})}),J(this.channel,O),R(a,()=>this.publishDebugStateChanges())),this.publishDebugStateChanges(),M(i)}publishCutsceneStatus(e){this.channel.queue("cutscene:status",e)}publishCutsceneView(e){this.channel.queue("cutscene:view",e)}disconnect(){for(let e of this.unsubscribes)e();this.unsubscribes=[],this.host=null,this.editorKnown={}}handleApplySwatch(e){let i=e.opId??`swatch-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,n=this.host?.applySwatches?this.host.applySwatches({...e,opId:i}):{results:e.uuids.flatMap(s=>e.swatches.map(r=>({uuid:s,kind:r.kind,source:r.source,ok:!1,reason:"entity-not-found"}))),entries:[]},o=[...new Set(n.entries.map(s=>s.uuid))];e.select&&o.length>0&&u(o),n.entries.length>0&&!this.applyingSceneOperation&&this.channel.send("scene:operation",{opId:i,kind:"swatch",label:F(e,n.entries,s=>this.host?.resolveEntity(s)?.name),entries:n.entries}),this.channel.send("entity:swatch-applied",{opId:i,results:n.results})}publishDebugStateChanges(){let e={};a.paused!==this.editorKnown.paused&&(this.editorKnown.paused=a.paused,e.paused=a.paused),a.enabled!==this.editorKnown.debug&&(this.editorKnown.debug=a.enabled,e.debug=a.enabled),(e.paused!==void 0||e.debug!==void 0)&&this.publishStatus(e),(a.selectedEntityId!==this.editorKnown.selectedUuid||a.hoveredEntityId!==this.editorKnown.hoveredUuid||!Z(a.selectedEntityIds,this.editorKnown.selectedUuids))&&(this.editorKnown.selectedUuid=a.selectedEntityId,this.editorKnown.selectedUuids=[...a.selectedEntityIds],this.editorKnown.hoveredUuid=a.hoveredEntityId,this.channel.queue("entity:selection",{selectedUuid:a.selectedEntityId,hoveredUuid:a.hoveredEntityId,selectedUuids:[...a.selectedEntityIds]}))}wantsEntityUpdates(){return this.channel.hasSubscribers("entity:upsert")||this.channel.hasSubscribers("stage:snapshot")}wantsThumbnails(){return this.channel.hasSubscribers("entity:thumbnail")}onEditorAttached(e){return this.channel.onSubscriberAdded(i=>{if(i!=="entity:upsert"&&i!=="entity:thumbnail")return;let n=i==="entity:upsert"?"entity:thumbnail":"entity:upsert";this.channel.subscriberCount(n)>0||e()})}publishConfig(e){this.channel.send("game:config",e)}publishLoading(e){this.channel.send("game:loading",e)}publishStatus(e){this.channel.queue("game:status",e)}publishVariable(e){this.channel.send("game:variable",e)}async loadLevel(e){let{spawned:i}=await I(e,n=>{this.host?.createEntity?.(n.typeId,void 0,n.pose)});this.publishNotice("info",`Streamed ${i} level entries`)}publishNotice(e,i){this.channel.send("game:notice",{level:e,message:i})}publishStageSnapshot(e){this.channel.send("stage:snapshot",e)}queueEntityUpsert(e){e.length&&this.channel.queue("entity:upsert",e)}queueEntityRemoved(e){e.length&&this.channel.queue("entity:removed",{uuids:e})}queueThumbnails(e){e.length&&this.channel.queue("entity:thumbnail",e)}publishCatalog(e){this.channel.send("catalog:snapshot",{entities:e})}publishSceneOperation(e){this.channel.send("scene:operation",e)}wantsSceneOperations(){return this.channel.hasSubscribers("scene:operation")}};function pe(t){d().channel.send("scene:operation",t)}export{Y as a,I as b,L as c,H as d,de as e,y as f,$ as g,Q as h,W as i,ue as j,A as k,pe as l};
|