castle-web-cli 0.4.255 → 0.4.257
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-failures.d.ts +1 -0
- package/dist/agent-failures.js +9 -0
- package/dist/agent.d.ts +3 -0
- package/dist/agent.js +43 -10
- package/dist/devSessionChild.js +8 -1
- package/dist/devSessionServer.d.ts +7 -0
- package/dist/devSessionServer.js +12 -5
- package/dist/hostFeatureCheck.d.ts +23 -0
- package/dist/hostFeatureCheck.js +70 -0
- package/dist/init.js +1 -1
- package/dist/platformDoc.d.ts +1 -0
- package/dist/platformDoc.js +19 -3
- package/dist/retryNotice.d.ts +3 -0
- package/dist/retryNotice.js +39 -0
- package/dist/save-deck.js +2 -0
- package/dist/shell/assets/index-CO225dl5.js +454 -0
- package/dist/shell/assets/{index-MVLfNYd9.css → index-D_8-R2mm.css} +1 -1
- package/dist/shell/index.html +2 -2
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +14 -0
- package/kits/base/sdk/server/platformHandle.d.ts +2 -0
- package/kits/base/sdk/server/wrapper.d.ts +4 -0
- package/kits/base/sdk/server/wrapper.js +29 -1
- package/kits/hub-game/code/client/chrome.js +80 -28
- package/kits/hub-game/code/client/crowdNames.js +3 -2
- package/kits/hub-game/code/client/hudTree.js +7 -3
- 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/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-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/turn-based/castle.json +1 -1
- package/package.json +2 -2
- package/dist/shell/assets/index-Bec6LpAv.js +0 -454
package/kits/base/castle.json
CHANGED
package/kits/base/sdk/README.md
CHANGED
|
@@ -155,6 +155,20 @@ is. `session.place` is the hub place the host started the session for (see
|
|
|
155
155
|
[`session.hub`](#sessionhub)), and `null` otherwise. It is never taken from a
|
|
156
156
|
client.
|
|
157
157
|
|
|
158
|
+
### `session.sessionSecret` and `session.assets.read`
|
|
159
|
+
|
|
160
|
+
Both are available in `onStart`. `session.sessionSecret` is the host-provided
|
|
161
|
+
signing key for this session, or `undefined` when the host supplies no key.
|
|
162
|
+
The key is read-only and omitted from object inspection, spread, and default JSON
|
|
163
|
+
serialization. Code that names the property, by reading it or by passing it in a
|
|
164
|
+
`JSON.stringify` property list, gets the key. Read it directly through `session.sessionSecret`.
|
|
165
|
+
Keep the key server-side and out of messages, logs, and storage.
|
|
166
|
+
|
|
167
|
+
`await session.assets.read(name)` returns the exact bytes of a mounted session
|
|
168
|
+
asset as a `Uint8Array`, or `null` if the name is absent. On older runtimes
|
|
169
|
+
without session asset support, the promise rejects with an unavailable error.
|
|
170
|
+
`session.assets` is omitted from object keys, spread, and JSON serialization.
|
|
171
|
+
|
|
158
172
|
### `session.storage`
|
|
159
173
|
|
|
160
174
|
A session ends when its last player leaves, and its memory goes with it.
|
|
@@ -41,6 +41,8 @@ export interface PlatformWorldTimeConfig {
|
|
|
41
41
|
advance: "wallClock";
|
|
42
42
|
}
|
|
43
43
|
export interface PlatformHandle {
|
|
44
|
+
readonly sessionSecret?: string;
|
|
45
|
+
readAsset?(name: string): Promise<Uint8Array | null>;
|
|
44
46
|
send(connId: string, text: string): void;
|
|
45
47
|
broadcast(text: string): void;
|
|
46
48
|
sendBinary?(connId: string, bytes: Uint8Array | ArrayBuffer): void;
|
|
@@ -22,6 +22,10 @@ export interface MultiplayerServerSession {
|
|
|
22
22
|
readonly sessionId: string;
|
|
23
23
|
readonly deckId: string;
|
|
24
24
|
readonly mode: MultiplayerSessionMode;
|
|
25
|
+
readonly sessionSecret?: string;
|
|
26
|
+
readonly assets: {
|
|
27
|
+
read(name: string): Promise<Uint8Array | null>;
|
|
28
|
+
};
|
|
25
29
|
/**
|
|
26
30
|
* The place the host started this session for (a hub door's destination, or
|
|
27
31
|
* the hub place ghost pinned the session to), or null when the host stamped
|
|
@@ -247,7 +247,7 @@ function createAuthorSession(platformHandle, players, arrivals, hidden, variants
|
|
|
247
247
|
return Boolean(hidden.get(a)?.has(userB) || hidden.get(b)?.has(userA));
|
|
248
248
|
});
|
|
249
249
|
const world = createServerWorld(platformHandle);
|
|
250
|
-
|
|
250
|
+
const session = {
|
|
251
251
|
get players() {
|
|
252
252
|
return Array.from(players.values());
|
|
253
253
|
},
|
|
@@ -257,6 +257,14 @@ function createAuthorSession(platformHandle, players, arrivals, hidden, variants
|
|
|
257
257
|
place: typeof platformHandle.config.place === "string"
|
|
258
258
|
? platformHandle.config.place
|
|
259
259
|
: hub?.place ?? null,
|
|
260
|
+
assets: {
|
|
261
|
+
async read(name) {
|
|
262
|
+
if (typeof platformHandle.readAsset !== "function") {
|
|
263
|
+
throw new TypeError("This Castle runtime does not support session assets yet.");
|
|
264
|
+
}
|
|
265
|
+
return platformHandle.readAsset(name);
|
|
266
|
+
},
|
|
267
|
+
},
|
|
260
268
|
storage: createServerStorage(platformHandle),
|
|
261
269
|
world,
|
|
262
270
|
characters: world?.characters ?? createPlaceCharacters(platformHandle),
|
|
@@ -308,6 +316,26 @@ function createAuthorSession(platformHandle, players, arrivals, hidden, variants
|
|
|
308
316
|
platformHandle.disconnect(playerId, reason ?? 1000);
|
|
309
317
|
},
|
|
310
318
|
};
|
|
319
|
+
Object.defineProperty(session, "assets", { enumerable: false });
|
|
320
|
+
// Inspectors can invoke getters. Keep the key in a closure off the inspected target.
|
|
321
|
+
const sessionSecret = platformHandle.sessionSecret;
|
|
322
|
+
return new Proxy(session, {
|
|
323
|
+
get(target, property, receiver) {
|
|
324
|
+
if (property === "sessionSecret")
|
|
325
|
+
return sessionSecret;
|
|
326
|
+
return Reflect.get(target, property, receiver);
|
|
327
|
+
},
|
|
328
|
+
set(target, property, value, receiver) {
|
|
329
|
+
if (property === "sessionSecret")
|
|
330
|
+
return false;
|
|
331
|
+
return Reflect.set(target, property, value, receiver);
|
|
332
|
+
},
|
|
333
|
+
defineProperty(target, property, descriptor) {
|
|
334
|
+
if (property === "sessionSecret")
|
|
335
|
+
return false;
|
|
336
|
+
return Reflect.defineProperty(target, property, descriptor);
|
|
337
|
+
},
|
|
338
|
+
});
|
|
311
339
|
}
|
|
312
340
|
const WORLD_OPERATION_ID_MAX_BYTES = 128;
|
|
313
341
|
const WORLD_OPERATION_ID_MAX_CHARACTERS = 120;
|
|
@@ -87,6 +87,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
87
87
|
let worldLayout = null;
|
|
88
88
|
let worldViewport = null;
|
|
89
89
|
let worldAvatar = null;
|
|
90
|
+
let worldNameTags = null;
|
|
90
91
|
// The avatar box snapped outward to 16 px, so a walking player does not
|
|
91
92
|
// re-solve or shuffle the action rail every frame.
|
|
92
93
|
let avatarReserve = null;
|
|
@@ -1066,13 +1067,22 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1066
1067
|
let hudClear = false;
|
|
1067
1068
|
let hudClearDrawn = false;
|
|
1068
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;
|
|
1069
1078
|
// The place before asked and this one does not: the styles of old, put
|
|
1070
1079
|
// back the moment the option goes, whether or not a HUD is drawn after.
|
|
1071
1080
|
function restoreHudClear() {
|
|
1072
1081
|
hudBig.style.fontSize = '56px';
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1082
|
+
hudBig.style.whiteSpace = hudNumber() ? 'nowrap' : '';
|
|
1083
|
+
hudBig.style.overflow = hudNumber() ? 'hidden' : '';
|
|
1084
|
+
hudBig.style.textOverflow = hudNumber() ? 'ellipsis' : '';
|
|
1085
|
+
hudNumberFitKey = '';
|
|
1076
1086
|
hudBig.style.maxWidth = '100%';
|
|
1077
1087
|
hud.style.maxHeight = '';
|
|
1078
1088
|
hud.style.overflow = '';
|
|
@@ -1118,7 +1128,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1118
1128
|
const column = [sayButton, emoteButton, grabButton, sound?.button]
|
|
1119
1129
|
.filter((node) => node && node.style.display !== 'none').map((node) => geometry.rect(node)).filter((box) => box.width > 0 && box.height > 0);
|
|
1120
1130
|
const backBox = back.style.display !== 'none' ? geometry.rect(back) : null;
|
|
1121
|
-
const key = shown ? [hudTitle.textContent,
|
|
1131
|
+
const key = shown ? [hudTitle.textContent, hudBigKey(), hudNumber(), view.w, view.h,
|
|
1122
1132
|
...[...column, ...(backBox ? [backBox] : [])].flatMap((box) => [box.left, box.top, box.right, box.bottom])].join('\u0001') : '';
|
|
1123
1133
|
if (key !== hudLaneKey) {
|
|
1124
1134
|
hudLaneKey = key;
|
|
@@ -1137,7 +1147,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1137
1147
|
hud.style.maxWidth = `${width}px`;
|
|
1138
1148
|
// The HUD is centred on the view; centre it on the lane instead.
|
|
1139
1149
|
hud.style.translate = `${Math.round(left + width / 2 - view.w / 2)}px 0px`;
|
|
1140
|
-
if (!hudClear) {
|
|
1150
|
+
if (!hudClear && !hudNumber()) {
|
|
1141
1151
|
writeHudBig('whiteSpace', 'nowrap');
|
|
1142
1152
|
writeHudBig('overflow', 'hidden');
|
|
1143
1153
|
writeHudBig('textOverflow', 'ellipsis');
|
|
@@ -1150,7 +1160,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1150
1160
|
if (hudClear && hudBig.style.maxWidth.endsWith('px') && Number.parseFloat(hudBig.style.maxWidth) > hudLaneWritten.width) {
|
|
1151
1161
|
writeHudBig('maxWidth', `${hudLaneWritten.width}px`);
|
|
1152
1162
|
}
|
|
1153
|
-
if (!hudClear) {
|
|
1163
|
+
if (!hudClear && !hudNumber()) {
|
|
1154
1164
|
const fit = geometry.fit(hudBig);
|
|
1155
1165
|
if (fit.text === hudBig.textContent && (fit.fontSize === hudBig.style.fontSize || !hudBig.style.fontSize)) {
|
|
1156
1166
|
const base = Number.parseFloat(fit.fontSize) || 56;
|
|
@@ -1159,11 +1169,41 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1159
1169
|
}
|
|
1160
1170
|
}
|
|
1161
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
|
+
}
|
|
1162
1202
|
function layoutHudClear(big, text) {
|
|
1163
1203
|
hudClearDrawn = true;
|
|
1164
1204
|
const backShown = back.style.display !== 'none';
|
|
1165
1205
|
const backBox = geometry.rect(back);
|
|
1166
|
-
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');
|
|
1167
1207
|
const layout = hudLayout({
|
|
1168
1208
|
big,
|
|
1169
1209
|
text,
|
|
@@ -1174,15 +1214,17 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1174
1214
|
});
|
|
1175
1215
|
if (key !== hudClearKey) {
|
|
1176
1216
|
hudClearKey = key;
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
hudBig.style.
|
|
1180
|
-
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' : '';
|
|
1181
1223
|
hudBig.style.maxWidth = layout.bigMaxWidth === null ? '100%' : `${layout.bigMaxWidth}px`;
|
|
1182
1224
|
hud.style.maxHeight = layout.maxHeight === null ? '' : `${layout.maxHeight}px`;
|
|
1183
1225
|
hud.style.overflow = layout.maxHeight === null ? '' : 'hidden';
|
|
1184
1226
|
}
|
|
1185
|
-
if (layout.bigOneLine) {
|
|
1227
|
+
if (layout.bigOneLine && !hudNumber()) {
|
|
1186
1228
|
const fit = geometry.fit(hudBig);
|
|
1187
1229
|
if (!geometry.active() || (fit.text === String(big) && fit.fontSize === hudBig.style.fontSize)) {
|
|
1188
1230
|
const base = Number.parseFloat(fit.fontSize) || layout.bigPx;
|
|
@@ -1190,6 +1232,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1190
1232
|
if (px < base) {hudBig.style.fontSize = `${px}px`;}
|
|
1191
1233
|
}
|
|
1192
1234
|
}
|
|
1235
|
+
return layout.bigPx;
|
|
1193
1236
|
}
|
|
1194
1237
|
// What a frame's setters ask to be kept clear of the HUD, by group
|
|
1195
1238
|
// ("labels", "roles", "pointers", "cabinet", "ribbon"): each entry is [node, x, y,
|
|
@@ -1885,7 +1928,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1885
1928
|
worldLabelsDefault = on;
|
|
1886
1929
|
// The root town retains its explicit near selection; its selected text
|
|
1887
1930
|
// still needs the same final HUD/control/avatar clearance as doors.
|
|
1888
|
-
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry, (node) => safeLayout?.heldAct?.(node) ?? null);
|
|
1931
|
+
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry, (node) => safeLayout?.heldAct?.(node) ?? null, () => worldNameTags);
|
|
1889
1932
|
},
|
|
1890
1933
|
// An avatar crossing the camera's near plane has no reliable screen box
|
|
1891
1934
|
// (and may be hidden by the renderer's first-person view).
|
|
@@ -1898,6 +1941,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1898
1941
|
},
|
|
1899
1942
|
worldAvatar: () => worldAvatar,
|
|
1900
1943
|
setWorldViewport: (area) => {worldViewport = area;},
|
|
1944
|
+
setWorldNameTags: (boxes) => {worldNameTags = boxes;},
|
|
1901
1945
|
beginWorldLabels: () => worldLayout?.begin(true),
|
|
1902
1946
|
flushWorldLabels: () => worldLayout?.flush(),
|
|
1903
1947
|
setMenu, clearMenu,
|
|
@@ -2228,6 +2272,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2228
2272
|
// since/until), not ten times a second, and the page ticks it here, each
|
|
2229
2273
|
// frame, at `simNow`.
|
|
2230
2274
|
setHud(spec, timerSeconds, simNow) {
|
|
2275
|
+
hudCall += 1;
|
|
2231
2276
|
if (!spec) {
|
|
2232
2277
|
hudSurface.setHud(null);
|
|
2233
2278
|
// Hidden, the safe layout may let go of its width: the same words
|
|
@@ -2235,6 +2280,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2235
2280
|
promptPlaced = null;
|
|
2236
2281
|
return;
|
|
2237
2282
|
}
|
|
2283
|
+
const numberFit = geometry.active() || hudNumberFitPending ? geometry.fit(hudBig) : null;
|
|
2238
2284
|
const { big, clock } = hudSurface.setHud(spec, timerSeconds, simNow);
|
|
2239
2285
|
if (clock && uiTreeDomEnabled()) {hudDom.tick();}
|
|
2240
2286
|
// A prompt shown or reworded is placed in this frame: upright it may be
|
|
@@ -2247,10 +2293,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2247
2293
|
safeLayout.flush();
|
|
2248
2294
|
}
|
|
2249
2295
|
}
|
|
2250
|
-
|
|
2251
|
-
layoutHudClear(big, spec.text ?? '');
|
|
2252
|
-
}
|
|
2296
|
+
const bigPx = hudClear ? layoutHudClear(big, spec.text ?? '') : 56;
|
|
2253
2297
|
layoutHudLane();
|
|
2298
|
+
fitHudNumber(bigPx, numberFit);
|
|
2254
2299
|
if (import.meta.env?.DEV) {
|
|
2255
2300
|
warnHudCopy(hudTitle, 'subtitle');
|
|
2256
2301
|
warnHudCopy(hudText, 'prompt', 1);
|
|
@@ -2383,22 +2428,21 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2383
2428
|
: node.dataset.hub === 'action-rail' ? [node] : []);
|
|
2384
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);
|
|
2385
2430
|
},
|
|
2386
|
-
//
|
|
2387
|
-
//
|
|
2388
|
-
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:') {
|
|
2389
2434
|
const shown = new Map(items.map((item) => [item.id, item]));
|
|
2390
2435
|
const entries = [];
|
|
2391
2436
|
for (const [id, node] of labelNodes) {
|
|
2392
|
-
if (!id.startsWith(
|
|
2437
|
+
if (!id.startsWith(prefix)) {
|
|
2393
2438
|
continue;
|
|
2394
2439
|
}
|
|
2395
2440
|
const item = shown.get(id);
|
|
2396
|
-
if (!item && id ===
|
|
2441
|
+
if (!item && id === `${prefix}${keepPlayerId}`) {
|
|
2397
2442
|
continue;
|
|
2398
2443
|
}
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
} else if (position) {
|
|
2444
|
+
node.style.display = item ? '' : 'none';
|
|
2445
|
+
if (item && position) {
|
|
2402
2446
|
node.style.left = `${item.x}px`;
|
|
2403
2447
|
node.style.top = `${item.y}px`;
|
|
2404
2448
|
node.style.opacity = String(item.opacity ?? 1);
|
|
@@ -2418,7 +2462,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2418
2462
|
.filter(([id]) => id !== 'crowd:summary')
|
|
2419
2463
|
.map(([id, node]) => {
|
|
2420
2464
|
const box = shownRect(node);
|
|
2421
|
-
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 }) };
|
|
2422
2468
|
})
|
|
2423
2469
|
.filter(Boolean);
|
|
2424
2470
|
},
|
|
@@ -2462,7 +2508,12 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2462
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);
|
|
2463
2509
|
labelNodes.set(item.id, node);
|
|
2464
2510
|
}
|
|
2465
|
-
|
|
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 = '';
|
|
2466
2517
|
node.style.visibility = '';
|
|
2467
2518
|
}
|
|
2468
2519
|
// An NPC's line is kept on screen: a reply over one at the edge of the
|
|
@@ -3473,7 +3524,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
3473
3524
|
// A role chip belongs under its name tag, and a place's tag (`hub.mark`) over a head,
|
|
3474
3525
|
// the viewer's own included; both are drawn over the viewer's body anyway. So is
|
|
3475
3526
|
// an NPC's line, Chirp's included, said from the viewer's shoulder.
|
|
3476
|
-
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 })),
|
|
3477
3529
|
...[...pointerNodes].map(([id, item]) => surface(`pointer:${id}`, item.chip, 'pointer', true)),
|
|
3478
3530
|
...externalEntries().map(([id, item]) => ({ ...surface(id, item.node, item.kind, item.kind === 'text'), ...item.placement, ...(id === 'engine-shift-lock' ? { stack: 4 } : {}) })),
|
|
3479
3531
|
...(actionOverflow?.surfaces?.() ?? []).map((node, i) => surface(`action-overflow:${i}`, node, 'control')),
|
|
@@ -3490,7 +3542,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
3490
3542
|
for (const child of entry.reportNodes?.() ?? []) {geometry.register(child.node);}
|
|
3491
3543
|
}
|
|
3492
3544
|
if (worldLabelsDefault) {
|
|
3493
|
-
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry, (node) => safeLayout?.heldAct?.(node) ?? null);
|
|
3545
|
+
worldLayout = makeWorldLayout(surfaces, worldView, worldObstacles, geometry, (node) => safeLayout?.heldAct?.(node) ?? null, () => worldNameTags);
|
|
3494
3546
|
}
|
|
3495
3547
|
if (safeInsets) {
|
|
3496
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,6 +17,8 @@
|
|
|
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'] };
|
|
@@ -61,6 +63,7 @@ export function buildHud(state) {
|
|
|
61
63
|
const toast = state.toast ?? {};
|
|
62
64
|
const big = hud.big ?? '';
|
|
63
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);
|
|
64
67
|
const toastText = toast.text ?? '';
|
|
65
68
|
const wrapToast = Boolean(toastText && toast.wrap);
|
|
66
69
|
return h('stack', { key: 'hud', style: { font: 'ui', size: 15, weight: 600, lh: 1.3, color: '#fff' } },
|
|
@@ -73,7 +76,7 @@ export function buildHud(state) {
|
|
|
73
76
|
h('column', {
|
|
74
77
|
key: 'hud',
|
|
75
78
|
at: { anchor: 'top', top: [12, 0] },
|
|
76
|
-
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 },
|
|
77
80
|
},
|
|
78
81
|
h('text', {
|
|
79
82
|
key: 'title', data: { hubCopy: 'subtitle' }, text: hud.title ?? '',
|
|
@@ -81,8 +84,9 @@ export function buildHud(state) {
|
|
|
81
84
|
}),
|
|
82
85
|
// The big line sits 4 px under the title (and 4 px down without one).
|
|
83
86
|
h('text', {
|
|
84
|
-
key: 'big', ...(clock ? { clock } : { text: big }),
|
|
85
|
-
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 },
|
|
86
90
|
})),
|
|
87
91
|
h('text', {
|
|
88
92
|
key: 'prompt', hub: 'hud-prompt', data: { hubCopy: 'instruction' }, text: hud.prompt ?? '',
|
|
@@ -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;
|