@zylem/game-lib 0.6.4 → 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 (122) hide show
  1. package/README.md +3 -1
  2. package/dist/actions.d.ts +255 -8
  3. package/dist/actions.js +1 -936
  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 -14
  27. package/dist/core.js +24 -12424
  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-vj-HTjzU.d.ts → entity-DNkYKfdp.d.ts} +452 -578
  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/{camera-4XO5gbQH.d.ts → zylem-stage-runtime-Cs-UDEVU.d.ts} +201 -329
  55. package/package.json +52 -63
  56. package/dist/actions.js.map +0 -1
  57. package/dist/behavior/jumper-2d.d.ts +0 -114
  58. package/dist/behavior/jumper-2d.js +0 -711
  59. package/dist/behavior/jumper-2d.js.map +0 -1
  60. package/dist/behavior/platformer-3d.d.ts +0 -296
  61. package/dist/behavior/platformer-3d.js +0 -761
  62. package/dist/behavior/platformer-3d.js.map +0 -1
  63. package/dist/behavior/ricochet-2d.d.ts +0 -275
  64. package/dist/behavior/ricochet-2d.js +0 -425
  65. package/dist/behavior/ricochet-2d.js.map +0 -1
  66. package/dist/behavior/ricochet-3d.d.ts +0 -117
  67. package/dist/behavior/ricochet-3d.js +0 -443
  68. package/dist/behavior/ricochet-3d.js.map +0 -1
  69. package/dist/behavior/screen-visibility.d.ts +0 -79
  70. package/dist/behavior/screen-visibility.js +0 -358
  71. package/dist/behavior/screen-visibility.js.map +0 -1
  72. package/dist/behavior/screen-wrap.d.ts +0 -87
  73. package/dist/behavior/screen-wrap.js +0 -246
  74. package/dist/behavior/screen-wrap.js.map +0 -1
  75. package/dist/behavior/shooter-2d.d.ts +0 -79
  76. package/dist/behavior/shooter-2d.js +0 -180
  77. package/dist/behavior/shooter-2d.js.map +0 -1
  78. package/dist/behavior/thruster.d.ts +0 -11
  79. package/dist/behavior/thruster.js +0 -292
  80. package/dist/behavior/thruster.js.map +0 -1
  81. package/dist/behavior/top-down-movement.d.ts +0 -56
  82. package/dist/behavior/top-down-movement.js +0 -125
  83. package/dist/behavior/top-down-movement.js.map +0 -1
  84. package/dist/behavior/world-boundary-2d.d.ts +0 -142
  85. package/dist/behavior/world-boundary-2d.js +0 -235
  86. package/dist/behavior/world-boundary-2d.js.map +0 -1
  87. package/dist/behavior/world-boundary-3d.d.ts +0 -76
  88. package/dist/behavior/world-boundary-3d.js +0 -274
  89. package/dist/behavior/world-boundary-3d.js.map +0 -1
  90. package/dist/behavior-descriptor-BXnVR8Ki.d.ts +0 -159
  91. package/dist/blueprints-DmbK2dki.d.ts +0 -26
  92. package/dist/camera.d.ts +0 -6
  93. package/dist/camera.js +0 -1993
  94. package/dist/camera.js.map +0 -1
  95. package/dist/composition-BASvMKrW.d.ts +0 -218
  96. package/dist/core-CARRaS55.d.ts +0 -541
  97. package/dist/core.js.map +0 -1
  98. package/dist/entities-ChFirVL9.d.ts +0 -410
  99. package/dist/entities.d.ts +0 -9
  100. package/dist/entities.js +0 -4986
  101. package/dist/entities.js.map +0 -1
  102. package/dist/entity-Bq_eNEDI.d.ts +0 -28
  103. package/dist/entity-types-DAu8sGJH.d.ts +0 -26
  104. package/dist/global-change-2JvMaz44.d.ts +0 -25
  105. package/dist/main.d.ts +0 -1353
  106. package/dist/main.js +0 -19525
  107. package/dist/main.js.map +0 -1
  108. package/dist/physics-pose-DCc4oE44.d.ts +0 -25
  109. package/dist/physics-protocol-BDD3P5W2.d.ts +0 -200
  110. package/dist/physics-worker.d.ts +0 -21
  111. package/dist/physics-worker.js +0 -306
  112. package/dist/physics-worker.js.map +0 -1
  113. package/dist/physics.d.ts +0 -205
  114. package/dist/physics.js +0 -577
  115. package/dist/physics.js.map +0 -1
  116. package/dist/stage-types-C19IhuzA.d.ts +0 -731
  117. package/dist/stage.d.ts +0 -52
  118. package/dist/stage.js +0 -8479
  119. package/dist/stage.js.map +0 -1
  120. package/dist/sync-state-machine-CZyspBpj.d.ts +0 -16
  121. package/dist/thruster-23lzoPZd.d.ts +0 -180
  122. package/dist/world-DfgxoNMt.d.ts +0 -105
