@zylem/game-lib 0.7.0 → 0.8.0

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 (95) hide show
  1. package/README.md +15 -1
  2. package/dist/actions.d.ts +71 -8
  3. package/dist/actions.js +1 -1
  4. package/dist/api/game-lib.api.json +54074 -0
  5. package/dist/api/game-lib.api.md +4544 -0
  6. package/dist/api/game-lib.d.ts +8258 -0
  7. package/dist/api/game-lib.typedoc.json +345421 -0
  8. package/dist/audio.js +1 -1
  9. package/dist/{base-node-life-cycle-CnJ-7zX-.d.ts → base-node-life-cycle-D2NuN1VB.d.ts} +12 -4
  10. package/dist/behavior.d.ts +2 -3
  11. package/dist/behavior.js +1 -1
  12. package/dist/blueprints-TbGY-h53.d.ts +162 -0
  13. package/dist/chunk-7FR5JSQ2.js +1 -0
  14. package/dist/chunk-7GYFZKK7.js +1 -0
  15. package/dist/chunk-7WRQ2UAN.js +1 -0
  16. package/dist/chunk-BH53MBAZ.js +1 -0
  17. package/dist/chunk-BIGH6D34.js +0 -0
  18. package/dist/chunk-CM5YRNBJ.js +19 -0
  19. package/dist/chunk-COM6HJ2L.js +1 -0
  20. package/dist/chunk-D2PATZCC.js +1 -0
  21. package/dist/chunk-DFLI7ICU.js +0 -0
  22. package/dist/chunk-E3UBSUPX.js +1 -0
  23. package/dist/chunk-FKIKN7RP.js +24 -0
  24. package/dist/chunk-G4HONLWC.js +1 -0
  25. package/dist/chunk-IKWE2W6L.js +1 -0
  26. package/dist/chunk-IPWUDOV5.js +1 -0
  27. package/dist/chunk-JEHFHUH4.js +0 -0
  28. package/dist/chunk-JNKPTL77.js +1 -0
  29. package/dist/chunk-JQKS42G4.js +1 -0
  30. package/dist/chunk-M3XNO56P.js +1 -0
  31. package/dist/chunk-ORIDWL3T.js +0 -0
  32. package/dist/chunk-QB3NL7VQ.js +1 -0
  33. package/dist/chunk-TAUWDQZF.js +9 -0
  34. package/dist/chunk-VS2D4B3W.js +1 -0
  35. package/dist/chunk-WQ3WMMZD.js +1 -0
  36. package/dist/chunk-XK63E4SX.js +1 -0
  37. package/dist/chunk-XNDS4YFR.js +1 -0
  38. package/dist/chunk-XNHVRFAK.js +1 -0
  39. package/dist/chunk-ZRT3ZQVH.js +1 -0
  40. package/dist/collision-builder-jF-toPIl.d.ts +38 -0
  41. package/dist/core.d.ts +45 -30
  42. package/dist/core.js +1 -24
  43. package/dist/debug-state-BPT6jEog.d.ts +17 -0
  44. package/dist/debug.d.ts +71 -19
  45. package/dist/debug.js +1 -1
  46. package/dist/{default-controls-BGc61yYl.d.ts → default-controls-0-vCnli7.d.ts} +3 -3
  47. package/dist/{entity-DNkYKfdp.d.ts → entity-BdSI8CL3.d.ts} +63 -444
  48. package/dist/entity-DZbFQ1Wg.d.ts +28 -0
  49. package/dist/{entity-type-map-C94h2TDW.d.ts → entity-type-map-Bd69SpAS.d.ts} +153 -6
  50. package/dist/entity.d.ts +11 -8
  51. package/dist/entity.js +1 -1
  52. package/dist/events.d.ts +10 -1
  53. package/dist/events.js +1 -1
  54. package/dist/{game-Cuj5gy7U.d.ts → game-C1FHVqXl.d.ts} +429 -133
  55. package/dist/game-default-QHROHW2O.js +1 -0
  56. package/dist/{game-interfaces-tfpM5NBk.d.ts → game-interfaces-mchNYSZE.d.ts} +2 -2
  57. package/dist/globals.d.ts +12 -1
  58. package/dist/globals.js +1 -1
  59. package/dist/graphics.d.ts +16 -46
  60. package/dist/graphics.js +1 -1
  61. package/dist/input-ui.d.ts +5 -4
  62. package/dist/input-ui.js +1 -1
  63. package/dist/input.d.ts +4 -3
  64. package/dist/input.js +1 -1
  65. package/dist/{material-Wz83vTTp.d.ts → material-9vJ6SZaI.d.ts} +25 -50
  66. package/dist/public.d.ts +38 -0
  67. package/dist/public.js +1 -0
  68. package/dist/runtime.d.ts +7 -381
  69. package/dist/runtime.js +1 -1
  70. package/dist/schema/entity.schema.json +244 -0
  71. package/dist/schema/game-config.schema.json +625 -0
  72. package/dist/schema/input-config.schema.json +499 -0
  73. package/dist/schema/stage-config.schema.json +93 -0
  74. package/dist/schema/stage.schema.json +271 -0
  75. package/dist/schema.d.ts +538 -0
  76. package/dist/schema.js +1 -0
  77. package/dist/stage-transition-CmGpV4tc.d.ts +46 -0
  78. package/dist/vector-CiSHbivc.d.ts +133 -0
  79. package/dist/web-components.d.ts +15 -12
  80. package/dist/web-components.js +1 -9
  81. package/dist/{zylem-stage-runtime-Cs-UDEVU.d.ts → zylem-camera-C3bn6BTI.d.ts} +62 -264
  82. package/package.json +28 -20
  83. package/dist/chunk-73VZQZUL.js +0 -1
  84. package/dist/chunk-A34ZG3L4.js +0 -1
  85. package/dist/chunk-CDPY4VOQ.js +0 -1
  86. package/dist/chunk-DR6XXZE7.js +0 -19
  87. package/dist/chunk-FM5TBEPO.js +0 -1
  88. package/dist/chunk-G2IIMSUH.js +0 -1
  89. package/dist/chunk-NIH5CONO.js +0 -1
  90. package/dist/chunk-ONWXGBWB.js +0 -1
  91. package/dist/chunk-QEDQDR27.js +0 -1
  92. package/dist/chunk-WKHW2QO2.js +0 -1
  93. package/dist/chunk-YHKXQ2ZN.js +0 -1
  94. package/dist/game-default-PZLLHYL7.js +0 -1
  95. package/dist/world-C9zdyl5d.d.ts +0 -103
