@zylem/game-lib 0.6.4 → 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.
- package/README.md +18 -2
- package/dist/actions.d.ts +321 -11
- package/dist/actions.js +1 -936
- package/dist/api/game-lib.api.json +54074 -0
- package/dist/api/game-lib.api.md +4544 -0
- package/dist/api/game-lib.d.ts +8258 -0
- package/dist/api/game-lib.typedoc.json +345421 -0
- package/dist/audio.d.ts +13 -0
- package/dist/audio.js +1 -0
- package/dist/base-node-life-cycle-D2NuN1VB.d.ts +151 -0
- package/dist/behavior.d.ts +2 -0
- package/dist/behavior.js +1 -0
- package/dist/blueprints-TbGY-h53.d.ts +162 -0
- package/dist/chunk-4QLJUQSJ.js +1 -0
- package/dist/chunk-7FR5JSQ2.js +1 -0
- package/dist/chunk-7GYFZKK7.js +1 -0
- package/dist/chunk-7WRQ2UAN.js +1 -0
- package/dist/chunk-BH53MBAZ.js +1 -0
- package/dist/chunk-BIGH6D34.js +0 -0
- package/dist/chunk-CM5YRNBJ.js +19 -0
- package/dist/chunk-COM6HJ2L.js +1 -0
- package/dist/chunk-D2PATZCC.js +1 -0
- package/dist/chunk-DFLI7ICU.js +0 -0
- package/dist/chunk-E3UBSUPX.js +1 -0
- package/dist/chunk-FKIKN7RP.js +24 -0
- package/dist/chunk-G4HONLWC.js +1 -0
- package/dist/chunk-IKWE2W6L.js +1 -0
- package/dist/chunk-IPWUDOV5.js +1 -0
- package/dist/chunk-JEHFHUH4.js +0 -0
- package/dist/chunk-JNKPTL77.js +1 -0
- package/dist/chunk-JQKS42G4.js +1 -0
- package/dist/chunk-M3XNO56P.js +1 -0
- package/dist/chunk-MSC2BEO5.js +1 -0
- package/dist/chunk-ORIDWL3T.js +0 -0
- package/dist/chunk-QB3NL7VQ.js +1 -0
- package/dist/chunk-QXVH6POE.js +1 -0
- package/dist/chunk-RXDTAWI2.js +29 -0
- package/dist/chunk-TAUWDQZF.js +9 -0
- package/dist/chunk-VS2D4B3W.js +1 -0
- package/dist/chunk-WQ3WMMZD.js +1 -0
- package/dist/chunk-XK63E4SX.js +1 -0
- package/dist/chunk-XNDS4YFR.js +1 -0
- package/dist/chunk-XNHVRFAK.js +1 -0
- package/dist/chunk-XRP4JJXL.js +1 -0
- package/dist/chunk-YHEWKN7N.js +1 -0
- package/dist/chunk-ZRT3ZQVH.js +1 -0
- package/dist/collision-builder-jF-toPIl.d.ts +38 -0
- package/dist/core.d.ts +223 -16
- package/dist/core.js +1 -12424
- package/dist/debug-state-BPT6jEog.d.ts +17 -0
- package/dist/debug.d.ts +76 -0
- package/dist/debug.js +1 -0
- package/dist/default-controls-0-vCnli7.d.ts +111 -0
- package/dist/{entity-vj-HTjzU.d.ts → entity-BdSI8CL3.d.ts} +119 -626
- package/dist/{entity-Bq_eNEDI.d.ts → entity-DZbFQ1Wg.d.ts} +4 -4
- package/dist/entity-type-map-Bd69SpAS.d.ts +928 -0
- package/dist/entity.d.ts +268 -0
- package/dist/entity.js +1 -0
- package/dist/events.d.ts +181 -0
- package/dist/events.js +1 -0
- package/dist/game-C1FHVqXl.d.ts +1886 -0
- package/dist/game-default-QHROHW2O.js +1 -0
- package/dist/game-interfaces-mchNYSZE.d.ts +90 -0
- package/dist/globals.d.ts +115 -0
- package/dist/globals.js +1 -0
- package/dist/graphics.d.ts +53 -0
- package/dist/graphics.js +1 -0
- package/dist/input-ui.d.ts +35 -0
- package/dist/input-ui.js +1 -0
- package/dist/input.d.ts +73 -0
- package/dist/input.js +1 -0
- package/dist/material-9vJ6SZaI.d.ts +126 -0
- package/dist/public.d.ts +38 -0
- package/dist/public.js +1 -0
- package/dist/runtime.d.ts +59 -0
- package/dist/runtime.js +1 -0
- package/dist/schema/entity.schema.json +244 -0
- package/dist/schema/game-config.schema.json +625 -0
- package/dist/schema/input-config.schema.json +499 -0
- package/dist/schema/stage-config.schema.json +93 -0
- package/dist/schema/stage.schema.json +271 -0
- package/dist/schema.d.ts +538 -0
- package/dist/schema.js +1 -0
- package/dist/stage-transition-CmGpV4tc.d.ts +46 -0
- package/dist/vector-CiSHbivc.d.ts +133 -0
- package/dist/web-components.d.ts +70 -0
- package/dist/web-components.js +1 -0
- package/dist/zylem-camera-C3bn6BTI.d.ts +575 -0
- package/package.json +70 -73
- package/dist/actions.js.map +0 -1
- package/dist/behavior/jumper-2d.d.ts +0 -114
- package/dist/behavior/jumper-2d.js +0 -711
- package/dist/behavior/jumper-2d.js.map +0 -1
- package/dist/behavior/platformer-3d.d.ts +0 -296
- package/dist/behavior/platformer-3d.js +0 -761
- package/dist/behavior/platformer-3d.js.map +0 -1
- package/dist/behavior/ricochet-2d.d.ts +0 -275
- package/dist/behavior/ricochet-2d.js +0 -425
- package/dist/behavior/ricochet-2d.js.map +0 -1
- package/dist/behavior/ricochet-3d.d.ts +0 -117
- package/dist/behavior/ricochet-3d.js +0 -443
- package/dist/behavior/ricochet-3d.js.map +0 -1
- package/dist/behavior/screen-visibility.d.ts +0 -79
- package/dist/behavior/screen-visibility.js +0 -358
- package/dist/behavior/screen-visibility.js.map +0 -1
- package/dist/behavior/screen-wrap.d.ts +0 -87
- package/dist/behavior/screen-wrap.js +0 -246
- package/dist/behavior/screen-wrap.js.map +0 -1
- package/dist/behavior/shooter-2d.d.ts +0 -79
- package/dist/behavior/shooter-2d.js +0 -180
- package/dist/behavior/shooter-2d.js.map +0 -1
- package/dist/behavior/thruster.d.ts +0 -11
- package/dist/behavior/thruster.js +0 -292
- package/dist/behavior/thruster.js.map +0 -1
- package/dist/behavior/top-down-movement.d.ts +0 -56
- package/dist/behavior/top-down-movement.js +0 -125
- package/dist/behavior/top-down-movement.js.map +0 -1
- package/dist/behavior/world-boundary-2d.d.ts +0 -142
- package/dist/behavior/world-boundary-2d.js +0 -235
- package/dist/behavior/world-boundary-2d.js.map +0 -1
- package/dist/behavior/world-boundary-3d.d.ts +0 -76
- package/dist/behavior/world-boundary-3d.js +0 -274
- package/dist/behavior/world-boundary-3d.js.map +0 -1
- package/dist/behavior-descriptor-BXnVR8Ki.d.ts +0 -159
- package/dist/blueprints-DmbK2dki.d.ts +0 -26
- package/dist/camera-4XO5gbQH.d.ts +0 -905
- package/dist/camera.d.ts +0 -6
- package/dist/camera.js +0 -1993
- package/dist/camera.js.map +0 -1
- package/dist/composition-BASvMKrW.d.ts +0 -218
- package/dist/core-CARRaS55.d.ts +0 -541
- package/dist/core.js.map +0 -1
- package/dist/entities-ChFirVL9.d.ts +0 -410
- package/dist/entities.d.ts +0 -9
- package/dist/entities.js +0 -4986
- package/dist/entities.js.map +0 -1
- package/dist/entity-types-DAu8sGJH.d.ts +0 -26
- package/dist/global-change-2JvMaz44.d.ts +0 -25
- package/dist/main.d.ts +0 -1353
- package/dist/main.js +0 -19525
- package/dist/main.js.map +0 -1
- package/dist/physics-pose-DCc4oE44.d.ts +0 -25
- package/dist/physics-protocol-BDD3P5W2.d.ts +0 -200
- package/dist/physics-worker.d.ts +0 -21
- package/dist/physics-worker.js +0 -306
- package/dist/physics-worker.js.map +0 -1
- package/dist/physics.d.ts +0 -205
- package/dist/physics.js +0 -577
- package/dist/physics.js.map +0 -1
- package/dist/stage-types-C19IhuzA.d.ts +0 -731
- package/dist/stage.d.ts +0 -52
- package/dist/stage.js +0 -8479
- package/dist/stage.js.map +0 -1
- package/dist/sync-state-machine-CZyspBpj.d.ts +0 -16
- package/dist/thruster-23lzoPZd.d.ts +0 -180
- package/dist/world-DfgxoNMt.d.ts +0 -105
package/dist/actions.js
CHANGED
|
@@ -1,936 +1 @@
|
|
|
1
|
-
|
|
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 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};
|