castle-web-cli 0.4.230 → 0.4.232

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.
Files changed (92) hide show
  1. package/dist/castle-host/host.js +81 -0
  2. package/dist/devSaveStorage.d.ts +36 -0
  3. package/dist/devSaveStorage.js +469 -0
  4. package/dist/devSessionChild.js +22 -12
  5. package/dist/devSessionServer.js +8 -2
  6. package/dist/devSessionStorage.d.ts +9 -0
  7. package/dist/devSessionStorage.js +66 -1
  8. package/dist/init.js +1 -1
  9. package/dist/serve.js +5 -1
  10. package/dist/serverBundle.js +5 -3
  11. package/kits/base/castle.json +1 -1
  12. package/kits/base/sdk/README.md +148 -1
  13. package/kits/base/sdk/castle.d.ts +4 -0
  14. package/kits/base/sdk/castle.js +2 -0
  15. package/kits/base/sdk/commands.d.ts +15 -0
  16. package/kits/base/sdk/multiplayer.js +52 -4
  17. package/kits/base/sdk/save.d.ts +197 -0
  18. package/kits/base/sdk/save.js +525 -0
  19. package/kits/base/sdk/saveCoordinator.d.ts +39 -0
  20. package/kits/base/sdk/saveCoordinator.js +252 -0
  21. package/kits/base/sdk/server/storage.d.ts +3 -2
  22. package/kits/base/sdk/server/storage.js +25 -5
  23. package/kits/base/sdk/server/wrapper.d.ts +4 -0
  24. package/kits/base/sdk/server/wrapper.js +2 -0
  25. package/kits/base/sdk/store.d.ts +3 -2
  26. package/kits/base/sdk/store.js +5 -0
  27. package/kits/hub-game/CLAUDE.md +29 -4
  28. package/kits/hub-game/code/client/avatar.js +39 -0
  29. package/kits/hub-game/code/client/chat.js +12 -0
  30. package/kits/hub-game/code/client/chrome.js +237 -13
  31. package/kits/hub-game/code/client/grab.js +166 -7
  32. package/kits/hub-game/code/client/hats.js +26 -0
  33. package/kits/hub-game/code/client/hookLayer.js +36 -3
  34. package/kits/hub-game/code/client/hudClear.js +126 -0
  35. package/kits/hub-game/code/client/state.js +35 -1
  36. package/kits/hub-game/code/client/talk.js +10 -36
  37. package/kits/hub-game/code/client/tiers.js +505 -0
  38. package/kits/hub-game/code/client/together.js +144 -4
  39. package/kits/hub-game/code/client/wear.js +96 -14
  40. package/kits/hub-game/code/server/actors.js +5 -0
  41. package/kits/hub-game/code/server/grab.js +299 -13
  42. package/kits/hub-game/code/server/hub.js +162 -7
  43. package/kits/hub-game/code/server/manifest.js +80 -8
  44. package/kits/hub-game/code/server/npcs.js +21 -33
  45. package/kits/hub-game/code/server/party.js +75 -6
  46. package/kits/hub-game/code/server/say.js +8 -2
  47. package/kits/hub-game/code/server/wear.js +116 -11
  48. package/kits/hub-game/code/systems/hub.js +386 -21
  49. package/kits/hub-game/docs/contract.md +285 -19
  50. package/kits/hub-game/package.json +1 -1
  51. package/kits/hub-game/scripts/test-chat.mjs +32 -0
  52. package/kits/hub-game/scripts/test-grab-client.mjs +511 -0
  53. package/kits/hub-game/scripts/test-grab.mjs +857 -3
  54. package/kits/hub-game/scripts/test-hats.mjs +229 -0
  55. package/kits/hub-game/scripts/test-hub-trip.mjs +721 -0
  56. package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
  57. package/kits/hub-game/scripts/test-manifest.mjs +122 -1
  58. package/kits/hub-game/scripts/test-npcs.mjs +34 -24
  59. package/kits/hub-game/scripts/test-party.mjs +108 -4
  60. package/kits/hub-game/scripts/test-say.mjs +59 -2
  61. package/kits/hub-game/scripts/test-tiers.mjs +854 -0
  62. package/kits/hub-game/scripts/test-together.mjs +33 -1
  63. package/kits/hub-game/scripts/test-try-on.mjs +940 -0
  64. package/kits/physics-2d/CLAUDE.md +2 -0
  65. package/kits/physics-2d/castle.json +2 -2
  66. package/kits/physics-2d/engine/scene.js +127 -0
  67. package/kits/physics-2d/package.json +1 -1
  68. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +298 -0
  69. package/kits/physics-3d/CLAUDE.md +531 -0
  70. package/kits/physics-3d/behaviors/Player.jsx +437 -3
  71. package/kits/physics-3d/castle.json +3 -3
  72. package/kits/physics-3d/docs/pxmodel-format.md +4 -0
  73. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -1
  74. package/kits/physics-3d/engine3d/actornode.js +253 -0
  75. package/kits/physics-3d/engine3d/nearshadows.js +600 -0
  76. package/kits/physics-3d/engine3d/optimize.js +49 -0
  77. package/kits/physics-3d/engine3d/orbitinput.js +277 -0
  78. package/kits/physics-3d/engine3d/unchanged.js +153 -0
  79. package/kits/physics-3d/engine3d/world3d.js +525 -11
  80. package/kits/physics-3d/package.json +1 -1
  81. package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
  82. package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
  83. package/kits/physics-3d/scripts/test-camera-follow.mjs +543 -0
  84. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2105 -0
  85. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
  86. package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
  87. package/kits/physics-3d/scripts/test-static-actors.mjs +667 -0
  88. package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
  89. package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
  90. package/kits/physics-3d/scripts/test-steady-hover.mjs +633 -0
  91. package/kits/physics-3d/systems/physics3d.js +273 -9
  92. package/package.json +1 -1
