castle-web-cli 0.4.236 → 0.4.238

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 (218) hide show
  1. package/dist/api.d.ts +2 -0
  2. package/dist/bundle.d.ts +24 -0
  3. package/dist/bundle.js +447 -4
  4. package/dist/bundleLatin1.d.ts +6 -0
  5. package/dist/bundleLatin1.js +333 -0
  6. package/dist/castle-host/host.d.ts +10 -1
  7. package/dist/castle-host/host.js +78 -9
  8. package/dist/castleJson.d.ts +20 -0
  9. package/dist/castleJson.js +40 -0
  10. package/dist/deckExports.d.ts +35 -0
  11. package/dist/deckExports.js +365 -0
  12. package/dist/importCheckHook.d.ts +1 -0
  13. package/dist/importCheckHook.js +1 -1
  14. package/dist/index.js +5 -0
  15. package/dist/init.js +2 -1
  16. package/dist/save-deck.js +18 -13
  17. package/kits/base/castle.json +1 -1
  18. package/kits/base/sdk/README.md +47 -0
  19. package/kits/base/sdk/castle.d.ts +3 -1
  20. package/kits/base/sdk/castle.js +1 -0
  21. package/kits/base/sdk/commands.d.ts +25 -1
  22. package/kits/base/sdk/commands.js +29 -1
  23. package/kits/base/sdk/hub.d.ts +17 -0
  24. package/kits/base/sdk/hub.js +33 -9
  25. package/kits/base/sdk/localCache.d.ts +27 -0
  26. package/kits/base/sdk/localCache.js +115 -0
  27. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  28. package/kits/base/sdk/localCacheStore.js +358 -0
  29. package/kits/base/sdk/transport.d.ts +1 -0
  30. package/kits/base/sdk/transport.js +4 -5
  31. package/kits/hub-game/CLAUDE.md +22 -2
  32. package/kits/hub-game/castle.json +4 -1
  33. package/kits/hub-game/code/client/act.js +66 -91
  34. package/kits/hub-game/code/client/actCore.js +134 -0
  35. package/kits/hub-game/code/client/car.js +35 -0
  36. package/kits/hub-game/code/client/chrome.js +207 -381
  37. package/kits/hub-game/code/client/crowdNames.js +2 -2
  38. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  39. package/kits/hub-game/code/client/hats.js +2 -0
  40. package/kits/hub-game/code/client/hookLayer.js +99 -48
  41. package/kits/hub-game/code/client/hostGo.js +77 -0
  42. package/kits/hub-game/code/client/hubControls.js +125 -0
  43. package/kits/hub-game/code/client/hubEntry.js +187 -0
  44. package/kits/hub-game/code/client/hudSurface.js +148 -0
  45. package/kits/hub-game/code/client/hudTree.js +96 -0
  46. package/kits/hub-game/code/client/idle.js +59 -13
  47. package/kits/hub-game/code/client/invites.js +13 -4
  48. package/kits/hub-game/code/client/menuIcons.js +8 -0
  49. package/kits/hub-game/code/client/noTrips.js +38 -0
  50. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  51. package/kits/hub-game/code/client/rehello.js +3 -1
  52. package/kits/hub-game/code/client/riders.js +26 -0
  53. package/kits/hub-game/code/client/role.js +79 -0
  54. package/kits/hub-game/code/client/safeLayout.js +32 -3
  55. package/kits/hub-game/code/client/sound.js +10 -3
  56. package/kits/hub-game/code/client/soundscape.js +2 -2
  57. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  58. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  59. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  60. package/kits/hub-game/code/client/state.js +19 -0
  61. package/kits/hub-game/code/client/stuck.js +2 -1
  62. package/kits/hub-game/code/client/talkSurface.js +178 -0
  63. package/kits/hub-game/code/client/talkTree.js +238 -0
  64. package/kits/hub-game/code/client/tiers.js +8 -5
  65. package/kits/hub-game/code/client/uiDom.js +600 -0
  66. package/kits/hub-game/code/client/uiTree.js +359 -0
  67. package/kits/hub-game/code/client/vehicle.js +154 -0
  68. package/kits/hub-game/code/client/wear.js +27 -5
  69. package/kits/hub-game/code/client/worldLabels.js +3 -2
  70. package/kits/hub-game/code/client/yours.js +10 -3
  71. package/kits/hub-game/code/server/actors.js +4 -3
  72. package/kits/hub-game/code/server/analytics.js +56 -6
  73. package/kits/hub-game/code/server/decor.js +56 -16
  74. package/kits/hub-game/code/server/hub.js +258 -46
  75. package/kits/hub-game/code/server/idle.js +118 -5
  76. package/kits/hub-game/code/server/manifest.js +46 -4
  77. package/kits/hub-game/code/server/npcs.js +4 -2
  78. package/kits/hub-game/code/server/players.js +3 -0
  79. package/kits/hub-game/code/server/role.js +142 -0
  80. package/kits/hub-game/code/server/standing.js +6 -4
  81. package/kits/hub-game/code/server/vehicle.js +126 -0
  82. package/kits/hub-game/code/shared/car.js +52 -0
  83. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  84. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  85. package/kits/hub-game/code/shared/expression.js +9 -0
  86. package/kits/hub-game/code/systems/hub.js +300 -85
  87. package/kits/hub-game/docs/analytics.md +11 -2
  88. package/kits/hub-game/docs/contract.md +353 -14
  89. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  90. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  91. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  92. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  93. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  94. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  95. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  96. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  97. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  98. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  99. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  100. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  101. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  102. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  103. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  104. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  105. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  106. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  107. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  108. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  109. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  110. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  111. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  112. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  113. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  114. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  115. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  116. package/kits/hub-game/package-lock.json +1 -1
  117. package/kits/hub-game/package.json +1 -1
  118. package/kits/hub-game/scripts/check.mjs +7 -4
  119. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  120. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  121. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  122. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  123. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  124. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  125. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  126. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  127. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  128. package/kits/hub-game/scripts/test-analytics.mjs +99 -5
  129. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  130. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  131. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  132. package/kits/hub-game/scripts/test-car.mjs +43 -0
  133. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  134. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  135. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  136. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  137. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  138. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  139. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  140. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  141. package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
  142. package/kits/hub-game/scripts/test-hub-trip.mjs +85 -0
  143. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  144. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  145. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  146. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  147. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  148. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  149. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  150. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  151. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  152. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  153. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  154. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  155. package/kits/hub-game/scripts/test-resync.mjs +183 -0
  156. package/kits/hub-game/scripts/test-role-client.mjs +421 -0
  157. package/kits/hub-game/scripts/test-role.mjs +350 -0
  158. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  159. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  160. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  161. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  162. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  163. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  164. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  165. package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
  166. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  167. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  168. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  169. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  170. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  171. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  172. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
  173. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  174. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  175. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  176. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  177. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
  178. package/kits/multiplayer-3d/castle.json +4 -4
  179. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  180. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  181. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  182. package/kits/multiplayer-3d/package-lock.json +1 -1
  183. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  184. package/kits/physics-3d/CLAUDE.md +1 -1
  185. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  186. package/kits/physics-3d/castle.json +2 -2
  187. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  188. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  189. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  190. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  191. package/kits/physics-3d/engine3d/world3d.js +6 -3
  192. package/kits/physics-3d/package.json +1 -1
  193. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  194. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  195. package/kits/physics-3d/systems/physics3d.js +5 -2
  196. package/kits/real-time/castle.json +2 -2
  197. package/kits/real-time/code/client/messages.js +5 -0
  198. package/kits/real-time/code/server/session.js +28 -1
  199. package/kits/real-time/package-lock.json +1 -1
  200. package/package.json +5 -4
  201. package/vendor/three/LICENSE +21 -0
  202. package/vendor/three/build/three.core.js +58773 -0
  203. package/vendor/three/build/three.module.js +18251 -0
  204. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  205. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  206. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  207. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  208. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  209. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  210. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  211. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  212. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  213. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  214. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  215. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  216. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  217. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  218. package/vendor/three/package.json +134 -0
