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
@@ -7,7 +7,8 @@
7
7
  // ribbon, the avatar the player wears everywhere, grabbing and throwing
8
8
  // the place's loose objects where it offers that (`client/grab.js`), and idle
9
9
  // play -- emotes, seats and the place's sounds -- where it offers that
10
- // (`client/idle.js`, `client/sound.js`).
10
+ // (`client/idle.js`, `client/sound.js`), and, in a deck that asks for it, a
11
+ // cheaper picture on a slow device (`client/tiers.js`).
11
12
  //
12
13
  // One engine, one iframe (HUB.md decision 2): going through a door unloads this
13
14
  // place's scene, loads the next one's (`scene.requestedScene`), and moves the
@@ -35,6 +36,7 @@ import { makeIdle } from '../client/idle.js';
35
36
  import { makeSay, REACTIONS } from '../client/say.js';
36
37
  import { makeSound } from '../client/sound.js';
37
38
  import { makeTalk } from '../client/talk.js';
39
+ import { makeTiers } from '../client/tiers.js';
38
40
  import { makeTogether, pointerAt } from '../client/together.js';
39
41
  import { makeWear } from '../client/wear.js';
40
42
 
@@ -71,6 +73,38 @@ const TICKETS_MAX = 4;
71
73
  // How often a place asks the host who of the player's friends is in its other
72
74
  // layers, while the player is there and idle.
73
75
  const FRIENDS_EVERY_MS = 20000;
76
+ // Cues (v1.23): while someone here is not named by the host as a friend, the
77
+ // host is asked again a few times (`together.due`) -- one such ask in this
78
+ // long at most on average, however many come in: 15 a minute (16 in the
79
+ // worst-placed one), never a 2 s poll. v1.32: counted as two in any twice this long, this far apart at
80
+ // least, so an ask the host answered a moment too soon (it knows a join
81
+ // within a few seconds) is put again while it matters.
82
+ const FRIENDS_EARLY_MS = 4000;
83
+ const FRIENDS_EARLY_PAIR_MS = 2000;
84
+ // ...and never this soon after any ask, the cadence's own included (v1.31:
85
+ // 1 s, with the first extra ask 1 s after someone is seen; were 2 s).
86
+ const FRIENDS_EARLY_AFTER_MS = 1000;
87
+ // Cues: a friend found already here is told to the player when no other
88
+ // toast is up, and not at all once this long has passed.
89
+ const HERE_CUE_MS = 15000;
90
+ // Cues: the party the place first tells a session about is the one the player
91
+ // already had; only a change after this long is a join worth a toast.
92
+ const PARTY_SETTLE_MS = 5000;
93
+ const PARTY_CARRY_MS = 30000;
94
+ // Cues: an accepted invitation is this player's own join for this long.
95
+ const PARTY_ACCEPT_MS = 10000;
96
+ // Cues: the chat field's own words. The field is about 20 characters wide,
97
+ // so the whole sentence is its accessible label and the note above it.
98
+ const CHAT_HINT = {
99
+ on: 'To your follows…',
100
+ // v1.29: one field and one sentence for every reason it cannot be used, so
101
+ // neither says which reason it is (never a player's age).
102
+ off: 'Friends only',
103
+ why: 'Typed chat is for friends who follow each other. Emotes work with everyone.',
104
+ label: 'Message · only players you follow each other with',
105
+ };
106
+ // Cues (v1.29): how long a player back from a game is offered it again.
107
+ const AGAIN_ASK_MS = 20000;
74
108
  // Starting next to a friend: how long after walking in a friend found here
75
109
  // still moves the player beside them, and how far the player may have walked.
76
110
  const START_NEAR_MS = 12000;
@@ -79,6 +113,8 @@ const START_NEAR_STAY_M = 4;
79
113
  const JUMP_GAP_MS = 1100;
80
114
  // How long "Let's play <door>" from someone here is offered as a Go.
81
115
  const PLAY_ASK_MS = 20000;
116
+ // How long "<friend> went into <door>" is offered as a Follow.
117
+ const WENT_ASK_MS = 45000;
82
118
  // The same player naming the same door is not offered again inside this.
83
119
  const PLAY_ASK_AGAIN_MS = 60000;
84
120
  // A cabinet (v1.7): how long the cover waits for the host to say it is playing
