@zylem/game-lib 0.6.3 → 0.7.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 (97) hide show
  1. package/README.md +3 -1
  2. package/dist/actions.d.ts +255 -8
  3. package/dist/actions.js +1 -772
  4. package/dist/audio.d.ts +13 -0
  5. package/dist/audio.js +1 -0
  6. package/dist/base-node-life-cycle-CnJ-7zX-.d.ts +143 -0
  7. package/dist/behavior.d.ts +3 -0
  8. package/dist/behavior.js +1 -0
  9. package/dist/chunk-4QLJUQSJ.js +1 -0
  10. package/dist/chunk-73VZQZUL.js +1 -0
  11. package/dist/chunk-A34ZG3L4.js +1 -0
  12. package/dist/chunk-CDPY4VOQ.js +1 -0
  13. package/dist/chunk-DR6XXZE7.js +19 -0
  14. package/dist/chunk-FM5TBEPO.js +1 -0
  15. package/dist/chunk-G2IIMSUH.js +1 -0
  16. package/dist/chunk-MSC2BEO5.js +1 -0
  17. package/dist/chunk-NIH5CONO.js +1 -0
  18. package/dist/chunk-ONWXGBWB.js +1 -0
  19. package/dist/chunk-QEDQDR27.js +1 -0
  20. package/dist/chunk-QXVH6POE.js +1 -0
  21. package/dist/chunk-RXDTAWI2.js +29 -0
  22. package/dist/chunk-WKHW2QO2.js +1 -0
  23. package/dist/chunk-XRP4JJXL.js +1 -0
  24. package/dist/chunk-YHEWKN7N.js +1 -0
  25. package/dist/chunk-YHKXQ2ZN.js +1 -0
  26. package/dist/core.d.ts +206 -13
  27. package/dist/core.js +24 -9160
  28. package/dist/debug.d.ts +24 -0
  29. package/dist/debug.js +1 -0
  30. package/dist/default-controls-BGc61yYl.d.ts +111 -0
  31. package/dist/entity-DNkYKfdp.d.ts +1043 -0
  32. package/dist/entity-type-map-C94h2TDW.d.ts +781 -0
  33. package/dist/entity.d.ts +265 -0
  34. package/dist/entity.js +1 -0
  35. package/dist/events.d.ts +172 -0
  36. package/dist/events.js +1 -0
  37. package/dist/game-Cuj5gy7U.d.ts +1590 -0
  38. package/dist/game-default-PZLLHYL7.js +1 -0
  39. package/dist/game-interfaces-tfpM5NBk.d.ts +90 -0
  40. package/dist/globals.d.ts +104 -0
  41. package/dist/globals.js +1 -0
  42. package/dist/graphics.d.ts +83 -0
  43. package/dist/graphics.js +1 -0
  44. package/dist/input-ui.d.ts +34 -0
  45. package/dist/input-ui.js +1 -0
  46. package/dist/input.d.ts +72 -0
  47. package/dist/input.js +1 -0
  48. package/dist/material-Wz83vTTp.d.ts +151 -0
  49. package/dist/runtime.d.ts +433 -0
  50. package/dist/runtime.js +1 -0
  51. package/dist/web-components.d.ts +67 -0
  52. package/dist/web-components.js +9 -0
  53. package/dist/world-C9zdyl5d.d.ts +103 -0
  54. package/dist/zylem-stage-runtime-Cs-UDEVU.d.ts +777 -0
  55. package/package.json +54 -41
  56. package/dist/actions.js.map +0 -1
  57. package/dist/behavior/platformer-3d.d.ts +0 -296
  58. package/dist/behavior/platformer-3d.js +0 -518
  59. package/dist/behavior/platformer-3d.js.map +0 -1
  60. package/dist/behavior/ricochet-2d.d.ts +0 -274
  61. package/dist/behavior/ricochet-2d.js +0 -394
  62. package/dist/behavior/ricochet-2d.js.map +0 -1
  63. package/dist/behavior/screen-wrap.d.ts +0 -86
  64. package/dist/behavior/screen-wrap.js +0 -195
  65. package/dist/behavior/screen-wrap.js.map +0 -1
  66. package/dist/behavior/thruster.d.ts +0 -10
  67. package/dist/behavior/thruster.js +0 -234
  68. package/dist/behavior/thruster.js.map +0 -1
  69. package/dist/behavior/world-boundary-2d.d.ts +0 -141
  70. package/dist/behavior/world-boundary-2d.js +0 -181
  71. package/dist/behavior/world-boundary-2d.js.map +0 -1
  72. package/dist/behavior-descriptor-BWNWmIjv.d.ts +0 -142
  73. package/dist/blueprints-BWGz8fII.d.ts +0 -26
  74. package/dist/camera-B5e4c78l.d.ts +0 -468
  75. package/dist/camera.d.ts +0 -6
  76. package/dist/camera.js +0 -1406
  77. package/dist/camera.js.map +0 -1
  78. package/dist/composition-DrzFrbqI.d.ts +0 -218
  79. package/dist/core-DAkskq6Y.d.ts +0 -498
  80. package/dist/core.js.map +0 -1
  81. package/dist/entities-DC9ce_vx.d.ts +0 -416
  82. package/dist/entities.d.ts +0 -9
  83. package/dist/entities.js +0 -4069
  84. package/dist/entities.js.map +0 -1
  85. package/dist/entity-BpbZqg19.d.ts +0 -1100
  86. package/dist/entity-Bq_eNEDI.d.ts +0 -28
  87. package/dist/entity-types-DAu8sGJH.d.ts +0 -26
  88. package/dist/global-change-Dc8uCKi2.d.ts +0 -25
  89. package/dist/main.d.ts +0 -654
  90. package/dist/main.js +0 -13355
  91. package/dist/main.js.map +0 -1
  92. package/dist/stage-types-BFsm3qsZ.d.ts +0 -567
  93. package/dist/stage.d.ts +0 -51
  94. package/dist/stage.js +0 -5738
  95. package/dist/stage.js.map +0 -1
  96. package/dist/thruster-DhRaJnoL.d.ts +0 -172
  97. package/dist/world-Be5m1XC1.d.ts +0 -31