@@ -7,6 +7,9 @@ import { faceArrivalCamera } from '../client/arrivalCamera.js';
7
7
  import { makeDoorErrors } from '../client/doorErrors.js';
8
8
  import { makeVisibility } from '../client/visibility.js';
9
9
  import { makeInvites } from '../client/invites.js';
10
+ import { makeHubEntry, planHubEntry } from '../client/hubEntry.js';
11
+ import { makeHostGo } from '../client/hostGo.js';
12
+ import { makeNoTrips } from '../client/noTrips.js';
10
13
  import { makeSignIn } from '../client/signIn.js';
11
14
  import { makeWeakestTier, readDistricts } from '../client/weakestTier.js';
12
15
  import { makeHudRate } from '../client/hudRate.js';
@@ -59,10 +62,13 @@ import * as Cabinets from '../client/cabinets.js';
59
62
  import { CHAT_BUBBLE_MS, makeChat } from '../client/chat.js';
60
63
  import { chatModerationEnabled } from '../client/chatModeration.js';
61
64
  import { makeChrome } from '../client/chrome.js';
65
+ import { setUiTreeTime, syncUiTreeTime } from '../client/uiTree.js';
66
+ import { hudInputs } from '../client/hudSurface.js';
62
67
  import * as Packs from '../client/pack.js';
63
68
  import * as Hub from '../client/state.js';
64
69
  import { clearShot } from '../client/shot.js';
65
70
  import { makeAct } from '../client/act.js';
71
+ import { backControl, backPress, backRoute, personAction, reportPerson } from '../client/hubControls.js';
66
72
  import { makeGrab } from '../client/grab.js';
67
73
  import { makeIdle } from '../client/idle.js';
68
74
  import { makeDecor } from '../client/decor.js';
@@ -78,9 +84,13 @@ import { makeInterestCap } from '../client/interestCap.js';
78
84
  import { makeFpsTelemetry, fpsTelemetryFor } from '../client/fpsTelemetry.js';
79
85
  import { loadTelemetryFor, reportLoadStage } from '../client/loadTelemetry.js';
80
86
  import { LOAD_STAGES } from '../shared/loadStages.js';
87
+ import { encodeDeviceClass } from '../shared/deviceClass.js';
81
88
  import { makeTiers } from '../client/tiers.js';
82
89
  import { goalPointers, goalText, makeTogether, pointerAt } from '../client/together.js';
83
- import { makeEarned, makeWear } from '../client/wear.js';
90
+ import { makeVehicle } from '../client/vehicle.js';
91
+ import { carInput } from '../client/car.js';
92
+ import { makeEarned, makeRole, makeWear } from '../client/wear.js';
93
+ import { roleEarned, roleItems, roleWearing } from '../client/role.js';
84
94
  import { makeCompanion } from '../client/companion.js';
85
95
  import { makeDefaultEnvironment } from '../client/defaultEnvironment.js';
86
96
  import { activeFallY, holdFallenPlayer } from '../client/fall.js';
@@ -92,6 +102,11 @@ const OPEN_MS = 650;
92
102
  const REVEAL_MS = 700;
93
103
  const LEAVING_MS = 2800;
94
104
  const LOADING_LIMIT_MS = 15000;
105
+ // Ghost's roster can lag a player's arrival in a session by up to 15 s, and
106
+ // the SDK asks a door again through the `forbidden` it answers meanwhile, for
107
+ // 16 s after the arrival (v1.154). A door asked inside that window has its
108
+ // LOADING_LIMIT_MS counted from the window's end: at most this much later.
109
+ const ROSTER_LAG_MS = 16000;
95
110
  // How long the cover waits for the place to say where it put this player
96
111
  // after the session has placed them, before it lifts anyway.
97
112
  const ARRIVAL_WAIT_MS = 4000;
@@ -173,6 +188,9 @@ const CABINET_CAM_OUT = 1.5;
173
188
  // What the multiplayer kit is switched to while a player is away in a classic
174
189
  // deck: no session. It is never joined (`leaveSession`).
175
190
  const AWAY_JOIN = { mode: 'hub', handoff: null, away: true };
191
+ // Place actions whose pick calls hub.invite (a town's Invite a friend, a win's
192
+ // Share, a house's Share): drawn only while the host makes links for this player.
193
+ const INVITE_ACTIONS = new Set(['invite-friend', 'share-win', 'share-town']);
176
194
  // Castle refuses a player it has barred from the hub at every door and at the
177
195
  // town itself with this code; the kit says so plainly and does not ask again.
178
196
  export const HUB_BANNED = 'CAULDRON_HUB_BANNED';
@@ -247,7 +265,9 @@ class HubSystem {
247
265
  this.spinData = null;
248
266
  this.spin = null;
249
267
  this.wear = makeWear();
268
+ this.vehicle = makeVehicle();
250
269
  this.earned = makeEarned();
270
+ this.roles = makeRole();
251
271
  this.toast = { text: '', until: 0 };
252
272
  this.leavingToast = null;
253
273
  this.stats = statsWanted();
@@ -426,6 +446,9 @@ class HubSystem {
426
446
  place: Hub.hub.place,
427
447
  visit: `${this.helloMark?.selfId ?? ''}:${this.helloMark?.again ?? ''}`,
428
448
  });
449
+ if (Hub.hub.roles.size > 0) {
450
+ this.chrome.syncRoleLabels?.(roleItems(scene, scene.actorWith('Player'), cam, frame.view, Hub.hub.roles, project));
451
+ }
429
452
  const labelBoxes = this.chrome.crowdNameLabelBoxes?.() ?? [];