package/README.md CHANGED
@@ -15,10 +15,24 @@ This library is intended for hobbyist developers who want to play with 3D web te
15
15
  The goal is to give you tools to build simple 3D games. It's basically comprised of:
16
16
 
17
17
  - Rendering via ThreeJS with some capability to handle postprocessing built-in. [ThreeJS](https://threejs.org/)
18
- - Collision handling, triggers, and rigid body physics via RapierRS [RapierRS](https://rapier.rs/)
18
+ - Collision handling, triggers, and rigid body physics simulated in WebAssembly (Rapier compiled to WASM via [@zylem/runtime](https://www.npmjs.com/package/@zylem/runtime), driven through [@zylem/behaviors](https://www.npmjs.com/package/@zylem/behaviors))
19
19
  - Game state management with Valtio [Valtio](https://valtio.dev/)
20
20
  - Simplified input handling (gamepad, keyboard, mouse)
21
21
 
22
+ **Architecture layers**
23
+
24
+ Zylem is split into three packages, each a strict layer over the one below:
25
+
26
+ | Layer | Package | Owns |
27
+ | --- | --- | --- |
28
+ | Game framework | `@zylem/game-lib` | Three.js rendering, input, assets, stages, game state |
29
+ | Simulation | `@zylem/behaviors` | `createSimulation()`, entity registry, behavior FSMs, event translation, runtime ownership |
30
+ | Runtime | `@zylem/runtime` | WASM module: ECS + Rapier physics, slot-indexed input/render/snapshot/event buffers |
31
+
32
+ Each frame, game-lib forwards behavior inputs into the simulation, calls `simulation.update(delta)` (fixed-timestep physics inside WASM), then syncs interpolated render poses onto Three.js objects. Disposal follows the same chain: `Game.dispose()` → `Simulation.dispose()` → WASM stage destroy.
33
+
34
+ Games normally never touch the runtime directly; for debug tooling there is an escape hatch: `game.experimental.getRuntime()` returns the underlying `Simulation`.
35
+
22
36
  > Note: This project is still in alpha. There are unfinished features and some APIs that may change.
23
37
 
24
38
  ## Installation
package/dist/actions.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { A as Action, G as GameEntity } from './entity-DNkYKfdp.js';
2
- export { H as getRotation, t as rotateEuler, r as rotateInDirection, u as rotateX, v as rotateY, s as rotateYEuler, w as rotateZ, F as setRotation, B as setRotationDegrees, D as setRotationDegreesX, C as setRotationDegreesY, E as setRotationDegreesZ, y as setRotationX, x as setRotationY, z as setRotationZ } from './entity-DNkYKfdp.js';
1
+ import { A as Action, G as GameEntity } from './entity-BdSI8CL3.js';
2
+ export { x as getRotation, i as rotateEuler, r as rotateInDirection, j as rotateX, k as rotateY, h as rotateYEuler, l as rotateZ, w as setRotation, q as setRotationDegrees, u as setRotationDegreesX, t as setRotationDegreesY, v as setRotationDegreesZ, n as setRotationX, m as setRotationY, o as setRotationZ } from './entity-BdSI8CL3.js';
3
3
  import { Object3D } from 'three';
4
4
  import { TransformState } from '@zylem/behaviors/core';
5
- export { TransformState, createTransformStore, getPosition, getVelocity, move, moveForwardXY, moveX, moveXY, moveXZ, moveY, moveZ, resetTransformStore, resetVelocity, setPosition, setPositionX, setPositionY, setPositionZ, wrapAround3D, wrapAroundXY } from '@zylem/behaviors/core';
6
- import { RigidBody } from '@dimforge/rapier3d-compat';
7
- import './material-Wz83vTTp.js';
5
+ export { TransformState, createTransformStore, getPosition, getVelocity, move, moveForwardXY, moveX, moveXY, moveXZ, moveY, moveZ, resetVelocity, setPosition, setPositionX, setPositionY, setPositionZ, wrapAround3D, wrapAroundXY } from '@zylem/behaviors/core';
6
+ import './vector-CiSHbivc.js';
7
+ import './material-9vJ6SZaI.js';
8
8
  import 'three/webgpu';
9
- import './base-node-life-cycle-CnJ-7zX-.js';
9
+ import './collision-builder-jF-toPIl.js';
10
+ import './base-node-life-cycle-D2NuN1VB.js';
11
+ import './stage-transition-CmGpV4tc.js';
10
12
  import './events.js';
11
13
  import 'mitt';
12
14
 
@@ -256,11 +258,72 @@ declare function repeat(action: Action, times: number): Action;
256
258
  declare function repeatForever(action: Action): Action;
257
259
 
258
260
  /**
259
- * Entity that can have transformations applied from a store
261
+ * Structural slice of the simulation body facade used to flush transform
262
+ * intents. `SimulationBody` satisfies this shape.
263
+ */
264
+ interface TransformableBodyLike {
265
+ linvel(): {
266
+ x: number;
267
+ y: number;
268
+ z: number;
269
+ };
270
+ translation(): {
271
+ x: number;
272
+ y: number;
273
+ z: number;
274
+ };
275
+ setLinvel(velocity: {
276
+ x: number;
277
+ y: number;
278
+ z: number;
279
+ }, wakeUp: boolean): void;
280
+ setTranslation(translation: {
281
+ x: number;
282
+ y: number;
283
+ z: number;
284
+ }, wakeUp: boolean): void;
285
+ setRotation(rotation: {
286
+ x: number;
287
+ y: number;
288
+ z: number;
289
+ w: number;
290
+ }, wakeUp: boolean): void;
291
+ setAngvel(velocity: {
292
+ x: number;
293
+ y: number;
294
+ z: number;
295
+ }, wakeUp: boolean): void;
296
+ }
297
+ /**
298
+ * Minimal slice of the WASM stage runtime used to apply transform intents via
299
+ * FFI. Kept structural so this module need not import the full runtime type.
300
+ */
301
+ interface RuntimeTransformTarget {
302
+ getLinearVelocity(slot: number, out?: [number, number, number]): [number, number, number] | null;
303
+ setLinearVelocity(slot: number, x: number, y: number, z: number): boolean;
304
+ setAngularVelocity(slot: number, x: number, y: number, z: number): boolean;
305
+ setRotation(slot: number, x: number, y: number, z: number, w: number): boolean;
306
+ setPosition(slot: number, x: number, y: number, z: number): boolean;
307
+ getPose(slot: number): {
308
+ position: [number, number, number];
309
+ rotation: [number, number, number, number];
310
+ } | null;
311
+ }
312
+ /**
313
+ * Entity that can have transformations applied from a store.
314
+ *
315
+ * When `body` (the simulation body facade) is present the intents flush
316
+ * through it; otherwise, if the entity carries a live WASM slot
317
+ * (`runtimeHandle` >= 0 + `wasmStageRef`), they flush through the runtime's
318
+ * FFI setters directly.
260
319
  */
261
320
  interface TransformableEntity {
262
- body: RigidBody | null;
321
+ body: TransformableBodyLike | null;
263
322
  transformStore?: TransformState;
323
+ /** Live WASM slot handle, or -1 when not runtime-attached. */
324
+ runtimeHandle?: number;
325
+ /** Runtime adapter the entity is attached to, if any. */
326
+ wasmStageRef?: RuntimeTransformTarget | null;
264
327
  }
265
328
  /**
266
329
  * Apply accumulated transformations from the store to the physics body.
package/dist/actions.js CHANGED
@@ -1 +1 @@
1
- import{a as C}from"./chunk-FM5TBEPO.js";import{a as G,b as D,c as P,d as R,e as I,f as X,g as Y,h as B,i as Z,j,k as V,l as q,m as F,n as S,o as _}from"./chunk-XRP4JJXL.js";var c=class{duration;done=!1;persistent=!1;elapsed=0;constructor(t){this.duration=t/1e3}tick(t,i){if(this.done)return;this.elapsed+=i;let n=this.duration>0?Math.min(this.elapsed/this.duration,1):1;this.onTick(t,i,n),this.elapsed>=this.duration&&(this.done=!0)}reset(){this.elapsed=0,this.done=!1}};import{setVelocityIntent as w}from"@zylem/behaviors/core";function A(e){let t=[];for(let i of e)i.traverse(n=>{if(!n.isMesh)return;let r=n,o=s=>{!("opacity"in s)||!("transparent"in s)||t.push(s)};Array.isArray(r.material)?r.material.forEach(o):r.material&&o(r.material)});return t}function E(e,t){if(t&&t.length>0)return t;let i=e.group??e.mesh;return i?[i]:[]}function U(e,t=1,i=!1){let n=E(e,void 0);for(let r of A(n))r.transparent=i,r.opacity=t,r.needsUpdate=!0}function H(e){return new l(e)}var l=class extends c{dx;dy;dz;constructor(t){super(t.duration),this.dx=t.x??0,this.dy=t.y??0,this.dz=t.z??0}onTick(t,i,n){if(this.duration<=0)return;let r=this.dx/this.duration,o=this.dy/this.duration,s=this.dz/this.duration,a=t.transformStore;a&&w(a,"actions",{x:r,y:o,z:s},{mode:"add"})}};function J(e){return new d(e)}var d=class extends c{targetX;targetY;targetZ;dx=0;dy=0;dz=0;initialized=!1;constructor(t){super(t.duration),this.targetX=t.x,this.targetY=t.y,this.targetZ=t.z}onTick(t,i,n){if(this.duration<=0)return;if(!this.initialized){let u=t.getPosition?.(),k=u?.x??0,M=u?.y??0,T=u?.z??0;this.dx=this.targetX-k,this.dy=this.targetY-M,this.dz=this.targetZ-T,this.initialized=!0}let r=this.dx/this.duration,o=this.dy/this.duration,s=this.dz/this.duration,a=t.transformStore;a&&w(a,"actions",{x:r,y:o,z:s},{mode:"add"})}reset(){super.reset(),this.initialized=!1}};function K(e){return new p(e)}var p=class extends c{rx;ry;rz;constructor(t){super(t.duration);let i=Math.PI/180;this.rx=(t.x??0)*i,this.ry=(t.y??0)*i,this.rz=(t.z??0)*i}onTick(t,i,n){if(this.duration<=0)return;let r=this.rx/this.duration,o=this.ry/this.duration,s=this.rz/this.duration,a=t.transformStore;a.angularVelocity.x+=r,a.angularVelocity.y+=o,a.angularVelocity.z+=s,a.dirty.angularVelocity=!0}};function L(e){return new m(e)}var m=class extends c{constructor(t){super(t)}onTick(){}};function N(e){return new h(e)}var h=class extends c{fn;called=!1;constructor(t){super(0),this.fn=t}onTick(){this.called||(this.fn(),this.called=!0)}reset(){super.reset(),this.called=!1}};function Q(e){return new f(e)}var f=class extends c{from;to;targets;restoreOpaque;materials=null;finalized=!1;constructor(t){super(t.duration),this.from=t.from??1,this.to=t.to??0,this.targets=t.targets,this.restoreOpaque=t.restoreOpaque??!1}onTick(t,i,n){if(!this.materials){this.materials=A(E(t,this.targets));for(let o of this.materials)o.transparent=!0,o.needsUpdate=!0}let r=this.from+(this.to-this.from)*n;for(let o of this.materials)o.opacity=r;if(n>=1&&!this.finalized&&(this.finalized=!0,this.restoreOpaque&&this.to>=1))for(let o of this.materials)o.transparent=!1,o.needsUpdate=!0}reset(){super.reset(),this.materials=null,this.finalized=!1}};function W(e){return new y(e.duration)}var y=class{duration;done=!1;persistent=!0;ready=!1;elapsed=0;constructor(t){this.duration=t/1e3}tick(t,i){this.elapsed+=i,this.elapsed>=this.duration&&(this.ready=!0)}consume(){this.ready=!1,this.elapsed=0}reset(){this.elapsed=0,this.ready=!1}};function $(){return new b}var b=class{duration=1/0;done=!1;persistent=!0;triggered=!1;wasPressed=!1;tick(){this.triggered=!1}check(t){t&&!this.wasPressed&&(this.triggered=!0),this.wasPressed=t}reset(){this.triggered=!1,this.wasPressed=!1}};function tt(){return new v}var v=class{duration=1/0;done=!1;persistent=!0;triggered=!1;wasPressed=!1;tick(){this.triggered=!1}check(t){!t&&this.wasPressed&&(this.triggered=!0),this.wasPressed=t}reset(){this.triggered=!1,this.wasPressed=!1}};function et(...e){return new x(e)}var x=class{duration;done=!1;persistent=!1;actions;currentIndex=0;constructor(t){this.actions=t,this.duration=t.reduce((i,n)=>i+n.duration,0)}tick(t,i){if(this.done||this.actions.length===0){this.done=!0;return}let n=i;for(;n>0&&this.currentIndex<this.actions.length;){let r=this.actions[this.currentIndex];if(r.tick(t,n),r.done){let o=r.duration,s=r.elapsed??o;n=Math.max(0,s-o),this.currentIndex++}else n=0}this.currentIndex>=this.actions.length&&(this.done=!0)}reset(){this.currentIndex=0,this.done=!1;for(let t of this.actions)t.reset()}};function it(...e){return new g(e)}var g=class{duration;done=!1;persistent=!1;actions;constructor(t){this.actions=t,this.duration=Math.max(0,...t.map(i=>i.duration))}tick(t,i){if(this.done)return;let n=!0;for(let r of this.actions)r.done||r.tick(t,i),r.done||(n=!1);n&&(this.done=!0)}reset(){this.done=!1;for(let t of this.actions)t.reset()}};function rt(e,t){return new O(e,t)}var O=class{duration;done=!1;persistent=!1;action;totalTimes;currentCount=0;constructor(t,i){this.action=t,this.totalTimes=i,this.duration=t.duration*i}tick(t,i){this.done||(this.action.tick(t,i),this.action.done&&(this.currentCount++,this.currentCount>=this.totalTimes?this.done=!0:this.action.reset()))}reset(){this.currentCount=0,this.done=!1,this.action.reset()}};function nt(e){return new z(e)}var z=class{duration=1/0;done=!1;persistent=!1;action;constructor(t){this.action=t}tick(t,i){this.action.tick(t,i),this.action.done&&this.action.reset()}reset(){this.done=!1,this.action.reset()}};import{createTransformStore as yt,resetTransformStore as bt}from"@zylem/behaviors/core";import{move as gt,moveX as Ot,moveY as zt,moveZ as wt,moveXY as At,moveXZ as Et,resetVelocity as kt,moveForwardXY as Mt,getPosition as Tt,getVelocity as Gt,setPosition as Dt,setPositionX as Pt,setPositionY as Rt,setPositionZ as It,wrapAroundXY as Xt,wrapAround3D as Yt}from"@zylem/behaviors/core";export{C as applyTransformChanges,N as callFunc,yt as createTransformStore,L as delay,Q as fadeOpacity,Tt as getPosition,_ as getRotation,Gt as getVelocity,gt as move,H as moveBy,Mt as moveForwardXY,J as moveTo,Ot as moveX,At as moveXY,Et as moveXZ,zt as moveY,wt as moveZ,$ as onPress,tt as onRelease,it as parallel,rt as repeat,nt as repeatForever,U as resetEntityOpacity,bt as resetTransformStore,kt as resetVelocity,K as rotateBy,P as rotateEuler,G as rotateInDirection,I as rotateX,R as rotateY,D as rotateYEuler,X as rotateZ,et as sequence,Dt as setPosition,Pt as setPositionX,Rt as setPositionY,It as setPositionZ,F as setRotation,S as setRotationDegrees,j as setRotationDegreesX,B as setRotationDegreesY,q as setRotationDegreesZ,Z as setRotationX,Y as setRotationY,V as setRotationZ,W as throttle,Yt as wrapAround3D,Xt as wrapAroundXY};
1
+ import{A as Q,B as R,C as S,D as T,E as U,a as q,b as r,c as s,d as t,e as u,f as v,g as w,h as x,i as y,j as z,k as A,l as B,m as C,n as D,o as E,p as F,q as G,r as H,s as I,t as J,u as K,v as L,w as M,x as N,y as O,z as P}from"./chunk-IPWUDOV5.js";import{a as p}from"./chunk-BH53MBAZ.js";import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-XRP4JJXL.js";export{p as applyTransformChanges,v as callFunc,E as createTransformStore,u as delay,w as fadeOpacity,N as getPosition,o as getRotation,O as getVelocity,F as move,r as moveBy,M as moveForwardXY,s as moveTo,G as moveX,J as moveXY,K as moveXZ,H as moveY,I as moveZ,y as onPress,z as onRelease,B as parallel,C as repeat,D as repeatForever,q as resetEntityOpacity,L as resetVelocity,t as rotateBy,c as rotateEuler,a as rotateInDirection,e as rotateX,d as rotateY,b as rotateYEuler,f as rotateZ,A as sequence,P as setPosition,Q as setPositionX,R as setPositionY,S as setPositionZ,m as setRotation,n as setRotationDegrees,j as setRotationDegreesX,h as setRotationDegreesY,l as setRotationDegreesZ,i as setRotationX,g as setRotationY,k as setRotationZ,x as throttle,U as wrapAround3D,T as wrapAroundXY};