package/README.md CHANGED
@@ -39,7 +39,9 @@ npm install @zylem/game-lib
39
39
  * the ball can be controlled with the arrow keys or gamepad
40
40
  * the ball cannot go outside the boundaries
41
41
  */
42
- import { createGame, createSphere, WorldBoundary2DBehavior } from '@zylem/game-lib';
42
+ import { createGame } from '@zylem/game-lib/core';
43
+ import { createSphere } from '@zylem/game-lib/entity';
44
+ import { WorldBoundary2DBehavior } from '@zylem/game-lib/behavior';
43
45
 
44
46
  // Creates a sphere (movement capabilities are built-in)
45
47
  const ball = createSphere();
package/dist/actions.d.ts CHANGED
@@ -1,12 +1,259 @@
1
- import { T as TransformState } from './entity-BpbZqg19.js';
2
- export { A as Action, c as createTransformStore, i as getPosition, H as getRotation, j as getVelocity, m as move, h as moveForwardXY, a as moveX, e as moveXY, f as moveXZ, b as moveY, d as moveZ, r as resetTransformStore, g as resetVelocity, t as rotateEuler, p as rotateInDirection, u as rotateX, v as rotateY, q as rotateYEuler, x as rotateZ, s as setPosition, k as setPositionX, l as setPositionY, n as setPositionZ, G as setRotation, C as setRotationDegrees, E as setRotationDegreesX, D as setRotationDegreesY, F as setRotationDegreesZ, z as setRotationX, y as setRotationY, B as setRotationZ, o as wrapAround3D, w as wrapAroundXY } from './entity-BpbZqg19.js';
3
- export { c as callFunc, d as delay, m as moveBy, a as moveTo, o as onPress, b as onRelease, p as parallel, e as repeat, f as repeatForever, r as rotateBy, s as sequence, t as throttle } from './composition-DrzFrbqI.js';
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';
3
+ import { Object3D } from 'three';
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';
4
6
  import { RigidBody } from '@dimforge/rapier3d-compat';
5
- export { g as globalChange, a as globalChanges, v as variableChange, b as variableChanges } from './global-change-Dc8uCKi2.js';
6
- import 'three';
7
- import 'bitecs';
7
+ import './material-Wz83vTTp.js';
8
+ import 'three/webgpu';
9
+ import './base-node-life-cycle-CnJ-7zX-.js';
10
+ import './events.js';
8
11
  import 'mitt';
