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
|
@@ -82,9 +82,12 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
82
82
|
}
|
|
83
83
|
let canvasSource = null;
|
|
84
84
|
let safeLayout = null;
|
|
85
|
+
// The prompt's words and display the safe layout last placed (`setHud`).
|
|
86
|
+
let promptPlaced = null;
|
|
85
87
|
let worldLayout = null;
|
|
86
88
|
let worldViewport = null;
|
|
87
89
|
let worldAvatar = null;
|
|
90
|
+
let worldNameTags = null;
|
|
88
91
|
// The avatar box snapped outward to 16 px, so a walking player does not
|
|
89
92
|
// re-solve or shuffle the action rail every frame.
|
|
90
93
|
let avatarReserve = null;
|
|
@@ -1064,13 +1067,22 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1064
1067
|
let hudClear = false;
|
|
1065
1068
|
let hudClearDrawn = false;
|
|
1066
1069
|
let hudClearKey = '';
|
|
1070
|
+
let hudCall = 0;
|
|
1071
|
+
let hudNumberFitKey = '';
|
|
1072
|
+
let hudNumberFitPx = 56;
|
|
1073
|
+
let hudNumberFitPending = false;
|
|
1074
|
+
let hudNumberFitWrittenAt = 0;
|
|
1075
|
+
const hudNumber = () => hudBig.dataset.hubSingleLine === '1';
|
|
1076
|
+
const numberShape = (text) => text.replace(/[0-9]/g, '0');
|
|
1077
|
+
const hudBigKey = () => hudNumber() ? numberShape(hudBig.textContent) : hudBig.textContent;
|
|
1067
1078
|
// The place before asked and this one does not: the styles of old, put
|
|
1068
1079
|
// back the moment the option goes, whether or not a HUD is drawn after.
|
|
1069
1080
|
function restoreHudClear() {
|
|
1070
1081
|
hudBig.style.fontSize = '56px';
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1082
|
+
hudBig.style.whiteSpace = hudNumber() ? 'nowrap' : '';
|
|
1083
|
+
hudBig.style.overflow = hudNumber() ? 'hidden' : '';
|
|
1084
|
+
hudBig.style.textOverflow = hudNumber() ? 'ellipsis' : '';
|
|
1085
|
+
hudNumberFitKey = '';
|
|
1074
1086
|
hudBig.style.maxWidth = '100%';
|
|
1075
1087
|
hud.style.maxHeight = '';
|
|
1076
1088
|
hud.style.overflow = '';
|
|
@@ -1116,7 +1128,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1116
1128
|
const column = [sayButton, emoteButton, grabButton, sound?.button]
|
|
1117
1129
|
.filter((node) => node && node.style.display !== 'none').map((node) => geometry.rect(node)).filter((box) => box.width > 0 && box.height > 0);
|
|
1118
1130
|
const backBox = back.style.display !== 'none' ? geometry.rect(back) : null;
|
|
1119
|
-
const key = shown ? [hudTitle.textContent,
|
|
1131
|
+
const key = shown ? [hudTitle.textContent, hudBigKey(), hudNumber(), view.w, view.h,
|
|
1120
1132
|
...[...column, ...(backBox ? [backBox] : [])].flatMap((box) => [box.left, box.top, box.right, box.bottom])].join('\u0001') : '';
|
|
1121
1133
|
if (key !== hudLaneKey) {
|
|
1122
1134
|
hudLaneKey = key;
|
|
@@ -1135,7 +1147,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1135
1147
|
hud.style.maxWidth = `${width}px`;
|
|
1136
1148
|
// The HUD is centred on the view; centre it on the lane instead.
|
|
1137
1149
|
hud.style.translate = `${Math.round(left + width / 2 - view.w / 2)}px 0px`;
|
|
1138
|
-
if (!hudClear) {
|
|
1150
|
+
if (!hudClear && !hudNumber()) {
|
|
1139
1151
|
writeHudBig('whiteSpace', 'nowrap');
|
|
1140
1152
|
writeHudBig('overflow', 'hidden');
|
|
1141
1153
|
writeHudBig('textOverflow', 'ellipsis');
|
|
@@ -1148,7 +1160,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1148
1160
|
if (hudClear && hudBig.style.maxWidth.endsWith('px') && Number.parseFloat(hudBig.style.maxWidth) > hudLaneWritten.width) {
|
|
1149
1161
|
writeHudBig('maxWidth', `${hudLaneWritten.width}px`);
|
|
1150
1162
|
}
|
|
1151
|
-
if (!hudClear) {
|
|
1163
|
+
if (!hudClear && !hudNumber()) {
|
|
1152
1164
|
const fit = geometry.fit(hudBig);
|
|
1153
1165
|
if (fit.text === hudBig.textContent && (fit.fontSize === hudBig.style.fontSize || !hudBig.style.fontSize)) {
|
|
1154
1166
|
const base = Number.parseFloat(fit.fontSize) || 56;
|
|
@@ -1157,11 +1169,41 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1157
1169
|
}
|
|
1158
1170
|
}
|
|
1159
1171
|
}
|
|
1172
|
+
function fitHudNumber(base, snapshot) {
|
|
1173
|
+
if (!hudNumber() || !hudBig.textContent) {
|
|
1174
|
+
if (hudNumberFitKey && !hudClear) {hudBig.style.fontSize = '56px';}
|
|
1175
|
+
hudNumberFitKey = '';
|
|
1176
|
+
hudNumberFitPending = false;
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
const view = geometry.view();
|
|
1180
|
+
const safeWidth = typeof hudBig.style.getPropertyValue === 'function' ? hudBig.style.getPropertyValue('--hub-safe-max-width') : '';
|
|
1181
|
+
const shape = numberShape(hudBig.textContent);
|
|
1182
|
+
const key = [shape, base, view.w, view.h, hud.style.maxWidth, hudBig.style.maxWidth, geometry.fontEpoch(), safeWidth].join('\u0001');
|
|
1183
|
+
if (key !== hudNumberFitKey) {
|
|
1184
|
+
hudNumberFitKey = key;
|
|
1185
|
+
hudNumberFitPx = base;
|
|
1186
|
+
hudNumberFitPending = true;
|
|
1187
|
+
hudNumberFitWrittenAt = hudCall;
|
|
1188
|
+
}
|
|
1189
|
+
// The sample predates this call's lane and font writes. Tabular digits
|
|
1190
|
+
// let a later sample measure the same shape even as the clock ticks.
|
|
1191
|
+
if (hudNumberFitPending && hudCall > hudNumberFitWrittenAt && snapshot?.client > 0
|
|
1192
|
+
&& snapshot.fontSize === `${hudNumberFitPx}px` && numberShape(snapshot.text) === shape) {
|
|
1193
|
+
if (snapshot.scroll > snapshot.client) {hudNumberFitPx = fitPx(hudNumberFitPx, snapshot.client - 16, snapshot.scroll - 8);}
|
|
1194
|
+
hudNumberFitPending = false;
|
|
1195
|
+
}
|
|
1196
|
+
const fontSize = `${hudNumberFitPx}px`;
|
|
1197
|
+
if (hudBig.style.fontSize !== fontSize) {
|
|
1198
|
+
hudBig.style.fontSize = fontSize;
|
|
1199
|
+
hudNumberFitWrittenAt = hudCall;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1160
1202
|
function layoutHudClear(big, text) {
|
|
1161
1203
|
hudClearDrawn = true;
|
|
1162
1204
|
const backShown = back.style.display !== 'none';
|
|
1163
1205
|
const backBox = geometry.rect(back);
|
|
1164
|
-
const key = [hudTitle.textContent,
|
|
1206
|
+
const key = [hudTitle.textContent, hudBigKey(), hudNumber(), text, geometry.view().w, geometry.view().h, backShown ? back.textContent : '', backBox.left, backBox.right].join('\u0001');
|
|
1165
1207
|
const layout = hudLayout({
|
|
1166
1208
|
big,
|
|
1167
1209
|
text,
|
|
@@ -1172,15 +1214,17 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1172
1214
|
});
|
|
1173
1215
|
if (key !== hudClearKey) {
|
|
1174
1216
|
hudClearKey = key;
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
hudBig.style.
|
|
1178
|
-
hudBig.style.
|
|
1217
|
+
// Numeric font sizing belongs to fitHudNumber, including when only
|
|
1218
|
+
// the title or Back geometry changed.
|
|
1219
|
+
if (!hudNumber()) {hudBig.style.fontSize = `${layout.bigPx}px`;}
|
|
1220
|
+
hudBig.style.whiteSpace = layout.bigOneLine || hudNumber() ? 'nowrap' : '';
|
|
1221
|
+
hudBig.style.overflow = layout.bigOneLine || hudNumber() ? 'hidden' : '';
|
|
1222
|
+
hudBig.style.textOverflow = layout.bigOneLine || hudNumber() ? 'ellipsis' : '';
|
|
1179
1223
|
hudBig.style.maxWidth = layout.bigMaxWidth === null ? '100%' : `${layout.bigMaxWidth}px`;
|
|
1180
1224
|
hud.style.maxHeight = layout.maxHeight === null ? '' : `${layout.maxHeight}px`;
|
|
1181
1225
|
hud.style.overflow = layout.maxHeight === null ? '' : 'hidden';
|
|
1182
1226
|
}
|
|
1183
|
-
if (layout.bigOneLine) {
|
|
1227
|
+
if (layout.bigOneLine && !hudNumber()) {
|
|
1184
1228
|
const fit = geometry.fit(hudBig);
|
|
1185
1229
|
if (!geometry.active() || (fit.text === String(big) && fit.fontSize === hudBig.style.fontSize)) {
|
|
1186
1230
|
const base = Number.parseFloat(fit.fontSize) || layout.bigPx;
|
|
@@ -1188,6 +1232,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1188
1232
|
if (px < base) {hudBig.style.fontSize = `${px}px`;}
|
|
1189
1233
|
}
|
|
1190
1234
|
}
|
|
1235
|
+
return layout.bigPx;
|
|
1191
1236
|
}
|
|
1192
1237
|
// What a frame's setters ask to be kept clear of the HUD, by group
|
|
1193
1238
|
// ("labels", "roles", "pointers", "cabinet", "ribbon"): each entry is [node, x, y,
|
|
@@ -1883,7 +1928,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1883
1928
|
worldLabelsDefault = on;
|
|
1884
1929
|
// The root town retains its explicit near selection; its selected text
|
|
1885
1930
|
// still needs the same final HUD/control/avatar clearance as doors.
|
|
1886
|
-
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry, (node) => safeLayout?.heldAct?.(node) ?? null);
|
|
1931
|
+
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry, (node) => safeLayout?.heldAct?.(node) ?? null, () => worldNameTags);
|
|
1887
1932
|
},
|
|
1888
1933
|
// An avatar crossing the camera's near plane has no reliable screen box
|
|
1889
1934
|
// (and may be hidden by the renderer's first-person view).
|
|
@@ -1896,6 +1941,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1896
1941
|
},
|
|
1897
1942
|
worldAvatar: () => worldAvatar,
|
|
1898
1943
|
setWorldViewport: (area) => {worldViewport = area;},
|
|
1944
|
+
setWorldNameTags: (boxes) => {worldNameTags = boxes;},
|
|
1899
1945
|
beginWorldLabels: () => worldLayout?.begin(true),
|
|
1900
1946
|
flushWorldLabels: () => worldLayout?.flush(),
|
|
1901
1947
|
setMenu, clearMenu,
|
|
@@ -2226,16 +2272,30 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2226
2272
|
// since/until), not ten times a second, and the page ticks it here, each
|
|
2227
2273
|
// frame, at `simNow`.
|
|
2228
2274
|
setHud(spec, timerSeconds, simNow) {
|
|
2275
|
+
hudCall += 1;
|
|
2229
2276
|
if (!spec) {
|
|
2230
2277
|
hudSurface.setHud(null);
|
|
2278
|
+
// Hidden, the safe layout may let go of its width: the same words
|
|
2279
|
+
// shown again are placed again.
|
|
2280
|
+
promptPlaced = null;
|
|
2231
2281
|
return;
|
|
2232
2282
|
}
|
|
2283
|
+
const numberFit = geometry.active() || hudNumberFitPending ? geometry.fit(hudBig) : null;
|
|
2233
2284
|
const { big, clock } = hudSurface.setHud(spec, timerSeconds, simNow);
|
|
2234
2285
|
if (clock && uiTreeDomEnabled()) {hudDom.tick();}
|
|
2235
|
-
|
|
2236
|
-
|
|
2286
|
+
// A prompt shown or reworded is placed in this frame: upright it may be
|
|
2287
|
+
// as wide as the row until the safe layout narrows it beside the
|
|
2288
|
+
// control column, and the layout's own pass can be 500 ms away.
|
|
2289
|
+
if (safeLayout) {
|
|
2290
|
+
const promptKey = `${hudText.style.display}\u0001${hudText.textContent}`;
|
|
2291
|
+
if (promptKey !== promptPlaced) {
|
|
2292
|
+
promptPlaced = promptKey;
|
|
2293
|
+
safeLayout.flush();
|
|
2294
|
+
}
|
|
2237
2295
|
}
|
|
2296
|
+
const bigPx = hudClear ? layoutHudClear(big, spec.text ?? '') : 56;
|
|
2238
2297
|
layoutHudLane();
|
|
2298
|
+
fitHudNumber(bigPx, numberFit);
|
|
2239
2299
|
if (import.meta.env?.DEV) {
|
|
2240
2300
|
warnHudCopy(hudTitle, 'subtitle');
|
|
2241
2301
|
warnHudCopy(hudText, 'prompt', 1);
|
|
@@ -2368,22 +2428,21 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2368
2428
|
: node.dataset.hub === 'action-rail' ? [node] : []);
|
|
2369
2429
|
return [...actionControls, hud, hudText, askCard, back, sound?.button, sound?.card, toast, stats, talkButton, sitButton, nearButton, panel, dock, doorsList, peopleList, picker, grabButton, emoteButton, emoteRow, sayButton, sayCard, actionChips, stuckChip, decorButton, cabinet, ribbon].map(shownRect).filter(Boolean);
|
|
2370
2430
|
},
|
|
2371
|
-
//
|
|
2372
|
-
//
|
|
2373
|
-
syncRoleLabels(items, keepPlayerId = null, position = true) {
|
|
2431
|
+
// Role chips and marks follow the final name positions and visibility.
|
|
2432
|
+
// Repositioned chips must clear the HUD again.
|
|
2433
|
+
syncRoleLabels(items, keepPlayerId = null, position = true, prefix = 'role:') {
|
|
2374
2434
|
const shown = new Map(items.map((item) => [item.id, item]));
|
|
2375
2435
|
const entries = [];
|
|
2376
2436
|
for (const [id, node] of labelNodes) {
|
|
2377
|
-
if (!id.startsWith(
|
|
2437
|
+
if (!id.startsWith(prefix)) {
|
|
2378
2438
|
continue;
|
|
2379
2439
|
}
|
|
2380
2440
|
const item = shown.get(id);
|
|
2381
|
-
if (!item && id ===
|
|
2441
|
+
if (!item && id === `${prefix}${keepPlayerId}`) {
|
|
2382
2442
|
continue;
|
|
2383
2443
|
}
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
} else if (position) {
|
|
2444
|
+
node.style.display = item ? '' : 'none';
|
|
2445
|
+
if (item && position) {
|
|
2387
2446
|
node.style.left = `${item.x}px`;
|
|
2388
2447
|
node.style.top = `${item.y}px`;
|
|
2389
2448
|
node.style.opacity = String(item.opacity ?? 1);
|
|
@@ -2403,7 +2462,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2403
2462
|
.filter(([id]) => id !== 'crowd:summary')
|
|
2404
2463
|
.map(([id, node]) => {
|
|
2405
2464
|
const box = shownRect(node);
|
|
2406
|
-
return box &&
|
|
2465
|
+
return box && { left: box.left, right: box.right, top: box.top, bottom: box.bottom,
|
|
2466
|
+
...(node.dataset.tagPlayerId === undefined ? {} : { tagPlayerId: node.dataset.tagPlayerId }),
|
|
2467
|
+
...(node.worldDepth === undefined ? {} : { depth: node.worldDepth }) };
|
|
2407
2468
|
})
|
|
2408
2469
|
.filter(Boolean);
|
|
2409
2470
|
},
|
|
@@ -2447,7 +2508,12 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2447
2508
|
node = el('div', { position: 'absolute', transform: 'translate(-50%, -100%)', padding: '4px 10px', borderRadius: '12px', background: 'rgba(15,12,10,0.7)', whiteSpace: 'nowrap', fontSize: '14px' }, labels);
|
|
2448
2509
|
labelNodes.set(item.id, node);
|
|
2449
2510
|
}
|
|
2450
|
-
|
|
2511
|
+
node.worldDepth = item.depth;
|
|
2512
|
+
if (item.id.startsWith('role:') || item.id.startsWith('mark:')) {
|
|
2513
|
+
node.dataset.tagPlayerId = item.id.slice(5);
|
|
2514
|
+
// The viewer's own mark steps down clear of the HUD (`dropSlot`).
|
|
2515
|
+
if (item.own) {node.dataset.ownMark = '1';} else {delete node.dataset.ownMark;}
|
|
2516
|
+
node.style.display = '';
|
|
2451
2517
|
node.style.visibility = '';
|
|
2452
2518
|
}
|
|
2453
2519
|
// An NPC's line is kept on screen: a reply over one at the edge of the
|
|
@@ -3458,7 +3524,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
3458
3524
|
// A role chip belongs under its name tag, and a place's tag (`hub.mark`) over a head,
|
|
3459
3525
|
// the viewer's own included; both are drawn over the viewer's body anyway. So is
|
|
3460
3526
|
// an NPC's line, Chirp's included, said from the viewer's shoulder.
|
|
3461
|
-
ignoreObstacle:
|
|
3527
|
+
ignoreObstacle: node.dataset.tagPlayerId || npcSpeech.has(id) ? worldAvatar : null, clamp: clampLabels.has(id), edge: npcSpeech.has(id), drop: node.dataset.ownMark === '1',
|
|
3528
|
+
depth: node.worldDepth, tagPlayerId: node.dataset.tagPlayerId })),
|
|
3462
3529
|
...[...pointerNodes].map(([id, item]) => surface(`pointer:${id}`, item.chip, 'pointer', true)),
|
|
3463
3530
|
...externalEntries().map(([id, item]) => ({ ...surface(id, item.node, item.kind, item.kind === 'text'), ...item.placement, ...(id === 'engine-shift-lock' ? { stack: 4 } : {}) })),
|
|
3464
3531
|
...(actionOverflow?.surfaces?.() ?? []).map((node, i) => surface(`action-overflow:${i}`, node, 'control')),
|
|
@@ -3475,7 +3542,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
3475
3542
|
for (const child of entry.reportNodes?.() ?? []) {geometry.register(child.node);}
|
|
3476
3543
|
}
|
|
3477
3544
|
if (worldLabelsDefault) {
|
|
3478
|
-
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry, (node) => safeLayout?.heldAct?.(node) ?? null);
|
|
3545
|
+
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry, (node) => safeLayout?.heldAct?.(node) ?? null, () => worldNameTags);
|
|
3479
3546
|
}
|
|
3480
3547
|
if (safeInsets) {
|
|
3481
3548
|
safeLayout = makeSafeLayout({ root, hud: () => hud, entries: surfaces, onLayout: () => {
|
|
@@ -140,12 +140,13 @@ export function layoutCrowdNames(state, candidates, { now, view, obstacles = []
|
|
|
140
140
|
const limit = tiny ? 0 : dense ? 2 : 1;
|
|
141
141
|
let used = 0;
|
|
142
142
|
for (const candidate of group) {
|
|
143
|
-
const
|
|
143
|
+
const blocks = (box, gap) => box.tagPlayerId !== candidate.id && !(box.depth > candidate.box.depth) && touches(candidate.box, box, gap);
|
|
144
|
+
const blocked = obstacles.some((box) => blocks(box, 0));
|
|
144
145
|
const conflicts = chosenBoxes.some((box) => touches(candidate.box, box));
|
|
145
146
|
let allowed = used < limit && !blocked && !conflicts;
|
|
146
147
|
let waiting = false;
|
|
147
148
|
if (allowed && state.suppressed.has(candidate.id)) {
|
|
148
|
-
const separated = !obstacles.some((box) =>
|
|
149
|
+
const separated = !obstacles.some((box) => blocks(box, RESTORE_PX)) &&
|
|
149
150
|
!chosenBoxes.some((box) => touches(candidate.box, box, RESTORE_PX));
|
|
150
151
|
if (!separated) {
|
|
151
152
|
state.clearSince.delete(candidate.id);
|
|
@@ -17,9 +17,13 @@
|
|
|
17
17
|
// }
|
|
18
18
|
import { h } from './uiTree.js';
|
|
19
19
|
|
|
20
|
+
const isHudNumber = (text) => /^[+-]?\d+(?:[.,:]\d+)*%?$/.test(text);
|
|
21
|
+
|
|
20
22
|
// HUD_COPY_STYLE (`hudCopy.js`) as tree style: a pill as wide as its words,
|
|
21
23
|
// at most its column, centred, wrapping anywhere.
|
|
22
24
|
const COPY = { bg: 'copy', radius: 14, pad: [4, 8], box: 'border', w: 'wrap', maxW: '100%', self: 'center', lh: 1.3, wrap: ['word', 'anywhere'] };
|
|
25
|
+
// The prompt's row: the view less 16 px (or the safe area) at each side.
|
|
26
|
+
const PROMPT_ROW = { vw: 100, sub: { l: 16, r: 16 } };
|
|
23
27
|
// An edge kept clear of the safe area only where the place asks for it.
|
|
24
28
|
const edge = (safeInsets, px) => (safeInsets ? [px, 0] : px);
|
|
25
29
|
|
|
@@ -59,6 +63,7 @@ export function buildHud(state) {
|
|
|
59
63
|
const toast = state.toast ?? {};
|
|
60
64
|
const big = hud.big ?? '';
|
|
61
65
|
const clock = hud.clock ? { gen: hud.clock.gen, t0: hud.clock.t0, v0: hud.clock.v0, rate: hud.clock.rate, fmt: 's.1', min: 0 } : null;
|
|
66
|
+
const numeric = Boolean(clock) || isHudNumber(big);
|
|
62
67
|
const toastText = toast.text ?? '';
|
|
63
68
|
const wrapToast = Boolean(toastText && toast.wrap);
|
|
64
69
|
return h('stack', { key: 'hud', style: { font: 'ui', size: 15, weight: 600, lh: 1.3, color: '#fff' } },
|
|
@@ -71,7 +76,7 @@ export function buildHud(state) {
|
|
|
71
76
|
h('column', {
|
|
72
77
|
key: 'hud',
|
|
73
78
|
at: { anchor: 'top', top: [12, 0] },
|
|
74
|
-
style: { maxW: landscape ? [{ vw: 42 }, { px: 420 }] : [{ vw: 70 }], talign: 'center', tshadow: 'outline', gone: !hud.show },
|
|
79
|
+
style: { w: 'wrap', maxW: landscape ? [{ vw: 42 }, { px: 420 }] : [{ vw: 70 }], talign: 'center', tshadow: 'outline', gone: !hud.show },
|
|
75
80
|
},
|
|
76
81
|
h('text', {
|
|
77
82
|
key: 'title', data: { hubCopy: 'subtitle' }, text: hud.title ?? '',
|
|
@@ -79,13 +84,20 @@ export function buildHud(state) {
|
|
|
79
84
|
}),
|
|
80
85
|
// The big line sits 4 px under the title (and 4 px down without one).
|
|
81
86
|
h('text', {
|
|
82
|
-
key: 'big', ...(clock ? { clock } : { text: big }),
|
|
83
|
-
style: { bg: 'copy', radius: 14, pad: [0, 8], box: 'border', w: 'wrap', maxW: '100%', self: 'center', mt: 4,
|
|
87
|
+
key: 'big', ...(clock ? { clock } : { text: big }), ...(numeric ? { data: { hubSingleLine: '1' } } : {}),
|
|
88
|
+
style: { bg: 'copy', radius: 14, pad: [0, 8], box: 'border', w: 'wrap', maxW: '100%', self: 'center', mt: 4,
|
|
89
|
+
...(numeric ? { wrap: 'none', lines: 1, tabular: true } : { wrap: 'anywhere' }), size: 56, weight: 800, lh: 1.05, gone: !big && !clock },
|
|
84
90
|
})),
|
|
85
91
|
h('text', {
|
|
86
92
|
key: 'prompt', hub: 'hud-prompt', data: { hubCopy: 'instruction' }, text: hud.prompt ?? '',
|
|
87
93
|
at: { anchor: 'bottom', bottom: [54, 48], left: [16, 0], right: [16, 0], z: 2 },
|
|
88
|
-
|
|
94
|
+
// The prompt keeps to 60% of the width, except upright where the safe
|
|
95
|
+
// layout places it (`hub.safeInsets`, or Act): there it may take the
|
|
96
|
+
// whole row, and the safe layout narrows it to the lane beside the
|
|
97
|
+
// control column. 60% of a 390 px phone is 234 px, and a 48-character
|
|
98
|
+
// sentence wrapped there on most doors. Without the safe layout
|
|
99
|
+
// nothing would move it off Grab or the column, so it keeps the cap.
|
|
100
|
+
style: { ...COPY, size: 14, weight: 500, clip: false, maxW: !landscape && safeInsets ? [{ px: 560 }, PROMPT_ROW] : [{ vw: 60 }, { px: 560 }, PROMPT_ROW], talign: 'center', gone: !hud.promptShown },
|
|
89
101
|
}),
|
|
90
102
|
h('text', {
|
|
91
103
|
key: 'toast', hub: 'toast', text: toastText,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const EDGE_MARGIN = 8;
|
|
2
|
+
|
|
3
|
+
// Three's name sprites are centered billboards. A name any part of which is
|
|
4
|
+
// in the view slides wholly inside it (a player at the edge usually has its
|
|
5
|
+
// tag's centre just past it: the reported "728" of a cut name). One wholly
|
|
6
|
+
// outside, or whose centre is above or below the view, stays where it is.
|
|
7
|
+
export function nameTagShift(box, area) {
|
|
8
|
+
const y = (box.top + box.bottom) / 2;
|
|
9
|
+
if (box.right <= area.left || box.left >= area.right || y < area.top || y > area.bottom) {return 0;}
|
|
10
|
+
const min = area.left + EDGE_MARGIN - box.left;
|
|
11
|
+
const max = area.right - EDGE_MARGIN - box.right;
|
|
12
|
+
if (min > max) {return 0;}
|
|
13
|
+
return Math.max(min, Math.min(0, max));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Project the billboard at its actual pose. In view space both edges are
|
|
17
|
+
// at the center's depth, so the same pixel scale converts the inward shift
|
|
18
|
+
// back to world units along camera right. The caller reuses point and box.
|
|
19
|
+
export function projectNameTag(sprite, cam, area, point, box) {
|
|
20
|
+
point.copy(sprite.position).applyMatrix4(cam.matrixWorldInverse);
|
|
21
|
+
if (point.z >= 0) {return null;}
|
|
22
|
+
const p = cam.projectionMatrix.elements;
|
|
23
|
+
const w = p[3] * point.x + p[7] * point.y + p[11] * point.z + p[15];
|
|
24
|
+
point.applyMatrix4(cam.projectionMatrix);
|
|
25
|
+
if (!(point.z >= -1 && point.z <= 1)) {return null;}
|
|
26
|
+
const scaleX = (p[0] * area.width) / (2 * w);
|
|
27
|
+
const scaleY = (p[5] * area.height) / (2 * w);
|
|
28
|
+
const x = area.left + (point.x + 1) * area.width / 2;
|
|
29
|
+
const y = area.top + (1 - point.y) * area.height / 2;
|
|
30
|
+
const halfW = Math.abs(sprite.scale.x * scaleX) / 2;
|
|
31
|
+
const halfH = Math.abs(sprite.scale.y * scaleY) / 2;
|
|
32
|
+
box.left = x - halfW; box.right = x + halfW;
|
|
33
|
+
box.top = y - halfH; box.bottom = y + halfH;
|
|
34
|
+
box.depth = point.z;
|
|
35
|
+
const shift = nameTagShift(box, area);
|
|
36
|
+
if (shift) {
|
|
37
|
+
const right = cam.matrixWorld.elements;
|
|
38
|
+
const dx = shift / scaleX;
|
|
39
|
+
sprite.position.x += dx * right[0];
|
|
40
|
+
sprite.position.y += dx * right[1];
|
|
41
|
+
sprite.position.z += dx * right[2];
|
|
42
|
+
box.left += shift;
|
|
43
|
+
box.right += shift;
|
|
44
|
+
}
|
|
45
|
+
return box;
|
|
46
|
+
}
|
|
@@ -69,11 +69,13 @@ export function roleItems(scene, local, cam, view, roles, project) {
|
|
|
69
69
|
// over that body. Other players follow the name's distance/crowd hide.
|
|
70
70
|
if (playerId !== self && tag && (!tag.visible || !(tag.material?.opacity > 0))) { continue; }
|
|
71
71
|
const at = visible ? (playerId === self ? local : scene.getActor(actorId))?.components?.Transform : null;
|
|
72
|
-
const
|
|
72
|
+
const tagAt = playerId !== self ? tag?.position : null;
|
|
73
|
+
const x = tagAt?.x ?? at?.x, y = tagAt?.y ?? (at?.y + 1.25), z = tagAt?.z ?? at?.z;
|
|
74
|
+
const screen = at ? project(cam, x, y, z, view) : null;
|
|
73
75
|
if (screen) {
|
|
74
76
|
const up = cam?.matrixWorld?.elements;
|
|
75
77
|
const half = Math.abs(tag?.scale?.y ?? 0) / 2;
|
|
76
|
-
const bottom = up && half ? project(cam,
|
|
78
|
+
const bottom = up && half ? project(cam, x - up[4] * half, y - up[5] * half, z - up[6] * half, view) : null;
|
|
77
79
|
// Marks' pill is about 30 px high including its border; leave 4 px.
|
|
78
80
|
out.push({ id: `role:${playerId}`, x: screen.x, y: (bottom?.y ?? screen.y + 15) + 34, text: role.label, color: role.color, opacity: playerId === self ? 1 : tag?.material?.opacity ?? 1 });
|
|
79
81
|
}
|
|
@@ -649,6 +649,7 @@ export function makeSafeLayout({ root, entries, view = globalThis.window, hud =
|
|
|
649
649
|
// The clear-HUD path may have clamped or ellipsized an inner line.
|
|
650
650
|
// The opted-in rule keeps those words reachable instead.
|
|
651
651
|
write(child, 'maxWidth', `${placed.w}px`);
|
|
652
|
+
if (child.dataset?.hubSingleLine) {continue;}
|
|
652
653
|
write(child, 'whiteSpace', 'normal');
|
|
653
654
|
write(child, 'overflowWrap', 'anywhere');
|
|
654
655
|
// Copy rows own their two-line clipping and empty-row visibility.
|
|
@@ -35,7 +35,7 @@ export function relevantLabels(state, items, view, now) {
|
|
|
35
35
|
// Over its own Talk prompt, a reserved corner or any card or control it
|
|
36
36
|
// steps to the nearest clear slot (`edgeSlot`) instead of being hidden; it
|
|
37
37
|
// never steps around the avatar, which it is already drawn over.
|
|
38
|
-
export function worldPlacement(pointers, labels, controls, view, around = []) {
|
|
38
|
+
export function worldPlacement(pointers, labels, controls, view, around = [], names = null) {
|
|
39
39
|
const insets = view.insets ?? { top: 0, right: 0, bottom: 0, left: 0 };
|
|
40
40
|
const world = view.world;
|
|
41
41
|
const bounds = {
|
|
@@ -59,11 +59,22 @@ export function worldPlacement(pointers, labels, controls, view, around = []) {
|
|
|
59
59
|
return placed;
|
|
60
60
|
});
|
|
61
61
|
const inside = (box) => box.left >= bounds.left && box.right <= bounds.right && box.top >= bounds.top && box.bottom <= bounds.bottom;
|
|
62
|
-
const
|
|
62
|
+
const depths = names?.size ? new Map() : null;
|
|
63
|
+
const chips = [];
|
|
64
|
+
const behindName = (box, depth) => {
|
|
65
|
+
if (!names || !Number.isFinite(depth)) {return false;}
|
|
66
|
+
for (const tag of names.values()) {
|
|
67
|
+
if (tag.depth < depth && overlaps(box, tag)) {return true;}
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
};
|
|
71
|
+
const clear = (box, ignore, chipDepth) => !taken.some((other) => other !== ignore &&
|
|
72
|
+
!(depths?.get(other) > chipDepth) && overlaps(box, other));
|
|
63
73
|
const labelBoxes = labels.map((box) => {
|
|
74
|
+
const chipDepth = box.tagPlayerId === undefined ? undefined : names?.get(box.tagPlayerId)?.depth;
|
|
64
75
|
// An NPC's line always goes through `edgeSlot`, which owns its held far
|
|
65
76
|
// slot (a clear own slot is not taken back from a held far one there).
|
|
66
|
-
let placed = !box.edge && inside(box) && clear(box, box.ignoreObstacle) ? box : null;
|
|
77
|
+
let placed = !box.edge && inside(box) && clear(box, box.ignoreObstacle, chipDepth) ? box : null;
|
|
67
78
|
if (!placed && box.clamp) {
|
|
68
79
|
const at = clampTo(box, bounds);
|
|
69
80
|
const w = box.right - box.left, h = box.bottom - box.top;
|
|
@@ -76,13 +87,46 @@ export function worldPlacement(pointers, labels, controls, view, around = []) {
|
|
|
76
87
|
.sort((a, b) => Math.hypot(a.left - box.left, a.top - box.top) - Math.hypot(b.left - box.left, b.top - box.top))[0] ?? null;
|
|
77
88
|
} else if (!placed && box.edge) {
|
|
78
89
|
placed = edgeSlot(box, bounds, taken, inside, clear, new Set(safeEdges));
|
|
90
|
+
} else if (!placed && box.drop) {
|
|
91
|
+
placed = dropSlot(box, bounds, inside, (at) => clear(at, box.ignoreObstacle, chipDepth),
|
|
92
|
+
(at) => taken.filter((other) => other !== box.ignoreObstacle && !(depths?.get(other) > chipDepth) && overlaps(at, other)));
|
|
93
|
+
}
|
|
94
|
+
if (placed && behindName(placed, box.depth)) {return null;}
|
|
95
|
+
if (placed) {
|
|
96
|
+
taken.push(placed);
|
|
97
|
+
if (Number.isFinite(box.depth)) {depths?.set(placed, box.depth);}
|
|
98
|
+
if (chipDepth !== undefined) {chips.push({ box: placed, depth: chipDepth });}
|
|
79
99
|
}
|
|
80
|
-
if (placed) {taken.push(placed);}
|
|
81
100
|
return placed;
|
|
82
101
|
});
|
|
102
|
+
if (chips.length) {
|
|
103
|
+
for (let i = 0; i < labels.length; i += 1) {
|
|
104
|
+
const placed = labelBoxes[i], depth = labels[i].depth;
|
|
105
|
+
if (placed && chips.some((chip) => chip.depth < depth && overlaps(placed, chip.box))) {labelBoxes[i] = null;}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
83
108
|
return { pointers: pointerBoxes, labels: labelBoxes };
|
|
84
109
|
}
|
|
85
110
|
|
|
111
|
+
// Where the viewer's own mark (`drop`) goes when its box is covered (the HUD
|
|
112
|
+
// on a turned phone, whose top band reaches down to the name's height) or
|
|
113
|
+
// starts above the view: straight down, just under whatever covers it, until
|
|
114
|
+
// it is clear. It is a tag over the viewer's own head, so it may come down
|
|
115
|
+
// over that body (`ignoreObstacle`) but never onto a control. Null when no
|
|
116
|
+
// clear slot is found in a few steps.
|
|
117
|
+
function dropSlot(box, bounds, inside, clear, blockers) {
|
|
118
|
+
const h = box.bottom - box.top;
|
|
119
|
+
let at = { left: box.left, right: box.right, top: Math.max(box.top, bounds.top), bottom: Math.max(box.top, bounds.top) + h };
|
|
120
|
+
for (let i = 0; i < 6; i += 1) {
|
|
121
|
+
if (!inside(at)) {return null;}
|
|
122
|
+
if (clear(at)) {return at;}
|
|
123
|
+
const below = Math.max(...blockers(at).map((other) => other.bottom));
|
|
124
|
+
if (!(below > at.top)) {return null;}
|
|
125
|
+
at = { left: at.left, right: at.right, top: below + 4, bottom: below + 4 + h };
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
86
130
|
// Where an NPC's line goes when its slid box is covered: the nearest clear
|
|
87
131
|
// slot higher up (above its own Talk prompt, beside a reserved corner as
|
|
88
132
|
// well if need be), then the nearest clear slot beside or below, within a
|
|
@@ -245,7 +289,7 @@ function surroundings(node, geometry) {
|
|
|
245
289
|
// `held(node)` is the box a control held before safe layout moved or hid it
|
|
246
290
|
// (an act prompt): labels and pointers make way for that box, as before, and
|
|
247
291
|
// for the box it is drawn in now.
|
|
248
|
-
export function makeWorldLayout(entries, view, obstacles = () => [], geometry = makeLayoutCache(), held = () => null) {
|
|
292
|
+
export function makeWorldLayout(entries, view, obstacles = () => [], geometry = makeLayoutCache(), held = () => null, names = () => null) {
|
|
249
293
|
const hidden = new Set();
|
|
250
294
|
const shifted = new Map();
|
|
251
295
|
const reflowed = new Map();
|
|
@@ -450,9 +494,11 @@ export function makeWorldLayout(entries, view, obstacles = () => [], geometry =
|
|
|
450
494
|
firstLine.set(node, top + line);
|
|
451
495
|
return top + line + (Number.parseFloat(style.paddingBottom) || 0);
|
|
452
496
|
};
|
|
453
|
-
const placements = worldPlacement(pointers.map((entry) => entry.box), labels.map(({ node, box, ignoreObstacle, clamp, edge }) =>
|
|
454
|
-
|
|
455
|
-
|
|
497
|
+
const placements = worldPlacement(pointers.map((entry) => entry.box), labels.map(({ node, box, ignoreObstacle, clamp, edge, drop, depth, tagPlayerId }) =>
|
|
498
|
+
ignoreObstacle || clamp || edge || drop || depth !== undefined || tagPlayerId !== undefined
|
|
499
|
+
? { left: box.left, right: box.right, top: box.top, bottom: box.bottom, ignoreObstacle, clamp, edge, drop, depth, tagPlayerId,
|
|
500
|
+
...(edge ? { line: lineOf(node), ...(farSlots.has(node) ? { far: farSlots.get(node) } : {}) } : {}) }
|
|
501
|
+
: box), [...controls, ...around], view(), around, names());
|
|
456
502
|
// An NPC line's far slot is held across flushes (`edgeSlot`).
|
|
457
503
|
labels.forEach(({ node, edge }, index) => {
|
|
458
504
|
const far = edge ? placements.labels[index]?.far : null;
|