@@ -1,15 +1,18 @@
1
1
  // The hub's own chrome: DOM drawn by the place, never by a game's content, so a
2
2
  // game cannot hide or fake it (contract: "Hub-owned UI"). The door cover, the
3
3
  // Back control, the declared HUD, actor labels and speech, the result ribbon,
4
- // the avatar picker, the NPC talk button and panel, a town's door list (jump
5
- // to a door), the people here and the player's friends, each friend with
4
+ // the avatar picker (with a Graphics row in a deck with device tiers), the NPC
5
+ // talk button and panel, a town's door list (jump to a door), the people here and the player's friends, each friend with
6
6
  // where they are and Join, each player with Report (where the host takes
7
7
  // reports), the pointers to friends out of sight,
8
8
  // the Grab / Throw button (a place with `grab`, v1.3), the emote picker and
9
9
  // the Sit / Stand button (a place with `idle`, v1.6), an arcade cabinet's
10
- // board card (v1.7), and the frame-rate readout behind `?hubstats`.
10
+ // board card (v1.7), and the frame-rate readout behind `?hubstats`. In a place
11
+ // that asks (`hud.clear`, v1.26) the HUD is kept short and what is drawn over
12
+ // the world is kept out from under it (`hudClear.js`).
11
13
 
12
14
  import { cardMode, makeCardView, tapCard } from './cabinets.js';
15
+ import { boxAt, fitPx, hudLayout, pushBelow } from './hudClear.js';
13
16
  import { guardScrollKeys } from './keys.js';
14
17
 
15
18
  const Z = 2147480000;
@@ -21,6 +24,11 @@ function el(tag, style, parent = document.body) {
21
24
  return node;
22
25
  }
23
26
 
27
+ // White text drawn straight over the world (the HUD, the feed): an outline
28
+ // close around each letter as well as the soft drop shadow, so it reads over a
29
+ // pale sky as it does over a dark street.
30
+ const BARE_TEXT_SHADOW = '0 0 2px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.95), 0 1px 4px rgba(0,0,0,0.75), 0 0 10px rgba(0,0,0,0.45)';
31
+
24
32
  export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {}, onJumpDoor = () => {}, onReport = () => {}, onAsk = () => {}, onLeaveParty = () => {}, onReportChat = () => {} }) {
25
33
  const unguardKeys = guardScrollKeys();
26
34
  // A desktop stage (a mouse, room to spare): NPC lines are narrower and the
@@ -42,7 +50,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
42
50
  onBack();
43
51
  });
44
52
 
45
- const hud = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', textAlign: 'center', textShadow: '0 1px 3px rgba(0,0,0,0.8)', display: 'none', maxWidth: '70vw' }, root);
53
+ const hud = el('div', { position: 'absolute', top: 'max(12px, env(safe-area-inset-top))', left: '50%', transform: 'translateX(-50%)', textAlign: 'center', textShadow: BARE_TEXT_SHADOW, display: 'none', maxWidth: '70vw' }, root);
46
54
  const hudTitle = el('div', { fontSize: '13px', opacity: '0.85', letterSpacing: '0.06em', textTransform: 'uppercase' }, hud);
47
55
  const hudBig = el('div', { fontSize: '56px', fontWeight: '800', lineHeight: '1.05' }, hud);
48
56
  const hudText = el('div', { fontSize: '14px', fontWeight: '500' }, hud);
@@ -174,6 +182,26 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
174
182
  }
175
183
  const pickerToggle = el('button', { padding: '8px 14px', borderRadius: '18px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.72)', color: '#fff', font: 'inherit', cursor: 'pointer' }, picker);
176
184
  pickerToggle.textContent = 'Character';
185
+ // Graphics: Auto / Low / High, under the characters, in a deck that has
186
+ // device tiers (`tiers.js`). Built on the first `setGraphics`, so a deck
187
+ // without them draws the card as it always was.
188
+ let graphics = null;
189
+ function buildGraphics() {
190
+ const row = el('div', { display: 'flex', alignItems: 'center', gap: '6px', marginTop: '2px' }, pickerCard);
191
+ el('div', { fontSize: '12px', opacity: '0.8', flex: '1' }, row).textContent = 'Graphics';
192
+ const buttons = new Map();
193
+ for (const [mode, text] of [['auto', 'Auto'], ['low', 'Low'], ['high', 'High']]) {
194
+ const button = el('button', { padding: '4px 9px', borderRadius: '12px', border: '1px solid rgba(255,255,255,0.4)', background: 'rgba(20,16,12,0.7)', color: '#fff', font: '600 12px system-ui, sans-serif', cursor: 'pointer' }, row);
195
+ button.textContent = text;
196
+ button.setAttribute('aria-label', `Graphics: ${text}`);
197
+ button.addEventListener('pointerdown', (event) => {
198
+ event.stopPropagation();
199
+ graphics.onPick(mode);
200
+ });
201
+ buttons.set(mode, button);
202
+ }
203
+ return { buttons, onPick: () => {} };
204
+ }
177
205
  pickerToggle.addEventListener('pointerdown', (event) => {
178
206
  event.stopPropagation();
179
207
  setPickerOpen(!pickerOpen);
@@ -196,7 +224,6 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
196
224
  event.stopPropagation();
197
225
  talkHandlers.end();
198
226
  });