9
- import './behavior-descriptor-BWNWmIjv.js';
12
+
13
+ /** Minimal entity shape for opacity helpers (avoids GameEntity generic variance). */
14
+ type OpacityEntity = {
15
+ group?: Object3D | null;
16
+ mesh?: Object3D | null;
17
+ };
18
+ /**
19
+ * Sets opacity on every fadeable material under an entity's visual root.
20
+ */
21
+ declare function resetEntityOpacity(entity: OpacityEntity, opacity?: number, transparent?: boolean): void;
22
+ interface MoveByOptions {
23
+ /** X displacement (default: 0) */
24
+ x?: number;
25
+ /** Y displacement (default: 0) */
26
+ y?: number;
27
+ /** Z displacement (default: 0) */
28
+ z?: number;
29
+ /** Duration in milliseconds */
30
+ duration: number;
31
+ }
32
+ /**
33
+ * Move an entity by a displacement over a duration.
34
+ * Distributes the movement as velocity each frame so physics stays in sync.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * entity.runAction(moveBy({ x: 10, duration: 500 }));
39
+ * ```
40
+ */
41
+ declare function moveBy(opts: MoveByOptions): Action;
42
+ interface MoveToOptions {
43
+ /** Target X position */
44
+ x: number;
45
+ /** Target Y position */
46
+ y: number;
47
+ /** Target Z position */
48
+ z: number;
49
+ /** Duration in milliseconds */
50
+ duration: number;
51
+ }
52
+ /**
53
+ * Move an entity to an absolute position over a duration.
54
+ * Calculates displacement from the entity's position on the first tick.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * entity.runAction(moveTo({ x: 0, y: 10, z: 0, duration: 2000 }));
59
+ * ```
60
+ */
61
+ declare function moveTo(opts: MoveToOptions): Action;
62
+ interface RotateByOptions {
63
+ /** X rotation in degrees (default: 0) */
64
+ x?: number;
65
+ /** Y rotation in degrees (default: 0) */
66
+ y?: number;
67
+ /** Z rotation in degrees (default: 0) */
68
+ z?: number;
69
+ /** Duration in milliseconds */
70
+ duration: number;
71
+ }
72
+ /**
73
+ * Rotate an entity by euler angles (degrees) over a duration.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * entity.runAction(rotateBy({ y: 360, duration: 2000 }));
78
+ * ```
79
+ */
80
+ declare function rotateBy(opts: RotateByOptions): Action;
81
+ /**
82
+ * Wait for a duration. Useful inside `sequence()`.
83
+ *
84
+ * @param ms Duration in milliseconds
85
+ * @example
86
+ * ```ts
87
+ * entity.runAction(sequence(moveBy({ x: 5, duration: 1000 }), delay(500), moveBy({ y: 3, duration: 1000 })));
88
+ * ```
89
+ */
90
+ declare function delay(ms: number): Action;
91
+ /**
92
+ * Call a function immediately. Completes in one frame.
93
+ * Useful inside `sequence()` for side effects.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * entity.runAction(sequence(moveBy({ x: 5, duration: 1000 }), callFunc(() => console.log('done'))));
98
+ * ```
99
+ */
100
+ declare function callFunc(fn: () => void): Action;
101
+ interface FadeOpacityOptions {
102
+ /** Starting opacity (default: 1) */
103
+ from?: number;
104
+ /** Ending opacity (default: 0) */
105
+ to?: number;
106
+ /** Duration in milliseconds */
107
+ duration: number;
108
+ /** Optional Object3D roots to traverse; defaults to entity.group ?? entity.mesh */
109
+ targets?: Object3D[];
110
+ /** When complete and `to >= 1`, restore transparent=false on affected materials */
111
+ restoreOpaque?: boolean;
112
+ }
113
+ /**
114
+ * Fade material opacity on an entity (or explicit targets) over a duration.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * entity.runAction(fadeOpacity({ from: 0, to: 1, duration: 400, restoreOpaque: true }));
119
+ * ```
120
+ */
121
+ declare function fadeOpacity(opts: FadeOpacityOptions): Action;
122
+
123
+ interface ThrottleOptions {
124
+ /** Interval in milliseconds between ready cycles */
125
+ duration: number;
126
+ }
127
+ /**
128
+ * A repeating timer that becomes ready every N milliseconds.
129
+ * Register with `entity.action(throttle(...))`.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * const t = entity.action(throttle({ duration: 500 }));
134
+ * entity.onUpdate(() => {
135
+ * if (t.ready) { t.consume(); // do something every 500ms }
136
+ * });
137
+ * ```
138
+ */
139
+ declare function throttle(opts: ThrottleOptions): ThrottleAction;
140
+ declare class ThrottleAction implements Action {
141
+ readonly duration: number;
142
+ done: boolean;
143
+ persistent: boolean;
144
+ ready: boolean;
145
+ private elapsed;
146
+ /** @param durationMs Duration in milliseconds */
147
+ constructor(durationMs: number);
148
+ tick(_entity: GameEntity<any>, delta: number): void;
149
+ /** Consume the ready state and reset the timer */
150
+ consume(): void;
151
+ reset(): void;
152
+ }
153
+ /**
154
+ * Detects the rising edge of a boolean signal (press).
155
+ * Call `.check(isPressed)` each frame in your onUpdate; `.triggered` is
156
+ * true for one frame on press.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * const press = entity.action(onPress());
161
+ * entity.onUpdate(({ inputs }) => {
162
+ * press.check(inputs.p1.buttons.A.pressed);
163
+ * if (press.triggered) { // do something once on press }
164
+ * });
165
+ * ```
166
+ */
167
+ declare function onPress(): OnPressAction;
168
+ declare class OnPressAction implements Action {
169
+ readonly duration: number;
170
+ done: boolean;
171
+ persistent: boolean;
172
+ triggered: boolean;
173
+ private wasPressed;
174
+ tick(): void;
175
+ /**
176
+ * Feed the current pressed state. Sets `.triggered = true` on the
177
+ * frame where `isPressed` transitions from false to true.
178
+ */
179
+ check(isPressed: boolean): void;
180
+ reset(): void;
181
+ }
182
+ /**
183
+ * Detects the falling edge of a boolean signal (release).
184
+ * Call `.check(isPressed)` each frame; `.triggered` is true for one frame
185
+ * on release.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const release = entity.action(onRelease());
190
+ * entity.onUpdate(({ inputs }) => {
191
+ * release.check(inputs.p1.buttons.A.pressed);
192
+ * if (release.triggered) { // do something once on release }
193
+ * });
194
+ * ```
195
+ */
196
+ declare function onRelease(): OnReleaseAction;
197
+ declare class OnReleaseAction implements Action {
198
+ readonly duration: number;
199
+ done: boolean;
200
+ persistent: boolean;
201
+ triggered: boolean;
202
+ private wasPressed;
203
+ tick(): void;
204
+ /**
205
+ * Feed the current pressed state. Sets `.triggered = true` on the
206
+ * frame where `isPressed` transitions from true to false.
207
+ */
208
+ check(isPressed: boolean): void;
209
+ reset(): void;
210
+ }
211
+
212
+ /**
213
+ * Run actions in order, one after another.
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * entity.runAction(sequence(
218
+ * moveBy({ x: 5, duration: 1000 }),
219
+ * delay(500),
220
+ * moveBy({ y: 3, duration: 1000 }),
221
+ * ));
222
+ * ```
223
+ */
224
+ declare function sequence(...actions: Action[]): Action;
225
+ /**
226
+ * Run all actions simultaneously. Done when all children are done.
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * entity.runAction(parallel(
231
+ * moveBy({ x: 5, duration: 1000 }),
232
+ * rotateBy({ y: 360, duration: 1000 }),
233
+ * ));
234
+ * ```
235
+ */
236
+ declare function parallel(...actions: Action[]): Action;
237
+ /**
238
+ * Repeat an action a fixed number of times.
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * entity.runAction(repeat(moveBy({ x: 2, duration: 500 }), 5));
243
+ * ```
244
+ */
245
+ declare function repeat(action: Action, times: number): Action;
246
+ /**
247
+ * Repeat an action forever. Never completes.
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * enemy.runAction(repeatForever(
252
+ * sequence(moveBy({ x: 3, duration: 2000 }), moveBy({ x: -3, duration: 2000 })),
253
+ * ));
254
+ * ```
255
+ */
256
+ declare function repeatForever(action: Action): Action;
10
257
 
11
258
  /**
12
259
  * Entity that can have transformations applied from a store
@@ -31,4 +278,4 @@ interface TransformableEntity {
31
278
  */
32
279
  declare function applyTransformChanges(entity: TransformableEntity, store: TransformState): void;
33
280
 
34
- export { TransformState, applyTransformChanges };
281
+ export { Action, type FadeOpacityOptions, type MoveByOptions, type MoveToOptions, type OpacityEntity, type RotateByOptions, type ThrottleOptions, applyTransformChanges, callFunc, delay, fadeOpacity, moveBy, moveTo, onPress, onRelease, parallel, repeat, repeatForever, resetEntityOpacity, rotateBy, sequence, throttle };