package/dist/actions.js CHANGED
@@ -1,936 +1 @@
1
- // src/lib/actions/action.ts
2
- var BaseAction = class {
3
- duration;
4
- done = false;
5
- persistent = false;
6
- elapsed = 0;
7
- /** @param durationMs Duration in milliseconds */
8
- constructor(durationMs) {
9
- this.duration = durationMs / 1e3;
10
- }
11
- tick(entity, delta) {
12
- if (this.done) return;
13
- this.elapsed += delta;
14
- const progress = this.duration > 0 ? Math.min(this.elapsed / this.duration, 1) : 1;
15
- this.onTick(entity, delta, progress);
16
- if (this.elapsed >= this.duration) {
17
- this.done = true;
18
- }
19
- }
20
- reset() {
21
- this.elapsed = 0;
22
- this.done = false;
23
- }
24
- };
25
-
26
- // src/lib/actions/capabilities/velocity-intents.ts
27
- function setVelocityIntent(store, sourceId, vector, options = {}) {
28
- const prev = store.velocityChannels[sourceId];
29
- const mode = options.mode ?? prev?.mode ?? "replace";
30
- const priority = options.priority ?? prev?.priority ?? 0;
31
- const isAdditiveMerge = mode === "add" && prev?.mode === "add";
32
- const x = vector.x == null ? prev?.x : isAdditiveMerge ? (prev?.x ?? 0) + vector.x : vector.x;
33
- const y = vector.y == null ? prev?.y : isAdditiveMerge ? (prev?.y ?? 0) + vector.y : vector.y;
34
- const z = vector.z == null ? prev?.z : isAdditiveMerge ? (prev?.z ?? 0) + vector.z : vector.z;
35
- store.velocityChannels[sourceId] = {
36
- x,
37
- y,
38
- z,
39
- mode,
40
- priority
41
- };
42
- store.dirty.velocityChannels = true;
43
- }
44
-
45
- // src/lib/actions/interval-actions.ts
46
- function moveBy(opts) {
47
- return new MoveByAction(opts);
48
- }
49
- var MoveByAction = class extends BaseAction {
50
- dx;
51
- dy;
52
- dz;
53
- constructor(opts) {
54
- super(opts.duration);
55
- this.dx = opts.x ?? 0;
56
- this.dy = opts.y ?? 0;
57
- this.dz = opts.z ?? 0;
58
- }
59
- onTick(entity, delta, _progress) {
60
- if (this.duration <= 0) return;
61
- const vx = this.dx / this.duration;
62
- const vy = this.dy / this.duration;
63
- const vz = this.dz / this.duration;
64
- const store = entity.transformStore;
65
- if (!store) return;
66
- setVelocityIntent(store, "actions", { x: vx, y: vy, z: vz }, { mode: "add" });
67
- }
68
- };
69
- function moveTo(opts) {
70
- return new MoveToAction(opts);
71
- }
72
- var MoveToAction = class extends BaseAction {
73
- targetX;
74
- targetY;
75
- targetZ;
76
- dx = 0;
77
- dy = 0;
78
- dz = 0;
79
- initialized = false;
80
- constructor(opts) {
81
- super(opts.duration);
82
- this.targetX = opts.x;
83
- this.targetY = opts.y;
84
- this.targetZ = opts.z;
85
- }
86
- onTick(entity, delta, _progress) {
87
- if (this.duration <= 0) return;
88
- if (!this.initialized) {
89
- const pos = entity.getPosition?.();
90
- const cx = pos?.x ?? 0;
91
- const cy = pos?.y ?? 0;
92
- const cz = pos?.z ?? 0;
93
- this.dx = this.targetX - cx;
94
- this.dy = this.targetY - cy;
95
- this.dz = this.targetZ - cz;
96
- this.initialized = true;
97
- }
98
- const vx = this.dx / this.duration;
99
- const vy = this.dy / this.duration;
100
- const vz = this.dz / this.duration;
101
- const store = entity.transformStore;
102
- if (!store) return;
103
- setVelocityIntent(store, "actions", { x: vx, y: vy, z: vz }, { mode: "add" });
104
- }
105
- reset() {
106
- super.reset();
107
- this.initialized = false;
108
- }
109
- };
110
- function rotateBy(opts) {
111
- return new RotateByAction(opts);
112
- }
113
- var RotateByAction = class extends BaseAction {
114
- rx;
115
- ry;
116
- rz;
117
- constructor(opts) {
118
- super(opts.duration);
119
- const toRad = Math.PI / 180;
120
- this.rx = (opts.x ?? 0) * toRad;
121
- this.ry = (opts.y ?? 0) * toRad;
122
- this.rz = (opts.z ?? 0) * toRad;
123
- }
124
- onTick(entity, delta, _progress) {
125
- if (this.duration <= 0) return;
126
- const wx = this.rx / this.duration;
127
- const wy = this.ry / this.duration;
128
- const wz = this.rz / this.duration;
129
- const store = entity.transformStore;
130
- store.angularVelocity.x += wx;
131
- store.angularVelocity.y += wy;
132
- store.angularVelocity.z += wz;
133
- store.dirty.angularVelocity = true;
134
- }
135
- };
136
- function delay(ms) {
137
- return new DelayAction(ms);
138
- }
139
- var DelayAction = class extends BaseAction {
140
- constructor(ms) {
141
- super(ms);
142
- }
143
- onTick() {
144
- }
145
- };
146
- function callFunc(fn) {
147
- return new CallFuncAction(fn);
148
- }
149
- var CallFuncAction = class extends BaseAction {
150
- fn;
151
- called = false;
152
- constructor(fn) {
153
- super(0);
154
- this.fn = fn;
155
- }
156
- onTick() {
157
- if (!this.called) {
158
- this.fn();
159
- this.called = true;
160
- }
161
- }
162
- reset() {
163
- super.reset();
164
- this.called = false;
165
- }
166
- };
167
-
168
- // src/lib/actions/persistent-actions.ts
169
- function throttle(opts) {
170
- return new ThrottleAction(opts.duration);
171
- }
172
- var ThrottleAction = class {
173
- duration;
174
- done = false;
175
- persistent = true;
176
- ready = false;
177
- elapsed = 0;
178
- /** @param durationMs Duration in milliseconds */
179
- constructor(durationMs) {
180
- this.duration = durationMs / 1e3;
181
- }
182
- tick(_entity, delta) {
183
- this.elapsed += delta;
184
- if (this.elapsed >= this.duration) {
185
- this.ready = true;
186
- }
187
- }
188
- /** Consume the ready state and reset the timer */
189
- consume() {
190
- this.ready = false;
191
- this.elapsed = 0;
192
- }
193
- reset() {
194
- this.elapsed = 0;
195
- this.ready = false;
196
- }
197
- };
198
- function onPress() {
199
- return new OnPressAction();
200
- }
201
- var OnPressAction = class {
202
- duration = Infinity;
203
- done = false;
204
- persistent = true;
205
- triggered = false;
206
- wasPressed = false;
207
- tick() {
208
- this.triggered = false;
209
- }
210
- /**
211
- * Feed the current pressed state. Sets `.triggered = true` on the
212
- * frame where `isPressed` transitions from false to true.
213
- */
214
- check(isPressed) {
215
- if (isPressed && !this.wasPressed) {
216
- this.triggered = true;
217
- }
218
- this.wasPressed = isPressed;
219
- }
220
- reset() {
221
- this.triggered = false;
222
- this.wasPressed = false;
223
- }
224
- };
225
- function onRelease() {
226
- return new OnReleaseAction();
227
- }
228
- var OnReleaseAction = class {
229
- duration = Infinity;
230
- done = false;
231
- persistent = true;
232
- triggered = false;
233
- wasPressed = false;
234
- tick() {
235
- this.triggered = false;
236
- }
237
- /**
238
- * Feed the current pressed state. Sets `.triggered = true` on the
239
- * frame where `isPressed` transitions from true to false.
240
- */
241
- check(isPressed) {
242
- if (!isPressed && this.wasPressed) {
243
- this.triggered = true;
244
- }
245
- this.wasPressed = isPressed;
246
- }
247
- reset() {
248
- this.triggered = false;
249
- this.wasPressed = false;
250
- }
251
- };
252
-
253
- // src/lib/actions/composition.ts
254
- function sequence(...actions) {
255
- return new SequenceAction(actions);
256
- }
257
- var SequenceAction = class {
258
- duration;
259
- done = false;
260
- persistent = false;
261
- actions;
262
- currentIndex = 0;
263
- constructor(actions) {
264
- this.actions = actions;
265
- this.duration = actions.reduce((sum, a) => sum + a.duration, 0);
266
- }
267
- tick(entity, delta) {
268
- if (this.done || this.actions.length === 0) {
269
- this.done = true;
270
- return;
271
- }
272
- let remaining = delta;
273
- while (remaining > 0 && this.currentIndex < this.actions.length) {
274
- const current = this.actions[this.currentIndex];
275
- current.tick(entity, remaining);
276
- if (current.done) {
277
- const actionDuration = current.duration;
278
- const actionElapsed = current.elapsed ?? actionDuration;
279
- const overflow = Math.max(0, actionElapsed - actionDuration);
280
- remaining = overflow;
281
- this.currentIndex++;
282
- } else {
283
- remaining = 0;
284
- }
285
- }
286
- if (this.currentIndex >= this.actions.length) {
287
- this.done = true;
288
- }
289
- }
290
- reset() {
291
- this.currentIndex = 0;
292
- this.done = false;
293
- for (const action of this.actions) {
294
- action.reset();
295
- }
296
- }
297
- };
298
- function parallel(...actions) {
299
- return new ParallelAction(actions);
300
- }
301
- var ParallelAction = class {
302
- duration;
303
- done = false;
304
- persistent = false;
305
- actions;
306
- constructor(actions) {
307
- this.actions = actions;
308
- this.duration = Math.max(0, ...actions.map((a) => a.duration));
309
- }
310
- tick(entity, delta) {
311
- if (this.done) return;
312
- let allDone = true;
313
- for (const action of this.actions) {
314
- if (!action.done) {
315
- action.tick(entity, delta);
316
- }
317
- if (!action.done) {
318
- allDone = false;
319
- }
320
- }
321
- if (allDone) {
322
- this.done = true;
323
- }
324
- }
325
- reset() {
326
- this.done = false;
327
- for (const action of this.actions) {
328
- action.reset();
329
- }
330
- }
331
- };
332
- function repeat(action, times) {
333
- return new RepeatAction(action, times);
334
- }
335
- var RepeatAction = class {
336
- duration;
337
- done = false;
338
- persistent = false;
339
- action;
340
- totalTimes;
341
- currentCount = 0;
342
- constructor(action, times) {
343
- this.action = action;
344
- this.totalTimes = times;
345
- this.duration = action.duration * times;
346
- }
347
- tick(entity, delta) {
348
- if (this.done) return;
349
- this.action.tick(entity, delta);
350
- if (this.action.done) {
351
- this.currentCount++;
352
- if (this.currentCount >= this.totalTimes) {
353
- this.done = true;
354
- } else {
355
- this.action.reset();
356
- }
357
- }
358
- }
359
- reset() {
360
- this.currentCount = 0;
361
- this.done = false;
362
- this.action.reset();
363
- }
364
- };
365
- function repeatForever(action) {
366
- return new RepeatForeverAction(action);
367
- }
368
- var RepeatForeverAction = class {
369
- duration = Infinity;
370
- done = false;
371
- persistent = false;
372
- action;
373
- constructor(action) {
374
- this.action = action;
375
- }
376
- tick(entity, delta) {
377
- this.action.tick(entity, delta);
378
- if (this.action.done) {
379
- this.action.reset();
380
- }
381
- }
382
- reset() {
383
- this.done = false;
384
- this.action.reset();
385
- }
386
- };
387
-
388
- // src/lib/actions/capabilities/transform-store.ts
389
- import { proxy } from "valtio";
390
- function createTransformStore(initial) {
391
- const defaultState = {
392
- position: { x: 0, y: 0, z: 0 },
393
- rotation: { x: 0, y: 0, z: 0, w: 1 },
394
- velocity: { x: 0, y: 0, z: 0 },
395
- angularVelocity: { x: 0, y: 0, z: 0 },
396
- velocityChannels: {},
397
- dirty: {
398
- position: false,
399
- rotation: false,
400
- velocity: false,
401
- velocityX: false,
402
- velocityY: false,
403
- velocityZ: false,
404
- velocityChannels: false,
405
- angularVelocity: false
406
- }
407
- };
408
- return proxy({
409
- ...defaultState,
410
- ...initial,
411
- // Ensure dirty flags are properly initialized even if partial initial state
412
- dirty: {
413
- ...defaultState.dirty,
414
- ...initial?.dirty
415
- }
416
- });
417
- }
418
- function resetTransformStore(store) {
419
- store.position.x = 0;
420
- store.position.y = 0;
421
- store.position.z = 0;
422
- store.rotation.x = 0;
423
- store.rotation.y = 0;
424
- store.rotation.z = 0;
425
- store.rotation.w = 1;
426
- store.velocity.x = 0;
427
- store.velocity.y = 0;
428
- store.velocity.z = 0;
429
- store.angularVelocity.x = 0;
430
- store.angularVelocity.y = 0;
431
- store.angularVelocity.z = 0;
432
- for (const sourceId of Object.keys(store.velocityChannels)) {
433
- delete store.velocityChannels[sourceId];
434
- }
435
- store.dirty.position = false;
436
- store.dirty.rotation = false;
437
- store.dirty.velocity = false;
438
- store.dirty.velocityX = false;
439
- store.dirty.velocityY = false;
440
- store.dirty.velocityZ = false;
441
- store.dirty.velocityChannels = false;
442
- store.dirty.angularVelocity = false;
443
- }
444
-
445
- // src/lib/actions/capabilities/apply-transform.ts
446
- function sortIntents(a, b) {
447
- if (a.priority !== b.priority) return a.priority - b.priority;
448
- return a.sourceId.localeCompare(b.sourceId);
449
- }
450
- function composeAxis(current, intents, axis) {
451
- let touched = false;
452
- let addSum = 0;
453
- let hasReplace = false;
454
- let replaceValue = current;
455
- let replacePriority = Number.NEGATIVE_INFINITY;
456
- for (const intent of intents) {
457
- const axisValue = intent[axis];
458
- if (axisValue == null) continue;
459
- touched = true;
460
- if (intent.mode === "add") {
461
- addSum += axisValue;
462
- continue;
463
- }
464
- if (!hasReplace || intent.priority >= replacePriority) {
465
- hasReplace = true;
466
- replacePriority = intent.priority;
467
- replaceValue = axisValue;
468
- }
469
- }
470
- return {
471
- touched,
472
- value: (hasReplace ? replaceValue : 0) + addSum
473
- };
474
- }
475
- function composeVelocity(current, intents) {
476
- return {
477
- x: composeAxis(current.x, intents, "x"),
478
- y: composeAxis(current.y, intents, "y"),
479
- z: composeAxis(current.z, intents, "z")
480
- };
481
- }
482
- function clearVelocityChannels(store) {
483
- for (const sourceId in store.velocityChannels) {
484
- delete store.velocityChannels[sourceId];
485
- }
486
- store.dirty.velocityChannels = false;
487
- }
488
- function applyTransformChanges(entity, store) {
489
- if (!entity.body) return;
490
- const hasPosition = store.dirty.position;
491
- const hasRotation = store.dirty.rotation;
492
- const hasAngularVelocity = store.dirty.angularVelocity;
493
- const hasPerAxis = store.dirty.velocityX || store.dirty.velocityY || store.dirty.velocityZ;
494
- const hasLegacyVelocity = store.dirty.velocity;
495
- const hasChannels = store.dirty.velocityChannels;
496
- if (!hasPosition && !hasRotation && !hasAngularVelocity && !hasPerAxis && !hasLegacyVelocity && !hasChannels) {
497
- return;
498
- }
499
- const intents = [];
500
- if (hasChannels) {
501
- for (const sourceId in store.velocityChannels) {
502
- const intent = store.velocityChannels[sourceId];
503
- intents.push({
504
- sourceId,
505
- mode: intent.mode ?? "replace",
506
- priority: intent.priority ?? 0,
507
- x: intent.x,
508
- y: intent.y,
509
- z: intent.z
510
- });
511
- }
512
- }
513
- if (hasLegacyVelocity) {
514
- intents.push({
515
- sourceId: "__legacy_velocity__",
516
- mode: "replace",
517
- priority: -100,
518
- x: store.velocity.x,
519
- y: store.velocity.y,
520
- z: store.velocity.z
521
- });
522
- } else if (hasPerAxis) {
523
- intents.push({
524
- sourceId: "__legacy_per_axis__",
525
- mode: "replace",
526
- priority: -100,
527
- x: store.dirty.velocityX ? store.velocity.x : void 0,
528
- y: store.dirty.velocityY ? store.velocity.y : void 0,
529
- z: store.dirty.velocityZ ? store.velocity.z : void 0
530
- });
531
- }
532
- if (intents.length > 0) {
533
- const current = entity.body.linvel();
534
- if (intents.length > 1) {
535
- intents.sort(sortIntents);
536
- }
537
- const composed = composeVelocity(current, intents);
538
- entity.body.setLinvel(
539
- {
540
- x: composed.x.touched ? composed.x.value : current.x,
541
- y: composed.y.touched ? composed.y.value : current.y,
542
- z: composed.z.touched ? composed.z.value : current.z
543
- },
544
- true
545
- );
546
- }
547
- if (hasRotation) {
548
- entity.body.setRotation(store.rotation, true);
549
- }
550
- if (hasAngularVelocity) {
551
- entity.body.setAngvel(store.angularVelocity, true);
552
- }
553
- if (hasPosition) {
554
- const current = entity.body.translation();
555
- entity.body.setTranslation(
556
- {
557
- x: current.x + store.position.x,
558
- y: current.y + store.position.y,
559
- z: current.z + store.position.z
560
- },
561
- true
562
- );
563
- }
564
- store.dirty.position = false;
565
- store.dirty.rotation = false;
566
- store.dirty.velocity = false;
567
- store.dirty.velocityX = false;
568
- store.dirty.velocityY = false;
569
- store.dirty.velocityZ = false;
570
- clearVelocityChannels(store);
571
- store.dirty.angularVelocity = false;
572
- }
573
-
574
- // src/lib/actions/capabilities/moveable.ts
575
- import { Vector3 } from "three";
576
- function moveX(entity, delta) {
577
- if (!entity.transformStore) return;
578
- setVelocityIntent(entity.transformStore, "actions", { x: delta }, { mode: "replace" });
579
- }
580
- function moveY(entity, delta) {
581
- if (!entity.transformStore) return;
582
- setVelocityIntent(entity.transformStore, "actions", { y: delta }, { mode: "replace" });
583
- }
584
- function moveZ(entity, delta) {
585
- if (!entity.transformStore) return;
586
- setVelocityIntent(entity.transformStore, "actions", { z: delta }, { mode: "replace" });
587
- }
588
- function moveXY(entity, deltaX, deltaY) {
589
- if (!entity.transformStore) return;
590
- setVelocityIntent(
591
- entity.transformStore,
592
- "actions",
593
- { x: deltaX, y: deltaY },
594
- { mode: "replace" }
595
- );
596
- }
597
- function moveXZ(entity, deltaX, deltaZ) {
598
- if (!entity.transformStore) return;
599
- setVelocityIntent(
600
- entity.transformStore,
601
- "actions",
602
- { x: deltaX, z: deltaZ },
603
- { mode: "replace" }
604
- );
605
- }
606
- function move(entity, vector) {
607
- if (!entity.transformStore) return;
608
- setVelocityIntent(
609
- entity.transformStore,
610
- "actions",
611
- { x: vector.x, y: vector.y, z: vector.z },
612
- { mode: "add" }
613
- );
614
- }
615
- function resetVelocity(entity) {
616
- if (!entity.body) return;
617
- entity.body.setLinvel(new Vector3(0, 0, 0), true);
618
- entity.body.setLinearDamping(5);
619
- }
620
- function moveForwardXY(entity, delta, rotation2DAngle) {
621
- const deltaX = Math.sin(-rotation2DAngle) * delta;
622
- const deltaY = Math.cos(-rotation2DAngle) * delta;
623
- moveXY(entity, deltaX, deltaY);
624
- }
625
- function getPosition(entity) {
626
- if (!entity.body) return null;
627
- return entity.body.translation();
628
- }
629
- function getVelocity(entity) {
630
- if (!entity.body) return null;
631
- return entity.body.linvel();
632
- }
633
- function setPosition(entity, x, y, z) {
634
- if (!entity.body) return;
635
- entity.body.setTranslation({ x, y, z }, true);
636
- }
637
- function setPositionX(entity, x) {
638
- if (!entity.body) return;
639
- const { y, z } = entity.body.translation();
640
- entity.body.setTranslation({ x, y, z }, true);
641
- }
642
- function setPositionY(entity, y) {
643
- if (!entity.body) return;
644
- const { x, z } = entity.body.translation();
645
- entity.body.setTranslation({ x, y, z }, true);
646
- }
647
- function setPositionZ(entity, z) {
648
- if (!entity.body) return;
649
- const { x, y } = entity.body.translation();
650
- entity.body.setTranslation({ x, y, z }, true);
651
- }
652
- function wrapAroundXY(entity, boundsX, boundsY) {
653
- const position = getPosition(entity);
654
- if (!position) return;
655
- const { x, y } = position;
656
- const newX = x > boundsX ? -boundsX : x < -boundsX ? boundsX : x;
657
- const newY = y > boundsY ? -boundsY : y < -boundsY ? boundsY : y;
658
- if (newX !== x || newY !== y) {
659
- setPosition(entity, newX, newY, 0);
660
- }
661
- }
662
- function wrapAround3D(entity, boundsX, boundsY, boundsZ) {
663
- const position = getPosition(entity);
664
- if (!position) return;
665
- const { x, y, z } = position;
666
- const newX = x > boundsX ? -boundsX : x < -boundsX ? boundsX : x;
667
- const newY = y > boundsY ? -boundsY : y < -boundsY ? boundsY : y;
668
- const newZ = z > boundsZ ? -boundsZ : z < -boundsZ ? boundsZ : z;
669
- if (newX !== x || newY !== y || newZ !== z) {
670
- setPosition(entity, newX, newY, newZ);
671
- }
672
- }
673
-
674
- // src/lib/actions/capabilities/rotatable.ts
675
- import { Euler, Vector3 as Vector32, MathUtils, Quaternion } from "three";
676
- function syncImmediateRotation(entity) {
677
- if (!entity.group || !entity.transformStore) return;
678
- entity.group.setRotationFromQuaternion(
679
- new Quaternion(
680
- entity.transformStore.rotation.x,
681
- entity.transformStore.rotation.y,
682
- entity.transformStore.rotation.z,
683
- entity.transformStore.rotation.w
684
- )
685
- );
686
- }
687
- function rotateInDirection(entity, moveVector) {
688
- if (!entity.body) return;
689
- const rotate = Math.atan2(-moveVector.x, moveVector.z);
690
- rotateYEuler(entity, rotate);
691
- }
692
- function rotateYEuler(entity, amount) {
693
- rotateEuler(entity, new Vector32(0, -amount, 0));
694
- }
695
- function rotateEuler(entity, rotation) {
696
- if (!entity.transformStore) return;
697
- const quat = new Quaternion().setFromEuler(
698
- new Euler(rotation.x, rotation.y, rotation.z)
699
- );
700
- entity.transformStore.rotation.w = quat.w;
701
- entity.transformStore.rotation.x = quat.x;
702
- entity.transformStore.rotation.y = quat.y;
703
- entity.transformStore.rotation.z = quat.z;
704
- entity.transformStore.dirty.rotation = true;
705
- syncImmediateRotation(entity);
706
- }
707
- function rotateY(entity, delta) {
708
- if (!entity.transformStore) return;
709
- const halfAngle = delta / 2;
710
- const deltaW = Math.cos(halfAngle);
711
- const deltaY = Math.sin(halfAngle);
712
- const q = entity.transformStore.rotation;
713
- const newW = q.w * deltaW - q.y * deltaY;
714
- const newX = q.x * deltaW + q.z * deltaY;
715
- const newY = q.y * deltaW + q.w * deltaY;
716
- const newZ = q.z * deltaW - q.x * deltaY;
717
- entity.transformStore.rotation.w = newW;
718
- entity.transformStore.rotation.x = newX;
719
- entity.transformStore.rotation.y = newY;
720
- entity.transformStore.rotation.z = newZ;
721
- entity.transformStore.dirty.rotation = true;
722
- syncImmediateRotation(entity);
723
- }
724
- function rotateX(entity, delta) {
725
- if (!entity.transformStore) return;
726
- const halfAngle = delta / 2;
727
- const deltaW = Math.cos(halfAngle);
728
- const deltaX = Math.sin(halfAngle);
729
- const q = entity.transformStore.rotation;
730
- const newW = q.w * deltaW - q.x * deltaX;
731
- const newX = q.x * deltaW + q.w * deltaX;
732
- const newY = q.y * deltaW + q.z * deltaX;
733
- const newZ = q.z * deltaW - q.y * deltaX;
734
- entity.transformStore.rotation.w = newW;
735
- entity.transformStore.rotation.x = newX;
736
- entity.transformStore.rotation.y = newY;
737
- entity.transformStore.rotation.z = newZ;
738
- entity.transformStore.dirty.rotation = true;
739
- syncImmediateRotation(entity);
740
- }
741
- function rotateZ(entity, delta) {
742
- if (!entity.transformStore) return;
743
- const halfAngle = delta / 2;
744
- const deltaW = Math.cos(halfAngle);
745
- const deltaZ = Math.sin(halfAngle);
746
- const q = entity.transformStore.rotation;
747
- const newW = q.w * deltaW - q.z * deltaZ;
748
- const newX = q.x * deltaW - q.y * deltaZ;
749
- const newY = q.y * deltaW + q.x * deltaZ;
750
- const newZ = q.z * deltaW + q.w * deltaZ;
751
- entity.transformStore.rotation.w = newW;
752
- entity.transformStore.rotation.x = newX;
753
- entity.transformStore.rotation.y = newY;
754
- entity.transformStore.rotation.z = newZ;
755
- entity.transformStore.dirty.rotation = true;
756
- entity._rotation2DAngle = (entity._rotation2DAngle ?? 0) + delta;
757
- syncImmediateRotation(entity);
758
- }
759
- function setRotationY(entity, y) {
760
- if (!entity.transformStore) return;
761
- const halfAngle = y / 2;
762
- const w = Math.cos(halfAngle);
763
- const yComponent = Math.sin(halfAngle);
764
- entity.transformStore.rotation.w = w;
765
- entity.transformStore.rotation.x = 0;
766
- entity.transformStore.rotation.y = yComponent;
767
- entity.transformStore.rotation.z = 0;
768
- entity.transformStore.dirty.rotation = true;
769
- syncImmediateRotation(entity);
770
- }
771
- function setRotationDegreesY(entity, y) {
772
- if (!entity.body) return;
773
- setRotationY(entity, MathUtils.degToRad(y));
774
- }
775
- function setRotationX(entity, x) {
776
- if (!entity.transformStore) return;
777
- const halfAngle = x / 2;
778
- const w = Math.cos(halfAngle);
779
- const xComponent = Math.sin(halfAngle);
780
- entity.transformStore.rotation.w = w;
781
- entity.transformStore.rotation.x = xComponent;
782
- entity.transformStore.rotation.y = 0;
783
- entity.transformStore.rotation.z = 0;
784
- entity.transformStore.dirty.rotation = true;
785
- syncImmediateRotation(entity);
786
- }
787
- function setRotationDegreesX(entity, x) {
788
- if (!entity.body) return;
789
- setRotationX(entity, MathUtils.degToRad(x));
790
- }
791
- function setRotationZ(entity, z) {
792
- if (!entity.transformStore) return;
793
- const halfAngle = z / 2;
794
- const w = Math.cos(halfAngle);
795
- const zComponent = Math.sin(halfAngle);
796
- entity.transformStore.rotation.w = w;
797
- entity.transformStore.rotation.x = 0;
798
- entity.transformStore.rotation.y = 0;
799
- entity.transformStore.rotation.z = zComponent;
800
- entity.transformStore.dirty.rotation = true;
801
- entity._rotation2DAngle = z;
802
- syncImmediateRotation(entity);
803
- }
804
- function setRotationDegreesZ(entity, z) {
805
- if (!entity.body) return;
806
- setRotationZ(entity, MathUtils.degToRad(z));
807
- }
808
- function setRotation(entity, x, y, z) {
809
- if (!entity.transformStore) return;
810
- const quat = new Quaternion().setFromEuler(new Euler(x, y, z));
811
- entity.transformStore.rotation.w = quat.w;
812
- entity.transformStore.rotation.x = quat.x;
813
- entity.transformStore.rotation.y = quat.y;
814
- entity.transformStore.rotation.z = quat.z;
815
- entity.transformStore.dirty.rotation = true;
816
- entity._rotation2DAngle = z;
817
- syncImmediateRotation(entity);
818
- }
819
- function setRotationDegrees(entity, x, y, z) {
820
- if (!entity.body) return;
821
- setRotation(entity, MathUtils.degToRad(x), MathUtils.degToRad(y), MathUtils.degToRad(z));
822
- }
823
- function getRotation(entity) {
824
- if (!entity.body) return null;
825
- return entity.body.rotation();
826
- }
827
-
828
- // src/lib/actions/global-change.ts
829
- function globalChange(key, callback) {
830
- let previousValue = void 0;
831
- return (ctx) => {
832
- const currentValue = ctx.globals?.[key];
833
- if (previousValue !== currentValue) {
834
- if (!(previousValue === void 0 && currentValue === void 0)) {
835
- callback(currentValue, ctx);
836
- }
837
- previousValue = currentValue;
838
- }
839
- };
840
- }
841
- function globalChanges(keys, callback) {
842
- let previousValues = new Array(keys.length).fill(void 0);
843
- return (ctx) => {
844
- const currentValues = keys.map((k) => ctx.globals?.[k]);
845
- const hasAnyChange = currentValues.some((val, idx) => previousValues[idx] !== val);
846
- if (hasAnyChange) {
847
- const allPrevUndef = previousValues.every((v) => v === void 0);
848
- const allCurrUndef = currentValues.every((v) => v === void 0);
849
- if (!(allPrevUndef && allCurrUndef)) {
850
- callback(currentValues, ctx);
851
- }
852
- previousValues = currentValues;
853
- }
854
- };
855
- }
856
- function variableChange(key, callback) {
857
- let previousValue = void 0;
858
- return (ctx) => {
859
- const currentValue = ctx.stage?.getVariable?.(key) ?? void 0;
860
- if (previousValue !== currentValue) {
861
- if (!(previousValue === void 0 && currentValue === void 0)) {
862
- callback(currentValue, ctx);
863
- }
864
- previousValue = currentValue;
865
- }
866
- };
867
- }
868
- function variableChanges(keys, callback) {
869
- let previousValues = new Array(keys.length).fill(void 0);
870
- return (ctx) => {
871
- const reader = (k) => ctx.stage?.getVariable?.(k);
872
- const currentValues = keys.map(reader);
873
- const hasAnyChange = currentValues.some((val, idx) => previousValues[idx] !== val);
874
- if (hasAnyChange) {
875
- const allPrevUndef = previousValues.every((v) => v === void 0);
876
- const allCurrUndef = currentValues.every((v) => v === void 0);
877
- if (!(allPrevUndef && allCurrUndef)) {
878
- callback(currentValues, ctx);
879
- }
880
- previousValues = currentValues;
881
- }
882
- };
883
- }
884
- export {
885
- applyTransformChanges,
886
- callFunc,
887
- createTransformStore,
888
- delay,
889
- getPosition,
890
- getRotation,
891
- getVelocity,
892
- globalChange,
893
- globalChanges,
894
- move,
895
- moveBy,
896
- moveForwardXY,
897
- moveTo,
898
- moveX,
899
- moveXY,
900
- moveXZ,
901
- moveY,
902
- moveZ,
903
- onPress,
904
- onRelease,
905
- parallel,
906
- repeat,
907
- repeatForever,
908
- resetTransformStore,
909
- resetVelocity,
910
- rotateBy,
911
- rotateEuler,
912
- rotateInDirection,
913
- rotateX,
914
- rotateY,
915
- rotateYEuler,
916
- rotateZ,
917
- sequence,
918
- setPosition,
919
- setPositionX,
920
- setPositionY,
921
- setPositionZ,
922
- setRotation,
923
- setRotationDegrees,
924
- setRotationDegreesX,
925
- setRotationDegreesY,
926
- setRotationDegreesZ,
927
- setRotationX,
928
- setRotationY,
929
- setRotationZ,
930
- throttle,
931
- variableChange,
932
- variableChanges,
933
- wrapAround3D,
934
- wrapAroundXY
935
- };
936
- //# sourceMappingURL=actions.js.map
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};