199
- const panelNote = el('div', { fontSize: '11px', opacity: '0.65', fontWeight: '500' }, panel);
200
227
  const panelLog = el('div', { maxHeight: '28vh', overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: '4px', fontSize: '14px', fontWeight: '500' }, panel);
201
228
  // Not a <form>: castle.xyz plays a deck in a frame sandboxed without
202
229
  // `allow-forms`, where a form's submission (Enter, or a submit button) is
@@ -301,7 +328,7 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
301
328
  setSayOpen(!sayOpen);
302
329
  setEmotesOpen(false);
303
330
  });
304
- const feed = el('div', { position: 'absolute', left: '10px', bottom: 'max(70px, calc(env(safe-area-inset-bottom) + 60px))', maxWidth: '62vw', display: 'flex', flexDirection: 'column', gap: '2px', font: '500 12px/1.3 system-ui, sans-serif', textShadow: '0 1px 3px rgba(0,0,0,0.85)', opacity: '0.92' }, root);
331
+ const feed = el('div', { position: 'absolute', left: '10px', bottom: 'max(70px, calc(env(safe-area-inset-bottom) + 60px))', maxWidth: '62vw', display: 'flex', flexDirection: 'column', gap: '2px', font: '500 12px/1.3 system-ui, sans-serif', textShadow: BARE_TEXT_SHADOW, opacity: '0.92' }, root);
305
332
  let feedKey = '';
306
333
  const sitButton = el('button', { position: 'absolute', bottom: 'max(112px, calc(env(safe-area-inset-bottom) + 102px))', left: '50%', transform: 'translateX(-50%)', pointerEvents: 'auto', padding: '10px 22px', borderRadius: '22px', border: '1px solid rgba(255,255,255,0.45)', background: 'rgba(20,16,12,0.8)', color: '#fff', font: 'inherit', display: 'none', cursor: 'pointer', touchAction: 'manipulation' }, root);