@@ -187,8 +223,27 @@ class HubSystem {
187
223
  // `${playerId}:${door}` -> when each was last offered.
188
224
  this.playAsk = null;
189
225
  this.playAsked = new Map();
226
+ // A friend who went through a door while the question could not be put.
227
+ this.wentAsk = null;
228
+ // Cues (v1.29): the game this player just came back from, offered again.
229
+ this.againAsk = null;
190
230
  this.chat = makeChat();
191
231
  this.namesTouched = new WeakMap();
232
+ // Cues (v1.23), all unused in a deck without `hub.cues`: when the host
233
+ // was last asked early for the friends; friends found already here, not
234
+ // yet told; the friend the player was just put beside; the roster as of
235
+ // the last frame; and the party as of the last frame, with what tells a
236
+ // party the player already had from one they just joined.
237
+ this.friendsEarlyAt = -Infinity;
238
+ this.friendsEarlyBeforeAt = -Infinity;
239
+ this.friendsSentAt = -Infinity;
240
+ this.hereCues = [];
241
+ this.besideTold = null;
242
+ this.rosterSeen = new Set();
243
+ this.partyLast = null;
244
+ this.partySettleUntil = 0;
245
+ this.partyCarryUntil = 0;
246
+ this.partyAccepted = null;
192
247
  }
193
248
 
194
249
  // Other players' names in a town: near ones only, and smaller
