castle-web-cli 0.4.253 → 0.4.255

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.
@@ -62,7 +62,7 @@ globalThis.__entryHub = {
62
62
  onBack: () => () => {},
63
63
  };
64
64
 
65
- const { parseHubEntry, planHubEntry, makeHubEntry, HUB_ENTRY_WAIT_MS } = await import('../code/client/hubEntry.js');
65
+ const { parseHubEntry, planHubEntry, makeHubEntry, HUB_ENTRY_WAIT_MS, UNKNOWN_DOOR_TOAST } = await import('../code/client/hubEntry.js');
66
66
  const { installSystem } = await import('../code/systems/hub.js');
67
67
  const HubState = await import('../code/client/state.js');
68
68
 
@@ -134,10 +134,12 @@ await test('plan: doors -- pad doors are the Doors list jump, layer/exact solo d
134
134
  { jump: listed[3], toast: 'Duo Dash needs 2 players · wait on the pad for others' }, 'a pair door is never a solo trip');
135
135
  assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-plaza' }, { ...me, host: new Map([['door-plaza', { placementKind: 'layer', enabled: false }]]) }),
136
136
  { toast: 'Plaza is closed right now' });
137
- assert.equal(planHubEntry({ kind: 'door', door: 'door-nope' }, { ...me, host }), null, 'an unknown door is ignored');
137
+ assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-nope' }, { ...me, host }), { toast: UNKNOWN_DOOR_TOAST }, 'an unknown door says it is not here');
138
+ assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-nope' }, me), { toast: UNKNOWN_DOOR_TOAST }, 'with no host rows too');
139
+ assert.equal(planHubEntry({ kind: 'door', door: 'cab-1' }, { ...me, host, present: ['cab-1', 'door-plaza'] }), null, 'a door the scene has but does not list (a cabinet) changes nothing');
138
140
  });
139
141
 
