castle-web-cli 0.4.231 → 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 (55) hide show
  1. package/dist/serverBundle.js +5 -3
  2. package/kits/hub-game/CLAUDE.md +26 -4
  3. package/kits/hub-game/code/client/avatar.js +39 -0
  4. package/kits/hub-game/code/client/chat.js +12 -0
  5. package/kits/hub-game/code/client/chrome.js +194 -4
  6. package/kits/hub-game/code/client/grab.js +31 -7
  7. package/kits/hub-game/code/client/hats.js +26 -0
  8. package/kits/hub-game/code/client/hookLayer.js +30 -3
  9. package/kits/hub-game/code/client/hudClear.js +126 -0
  10. package/kits/hub-game/code/client/state.js +22 -0
  11. package/kits/hub-game/code/client/tiers.js +31 -6
  12. package/kits/hub-game/code/client/together.js +66 -1
  13. package/kits/hub-game/code/client/wear.js +96 -14
  14. package/kits/hub-game/code/server/actors.js +5 -0
  15. package/kits/hub-game/code/server/grab.js +296 -11
  16. package/kits/hub-game/code/server/hub.js +63 -2
  17. package/kits/hub-game/code/server/manifest.js +48 -3
  18. package/kits/hub-game/code/server/party.js +11 -0
  19. package/kits/hub-game/code/server/say.js +8 -2
  20. package/kits/hub-game/code/server/wear.js +116 -11
  21. package/kits/hub-game/code/systems/hub.js +253 -5
  22. package/kits/hub-game/docs/contract.md +204 -8
  23. package/kits/hub-game/package.json +1 -1
  24. package/kits/hub-game/scripts/test-chat.mjs +32 -0
  25. package/kits/hub-game/scripts/test-grab-client.mjs +186 -3
  26. package/kits/hub-game/scripts/test-grab.mjs +857 -3
  27. package/kits/hub-game/scripts/test-hats.mjs +229 -0
  28. package/kits/hub-game/scripts/test-hub-trip.mjs +513 -0
  29. package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
  30. package/kits/hub-game/scripts/test-manifest.mjs +75 -0
  31. package/kits/hub-game/scripts/test-party.mjs +22 -1
  32. package/kits/hub-game/scripts/test-say.mjs +59 -2
  33. package/kits/hub-game/scripts/test-tiers.mjs +190 -2
  34. package/kits/hub-game/scripts/test-try-on.mjs +940 -0
  35. package/kits/physics-2d/castle.json +1 -1
  36. package/kits/physics-2d/engine/scene.js +35 -0
  37. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +44 -0
  38. package/kits/physics-3d/CLAUDE.md +252 -0
  39. package/kits/physics-3d/behaviors/Player.jsx +363 -2
  40. package/kits/physics-3d/castle.json +2 -2
  41. package/kits/physics-3d/docs/pxmodel-format.md +4 -0
  42. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -0
  43. package/kits/physics-3d/engine3d/optimize.js +49 -0
  44. package/kits/physics-3d/engine3d/orbitinput.js +277 -0
  45. package/kits/physics-3d/engine3d/world3d.js +81 -25
  46. package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
  47. package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
  48. package/kits/physics-3d/scripts/test-camera-follow.mjs +12 -2
  49. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2105 -0
  50. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
  51. package/kits/physics-3d/scripts/test-static-actors.mjs +6 -1
  52. package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
  53. package/kits/physics-3d/scripts/test-steady-hover.mjs +633 -0
  54. package/kits/physics-3d/systems/physics3d.js +91 -6
  55. package/package.json +1 -1
@@ -10,11 +10,31 @@
10
10
  // { k: 'hub-grab-deny', actor } server -> that client
11
11
  // { k: 'hub-drop' } server -> that client
12
12
  //
13
+ // A place may keep a held object its holder's (v1.25, `grab.keepHeld`):
14
+ // multiplayer-3d hands a loose object to whichever player is nearer, so
15
+ // someone standing close takes a held object out of its holder's hands. In
16
+ // such a place the held object is pinned -- its sim entry's `claimable` is
17
+ // false, so multiplayer-3d refuses every other claim -- for as long as the
18
+ // hold lasts and its holder's client keeps saying it holds it:
19
+ //
20
+ // { k: 'hub-grab', actor, op: 'hold' } client -> server, about once a second
21
+ //
22
+ // A place without `keepHeld` never pins, and drops that message as malformed.
23
+ //
24
+ // A place may keep a loose object for one player (v1.27, `hub.keepFor`): a
25
+ // grab of it by anyone else is refused here, before the place's hook is asked,
26
+ // and every client is told whose it is (`hubKept`, `keptOf`) so it is offered
27
+ // to nobody else. `keptFor` is empty until a place calls `hub.keepFor`, and
28
+ // every line that reads it does nothing while it is: such a place is checked,
29
+ // asked and sent exactly what it was.
30
+ //
13
31
  // `h` is the hub layer's state: `place`, `actors`, `sim`, `hidden`, `held`,
