castle-web-cli 0.4.254 → 0.4.256
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/chrome.js +94 -27
- package/kits/hub-game/code/client/crowdNames.js +3 -2
- package/kits/hub-game/code/client/hudTree.js +16 -4
- package/kits/hub-game/code/client/nameTagLayout.js +46 -0
- package/kits/hub-game/code/client/role.js +4 -2
- package/kits/hub-game/code/client/safeLayout.js +1 -0
- package/kits/hub-game/code/client/worldLabels.js +54 -8
- package/kits/hub-game/code/systems/hub.js +90 -12
- package/kits/hub-game/docs/contract.md +10 -2
- package/kits/hub-game/scripts/fixtures/hud-surface.json +63 -63
- package/kits/hub-game/scripts/fixtures/talk-surface.json +4 -4
- package/kits/hub-game/scripts/test-actions-client.mjs +13 -3
- package/kits/hub-game/scripts/test-disguise-client.mjs +1 -1
- package/kits/hub-game/scripts/test-hud-clear.mjs +16 -10
- package/kits/hub-game/scripts/test-hud-defects-dom.mjs +59 -0
- package/kits/hub-game/scripts/test-hud-surface.mjs +31 -4
- package/kits/hub-game/scripts/test-placement-cache.mjs +87 -0
- package/kits/hub-game/scripts/test-prompt-portrait-dom.mjs +128 -0
- package/kits/hub-game/scripts/test-quality.mjs +1 -1
- package/kits/hub-game/scripts/test-role-client.mjs +82 -6
- package/kits/hub-game/scripts/test-talk-surface.mjs +3 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +81 -0
- package/kits/multiplayer-3d/CLAUDE.md +13 -0
- package/kits/multiplayer-3d/castle.json +3 -3
- package/kits/multiplayer-3d/code/client/resumeGate.js +70 -8
- package/kits/multiplayer-3d/code/systems/multiplayer.js +3 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +133 -1
- package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +39 -0
- package/package.json +1 -1
|
@@ -978,8 +978,8 @@
|
|
|
978
978
|
[]
|
|
979
979
|
]
|
|
980
980
|
],
|
|
981
|
-
"dom": "
|
|
982
|
-
"writes":
|
|
981
|
+
"dom": "ceaf89d63e3d2a1279d7b0085bbfe3e77ebfdf9edaa15c2ccf93ceba15273f88",
|
|
982
|
+
"writes": 1075
|
|
983
983
|
},
|
|
984
984
|
"host:portrait": {
|
|
985
985
|
"record": [
|
|
@@ -2942,8 +2942,8 @@
|
|
|
2942
2942
|
[]
|
|
2943
2943
|
]
|
|
2944
2944
|
],
|
|
2945
|
-
"dom": "
|
|
2946
|
-
"writes":
|
|
2945
|
+
"dom": "1c760990373ee7c67daad59a423e73793b67312c7f13a0bfec4fe61b7dd601f1",
|
|
2946
|
+
"writes": 1130
|
|
2947
2947
|
},
|
|
2948
2948
|
"host:landscape": {
|
|
2949
2949
|
"record": [
|
|
@@ -614,19 +614,29 @@ test('frame wiring only draws in opted-in places and clears once on keyless trav
|
|
|
614
614
|
parent: null,
|
|
615
615
|
matrixWorldAutoUpdate: true,
|
|
616
616
|
updateMatrixWorld() {
|
|
617
|
-
|
|
617
|
+
if (scene.data.engine.hubCrowdNames) {
|
|
618
|
+
assert(!Object.hasOwn(system, 'crowdFrame'), 'the root camera updates before capturing shared projection geometry');
|
|
619
|
+
}
|
|
618
620
|
cameraUpdates += 1;
|
|
619
621
|
},
|
|
620
622
|
};
|
|
621
623
|
scene.three = { camera };
|
|
622
624
|
scene.data.engine.hubCrowdNames = true;
|
|
623
625
|
system.afterBehaviors(scene, 0.05);
|
|
624
|
-
assert.equal(cameraUpdates, 1, '
|
|
626
|
+
assert.equal(cameraUpdates, 1, 'the frame mirrors the renderer root-camera update once');
|
|
625
627
|
assert.equal(system.crowdFrame.camera, camera, 'the synchronized camera is captured for the late pass');
|
|
626
628
|
scene.data.engine.hubCrowdNames = false;
|
|
627
629
|
system.afterBehaviors(scene, 0.05);
|
|
628
|
-
|
|
630
|
+
// Ordinary labels also compare depths with names projected in the late pass.
|
|
631
|
+
assert.equal(cameraUpdates, 2, 'OFF synchronizes the camera before projecting world labels too');
|
|
629
632
|
system.fadeNames(scene);
|
|
633
|
+
camera.parent = {};
|
|
634
|
+
camera.updateWorldMatrix = (...args) => {
|
|
635
|
+
assert.deepEqual(args, [true, false], 'a parented camera updates its ancestors too');
|
|
636
|
+
cameraUpdates += 1;
|
|
637
|
+
};
|
|
638
|
+
system.afterBehaviors(scene, 0.05);
|
|
639
|
+
assert.equal(cameraUpdates, 3, 'the full camera API also synchronizes without crowd names');
|
|
630
640
|
delete scene.three;
|
|
631
641
|
hook.state({}, { hubPlace: { id: 'main', title: 'Town', scene: 'scenes/main.scene', result: null } });
|
|
632
642
|
assert(!Object.hasOwn(State.hub, 'actions'));
|
|
@@ -231,7 +231,7 @@ const rows = to => [['p', 'look', to]];
|
|
|
231
231
|
const roles = new Map([['p', { label: 'Role', color: '#00ff00' }]]);
|
|
232
232
|
assert.deepEqual(roleItems(scene, local, {}, {}, roles, project), []);
|
|
233
233
|
const source = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
234
|
-
const a = source.indexOf(' markItems(scene, local, cam, view
|
|
234
|
+
const a = source.indexOf(' markItems(scene, local, cam, view'), b = source.indexOf(' measure(', a);
|
|
235
235
|
const marks = Function('Hub', 'disguiseTags', 'project', 'return ({' + source.slice(a, b) + '});');
|
|
236
236
|
const { disguiseTags } = await import('../code/client/disguise.js');
|
|
237
237
|
hub.marks = { p: { text: 'Mark' } };
|
|
@@ -383,9 +383,9 @@ const tree = (node) => ({ id: node.id, text: node.children.length ? undefined :
|
|
|
383
383
|
// The HUD as it is today, written here so a change to the default shows.
|
|
384
384
|
const COPY = { background: 'rgba(20,16,12,0.78)', borderRadius: '14px', padding: '4px 8px', boxSizing: 'border-box', width: 'max-content', maxWidth: '100%', margin: '0 auto', lineHeight: '1.3', whiteSpace: 'normal', overflowWrap: 'anywhere', overflow: 'hidden', display: 'block' };
|
|
385
385
|
const TODAY = {
|
|
386
|
-
hud: { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', textAlign: 'center', textShadow: '0 0 2px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.95), 0 1px 4px rgba(0,0,0,0.75), 0 0 10px rgba(0,0,0,0.45)', display: 'block', maxWidth: '70vw' },
|
|
386
|
+
hud: { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', width: 'max-content', textAlign: 'center', textShadow: '0 0 2px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.95), 0 1px 4px rgba(0,0,0,0.75), 0 0 10px rgba(0,0,0,0.45)', display: 'block', maxWidth: '70vw' },
|
|
387
387
|
title: { ...COPY, fontSize: '13px', maxHeight: '41.8px', letterSpacing: '0.06em', textTransform: 'uppercase' },
|
|
388
|
-
big: { background: 'rgba(20,16,12,0.78)', borderRadius: '14px', padding: '0 8px', boxSizing: 'border-box', width: 'max-content', maxWidth: '100%', margin: '4px auto 0',
|
|
388
|
+
big: { background: 'rgba(20,16,12,0.78)', borderRadius: '14px', padding: '0 8px', boxSizing: 'border-box', width: 'max-content', maxWidth: '100%', margin: '4px auto 0', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', fontVariantNumeric: 'tabular-nums', fontSize: '56px', fontWeight: '800', lineHeight: '1.05', display: 'block' },
|
|
389
389
|
text: { ...COPY, position: 'absolute', left: 'max(16px, env(safe-area-inset-left))', right: 'max(16px, env(safe-area-inset-right))', bottom: 'max(54px, calc(env(safe-area-inset-bottom) + 48px))', fontSize: '14px', overflow: 'visible', maxWidth: 'min(60vw, 560px, calc(100vw - max(16px, env(safe-area-inset-left)) - max(16px, env(safe-area-inset-right))))', fontWeight: '500', textAlign: 'center', zIndex: '2' },
|
|
390
390
|
};
|
|
391
391
|
|
|
@@ -403,10 +403,9 @@ test('never told: the HUD, labels and pointers are styled and placed as today',
|
|
|
403
403
|
const top = Object.fromEntries(r.labels.children.map((c) => [c.textContent, c.styles.top]));
|
|
404
404
|
assert.deepEqual(top, { 'Start here': '90px', 'Take the lantern to the well.': '60px', IT: '80px', Well: '400px', '👋': '138px' });
|
|
405
405
|
assert.deepEqual(r.pointers.children.map((c) => c.styles.top), ['84px', '95px', '500px']);
|
|
406
|
-
//
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
406
|
+
// Numeric nowrap/ellipsis are baseline styles, with no clear-HUD height cap.
|
|
407
|
+
assert.equal(r.hud.styles.maxHeight ?? '', '');
|
|
408
|
+
assert.equal(r.hudBig.styles.maxWidth, '100%');
|
|
410
409
|
});
|
|
411
410
|
|
|
412
411
|
test('told no: the same writes in the same order as never told', () => {
|
|
@@ -582,9 +581,13 @@ test('after a place that asked, a place that does not is drawn as never told', (
|
|
|
582
581
|
assert.deepEqual(styleOf(after.hudBig), TODAY.big);
|
|
583
582
|
assert.deepEqual(styleOf(after.hudText), TODAY.text);
|
|
584
583
|
assert.deepEqual(styleOf(after.hud), view.viewW > view.viewH ? { ...TODAY.hud, maxWidth: 'min(42vw, 420px)' } : TODAY.hud);
|
|
585
|
-
//
|
|
586
|
-
|
|
587
|
-
|
|
584
|
+
// Numeric/text changes own their ellipsis styles even without hud.clear.
|
|
585
|
+
// The clear-HUD height cap is restored only once.
|
|
586
|
+
const putBack = after.log.slice(mark).filter((line) => /maxHeight/.test(line));
|
|
587
|
+
assert.equal(putBack.length, 1, 'height cap put back once, in the first frame');
|
|
588
|
+
const restored = after.log.length;
|
|
589
|
+
after.chrome.setHudClear(false);
|
|
590
|
+
assert.equal(after.log.length, restored, 'an already disabled clear HUD writes nothing');
|
|
588
591
|
}
|
|
589
592
|
});
|
|
590
593
|
|
|
@@ -759,7 +762,10 @@ test('asked, then not, with no HUD drawn: put back at once, and written to as ne
|
|
|
759
762
|
// root is drawn by a renderer that skips them, and the client never told
|
|
760
763
|
// still had a HUD up when its later frames began).
|
|
761
764
|
frames(after, () => undefined, later);
|
|
762
|
-
|
|
765
|
+
// A restored numeric fit may measure again. Compare mutations here,
|
|
766
|
+
// while placement-cache tests own the read-before-write invariant.
|
|
767
|
+
const told = after.log.slice(mark).filter((line) => !line.endsWith(' read'));
|
|
768
|
+
const untold = never.log.slice(neverMark).filter((line) => !line.endsWith(' read'));
|
|
763
769
|
let at = 0;
|
|
764
770
|
for (const line of told) {
|
|
765
771
|
at = untold.indexOf(line, at);
|
|
@@ -15,6 +15,65 @@ try {
|
|
|
15
15
|
assert(fileURLToPath(url).startsWith(fileURLToPath(root)));
|
|
16
16
|
await route.fulfill({ contentType: 'text/javascript', body: await readFile(url, 'utf8') });
|
|
17
17
|
});
|
|
18
|
+
await page.setViewportSize({ width: 390, height: 844 });
|
|
19
|
+
await page.goto('http://hud.test/');
|
|
20
|
+
const portrait = await page.evaluate(async () => {
|
|
21
|
+
const { makeChrome } = await import('/kits/hub-game/code/client/chrome.js');
|
|
22
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
23
|
+
const spec = { title: 'Vault · Deliver your treasures to the team entrance', timer: { since: 0 } };
|
|
24
|
+
const title = document.querySelector('[data-hub-copy="subtitle"]');
|
|
25
|
+
const big = title.nextElementSibling;
|
|
26
|
+
const sample = seconds => {
|
|
27
|
+
chrome.beginLayoutFrame();
|
|
28
|
+
chrome.setHud(spec, seconds, seconds * 1000);
|
|
29
|
+
chrome.endLayoutFrame();
|
|
30
|
+
const line = node => {
|
|
31
|
+
const range = document.createRange();
|
|
32
|
+
range.selectNodeContents(node);
|
|
33
|
+
const style = getComputedStyle(node);
|
|
34
|
+
return { rows: new Set([...range.getClientRects()].map((rect) => Math.round(rect.top))).size, whitespace: style.whiteSpace,
|
|
35
|
+
width: node.clientWidth, scroll: node.scrollWidth, font: parseFloat(style.fontSize), tabular: style.fontVariantNumeric, ellipsis: style.textOverflow, text: node.textContent, height: node.clientHeight, scrollHeight: node.scrollHeight };
|
|
36
|
+
};
|
|
37
|
+
return { text: big.textContent, title: line(title), expectedTitle: spec.title, big: line(big) };
|
|
38
|
+
};
|
|
39
|
+
const normal = sample(83.4);
|
|
40
|
+
spec.title = 'Vault'; // Keep the title short in this artificial clock lane.
|
|
41
|
+
big.parentElement.style.maxWidth = '105px';
|
|
42
|
+
sample(83.5); // This frame detects the width change.
|
|
43
|
+
const narrow = sample(83.6);
|
|
44
|
+
const next = sample(83.7);
|
|
45
|
+
// A clear HUD's title changes must retain the fit through every tick.
|
|
46
|
+
chrome.setHudClear(true);
|
|
47
|
+
const clearA = sample(83.8);
|
|
48
|
+
spec.title = 'Crew';
|
|
49
|
+
const clearB = sample(83.9);
|
|
50
|
+
const clearC = sample(84.0);
|
|
51
|
+
chrome.dispose();
|
|
52
|
+
return { normal, narrow, next, clearA, clearB, clearC };
|
|
53
|
+
});
|
|
54
|
+
for (const result of Object.values(portrait)) {
|
|
55
|
+
assert.equal(result.big.rows, 1);
|
|
56
|
+
assert.equal(result.big.whitespace, 'nowrap');
|
|
57
|
+
assert.equal(result.big.tabular, 'tabular-nums');
|
|
58
|
+
assert(result.big.scroll <= result.big.width, 'the full number fits');
|
|
59
|
+
assert(result.title.rows <= 2, 'title keeps to two rows');
|
|
60
|
+
assert.equal(result.title.text, result.expectedTitle, 'all title words are present');
|
|
61
|
+
assert.equal(result.title.whitespace, 'normal');
|
|
62
|
+
assert.notEqual(result.title.ellipsis, 'ellipsis');
|
|
63
|
+
assert(result.title.scrollHeight <= result.title.height + 1, 'all title words fit in the two rows');
|
|
64
|
+
}
|
|
65
|
+
assert.equal(portrait.normal.text, '83.4');
|
|
66
|
+
assert.equal(portrait.normal.big.font, 56);
|
|
67
|
+
assert(portrait.normal.title.width > 195, 'centered title uses the HUD width cap instead of half the viewport');
|
|
68
|
+
assert(portrait.narrow.big.font < portrait.normal.big.font, 'a constrained clock shrinks');
|
|
69
|
+
assert.equal(portrait.narrow.text, '83.6');
|
|
70
|
+
assert.equal(portrait.next.text, '83.7');
|
|
71
|
+
assert.equal(portrait.next.big.width, portrait.narrow.big.width, 'digit changes keep the same width');
|
|
72
|
+
assert.equal(portrait.clearB.text, '83.9');
|
|
73
|
+
assert.equal(portrait.clearC.text, '84.0');
|
|
74
|
+
assert.equal(portrait.clearB.big.font, portrait.clearA.big.font, 'a title change retains the fitted clock');
|
|
75
|
+
assert.equal(portrait.clearC.big.font, portrait.clearB.big.font, 'the next tick retains the fitted clock');
|
|
76
|
+
console.log('390x844: clock stays on one line and shrinks in a constrained lane');
|
|
18
77
|
for (const [width, height] of [[412, 870], [844, 390]]) {
|
|
19
78
|
await page.setViewportSize({ width, height });
|
|
20
79
|
await page.goto('http://hud.test/');
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
// scripted sequence below is played through the web chrome on the stand-in
|
|
4
4
|
// DOM and recorded: every `hud` root the sink is sent (its bytes, rev and sim
|
|
5
5
|
// time), every time sync, every event handled, and a digest of every DOM
|
|
6
|
-
// write. The
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// send the host the same roots. `RECORD=1` writes the recording anew.
|
|
6
|
+
// write. The chrome must match `fixtures/hud-surface.json` byte for byte,
|
|
7
|
+
// and the surface alone (no DOM at all) must send the host the same roots.
|
|
8
|
+
// `RECORD=1` writes the recording anew.
|
|
10
9
|
import assert from 'node:assert/strict';
|
|
11
10
|
import { createHash } from 'node:crypto';
|
|
12
11
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
@@ -268,5 +267,33 @@ if (RECORD) {
|
|
|
268
267
|
assert.deepEqual(hudInputs({ hud: null, hudMe: undefined }, 5_000), { spec: null, timer: null });
|
|
269
268
|
assert.deepEqual(hudInputs({}, 5_000), { spec: undefined, timer: null });
|
|
270
269
|
passed += 1;
|
|
270
|
+
|
|
271
|
+
const dom = fakeDom({ viewW: 390, viewH: 844 });
|
|
272
|
+
const { makeChrome } = await import('../code/client/chrome.js');
|
|
273
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
274
|
+
const clock = { title: 'Vault', timer: { since: 0 } };
|
|
275
|
+
chrome.setHud(clock, 83.4, 83_400);
|
|
276
|
+
const big = dom.made.find(node => node.textContent === '83.4');
|
|
277
|
+
const title = dom.made.find(node => node.dataset.hubCopy === 'subtitle');
|
|
278
|
+
assert.equal(title.style.whiteSpace, 'normal');
|
|
279
|
+
assert.equal(title.style.textOverflow, '');
|
|
280
|
+
assert.equal(big.style.whiteSpace, 'nowrap');
|
|
281
|
+
assert.equal(big.style.fontVariantNumeric, 'tabular-nums');
|
|
282
|
+
assert.equal(big.style.fontSize, '56px');
|
|
283
|
+
title.parent.style.maxWidth = '105px';
|
|
284
|
+
big.client = 105; big.scroll = 137;
|
|
285
|
+
chrome.setHud(clock, 83.5, 83_500);
|
|
286
|
+
chrome.setHud(clock, 83.6, 83_600);
|
|
287
|
+
assert(Number.parseFloat(big.style.fontSize) < 56);
|
|
288
|
+
const fitted = big.style.fontSize;
|
|
289
|
+
chrome.setHud(clock, 75.3, 75_300);
|
|
290
|
+
assert.equal(big.textContent, '75.3');
|
|
291
|
+
assert.equal(big.style.fontSize, fitted);
|
|
292
|
+
title.parent.style.maxWidth = '70vw';
|
|
293
|
+
big.client = big.scroll;
|
|
294
|
+
chrome.setHud(clock, 75.3, 75_300);
|
|
295
|
+
assert.equal(big.style.fontSize, '56px');
|
|
296
|
+
chrome.dispose();
|
|
297
|
+
passed += 1;
|
|
271
298
|
console.log(`hud surface: ${passed} checks passed`);
|
|
272
299
|
}
|
|
@@ -496,6 +496,93 @@ assert.deepEqual(hudContents(scene, self, self.components.Transform, 0), { remai
|
|
|
496
496
|
chrome.endLayoutFrame(); chrome.dispose();
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
+
// A numeric fit survives clear-HUD relayouts and clock ticks without first
|
|
500
|
+
// returning to the layout font or reading fresh geometry after writes.
|
|
501
|
+
{
|
|
502
|
+
const dom = fakeDom({ viewW: 390, viewH: 844 });
|
|
503
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
504
|
+
const spec = { title: 'Vault', timer: { since: 0 } };
|
|
505
|
+
chrome.setHud(spec, 83.4, 83_400);
|
|
506
|
+
const big = dom.made.find((node) => node.textContent === '83.4');
|
|
507
|
+
big.parent.style.maxWidth = '105px';
|
|
508
|
+
big.client = 105;
|
|
509
|
+
Object.defineProperty(big, 'scrollWidth', { get() {
|
|
510
|
+
dom.log.push('clock scroll read');
|
|
511
|
+
return Math.max(105, 16 + Number.parseFloat(big.style.fontSize) * 2.3);
|
|
512
|
+
} });
|
|
513
|
+
chrome.setHudClear(true);
|
|
514
|
+
chrome.showBack(true);
|
|
515
|
+
const back = dom.made.find((node) => node.tag === 'button' && node.textContent === '‹ Back');
|
|
516
|
+
const frame = (seconds) => {
|
|
517
|
+
chrome.beginLayoutFrame();
|
|
518
|
+
const start = dom.log.length;
|
|
519
|
+
chrome.setHud(spec, seconds, seconds * 1000);
|
|
520
|
+
const firstWrite = dom.log.findIndex((line, i) => i >= start && line.includes(' style.'));
|
|
521
|
+
assert(!dom.log.slice(firstWrite < 0 ? dom.log.length : firstWrite).some((line) => line.endsWith(' read')));
|
|
522
|
+
chrome.endLayoutFrame();
|
|
523
|
+
};
|
|
524
|
+
frame(83.5);
|
|
525
|
+
frame(83.6);
|
|
526
|
+
const fitted = big.style.fontSize;
|
|
527
|
+
assert(Number.parseFloat(fitted) < 56, 'a clock that advances every frame fits the lane');
|
|
528
|
+
assert(big.scrollWidth <= big.clientWidth, 'the full clock fits');
|
|
529
|
+
for (let i = 0; i < 5; i += 1) {
|
|
530
|
+
spec.title = `Vault ${i}`;
|
|
531
|
+
back.rect = { left: i, right: 70 + i, top: 12, bottom: 50 };
|
|
532
|
+
const start = dom.log.length;
|
|
533
|
+
frame(83.7 + i / 10);
|
|
534
|
+
assert.equal(big.style.fontSize, fitted, 'title/Back changes retain the fitted clock size');
|
|
535
|
+
assert(!dom.log.slice(start).includes(`${big.id} style.fontSize=56px`), 'relayout never resets the fitted font');
|
|
536
|
+
}
|
|
537
|
+
chrome.dispose();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// The lane can narrow after the current frame sampled a wider number.
|
|
541
|
+
{
|
|
542
|
+
const dom = fakeDom({ viewW: 390, viewH: 844 });
|
|
543
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
544
|
+
chrome.setEmotes([['wave', '👋']]);
|
|
545
|
+
chrome.setSay({ reactions: [], phrases: [] });
|
|
546
|
+
const emote = dom.made.find((node) => node.attrs['aria-label'] === 'Emote');
|
|
547
|
+
const say = dom.made.find((node) => node.attrs['aria-label'] === 'Quick chat');
|
|
548
|
+
emote.rect = { left: 176, right: 228, top: 45, bottom: 97 };
|
|
549
|
+
say.rect = { left: 121, right: 173, top: 80, bottom: 132 };
|
|
550
|
+
const spec = { title: 'Vault', big: '83.4' };
|
|
551
|
+
chrome.setHud(spec, null);
|
|
552
|
+
const big = dom.made.find((node) => node.textContent === spec.big);
|
|
553
|
+
const hud = big.parent;
|
|
554
|
+
const laneWidth = () => hud.style.maxWidth.endsWith('px') ? parseFloat(hud.style.maxWidth) : 240;
|
|
555
|
+
const numberWidth = () => Math.ceil(16 + parseFloat(big.style.fontSize) * 2.3);
|
|
556
|
+
let hudBottom = 70;
|
|
557
|
+
Object.defineProperty(hud, 'rect', { get() {
|
|
558
|
+
const width = laneWidth();
|
|
559
|
+
return { left: (390 - width) / 2, right: (390 + width) / 2, top: 12, bottom: hudBottom };
|
|
560
|
+
} });
|
|
561
|
+
Object.defineProperties(big, {
|
|
562
|
+
clientWidth: { get: () => Math.min(laneWidth(), numberWidth()) },
|
|
563
|
+
scrollWidth: { get: numberWidth },
|
|
564
|
+
});
|
|
565
|
+
const frame = () => {
|
|
566
|
+
chrome.beginLayoutFrame();
|
|
567
|
+
chrome.setHud(spec, null);
|
|
568
|
+
chrome.endLayoutFrame();
|
|
569
|
+
};
|
|
570
|
+
frame();
|
|
571
|
+
frame();
|
|
572
|
+
assert.equal(hud.style.maxWidth, '160px');
|
|
573
|
+
assert.equal(big.style.fontSize, '56px');
|
|
574
|
+
hudBottom = 110; // The HUD now hits the second control, inside the first lane.
|
|
575
|
+
frame();
|
|
576
|
+
assert.equal(hud.style.maxWidth, '105px');
|
|
577
|
+
frame();
|
|
578
|
+
assert(Number.parseFloat(big.style.fontSize) < 56, 'the next frame fits the narrower lane');
|
|
579
|
+
assert(big.scrollWidth <= big.clientWidth, 'the full number fits after the lane narrows');
|
|
580
|
+
const fitted = big.style.fontSize;
|
|
581
|
+
frame();
|
|
582
|
+
assert.equal(big.style.fontSize, fitted, 'the new fit stays in place');
|
|
583
|
+
chrome.dispose();
|
|
584
|
+
}
|
|
585
|
+
|
|
499
586
|
// A dock can stay display:flex with an empty box while all its buttons hide.
|
|
500
587
|
// Showing a descendant must update the dock on N+1, without invalidation.
|
|
501
588
|
{
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// The bottom prompt on a phone held upright (Nov 19 door pass: it wrapped on
|
|
2
|
+
// 37 doors in portrait, capped at 60% of a 390 px view, 234 px, about 30
|
|
3
|
+
// characters). Upright, where the safe layout places it (`hub.safeInsets` or
|
|
4
|
+
// Act), it now takes the lane beside the control column: a 40-character
|
|
5
|
+
// sentence stays on one line on a 360 px phone, a longer one is as wide as
|
|
6
|
+
// that lane before it wraps, and every one stays clear of the controls, in
|
|
7
|
+
// the first frame it is shown too (not 500 ms later). Without the safe layout,
|
|
8
|
+
// and in landscape, the prompt keeps its 60% cap. Run with CHROME pointing to the QA browser (and BROWSER_WS when
|
|
9
|
+
// using a remote GPU browser).
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { chromium } from 'playwright-core';
|
|
14
|
+
import { launchChromium, logRenderer } from '../../../experiments/hub-town/qa/launch.mjs';
|
|
15
|
+
|
|
16
|
+
const root = new URL('../../../', import.meta.url);
|
|
17
|
+
const source = await readFile(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
18
|
+
const setup = source.slice(source.indexOf(' this.chrome.setWorldLabelFocus'), source.indexOf(' Avatar.load(scene);'));
|
|
19
|
+
const browser = await launchChromium(chromium, { executablePath: process.env.CHROME });
|
|
20
|
+
try {
|
|
21
|
+
const page = await browser.newPage();
|
|
22
|
+
await page.route('http://layout.test/**', async route => {
|
|
23
|
+
const path = new URL(route.request().url()).pathname;
|
|
24
|
+
if (path === '/') return route.fulfill({ contentType: 'text/html', body: '<script type="importmap">{"imports":{"three":"/node_modules/three/build/three.module.js"}}</script><body style="margin:0"></body>' });
|
|
25
|
+
const url = new URL(`.${path}`, root);
|
|
26
|
+
assert(fileURLToPath(url).startsWith(fileURLToPath(root)));
|
|
27
|
+
await route.fulfill({ contentType: 'text/javascript', body: await readFile(url, 'utf8') });
|
|
28
|
+
});
|
|
29
|
+
const SHORT = 'Pulse the pink sentry, then fix the seal';
|
|
30
|
+
const LONG = 'Pulse the pink sentry, then restore the old seal';
|
|
31
|
+
assert.equal(SHORT.length, 40);
|
|
32
|
+
assert.equal(LONG.length, 48);
|
|
33
|
+
for (const [width, height] of [[390, 844], [360, 740], [412, 915], [375, 667], [844, 390]]) {
|
|
34
|
+
await page.setViewportSize({ width, height });
|
|
35
|
+
for (const mode of ['act', 'safe', 'legacy']) for (const PROMPT of [SHORT, LONG]) {
|
|
36
|
+
await page.goto('http://layout.test/');
|
|
37
|
+
await logRenderer(page, 'prompt portrait');
|
|
38
|
+
const result = await page.evaluate(async ({ mode, setup, text }) => {
|
|
39
|
+
const { makeChrome } = await import('/kits/hub-game/code/client/chrome.js');
|
|
40
|
+
const { overlaps } = await import('/kits/hub-game/code/client/safeLayout.js');
|
|
41
|
+
const chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {}, safeInsets: ['safe', 'act'].includes(mode) });
|
|
42
|
+
chrome.soundControl(true, { volume: 0.7, muted: false }, { onMuted() {}, onVolume() {} });
|
|
43
|
+
chrome.showPicker(true, 0);
|
|
44
|
+
chrome.setEmotes([['wave', '👋']]); chrome.setSay({ reactions: [], phrases: [] });
|
|
45
|
+
chrome.setDoors([{ id: 'cove', title: 'Cove' }]);
|
|
46
|
+
const { attachOrbitInput } = await import('/kits/physics-3d/engine3d/orbitinput.js');
|
|
47
|
+
const canvas = document.createElement('canvas'); document.body.append(canvas);
|
|
48
|
+
const runtime = { cameraControl: 'orbit', keys: new Set() };
|
|
49
|
+
const engine = attachOrbitInput(canvas, runtime, { set() {} }, () => {});
|
|
50
|
+
runtime.lookInput.listen();
|
|
51
|
+
window.dispatchEvent(new PointerEvent('pointerdown', { pointerType: 'touch' }));
|
|
52
|
+
const scene = { persistent: {}, three: { renderer: { domElement: { parentElement: document.body } } } };
|
|
53
|
+
const Hub = { deck: { safeInsets: mode === 'safe', act: mode === 'act' }, hub: {} };
|
|
54
|
+
const context = { chrome };
|
|
55
|
+
let words = '';
|
|
56
|
+
const draw = () => {
|
|
57
|
+
chrome.setHud({ title: 'Bell Quay', text: words }, null);
|
|
58
|
+
new Function('Hub', 'scene', 'worldLabelFocus', setup).call(context, Hub, scene, () => false);
|
|
59
|
+
chrome.grabPrompt(null); chrome.sitPrompt(null); chrome.talkPrompt(null);
|
|
60
|
+
chrome.layoutInteractionRail();
|
|
61
|
+
chrome.setActions([{ id: 'invite-friend', label: 'Invite a friend' }], () => {}, true, 1, false);
|
|
62
|
+
chrome.frameSafeInsets?.();
|
|
63
|
+
};
|
|
64
|
+
if (mode === 'act') {
|
|
65
|
+
const { makeAct } = await import('/kits/hub-game/code/client/act.js');
|
|
66
|
+
const { hub } = await import('/kits/hub-game/code/client/state.js');
|
|
67
|
+
hub.place = { id: 'main', act: true };
|
|
68
|
+
hub.prompts = [];
|
|
69
|
+
const act = makeAct(chrome, { perform() {} }, { prepare() {} });
|
|
70
|
+
Object.assign(scene, { getActors: () => [], getActor: () => null, moveInput: { consumeJump() {} } });
|
|
71
|
+
scene.three.camera = { position: { clone: () => ({ set() { return this; }, project: () => ({ x: 0, y: 0, z: 0 }) }) } };
|
|
72
|
+
act.frame(scene, { net: { selfId: () => 'p', send() {} } }, { components: { Transform: { x: 0, y: 1, z: 0 } } }, true);
|
|
73
|
+
}
|
|
74
|
+
const paint = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
75
|
+
draw(); await paint(); draw(); await paint();
|
|
76
|
+
await new Promise(resolve => setTimeout(resolve, 550));
|
|
77
|
+
for (let frame = 0; frame < 8; frame++) {draw(); await paint();}
|
|
78
|
+
// Shown on a settled screen: placed in its first frame, before the
|
|
79
|
+
// layout's own 500 ms pass.
|
|
80
|
+
words = text; draw(); await paint();
|
|
81
|
+
const prompt = document.querySelector('[data-hub="hud-prompt"]');
|
|
82
|
+
const firstBox = prompt.getBoundingClientRect();
|
|
83
|
+
await new Promise(resolve => setTimeout(resolve, 550));
|
|
84
|
+
for (let frame = 0; frame < 4; frame++) {draw(); await paint();}
|
|
85
|
+
// Taken down (no HUD) long enough for the layout to let go of it,
|
|
86
|
+
// then the same words again: placed again in their first frame.
|
|
87
|
+
chrome.setHud(null, null); await paint();
|
|
88
|
+
await new Promise(resolve => setTimeout(resolve, 550));
|
|
89
|
+
await paint();
|
|
90
|
+
draw(); await paint();
|
|
91
|
+
const againBox = prompt.getBoundingClientRect();
|
|
92
|
+
await new Promise(resolve => setTimeout(resolve, 550));
|
|
93
|
+
for (let frame = 0; frame < 4; frame++) {draw(); await paint();}
|
|
94
|
+
const style = getComputedStyle(prompt);
|
|
95
|
+
const box = prompt.getBoundingClientRect();
|
|
96
|
+
const oneLine = Math.ceil(parseFloat(style.lineHeight) + parseFloat(style.paddingTop) + parseFloat(style.paddingBottom));
|
|
97
|
+
const nodes = [...document.querySelectorAll('button')].filter(node => ['Character', 'Invite a friend', 'Doors'].includes(node.textContent) || /^(Emote|Quick chat|Sound:)/.test(node.getAttribute('aria-label') ?? '') || ['act', 'jump'].includes(node.dataset.hubAct));
|
|
98
|
+
const controls = nodes.filter(node => node.getBoundingClientRect().width > 0 && getComputedStyle(node).visibility !== 'hidden')
|
|
99
|
+
.map(node => ({ name: node.getAttribute('aria-label') || node.textContent, ...Object.fromEntries(['left', 'right', 'top', 'bottom'].map(key => [key, node.getBoundingClientRect()[key]])) }));
|
|
100
|
+
const hits = controls.filter(control => overlaps(control, box)).map(control => control.name);
|
|
101
|
+
const wrapped = prompt.scrollHeight > oneLine;
|
|
102
|
+
const shown = style.display !== 'none' && style.visibility !== 'hidden';
|
|
103
|
+
const said = prompt.textContent;
|
|
104
|
+
const freshHits = controls.filter(control => overlaps(control, firstBox)).map(control => control.name);
|
|
105
|
+
const againHits = controls.filter(control => overlaps(control, againBox)).map(control => control.name);
|
|
106
|
+
const result = { text: said, visible: shown, wrapped,
|
|
107
|
+
left: box.left, right: box.right, top: box.top, bottom: box.bottom, width: box.width, hits, freshHits, againHits, w: innerWidth, h: innerHeight };
|
|
108
|
+
engine.detach(); chrome.dispose(); canvas.remove();
|
|
109
|
+
return result;
|
|
110
|
+
}, { mode, setup, text: PROMPT });
|
|
111
|
+
const at = `${width}x${height} ${mode} ${PROMPT.length} chars`;
|
|
112
|
+
assert(result.visible && result.text === PROMPT, `${at}: prompt drawn`);
|
|
113
|
+
assert.deepEqual(result.hits, [], `${at}: prompt clears the controls`);
|
|
114
|
+
assert.deepEqual(result.freshHits, [], `${at}: a newly shown prompt clears the controls in its first frame`);
|
|
115
|
+
assert.deepEqual(result.againHits, [], `${at}: the same prompt shown again clears the controls in its first frame`);
|
|
116
|
+
assert(result.left >= 0 && result.right <= result.w && result.bottom <= result.h, `${at}: prompt inside the view`);
|
|
117
|
+
if (width < height && mode !== 'legacy') {
|
|
118
|
+
if (PROMPT === SHORT) {assert.equal(result.wrapped, false, `${at}: stays on one line (${Math.round(result.width)} px)`);}
|
|
119
|
+
// Before: 234 px at 390, 216 at 360. The lane beside the column is
|
|
120
|
+
// about 314 at 390 and 284 at 360.
|
|
121
|
+
else {assert(result.width >= result.w - 106, `${at}: as wide as the lane beside the column (${Math.round(result.width)} px)`);}
|
|
122
|
+
} else {
|
|
123
|
+
assert(result.width <= result.w * 0.6 + 1, `${at}: a landscape or legacy prompt keeps its 60% cap`);
|
|
124
|
+
}
|
|
125
|
+
console.log(`${at}: prompt ${Math.round(result.width)} px, ${result.wrapped ? 'wrapped' : 'one line'}, clear`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} finally { await browser.close(); }
|
|
@@ -447,7 +447,7 @@ function tagFrameFixture() {
|
|
|
447
447
|
const b = source.indexOf(' worldLabelCount = labels.length;', a);
|
|
448
448
|
const c = source.indexOf(' if (qualityTagItems) {', b);
|
|
449
449
|
const d = source.indexOf(' labels.push(...this.idle', c);
|
|
450
|
-
const m = source.indexOf(' markItems(scene, local, cam, view
|
|
450
|
+
const m = source.indexOf(' markItems(scene, local, cam, view');
|
|
451
451
|
const markItems = source.slice(m, source.indexOf('\n measure(', m)).trim();
|
|
452
452
|
assert.ok(a > 0 && b > a && c > b && d > c && m > 0);
|
|
453
453
|
const project = (_cam, x, y, z) => ({ x: 100 + x * 10, y: 300 - y * 10 + z });
|
|
@@ -35,6 +35,7 @@ register(`data:text/javascript,${encodeURIComponent(hooks)}`);
|
|
|
35
35
|
const THREE = await import('three');
|
|
36
36
|
const Avatar = await import('../code/client/avatar.js');
|
|
37
37
|
const Role = await import('../code/client/role.js');
|
|
38
|
+
const { disguiseTags } = await import('../code/client/disguise.js');
|
|
38
39
|
const HoldShow = await import('../code/client/holdShow.js');
|
|
39
40
|
const State = await import('../code/client/state.js');
|
|
40
41
|
const hooksLayer = (await import('../code/client/hookLayer.js')).default;
|
|
@@ -45,6 +46,7 @@ const Hats = await import('./gen-hats.mjs');
|
|
|
45
46
|
const { makeChrome } = await import('../code/client/chrome.js');
|
|
46
47
|
const { fakeDom } = await import('./fixtures/fake-dom.mjs');
|
|
47
48
|
const { crowdNamesFor, layoutCrowdNames, makeCrowdNames, readableSpriteBox, spriteBox } = await import('../code/client/crowdNames.js');
|
|
49
|
+
const { projectNameTag } = await import('../code/client/nameTagLayout.js');
|
|
48
50
|
const { placeLabels } = await import('../code/client/padOccupancy.js');
|
|
49
51
|
const police = { id: 'police', label: 'Police', color: '#22335a', hat: 'police-cap', top: 'vest', tool: 'torch' };
|
|
50
52
|
const doctor = { id: 'doctor', label: 'Doctor', color: '#42a6c0', hat: 'nurse-cap', top: 'scrubs', tool: 'bag' };
|
|
@@ -228,11 +230,79 @@ test('role chip uses final name height and remote name visibility while keeping
|
|
|
228
230
|
const nodes = new Map([['role:me', { style: {} }], ['role:p2', { style: {} }], ['mark:p2', { style: {} }]]);
|
|
229
231
|
const sync = new Function('labelNodes', 'hudClear', 'hudText', `return ({${method}}).syncRoleLabels`)(nodes, false, { style: { display: 'none' } });
|
|
230
232
|
sync([items[0]]);
|
|
231
|
-
assert.equal(nodes.get('role:p2').style.
|
|
233
|
+
assert.equal(nodes.get('role:p2').style.display, 'none');
|
|
232
234
|
assert.equal(nodes.get('role:me').style.top, `${items[0].y}px`);
|
|
233
235
|
assert.deepEqual(nodes.get('mark:p2').style, {});
|
|
234
236
|
});
|
|
235
237
|
|
|
238
|
+
test('IT sits four pixels above a tall, distance-scaled name and follows its opacity', () => {
|
|
239
|
+
const scene = sceneOf();
|
|
240
|
+
const camera = new THREE.PerspectiveCamera(55, 390 / 844, 0.1, 100);
|
|
241
|
+
camera.position.set(0, 5, 9); camera.lookAt(0, 1, 0); camera.updateMatrixWorld();
|
|
242
|
+
const view = { w: 390, h: 844 };
|
|
243
|
+
const project = (cam, x, y, z, { w, h }) => {
|
|
244
|
+
const p = new THREE.Vector3(x, y, z).project(cam);
|
|
245
|
+
return { x: (p.x + 1) * w / 2, y: (1 - p.y) * h / 2 };
|
|
246
|
+
};
|
|
247
|
+
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ opacity: 0.6 }));
|
|
248
|
+
sprite.position.set(1.6, 4, 0); sprite.scale.set(0.9, 0.45, 1);
|
|
249
|
+
scene.multiplayer.avatars.tags = new Map([['p2', { sprite }]]);
|
|
250
|
+
const source = read('code/systems/hub.js');
|
|
251
|
+
const start = source.indexOf(' markItems(scene, local, cam, view');
|
|
252
|
+
const method = source.slice(start, source.indexOf('\n }\n', start) + 4);
|
|
253
|
+
const hub = { marks: { p2: { text: 'IT', color: '#cc0000' } }, roles: new Map() };
|
|
254
|
+
const marks = new Function('Hub', 'disguiseTags', 'project', `return ({${method}}).markItems`)({ hub }, disguiseTags, project);
|
|
255
|
+
const draw = () => marks(scene, scene.local, camera, view);
|
|
256
|
+
const [item] = draw();
|
|
257
|
+
const name = spriteBox(sprite, camera, view, project);
|
|
258
|
+
assert.ok(Math.abs(item.x - (name.left + name.right) / 2) < 1e-9);
|
|
259
|
+
assert.ok(Math.abs(item.y - (name.top - 4)) < 1e-9);
|
|
260
|
+
assert.equal(item.opacity, 0.6);
|
|
261
|
+
sprite.visible = false;
|
|
262
|
+
assert.deepEqual(draw(), []);
|
|
263
|
+
sprite.visible = true; sprite.material.opacity = 0;
|
|
264
|
+
assert.deepEqual(draw(), []);
|
|
265
|
+
|
|
266
|
+
const methods = source.slice(source.indexOf(' playerNameBox('), source.indexOf(' invalidateCrowdNames('));
|
|
267
|
+
const owner = new Function('Hub', 'projectNameTag', `return new (class {${methods}})()`)({ hub }, projectNameTag);
|
|
268
|
+
scene.three.camera = camera; scene.actorWith = () => scene.local;
|
|
269
|
+
owner.nameTagFrame = { scene, view, idle: true };
|
|
270
|
+
owner.markItems = marks;
|
|
271
|
+
let chips, boxes;
|
|
272
|
+
owner.chrome = { syncRoleLabels: (items) => {chips = items;}, setWorldNameTags: (tags) => {boxes = tags;} };
|
|
273
|
+
sprite.material.opacity = 0.6;
|
|
274
|
+
sprite.position.set(0.99, 0, 0.97).unproject(camera);
|
|
275
|
+
owner.finishNameLabels(scene);
|
|
276
|
+
const clamped = boxes.get('p2');
|
|
277
|
+
assert.ok(clamped.right <= view.w - 8 + 1e-9, 'the late pass clamps the name before positioning the mark');
|
|
278
|
+
assert.ok(Math.abs(chips[0].x - (clamped.left + clamped.right) / 2) < 1e-9);
|
|
279
|
+
assert.ok(Math.abs(chips[0].y - (clamped.top - 4)) < 1e-9);
|
|
280
|
+
scene.multiplayer.avatars.tags.clear();
|
|
281
|
+
assert.equal(draw()[0].y, project(camera, 2, 2.95, 0, view).y);
|
|
282
|
+
|
|
283
|
+
// The viewer's own mark sits where its hidden name is drawn: over this
|
|
284
|
+
// frame's body at the own-tag height, sized by the own sprite. A sprite
|
|
285
|
+
// multiplayer stopped placing does not move it; with no sprite at all it
|
|
286
|
+
// still sits at the name's height, not 1.95 m up.
|
|
287
|
+
hub.marks = { me: { text: 'IT', color: '#cc0000' } };
|
|
288
|
+
const own = new THREE.Sprite(new THREE.SpriteMaterial());
|
|
289
|
+
own.visible = false;
|
|
290
|
+
own.position.set(0, 2.25, 0); own.scale.set(0.9, 0.45, 1);
|
|
291
|
+
scene.multiplayer.avatars.tags.set('self', { sprite: own });
|
|
292
|
+
const ownName = spriteBox(own, camera, view, project);
|
|
293
|
+
const [mine] = draw();
|
|
294
|
+
assert.equal(mine.id, 'mark:me');
|
|
295
|
+
assert.ok(Math.abs(mine.x - (ownName.left + ownName.right) / 2) < 1e-9);
|
|
296
|
+
assert.ok(Math.abs(mine.y - (ownName.top - 4)) < 1e-9);
|
|
297
|
+
assert.equal(mine.opacity, 1);
|
|
298
|
+
assert.ok(mine.y > project(camera, 0, 2.95, 0, view).y, 'lower than the old fixed 1.95 m');
|
|
299
|
+
own.position.set(5, 7, 0);
|
|
300
|
+
assert.deepEqual(draw()[0], mine, 'a stale own sprite does not move the mark');
|
|
301
|
+
assert.deepEqual(marks(scene, scene.local, camera, view, false)[0], mine, 'the early pass agrees with the late one');
|
|
302
|
+
scene.multiplayer.avatars.tags.delete('self');
|
|
303
|
+
assert.ok(Math.abs(draw()[0].y - (project(camera, 0, 2.25, 0, view).y - 4)) < 1e-9);
|
|
304
|
+
});
|
|
305
|
+
|
|
236
306
|
test('role chips may overlap the viewer body but still clear HUD and controls; ordinary labels yield', () => {
|
|
237
307
|
for (const focused of [true, false]) {
|
|
238
308
|
const dom = fakeDom({ viewW: 574, viewH: 246 });
|
|
@@ -366,7 +436,7 @@ test('crowd selection reanchors roles after name resizing and excludes only thei
|
|
|
366
436
|
const deps = { Hub: { hub: State.hub }, AvatarCap: { shown: () => 1 }, roleItems: Role.roleItems,
|
|
367
437
|
project, crowdNamesFor, layoutCrowdNames, readableSpriteBox, spriteBox, placeLabels, sceneKeyOf: () => 'main' };
|
|
368
438
|
const layout = new Function(...Object.keys(deps), `return ({${method}}).layoutCrowdNames`)(...Object.values(deps));
|
|
369
|
-
const system = { chrome, crowdNamesReady: () => true, friendsAll: null,
|
|
439
|
+
const system = { chrome, crowdNamesReady: () => true, playerNameBox: () => null, friendsAll: null,
|
|
370
440
|
crowdFrame: { view, controls: [], local: scene.local.components.Transform } };
|
|
371
441
|
const labelBoxes = chrome.crowdNameLabelBoxes.bind(chrome);
|
|
372
442
|
chrome.crowdNameLabelBoxes = () => {
|
|
@@ -378,14 +448,20 @@ test('crowd selection reanchors roles after name resizing and excludes only thei
|
|
|
378
448
|
assert.equal(sprite.visible, true, 'role chip never suppresses its name');
|
|
379
449
|
assert.notEqual(chip.style.visibility, 'hidden');
|
|
380
450
|
const ownBox = labelBoxes()[0];
|
|
381
|
-
assert.equal(ownBox.
|
|
451
|
+
assert.equal(ownBox.tagPlayerId, 'p2');
|
|
382
452
|
const candidate = { id: 'p2', distance: 1, at: { x: 2, z: 0 }, box: ownBox };
|
|
383
453
|
const state = makeCrowdNames();
|
|
384
|
-
const run = (now,
|
|
454
|
+
const run = (now, tagPlayerId) => layoutCrowdNames(state, [candidate], { now, view, obstacles: [{ ...ownBox, tagPlayerId }] });
|
|
385
455
|
assert.ok(run(0, 'p2').visible.has('p2'), 'own chip is exempt even when clearance overlaps its name');
|
|
386
456
|
assert.equal(run(1, 'other').visible.size, 0, 'other players chips remain obstacles');
|
|
387
457
|
assert.equal(run(2, 'p2').visible.size, 0);
|
|
388
458
|
assert.ok(run(252, 'p2').visible.has('p2'), 'own chip cannot prevent hysteresis restoration');
|
|
459
|
+
chrome.setLabels([{ id: 'mark:p2', text: 'IT', x: 220, y: 299, color: '#cc0000' }]);
|
|
460
|
+
dom.made.find((node) => node.textContent === 'IT').rect = ownBox;
|
|
461
|
+
assert.equal(labelBoxes.call(chrome)[0].tagPlayerId, 'p2', 'IT has the same crowd clearance exemption as a role');
|
|
462
|
+
candidate.box = { ...candidate.box, depth: 0.6 };
|
|
463
|
+
const sign = { ...candidate.box, tagPlayerId: undefined, depth: 0.8 };
|
|
464
|
+
assert.ok(layoutCrowdNames(state, [candidate], { now: 253, view, obstacles: [sign] }).visible.has('p2'), 'a farther sign yields to the name');
|
|
389
465
|
chrome.dispose(); State.clear();
|
|
390
466
|
});
|
|
391
467
|
test('a chip whose name the crowd pass rejects stays hidden after the summary flush', () => {
|
|
@@ -411,7 +487,7 @@ test('a chip whose name the crowd pass rejects stays hidden after the summary fl
|
|
|
411
487
|
project, crowdNamesFor, layoutCrowdNames, readableSpriteBox, spriteBox, placeLabels, sceneKeyOf: () => 'main' };
|
|
412
488
|
const layout = new Function(...Object.keys(deps), `return ({${method}}).layoutCrowdNames`)(...Object.values(deps));
|
|
413
489
|
// A control over the whole view rejects every name.
|
|
414
|
-
const system = { chrome, crowdNamesReady: () => true, friendsAll: null,
|
|
490
|
+
const system = { chrome, crowdNamesReady: () => true, playerNameBox: () => null, friendsAll: null,
|
|
415
491
|
crowdFrame: { view, controls: [{ left: 0, right: 400, top: 0, bottom: 800 }], local: scene.local.components.Transform } };
|
|
416
492
|
// The summary's world-layout flush restores labels layout hid, so the
|
|
417
493
|
// late role pass (position false) must come after it.
|
|
@@ -422,7 +498,7 @@ test('a chip whose name the crowd pass rejects stays hidden after the summary fl
|
|
|
422
498
|
layout.call(system, scene, 0);
|
|
423
499
|
assert.equal(sprite.visible, false, 'the name was rejected');
|
|
424
500
|
assert.deepEqual(order, ['roles', 'summary', 'roles-late']);
|
|
425
|
-
assert.equal(chip.style.
|
|
501
|
+
assert.equal(chip.style.display, 'none', 'its role chip is hidden with it, after the summary flush');
|
|
426
502
|
chrome.dispose(); State.clear();
|
|
427
503
|
});
|
|
428
504
|
console.log(`test-role-client: ${n} passed`);
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
// it rides above the keyboard on every renderer (as the text ask's and
|
|
21
21
|
// quick chat's cards do), not only where the view's inset holds the
|
|
22
22
|
// keyboard. Nothing else in a root moves, and the DOM writes are unchanged.
|
|
23
|
+
// A third: the HUD column is drawn as wide as its content (a clock's
|
|
24
|
+
// number stays on one line), one more style write in each DOM run; the
|
|
25
|
+
// talk roots are unchanged.
|
|
23
26
|
// `RECORD=1` writes the recording anew.
|
|
24
27
|
import assert from 'node:assert/strict';
|
|
25
28
|
import { createHash } from 'node:crypto';
|