430
453
  const obstacles = [...frame.controls, ...(frame.own ? [frame.own] : []), ...labelBoxes];
431
454
  const result = layoutCrowdNames(state, candidates, { now, view: frame.view, obstacles });
@@ -457,6 +480,11 @@ class HubSystem {
457
480
  // Ordinary labels have already completed HUD clearance. Updating only
458
481
  // E's summary preserves those final DOM positions for this paint.
459
482
  this.chrome.setCrowdNameSummary?.(summary[0] ?? null);
483
+ // After the summary's flush, which restores what layout hid: a role chip
484
+ // whose name the crowd pass rejected stays hidden with it.
485
+ if (Hub.hub.roles.size > 0) {
486
+ this.chrome.syncRoleLabels?.(roleItems(scene, scene.actorWith('Player'), cam, frame.view, Hub.hub.roles, project), null, false);
487
+ }
460
488
  }
461
489
 
462
490
  invalidateCrowdNames(scene) {
@@ -480,6 +508,9 @@ class HubSystem {
480
508
  }
481
509
  }
482
510
  if (hidden) {this.crowdHidden = hidden;}
511
+ if (Hub.hub.roles.size > 0) {
512
+ this.chrome.syncRoleLabels?.([], scene.multiplayer?.net?.selfId?.());
513
+ }
483
514
  if (Object.hasOwn(this, 'crowdSprites')) {delete this.crowdSprites;}
484
515
  }
485
516
 
@@ -509,6 +540,9 @@ class HubSystem {
509
540
  this.doorErrors.sync(mp.net, Boolean(Hub.hub.place?.result) && !this.trip, now);
510
541
  }
