castle-web-cli 0.4.252 → 0.4.253
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/kits/hub-game/code/client/layoutCache.js +21 -4
- package/kits/hub-game/code/client/worldLabels.js +68 -22
- package/kits/hub-game/scripts/test-safe-act.mjs +82 -9
- package/kits/hub-game/scripts/test-world-labels.mjs +106 -4
- package/kits/physics-3d/CLAUDE.md +2 -2
- package/kits/physics-3d/behaviors/Player.jsx +29 -5
- package/kits/physics-3d/castle.json +1 -1
- package/kits/physics-3d/docs/engine-camera.md +14 -1
- package/kits/physics-3d/play/behaviors/Player.js +27 -5
- package/kits/physics-3d/scripts/Player.before-portrait.mjs +1256 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +116 -0
- package/package.json +1 -1
|
@@ -125,6 +125,7 @@ const hooks = `
|
|
|
125
125
|
register(`data:text/javascript,${encodeURIComponent(hooks)}`);
|
|
126
126
|
const { Player } = await import('../behaviors/Player.jsx');
|
|
127
127
|
const { Player: PlayerBefore } = await import('./Player.before-orbit.mjs');
|
|
128
|
+
const { Player: PlayerBeforePortrait } = await import('./Player.before-portrait.mjs');
|
|
128
129
|
const { placeFollowCamera, Physics3DSystem } = await import('../systems/physics3d.js');
|
|
129
130
|
const { makeLookGestures, attachOrbitInput, stickFrom, LOOK_RAD_PER_PX, WHEEL_ZOOM_PER_NOTCH } = await import('../engine3d/orbitinput.js');
|
|
130
131
|
const { SceneRuntime } = await import('../../physics-2d/engine/scene.js');
|
|
@@ -1241,6 +1242,120 @@ function looking() {
|
|
|
1241
1242
|
return checks;
|
|
1242
1243
|
}
|
|
1243
1244
|
|
|
1245
|
+
// `engine.camera.portrait`: the starts while the canvas is taller than wide.
|
|
1246
|
+
// - Without the key (and with it, on a canvas wider than tall) every frame
|
|
1247
|
+
// of a scripted run is the frame of Player.before-portrait.mjs, the
|
|
1248
|
+
// Player as it was on the commit before the key, number for number, on a
|
|
1249
|
+
// landscape and a portrait canvas.
|
|
1250
|
+
// - On a portrait canvas its finite distance and pitch are the starts; an
|
|
1251
|
+
// absent or non-finite one keeps the scene's own start.
|
|
1252
|
+
// - Turning the canvas restarts the camera at that orientation's starts,
|
|
1253
|
+
// both ways, and the camera comes to rest there; staying in one
|
|
1254
|
+
// orientation keeps what the player chose.
|
|
1255
|
+
const TALL = 390 / 844;
|
|
1256
|
+
const WIDE = 844 / 390;
|
|
1257
|
+
function aspectOf(world, aspect) {
|
|
1258
|
+
world.camera.aspect = aspect;
|
|
1259
|
+
world.camera.updateProjectionMatrix();
|
|
1260
|
+
}
|
|
1261
|
+
function portraitStarts() {
|
|
1262
|
+
let checks = 0;
|
|
1263
|
+
for (const aspect of [1280 / 800, WIDE, TALL]) {
|
|
1264
|
+
for (const [camera, beforeCamera] of [
|
|
1265
|
+
[{}, {}],
|
|
1266
|
+
[{ distance: 8, pitch: 30 }, { distance: 8, pitch: 30 }],
|
|
1267
|
+
[{ minPitch: 0 }, { minPitch: 0 }],
|
|
1268
|
+
...(aspect < 1 ? [] : [[{ distance: 8, pitch: 30, portrait: { distance: 5, pitch: 40 } }, { distance: 8, pitch: 30 }]]),
|
|
1269
|
+
...[null, 6, 'x', true].map((portrait) => [{ distance: 8, portrait }, { distance: 8 }]),
|
|
1270
|
+
]) {
|
|
1271
|
+
const now = makeWorld('orbit');
|
|
1272
|
+
const before = makeWorld('orbit', PlayerBeforePortrait);
|
|
1273
|
+
for (const w of [now, before]) aspectOf(w, aspect);
|
|
1274
|
+
now.scene.data = { engine: { camera } };
|
|
1275
|
+
before.scene.data = { engine: { camera: beforeCamera } };
|
|
1276
|
+
const stepNow = scripted(now);
|
|
1277
|
+
const stepBefore = scripted(before);
|
|
1278
|
+
for (let i = 0; i < 720; i += 1) {
|
|
1279
|
+
stepNow(i);
|
|
1280
|
+
stepBefore(i);
|
|
1281
|
+
}
|
|
1282
|
+
same(now, before, `aspect ${aspect.toFixed(2)} ${JSON.stringify(camera)}: today's camera`);
|
|
1283
|
+
const keyed = camera.portrait && typeof camera.portrait === 'object';
|
|
1284
|
+
const { orientation, ...choice } = now.scene.cameraOrbit;
|
|
1285
|
+
assert.equal(orientation, keyed ? 'wide' : undefined, 'which way the canvas faces is kept only with the key');
|
|
1286
|
+
assert.deepEqual(keyed ? choice : now.scene.cameraOrbit, before.scene.cameraOrbit, 'and the same choice on the runtime');
|
|
1287
|
+
checks += 1;
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
for (const [camera, range, pitch] of [
|
|
1291
|
+
[{ portrait: { distance: 6 } }, 6, PITCH0],
|
|
1292
|
+
[{ distance: 8, pitch: 30, portrait: { distance: 6 } }, 6, 30 * DEG],
|
|
1293
|
+
[{ pitch: 20, portrait: { pitch: 40 } }, RANGE0, 40 * DEG],
|
|
1294
|
+
[{ distance: 8, portrait: { distance: 200, pitch: 200 } }, FARTHEST, PITCH_MOST],
|
|
1295
|
+
[{ distance: 8, pitch: 30, portrait: {} }, 8, 30 * DEG],
|
|
1296
|
+
...[NaN, Infinity, '6', null].map((v) => [{ distance: 8, pitch: 30, portrait: { distance: v, pitch: v } }, 8, 30 * DEG]),
|
|
1297
|
+
]) {
|
|
1298
|
+
const world = makeWorld('orbit');
|
|
1299
|
+
aspectOf(world, TALL);
|
|
1300
|
+
world.scene.data = { engine: { camera } };
|
|
1301
|
+
world.run(90);
|
|
1302
|
+
assert.equal(world.scene.cameraOrbit.range, range, `${JSON.stringify(camera)}: portrait distance`);
|
|
1303
|
+
assert.equal(world.scene.cameraOrbit.pitch, pitch, `${JSON.stringify(camera)}: portrait pitch`);
|
|
1304
|
+
assert.ok(world.off(world.rest(world.scene.persistent.camAngle, pitch, range)) < 1e-3, 'the camera rests at the portrait start');
|
|
1305
|
+
checks += 1;
|
|
1306
|
+
}
|
|
1307
|
+
{
|
|
1308
|
+
const world = makeWorld('orbit');
|
|
1309
|
+
aspectOf(world, WIDE);
|
|
1310
|
+
world.scene.data = { engine: { camera: { distance: 3.65, pitch: 15, portrait: { distance: 6, pitch: 25 } } } };
|
|
1311
|
+
const settle = (range, pitch, label) => {
|
|
1312
|
+
world.run(120, ['KeyW']);
|
|
1313
|
+
assert.equal(world.scene.cameraOrbit.range, range, label);
|
|
1314
|
+
assert.equal(world.scene.cameraOrbit.pitch, pitch, label);
|
|
1315
|
+
world.run(120);
|
|
1316
|
+
assert.ok(world.off(world.rest(world.scene.persistent.camAngle, pitch, range)) < 1e-3, `${label}: at rest there`);
|
|
1317
|
+
checks += 1;
|
|
1318
|
+
};
|
|
1319
|
+
settle(3.65, 15 * DEG, 'landscape starts');
|
|
1320
|
+
for (const [aspect, range, pitch, label] of [
|
|
1321
|
+
[TALL, 6, 25 * DEG, 'turned to portrait'],
|
|
1322
|
+
[WIDE, 3.65, 15 * DEG, 'turned back to landscape'],
|
|
1323
|
+
[TALL, 6, 25 * DEG, 'portrait again'],
|
|
1324
|
+
]) {
|
|
1325
|
+
// What the player chose in this orientation is kept while it lasts.
|
|
1326
|
+
world.scene.cameraOrbit.range = 9;
|
|
1327
|
+
const kept = world.scene.cameraOrbit;
|
|
1328
|
+
aspectOf(world, aspect === TALL ? 0.9 * WIDE : 1.1 * TALL);
|
|
1329
|
+
world.run(30);
|
|
1330
|
+
assert.equal(world.scene.cameraOrbit, kept, `${label}: a resize within the orientation keeps the choice`);
|
|
1331
|
+
assert.equal(kept.range, 9);
|
|
1332
|
+
aspectOf(world, aspect);
|
|
1333
|
+
world.frame();
|
|
1334
|
+
assert.notEqual(world.scene.cameraOrbit, kept, `${label}: a fresh choice`);
|
|
1335
|
+
settle(range, pitch, label);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
// A turn restarts even where both orientations' starts are the same.
|
|
1339
|
+
for (const camera of [{ distance: 6, pitch: 25, portrait: { distance: 6 } }, { distance: 6, pitch: 25, portrait: {} }]) {
|
|
1340
|
+
const world = makeWorld('orbit');
|
|
1341
|
+
aspectOf(world, WIDE);
|
|
1342
|
+
world.scene.data = { engine: { camera } };
|
|
1343
|
+
world.run(30);
|
|
1344
|
+
for (const aspect of [TALL, WIDE]) {
|
|
1345
|
+
world.scene.cameraOrbit.range = 9;
|
|
1346
|
+
world.scene.cameraOrbit.pitch = 0;
|
|
1347
|
+
const kept = world.scene.cameraOrbit;
|
|
1348
|
+
aspectOf(world, aspect);
|
|
1349
|
+
world.frame();
|
|
1350
|
+
assert.notEqual(world.scene.cameraOrbit, kept, `${JSON.stringify(camera)}: turned to ${aspect < 1 ? 'portrait' : 'landscape'}, a fresh choice`);
|
|
1351
|
+
assert.equal(world.scene.cameraOrbit.range, 6);
|
|
1352
|
+
assert.equal(world.scene.cameraOrbit.pitch, 25 * DEG);
|
|
1353
|
+
checks += 1;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
return checks;
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1244
1359
|
function startingValues() {
|
|
1245
1360
|
let checks = 0;
|
|
1246
1361
|
const cases = [
|
|
@@ -4581,6 +4696,7 @@ export async function run() {
|
|
|
4581
4696
|
walking: walking(),
|
|
4582
4697
|
looking: looking(),
|
|
4583
4698
|
startingValues: startingValues(),
|
|
4699
|
+
portraitStarts: portraitStarts(),
|
|
4584
4700
|
blocked: blocked(),
|
|
4585
4701
|
grounded: grounded(),
|
|
4586
4702
|
wideLens: wideLens(),
|