14
32
  // `hooks`, `ctx`, `session`, and `grabs`, `grabBudget`, `flying` from
15
33
  // `newGrabState`. Every message is a client's word, so each is checked
16
34
  // against the simulation and bounded per player.
17
35
 
36
+ import { warnOnce } from './actors.js';
37
+
18
38
  // How far from a player's body (metres) an object they say they grabbed may
19
39
  // be: the client offers one within about 2.5 m (with a place's `grab.reach`
20
40
  // or `grab.steady`, v1.22, never one whose centre is past 3.5 m), and the
@@ -31,6 +51,16 @@ export const GRAB_BURST = 4;
31
51
  // again, and the speed below which it has landed.
32
52
  export const FLIGHT_MS = 3000;
33
53
  const LANDED_SPEED = 4;
54
+ // v1.25 `keepHeld`: a pin lasts this long past the grab or the holder's last
55
+ // `hold`. The client ends a hold by itself without a word (a trip, the talk
56
+ // panel, a refusal), and one from before v1.25 never says `hold` at all, so a
57
+ // pin nobody renews lapses and the object is anyone's again, as before.
58
+ export const KEEP_LEASE_MS = 2500;
59
+ // A pinned object is in front of its holder (`holdDistance` is at most 3 m,
60
+ // `holdHeight` 2.5 m). Farther than this from the holder's body, by the
61
+ // server's own poses, it is not being held: the pin and the hold end, at each
62
+ // tick and at each `hold`, so a client cannot keep an object pinned from afar.
63
+ export const KEEP_REACH = THROW_REACH;
34
64
 