511
542
  if (!this.chrome) {
543
+ // A UI tree host reads every `clock` in the simulation's time; each
544
+ // root it is sent carries this time.
545
+ setUiTreeTime(() => Hub.simNow() / 1000);
512
546
  this.chrome = makeChrome({
513
547
  worldLabelsDefault: !Hub.deck.labels,
514
548
  ...((Hub.deck.safeInsets === true || Hub.deck.act === true) ? { safeInsets: true } : {}),
@@ -549,7 +583,7 @@ class HubSystem {
549
583
  this.idle ??= makeIdle(this.chrome);
550
584
  this.sound ??= makeSound();
551
585
  if (Hub.deck.soundscape && !this.soundscape) {
552
- this.hearPlace();
586
+ this.hearPlace(scene);
553
587
  }
554
588
  if (!this.sayHooked) {
555
589
  this.sayHooked = true;
@@ -567,6 +601,7 @@ class HubSystem {
567
601
  this.backHooked = true;
568
602
  castleSdk.Hub.onBack(() => this.backFromControl(this.scene));
569
603
  }
604
+ this.hookHostGo();
570
605
  const per = (scene.persistent ??= {});
571
606
  per.hubTickets ??= [];
572
607
  this.keepResident(scene, per.hubTickets);
@@ -583,6 +618,7 @@ class HubSystem {
583
618
  const local = scene.actorWith('Player');
584
619
  this.wearAvatar(scene, local);
585
620
  this.applyTune(local);
621
+ this.vehicle.frame(scene, local, Hub.hub.cars, !this.trip && this.pendingEnd === null);
586
622
  this.watchSession(scene, mp);
587
623
  this.sayHello(scene, mp);
588
624
  if (Hub.hub.place?.push?.version === 1 && Hub.hub.arrivedFacing !== null && mp.net) {
@@ -621,6 +657,8 @@ class HubSystem {
621
657
  if (!this.trip) {this.invites.frame(mp.net);}
622
658
  } else if (Hub.hub.place && this.invites) { this.invites.dispose(); this.invites = null; }
623
659
  this.runCommands(scene, now);
660
+ this.hubEntryFrame(scene, mp, local);
661
+ this.hostGoFrame(scene, mp, local);
624
662
  this.askFriends(scene, mp, now);
625
663
  this.together.frame(mp, this.friendsAll, !this.trip && this.pendingEnd === null, now, this.chrome.peopleOpen?.() === true);
626
664
 
@@ -739,12 +777,17 @@ class HubSystem {
739
777
  }
740
778
  // Grabbing and throwing (v1.3), in a place that offers it: after this
741
779
  // frame's physics step, before the multiplayer kit reports what it owns.
742
- this.grab.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.actionInput,
780
+ this.grab.frame(scene, mp, local, !Object.hasOwn(Hub.hub.cars, mp.net?.selfId?.()) && !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.actionInput,
743
781
  Hub.deck.act === true && Boolean(this.actionInput) && !this.trip && this.pendingEnd === null);
782
+ const myCar = Hub.hub.cars[mp.net?.selfId?.()];
783
+ if (myCar?.horn && !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded) {
784
+ this.chrome.hornPrompt?.(() => mp.net?.send({ k: 'hub-horn' }));
785
+ }
744
786
  if (Hub.deck.act === true) {
745
787
  this.act ??= makeAct(this.chrome, this.grab, this.talk);
746
788
  this.act.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.actionInput && !this.askInput && !this.menuInput && !this.carded);
747
789
  }
790
+ this.noteArrival(mp, now);
748
791
  if (this.trip) {
749
792
  this.stepTrip(scene, mp, local, now);
750
793
  } else if (!Hub.hub.faced) {
@@ -773,9 +816,12 @@ class HubSystem {
773
816
  if (Hub.hub.place?.actions === true || Hub.hub.place?.anonymousEntry === true) {
774
817
  this.actionsDrawn = true;
775
818
  const hud = Hub.hub.hudMe ?? Hub.hub.hud;
776
- const items = this.signIn.items(Hub.hub.place, hud, Hub.hub.actions?.items ?? null);
819
+ const inviting = () => Hub.hub.place?.invite === true && this.invites?.canInvite(mp.net, castleSdk.User) === true;
820
+ const offered = Hub.hub.actions?.items ?? null, invites = offered?.some((item) => INVITE_ACTIONS.has(item?.id)) ? inviting() : true;
821
+ const items = this.signIn.items(Hub.hub.place, hud, invites ? offered : offered.filter((item) => !INVITE_ACTIONS.has(item?.id)));
777
822
  this.chrome.setActions(items, (id, n) => {
778
823
  if (id === 'signin' && Hub.hub.place?.anonymousEntry === true) {void this.signIn.press(hud?.text ?? 'Keep your progress');}
824
+ else if (INVITE_ACTIONS.has(id) && !inviting()) {return;}
779
825
  else {mp.net?.send({ k: 'hub-action', id, n });}
780
826
  }, !this.signIn.pending() && !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded && !this.askInput && !this.menuInput,
781
827
  Hub.hub.actions?.n, scene.data?.engine?.hubActionOverflow === true || !landscapeViewport(), (open) => {
@@ -820,8 +866,8 @@ class HubSystem {
820
866
  // listener, storage read or chrome of it is made. Made with the chrome, and
821
867
  // put away with it (`dispose`): an NPC's line in the talk panel is heard as
822
868
  // the panel is given it, by this player alone.
823
- hearPlace() {
824
- const soundscape = makeSoundscape(Hub.deck.soundscape, { onHide: () => this.sound?.hush(), isOn: () => !this.trip, loudestLoop: () => this.sound?.loudestLoop() ?? 0 });
869
+ hearPlace(scene) {
870
+ const soundscape = makeSoundscape(Hub.deck.soundscape, { lowMemory: scene?.three?.lowMemory === true, onHide: () => this.sound?.hush(), isOn: () => !this.trip, loudestLoop: () => this.sound?.loudestLoop() ?? 0 });
825
871
  this.soundscape = soundscape;
826
872
  this.sound?.filterEvents?.(soundscape.live);
827
873
  this.soundHandlers = { onVolume: (volume) => soundscape.setVolume(volume), onMuted: (muted) => soundscape.setMuted(muted) };
@@ -846,6 +892,7 @@ class HubSystem {
846
892
  }
847
893
  if (!this.tiers) {
848
894
  this.tiers = qualityFor(scene)?.tiers ?? makeTiers({ weakest: Hub.deck.weakestTier === true,
895
+ lowMemory: scene.three?.lowMemory === true,
849
896
  onLayout: (node) => this.chrome?.safeSurface?.('cells-debug', node, 'text') });
850
897
  const pick = (mode) => {
851
898
  this.tiers.set(mode);
@@ -924,6 +971,15 @@ class HubSystem {
924
971
  }
925
972
 
926
973
  // The systems that run after every other one, registered once per runtime.
974
+ // Cars (v1.160) after the multiplayer kit has placed every avatar: each
975
+ // look under its driver's node, riders on their seats, a rider's camera.
976
+ applyCars(s) {
977
+ this.vehicle.draw(s, s.actorWith('Player'), Hub.hub.cars);
978
+ if (Object.keys(Hub.hub.cars).length) {
979
+ this.vehicle.camera(s, s.actorWith('Player'), Hub.hub.cars);
980
+ }
981
+ }
982
+
927
983
  registerLate(scene) {
928
984
  if (this.lateScenes?.has(scene)) {return;}
929
985
  (this.lateScenes ??= new WeakSet()).add(scene);
@@ -931,6 +987,7 @@ class HubSystem {
931
987
  afterBehaviors: (s) => {
932
988
  this.applyVisibility(s);
933
989
  this.applyWear(s);
990
+ this.applyCars(s);
934
991
  this.fadeNames(s);
935
992
  },
936
993
  });
@@ -1033,8 +1090,10 @@ class HubSystem {
1033
1090
  this.tinted.clear();
1034
1091
  this.spawnedHere.clear();
1035
1092
  this.companion?.clear();
1093
+ this.vehicle.clear();
1036
1094
  this.wear.clear(scene);
1037
1095
  this.earned.clear();
1096
+ this.roles.clear();
1038
1097
  this.idle?.release();
1039
1098
  if (this.decor) {
1040
1099
  this.decor.dispose();
@@ -1078,12 +1137,15 @@ class HubSystem {
1078
1137
  this.stash.clear();
1079
1138
  this.tinted.clear();
1080
1139
  this.spawnedHere.clear();
1140
+ this.vehicle.clear();
1081
1141
  if (scene) {
1082
1142
  this.wear.clear(scene);
1083
1143
  this.earned.clear();
1144
+ this.roles.clear();
1084
1145
  } else {
1085
1146
  this.wear.forget();
1086
1147
  this.earned.forget();
1148
+ this.roles.forget();
1087
1149
  }
1088
1150
  }
1089
1151
 
@@ -1099,7 +1161,7 @@ class HubSystem {
1099
1161
  this.wear.frame(
1100
1162
  scene,
1101
1163
  local ?? scene.actorWith('Player'),
1102
- Hub.hub.wearing,
1164
+ roleWearing(Hub.hub.wearing, Hub.hub.roles),
1103
1165
  (playerId) => {
1104
1166
  const index = indexOf(playerId);
1105
1167
  return Avatar.top(index, Avatar.drawn(scene.files, index, style));
@@ -1111,10 +1173,16 @@ class HubSystem {
1111
1173
  return Avatar.hatFit(index, Avatar.drawn(scene.files, index, style));
1112
1174
  },
1113
1175
  );
1176
+ if (Hub.hub.roles.size > 0 || this.roles.size > 0) {
1177
+ this.roles.frame(scene, local ?? scene.actorWith('Player'), Hub.hub.roles, (playerId) => {
1178
+ const index = indexOf(playerId);
1179
+ return Avatar.earnedFit(index, Avatar.drawn(scene.files, index, style));
1180
+ });
1181
+ }
1114
1182
  // Earned items (v1.53): no work at all while nobody shows one and
1115
1183
  // nothing is drawn.
1116
1184
  if (Hub.hub.earned.size > 0 || this.earned.size > 0) {
1117
- this.earned.frame(scene, local ?? scene.actorWith('Player'), Hub.hub.earned, (playerId) => {
1185
+ this.earned.frame(scene, local ?? scene.actorWith('Player'), roleEarned(Hub.hub.earned, Hub.hub.roles), (playerId) => {
1118
1186
  const index = indexOf(playerId);
1119
1187
  return Avatar.earnedFit(index, Avatar.drawn(scene.files, index, style));
1120
1188
  });
@@ -1132,6 +1200,7 @@ class HubSystem {
1132
1200
  if (this.tuneBase?.player !== player) {
1133
1201
  this.tuneBase = { player, speed: player.speed, jumpSpeed: player.jumpSpeed };
1134
1202
  }
1203
+ if (Object.hasOwn(Hub.hub.cars, this.scene?.multiplayer?.net?.selfId?.())) {return;}
1135
1204
  const t = Hub.hub.tune;
1136
1205
  const mul = (v, lo, hi) => (typeof v === 'number' && Number.isFinite(v) ? Math.min(hi, Math.max(lo, v)) : 1);
1137
1206
  const speed = this.tuneBase.speed * mul(t?.speed, 0.25, 3);
@@ -1180,6 +1249,9 @@ class HubSystem {
1180
1249
  const color = Avatar.currentColor(scene);
1181
1250
  if (net === this.helloNet) {
1182
1251
  const back = Rehello.resumed(mp, net, this.helloMark);
1252
+ if (back) {
1253
+ this.admitEpoch = (this.admitEpoch ?? 0) + 1;
1254
+ }
1183
1255
  // (Another player id was reset for by `newIdentity`, already.) A game
1184
1256
  // (a place with `result`) back under the same id keeps the old way, as
1185
1257
  // its server does, unless its place says `resume: true` (v1.72); under a
@@ -1190,6 +1262,7 @@ class HubSystem {
1190
1262
  if (say !== 'none') {
1191
1263
  console.log(`[hub] the connection came back (${back}): saying a ${say} hello`);
1192
1264
  this.sendHello(scene, mp, net, avatar, say === 'resume' ? { resume: true } : { solo: true });
1265
+ this.noTripsAfterHello(net);
1193
1266
  if (back === 'world') {
1194
1267
  this.talk?.resume();
1195
1268
  }
@@ -1220,6 +1293,7 @@ class HubSystem {
1220
1293
  this.freshSession(scene);
1221
1294
  }
1222
1295
  this.sendHello(scene, mp, net, avatar, { again, inviteNear });
1296
+ this.noTripsAfterHello(net);
1223
1297
  if (!again) {this.invites?.landed();}
1224
1298
  }
1225
1299
 
@@ -1229,6 +1303,7 @@ class HubSystem {
1229
1303
  // as on any switch of session, along with what this client kept of it.
1230
1304
  newIdentity() {
1231
1305
  this.pushVisit = null;
1306
+ this.admitEpoch = (this.admitEpoch ?? 0) + 1;
1232
1307
  console.log('[hub] the connection has a new player id: a new session');
1233
1308
  this.identityPlace = Hub.hub.place ?? this.identityPlace;
1234
1309
  Hub.clear();
@@ -1280,6 +1355,13 @@ class HubSystem {
1280
1355
  }
1281
1356
  }
1282
1357
 
1358
+ // v1.156: after a hello, an app that cannot go through doors says so
1359
+ // (`client/noTrips.js`).
1360
+ noTripsAfterHello(net) {
1361
+ this.noTrips ??= makeNoTrips(castleSdk);
1362
+ this.noTrips.afterHello(net, () => this.helloNet === net);
1363
+ }
1364
+
1283
1365
  // `solo`: a party of one carrying nothing and naming no friend, as `resume`
1284
1366
  // is, without saying it resumes (a game's new session, `helloAfter`).
1285
1367
  sendHello(scene, mp, net, avatar, { again = false, resume = false, solo = resume, inviteNear = null } = {}) {
@@ -1304,8 +1386,18 @@ class HubSystem {
1304
1386
  this.helloMark = Rehello.mark(mp, net, () => this.newIdentity());
1305
1387
  const per = scene.persistent;
1306
1388
  const arriving = per.hubArriving ?? null;
1389
+ const readDevice = (read) => { try { return read(); } catch { return undefined; } };
1390
+ const device = encodeDeviceClass({
1391
+ lowMemory: scene.three?.lowMemory === true,
1392
+ cores: readDevice(() => typeof navigator === 'undefined' ? undefined : navigator.hardwareConcurrency),
1393
+ dpr: readDevice(() => typeof devicePixelRatio === 'undefined' ? undefined : devicePixelRatio),
1394
+ width: readDevice(() => typeof screen === 'undefined' ? undefined : screen.width),
1395
+ height: readDevice(() => typeof screen === 'undefined' ? undefined : screen.height),
1396
+ deviceMemory: readDevice(() => typeof navigator === 'undefined' ? undefined : navigator.deviceMemory),
1397
+ });
1307
1398
  net.send({
1308
1399
  k: 'hub-hello',
1400
+ ...(device ? { device } : {}),
1309
1401
  avatar,
1310
1402
  ...(Number.isInteger(this.helloColor) && this.helloColor > 0 ? { color: this.helloColor } : {}),
1311
1403
  from: arriving?.door ?? null,
@@ -1531,10 +1623,132 @@ class HubSystem {
1531
1623
  this.pendingEnd = this.endCovered ? now : now + END_PAUSE_MS;
1532
1624
  this.endSession = sessionKey(scene);
1533
1625
  this.endLeaving = null;
1626
+ // Only a game is over: a place without a result that sends a player
1627
+ // back (the House's front door, the first room's way to the Town)
1628
+ // says what it says in its own HUD.
1534
1629
  const r = scene.persistent.hubResult;
1535
- this.toast = { text: r && Date.now() - r.at < 30000 ? resultLine(r) : 'Game over', until: now + END_PAUSE_MS + 200 };
1630
+ if (Hub.hub.place?.result) {
1631
+ this.toast = { text: r && Date.now() - r.at < 30000 ? resultLine(r) : 'Game over', until: now + END_PAUSE_MS + 200 };
1632
+ }
1633
+ }
1634
+ }
1635
+ }
1636
+
1637
+ // A hub-entry link (`client/hubEntry.js`): the Town's link for the House or
1638
+ // one of its doors, read once per page load on the first place it enters
1639
+ // at the root. An invite wins; a trip or session swap first spends it.
1640
+ hubEntryFrame(scene, mp, local) {
1641
+ this.hubEntry ??= makeHubEntry({
1642
+ joinHint: () => castleSdk.Multiplayer?.joinHint?.() ?? null,
1643
+ extras: (target) => this.hubEntryExtras(target),
1644
+ act: (target, info) => this.hubEntryAct(this.scene, target, info),
1645
+ current: () => this.hubEntryContext(this.scene),
1646
+ });
1647
+ // Admissions are counted from the first look at a connection, not only
1648
+ // from its first hello: an invite check can hold that hello back, and a
1649
+ // re-admission meanwhile must spend the link too.
1650
+ if (mp.net && this.hubEntry.state() !== 'done' && this.entryWatch?.net !== mp.net) {
1651
+ this.entryWatch = { net: mp.net, w: Rehello.watch(mp, mp.net) };
1652
+ }
1653
+ this.hubEntry.frame(this.hubEntryContext(scene, mp, local));
1654
+ }
1655
+
1656
+ // The host's Go (v1.155, `client/hostGo.js`): through a door of this
1657
+ // place as if its pad had fired. An SDK without `Hub.onGo` never sends one.
1658
+ hookHostGo() {
1659
+ if (this.hostGoHooked || typeof castleSdk.Hub?.onGo !== 'function') {
1660
+ return;
1661
+ }
1662
+ this.hostGoHooked = true;
1663
+ this.hostGo ??= makeHostGo();
1664
+ castleSdk.Hub.onGo((go) => this.hostGo.offer(go, { at: performance.now(), tripping: Boolean(this.trip) }));
1665
+ }
1666
+
1667
+ hostGoFrame(scene, mp, local) {
1668
+ const msg = this.hostGo?.take({
1669
+ now: performance.now(),
1670
+ settled: this.hubEntryContext(scene, mp, local).settled,
1671
+ tripping: Boolean(this.trip),
1672
+ result: Boolean(Hub.hub.place?.result),
1673
+ doors: Hub.hub.doors,
1674
+ });
1675
+ if (msg) {
1676
+ console.log(`[hub-host-go] ${JSON.stringify({ door: msg.door, party: msg.party, owner: Boolean(msg.owner) })}`);
1677
+ this.goHub(scene, msg);
1678
+ }
1679
+ }
1680
+
1681
+ // Where the first entry stands now. `epoch` moves at every re-admission
1682
+ // on a greeted connection and every new player id (`sayHello`,
1683
+ // `newIdentity`): a reconnect on the same net spends the link.
1684
+ hubEntryContext(scene, mp = scene?.multiplayer, local = scene?.actorWith?.('Player')) {
1685
+ const place = Hub.hub.place;
1686
+ const per = scene?.persistent ?? {};
1687
+ const net = mp?.net ?? null;
1688
+ const selfId = net?.selfId?.() ?? null;
1689
+ return {
1690
+ known: Boolean(place),
1691
+ root: Boolean(scene && mp && place) && !place.result && !this.trip && this.tripCount === 0 && !(per.hubDepth > 0) &&
1692
+ !(per.hubTickets?.length) && mp.target?.mode !== 'hub' && !per.hubArriving?.door,
1693
+ net,
1694
+ selfId,
1695
+ epoch: net ? `${this.admitEpoch ?? 0}:${this.entryWatch?.net === net ? this.entryWatch.w.again : '-'}` : null,
1696
+ invited: this.invites?.carried?.() === true,
1697
+ settled: Boolean(net) && net === this.helloNet && !net.closed?.() && mp?.placed?.() === true &&
1698
+ this.pendingEnd === null && Boolean(local) && Hub.hub.doors.length > 0 && !Hub.hub.held.has(selfId),
1699
+ };
1700
+ }
1701
+
1702
+ // Read just before deciding: whether this player is a guest (no House the
1703
+ // kit can host: firstVisit.js in the Town), and the host's door rows.
1704
+ async hubEntryExtras(target) {
1705
+ const selfId = this.scene?.multiplayer?.net?.selfId?.();
1706
+ let guest = Hub.hub.guests?.has?.(selfId) === true ? true : null;
1707
+ if (guest === null) {
1708
+ try {
1709
+ const me = await castleSdk.User?.getCurrent?.();
1710
+ guest = me && typeof me === 'object' ? !me.userId || me.isAnonymous === true : null;
1711
+ } catch { guest = null; }
1712
+ }
1713
+ let host = null;
1714
+ if (target.kind === 'door') {
1715
+ try {
1716
+ const answer = await castleSdk.Hub?.doors?.();
1717
+ if (answer?.status === 'ok' && Array.isArray(answer.doors)) {
1718
+ host = new Map(answer.doors.filter((d) => typeof d?.doorId === 'string').map((d) => [d.doorId, d]));
1719
+ }
1720
+ } catch { host = null; }
1721
+ }
1722
+ return { guest, host };
1723
+ }
1724
+
1725
+ hubEntryAct(scene, target, { guest = null, host = null } = {}) {
1726
+ const mp = scene?.multiplayer;
1727
+ // `makeHubEntry` checked the whole context again just now; this is the backstop.
1728
+ if (!scene || !mp?.net || this.trip || this.tripCount > 0 || this.pendingEnd !== null || Hub.hub.place?.result ||
1729
+ Hub.hub.held.has(mp.net.selfId?.())) {
1730
+ return;
1731
+ }
1732
+ const me = scene.actorWith('Player')?.components.Transform;
1733
+ const homes = [];
1734
+ for (const actor of allActors(scene)) {
1735
+ const door = actor.components?.HubDoor;
1736
+ if (door?.to === 'deck:house' && typeof door.id === 'string') {
1737
+ const t = actor.components.Transform;
1738
+ homes.push({ id: door.id, d: me && t ? Math.hypot(t.x - me.x, t.z - me.z) : Infinity });
1536
1739
  }
1537
1740
  }
1741
+ homes.sort((a, b) => a.d - b.d);
1742
+ const plan = planHubEntry(target, { listed: Hub.hub.doors, homes: homes.map((h) => h.id), host, guest });
1743
+ console.log(`[hub-entry] ${JSON.stringify({ target, plan: plan ? Object.keys(plan) : null })}`);
1744
+ if (plan?.go) {
1745
+ this.goHub(scene, { door: plan.go.door, title: plan.go.title });
1746
+ } else if (plan?.jump) {
1747
+ this.goDoor(scene, plan.jump);
1748
+ }
1749
+ if (plan?.toast) {
1750
+ this.toast = { text: plan.toast, until: performance.now() + TOAST_MS };
1751
+ }
1538
1752
  }
1539
1753
 
1540
1754
  // Through a door ghost fixed a group for (the place's server fired its pad):
@@ -2014,40 +2228,20 @@ class HubSystem {
2014
2228
  // invitation into the party (Invite), or Join -- beside a party member or a
2015
2229
  // friend in this layer (the place moves this player), into the layer of
2016
2230
  // this place a friend is in (a jump), or to the door of the game a friend
2017
- // is inside.
2231
+ // is inside (`personAction`, shared with a native host).
2018
2232
  join(scene, person, action) {
2019
- const net = scene?.multiplayer?.net;
2020
- if (!net || this.trip || !person) {
2233
+ if (this.trip) {
2021
2234
  return;
2022
2235
  }
2023
- const say = (text) => {
2024
- this.toast = { text, until: performance.now() + TOAST_MS };
2025
- };
2026
- if (action === 'find' && person.playerId) {
2027
- this.together.find(person.playerId);
2028
- } else if (action === 'invite' && person.playerId) {
2029
- net.send({ k: 'hub-party', op: 'invite', player: person.playerId });
2030
- say(`Invited ${person.username ?? 'them'} to your party`);
2031
- } else if (action === 'goto' && person.playerId) {
2032
- this.sendJump(net, { k: 'hub-goto', player: person.playerId });
2033
- } else if (action === 'door' && person.door && person.owner) {
2034
- // A friend at home: the place sends this player through their House
2035
- // door with the owner (`hub-go` carrying `owner`), ending the visit here
2036
- // as any door's trip does. A host that predates the owner acquires this
2037
- // player's own House, as the pad would have.
2038
- this.sendJump(net, { k: 'hub-house-visit', door: person.door, owner: person.owner });
2039
- say(`Going to ${person.username ?? 'your friend'}'s House`);
2040
- } else if (action === 'door' && person.door) {
2041
- this.sendJump(net, { k: 'hub-door-jump', door: person.door });
2042
- // A friend inside the game is said to be; someone standing at the door
2043
- // is simply gone to.
2044
- if (person.playerId === null) {
2045
- const title = Hub.hub.doors.find((d) => d.id === person.door)?.title ?? 'that game';
2046
- say(`${person.username ?? 'Your friend'} is inside ${title}`);
2047
- }
2048
- } else if (action === 'jump' && person.userId) {
2049
- this.jump(scene, { userId: person.userId, username: person.username });
2050
- }
2236
+ personAction(scene?.multiplayer?.net, person, action, {
2237
+ together: this.together,
2238
+ say: (text) => {
2239
+ this.toast = { text, until: performance.now() + TOAST_MS };
2240
+ },
2241
+ jump: (net, message) => this.sendJump(net, message),
2242
+ jumpTo: (friend) => this.jump(scene, friend),
2243
+ doors: Hub.hub.doors,
2244
+ });
2051
2245
  }
2052
2246
 
2053
2247
  // "Stuck?" (v1.33, `client/stuck.js`), only in a deck whose castle.json asks
@@ -2068,7 +2262,8 @@ class HubSystem {
2068
2262
  return;
2069
2263
  }
2070
2264
  this.stuck ??= makeStuck();
2071
- const walking = walkInput(scene.keys, scene.moveInput, scene.cameraControl === 'orbit');
2265
+ const driving = Object.hasOwn(Hub.hub.cars, selfId);
2266
+ const walking = driving ? carInput(scene.keys, scene.moveInput).forward !== 0 : walkInput(scene.keys, scene.moveInput, scene.cameraControl === 'orbit');
2072
2267
  const hidden = globalThis.document?.visibilityState === 'hidden';
2073
2268
  const shown = stuckFrame(this.stuck, { key: `${this.sceneKey}|${Hub.hub.place.id}`, x: t.x, z: t.z, walking, hidden }, now);
2074
2269
  let text = shown ? stuckText(offer.to) : null;
@@ -2088,6 +2283,7 @@ class HubSystem {
2088
2283
  this.toast = { text: stuckDone(done.to, done.spot), until: now + TOAST_MS };
2089
2284
  }
2090
2285
  }
2286
+ if (driving && shown) {text = stuckText(null, false, true);}
2091
2287
  this.stuckShown = shown;
2092
2288
  this.chrome.stuckPrompt?.(text, () => this.unstick(this.scene));
2093
2289
  }
@@ -2482,15 +2678,20 @@ class HubSystem {
2482
2678
 
2483
2679
  // A user Back first dismisses transient chrome; automatic travel still uses back.
2484
2680
  backFromControl(scene) {
2485
- if (this.chrome?.actionOverflowOpen?.()) {
2681
+ const press = backPress({
2682
+ overflowOpen: this.chrome?.actionOverflowOpen?.(),
2683
+ menuOpen: this.chrome?.menuOpen?.(),
2684
+ inGame: Boolean(Hub.hub.place?.result),
2685
+ });
2686
+ if (press === 'overflow') {
2486
2687
  this.chrome.cancelActionOverflow();
2487
2688
  return;
2488
2689
  }
2489
- if (this.chrome?.menuOpen?.()) {
2690
+ if (press === 'menu') {
2490
2691
  this.chrome.cancelMenu();
2491
2692
  return;
2492
2693
  }
2493
- if (Hub.hub.place?.result) {scene.multiplayer?.net?.send({ k: 'hub-door-quit' });}
2694
+ if (press === 'quit') {scene.multiplayer?.net?.send({ k: 'hub-door-quit' });}
2494
2695
  this.back(scene);
2495
2696
  }
2496
2697
 
@@ -2509,10 +2710,11 @@ class HubSystem {
2509
2710
  }
2510
2711
  const per = scene.persistent;
2511
2712
  const ticket = per.hubTickets.pop();
2713
+ const route = backRoute({ ticket, hubDepth: per.hubDepth });
2512
2714
  // A place reached by a hub trip goes back the way the host says (`Hub.back`):
2513
2715
  // to the place in this runtime the ticket remembers, or, with no ticket, to
2514
2716
  // wherever ghost's return ticket leads, from its pack.
2515
- if (ticket?.hub || (!ticket && per.hubDepth > 0)) {
2717
+ if (route === 'host') {
2516
2718
  const stay = ticket ? { content: ticket.content ?? null } : undefined;
2517
2719
  this.startTrip(scene, {
2518
2720
  scene: ticket?.scene ?? null,
@@ -2543,7 +2745,7 @@ class HubSystem {
2543
2745
  }
2544
2746
  return;
2545
2747
  }
2546
- if (!ticket) {
2748
+ if (route === 'instance') {
2547
2749
  const place = Hub.hub.place?.id ?? 'main';
2548
2750
  // Another deck's place runs that deck's server: its key keeps the prefix.
2549
2751
  const prefix = scene.content?.sessionKeyPrefix ?? '';
@@ -2839,6 +3041,27 @@ class HubSystem {
2839
3041
  }
2840
3042
  }
2841
3043
 
3044
+ // This player's latest arrival in a session (a join, a trip's, a
3045
+ // reconnect's), for a door's roster window (`contentDeadline`). Each frame,
3046
+ // before the trip steps.
3047
+ noteArrival(mp, now) {
3048
+ const placed = mp.placed?.() ?? null;
3049
+ if (placed === true && this.placedLast !== true) {
3050
+ this.arrivedAt = now;
3051
+ }
3052
+ this.placedLast = placed;
3053
+ }
3054
+
3055
+ // When a door still being asked gives up: LOADING_LIMIT_MS after it was
3056
+ // asked, or after the roster window of this player's latest arrival when
3057
+ // that ends later (v1.154). A player not placed right now is arriving now.
3058
+ contentDeadline(trip, now) {
3059
+ const from = trip.target.pendingFrom ?? trip.startedAt;
3060
+ const arrived = this.placedLast === false ? now : this.arrivedAt;
3061
+ const grace = arrived === undefined ? 0 : Math.min(ROSTER_LAG_MS, Math.max(0, arrived + ROSTER_LAG_MS - from));
3062
+ return from + LOADING_LIMIT_MS + grace;
3063
+ }
3064
+
2842
3065
  // Whether a door to another deck has its content, once the cover is down.
2843
3066
  // Until then the cover holds; a pack that failed, or never came, keeps the
2844
3067
  // door shut: the trip turns back without leaving this place (HUB.md, Doors:
@@ -2851,7 +3074,7 @@ class HubSystem {
2851
3074
  trip.marks.covered ??= now;
2852
3075
  this.setTripCover(1, trip);
2853
3076
  // A retried way back has its own deadline, from when it was asked again.
2854
- if (!pending.done && now - (trip.target.pendingFrom ?? trip.startedAt) < LOADING_LIMIT_MS) {
3077
+ if (!pending.done && now < this.contentDeadline(trip, now)) {
2855
3078
  return false;
2856
3079
  }
2857
3080
  // A player barred from the hub is told so, and not asked for again. A way
@@ -3203,7 +3426,7 @@ class HubSystem {
3203
3426
  }
3204
3427
  }
3205
3428
  if (Hub.deck.yourGames && trip.target.arrive?.returning && trip.target.arrive.door) {
3206
- this.yourGames().returned(trip.target.arrive.door, r);
3429
+ this.yourGames().returned(trip.target.arrive.door, r, houseDoor(scene, trip.target.arrive.door));
3207
3430
  }
3208
3431
  if (Hub.deck.cues && !Hub.deck.yourGames && trip.target.arrive?.returning && trip.target.arrive.door) {
3209
3432
  // Cues: a next step, put once the player is back in the town, whether
@@ -3282,11 +3505,12 @@ class HubSystem {
3282
3505
  // Away in a classic deck, the cover is down and Back is the only control.
3283
3506
  const away = this.trip?.phase === 'away';
3284
3507
  const hostTrail = scene.persistent.hubDepth > 0;
3508
+ // Old Android landscape hosts draw Exit deck, so keep a way back into
3509
+ // town. Hosts advertising their landscape Back retain sole ownership.
3510
+ const back = backControl({ away, idle, pendingEnd: this.pendingEnd, hostTrail, place, ticket, kitBack: hostTrail && kitBackNeeded() });
3285
3511
  chrome.showBack(
3286
- // Old Android landscape hosts draw Exit deck, so keep a way back into
3287
- // town. Hosts advertising their landscape Back retain sole ownership.
3288
- (away || (idle && this.pendingEnd === null)) && (hostTrail ? place !== null && kitBackNeeded() : inGame || Boolean(ticket)),
3289
- ticket?.title ?? (hostTrail && kitBackNeeded() ? 'Back' : 'Again'),
3512
+ back.show,
3513
+ back.label,
3290
3514
  );
3291
3515
  const free = idle && place !== null && this.pendingEnd === null && !this.talk.talking() && !this.carded;
3292
3516
  const town = free && !inGame;
@@ -3445,21 +3669,21 @@ class HubSystem {
3445
3669
  }
3446
3670
 
3447
3671
  if (panels) {
3448
- const spec = Hub.hub.hudMe ?? Hub.hub.hud;
3449
- let timer = null;
3450
- if (spec?.timer?.since !== undefined) {
3451
- timer = Math.max(0, (Hub.simNow() - spec.timer.since) / 1000);
3452
- } else if (spec?.timer?.until !== undefined) {
3453
- timer = Math.max(0, (spec.timer.until - Hub.simNow()) / 1000);
3454
- }
3672
+ // The player's own HUD over the place's, and its timer's seconds now.
3673
+ const { spec, timer } = hudInputs(Hub.hub, Hub.simNow());
3455
3674
  // A place that asks (`hud.clear`, v1.26) has its HUD kept short and its
3456
3675
  // labels kept out from under it; any other is drawn as it always was.
3457
3676
  if (place?.hud?.clear === true || this.hudClear) {
3458
3677
  this.hudClear = place?.hud?.clear === true;
3459
3678
  chrome.setHudClear?.(this.hudClear);
3460
3679
  }
3461
- chrome.setHud(idle || this.trip?.phase === 'revealing' ? spec : null, timer);
3680
+ // The sim time lets the chrome send the timer as a clock that counts
3681
+ // by itself, sent again only when its base moves.
3682
+ chrome.setHud(idle || this.trip?.phase === 'revealing' ? spec : null, timer, Hub.simNow());
3462
3683
  }
3684
+ // A server time correction with nothing else changed still reaches a UI
3685
+ // tree host, whose clocks read the simulation time.
3686
+ syncUiTreeTime();
3463
3687
 
3464
3688
  const cam = scene.three?.camera;
3465
3689
  const view = { w: window.innerWidth, h: window.innerHeight };
@@ -3577,6 +3801,7 @@ class HubSystem {
3577
3801
  chrome.setPointers?.(pointers.map((point) => offsetWorldPoint(point, view)));
3578
3802
  if (cam && idle) {
3579
3803
  labels.push(...this.markItems(scene, local, cam, view));
3804
+ labels.push(...roleItems(scene, local, cam, view, Hub.hub.roles, project));
3580
3805
  labels.push(...this.idle.labels(scene, local, cam, view, project));
3581
3806
  labels.push(...this.say.labels(scene, local, cam, view, project, scene.multiplayer?.net?.selfId?.() ?? null));
3582
3807
  }
@@ -3820,31 +4045,14 @@ class HubSystem {
3820
4045
 
3821
4046
  // Reports a player to Castle (`Hub.report`), one at a time.
3822
4047
  report(person) {
3823
- if (this.reporting || !person?.userId || typeof castleSdk.Hub?.report !== 'function') {
3824
- return;
3825
- }
3826
- this.reporting = true;
3827
- const say = (text) => {
3828
- this.toast = { text, until: performance.now() + TOAST_MS };
3829
- };
3830
- Promise.resolve(castleSdk.Hub.report(person.userId))
3831
- .then((answer) => {
3832
- if (answer?.status === 'ok') {
3833
- say('Reported. Thanks.');
3834
- return;
3835
- }
3836
- this.reportOff = true;
3837
- say("Reporting isn't available here.");
3838
- })
3839
- .catch((err) => {
3840
- if (err?.code === 'UNKNOWN_COMMAND' || err?.code === 'CASTLE_HOST_UNAVAILABLE') {
3841
- this.reportOff = true;
3842
- }
3843
- say("That report didn't go through. Try again later.");
3844
- })
3845
- .finally(() => {
3846
- this.reporting = false;
3847
- });
4048
+ reportPerson(person, {
4049
+ report: typeof castleSdk.Hub?.report === 'function' ? (userId) => castleSdk.Hub.report(userId) : null,
4050
+ // `reporting` and `reportOff` are this system's own.
4051
+ gate: this,
4052
+ say: (text) => {
4053
+ this.toast = { text, until: performance.now() + TOAST_MS };
4054
+ },
4055
+ });
3848
4056
  }
3849
4057
 
3850
4058
  // The tags the place put over players (`hub.mark`): over this player's own
@@ -3955,8 +4163,10 @@ class HubSystem {
3955
4163
  // What players wear hangs on the avatars' nodes and holds shares of the
3956
4164
  // hat builds: given back with the runtime.
3957
4165
  this.companion?.dispose();
4166
+ this.vehicle?.clear();
3958
4167
  this.wear?.clear();
3959
4168
  this.earned?.clear();
4169
+ this.roles?.clear();
3960
4170
  }
3961
4171
  }
3962
4172
 
@@ -4004,6 +4214,11 @@ function isCabinet(door) {
4004
4214
  }
4005
4215
 
4006
4216
  // The scene actor of a door id: the actor whose `HubDoor` names it.
4217
+ // Whether this place's door leads into a House (a player's own, or a friend's).
4218
+ function houseDoor(scene, door) {
4219
+ return Boolean(door) && allActors(scene).some((actor) => actor.components?.HubDoor?.id === door && actor.components.HubDoor.to === 'deck:house');
4220
+ }
4221
+
4007
4222
  function doorActor(scene, door) {
4008
4223
  if (!door) {
4009
4224
  return null;