307
334
  sitButton.addEventListener('pointerdown', (event) => {
@@ -453,6 +480,133 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
453
480
 
454
481
  const stats = el('div', { position: 'absolute', right: '8px', top: 'max(8px, env(safe-area-inset-top))', font: '11px/1.3 ui-monospace, monospace', opacity: '0.7', textAlign: 'right', whiteSpace: 'pre' }, root);
455
482
 
483
+ // A clear HUD (v1.26, `hudClear.js`), in a place whose manifest asks for it
484
+ // (`setHudClear`). Everything below runs only then, or once as the option
485
+ // goes to put the HUD back as it always was: a place that never asks is
486
+ // drawn by the code above and below with none of this in its way.
487
+ let hudClear = false;
488
+ let hudClearDrawn = false;
489
+ let hudClearKey = '';
490
+ let hudClearRect = null;
491
+ const hudClearSizes = new WeakMap();
492
+ // The place before asked and this one does not: the styles of old, put
493
+ // back the moment the option goes, whether or not a HUD is drawn after.
494
+ function restoreHudClear() {
495
+ hudBig.style.fontSize = '56px';
496
+ for (const key of ['whiteSpace', 'overflow', 'textOverflow', 'maxWidth', 'marginLeft', 'marginRight']) {
497
+ hudBig.style[key] = '';
498
+ }
499
+ for (const key of ['display', 'overflow', 'webkitLineClamp', 'webkitBoxOrient']) {
500
+ hudText.style[key] = '';
501
+ }
502
+ hud.style.maxHeight = '';
503
+ hud.style.overflow = '';
504
+ hudClearDrawn = false;
505
+ hudClearKey = '';
506
+ hudClearRect = null;
507
+ hudClearPending.clear();
508
+ }
509
+ function layoutHudClear(big, text) {
510
+ hudClearDrawn = true;
511
+ const backShown = back.style.display !== 'none';
512
+ const key = [hudTitle.textContent, big, text, window.innerWidth, window.innerHeight, backShown ? back.textContent : ''].join('\u0001');
513
+ if (key === hudClearKey) {
514
+ return;
515
+ }
516
+ hudClearKey = key;
517
+ const layout = hudLayout({
518
+ big,
519
+ text,
520
+ viewW: window.innerWidth,
521
+ viewH: window.innerHeight,
522
+ // The big line's row is the Back button's: it keeps out of its way.
523
+ reserve: backShown ? back.offsetLeft + back.offsetWidth + 8 : 0,
524
+ });
525
+ hudBig.style.fontSize = `${layout.bigPx}px`;
526
+ hudBig.style.whiteSpace = layout.bigOneLine ? 'nowrap' : '';
527
+ hudBig.style.overflow = layout.bigOneLine ? 'hidden' : '';
528
+ hudBig.style.textOverflow = layout.bigOneLine ? 'ellipsis' : '';
529
+ hudBig.style.maxWidth = layout.bigMaxWidth === null ? '' : `${layout.bigMaxWidth}px`;
530
+ hudBig.style.marginLeft = layout.bigMaxWidth === null ? '' : 'auto';
531
+ hudBig.style.marginRight = layout.bigMaxWidth === null ? '' : 'auto';
532
+ hudText.style.display = layout.textLines === null ? '' : '-webkit-box';
533
+ hudText.style.overflow = layout.textLines === null ? '' : 'hidden';
534
+ hudText.style.webkitLineClamp = layout.textLines === null ? '' : String(layout.textLines);
535
+ hudText.style.webkitBoxOrient = layout.textLines === null ? '' : 'vertical';
536
+ hud.style.maxHeight = layout.maxHeight === null ? '' : `${layout.maxHeight}px`;
537
+ hud.style.overflow = layout.maxHeight === null ? '' : 'hidden';
538
+ if (layout.bigOneLine) {
539
+ // The estimate fell short of this face: shrink to what was drawn.
540
+ const px = fitPx(layout.bigPx, hudBig.clientWidth, hudBig.scrollWidth);
541
+ if (px !== layout.bigPx) {
542
+ hudBig.style.fontSize = `${px}px`;
543
+ }
544
+ }
545
+ // The box as it is drawn now; it changes only with what the key holds.
546
+ const r = hud.getBoundingClientRect();
547
+ hudClearRect = r.width > 0 && r.height > 0 ? { left: r.left, right: r.right, top: r.top, bottom: r.bottom } : null;
548
+ }
549
+ // What a frame's setters ask to be kept clear of the HUD, by group
550
+ // ("labels", "pointers", "cabinet", "ribbon"): each entry is [node, x, y,
551
+ // anchor, text] -- `node`, hung from (x, y) by `anchor` (`boxAt`), is moved
552
+ // to just under the HUD's box when it would lie over it, never past the
553
+ // bottom of the view. Nothing is measured or moved as it is asked: the
554
+ // whole frame is flushed once (`flushHudClear`, said by the hub system when
555
+ // it has drawn everything), every size that must be measured read first and
556
+ // only then anything moved. A write between two reads would have the
557
+ // browser lay the page out again for each, and a crowd of bubbles drifting
558
+ // sideways is measured every frame. A setter called with no flush after it
559
+ // is still flushed, before the browser paints (a microtask).
560
+ const hudClearPending = new Map();
561
+ let hudClearQueued = false;
562
+ function keepClearOfHud(group, entries) {
563
+ hudClearPending.set(group, entries);
564
+ if (!hudClearQueued) {
565
+ hudClearQueued = true;
566
+ (globalThis.queueMicrotask ?? ((fn) => Promise.resolve().then(fn)))(() => {
567
+ hudClearQueued = false;
568
+ flushHudClear();
569
+ });
570
+ }
571
+ }
572
+ function flushHudClear() {
573
+ if (!hudClearPending.size) {
574
+ return;
575
+ }
576
+ const groups = [...hudClearPending.values()];
577
+ hudClearPending.clear();
578
+ const rect = hudClear && hud.style.display !== 'none' ? hudClearRect : null;
579
+ if (!rect) {
580
+ return;
581
+ }
582
+ const moves = [];
583
+ for (const entries of groups) {
584
+ for (const [node, x, y, anchor, text] of entries) {
585
+ // One since hidden or taken away is left alone.
586
+ if (!node || node.style.display === 'none' || !Number.isFinite(x) || !Number.isFinite(y)) {
587
+ continue;
588
+ }
589
+ // Its size is measured once for each `text` it shows -- and, for a
590
+ // bubble that wraps by the room to its right (speech with no width
591
+ // of its own), again whenever it moves sideways.
592
+ const wraps = node.style.whiteSpace === 'normal' && node.style.width !== 'max-content';
593
+ const key = [text, node.style.fontSize, node.style.maxWidth, node.style.padding, window.innerWidth, wraps ? node.style.left : ''].join('\u0001');
594
+ let box = hudClearSizes.get(node);
595
+ if (!box || box.key !== key) {
596
+ box = { key, w: node.offsetWidth, h: node.offsetHeight };
597
+ hudClearSizes.set(node, box);
598
+ }
599
+ const down = pushBelow(boxAt(x, y, box.w, box.h, anchor), rect, undefined, window.innerHeight);
600
+ if (down > 0) {
601
+ moves.push([node, y + down]);
602
+ }
603
+ }
604
+ }
605
+ for (const [node, top] of moves) {
606
+ node.style.top = `${top}px`;
607
+ }
608
+ }
609
+
456
610
  return {
457
611
  setCover(alpha, text) {
458
612
  cover.style.opacity = String(alpha);
@@ -479,7 +633,25 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
479
633
  hudBig.textContent = big;
480
634
  hudBig.style.display = big ? 'block' : 'none';
481
635
  hudText.textContent = spec.text ?? '';
636
+ if (hudClear) {
637
+ layoutHudClear(big, spec.text ?? '');
638
+ }
482
639
  },
640
+ // Whether this place asks for a clear HUD (`hud.clear`, v1.26). Said each
641
+ // frame before `setHud`; never said true, nothing of it is drawn.
642
+ setHudClear(on) {
643
+ hudClear = on === true;
644
+ if (!hudClear && hudClearDrawn) {
645
+ restoreHudClear();
646
+ }
647
+ if (!hudClear) {
648
+ hudClearPending.clear();
649
+ }
650
+ },
651
+ // The end of a frame's drawing in a place with a clear HUD: everything
652
+ // the setters above asked to be kept clear of it is measured, then moved.
653
+ // Nothing asked (a place without the option): nothing read or written.
654
+ flushHudClear,
483
655
  // `items` is [{ id, x, y, text, speech, npc, color }] in CSS pixels (a
484
656
  // `color` is a player's mark); anything not
485
657
  // listed is removed.
@@ -544,6 +716,15 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
544
716
  labelNodes.delete(id);
545
717
  }
546
718
  }
719
+ if (hudClear) {
720
+ keepClearOfHud(
721
+ 'labels',
722
+ items.map((item) => {
723
+ const node = labelNodes.get(item.id);
724
+ return [node, parseFloat(node.style.left), item.y, 'bottom', item.text];
725
+ }),
726
+ );
727
+ }
547
728
  },