35
65
  export function newGrabState() {
36
66
  return {
@@ -41,11 +71,195 @@ export function newGrabState() {
41
71
  // actorId -> { until }: thrown objects in flight (their sim entry carries
42
72
  // the flight's `speedCap` meanwhile)
43
73
  flying: new Map(),
74
+ // actorId -> { holder, claimable, until }: held objects pinned to their
75
+ // holder (v1.25 `keepHeld`), with the `claimable` to put back
76
+ pins: new Map(),
77
+ // `keepHeld` only: how many times a hold of each player, or of each
78
+ // object, or everyone's, has been ended or ruled out (`ended`), so a grab
79
+ // being put to the place's hook can tell that the hook itself did so
80
+ ends: { players: new Map(), objects: new Map(), all: 0 },
81
+ // actorId -> the only player who may grab it (v1.27 `hub.keepFor`); empty
82
+ // in a place that never calls it
83
+ keptFor: new Map(),
44
84
  };
45
85
  }
46
86
 
87
+ // v1.27: whether this object is kept for a player other than this one. False
88
+ // for everything while nothing is kept.
89
+ function keptFromPlayer(h, playerId, actorId) {
90
+ return h.keptFor.size > 0 && h.keptFor.has(actorId) && h.keptFor.get(actorId) !== playerId;
91
+ }
92
+
93
+ // `hub.keepFor(actorId, playerId | null)` (v1.27): from now on only that
94
+ // player may grab this loose object; `null` makes it anyone's again. Anyone
95
+ // else holding it lets go (`hub-drop`, as `hub.drop` tells them). Returns
96
+ // whether the object is now kept as asked; a place without `grab`, an actor
97
+ // that is not a dynamic one of the place's scene, or a player who is not here
98
+ // is warned about once and changes nothing. The mark outlives `hub.reset` and
99
+ // ends with `hub.hide`, with the player's leaving, and with `null`.
100
+ export function keepFor(h, actorId, playerId) {
101
+ if (!h.place.grab) {
102
+ warnOnce(h, 'keepFor:grab', 'hub.keepFor: this place has no "grab" in its hub block');
103
+ return false;
104
+ }
105
+ const actor = typeof actorId === 'string' ? h.actors.find((a) => a.id === actorId) : null;
106
+ if (actor?.components.Body?.type !== 'dynamic' || !h.sim?.objects?.get(actorId)?.body) {
107
+ warnOnce(h, `keepFor:${actorId}`, `hub.keepFor: "${actorId}" is not a dynamic actor of this place's scene`);
108
+ return false;
109
+ }
110
+ // Only `null` clears: a player id that is missing (a lookup that failed) is
111
+ // an invalid player, warned about below, and never frees the object.
112
+ if (playerId === null) {
113
+ h.keptFor.delete(actorId);
114
+ return true;
115
+ }
116
+ if (!h.players.has(playerId)) {
117
+ warnOnce(h, `keepFor:player:${playerId}`, `hub.keepFor: "${playerId}" is not a player in this place`);
118
+ return false;
119
+ }
120
+ h.keptFor.set(actorId, playerId);
121
+ for (const [holder, held] of [...h.grabs]) {
122
+ if (held === actorId && holder !== playerId) {
123
+ endHold(h, holder);
124
+ h.session?.send(holder, { k: 'hub-drop', actor: actorId });
125
+ }
126
+ }
127
+ return true;
128
+ }
129
+
130
+ // The place hid an object (`hub.hide`): kept for nobody. (A copy made by
131
+ // `hub.spawn` is never a loose object, so `hub.despawn` has none to forget.)
132
+ export function unkeep(h, actorId) {
133
+ h.keptFor.delete(actorId);
134
+ }
135
+
136
+ // What clients are told (`hubKept`): actor id -> the player it is kept for.
137
+ export function keptOf(h) {
138
+ const out = Object.create(null);
139
+ for (const [actorId, playerId] of h.keptFor) {
140
+ out[actorId] = playerId;
141
+ }
142
+ return out;
143
+ }
144
+
145
+ // In a `keepHeld` place, note that this player's hold, this object's, or
146
+ // everyone's (neither given) is over, whether or not there was one.
147
+ function ended(h, playerId, actorId) {
148
+ if (!keeps(h)) {
149
+ return;
150
+ }
151
+ if (playerId === undefined && actorId === undefined) {
152
+ h.ends.all += 1;
153
+ }
154
+ if (playerId !== undefined) {
155
+ h.ends.players.set(playerId, (h.ends.players.get(playerId) ?? 0) + 1);
156
+ }
157
+ if (actorId !== undefined) {
158
+ h.ends.objects.set(actorId, (h.ends.objects.get(actorId) ?? 0) + 1);
159
+ }
160
+ }
161
+
162
+ function endsOf(h, playerId, actorId) {
163
+ return `${h.ends.all}:${h.ends.players.get(playerId) ?? 0}:${h.ends.objects.get(actorId) ?? 0}`;
164
+ }
165
+
166
+ function keeps(h) {
167
+ return h.place.grab?.keepHeld === true;
168
+ }
169
+
170
+ // Pin a held object to its holder, or renew the pin.
171
+ function pin(h, playerId, actorId, entry) {
172
+ if (!keeps(h)) {
173
+ return;
174
+ }
175
+ const until = h.sim.timeMs + KEEP_LEASE_MS;
176
+ const had = h.pins.get(actorId);
177
+ if (had) {
178
+ had.holder = playerId;
179
+ had.until = until;
180
+ return;
181
+ }
182
+ h.pins.set(actorId, { holder: playerId, claimable: entry.claimable, until });
183
+ entry.claimable = false;
184
+ }
185
+
186
+ // Take a pin off: the object is as claimable as it was before. With `holder`,
187
+ // only that player's pin. `hub.reset` unpins before its own hold on
188
+ // `claimable` (`actors.js`), so the two never save each other's `false`.
189
+ export function unpin(h, actorId, holder) {
190
+ const pinned = h.pins?.get(actorId);
191
+ if (!pinned || (holder !== undefined && pinned.holder !== holder)) {
192
+ return;
193
+ }
194
+ h.pins.delete(actorId);
195
+ const entry = h.sim?.objects?.get(actorId);
196
+ if (entry) {
197
+ entry.claimable = pinned.claimable;
198
+ }
199
+ }
200
+
201
+ // What a hold in a `keepHeld` place needs beyond what any hold does, checked
202
+ // at every tick and every `hold` whether or not it is pinned just now: a
203
+ // player who has arrived and whose game has not ended, with their body by
204
+ // the object.
205
+ function inForce(h, playerId, entry) {
206
+ const player = h.players.get(playerId);
207
+ return Boolean(player?.arrived && !player.ended && entry?.body && near(h, playerId, entry, KEEP_REACH));
208
+ }
209
+
210
+ // The place took an object out of play (`hub.hide`, `hub.reset`): unpinned,
211
+ // and in a `keepHeld` place its hold is over at once, not at the next tick.
212
+ export function taken(h, actorId) {
213
+ ended(h, undefined, actorId);
214
+ unpin(h, actorId);
215
+ if (keeps(h)) {
216
+ for (const [playerId, held] of [...h.grabs]) {
217
+ if (held === actorId) {
218
+ endHold(h, playerId);
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+ // The place held a player still (`hub.hold`): in a `keepHeld` place their
225
+ // hold is over at once.
226
+ export function stilled(h, playerId) {
227
+ ended(h, playerId);
228
+ if (keeps(h)) {
229
+ endHold(h, playerId);
230
+ }
231
+ }
232
+
233
+ // In a `keepHeld` place, after the place's hook has run: everything a grab
234
+ // had to pass before it, read again, since the hook may have ended the
235
+ // player's game, moved or removed their body, or taken the object away.
236
+ function stillGrabbable(h, playerId, actorId) {
237
+ const entry = looseObject(h, actorId);
238
+ const player = h.players.get(playerId);
239
+ return Boolean(
240
+ player?.arrived &&
241
+ !player.ended &&
242
+ h.sim.players.has(playerId) &&
243
+ !h.held.has(playerId) &&
244
+ entry?.owner === playerId &&
245
+ near(h, playerId, entry, GRAB_REACH),
246
+ );
247
+ }
248
+
249
+ // Every end of a hold goes through here, so its pin goes with it.
250
+ function endHold(h, playerId) {
251
+ const actorId = h.grabs.get(playerId);
252
+ if (actorId === undefined) {
253
+ return;
254
+ }
255
+ h.grabs.delete(playerId);
256
+ ended(h, playerId, actorId);
257
+ unpin(h, actorId, playerId);
258
+ }
259
+
47
260
  // A scene actor whose body multiplayer-3d hands to clients: authored with a
48
- // dynamic Body, built as a claimable object, and not hidden by the place.
261
+ // dynamic Body, built as a claimable object, and not hidden by the place. A
262
+ // pinned object (v1.25) is still one: it is unclaimable only because it is held.
49
263
  function looseObject(h, actorId) {
50
264
  if (typeof actorId !== 'string' || actorId.length > 128 || h.hidden.has(actorId)) {
51
265
  return null;
@@ -55,7 +269,7 @@ function looseObject(h, actorId) {
55
269
  return null;
56
270
  }
57
271
  const entry = h.sim?.objects?.get(actorId);
58
- return entry?.claimable && entry.body ? entry : null;
272
+ return (entry?.claimable || (entry && h.pins.has(actorId))) && entry.body ? entry : null;
59
273
  }
60
274
 
61
275
  function near(h, playerId, entry, reach) {
@@ -79,6 +293,13 @@ function spend(h, playerId) {
79
293
  }
80
294
 
81
295
  function deny(h, playerId, actorId) {
296
+ // In a `keepHeld` place a refusal of what the player holds ends that hold,
297
+ // record and pin: the client lets go, and no later `hold` may renew a pin
298
+ // the place's hook has since refused. (Elsewhere a refusal leaves the
299
+ // record as it always did, until the object moves on.)
300
+ if (keeps(h) && h.grabs.get(playerId) === actorId) {
301
+ endHold(h, playerId);
302
+ }
82
303
  h.session?.send(playerId, { k: 'hub-grab-deny', actor: actorId });
83
304
  }
84
305
 
@@ -100,8 +321,9 @@ function ask(h, playerId, actorId, op) {
100
321
  // dropped. A grab that is refused -- past the rate, not a loose object of the
101
322
  // place, too far, not this player's to simulate, a held or departed player,
102
323
  // or the place's hook said no -- is answered `hub-grab-deny`, and the client
103
- // lets go. A throw of something the place does not know this player holds is
104
- // dropped.
324
+ // lets go. So is a grab of an object the place keeps for another player
325
+ // (v1.27), which the hook is never asked about. A throw of something the
326
+ // place does not know this player holds is dropped.
105
327
  export function message(h, playerId, data) {
106
328
  const op = data?.op;
107
329
  if (
@@ -109,7 +331,7 @@ export function message(h, playerId, data) {
109
331
  playerId === null ||
110
332
  !h.place.grab ||
111
333
  !h.sim ||
112
- (op !== 'grab' && op !== 'throw') ||
334
+ (op !== 'grab' && op !== 'throw' && !(op === 'hold' && keeps(h))) ||
113
335
  typeof data.actor !== 'string' ||
114
336
  data.actor.length > 128
115
337
  ) {
@@ -119,16 +341,35 @@ export function message(h, playerId, data) {
119
341
  if (!spend(h, playerId)) {
120
342
  if (op === 'grab') {
121
343
  deny(h, playerId, actorId);
344
+ } else if (op === 'throw' && keeps(h) && h.grabs.get(playerId) === actorId) {
345
+ // Past the rate a throw is not heard, but in a `keepHeld` place the
346
+ // hold it ends is over all the same: no `hold` renews it.
347
+ endHold(h, playerId);
122
348
  }
123
349
  return;
124
350
  }
125
351
  const entry = looseObject(h, actorId);
126
352
  const entered = h.players.get(playerId)?.arrived && !h.players.get(playerId)?.ended;
353
+ if (op === 'hold') {
354
+ // Still holding it, says its holder's client: the pin is renewed (or put
355
+ // back after a lapse) while the hold is one the server still knows.
356
+ // A holder whose body is not by the object is not holding it, whatever
357
+ // poses its client reports for it: that hold is over.
358
+ if (h.grabs.get(playerId) !== actorId) {
359
+ return;
360
+ }
361
+ if (entry?.owner === playerId && !h.held.has(playerId) && inForce(h, playerId, entry)) {
362
+ pin(h, playerId, actorId, entry);
363
+ } else {
364
+ endHold(h, playerId);
365
+ }
366
+ return;
367
+ }
127
368
  if (op === 'throw') {
128
369
  if (h.grabs.get(playerId) !== actorId) {
129
370
  return;
130
371
  }
131
- h.grabs.delete(playerId);
372
+ endHold(h, playerId);
132
373
  // Still theirs, now: the object may have been handed to someone else, or
133
374
  // the player held, since the place last looked.
134
375
  if (entry && entry.owner === playerId && entered && !h.held.has(playerId) && near(h, playerId, entry, THROW_REACH)) {
@@ -148,7 +389,24 @@ export function message(h, playerId, data) {
148
389
  deny(h, playerId, actorId);
149
390
  return;
150
391
  }
151
- if (!ask(h, playerId, actorId, 'grab')) {
392
+ // v1.27: an object kept for someone else (`hub.keepFor`) is refused here,
393
+ // and the place's hook never hears of it.
394
+ if (keptFromPlayer(h, playerId, actorId)) {
395
+ deny(h, playerId, actorId);
396
+ return;
397
+ }
398
+ // In a `keepHeld` place the hook's own acts stand: if it dropped this
399
+ // player, hid or reset the object, or held the player still -- even if it
400
+ // undid that before returning -- the grab is refused, and the client is
401
+ // told so (`hub-grab-deny`) and lets go, rather than a hold the place just
402
+ // ended being recorded and pinned again.
403
+ const stamp = keeps(h) ? endsOf(h, playerId, actorId) : null;
404
+ if (
405
+ !ask(h, playerId, actorId, 'grab') ||
406
+ (stamp !== null && (endsOf(h, playerId, actorId) !== stamp || !stillGrabbable(h, playerId, actorId))) ||
407
+ // v1.27: the hook itself kept the object for someone else.
408
+ keptFromPlayer(h, playerId, actorId)
409
+ ) {
152
410
  deny(h, playerId, actorId);
153
411
  return;
154
412
  }
@@ -158,7 +416,14 @@ export function message(h, playerId, data) {
158
416
  h.grabs.delete(other);
159
417
  }
160
418
  }
419
+ // The object held before goes free. The record is set in place, as ever:
420
+ // the order of holders is the order `hub.drop` tells them in.
421
+ const before = h.grabs.get(playerId);
422
+ if (before !== undefined && before !== actorId) {
423
+ unpin(h, before, playerId);
424
+ }
161
425
  h.grabs.set(playerId, actorId);
426
+ pin(h, playerId, actorId, entry);
162
427
  }
163
428
 
164
429
  // A thrown object is not slowed to a shove's speed while it flies: until it
@@ -192,12 +457,13 @@ function capSpeed(body, cap) {
192
457
  // `hub.drop(playerId?)`: whoever holds something lets go (default: everyone).
193
458
  // Only players the place knows hold something are told. Returns how many.
194
459
  export function drop(h, playerId) {
460
+ ended(h, playerId);
195
461
  let n = 0;
196
462
  for (const [holder, actorId] of [...h.grabs]) {
197
463
  if (playerId !== undefined && holder !== playerId) {
198
464
  continue;
199
465
  }
200
- h.grabs.delete(holder);
466
+ endHold(h, holder);
201
467
  h.session?.send(holder, { k: 'hub-drop', actor: actorId });
202
468
  n += 1;
203
469
  }
@@ -214,9 +480,16 @@ export function tick(h) {
214
480
  !entry ||
215
481
  entry.owner !== playerId ||
216
482
  h.held.has(playerId) ||
217
- !h.sim.players.has(playerId)
483
+ !h.sim.players.has(playerId) ||
484
+ (keeps(h) && !inForce(h, playerId, entry))
218
485
  ) {
219
- h.grabs.delete(playerId);
486
+ endHold(h, playerId);
487
+ }
488
+ }
489
+ // A pin outlives nothing: not its hold, its lease, or its holder's visit.
490
+ for (const [actorId, pinned] of [...h.pins]) {
491
+ if (h.grabs.get(pinned.holder) !== actorId || h.sim.timeMs >= pinned.until) {
492
+ unpin(h, actorId);
220
493
  }
221
494
  }
222
495
  for (const [actorId, flight] of [...h.flying]) {
@@ -238,8 +511,20 @@ export function tick(h) {
238
511
  }
239
512
 
240
513
  export function forget(h, playerId) {
241
- h.grabs.delete(playerId);
514
+ endHold(h, playerId);
515
+ // Their count goes with them; `all` moves instead, so a grab in the hook
516
+ // just now still sees that something ended.
517
+ ended(h);
518
+ h.ends.players.delete(playerId);
242
519
  h.grabBudget.delete(playerId);
520
+ // v1.27: what was kept for them is anyone's again.
521
+ if (h.keptFor.size > 0) {
522
+ for (const [actorId, keeper] of [...h.keptFor]) {
523
+ if (keeper === playerId) {
524
+ h.keptFor.delete(actorId);
525
+ }
526
+ }
527
+ }
243
528
  }
244
529
 
245
530
  // Who holds what, for the place: actor id or null.
@@ -155,7 +155,7 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
155
155
  return;
156
156
  }
157
157
  if (data?.k === 'hub-say') {
158
- Say.message({ h, blockedPairs, jumpDoors: doors }, player, data);
158
+ Say.message(sayDeps(h), player, data);
159
159
  return;
160
160
  }
161
161
  if (data?.k === 'hub-party') {
@@ -198,6 +198,10 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
198
198
  const dt = h.lastPlaceAt === null ? 0 : Math.min(0.25, (sim.timeMs - h.lastPlaceAt) / 1000);
199
199
  h.lastPlaceAt = sim.timeMs;
200
200
  reconcile(h);
201
+ // v1.28: a try-on on a player who went before saying hello goes too.
202
+ if (Wear.tryOnUsed(h)) {
203
+ Wear.pruneTries(h);
204
+ }
201
205
  readResults(h);
202
206
  arrivals(h);
203
207
  enforceHolds(h);
@@ -223,6 +227,10 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
223
227
  sendAvatarOverrides(h);
224
228
  Party.tick(partyDeps(h));
225
229
  Wear.sendOverrides(h, blockedPairs(h));
230
+ // v1.28 `hub.tryOn`: nothing in a place that never calls it.
231
+ if (Wear.tryOnUsed(h)) {
232
+ Wear.sendTryOverrides(h, blockedPairs(h));
233
+ }
226
234
  // Cabinet cards (v1.7): nothing in a place with no classic door.
227
235
  Cabinets.send(h, (playerId) => namesOf(h, blockedPairs(h)?.get(playerId) ?? []));
228
236
  Actors.flushHandovers(h, handovers);
@@ -260,6 +268,10 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
260
268
  spawnTemplates: Actors.templatesOf(h),
261
269
  // v1.6, only in a place that turns idle play on.
262
270
  ...Idle.fields(h),
271
+ // v1.27, only once the place keeps an object for a player.
272
+ ...(h.keptFor.size > 0 ? { hubKept: Grab.keptOf(h) } : {}),
273
+ // v1.28, only while the place shows a try-on on someone.
274
+ ...(h.trying.size > 0 ? tryingForJoin(h) : {}),
263
275
  };
264
276
  },
265
277
 
@@ -279,6 +291,14 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
279
291
  for (const [field, value] of Object.entries(Idle.fields(h))) {
280
292
  latch(h, field, value, out);
281
293
  }
294
+ // v1.27 `hub.keepFor`: nothing until something is kept, then each change.
295
+ if (h.keptFor.size > 0 || h.sent.has('hubKept')) {
296
+ latch(h, 'hubKept', Grab.keptOf(h), out);
297
+ }
298
+ // v1.28 `hub.tryOn`: nothing until someone tries something on, then each change.
299
+ if (h.trying.size > 0 || h.sent.has('hubTry')) {
300
+ latchTrying(h, out);
301
+ }
282
302
  return Object.keys(out).length ? out : null;
283
303
  },
284
304
 
@@ -501,6 +521,7 @@ function makeContext(h) {
501
521
  const point = at ? { ...at } : { ...body.at };
502
522
  const facing = facingDeg === undefined ? body.facing : facingDeg * DEG;
503
523
  h.held.set(playerId, { at: point, facing });
524
+ Grab.stilled(h, playerId);
504
525
  placeAt(h, playerId, point, facing);
505
526
  },
506
527
  release(playerId) {
@@ -517,10 +538,17 @@ function makeContext(h) {
517
538
  }
518
539
  },
519
540
  hide(actorId) {
520
- if (!isSceneActor(h, actorId) || h.hidden.has(actorId)) {
541
+ if (!isSceneActor(h, actorId)) {
542
+ return;
543
+ }
544
+ if (h.hidden.has(actorId)) {
545
+ // Hidden already, and kept since (`keepFor` takes a hidden object): hiding it again still ends that.
546
+ Grab.unkeep(h, actorId);
521
547
  return;
522
548
  }
523
549
  h.hidden.add(actorId);
550
+ Grab.taken(h, actorId);
551
+ Grab.unkeep(h, actorId);
524
552
  h.sim?.bodies.get(actorId)?.setEnabled(false);
525
553
  },
526
554
  show(actorId) {
@@ -534,6 +562,7 @@ function makeContext(h) {
534
562
  mark: (playerId, spec) => Actors.mark(h, playerId, spec),
535
563
  results: (playerId) => History.results(h, playerId),
536
564
  wear: (playerId, spec) => wear(h, playerId, spec),
565
+ tryOn: (playerId, spec) => Wear.tryOn(h, playerId, spec),
537
566
  tune: (playerId, spec) => Actors.tune(h, playerId, spec),
538
567
  spawn: (fromActorId, at) => Actors.spawn(h, fromActorId, at, h.engine),
539
568
  pose: (actorId) => Actors.pose(h, actorId),
@@ -550,6 +579,7 @@ function makeContext(h) {
550
579
  seat: (playerId) => Idle.seat(h, playerId),
551
580
  sound: (actorId, file, options) => Idle.sound(h, actorId, file, options),
552
581
  holding: (playerId) => Grab.holding(h, playerId),
582
+ keepFor: (actorId, playerId) => Grab.keepFor(h, actorId, playerId),
553
583
  end(playerIds) {
554
584
  const ids = playerIds ?? [...(h.sim?.players.keys() ?? [])];
555
585
  for (const playerId of ids) {
@@ -592,6 +622,8 @@ function hello(h, player, data) {
592
622
  // holds none of the cabinet cards it was sent (v1.7).
593
623
  if (data.again !== true) {
594
624
  Cabinets.forget(h, player.playerId);
625
+ // v1.28: nothing in a place that never sent a try-on to one player alone.
626
+ Wear.joinedAfresh(h, player.playerId);
595
627
  }
596
628
  h.players.set(player.playerId, {
597
629
  // Who this is, kept for `leave`: by then the session has forgotten them.
@@ -706,6 +738,9 @@ async function shutdown(h) {
706
738
  for (const playerId of [...h.players.keys()]) {
707
739
  forget(h, playerId);
708
740
  }
741
+ if (Wear.tryOnUsed(h)) {
742
+ Wear.endTries(h);
743
+ }
709
744
  let timer = null;
710
745
  await Promise.race([
711
746
  Promise.resolve()
@@ -1137,6 +1172,18 @@ function frontOf(door) {
1137
1172
  return doorPoint({ x: t.x, z: t.z, rotationY: t.rotationY ?? 0 }, (Math.random() - 0.5) * JUMP_SPREAD, JUMP_OUT);
1138
1173
  }
1139
1174
 
1175
+ // What `say.js` uses of this layer. A deck whose manifest sets `cues` (v1.23)
1176
+ // hands it more; any other hands it exactly what it did.
1177
+ function sayDeps(h) {
1178
+ const d = { h, blockedPairs, jumpDoors: doors };
1179
+ if (h.manifest.cues) {
1180
+ d.cues = true;
1181
+ d.goDoors = jumpDoors;
1182
+ d.proposalDoor = Party.proposalDoor;
1183
+ }
1184
+ return d;
1185
+ }
1186
+
1140
1187
  // What `party.js` uses of this layer.
1141
1188
  function partyDeps(h) {
1142
1189
  // A party member put on a pad is settled there like any jump.
@@ -1963,6 +2010,20 @@ function latchWearing(h, out) {
1963
2010
  }
1964
2011
  }
1965
2012
 
2013
+ // `hubTry` (v1.28) the same way: in the snapshot only while a try-on is
2014
+ // shown, in deltas from the first one on, `{}` once when the last is gone.
2015
+ function tryingForJoin(h) {
2016
+ const trying = Wear.tryingOf(h, blockedPairs(h));
2017
+ return Object.keys(trying).length ? { hubTry: trying } : {};
2018
+ }
2019
+
2020
+ function latchTrying(h, out) {
2021
+ const trying = Wear.tryingOf(h, blockedPairs(h));
2022
+ if (Object.keys(trying).length || h.sent.has('hubTry')) {
2023
+ latch(h, 'hubTry', trying, out);
2024
+ }
2025
+ }
2026
+
1966
2027
  function latch(h, field, value, out) {
1967
2028
  const json = JSON.stringify(value);
1968
2029
  if (h.sent.get(field) !== json) {
@@ -35,7 +35,9 @@ const GRAB_LIMITS = { throwSpeed: [1, 14, 'm/s'], holdDistance: [0.8, 3, 'metres
35
35
  // top stays inside the server's GRAB_REACH (4 m, centre to centre), and the
36
36
  // client also never offers an object whose centre is past 3 m.
37
37
  export const GRAB_REACH_LIMITS = [1.6, 3, 'metres'];
38
- const GRAB_KEYS = [...Object.keys(GRAB_DEFAULTS), 'reach', 'steady'];
38
+ // v1.25 `keepHeld`: a held object stays its holder's (`code/server/grab.js`).
39
+ // Kept only when true, like `steady`.
40
+ const GRAB_KEYS = [...Object.keys(GRAB_DEFAULTS), 'reach', 'steady', 'keepHeld'];
39
41
  // Idle play (v1.6, §6): emotes, seats and the place's own sounds. Sounds are
40
42
  // files of the deck, listed so the server can refuse any other name.
41
43
  export const IDLE_KEYS = ['emotes', 'seats', 'sounds'];
@@ -43,6 +45,12 @@ export const SOUND_EXTS = ['.mp3', '.wav', '.m4a'];
43
45
  export const MAX_SOUND_FILES = 16;
44
46
  const SOUND_PATH = /^[A-Za-z0-9_@-][A-Za-z0-9_./@-]{0,199}$/;
45
47
 
48
+ // v1.26 `hud`: how a place's client lays the HUD out. `clear` keeps the HUD
49
+ // short and keeps what is drawn over the world out from under it
50
+ // (`code/client/hudClear.js`). The client's only; kept only when true, so a
51
+ // place without it is read and sent exactly as before.
52
+ const HUD_KEYS = ['clear'];
53
+
46
54
  const PLACE_KEYS = [
47
55
  'title',
48
56
  'scene',
@@ -59,10 +67,14 @@ const PLACE_KEYS = [
59
67
  'fallY',
60
68
  'grab',
61
69
  'idle',
70
+ 'hud',
62
71
  ];
63
72
  // `tiers` is the deck's, not a place's: the client's picture on a slow device
64
73
  // (v1.21, `code/client/tiers.js`). The server reads nothing of it.
65
- const TOP_KEYS = ['contract', 'places', 'tiers', ...PLACE_KEYS];
74
+ // `cues` is the deck's too (v1.23): a town that tells its players more about
75
+ // the friends and party they came with. Both halves read it, and a deck
76
+ // without it is sent and draws exactly what it did.
77
+ const TOP_KEYS = ['contract', 'places', 'tiers', 'cues', ...PLACE_KEYS];
66
78
 
67
79
  const DEFAULT_SCENE = 'scenes/main.scene';
68
80
 
@@ -83,6 +95,9 @@ export function readManifest(castleJson, sceneExists = () => true) {
83
95
  if (hub.tiers !== undefined && typeof hub.tiers !== 'boolean') {
84
96
  errors.push('hub.tiers must be true or false.');
85
97
  }
98
+ if (hub.cues !== undefined && typeof hub.cues !== 'boolean') {
99
+ errors.push('hub.cues must be true or false.');
100
+ }
86
101
  const defaultScene =
87
102
  typeof castleJson?.editor?.defaultPlayFile === 'string' ? castleJson.editor.defaultPlayFile : DEFAULT_SCENE;
88
103
  const serverMax = Number.isInteger(castleJson?.server?.maxPlayers) ? castleJson.server.maxPlayers : MAX_PLAYERS_CAP;
@@ -110,7 +125,7 @@ export function readManifest(castleJson, sceneExists = () => true) {
110
125
  }
111
126
  }
112
127
  }
113
- return errors.length ? { errors, manifest: null } : { errors, manifest: { contract: CONTRACT_VERSION, places } };
128
+ return errors.length ? { errors, manifest: null } : { errors, manifest: { contract: CONTRACT_VERSION, cues: hub.cues === true, places } };
114
129
  }
115
130
 
116
131
  function readPlace(block, where, defaultScene, serverMax, sceneExists, errors, destinations, bundle) {
@@ -187,9 +202,32 @@ function readPlace(block, where, defaultScene, serverMax, sceneExists, errors, d
187
202
  if (idle) {
188
203
  place.idle = idle;
189
204
  }
205
+ // v1.26: the HUD's layout, likewise carried only by a place that asks.
206
+ const hud = readHud(block.hud, `${where}.hud`, errors);
207
+ if (hud) {
208
+ place.hud = hud;
209
+ }
190
210
  return place;
191
211
  }
192
212
 
213
+ // `hud`: absent is none; an object turns each option on by name. `clear:
214
+ // false` (and an empty object) is the same as leaving it out.
215
+ function readHud(value, where, errors) {
216
+ if (value === undefined) {
217
+ return null;
218
+ }
219
+ if (!isObject(value)) {
220
+ errors.push(`${where} must be an object.`);
221
+ return null;
222
+ }
223
+ unknownKeys(value, HUD_KEYS, where, errors);
224
+ if (value.clear !== undefined && typeof value.clear !== 'boolean') {
225
+ errors.push(`${where}.clear must be true or false.`);
226
+ return null;
227
+ }
228
+ return value.clear === true ? { clear: true } : null;
229
+ }
230
+
193
231
  // `grab`: absent or false is none; true is the defaults; an object sets any of
194
232
  // them, and may add `reach` and `steady` (v1.22), which are kept only when
195
233
  // set: `steady: false` is the same as leaving it out.
@@ -229,6 +267,11 @@ function readGrab(value, where, errors) {
229
267
  } else if (value.steady === true) {
230
268
  grab.steady = true;
231
269
  }
270
+ if (value.keepHeld !== undefined && typeof value.keepHeld !== 'boolean') {
271
+ errors.push(`${where}.keepHeld must be true or false.`);
272
+ } else if (value.keepHeld === true) {
273
+ grab.keepHeld = true;
274
+ }
232
275
  return grab;
233
276
  }
234
277
 
@@ -524,6 +567,8 @@ export function publicPlace(id, place) {
524
567
  ...(place.grab ? { grab: { ...place.grab } } : {}),
525
568
  // v1.6: likewise idle play.
526
569
  ...(place.idle ? { idle: { emotes: place.idle.emotes, seats: place.idle.seats, sounds: [...place.idle.sounds] } } : {}),
570
+ // v1.26: likewise the HUD's layout.
571
+ ...(place.hud ? { hud: { ...place.hud } } : {}),
527
572
  result: place.result
528
573
  ? { score: place.result.score ? { unit: place.result.score.unit, better: place.result.score.better } : null }
529
574
  : null,