@zylem/game-lib 0.6.2 → 0.6.3

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -16
  3. package/dist/actions.d.ts +30 -21
  4. package/dist/actions.js +628 -145
  5. package/dist/actions.js.map +1 -1
  6. package/dist/behavior/platformer-3d.d.ts +296 -0
  7. package/dist/behavior/platformer-3d.js +518 -0
  8. package/dist/behavior/platformer-3d.js.map +1 -0
  9. package/dist/behavior/ricochet-2d.d.ts +274 -0
  10. package/dist/behavior/ricochet-2d.js +394 -0
  11. package/dist/behavior/ricochet-2d.js.map +1 -0
  12. package/dist/behavior/screen-wrap.d.ts +86 -0
  13. package/dist/behavior/screen-wrap.js +195 -0
  14. package/dist/behavior/screen-wrap.js.map +1 -0
  15. package/dist/behavior/thruster.d.ts +10 -0
  16. package/dist/behavior/thruster.js +234 -0
  17. package/dist/behavior/thruster.js.map +1 -0
  18. package/dist/behavior/world-boundary-2d.d.ts +141 -0
  19. package/dist/behavior/world-boundary-2d.js +181 -0
  20. package/dist/behavior/world-boundary-2d.js.map +1 -0
  21. package/dist/behavior-descriptor-BWNWmIjv.d.ts +142 -0
  22. package/dist/{blueprints-Cq3Ko6_G.d.ts → blueprints-BWGz8fII.d.ts} +2 -2
  23. package/dist/camera-B5e4c78l.d.ts +468 -0
  24. package/dist/camera.d.ts +3 -2
  25. package/dist/camera.js +900 -211
  26. package/dist/camera.js.map +1 -1
  27. package/dist/composition-DrzFrbqI.d.ts +218 -0
  28. package/dist/{core-bO8TzV7u.d.ts → core-DAkskq6Y.d.ts} +60 -62
  29. package/dist/core.d.ts +10 -6
  30. package/dist/core.js +6896 -5020
  31. package/dist/core.js.map +1 -1
  32. package/dist/{entities-DvByhMGU.d.ts → entities-DC9ce_vx.d.ts} +113 -3
  33. package/dist/entities.d.ts +5 -3
  34. package/dist/entities.js +3727 -3167
  35. package/dist/entities.js.map +1 -1
  36. package/dist/entity-BpbZqg19.d.ts +1100 -0
  37. package/dist/global-change-Dc8uCKi2.d.ts +25 -0
  38. package/dist/main.d.ts +418 -15
  39. package/dist/main.js +11384 -8515
  40. package/dist/main.js.map +1 -1
  41. package/dist/{stage-types-Bd-KtcYT.d.ts → stage-types-BFsm3qsZ.d.ts} +205 -13
  42. package/dist/stage.d.ts +10 -7
  43. package/dist/stage.js +5311 -3880
  44. package/dist/stage.js.map +1 -1
  45. package/dist/thruster-DhRaJnoL.d.ts +172 -0
  46. package/dist/world-Be5m1XC1.d.ts +31 -0
  47. package/package.json +29 -13
  48. package/dist/behaviors.d.ts +0 -854
  49. package/dist/behaviors.js +0 -1209
  50. package/dist/behaviors.js.map +0 -1
  51. package/dist/camera-CeJPAgGg.d.ts +0 -116
  52. package/dist/moveable-B_vyA6cw.d.ts +0 -67
  53. package/dist/transformable-CUhvyuYO.d.ts +0 -67
  54. package/dist/world-C8tQ7Plj.d.ts +0 -774
package/dist/actions.js CHANGED
@@ -1,113 +1,480 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
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
+ }
5
24
  };
6
25
 