548
729
  // `item` is { id, rev, card, x, y, opacity } in CSS pixels, or null for no
549
730
  // card; `imageOf(value)` is a picture's `src`, or null for none.
@@ -567,6 +748,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
567
748
  const half = cabinet.offsetWidth / 2;
568
749
  cabinet.style.left = `${Math.min(Math.max(item.x, half + 6), window.innerWidth - half - 6)}px`;
569
750
  cabinet.style.top = `${Math.max(item.y, cabinet.offsetHeight + 6)}px`;
751
+ if (hudClear) {
752
+ keepClearOfHud('cabinet', [[cabinet, parseFloat(cabinet.style.left), parseFloat(cabinet.style.top), 'bottom', cabinetKey]]);
753
+ }
570
754
  // A board the player asked for is read whole, wherever they stand by it.
571
755
  cabinet.style.opacity = String(open ? 1 : item.opacity);
572
756
  },
@@ -581,6 +765,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
581
765
  if (ribbon.textContent !== text) {
582
766
  ribbon.textContent = text;
583
767
  }
768
+ if (hudClear) {
769
+ keepClearOfHud('ribbon', [[ribbon, pos.x, pos.y, 'bottom', text]]);
770
+ }
584
771
  },
585
772
  setToast(text) {
586
773
  toast.style.display = text ? 'block' : 'none';
@@ -597,6 +784,15 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
597
784
  button.style.borderColor = i === selected ? '#f2c94c' : 'rgba(255,255,255,0.4)';
598
785
  });
599
786
  },
787
+ // The Graphics row: `mode` is the one picked ('auto', 'low' or 'high').
788
+ setGraphics(mode, onPick) {
789
+ graphics ??= buildGraphics();
790
+ graphics.onPick = onPick;
791
+ for (const [m, button] of graphics.buttons) {
792
+ button.style.borderColor = m === mode ? '#f2c94c' : 'rgba(255,255,255,0.4)';
793
+ button.setAttribute('aria-pressed', String(m === mode));
794
+ }
795
+ },
600
796
  onTalk(handlers) {
601
797
  talkHandlers = handlers;
602
798
  },
@@ -653,6 +849,12 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
653
849
  if (key === sayKey && sayNote && chat && sayNote.textContent !== (chat.note ?? '')) {
654
850
  sayNote.textContent = chat.note ?? '';
655
851
  }
852
+ // The field's own words (a deck with cues, v1.23): rewritten in place
853
+ // too. A chat part that names none keeps 'Message…'.
854
+ if (key === sayKey && sayInput && chat?.placeholder && sayInput.placeholder !== chat.placeholder) {
855
+ sayInput.placeholder = chat.placeholder;
856
+ sayInput.setAttribute('aria-label', chat.label ?? chat.placeholder);
857
+ }
656
858
  if (key === sayKey) {
657
859
  return;
658
860
  }
@@ -690,7 +892,10 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
690
892
  const line = el('div', { display: 'flex', gap: '6px', opacity: chat.input ? '1' : '0.5' }, sayCard);
691
893
  const input = el('input', { flex: '1', minWidth: '0', padding: '7px 9px', borderRadius: '8px', border: '1px solid rgba(255,255,255,0.3)', background: 'rgba(255,255,255,0.1)', color: '#fff', font: '500 14px system-ui, sans-serif' }, line);
692
894
  input.maxLength = 200;
693
- input.placeholder = 'Message…';
895
+ input.placeholder = chat.placeholder ?? 'Message…';
896
+ if (chat.placeholder) {
897
+ input.setAttribute('aria-label', chat.label ?? chat.placeholder);
898
+ }
694
899
  // Shown even when it cannot be used, so chat can be found; the note says why.
695
900
  input.disabled = !chat.input;
696
901
  input.enterKeyHint = 'send';
@@ -795,10 +1000,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
795
1000
  talkButton.textContent = text;
796
1001
  }
797
1002
  },