140
- await test('plan: a guest never trips or jumps for a door link; an unknown account stays quietly', () => {
142
+ await test('plan: a guest never trips or jumps for a door link; an unknown account stays quietly; an unknown door is said', () => {
141
143
  const host = new Map([
142
144
  ['door-prism', { doorId: 'door-prism', placementKind: 'pad', enabled: true }],
143
145
  ['door-plaza', { doorId: 'door-plaza', placementKind: 'layer', enabled: true }],
@@ -145,7 +147,8 @@ await test('plan: a guest never trips or jumps for a door link; an unknown accou
145
147
  assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-plaza' }, { listed, homes, host, guest: true }), { toast: 'Plaza is in the Town · sign in to play' });
146
148
  assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-prism' }, { listed, homes, host, guest: true }), { toast: 'Prism is in the Town · sign in to play' });
147
149
  assert.equal(planHubEntry({ kind: 'door', door: 'door-plaza' }, { listed, homes, host, guest: null }), null);
148
- assert.equal(planHubEntry({ kind: 'door', door: 'door-nope' }, { listed, homes, host, guest: true }), null, 'an unknown door is still silent');
150
+ assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-nope' }, { listed, homes, host, guest: true }), { toast: UNKNOWN_DOOR_TOAST }, 'a guest is told too');
151
+ assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-nope' }, { listed, homes, host, guest: null }), { toast: UNKNOWN_DOOR_TOAST }, 'and an unknown account');
149
152
  });
150
153
 
151
154
  // ---- the once-per-load state ----
@@ -299,6 +302,7 @@ function setup({ slot = 'house', depth = 0, target = { mode: 'public' } } = {})
299
302
  ['d1', { id: 'd1', components: { HubDoor: { id: 'home-1', to: 'deck:house' }, Transform: { x: 30, z: 0 } } }],
300
303
  ['d2', { id: 'd2', components: { HubDoor: { id: 'home-2', to: 'deck:house' }, Transform: { x: 5, z: 0 } } }],
301
304
  ['d3', { id: 'd3', components: { HubDoor: { id: 'door-prism', to: 'deck:prism' }, Transform: { x: 0, z: 9 } } }],
305
+ ['c1', { id: 'c1', components: { HubDoor: { id: 'cab-1', kind: 'cabinet', to: 'deck:cab' }, Transform: { x: 0, z: -9 } } }],
302
306
  ]);
303
307
  const scene = {
304
308
  persistent: { hubTickets: [], ...(depth ? { hubDepth: depth } : {}) },
@@ -401,8 +405,26 @@ await test('system: not at the root (behind a door, a hub join, a trip already)
401
405
  assert.equal(hints, 0, 'a game is not the Town');
402
406
  });
403
407
 
408
+ await test('system: a door link the place does not list stays in the Town and says so', async () => {
409
+ const { system, frame, sent } = setup({ slot: 'door:door-nope' });
410
+ await frame();
411
+ assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
412
+ assert.equal(sent.length, 0);
413
+ assert.equal(system.trip, null);
414
+ assert.equal(system.toast.text, UNKNOWN_DOOR_TOAST);
415
+ });
416
+
417
+ await test('system: a door link to a scene door the place does not list (a cabinet) changes nothing', async () => {
418
+ const { system, frame, sent } = setup({ slot: 'door:cab-1' });
419
+ await frame();
420
+ assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
421
+ assert.equal(sent.length, 0);
422
+ assert.equal(system.trip, null);
423
+ assert.equal(system.toast.text, '');
424
+ });
425
+
404
426
  await test('system: unknown slots and old hosts change nothing', async () => {
405
- for (const slot of ['garden', 'door:door-nope', null]) {
427
+ for (const slot of ['garden', null]) {
406
428
  const { system, frame, sent } = setup({ slot });
407
429
  await frame();
408
430
  assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
@@ -0,0 +1,138 @@
1
+ // The HUD, the kit Back and the standing prompt never overlap, in the real
2
+ // CSS cascade with the safe-inset layout on. Since the landscape layout
3
+ // (574937353) the kit Back stands right of the host's 64 px corner on a turned
4
+ // phone and under it in portrait, while the HUD stayed centred at the top: on
5
+ // door games (Tag, Nightwatch, Bumper Ball) its title and big line ran under
6
+ // Back on a phone in portrait and on the 497x213 frame a landscape browser
7
+ // gives an embedded deck, and its big line down onto the prompt there.
8
+ import assert from 'node:assert/strict';
9
+ import { readFile } from 'node:fs/promises';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { chromium } from 'playwright-core';
12
+ import { launchChromium } from '../../../experiments/hub-town/qa/launch.mjs';
13
+
14
+ const root = new URL('../../../', import.meta.url);
15
+ // Phone portrait and landscape, the short landscape embed, and a wider one.
16
+ // Small views (400x250, 380x250, 400x200, 280x200, 280x230, 360x180) stack the right-edge controls to
17
+ // the top, where the HUD keeps beside them too.
18
+ const SIZES = [[390, 844], [844, 390], [497, 213], [707, 303], [360, 640], [640, 200], [400, 250], [380, 250], [400, 200], [280, 200], [280, 230], [360, 180]];
19
+ // Where the HUD must be drawn: the phone and embed sizes. A smaller frame may
20
+ // leave Back and the prompt no room for it, and it is cut, never drawn over them.
21
+ const DRAWN = new Set(['390x844', '844x390', '497x213', '707x303', '360x640', '640x200']);
22
+ // HUDs as the doors send them (hub-tag `hud` through its daily wrapper).
23
+ const HUDS = {
24
+ frozen: { title: 'Tag · 3s freeze', big: "YOU'RE IT", text: 'frozen 2s... · Tag · 3s freeze · 11-19 UTC' },
25
+ playing: { title: 'Tag · least time as IT wins', text: 'Sam is IT (red tag) — keep away! · 3s freeze · 11-19 UTC' },
26
+ winner: { title: 'Nightwatch · lanterns lit', big: 'WINNER', text: 'You made 3 tags · best 3 tags · 12 s as IT · Sam wins' },
27
+ countdown: { title: 'Bumper Ball', big: '3', text: 'Bump the ball into the other goal; first to three wins.' },
28
+ silent: { title: 'Tag · 3s freeze', big: "YOU'RE IT" },
29
+ };
30
+ // Both labels a door's Back shows, with the clear HUD (v1.26) on and off.
31
+ const BACKS = ['Again', 'Back', null];
32
+ const browser = await launchChromium(chromium, { executablePath: process.env.CHROME });
33
+ try {
34
+ const page = await browser.newPage();
35
+ await page.route('**/*', async route => {
36
+ const url = new URL(route.request().url());
37
+ assert.equal(url.origin, 'http://layout.test');
38
+ if (url.pathname === '/') {
39
+ 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>' });
40
+ }
41
+ const file = new URL(`.${url.pathname}`, root);
42
+ assert(fileURLToPath(file).startsWith(fileURLToPath(root)));
43
+ await route.fulfill({ contentType: 'text/javascript', body: await readFile(file, 'utf8') });
44
+ });
45
+ let checks = 0;
46
+ for (const [width, height] of SIZES) {
47
+ await page.setViewportSize({ width, height });
48
+ for (const [name, hud] of Object.entries(HUDS)) {
49
+ for (const [label, clear] of BACKS.flatMap((label) => [[label, true], [label, false]])) {
50
+ await page.goto('http://layout.test/');
51
+ const seen = await page.evaluate(async ({ hud, label, clear }) => {
52
+ const { makeChrome } = await import('/kits/hub-game/code/client/chrome.js');
53
+ const chrome = makeChrome({ avatarCount: 1, onBack() {}, onAvatar() {}, safeInsets: true });
54
+ try {
55
+ chrome.setHudClear(clear);
56
+ if (label) {chrome.showBack(true, label);}
57
+ chrome.setHud(hud, null, 0);
58
+ for (let i = 0; i < 4; i++) {
59
+ chrome.flushSafeInsets();
60
+ await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
61
+ chrome.frameSafeInsets();
62
+ }
63
+ const shown = (node) => {
64
+ for (let p = node; p; p = p.parentElement) {
65
+ const s = getComputedStyle(p);
66
+ if (s.display === 'none' || s.visibility === 'hidden') {return null;}
67
+ }
68
+ const b = node.getBoundingClientRect();
69
+ return b.width > 0 && b.height > 0 ? { left: b.left, top: b.top, right: b.right, bottom: b.bottom } : null;
70
+ };
71
+ const leaf = (text) => [...document.body.querySelectorAll('*')].find((node) => node.children.length === 0 && node.textContent.trim() === text);
72
+ const back = label && [...document.querySelectorAll('button')].find((node) => node.textContent.includes(label));
73
+ const parts = { back: back ? shown(back) : null };
74
+ // The other controls drawn (Quick chat, Emote, Sound ...).
75
+ [...document.querySelectorAll('button')].filter((node) => node !== back && !node.closest('[data-hub="hud-prompt"]')).forEach((node, i) => {
76
+ const box = shown(node);
77
+ if (box && node.offsetParent !== null) {parts[`control ${i} ${node.textContent.trim().slice(0, 12)}`] = box;}
78
+ });
79
+ // A HUD cut to the room left (overflow hidden) shows its lines
80
+ // only inside its own box.
81
+ const clip = (box, node) => {
82
+ const outer = node?.parentElement && shown(node.parentElement);
83
+ if (!box || !outer) {return box;}
84
+ const cut = { left: Math.max(box.left, outer.left), top: Math.max(box.top, outer.top), right: Math.min(box.right, outer.right), bottom: Math.min(box.bottom, outer.bottom) };
85
+ return cut.right > cut.left && cut.bottom > cut.top ? cut : null;
86
+ };
87
+ for (const key of ['title', 'big']) {
88
+ const node = hud[key] && leaf(hud[key]);
89
+ parts[key] = node ? clip(shown(node), node) : null;
90
+ }
91
+ const prompt = document.querySelector('[data-hub="hud-prompt"]');
92
+ parts.prompt = prompt && shown(prompt);
93
+ // A big line broken inside a word: its widest word is wider than
94
+ // the line's content box, while it could still be drawn smaller
95
+ // (16 px is as small as the layout draws it).
96
+ let broken = false;
97
+ const big = hud.big && leaf(hud.big);
98
+ if (big) {
99
+ const s = getComputedStyle(big);
100
+ const ctx = document.createElement('canvas').getContext('2d');
101
+ ctx.font = s.font;
102
+ const widest = Math.max(...hud.big.split(/\s+/).map((word) => ctx.measureText(word).width));
103
+ broken = parseFloat(s.fontSize) > 16 && widest > big.clientWidth - parseFloat(s.paddingLeft) - parseFloat(s.paddingRight) + 0.5;
104
+ }
105
+ return { parts, broken, view: { w: innerWidth, h: innerHeight } };
106
+ } finally {
107
+ chrome.dispose();
108
+ }
109
+ }, { hud, label, clear });
110
+ const where = `${width}x${height} ${name} (${label}${clear ? ', clear HUD' : ''})`;
111
+ const { parts, view } = seen;
112
+ if (label) {assert(parts.back, `${where}: Back is drawn`);}
113
+ if (hud.text) {assert(parts.prompt, `${where}: the prompt is drawn`);}
114
+ for (const key of ['title', 'big']) {
115
+ if (hud[key] && key !== 'big' && DRAWN.has(`${width}x${height}`)) {assert(parts[key], `${where}: the HUD ${key} is drawn`);}
116
+ }
117
+ assert(!seen.broken, `${where}: the big line keeps whole words`);
118
+ const boxes = Object.entries(parts).filter(([, box]) => box);
119
+ for (const [key, box] of boxes) {
120
+ assert(box.left >= -0.5 && box.top >= -0.5 && box.right <= view.w + 0.5 && box.bottom <= view.h + 0.5, `${where}: ${key} inside the frame ${JSON.stringify(box)}`);
121
+ }
122
+ for (let i = 0; i < boxes.length; i++) {
123
+ for (let j = i + 1; j < boxes.length; j++) {
124
+ const [ka, a] = boxes[i], [kb, b] = boxes[j];
125
+ if (ka.startsWith('control') && (kb.startsWith('control') || kb === 'back')) {continue;}
126
+ if (kb.startsWith('control') && ka === 'back') {continue;}
127
+ const hit = a.left < b.right - 0.5 && b.left < a.right - 0.5 && a.top < b.bottom - 0.5 && b.top < a.bottom - 0.5;
128
+ assert(!hit, `${where}: ${ka} ${JSON.stringify(a)} overlaps ${kb} ${JSON.stringify(b)}`);
129
+ }
130
+ }
131
+ checks++;
132
+ }
133
+ }
134
+ }
135
+ console.log(`test-hud-back-dom: ok (${checks} layouts)`);
136
+ } finally {
137
+ await browser.close();
138
+ }
@@ -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(); }
@@ -348,3 +348,16 @@ text (comparing the raw username rebuilt an anonymous player's canvas and textur
348
348
  every frame), and `connection.js`'s `status().you` falls back to the roster entry
349
349
  for the local playerId, so a local player's own tag is not missing while the
350
350
  SDK's `you` is still null.
351
+
352
+ ## Change notes
353
+
354
+ - 2026-11-19 (572b9ab0b): a short away (a frame stall past `STALL_MS`, or an app
355
+ switch under `RESYNC_AWAY_MS` with the socket kept) asks for its resync once the
356
+ page has been shown `RESYNC_QUIET_MS` (250 ms) since it last hid and a drain
357
+ brought nothing current (`ResumeGate.askQuiet`). The session sends nothing on a
358
+ tick where nothing changed, so a still room (Foot Race's start line) used to keep
359
+ the resume cover up until 5 s: black, then "Reconnecting…". A page that hides
360
+ with a resync out asks again on return, and only a WORLD arriving after the latest
361
+ request answers it. Known limit: replies carry no request id, so a late reply to
362
+ an earlier request still counts. No wire change; aways of 5 s or more and dropped
363
+ connections behave as before.
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "castle.physics-3d": {
13
13
  "deckId": "JH0SclbPVP0y",
14
- "version": "2026-11-15T00:45:03.769Z"
14
+ "version": "2026-11-19T11:14:34.739Z"
15
15
  },
16
16
  "castle.physics-2d": {
17
17
  "deckId": "ckRZGFW4iPrx",
@@ -20,13 +20,13 @@
20
20
  },
21
21
  "castle.base": {
22
22
  "deckId": "yRcmH4_aYllE",
23
- "version": "2026-11-15T00:40:25.157Z"
23
+ "version": "2026-11-19T09:37:15.255Z"
24
24
  }
25
25
  },
26
26
  "autoUpdateWhenImported": true,
27
27
  "deckId": "ZwA_P_-VO-Qh",
28
28
  "cardId": "bvRmCzyUpt_a",
29
- "publishedVersion": "2026-11-17T22:31:57.174Z",
29
+ "publishedVersion": "2026-11-19T12:39:24.311Z",
30
30
  "main": "main.jsx",
31
31
  "server": {
32
32
  "main": "code/server/index.js",
@@ -57,6 +57,15 @@ const WORLD = 'w';
57
57
  // ordinary release, as does a session that offers none.
58
58
  export const RESYNC_AWAY_MS = 5000;
59
59
 
60
+ // A session broadcasts nothing on a tick where nothing changed, so a still room
61
+ // (players waiting at a start line) may send no current broadcast at all after
62
+ // a short away: a phone rotation or an arrival hitch past `STALL_MS` then kept
63
+ // the cover up until `RESYNC_AWAY_MS`, black and then 'Reconnecting…'. A shorter
64
+ // away is asked for its resync once the page has been shown this long, without
65
+ // hiding, and a whole drain still brought nothing current (`askQuiet`); a busy
66
+ // room's next broadcast releases it well before.
67
+ export const RESYNC_QUIET_MS = 250;
68
+
60
69
  // A socket can read connected and carry nothing after an away. A resync left
61
70
  // unanswered this long asks the transport to recover instead of waiting for
62
71
  // its keepalive deadline.
@@ -69,9 +78,13 @@ export const RESYNC_REPLY_MS = 3000;
69
78
  // it was seen not connected, `backAt` when it came back after that, and
70
79
  // `asked` whether a resync was asked for (`ask`), `askedAt` the page time then,
71
80
  // `replyExpired` whether its unanswered reply has been reported, and `hiddenAt`
72
- // the page time the page hid with a resync out (`suspendReply`).
81
+ // the page time the page hid with a resync out (`suspendReply`). `visibleAt` is
82
+ // the first frame of the page's current showing (cleared by a hide), `replyAfter`
83
+ // the page time of the latest resync sent, which only a WORLD arriving after
84
+ // answers, and `reask` whether the page hid with a resync out, so its return
85
+ // asks again.
73
86
  export function makeGate() {
74
- return { armed: false, since: 0, serverAt: null, shownAt: null, dropped: false, lostAt: null, backAt: null, asked: false, askedAt: null, replyExpired: false, hiddenAt: null, pausedAt: null };
87
+ return { armed: false, since: 0, serverAt: null, shownAt: null, dropped: false, lostAt: null, backAt: null, asked: false, askedAt: null, replyExpired: false, hiddenAt: null, pausedAt: null, visibleAt: null, replyAfter: null, reask: false };
75
88
  }
76
89
 
77
90
  // Arm the gate for an away that began at page time `since`, when the server's
@@ -93,6 +106,9 @@ export function arm(gate, since, serverAt) {
93
106
  gate.replyExpired = false;
94
107
  gate.hiddenAt = null;
95
108
  gate.pausedAt = null;
109
+ gate.visibleAt = null;
110
+ gate.replyAfter = null;
111
+ gate.reask = false;
96
112
  return true;
97
113
  }
98
114
 
@@ -108,17 +124,49 @@ export function clear(gate) {
108
124
  gate.replyExpired = false;
109
125
  gate.hiddenAt = null;
110
126
  gate.pausedAt = null;
127
+ gate.visibleAt = null;
128
+ gate.replyAfter = null;
129
+ gate.reask = false;
111
130
  }
112
131
 
113
- // Whether to ask for a resync now, at page time `now`: once per away, an away
114
- // of at least `RESYNC_AWAY_MS` over a connection that never dropped (one that
115
- // dropped is sent a WORLD anyway). Marks the gate asked when it says yes.
132
+ // Whether to ask for a resync now, at page time `now`, before a drain: once per
133
+ // away of at least `RESYNC_AWAY_MS` over a connection that never dropped (one
134
+ // that dropped is sent a WORLD anyway), and again after the page hid with one
135
+ // out, since a reply that came while hidden may be followed by dropped frames.
136
+ // Marks the gate asked when it says yes.
116
137
  export function ask(gate, now) {
117
- if (!gate.armed || gate.dropped || gate.asked || now - gate.since < RESYNC_AWAY_MS) {
138
+ if (!gate.armed || gate.dropped) {
139
+ return false;
140
+ }
141
+ if (gate.asked) {
142
+ if (!gate.reask) {
143
+ return false;
144
+ }
145
+ gate.reask = false;
146
+ gate.replyAfter = now;
147
+ return true;
148
+ }
149
+ if (now - gate.since < RESYNC_AWAY_MS) {
118
150
  return false;
119
151
  }
152
+ return asking(gate, now);
153
+ }
154
+
155
+ // Whether to ask for a resync now, at page time `now`, after a drain that left
156
+ // the gate armed: a shorter away over a connection that never dropped, whose
157
+ // page has been shown for `RESYNC_QUIET_MS` since it last hid. A still room
158
+ // sends no broadcast to release it.
159
+ export function askQuiet(gate, now) {
160
+ if (!gate.armed || gate.dropped || gate.asked || gate.visibleAt === null || now - gate.visibleAt < RESYNC_QUIET_MS) {
161
+ return false;
162
+ }
163
+ return asking(gate, now);
164
+ }
165
+
166
+ function asking(gate, now) {
120
167
  gate.asked = true;
121
168
  gate.askedAt = now;
169
+ gate.replyAfter = now;
122
170
  return true;
123
171
  }
124
172
 
@@ -137,8 +185,17 @@ export function unanswered(gate, now, limit) {
137
185
  // be drained while hidden, so the reply wait and the give-up both count visible
138
186
  // time only: `resumeReply` moves them on by the time away. Neither restarts, so
139
187
  // a page that keeps hiding still reaches both.
188
+ // The page hiding also ends its current showing (`askQuiet` counts from the
189
+ // next), and a resync out is asked again on the return (`ask`).
140
190
  export function suspendReply(gate, now) {
141
- if (gate.armed && gate.asked && gate.hiddenAt === null) {
191
+ if (!gate.armed) {
192
+ return;
193
+ }
194
+ gate.visibleAt = null;
195
+ if (gate.asked) {
196
+ gate.reask = true;
197
+ }
198
+ if (gate.asked && gate.hiddenAt === null) {
142
199
  gate.hiddenAt = now;
143
200
  }
144
201
  }
@@ -189,8 +246,12 @@ export function current(gate, msg) {
189
246
  if (gate.dropped) {
190
247
  return msg.k === WORLD && gate.backAt !== null && msg.localMs >= gate.backAt;
191
248
  }
249
+ // Asked for a resync, only a WORLD after the latest request answers it.
250
+ // Known limit: a reply carries no request id, so a reply to an earlier
251
+ // request that is delivered late (after a hide's re-ask) still counts. Closing
252
+ // that needs the session to echo a request id: a wire change.
192
253
  if (msg.k === WORLD) {
193
- return true;
254
+ return !gate.asked || msg.localMs >= gate.replyAfter;
194
255
  }
195
256
  // A resync was asked for: no broadcast can say what the dropped ones did.
196
257
  if (gate.asked) {
@@ -227,5 +288,6 @@ export function waited(gate, now, visible) {
227
288
  gate.pausedAt = null;
228
289
  }
229
290
  gate.shownAt ??= now;
291
+ gate.visibleAt ??= now;
230
292
  return now - gate.shownAt > RESUME_WAIT_MS;
231
293
  }
@@ -918,6 +918,9 @@ class MultiplayerSystem {
918
918
  }
919
919
  if (fresh) {
920
920
  this.resumed();
921
+ } else if (resuming && this.resyncs && ResumeGate.askQuiet(this.resume, performance.now())) {
922
+ // After the drain, so a current broadcast already queued releases first.
923
+ this.net.send({ k: RESYNC });
921
924
  }
922
925
  this.placeGrants(scene);
923
926
  }