7
- // src/lib/actions/behaviors/actions.ts
8
- var actions_exports = {};
9
- __export(actions_exports, {
10
- actionOnPress: () => actionOnPress,
11
- actionOnRelease: () => actionOnRelease,
12
- actionWithCooldown: () => actionWithCooldown,
13
- actionWithThrottle: () => actionWithThrottle,
14
- wait: () => wait
15
- });
16
- function wait(delay, callback) {
17
- setTimeout(callback, delay);
18
- }
19
- var actionOnPress = /* @__PURE__ */ (() => {
20
- let buttonPressed = false;
21
- return (isPressed, callback) => {
22
- if (isPressed && !buttonPressed) {
23
- buttonPressed = true;
24
- callback();
25
- } else if (!isPressed) {
26
- buttonPressed = false;
26
+ // src/lib/actions/interval-actions.ts
27
+ function moveBy(opts) {
28
+ return new MoveByAction(opts);
29
+ }
30
+ var MoveByAction = class extends BaseAction {
31
+ dx;
32
+ dy;
33
+ dz;
34
+ constructor(opts) {
35
+ super(opts.duration);
36
+ this.dx = opts.x ?? 0;
37
+ this.dy = opts.y ?? 0;
38
+ this.dz = opts.z ?? 0;
39
+ }
40
+ onTick(entity, delta, _progress) {
41
+ if (this.duration <= 0) return;
42
+ const vx = this.dx / this.duration;
43
+ const vy = this.dy / this.duration;
44
+ const vz = this.dz / this.duration;
45
+ const store = entity.transformStore;
46
+ store.velocity.x += vx;
47
+ store.velocity.y += vy;
48
+ store.velocity.z += vz;
49
+ store.dirty.velocity = true;
50
+ }
51
+ };
52
+ function moveTo(opts) {
53
+ return new MoveToAction(opts);
54
+ }
55
+ var MoveToAction = class extends BaseAction {
56
+ targetX;
57
+ targetY;
58
+ targetZ;
59
+ dx = 0;
60
+ dy = 0;
61
+ dz = 0;
62
+ initialized = false;
63
+ constructor(opts) {
64
+ super(opts.duration);
65
+ this.targetX = opts.x;
66
+ this.targetY = opts.y;
67
+ this.targetZ = opts.z;
68
+ }
69
+ onTick(entity, delta, _progress) {
70
+ if (this.duration <= 0) return;
71
+ if (!this.initialized) {
72
+ const pos = entity.getPosition?.();
73
+ const cx = pos?.x ?? 0;
74
+ const cy = pos?.y ?? 0;
75
+ const cz = pos?.z ?? 0;
76
+ this.dx = this.targetX - cx;
77
+ this.dy = this.targetY - cy;
78
+ this.dz = this.targetZ - cz;
79
+ this.initialized = true;
27
80
  }
28
- };
29
- })();
30
- var actionOnRelease = /* @__PURE__ */ (() => {
31
- let buttonPressed = false;
32
- return (isPressed, callback) => {
33
- if (!isPressed && buttonPressed) {
34
- buttonPressed = false;
35
- callback();
36
- } else if (isPressed) {
37
- buttonPressed = true;
81
+ const vx = this.dx / this.duration;
82
+ const vy = this.dy / this.duration;
83
+ const vz = this.dz / this.duration;
84
+ const store = entity.transformStore;
85
+ store.velocity.x += vx;
86
+ store.velocity.y += vy;
87
+ store.velocity.z += vz;
88
+ store.dirty.velocity = true;
89
+ }
90
+ reset() {
91
+ super.reset();
92
+ this.initialized = false;
93
+ }
94
+ };
95
+ function rotateBy(opts) {
96
+ return new RotateByAction(opts);
97
+ }
98
+ var RotateByAction = class extends BaseAction {
99
+ rx;
100
+ ry;
101
+ rz;
102
+ constructor(opts) {
103
+ super(opts.duration);
104
+ const toRad = Math.PI / 180;
105
+ this.rx = (opts.x ?? 0) * toRad;
106
+ this.ry = (opts.y ?? 0) * toRad;
107
+ this.rz = (opts.z ?? 0) * toRad;
108
+ }
109
+ onTick(entity, delta, _progress) {
110
+ if (this.duration <= 0) return;
111
+ const wx = this.rx / this.duration;
112
+ const wy = this.ry / this.duration;
113
+ const wz = this.rz / this.duration;
114
+ const store = entity.transformStore;
115
+ store.angularVelocity.x += wx;
116
+ store.angularVelocity.y += wy;
117
+ store.angularVelocity.z += wz;
118
+ store.dirty.angularVelocity = true;
119
+ }
120
+ };
121
+ function delay(ms) {
122
+ return new DelayAction(ms);
123
+ }
124
+ var DelayAction = class extends BaseAction {
125
+ constructor(ms) {
126
+ super(ms);
127
+ }
128
+ onTick() {
129
+ }
130
+ };
131
+ function callFunc(fn) {
132
+ return new CallFuncAction(fn);
133
+ }
134
+ var CallFuncAction = class extends BaseAction {
135
+ fn;
136
+ called = false;
137
+ constructor(fn) {
138
+ super(0);
139
+ this.fn = fn;
140
+ }
141
+ onTick() {
142
+ if (!this.called) {
143
+ this.fn();
144
+ this.called = true;
38
145
  }
39
- };
40
- })();
41
- var actionWithCooldown = /* @__PURE__ */ (() => {
42
- let lastExecutionTime = -Infinity;
43
- let flagImmediate = false;
44
- return ({ timer, immediate = true }, callback, update) => {
45
- let currentTime = Date.now();
46
- if (!flagImmediate && !immediate) {
47
- flagImmediate = true;
48
- lastExecutionTime = currentTime;
146
+ }
147
+ reset() {
148
+ super.reset();
149
+ this.called = false;
150
+ }
151
+ };
152
+
153
+ // src/lib/actions/persistent-actions.ts
154
+ function throttle(opts) {
155
+ return new ThrottleAction(opts.duration);
156
+ }
157
+ var ThrottleAction = class {
158
+ duration;
159
+ done = false;
160
+ persistent = true;
161
+ ready = false;
162
+ elapsed = 0;
163
+ /** @param durationMs Duration in milliseconds */
164
+ constructor(durationMs) {
165
+ this.duration = durationMs / 1e3;
166
+ }
167
+ tick(_entity, delta) {
168
+ this.elapsed += delta;
169
+ if (this.elapsed >= this.duration) {
170
+ this.ready = true;
49
171
  }
50
- const delta = currentTime - lastExecutionTime;
51
- if (delta >= timer) {
52
- lastExecutionTime = currentTime;
53
- callback();
172
+ }
173
+ /** Consume the ready state and reset the timer */
174
+ consume() {
175
+ this.ready = false;
176
+ this.elapsed = 0;
177
+ }
178
+ reset() {
179
+ this.elapsed = 0;
180
+ this.ready = false;
181
+ }
182
+ };
183
+ function onPress() {
184
+ return new OnPressAction();
185
+ }
186
+ var OnPressAction = class {
187
+ duration = Infinity;
188
+ done = false;
189
+ persistent = true;
190
+ triggered = false;
191
+ wasPressed = false;
192
+ tick() {
193
+ this.triggered = false;
194
+ }
195
+ /**
196
+ * Feed the current pressed state. Sets `.triggered = true` on the
197
+ * frame where `isPressed` transitions from false to true.
198
+ */
199
+ check(isPressed) {
200
+ if (isPressed && !this.wasPressed) {
201
+ this.triggered = true;
54
202
  }
55
- update({ delta });
56
- };
57
- })();
58
- var actionWithThrottle = /* @__PURE__ */ (() => {
59
- let lastExecutionTime = 0;
60
- return (timer, callback) => {
61
- const currentTime = Date.now();
62
- const delta = currentTime - lastExecutionTime;
63
- if (delta >= timer) {
64
- lastExecutionTime = currentTime;
65
- callback();
203
+ this.wasPressed = isPressed;
204
+ }
205
+ reset() {
206
+ this.triggered = false;
207
+ this.wasPressed = false;
208
+ }
209
+ };
210
+ function onRelease() {
211
+ return new OnReleaseAction();
212
+ }
213
+ var OnReleaseAction = class {
214
+ duration = Infinity;
215
+ done = false;
216
+ persistent = true;
217
+ triggered = false;
218
+ wasPressed = false;
219
+ tick() {
220
+ this.triggered = false;
221
+ }
222
+ /**
223
+ * Feed the current pressed state. Sets `.triggered = true` on the
224
+ * frame where `isPressed` transitions from true to false.
225
+ */
226
+ check(isPressed) {
227
+ if (!isPressed && this.wasPressed) {
228
+ this.triggered = true;
229
+ }
230
+ this.wasPressed = isPressed;
231
+ }
232
+ reset() {
233
+ this.triggered = false;
234
+ this.wasPressed = false;
235
+ }
236
+ };
237
+
238
+ // src/lib/actions/composition.ts
239
+ function sequence(...actions) {
240
+ return new SequenceAction(actions);
241
+ }
242
+ var SequenceAction = class {
243
+ duration;
244
+ done = false;
245
+ persistent = false;
246
+ actions;
247
+ currentIndex = 0;
248
+ constructor(actions) {
249
+ this.actions = actions;
250
+ this.duration = actions.reduce((sum, a) => sum + a.duration, 0);
251
+ }
252
+ tick(entity, delta) {
253
+ if (this.done || this.actions.length === 0) {
254
+ this.done = true;
255
+ return;
256
+ }
257
+ let remaining = delta;
258
+ while (remaining > 0 && this.currentIndex < this.actions.length) {
259
+ const current = this.actions[this.currentIndex];
260
+ current.tick(entity, remaining);
261
+ if (current.done) {
262
+ const actionDuration = current.duration;
263
+ const actionElapsed = current.elapsed ?? actionDuration;
264
+ const overflow = Math.max(0, actionElapsed - actionDuration);
265
+ remaining = overflow;
266
+ this.currentIndex++;
267
+ } else {
268
+ remaining = 0;
269
+ }
270
+ }
271
+ if (this.currentIndex >= this.actions.length) {
272
+ this.done = true;
273
+ }
274
+ }
275
+ reset() {
276
+ this.currentIndex = 0;
277
+ this.done = false;
278
+ for (const action of this.actions) {
279
+ action.reset();
280
+ }
281
+ }
282
+ };
283
+ function parallel(...actions) {
284
+ return new ParallelAction(actions);
285
+ }
286
+ var ParallelAction = class {
287
+ duration;
288
+ done = false;
289
+ persistent = false;
290
+ actions;
291
+ constructor(actions) {
292
+ this.actions = actions;
293
+ this.duration = Math.max(0, ...actions.map((a) => a.duration));
294
+ }
295
+ tick(entity, delta) {
296
+ if (this.done) return;
297
+ let allDone = true;
298
+ for (const action of this.actions) {
299
+ if (!action.done) {
300
+ action.tick(entity, delta);
301
+ }
302
+ if (!action.done) {
303
+ allDone = false;
304
+ }
305
+ }
306
+ if (allDone) {
307
+ this.done = true;
308
+ }
309
+ }
310
+ reset() {
311
+ this.done = false;
312
+ for (const action of this.actions) {
313
+ action.reset();
314
+ }
315
+ }
316
+ };
317
+ function repeat(action, times) {
318
+ return new RepeatAction(action, times);
319
+ }
320
+ var RepeatAction = class {
321
+ duration;
322
+ done = false;
323
+ persistent = false;
324
+ action;
325
+ totalTimes;
326
+ currentCount = 0;
327
+ constructor(action, times) {
328
+ this.action = action;
329
+ this.totalTimes = times;
330
+ this.duration = action.duration * times;
331
+ }
332
+ tick(entity, delta) {
333
+ if (this.done) return;
334
+ this.action.tick(entity, delta);
335
+ if (this.action.done) {
336
+ this.currentCount++;
337
+ if (this.currentCount >= this.totalTimes) {
338
+ this.done = true;
339
+ } else {
340
+ this.action.reset();
341
+ }
342
+ }
343
+ }
344
+ reset() {
345
+ this.currentCount = 0;
346
+ this.done = false;
347
+ this.action.reset();
348
+ }
349
+ };
350
+ function repeatForever(action) {
351
+ return new RepeatForeverAction(action);
352
+ }
353
+ var RepeatForeverAction = class {
354
+ duration = Infinity;
355
+ done = false;
356
+ persistent = false;
357
+ action;
358
+ constructor(action) {
359
+ this.action = action;
360
+ }
361
+ tick(entity, delta) {
362
+ this.action.tick(entity, delta);
363
+ if (this.action.done) {
364
+ this.action.reset();
365
+ }
366
+ }
367
+ reset() {
368
+ this.done = false;
369
+ this.action.reset();
370
+ }
371
+ };
372
+
373
+ // src/lib/actions/capabilities/transform-store.ts
374
+ import { proxy } from "valtio";
375
+ function createTransformStore(initial) {
376
+ const defaultState = {
377
+ position: { x: 0, y: 0, z: 0 },
378
+ rotation: { x: 0, y: 0, z: 0, w: 1 },
379
+ velocity: { x: 0, y: 0, z: 0 },
380
+ angularVelocity: { x: 0, y: 0, z: 0 },
381
+ dirty: {
382
+ position: false,
383
+ rotation: false,
384
+ velocity: false,
385
+ angularVelocity: false
66
386
  }
67
387
  };
68
- })();
388
+ return proxy({
389
+ ...defaultState,
390
+ ...initial,
391
+ // Ensure dirty flags are properly initialized even if partial initial state
392
+ dirty: {
393
+ ...defaultState.dirty,
394
+ ...initial?.dirty
395
+ }
396
+ });
397
+ }
398
+ function resetTransformStore(store) {
399
+ store.position.x = 0;
400
+ store.position.y = 0;
401
+ store.position.z = 0;
402
+ store.rotation.x = 0;
403
+ store.rotation.y = 0;
404
+ store.rotation.z = 0;
405
+ store.rotation.w = 1;
406
+ store.velocity.x = 0;
407
+ store.velocity.y = 0;
408
+ store.velocity.z = 0;
409
+ store.angularVelocity.x = 0;
410
+ store.angularVelocity.y = 0;
411
+ store.angularVelocity.z = 0;
412
+ store.dirty.position = false;
413
+ store.dirty.rotation = false;
414
+ store.dirty.velocity = false;
415
+ store.dirty.angularVelocity = false;
416
+ }
417
+
418
+ // src/lib/actions/capabilities/apply-transform.ts
419
+ function applyTransformChanges(entity, store) {
420
+ if (!entity.body) return;
421
+ if (store.dirty.velocity) {
422
+ entity.body.setLinvel(store.velocity, true);
423
+ }
424
+ if (store.dirty.rotation) {
425
+ entity.body.setRotation(store.rotation, true);
426
+ }
427
+ if (store.dirty.angularVelocity) {
428
+ entity.body.setAngvel(store.angularVelocity, true);
429
+ }
430
+ if (store.dirty.position) {
431
+ const current = entity.body.translation();
432
+ entity.body.setTranslation(
433
+ {
434
+ x: current.x + store.position.x,
435
+ y: current.y + store.position.y,
436
+ z: current.z + store.position.z
437
+ },
438
+ true
439
+ );
440
+ }
441
+ }
69
442
 
70
443
  // src/lib/actions/capabilities/moveable.ts
71
444
  import { Vector3 } from "three";
72
445
  function moveX(entity, delta) {
73
- if (!entity.body) return;
74
- const currentVelocity = entity.body.linvel();
75
- const newVelocity = new Vector3(delta, currentVelocity.y, currentVelocity.z);
76
- entity.body.setLinvel(newVelocity, true);
446
+ if (!entity.transformStore) return;
447
+ entity.transformStore.velocity.x = delta;
448
+ entity.transformStore.dirty.velocity = true;
77
449
  }
78
450
  function moveY(entity, delta) {
79
- if (!entity.body) return;
80
- const currentVelocity = entity.body.linvel();
81
- const newVelocity = new Vector3(currentVelocity.x, delta, currentVelocity.z);
82
- entity.body.setLinvel(newVelocity, true);
451
+ if (!entity.transformStore) return;
452
+ entity.transformStore.velocity.y = delta;
453
+ entity.transformStore.dirty.velocity = true;
83
454
  }
84
455
  function moveZ(entity, delta) {
85
- if (!entity.body) return;
86
- const currentVelocity = entity.body.linvel();
87
- const newVelocity = new Vector3(currentVelocity.x, currentVelocity.y, delta);
88
- entity.body.setLinvel(newVelocity, true);
456
+ if (!entity.transformStore) return;
457
+ entity.transformStore.velocity.z = delta;
458
+ entity.transformStore.dirty.velocity = true;
89
459
  }
90
460
  function moveXY(entity, deltaX, deltaY) {
91
- if (!entity.body) return;
92
- const currentVelocity = entity.body.linvel();
93
- const newVelocity = new Vector3(deltaX, deltaY, currentVelocity.z);
94
- entity.body.setLinvel(newVelocity, true);
461
+ if (!entity.transformStore) return;
462
+ entity.transformStore.velocity.x = deltaX;
463
+ entity.transformStore.velocity.y = deltaY;
464
+ entity.transformStore.dirty.velocity = true;
95
465
  }
96
466
  function moveXZ(entity, deltaX, deltaZ) {
97
- if (!entity.body) return;
98
- const currentVelocity = entity.body.linvel();
99
- const newVelocity = new Vector3(deltaX, currentVelocity.y, deltaZ);
100
- entity.body.setLinvel(newVelocity, true);
467
+ if (!entity.transformStore) return;
468
+ entity.transformStore.velocity.x = deltaX;
469
+ entity.transformStore.velocity.z = deltaZ;
470
+ entity.transformStore.dirty.velocity = true;
101
471
  }
102
472
  function move(entity, vector) {
103
- if (!entity.body) return;
104
- const currentVelocity = entity.body.linvel();
105
- const newVelocity = new Vector3(
106
- currentVelocity.x + vector.x,
107
- currentVelocity.y + vector.y,
108
- currentVelocity.z + vector.z
109
- );
110
- entity.body.setLinvel(newVelocity, true);
473
+ if (!entity.transformStore) return;
474
+ entity.transformStore.velocity.x += vector.x;
475
+ entity.transformStore.velocity.y += vector.y;
476
+ entity.transformStore.velocity.z += vector.z;
477
+ entity.transformStore.dirty.velocity = true;
111
478
  }
112
479
  function resetVelocity(entity) {
113
480
  if (!entity.body) return;
@@ -167,26 +534,6 @@ function wrapAround3D(entity, boundsX, boundsY, boundsZ) {
167
534
  setPosition(entity, newX, newY, newZ);
168
535
  }
169
536
  }
170
- function makeMoveable(entity) {
171
- const moveable = entity;
172
- moveable.moveX = (delta) => moveX(entity, delta);
173
- moveable.moveY = (delta) => moveY(entity, delta);
174
- moveable.moveZ = (delta) => moveZ(entity, delta);
175
- moveable.moveXY = (deltaX, deltaY) => moveXY(entity, deltaX, deltaY);
176
- moveable.moveXZ = (deltaX, deltaZ) => moveXZ(entity, deltaX, deltaZ);
177
- moveable.move = (vector) => move(entity, vector);
178
- moveable.resetVelocity = () => resetVelocity(entity);
179
- moveable.moveForwardXY = (delta, rotation2DAngle) => moveForwardXY(entity, delta, rotation2DAngle);
180
- moveable.getPosition = () => getPosition(entity);
181
- moveable.getVelocity = () => getVelocity(entity);
182
- moveable.setPosition = (x, y, z) => setPosition(entity, x, y, z);
183
- moveable.setPositionX = (x) => setPositionX(entity, x);
184
- moveable.setPositionY = (y) => setPositionY(entity, y);
185
- moveable.setPositionZ = (z) => setPositionZ(entity, z);
186
- moveable.wrapAroundXY = (boundsX, boundsY) => wrapAroundXY(entity, boundsX, boundsY);
187
- moveable.wrapAround3D = (boundsX, boundsY, boundsZ) => wrapAround3D(entity, boundsX, boundsY, boundsZ);
188
- return moveable;
189
- }
190
537
 
191
538
  // src/lib/actions/capabilities/rotatable.ts
192
539
  import { Euler, Vector3 as Vector32, MathUtils, Quaternion } from "three";
@@ -204,48 +551,106 @@ function rotateEuler(entity, rotation) {
204
551
  entity.group.setRotationFromEuler(euler);
205
552
  }
206
553
  function rotateY(entity, delta) {
207
- setRotationY(entity, delta);
554
+ if (!entity.transformStore) return;
555
+ const halfAngle = delta / 2;
556
+ const deltaW = Math.cos(halfAngle);
557
+ const deltaY = Math.sin(halfAngle);
558
+ const q = entity.transformStore.rotation;
559
+ const newW = q.w * deltaW - q.y * deltaY;
560
+ const newX = q.x * deltaW + q.z * deltaY;
561
+ const newY = q.y * deltaW + q.w * deltaY;
562
+ const newZ = q.z * deltaW - q.x * deltaY;
563
+ entity.transformStore.rotation.w = newW;
564
+ entity.transformStore.rotation.x = newX;
565
+ entity.transformStore.rotation.y = newY;
566
+ entity.transformStore.rotation.z = newZ;
567
+ entity.transformStore.dirty.rotation = true;
568
+ }
569
+ function rotateX(entity, delta) {
570
+ if (!entity.transformStore) return;
571
+ const halfAngle = delta / 2;
572
+ const deltaW = Math.cos(halfAngle);
573
+ const deltaX = Math.sin(halfAngle);
574
+ const q = entity.transformStore.rotation;
575
+ const newW = q.w * deltaW - q.x * deltaX;
576
+ const newX = q.x * deltaW + q.w * deltaX;
577
+ const newY = q.y * deltaW + q.z * deltaX;
578
+ const newZ = q.z * deltaW - q.y * deltaX;
579
+ entity.transformStore.rotation.w = newW;
580
+ entity.transformStore.rotation.x = newX;
581
+ entity.transformStore.rotation.y = newY;
582
+ entity.transformStore.rotation.z = newZ;
583
+ entity.transformStore.dirty.rotation = true;
208
584
  }
209
585
  function rotateZ(entity, delta) {
210
- setRotationZ(entity, delta);
586
+ if (!entity.transformStore) return;
587
+ const halfAngle = delta / 2;
588
+ const deltaW = Math.cos(halfAngle);
589
+ const deltaZ = Math.sin(halfAngle);
590
+ const q = entity.transformStore.rotation;
591
+ const newW = q.w * deltaW - q.z * deltaZ;
592
+ const newX = q.x * deltaW - q.y * deltaZ;
593
+ const newY = q.y * deltaW + q.x * deltaZ;
594
+ const newZ = q.z * deltaW + q.w * deltaZ;
595
+ entity.transformStore.rotation.w = newW;
596
+ entity.transformStore.rotation.x = newX;
597
+ entity.transformStore.rotation.y = newY;
598
+ entity.transformStore.rotation.z = newZ;
599
+ entity.transformStore.dirty.rotation = true;
211
600
  }
212
601
  function setRotationY(entity, y) {
213
- if (!entity.body) return;
602
+ if (!entity.transformStore) return;
214
603
  const halfAngle = y / 2;
215
604
  const w = Math.cos(halfAngle);
216
605
  const yComponent = Math.sin(halfAngle);
217
- entity.body.setRotation({ w, x: 0, y: yComponent, z: 0 }, true);
606
+ entity.transformStore.rotation.w = w;
607
+ entity.transformStore.rotation.x = 0;
608
+ entity.transformStore.rotation.y = yComponent;
609
+ entity.transformStore.rotation.z = 0;
610
+ entity.transformStore.dirty.rotation = true;
218
611
  }
219
612
  function setRotationDegreesY(entity, y) {
220
613
  if (!entity.body) return;
221
614
  setRotationY(entity, MathUtils.degToRad(y));
222
615
  }
223
616
  function setRotationX(entity, x) {
224
- if (!entity.body) return;
617
+ if (!entity.transformStore) return;
225
618
  const halfAngle = x / 2;
226
619
  const w = Math.cos(halfAngle);
227
620
  const xComponent = Math.sin(halfAngle);
228
- entity.body.setRotation({ w, x: xComponent, y: 0, z: 0 }, true);
621
+ entity.transformStore.rotation.w = w;
622
+ entity.transformStore.rotation.x = xComponent;
623
+ entity.transformStore.rotation.y = 0;
624
+ entity.transformStore.rotation.z = 0;
625
+ entity.transformStore.dirty.rotation = true;
229
626
  }
230
627
  function setRotationDegreesX(entity, x) {
231
628
  if (!entity.body) return;
232
629
  setRotationX(entity, MathUtils.degToRad(x));
233
630
  }
234
631
  function setRotationZ(entity, z) {
235
- if (!entity.body) return;
632
+ if (!entity.transformStore) return;
236
633
  const halfAngle = z / 2;
237
634
  const w = Math.cos(halfAngle);
238
635
  const zComponent = Math.sin(halfAngle);
239
- entity.body.setRotation({ w, x: 0, y: 0, z: zComponent }, true);
636
+ entity.transformStore.rotation.w = w;
637
+ entity.transformStore.rotation.x = 0;
638
+ entity.transformStore.rotation.y = 0;
639
+ entity.transformStore.rotation.z = zComponent;
640
+ entity.transformStore.dirty.rotation = true;
240
641
  }
241
642
  function setRotationDegreesZ(entity, z) {
242
643
  if (!entity.body) return;
243
644
  setRotationZ(entity, MathUtils.degToRad(z));
244
645
  }
245
646
  function setRotation(entity, x, y, z) {
246
- if (!entity.body) return;
647
+ if (!entity.transformStore) return;
247
648
  const quat = new Quaternion().setFromEuler(new Euler(x, y, z));
248
- entity.body.setRotation({ w: quat.w, x: quat.x, y: quat.y, z: quat.z }, true);
649
+ entity.transformStore.rotation.w = quat.w;
650
+ entity.transformStore.rotation.x = quat.x;
651
+ entity.transformStore.rotation.y = quat.y;
652
+ entity.transformStore.rotation.z = quat.z;
653
+ entity.transformStore.dirty.rotation = true;
249
654
  }
250
655
  function setRotationDegrees(entity, x, y, z) {
251
656
  if (!entity.body) return;
@@ -255,35 +660,113 @@ function getRotation(entity) {
255
660
  if (!entity.body) return null;
256
661
  return entity.body.rotation();
257
662
  }
258
- function makeRotatable(entity) {
259
- const rotatableEntity = entity;
260
- rotatableEntity.rotateInDirection = (moveVector) => rotateInDirection(entity, moveVector);
261
- rotatableEntity.rotateYEuler = (amount) => rotateYEuler(entity, amount);
262
- rotatableEntity.rotateEuler = (rotation) => rotateEuler(entity, rotation);
263
- rotatableEntity.rotateY = (delta) => rotateY(entity, delta);
264
- rotatableEntity.rotateZ = (delta) => rotateZ(entity, delta);
265
- rotatableEntity.setRotationY = (y) => setRotationY(entity, y);
266
- rotatableEntity.setRotationX = (x) => setRotationX(entity, x);
267
- rotatableEntity.setRotationZ = (z) => setRotationZ(entity, z);
268
- rotatableEntity.setRotationDegreesY = (y) => setRotationDegreesY(entity, y);
269
- rotatableEntity.setRotationDegreesX = (x) => setRotationDegreesX(entity, x);
270
- rotatableEntity.setRotationDegreesZ = (z) => setRotationDegreesZ(entity, z);
271
- rotatableEntity.setRotationDegrees = (x, y, z) => setRotationDegrees(entity, x, y, z);
272
- rotatableEntity.setRotation = (x, y, z) => setRotation(entity, x, y, z);
273
- rotatableEntity.getRotation = () => getRotation(entity);
274
- return rotatableEntity;
275
- }
276
663
 
277
- // src/lib/actions/capabilities/transformable.ts
278
- function makeTransformable(entity) {
279
- const withMovement = makeMoveable(entity);
280
- const withRotation = makeRotatable(withMovement);
281
- return withRotation;
664
+ // src/lib/actions/global-change.ts
665
+ function globalChange(key, callback) {
666
+ let previousValue = void 0;
667
+ return (ctx) => {
668
+ const currentValue = ctx.globals?.[key];
669
+ if (previousValue !== currentValue) {
670
+ if (!(previousValue === void 0 && currentValue === void 0)) {
671
+ callback(currentValue, ctx);
672
+ }
673
+ previousValue = currentValue;
674
+ }
675
+ };
676
+ }
677
+ function globalChanges(keys, callback) {
678
+ let previousValues = new Array(keys.length).fill(void 0);
679
+ return (ctx) => {
680
+ const currentValues = keys.map((k) => ctx.globals?.[k]);
681
+ const hasAnyChange = currentValues.some((val, idx) => previousValues[idx] !== val);
682
+ if (hasAnyChange) {
683
+ const allPrevUndef = previousValues.every((v) => v === void 0);
684
+ const allCurrUndef = currentValues.every((v) => v === void 0);
685
+ if (!(allPrevUndef && allCurrUndef)) {
686
+ callback(currentValues, ctx);
687
+ }
688
+ previousValues = currentValues;
689
+ }
690
+ };
691
+ }
692
+ function variableChange(key, callback) {
693
+ let previousValue = void 0;
694
+ return (ctx) => {
695
+ const currentValue = ctx.stage?.getVariable?.(key) ?? void 0;
696
+ if (previousValue !== currentValue) {
697
+ if (!(previousValue === void 0 && currentValue === void 0)) {
698
+ callback(currentValue, ctx);
699
+ }
700
+ previousValue = currentValue;
701
+ }
702
+ };
703
+ }
704
+ function variableChanges(keys, callback) {
705
+ let previousValues = new Array(keys.length).fill(void 0);
706
+ return (ctx) => {
707
+ const reader = (k) => ctx.stage?.getVariable?.(k);
708
+ const currentValues = keys.map(reader);
709
+ const hasAnyChange = currentValues.some((val, idx) => previousValues[idx] !== val);
710
+ if (hasAnyChange) {
711
+ const allPrevUndef = previousValues.every((v) => v === void 0);
712
+ const allCurrUndef = currentValues.every((v) => v === void 0);
713
+ if (!(allPrevUndef && allCurrUndef)) {
714
+ callback(currentValues, ctx);
715
+ }
716
+ previousValues = currentValues;
717
+ }
718
+ };
282
719
  }
283
720
  export {
284
- actions_exports as actions,
285
- makeMoveable,
286
- makeRotatable,
287
- makeTransformable
721
+ applyTransformChanges,
722
+ callFunc,
723
+ createTransformStore,
724
+ delay,
725
+ getPosition,
726
+ getRotation,
727
+ getVelocity,
728
+ globalChange,
729
+ globalChanges,
730
+ move,
731
+ moveBy,
732
+ moveForwardXY,
733
+ moveTo,
734
+ moveX,
735
+ moveXY,
736
+ moveXZ,
737
+ moveY,
738
+ moveZ,
739
+ onPress,
740
+ onRelease,
741
+ parallel,
742
+ repeat,
743
+ repeatForever,
744
+ resetTransformStore,
745
+ resetVelocity,
746
+ rotateBy,
747
+ rotateEuler,
748
+ rotateInDirection,
749
+ rotateX,
750
+ rotateY,
751
+ rotateYEuler,
752
+ rotateZ,
753
+ sequence,
754
+ setPosition,
755
+ setPositionX,
756
+ setPositionY,
757
+ setPositionZ,
758
+ setRotation,
759
+ setRotationDegrees,
760
+ setRotationDegreesX,
761
+ setRotationDegreesY,
762
+ setRotationDegreesZ,
763
+ setRotationX,
764
+ setRotationY,
765
+ setRotationZ,
766
+ throttle,
767
+ variableChange,
768
+ variableChanges,
769
+ wrapAround3D,
770
+ wrapAroundXY
288
771
  };
289
772
  //# sourceMappingURL=actions.js.map