@irtio/testing 4.3.0 → 4.4.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/dist/{chunk-7GS3V7QO.js → chunk-YP2FKKYJ.js} +42 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/matchers.js +1 -1
- package/package.json +7 -7
|
@@ -161,6 +161,9 @@ var InProcessSocket = class {
|
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
// src/physics.ts
|
|
164
|
+
function emptyPose() {
|
|
165
|
+
return { x: 0, y: 0, z: 0, qx: 0, qy: 0, qz: 0, qw: 1, vx: 0, vy: 0, vz: 0, wx: 0, wy: 0, wz: 0 };
|
|
166
|
+
}
|
|
164
167
|
function vec(v) {
|
|
165
168
|
return { x: v.x, y: v.y, z: v.z ?? 0 };
|
|
166
169
|
}
|
|
@@ -184,16 +187,39 @@ function createTestPhysics(core) {
|
|
|
184
187
|
}
|
|
185
188
|
return body;
|
|
186
189
|
};
|
|
190
|
+
const poseOf = (collection, id) => {
|
|
191
|
+
const body = bodyOf(collection, id);
|
|
192
|
+
const out = emptyPose();
|
|
193
|
+
stepperOf().readPose(body, out);
|
|
194
|
+
return out;
|
|
195
|
+
};
|
|
196
|
+
const stepperOf = () => {
|
|
197
|
+
const stepper = physicsOf().liveStepper;
|
|
198
|
+
if (!stepper) {
|
|
199
|
+
throw new Error(
|
|
200
|
+
"t.physics: this room runs a custom stepper but physics.world has not built one (or it threw). Check the room definition."
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
return stepper;
|
|
204
|
+
};
|
|
187
205
|
return {
|
|
188
206
|
get engine() {
|
|
189
207
|
return core.physics?.engineKind;
|
|
190
208
|
},
|
|
191
209
|
position(collection, id) {
|
|
210
|
+
if (physicsOf().engineKind === "custom") {
|
|
211
|
+
const p = poseOf(collection, id);
|
|
212
|
+
return { x: p.x, y: p.y, z: p.z };
|
|
213
|
+
}
|
|
192
214
|
const body = bodyOf(collection, id);
|
|
193
215
|
if (physicsOf().engineKind === "matter2d") return vec(body.position);
|
|
194
216
|
return vec(body.translation());
|
|
195
217
|
},
|
|
196
218
|
velocity(collection, id) {
|
|
219
|
+
if (physicsOf().engineKind === "custom") {
|
|
220
|
+
const p = poseOf(collection, id);
|
|
221
|
+
return { x: p.vx, y: p.vy, z: p.vz };
|
|
222
|
+
}
|
|
197
223
|
const body = bodyOf(collection, id);
|
|
198
224
|
if (physicsOf().engineKind === "matter2d") return vec(body.velocity);
|
|
199
225
|
return vec(body.linvel());
|
|
@@ -201,6 +227,14 @@ function createTestPhysics(core) {
|
|
|
201
227
|
teleport(collection, id, to) {
|
|
202
228
|
const p = physicsOf();
|
|
203
229
|
const body = bodyOf(collection, id);
|
|
230
|
+
if (p.engineKind === "custom") {
|
|
231
|
+
const pose = poseOf(collection, id);
|
|
232
|
+
pose.x = to.x;
|
|
233
|
+
pose.y = to.y;
|
|
234
|
+
pose.z = to.z ?? 0;
|
|
235
|
+
stepperOf().writePose(body, pose);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
204
238
|
if (p.engineKind === "matter2d") {
|
|
205
239
|
matterOf(p).Body.setPosition(body, { x: to.x, y: to.y });
|
|
206
240
|
return;
|
|
@@ -213,6 +247,14 @@ function createTestPhysics(core) {
|
|
|
213
247
|
impulse(collection, id, by) {
|
|
214
248
|
const p = physicsOf();
|
|
215
249
|
const body = bodyOf(collection, id);
|
|
250
|
+
if (p.engineKind === "custom") {
|
|
251
|
+
const pose = poseOf(collection, id);
|
|
252
|
+
pose.vx += by.x;
|
|
253
|
+
pose.vy += by.y;
|
|
254
|
+
pose.vz += by.z ?? 0;
|
|
255
|
+
stepperOf().writePose(body, pose);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
216
258
|
if (p.engineKind === "matter2d") {
|
|
217
259
|
const m = body;
|
|
218
260
|
matterOf(p).Body.setVelocity(body, {
|
package/dist/index.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ interface TestVectorInput {
|
|
|
40
40
|
}
|
|
41
41
|
interface TestPhysics {
|
|
42
42
|
/** Which engine this room runs, or `undefined` when it declares no physics at all. */
|
|
43
|
-
readonly engine: 'rapier3d' | 'matter2d' | 'rapier2d' | undefined;
|
|
43
|
+
readonly engine: 'rapier3d' | 'matter2d' | 'rapier2d' | 'custom' | undefined;
|
|
44
44
|
/** The body's position. Throws when the room has no physics or the body is not there. */
|
|
45
45
|
position(collection: string, id: string): TestVector;
|
|
46
46
|
/** The body's linear velocity. */
|
package/dist/index.js
CHANGED
package/dist/matchers.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@irtio/testing",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "irtio's blessed test API: testRoom() in-process rooms with real client semantics, plus Vitest matchers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@irtio/bots": "^4.
|
|
32
|
-
"@irtio/
|
|
33
|
-
"@irtio/runtime": "^4.
|
|
34
|
-
"@irtio/
|
|
35
|
-
"@irtio/
|
|
36
|
-
"@irtio/
|
|
31
|
+
"@irtio/bots": "^4.4.0",
|
|
32
|
+
"@irtio/protocol": "^4.4.0",
|
|
33
|
+
"@irtio/runtime": "^4.4.0",
|
|
34
|
+
"@irtio/client": "^4.4.0",
|
|
35
|
+
"@irtio/schema": "^4.4.0",
|
|
36
|
+
"@irtio/server": "^4.4.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"vitest": ">=3"
|