798
- openTalk(name, note) {
1003
+ openTalk(name) {
799
1004
  talkOpen = true;
800
1005
  panelName.textContent = name;
801
- panelNote.textContent = note;
802
1006
  panelLog.replaceChildren();
803
1007
  panel.style.display = 'flex';
804
1008
  talkButton.style.display = 'none';
@@ -848,16 +1052,20 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
848
1052
  doorsList.replaceChildren();
849
1053
  for (const door of doors) {
850
1054
  const row = el('div', { display: 'flex', alignItems: 'center', gap: '8px' }, doorsList);
851
- const name = el('div', { flex: '1', minWidth: '0', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, row);
1055
+ // The title on a line of its own, with one short word under it on what
1056
+ // the door takes (a solo game, how many it needs): beside the button
1057
+ // they squeezed the title to a few letters.
1058
+ const words = el('div', { flex: '1', minWidth: '0' }, row);
1059
+ const name = el('div', { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, words);
852
1060
  name.textContent = `${door.featured ? '★ ' : ''}${door.title ?? door.id}`;
853
- // One short word on what the door takes: a solo game, or how many it needs.
854
1061
  const takes = door.solo ? 'solo' : door.need ? `needs ${door.need}` : '';
855
1062
  if (takes) {
856
- el('div', { flex: 'none', fontSize: '11px', fontWeight: '500', opacity: '0.7' }, row).textContent = takes;
1063
+ el('div', { fontSize: '11px', fontWeight: '500', opacity: '0.7' }, words).textContent = takes;
857
1064
  }
858
1065
  const go = el('button', { padding: '5px 12px', borderRadius: '12px', border: 'none', background: '#e9c48f', color: '#2b2118', font: '700 13px system-ui, sans-serif', cursor: 'pointer' }, row);
859
1066
  // A party cannot go together through a door that takes one player.
860
1067
  go.textContent = door.solo ? 'Go' : goText;
1068
+ go.style.flex = 'none';
861
1069
  go.addEventListener('pointerdown', (event) => {
862
1070
  event.stopPropagation();
863
1071
  closeDoors();
@@ -878,7 +1086,10 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
878
1086
  peopleKey = '';
879
1087
  return;
880
1088
  }
881
- const label = `People · ${people.length}`;
1089
+ // Everyone in this place, the player too: a count of the others read as
1090
+ // one short beside the avatars on screen. Friends elsewhere are rows of
1091
+ // the list, not people here.
1092
+ const label = `People · ${people.filter((p) => p.playerId).length + 1}`;
882
1093
  if (peopleButton.textContent !== label) {
883
1094
  peopleButton.textContent = label;
884
1095
  }
@@ -944,6 +1155,16 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
944
1155
  pointerNodes.delete(id);
945
1156
  }
946
1157
  }
1158
+ if (hudClear) {
1159
+ keepClearOfHud(
1160
+ 'pointers',
1161
+ items.map((item) => {
1162
+ const chip = pointerNodes.get(item.id).chip;
1163
+ const edge = item.angle !== null && item.angle !== undefined;
1164
+ return [chip, parseFloat(chip.style.left), item.y, edge ? 'center' : 'bottom', `${edge ? '>' : ''}${item.text}`];
1165
+ }),
1166
+ );
1167
+ }
947
1168
  },
948
1169
  // `ask` is { key, text, yes, no } (the words and the two buttons'), or
949
1170
  // null for none; an answer goes to `onAsk(ask, true | false)`.
@@ -986,6 +1207,9 @@ export function makeChrome({ onBack, onAvatar, avatarCount, onPerson = () => {},
986
1207
  }
987
1208
  },
988
1209
  dispose() {
1210
+ if (hudClearDrawn) {
1211
+ restoreHudClear();
1212
+ }
989
1213
  unguardKeys();
990
1214
  desktopQuery?.removeEventListener?.('change', layoutPanel);
991
1215
  root.remove();
@@ -10,6 +10,14 @@
10
10
  // server bounds those reports as before. A throw is the velocity it is let go
11
11
  // with. The place's server hears each grab and throw (`hub-grab`) and may
12
12
  // refuse a grab or end a hold (`hub-grab-deny`, `hub-drop`).
13
+ //
14
+ // A place may ask for a steadier offer (v1.22, `grab.reach` and
15
+ // `grab.steady`): a longer reach, and an offer that does not flicker at its
16
+ // edges. A place that asks for neither runs exactly the code it always did.
17
+ //
18
+ // A place may keep an object for one player (v1.27, `hub.keepFor`): it is
19
+ // never offered to anyone else, so the nearest object a player may take is
20
+ // the one offered. Where nothing is kept the offer is exactly what it was.
13
21
 
14
22
  import { hub } from './state.js';
15
23
 
@@ -31,12 +39,62 @@ const THROW_UP = 0.25;
31
39
  // After a throw, nothing is offered for this long: the object is still in
32
40
  // front of the player as it leaves.
33
41
  const REGRAB_MS = 400;
42
+ // v1.22, only where the place sets `grab.reach` or `grab.steady`: the centre
43
+ // of an offered object is never farther than this from the player's centre.
44
+ // The server refuses a grab past its GRAB_REACH (4 m, from the poses it has,
45
+ // which trail a moving player's: a grab can be heard before that frame's
46
+ // movement report). With `reach` or `steady`, the client keeps inside it by
47
+ // what the player may travel in that time at the speed they are moving now
48
+ // (their body's own velocity, so an authored speed, a tune, a jump and a tune
49
+ // not yet applied are all counted) or the speed they are tuned to, whichever
50
+ // is more. It is a margin, not a promise: a grab the server still refuses is
51
+ // let go, as any refused grab is (`hub-grab-deny`).
52
+ export const OFFER_CENTRE_M = 3;
53
+ const WALK_SPEED = 6; // the walk preset's speed, metres a second
54
+ const POSE_LAG_S = 0.2;
55
+ const LAG_SLACK_M = 0.25;
56
+ // `speed` is the controller's own (the kit's applyTune has already multiplied
57
+ // it by the tune); without one, the walk preset's times the tune.
58
+ export function offerCap(velocity = null, tune = hub.tune, speed = null) {
59
+ const moving = velocity ? Math.hypot(velocity.x ?? 0, velocity.y ?? 0, velocity.z ?? 0) : 0;
60
+ const tuned = Number(speed) > 0 ? Number(speed) : WALK_SPEED * Math.max(1, Number(tune?.speed) || 1);
61
+ return Math.max(0, Math.min(OFFER_CENTRE_M, 4 - LAG_SLACK_M - Math.max(moving, tuned) * POSE_LAG_S));
62
+ }
63
+ // The cap for this player now: their body's velocity and authored speed.
64
+ function capFor(scene, local) {
65
+ const body = scene.physics3d?.bodyOf?.(local.id);
66
+ return offerCap(body?.linvel?.() ?? null, hub.tune, local.components?.Player?.speed);
67
+ }
68
+ // v1.22 `grab.steady`: once an object is offered it stays the one offered
69
+ // while its near side is within the reach and this much more, and within 90
70
+ // degrees of facing. Through a moment where it is not (its owner briefly
71
+ // someone else, a turn past the cone, a step back), the button stays up for
72
+ // STEADY_GRACE_MS; a press then waits up to PRESS_WAIT_MS for the object to
73
+ // be this client's again, and is dropped if it never is.
74
+ export const KEEP_MARGIN_M = 0.4;
75
+ const KEEP_COS = 0;
76
+ export const STEADY_GRACE_MS = 600;
77
+ export const PRESS_WAIT_MS = 500;
78
+ // v1.25 `grab.keepHeld`: how often the server is told a hold goes on (its
79
+ // pin on the held object lasts 2.5 s past the last word).
80
+ export const KEEP_TELL_MS = 1000;
34
81
  // Where the walk preset's capsule stands (physics-3d `Player`): its radius and
35
82
  // height, and how far it hovers.
36
83
  const PLAYER = { radius: 0.35, height: 1.4, hover: 0.15 };
37
84
 
38
85
  export function makeGrab(chrome) {
39
- const t = { chrome, held: null, net: null, pressed: false, quietUntil: 0, lastAt: 0 };
86
+ const t = {
87
+ chrome,
88
+ held: null,
89
+ net: null,
90
+ pressed: false,
91
+ quietUntil: 0,
92
+ lastAt: 0,
93
+ // v1.22 `steady` only: the object kept on offer `{ id, okAt }`, and a press
94
+ // waiting for it `{ id, until }`.
95
+ offer: null,
96
+ waiting: null,
97
+ };
40
98
  chrome.onGrab?.(() => {
41
99
  t.pressed = true;
42
100
  });
@@ -77,6 +135,8 @@ function frame(t, scene, mp, local, idle) {
77
135
  // A new session: whatever was held belonged to the last one.
78
136
  t.net = net;
79
137
  t.held = null;
138
+ t.offer = null;
139
+ t.waiting = null;
80
140
  }
81
141
  const config = hub.place?.grab ?? null;
82
142
  const phys = scene.physics3d;
@@ -105,13 +165,34 @@ function frame(t, scene, mp, local, idle) {
105
165
  throwHeld(t, scene, body, local, config, net, now);
106
166
  } else {
107
167
  carry(t, scene, body, local, config, dt);
168
+ if (config.keepHeld === true) {
169
+ // v1.25: the server keeps a held object this client's only while it
170
+ // hears the hold goes on.
171
+ t.held.toldAt ??= now;
172
+ if (now - t.held.toldAt >= KEEP_TELL_MS) {
173
+ t.held.toldAt = now;
174
+ net.send({ k: 'hub-grab', actor: id, op: 'hold' });
175
+ }
176
+ }
108
177
  }
109
178
  }
110
179
  if (t.held) {
180
+ t.offer = null;
181
+ t.waiting = null;
111
182
  t.chrome.grabPrompt?.('Throw');
112
183
  return;
113
184
  }
114
- const target = can && now >= t.quietUntil ? grabbable(scene, mp, local) : null;
185
+ if (config?.steady === true) {
186
+ steadyFrame(t, scene, mp, local, config, net, can && now >= t.quietUntil, pressed, now, dt);
187
+ return;
188
+ }
189
+ const reach = config?.reach;
190
+ const target =
191
+ can && now >= t.quietUntil
192
+ ? reach === undefined
193
+ ? grabbable(scene, mp, local)
194
+ : grabbable(scene, mp, local, reach, FRONT_COS, capFor(scene, local))
195
+ : null;
115
196
  if (target && pressed) {
116
197
  const at = phys.bodyOf(target.id).translation();
117
198
  t.held = {
@@ -128,8 +209,83 @@ function frame(t, scene, mp, local, idle) {
128
209
  t.chrome.grabPrompt?.(target ? 'Grab' : null);
129
210
  }
130
211
 
131
- // The nearest object this client owns in front of the player, or null.
132
- function grabbable(scene, mp, local) {
212
+ // v1.22 `grab.steady`: the offer with hysteresis. Only an object that passes
213
+ // the full test this frame -- this client's own, in reach, in front -- is ever
214
+ // grabbed; the grace only keeps the button up and a press waiting.
215
+ function steadyFrame(t, scene, mp, local, config, net, active, pressed, now, dt) {
216
+ if (!active) {
217
+ t.offer = null;
218
+ t.waiting = null;
219
+ t.chrome.grabPrompt?.(null);
220
+ return;
221
+ }
222
+ const reach = config.reach ?? REACH_M;
223
+ const kept = t.offer;
224
+ // The kept object holds the offer on the wider test; when it fails this
225
+ // frame (or there is none), one passing the ordinary test takes over.
226
+ const ready =
227
+ (kept &&
228
+ grabbable(scene, mp, local, reach + KEEP_MARGIN_M, KEEP_COS, capFor(scene, local), kept.id)) ||
229
+ grabbable(scene, mp, local, reach, FRONT_COS, capFor(scene, local));
230
+ if (ready) {
231
+ t.offer = { id: ready.id, okAt: now };
232
+ } else if (kept && (now - kept.okAt > STEADY_GRACE_MS || !stillThere(scene, kept.id, mp))) {
233
+ t.offer = null;
234
+ }
235
+ if (t.waiting && (now > t.waiting.until || !stillThere(scene, t.waiting.id, mp))) {
236
+ t.waiting = null;
237
+ }
238
+ if (pressed && (ready || t.offer)) {
239
+ const id = ready?.id ?? t.offer.id;
240
+ t.waiting = { id, until: now + PRESS_WAIT_MS };
241
+ }
242
+ if (!ready || t.waiting?.id !== ready.id) {
243
+ t.chrome.grabPrompt?.(t.offer || t.waiting ? 'Grab' : null);
244
+ return;
245
+ }
246
+ t.waiting = null;
247
+ t.offer = null;
248
+ const body = scene.physics3d.bodyOf(ready.id);
249
+ const at = body.translation();
250
+ t.held = {
251
+ id: ready.id,
252
+ extent: ready.extent,
253
+ half: ready.half,
254
+ at: { x: at.x, y: at.y, z: at.z },
255
+ };
256
+ net.send({ k: 'hub-grab', actor: ready.id, op: 'grab' });
257
+ carry(t, scene, body, local, config, dt);
258
+ t.chrome.grabPrompt?.('Throw');
259
+ }
260
+
261
+ // Whether an object kept on offer can still come back: in the scene, not
262
+ // hidden by the place, not kept for someone else (v1.27). Anything else may
263
+ // change within a grace.
264
+ function stillThere(scene, id, mp) {
265
+ return Boolean(scene.getActor(id)) && !hub.hidden.has(id) && !keptFromMe(mp, id);
266
+ }
267
+
268
+ // v1.27 `hub.keepFor`: whether the place keeps this object for another player.
269
+ // False for every object where nothing is kept.
270
+ function keptFromMe(mp, id) {
271
+ return hub.keptFor.size > 0 && hub.keptFor.has(id) && hub.keptFor.get(id) !== mp.net?.selfId?.();
272
+ }
273
+
274
+ // The nearest object this client owns in front of the player, or null; one the
275
+ // place keeps for someone else (v1.27) is passed over for the next nearest. With
276
+ // no more arguments it is the test every place had before v1.22; `reach`,
277
+ // `cos` and `centre` (the farthest an object's centre may be from the
278
+ // player's) carry a place's `grab.reach` and `grab.steady`, and `only` limits
279
+ // the test to one object.
280
+ function grabbable(
281
+ scene,
282
+ mp,
283
+ local,
284
+ reach = REACH_M,
285
+ cos = FRONT_COS,
286
+ centre = Infinity,
287
+ only = null,
288
+ ) {
133
289
  const mine = mp.own?.mine;
134
290
  if (!mine?.size || typeof mp.claimable !== 'function') {
135
291
  return null;
@@ -140,7 +296,7 @@ function grabbable(scene, mp, local) {
140
296
  const fz = Math.cos(f);
141
297
  let best = null;
142
298
  for (const [id, at] of mp.claimable(scene)) {
143
- if (!mine.has(id) || hub.hidden.has(id)) {
299
+ if ((only !== null && id !== only) || !mine.has(id) || hub.hidden.has(id) || keptFromMe(mp, id)) {
144
300
  continue;
145
301
  }
146
302
  const actor = scene.getActor(id);
@@ -151,10 +307,13 @@ function grabbable(scene, mp, local) {
151
307
  const dx = at.x - me.x;
152
308
  const dz = at.z - me.z;
153
309
  const d = Math.hypot(dx, dz);
154
- if (size.extent > MAX_EXTENT || d - size.extent > REACH_M || Math.abs(at.y - me.y) > RISE_M) {
310
+ if (size.extent > MAX_EXTENT || d - size.extent > reach || Math.abs(at.y - me.y) > RISE_M) {
311
+ continue;
312
+ }
313
+ if (d > 0.01 && (dx * fx + dz * fz) / d < cos) {
155
314
  continue;
156
315
  }
157
- if (d > 0.01 && (dx * fx + dz * fz) / d < FRONT_COS) {
316
+ if (Math.hypot(d, at.y - me.y) > centre) {
158
317
  continue;
159
318
  }
160
319
  if (!best || d < best.d) {
@@ -0,0 +1,26 @@
1
+ // The hats this kit draws (contract §11): a wearable whose `kind` is
2
+ // `hat-<id>` for an id here. Ids only, and nothing imported, so a place's
3
+ // server may read the list (`@imports/castle.hub-game/code/client/hats.js`)
4
+ // to offer exactly the hats every client can draw; how each one is built is
5
+ // `wear.js`'s.
6
+ export const HAT_PREFIX = 'hat-';
7
+
8
+ export const HAT_SETS = {
9
+ stadium: ['sweatband', 'cap', 'foam-crown', 'laurel'],
10
+ hollow: ['bat-clip', 'witch', 'lantern', 'crooked-top'],
11
+ sunny: ['straw', 'flower-crown', 'beekeeper', 'sunflower'],
12
+ harbour: ['sailor', 'souwester', 'captain', 'lighthouse'],
13
+ };
14
+
15
+ export const HATS = Object.values(HAT_SETS).flat();
16
+
17
+ // The wearable kind of a hat id, and the hat id of a kind (null for a kind
18
+ // that is not one of these hats).
19
+ export function hatKind(id) {
20
+ return `${HAT_PREFIX}${id}`;
21
+ }
22
+
23
+ export function hatId(kind) {
24
+ const id = typeof kind === 'string' && kind.startsWith(HAT_PREFIX) ? kind.slice(HAT_PREFIX.length) : null;
25
+ return HATS.includes(id) ? id : null;
26
+ }