@@ -256,13 +311,7 @@ class HubSystem {
256
311
  // network pose each frame, which would lift a hidden one back up.
257
312
  if (this.lateFor !== scene && typeof scene.registerSystem === 'function') {
258
313
  this.lateFor = scene;
259
- scene.registerSystem({
260
- afterBehaviors: (s) => {
261
- this.applyVisibility(s);
262
- this.applyWear(s);
263
- this.fadeNames(s);
264
- },
265
- });
314
+ this.registerLate(scene);
266
315
  }
267
316
  this.applyVisibility(scene);
268
317
  this.applyWear(scene);
@@ -281,6 +330,11 @@ class HubSystem {
281
330
  this.sound.frame(scene, local, !this.trip);
282
331
  if (this.trip || held || this.talk.typing() || this.chrome.chatFocused?.()) {
283
332
  lockInput(scene);
333
+ // Under the engine's orbit camera key the player's drags and wheel do
334
+ // not move the trip's camera, nor queue up for after it.
335
+ if (this.trip && scene.cameraControl === 'orbit') {
336
+ scene.lookInput?.lock?.();
337
+ }
284
338
  }
285
339
  // Grabbing and throwing (v1.3), in a place that offers it: after this
286
340
  // frame's physics step, before the multiplayer kit reports what it owns.
@@ -295,6 +349,46 @@ class HubSystem {
295
349
  this.measure(scene, mp, now);
296
350
  }
297
351
 
352
+ // Device tiers (`client/tiers.js`), only in a deck whose castle.json asks
353
+ // (`hub.tiers`): without it this is never called, nothing of theirs is made
354
+ // or run, and the place is drawn and behaves exactly as it did. A frame
355
+ // counts toward the judge only while the player is placed and no trip or
356
+ // ending is under way: a scene swap's frames say nothing about how this
357
+ // device draws the place.
358
+ deviceTier(scene, mp, now) {
359
+ if (!Hub.deck.tiers) {
360
+ return;
361
+ }
362
+ if (!this.tiers) {
363
+ this.tiers = makeTiers();
364
+ const pick = (mode) => {
365
+ this.tiers.set(mode);
366
+ this.chrome?.setGraphics?.(this.tiers.mode, pick);
367
+ };
368
+ this.chrome?.setGraphics?.(this.tiers.mode, pick);
369
+ }
370
+ const counts = !this.trip && this.pendingEnd === null && mp?.placed?.() === true;
371
+ this.tiers.frame(scene, counts, now);
372
+ globalThis.__hub.tier = this.tiers.handle;
373
+ }
374
+
375
+ // The systems that run after every other one, registered once per runtime.
376
+ registerLate(scene) {
377
+ scene.registerSystem({
378
+ afterBehaviors: (s) => {
379
+ this.applyVisibility(s);
380
+ this.applyWear(s);
381
+ this.fadeNames(s);
382
+ },
383
+ });
384
+ // Device tiers run as a system of their own, registered only in a deck
385
+ // that asks (`deck.tiers` is read once, as the page loads): a deck without
386
+ // it runs exactly the frame it always did.
387
+ if (Hub.deck.tiers) {
388
+ scene.registerSystem({ afterBehaviors: (s) => this.deviceTier(s, s.multiplayer, performance.now()) });
389
+ }
390
+ }
391
+
298
392
  // The places this player will walk back into stay built while they are away
299
393
  // (physics-3d's `residentScenes`): a return redraws the town from the nodes
300
394
  // it left, rather than rebuilding every mesh behind the door.
@@ -347,6 +441,8 @@ class HubSystem {
347
441
  this.say.clear();
348
442
  this.together.clear();
349
443
  this.playAsk = null;
444
+ this.wentAsk = null;
445
+ this.againAsk = null;
350
446
  this.playAsked.clear();
351
447
  }
352
448
 
@@ -369,10 +465,22 @@ class HubSystem {
369
465
  applyWear(scene) {
370
466
  const self = scene.multiplayer?.net?.selfId?.() ?? null;
371
467
  const style = Avatar.style();
372
- this.wear.frame(scene, scene.actorWith('Player'), Hub.hub.wearing, (playerId) => {
373
- const index = playerId === self ? Avatar.current(scene) : Hub.hub.avatars.get(playerId);
374
- return Avatar.top(index, Avatar.drawn(scene.files, index, style));
375
- });
468
+ const indexOf = (playerId) => (playerId === self ? Avatar.current(scene) : Hub.hub.avatars.get(playerId));
469
+ this.wear.frame(
470
+ scene,
471
+ scene.actorWith('Player'),
472
+ Hub.hub.wearing,
473
+ (playerId) => {
474
+ const index = indexOf(playerId);
475
+ return Avatar.top(index, Avatar.drawn(scene.files, index, style));
476
+ },
477
+ undefined,
478
+ // Asked only for a player wearing a hat.
479
+ (playerId) => {
480
+ const index = indexOf(playerId);
481
+ return Avatar.hatFit(index, Avatar.drawn(scene.files, index, style));
482
+ },
483
+ );
376
484
  }
377
485
 
378
486
  // The place's tuning of this player's own controller (`hub.tune`): the
@@ -440,8 +548,20 @@ class HubSystem {
440
548
  this.say.clear();
441
549
  this.together.clear();
442
550
  this.playAsk = null;
551
+ this.wentAsk = null;
552
+ this.againAsk = null;
443
553
  this.playAsked.clear();
444
554
  this.chat.reset();
555
+ if (Hub.deck.cues) {
556
+ this.hereCues = [];
557
+ this.besideTold = null;
558
+ this.rosterSeen = new Set();
559
+ // The party this session is first told of is the one the player had.
560
+ this.partyCarryUntil = this.partyLast?.members ? performance.now() + PARTY_CARRY_MS : 0;
561
+ this.partyLast = null;
562
+ this.partySettleUntil = performance.now() + PARTY_SETTLE_MS;
563
+ this.partyAccepted = null;
564
+ }
445
565
  }
446
566
  this.helloNet = net;
447
567
  this.helloAvatar = avatar;
@@ -555,7 +675,18 @@ class HubSystem {
555
675
 
556
676
  // The session under this player ended without a trip of ours: the game's
557
677
  // server crashed or was replaced. A game is left through the door the player
558
- // came in by (contract §5); anywhere else the multiplayer kit rejoins.
678
+ // came in by (contract §5); anywhere else the multiplayer kit rejoins, but
679
+ // only a join it can make again. A player who came back to the town through
680
+ // a door is there by a hub join, whose handoff is spent: when the town's own
681
+ // server is replaced under them (a new version saved) nothing would join
682
+ // again and the town would stand there dead, so the join this runtime began
683
+ // with is made again, as a lost join at the root of the trail is. Deeper on
684
+ // the host's trail (a place behind a door) there is no join to make again
685
+ // from where the player stands -- the host's doors are this place's own, and
686
+ // only a new acquisition names the new version's content -- so the player is
687
+ // sent back the way they came, as from a game, and walks in again through
688
+ // the door. Once per close: `lastNet` is forgotten, the way back is a trip,
689
+ // and one that is refused leaves the host's Back to ask again.
559
690
  watchSession(scene, mp) {
560
691
  if (this.trip) {
561
692
  // Our own switch closes the old connection; that is not an ending.
@@ -571,10 +702,24 @@ class HubSystem {
571
702
  }
572
703
  this.lastNet = null;
573
704
  const inGame = Boolean(Hub.hub.place?.result);
705
+ const barred = last.closeError?.() === HUB_BANNED;
574
706
  Hub.clear();
575
707
  if (inGame && scene.persistent.hubTickets.length) {
576
708
  this.toast = { text: 'The game ended', until: performance.now() + TOAST_MS };
577
709
  this.back(scene);
710
+ } else if (!inGame && !barred && mp.target?.mode === 'hub' && !(scene.persistent.hubDepth > 0)) {
711
+ console.warn('[hub-door] this place ended under a hub join: joining it again');
712
+ mp.switchSession(scene, scene.persistent.hubRootJoin ?? { mode: 'public' });
713
+ this.helloNet = null;
714
+ this.toast = { text: 'Reconnecting…', until: performance.now() + TOAST_MS };
715
+ } else if (!inGame && !barred && mp.target?.mode === 'hub') {
716
+ console.warn('[hub-door] this place ended under a hub join behind a door: leaving by its way back');
717
+ const title = scene.persistent.hubTickets.at(-1)?.title;
718
+ this.toast = {
719
+ text: title ? `This place was updated. Back to ${title}…` : 'This place was updated. Going back…',
720
+ until: performance.now() + TOAST_MS,
721
+ };
722
+ this.back(scene);
578
723
  }
579
724
  }
580
725
 
@@ -980,11 +1125,39 @@ class HubSystem {
980
1125
  }
981
1126
  const place = Hub.hub.place;
982
1127
  const idle = !this.trip && this.pendingEnd === null && (mp.joinState?.() ?? 'joined') === 'joined';
983
- if (!place || place.result || !idle || now - this.friendsAt < FRIENDS_EVERY_MS) {
1128
+ if (!place || place.result || !idle) {
1129
+ return;
1130
+ }
1131
+ // Cues (v1.23): someone here is not named by the host as a friend, and
1132
+ // may be one it has not heard is here yet (it learns presence on a
1133
+ // heartbeat), so the host is asked again when `together.due` says, not
1134
+ // at the end of its 20 s. Every bound is measured from asks that were
1135
+ // really sent: at most two such asks in any 8 s, 2 s apart, none within
1136
+ // 1 s of any ask.
1137
+ // One that cannot be sent (a trip, a join still pending) reaches none of
1138
+ // this and is simply tried again when it can be, owing nothing it missed.
1139
+ const onTime = now - this.friendsAt >= FRIENDS_EVERY_MS;
1140
+ const early =
1141
+ !onTime &&
1142
+ Hub.deck.cues &&
1143
+ now - this.friendsEarlyAt >= FRIENDS_EARLY_PAIR_MS &&
1144
+ now - this.friendsEarlyBeforeAt >= 2 * FRIENDS_EARLY_MS &&
1145
+ now - this.friendsSentAt >= FRIENDS_EARLY_AFTER_MS &&
1146
+ this.together.due(this.friendsAll, now);
1147
+ if (!onTime && !early) {
984
1148
  return;
985
1149
  }
986
1150
  this.friendsAt = now;
987
1151
  this.friendsAsking = true;
1152
+ if (Hub.deck.cues) {
1153
+ // Sent: the bounds count from here, and the steps come due are spent.
1154
+ this.friendsSentAt = now;
1155
+ if (early) {
1156
+ this.friendsEarlyBeforeAt = this.friendsEarlyAt;
1157
+ this.friendsEarlyAt = now;
1158
+ }
1159
+ this.together.asked(now);
1160
+ }
988
1161
  const key = this.sceneKey;
989
1162
  Promise.resolve(castleSdk.Hub.friends())
990
1163
  .then((answer) => {
@@ -1105,6 +1278,8 @@ class HubSystem {
1105
1278
  this.startNear = null;
1106
1279
  if (name) {
1107
1280
  this.toast = { text: `You're next to ${name}`, until: now + TOAST_MS };
1281
+ // Cues: this friend has been told; "is here" would say it twice.
1282
+ this.besideTold = start.asked;
1108
1283
  }
1109
1284
  return;
1110
1285
  }
@@ -1134,6 +1309,21 @@ class HubSystem {
1134
1309
  }
1135
1310
  }
1136
1311
 
1312
+ // Why chat reaches nobody when a friend exists but is not in this layer:
1313
+ // "amy is in Tile Fall · chat when they're back". Only the friends the
1314
+ // People list also names: one inside a game behind one of this town's
1315
+ // doors, or in another layer of it. Null when there is nobody to name.
1316
+ awayNote() {
1317
+ const title = (door) => Hub.hub.doors.find((d) => d.id === door)?.title ?? null;
1318
+ const rows = (this.friendsAll ?? []).filter((f) => f && !f.here && (typeof f.door !== 'string' || title(f.door)));
1319
+ const away = rows.find((f) => typeof f.door === 'string') ?? rows[0];
1320
+ if (!away) {
1321
+ return null;
1322
+ }
1323
+ const where = typeof away.door === 'string' ? `in ${title(away.door)}` : 'in another part of town';
1324
+ return `${away.username ?? 'Your friend'} is ${where} · chat when they're back`;
1325
+ }
1326
+
1137
1327
  // A pick from the speech card: a reaction or a phrase goes to the place; a
1138
1328
  // typed line goes to the host, which sends it to whoever ghost lets read it.
1139
1329
  saying(what) {
@@ -1142,7 +1332,10 @@ class HubSystem {
1142
1332
  return;
1143
1333
  }
1144
1334
  this.chat.send(what.text, (status) => {
1145
- const text = status === 'none' ? 'Nobody here can read that. Follow each other to chat.' : status === 'limited' ? 'Slow down a little.' : status === 'sent' ? null : "That didn't send.";
1335
+ // A sent line says whom it went to: there is no other sign it arrived.
1336
+ const to = this.chatReach ?? [];
1337
+ const sent = to.length ? `Sent to ${to.slice(0, 3).join(', ')}${to.length > 3 ? ` +${to.length - 3}` : ''}` : null;
1338
+ const text = status === 'none' ? 'Nobody here can read that. Follow each other to chat.' : status === 'limited' ? 'Slow down a little.' : status === 'sent' ? sent : "That didn't send.";
1146
1339
  if (text) {
1147
1340
  this.toast = { text, until: performance.now() + TOAST_MS };
1148
1341
  }
@@ -1167,11 +1360,26 @@ class HubSystem {
1167
1360
  const play = this.playAsk;
1168
1361
  if (play && performance.now() < play.until && Hub.hub.doors.some((d) => d.id === play.door) && !invite) {
1169
1362
  const title = Hub.hub.doors.find((d) => d.id === play.door)?.title ?? 'a game';
1170
- return { key: `play:${play.from}:${play.door}:${play.until}`, kind: 'play', door: play.door, text: `${play.name}: let's play ${title}`, yes: 'Go', no: 'Not now' };
1363
+ // A game that takes no late joiners cannot be followed into: the player
1364
+ // is told where their friend is, and that they will be back.
1365
+ const late = Hub.hub.doors.find((d) => d.id === play.door)?.late === true;
1366
+ if (play.went && !late) {
1367
+ return { key: `play:${play.from}:${play.door}:${play.until}`, kind: 'play', door: null, text: `${play.name} went into ${title} · back soon`, yes: 'OK', no: 'Go to the door' };
1368
+ }
1369
+ const text = play.went ? `${play.name} went into ${title}` : `${play.name}: let's play ${title}`;
1370
+ return { key: `play:${play.from}:${play.door}:${play.until}`, kind: 'play', door: play.door, text, yes: play.went ? 'Follow' : 'Go', no: 'Not now' };
1171
1371
  }
1172
1372
  if (invite) {
1173
1373
  return { key: `invite:${invite.from}`, kind: 'invite', from: invite.from, text: `${invite.username ?? 'Someone'} invited you to their party`, yes: 'Join party', no: 'No thanks' };
1174
1374
  }
1375
+ // Cues (v1.29): back from a game with nothing else asked -- the same game
1376
+ // again, with the party when there is one (the Doors list's own Go).
1377
+ const again = Hub.deck.cues ? this.againAsk : null;
1378
+ const door = again && performance.now() < again.until ? Hub.hub.doors.find((d) => d.id === again.door) : null;
1379
+ if (door) {
1380
+ const together = Hub.hub.party.members?.length && !door.solo;
1381
+ return { key: `again:${again.door}:${again.until}`, kind: 'again', door: door.id, text: `Play ${door.title ?? 'that'} again${together ? ' together' : ''}?`, yes: together ? 'Go together' : 'Play again', no: 'Not now' };
1382
+ }
1175
1383
  return null;
1176
1384
  }
1177
1385
 
@@ -1180,10 +1388,27 @@ class HubSystem {
1180
1388
  if (!net || !ask) {
1181
1389
  return;
1182
1390
  }
1391
+ if (ask.kind === 'again') {
1392
+ // Only the offer that is up: one whose time ran out, or that a later
1393
+ // return replaced, is answered by nothing.
1394
+ const again = this.againAsk;
1395
+ if (!Hub.deck.cues || !again || ask.key !== `again:${again.door}:${again.until}` || performance.now() >= again.until) {
1396
+ return;
1397
+ }
1398
+ this.againAsk = null;
1399
+ if (yes) {
1400
+ this.goDoor(scene, Hub.hub.doors.find((d) => d.id === again.door));
1401
+ }
1402
+ return;
1403
+ }
1183
1404
  if (ask.kind === 'play') {
1405
+ // "Back soon" (no door on the question): OK stays, the other button
1406
+ // goes to wait at the door.
1407
+ const door = ask.door ?? (yes ? null : this.playAsk?.door ?? null);
1408
+ const go = ask.door ? yes : !yes;
1184
1409
  this.playAsk = null;
1185
- if (yes) {
1186
- this.sendJump(net, { k: 'hub-door-jump', door: ask.door });
1410
+ if (go && door) {
1411
+ this.sendJump(net, { k: 'hub-door-jump', door });
1187
1412
  }
1188
1413
  return;
1189
1414
  }
@@ -1192,6 +1417,67 @@ class HubSystem {
1192
1417
  net.send({ k: 'hub-party', op: yes ? 'go-yes' : 'go-no', id: ask.id });
1193
1418
  } else {
1194
1419
  net.send({ k: 'hub-party', op: yes ? 'accept' : 'decline', from: ask.from });
1420
+ if (Hub.deck.cues && yes) {
1421
+ // Cues: the party that comes of this is one the player joined.
1422
+ this.partyAccepted = { from: ask.from, username: Hub.hub.party.invite?.username ?? null, until: performance.now() + PARTY_ACCEPT_MS };
1423
+ }
1424
+ }
1425
+ }
1426
+
1427
+ // Cues (v1.23): the friends found already in this layer are told to the
1428
+ // player ("amy is here") and pointed to, one at a time and never over
1429
+ // another toast -- the result line of a game just left, or "You're next to
1430
+ // amy", which says it already.
1431
+ cueHere(now) {
1432
+ const waiting = [];
1433
+ for (const who of this.hereCues) {
1434
+ // Gone, or no longer a friend the player can see, since it was queued:
1435
+ // nothing is said of someone who is not here.
1436
+ if (this.besideTold === who.playerId || now > who.until || !this.together.close(who.playerId)) {
1437
+ continue;
1438
+ }
1439
+ // A start beside a friend still to be asked for, or asked for this one:
1440
+ // its own toast may be about to say it.
1441
+ if ((this.startNear && (!this.startNear.asked || this.startNear.asked === who.playerId)) || now < this.toast.until) {
1442
+ waiting.push(who);
1443
+ continue;
1444
+ }
1445
+ this.toast = { text: `${who.username ?? 'A friend'} is here · People to join`, until: now + TOAST_MS };
1446
+ this.together.ping(who.playerId, now, true);
1447
+ }
1448
+ this.hereCues = waiting;
1449
+ }
1450
+
1451
+ // Cues (v1.23): a party that gained someone says so -- "You joined amy's
1452
+ // party" to the one who accepted, "bo joined your party" to the rest. Not
1453
+ // the party a session is first told of (the player had it already), and
1454
+ // not a member back from a game (one fewer is away).
1455
+ cueParty(net, now) {
1456
+ if (this.trip) {
1457
+ return;
1458
+ }
1459
+ const cur = Hub.hub.party;
1460
+ const prev = this.partyLast;
1461
+ this.partyLast = { members: cur.members ? [...cur.members] : null, away: cur.away };
1462
+ if (!prev || now < this.partySettleUntil) {
1463
+ return;
1464
+ }
1465
+ const gained = (cur.members ?? []).filter((id) => !prev.members?.includes(id));
1466
+ if (!gained.length || cur.away < prev.away) {
1467
+ return;
1468
+ }
1469
+ if (!prev.members && now < this.partyCarryUntil) {
1470
+ this.partyCarryUntil = 0;
1471
+ return;
1472
+ }
1473
+ const accepted = this.partyAccepted;
1474
+ this.partyAccepted = null;
1475
+ const nameOf = (playerId) => net?.others?.().get(playerId) || null;
1476
+ if (accepted && now < accepted.until && cur.members.includes(accepted.from)) {
1477
+ const name = accepted.username ?? nameOf(accepted.from);
1478
+ this.toast = { text: name ? `You joined ${name}'s party` : 'You joined the party', until: now + TOAST_MS };
1479
+ } else {
1480
+ this.toast = { text: `${nameOf(gained[0]) ?? 'Someone'} joined your party`, until: now + TOAST_MS };
1195
1481
  }
1196
1482
  }
1197
1483
 
@@ -1770,6 +2056,11 @@ class HubSystem {
1770
2056
  faceArrival(scene) {
1771
2057
  if (Hub.hub.arrivedFacing !== null) {
1772
2058
  scene.persistent.camAngle = Math.PI - Hub.hub.arrivedFacing;
2059
+ // Under the engine's orbit camera key the character's facing is not
2060
+ // PI - camAngle: it is asked for.
2061
+ if (scene.cameraControl === 'orbit') {
2062
+ scene.faceRequest = Hub.hub.arrivedFacing;
2063
+ }
1773
2064
  Hub.hub.faced = true;
1774
2065
  }
1775
2066
  }
@@ -1818,6 +2109,11 @@ class HubSystem {
1818
2109
  if (trip.target.arrive?.returning && r) {
1819
2110
  this.toast = { text: `Back from ${resultLine(r)}`, until: performance.now() + TOAST_MS };
1820
2111
  }
2112
+ if (Hub.deck.cues && trip.target.arrive?.returning && trip.target.arrive.door) {
2113
+ // Cues: a next step, put once the player is back in the town, whether
2114
+ // or not the game had a result to tell.
2115
+ this.againAsk = { door: trip.target.arrive.door, until: performance.now() + AGAIN_ASK_MS };
2116
+ }
1821
2117
  }
1822
2118
 
1823
2119
  // Swing a door leaf open by `amount` (0 shut, 1 open) about its left edge,
@@ -1863,11 +2159,38 @@ class HubSystem {
1863
2159
  chrome.setPeople?.(free ? this.people(scene, inGame) : null, town ? this.together.partyLine() : null);
1864
2160
  chrome.setAsk?.(town ? this.ask() : null);
1865
2161
  this.startBeside(scene, local, town, now);
2162
+ // A friend or party member went through a door: say so, and offer to follow.
2163
+ // Kept until the question can be put (not while talking to an NPC): the
2164
+ // name is taken now, while the friend is still remembered.
2165
+ for (const went of Hub.hub.wentEvents.splice(0)) {
2166
+ const name = place && !inGame ? went.players.map((id) => this.together.lately(id)).find(Boolean) : null;
2167
+ if (name) {
2168
+ this.wentAsk = { from: went.players[0], name, door: went.door, until: now + WENT_ASK_MS, went: true };
2169
+ }
2170
+ }
2171
+ if (town && this.wentAsk) {
2172
+ if (now < this.wentAsk.until && Hub.hub.doors.some((d) => d.id === this.wentAsk.door)) {
2173
+ this.playAsk = this.wentAsk;
2174
+ }
2175
+ this.wentAsk = null;
2176
+ }
1866
2177
  // A friend or party member who just came in: say so, and point to them.
1867
2178
  for (const who of town ? this.together.arrivals() : []) {
2179
+ // Cues: one who was here already (`here`, never set without cues)
2180
+ // waits its turn in `cueHere`.
2181
+ if (who.here) {
2182
+ this.hereCues.push({ ...who, until: now + HERE_CUE_MS });
2183
+ continue;
2184
+ }
1868
2185
  this.toast = { text: `${who.username ?? 'A friend'} is here · People to join`, until: now + TOAST_MS };
1869
2186
  this.together.ping(who.playerId, now, true);
1870
2187
  }
2188
+ if (Hub.deck.cues && town) {
2189
+ this.cueHere(now);
2190
+ }
2191
+ if (Hub.deck.cues && place !== null && !inGame) {
2192
+ this.cueParty(scene.multiplayer?.net, now);
2193
+ }
1871
2194
  // Quick reactions and phrases, in every place; what was said, as bubbles
1872
2195
  // (below, with the labels) and a short feed.
1873
2196
  const net = scene.multiplayer?.net;
@@ -1889,6 +2212,22 @@ class HubSystem {
1889
2212
  this.playAsk = { from: playerId, name, door, until: now + PLAY_ASK_MS };
1890
2213
  },
1891
2214
  );
2215
+ // Cues: someone new in the roster may be one this player can chat with,
2216
+ // so the host is asked soon, not at the end of its idle wait. In a town
2217
+ // only, like every cue: a game behind one of its doors is drawn by this
2218
+ // client too, and is left exactly as it was.
2219
+ const cuesHere = Hub.deck.cues && place !== null && !inGame;
2220
+ if (cuesHere) {
2221
+ const here = new Set(net?.others?.().keys() ?? []);
2222
+ let fresh = false;
2223
+ for (const playerId of here) {
2224
+ fresh ||= !this.rosterSeen.has(playerId);
2225
+ }
2226
+ this.rosterSeen = here;
2227
+ if (fresh) {
2228
+ this.chat.soon(now);
2229
+ }
2230
+ }
1892
2231
  // Free-text chat, where the host has it: ghost says whom this player may
1893
2232
  // chat with (they follow each other and both are over 13); the kit only
1894
2233
  // shows what it is handed.
@@ -1910,6 +2249,7 @@ class HubSystem {
1910
2249
  this.say.chat(now, from?.playerId ?? null, from?.username ?? message.fromUsername ?? 'Someone', message, CHAT_BUBBLE_MS);
1911
2250
  }
1912
2251
  const reach = (this.chat.peers ?? []).map((userId) => byUser.get(userId)?.username).filter(Boolean);
2252
+ this.chatReach = reach;
1913
2253
  // The field is always there where the host has chat, so it can be found;
1914
2254
  // when it cannot be used the card says why, in terms of this player alone
1915
2255
  // (never another player's age).
@@ -1917,17 +2257,31 @@ class HubSystem {
1917
2257
  ? "Chat isn't available on this account"
1918
2258
  : reach.length
1919
2259
  ? `Chat reaches ${reach.slice(0, 3).join(', ')}${reach.length > 3 ? ` +${reach.length - 3}` : ''}`
1920
- : 'Follow each other to chat. Nobody here follows you back yet.';
2260
+ : this.awayNote() ?? 'Chat is for players who follow each other. None of yours are here now · the phrases above reach everyone.';
1921
2261
  const chatPart = this.chat.available() && this.chat.peers !== null
1922
2262
  ? { input: this.chat.canChat && reach.length > 0, note: chatNote }
1923
2263
  : null;
2264
+ // Cues: the field itself says who reads a line, or in a few words why it
2265
+ // cannot be used (the note has the long form).
2266
+ if (chatPart && cuesHere) {
2267
+ if (!chatPart.input) {
2268
+ chatPart.note = CHAT_HINT.why;
2269
+ }
2270
+ chatPart.placeholder = chatPart.input ? CHAT_HINT.on : CHAT_HINT.off;
2271
+ chatPart.label = chatPart.input ? CHAT_HINT.label : CHAT_HINT.why;
2272
+ }
1924
2273
  chrome.setSay?.(free ? { reactions: REACTIONS, phrases: this.say.phrases(), chat: chatPart } : null);
1925
2274
  chrome.setFeed?.(idle && place !== null ? this.say.feed() : []);
1926
2275
  // Standing still beside someone: a small button invites them.
1927
2276
  const beside = town && !Hub.hub.party.invite && local ? this.together.beside(scene, local) : null;
1928
2277
  chrome.nearPrompt?.(
1929
- beside ? `+ Party · ${beside.username ?? 'this player'}` : null,
1930
- () => this.join(scene, beside, 'invite'),
2278
+ beside ? `${beside.sent ? 'Invited' : '+ Party'} · ${beside.username ?? 'this player'}` : null,
2279
+ () => {
2280
+ if (!beside.sent) {
2281
+ this.together.invited(beside.playerId);
2282
+ this.join(scene, beside, 'invite');
2283
+ }
2284
+ },
1931
2285
  );
1932
2286
  // Barred from the hub: the town's own join was refused, and is not asked again.
1933
2287
  if (scene.multiplayer?.joinError === HUB_BANNED) {
@@ -1941,6 +2295,12 @@ class HubSystem {
1941
2295
  } else if (spec?.timer?.until !== undefined) {
1942
2296
  timer = Math.max(0, (spec.timer.until - Hub.simNow()) / 1000);
1943
2297
  }
2298
+ // A place that asks (`hud.clear`, v1.26) has its HUD kept short and its
2299
+ // labels kept out from under it; any other is drawn as it always was.
2300
+ if (place?.hud?.clear === true || this.hudClear) {
2301
+ this.hudClear = place?.hud?.clear === true;
2302
+ chrome.setHudClear?.(this.hudClear);
2303
+ }
1944
2304
  chrome.setHud(idle || this.trip?.phase === 'revealing' ? spec : null, timer);
1945
2305
 
1946
2306
  const cam = scene.three?.camera;
@@ -2010,6 +2370,11 @@ class HubSystem {
2010
2370
  const showRibbon = !inGame && idle && r && Date.now() - r.at < RIBBON_MS && lt && cam;
2011
2371
  chrome.setRibbon(showRibbon ? project(cam, lt.x, lt.y + 1.7, lt.z, view) : null, r ? `🏅 ${resultLine(r)}` : '');
2012
2372
  chrome.setToast(now < this.toast.until ? this.toast.text : '');
2373
+ // A clear HUD (v1.26): everything drawn above is measured, then moved
2374
+ // out from under it, once for the frame. Never said in any other place.
2375
+ if (this.hudClear) {
2376
+ chrome.flushHudClear?.();
2377
+ }
2013
2378
  }
2014
2379
 
2015
2380
  // The People list's rows. In a town: everyone here and the player's