castle-web-cli 0.4.237 → 0.4.239

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 (239) hide show
  1. package/dist/bundle.d.ts +24 -0
  2. package/dist/bundle.js +447 -4
  3. package/dist/bundleLatin1.d.ts +6 -0
  4. package/dist/bundleLatin1.js +333 -0
  5. package/dist/castle-host/host.d.ts +10 -1
  6. package/dist/castle-host/host.js +133 -9
  7. package/dist/castleJson.d.ts +2 -0
  8. package/dist/castleJson.js +1 -0
  9. package/dist/deckExports.d.ts +35 -0
  10. package/dist/deckExports.js +365 -0
  11. package/dist/importCheckHook.d.ts +1 -0
  12. package/dist/importCheckHook.js +1 -1
  13. package/dist/index.js +21 -0
  14. package/dist/init.js +2 -1
  15. package/dist/multiplayerDoc.d.ts +1 -1
  16. package/dist/multiplayerDoc.js +9 -0
  17. package/dist/platformDoc.js +2 -1
  18. package/dist/playPagePolicy.d.ts +1 -0
  19. package/dist/playPagePolicy.js +8 -3
  20. package/dist/roomLogs.d.ts +39 -0
  21. package/dist/roomLogs.js +166 -0
  22. package/dist/save-deck.js +4 -0
  23. package/kits/base/CLAUDE.md +1 -0
  24. package/kits/base/castle.json +1 -1
  25. package/kits/base/sdk/README.md +113 -2
  26. package/kits/base/sdk/castle.d.ts +6 -2
  27. package/kits/base/sdk/castle.js +2 -0
  28. package/kits/base/sdk/commands.d.ts +56 -1
  29. package/kits/base/sdk/commands.js +29 -1
  30. package/kits/base/sdk/hub.d.ts +17 -0
  31. package/kits/base/sdk/hub.js +33 -9
  32. package/kits/base/sdk/localCache.d.ts +27 -0
  33. package/kits/base/sdk/localCache.js +115 -0
  34. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  35. package/kits/base/sdk/localCacheStore.js +358 -0
  36. package/kits/base/sdk/multiplayer.js +30 -0
  37. package/kits/base/sdk/rooms.d.ts +11 -0
  38. package/kits/base/sdk/rooms.js +22 -0
  39. package/kits/base/sdk/store.d.ts +8 -2
  40. package/kits/base/sdk/store.js +5 -1
  41. package/kits/base/sdk/transport.d.ts +1 -0
  42. package/kits/base/sdk/transport.js +4 -5
  43. package/kits/hub-game/CLAUDE.md +22 -2
  44. package/kits/hub-game/castle.json +8 -5
  45. package/kits/hub-game/code/client/act.js +66 -91
  46. package/kits/hub-game/code/client/actCore.js +134 -0
  47. package/kits/hub-game/code/client/car.js +35 -0
  48. package/kits/hub-game/code/client/chrome.js +208 -381
  49. package/kits/hub-game/code/client/crowdNames.js +2 -2
  50. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  51. package/kits/hub-game/code/client/hats.js +2 -0
  52. package/kits/hub-game/code/client/hookLayer.js +99 -48
  53. package/kits/hub-game/code/client/hostGo.js +77 -0
  54. package/kits/hub-game/code/client/hubControls.js +125 -0
  55. package/kits/hub-game/code/client/hubEntry.js +187 -0
  56. package/kits/hub-game/code/client/hudSurface.js +148 -0
  57. package/kits/hub-game/code/client/hudTree.js +96 -0
  58. package/kits/hub-game/code/client/idle.js +59 -13
  59. package/kits/hub-game/code/client/invites.js +13 -4
  60. package/kits/hub-game/code/client/menuIcons.js +8 -0
  61. package/kits/hub-game/code/client/menuRows.js +8 -2
  62. package/kits/hub-game/code/client/noTrips.js +38 -0
  63. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  64. package/kits/hub-game/code/client/rehello.js +3 -1
  65. package/kits/hub-game/code/client/riders.js +26 -0
  66. package/kits/hub-game/code/client/role.js +79 -0
  67. package/kits/hub-game/code/client/safeLayout.js +32 -3
  68. package/kits/hub-game/code/client/sound.js +10 -3
  69. package/kits/hub-game/code/client/soundscape.js +2 -2
  70. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  71. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  72. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  73. package/kits/hub-game/code/client/state.js +19 -0
  74. package/kits/hub-game/code/client/stuck.js +2 -1
  75. package/kits/hub-game/code/client/talkSurface.js +178 -0
  76. package/kits/hub-game/code/client/talkTree.js +238 -0
  77. package/kits/hub-game/code/client/tiers.js +8 -5
  78. package/kits/hub-game/code/client/uiDom.js +600 -0
  79. package/kits/hub-game/code/client/uiTree.js +359 -0
  80. package/kits/hub-game/code/client/vehicle.js +156 -0
  81. package/kits/hub-game/code/client/wear.js +27 -5
  82. package/kits/hub-game/code/client/worldLabels.js +13 -3
  83. package/kits/hub-game/code/client/yours.js +10 -3
  84. package/kits/hub-game/code/server/actors.js +4 -3
  85. package/kits/hub-game/code/server/analytics.js +61 -18
  86. package/kits/hub-game/code/server/decor.js +56 -16
  87. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  88. package/kits/hub-game/code/server/hub.js +261 -46
  89. package/kits/hub-game/code/server/idle.js +118 -5
  90. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  91. package/kits/hub-game/code/server/manifest.js +46 -4
  92. package/kits/hub-game/code/server/npcs.js +4 -2
  93. package/kits/hub-game/code/server/players.js +3 -0
  94. package/kits/hub-game/code/server/role.js +142 -0
  95. package/kits/hub-game/code/server/standing.js +6 -4
  96. package/kits/hub-game/code/server/trackQueue.js +29 -0
  97. package/kits/hub-game/code/server/vehicle.js +126 -0
  98. package/kits/hub-game/code/shared/car.js +52 -0
  99. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  100. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  101. package/kits/hub-game/code/shared/expression.js +9 -0
  102. package/kits/hub-game/code/systems/hub.js +281 -86
  103. package/kits/hub-game/docs/analytics.md +15 -3
  104. package/kits/hub-game/docs/contract.md +352 -14
  105. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  106. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  107. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  108. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  109. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  110. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  111. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  112. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  113. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  114. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  115. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  116. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  117. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  118. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  119. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  120. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  121. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  122. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  123. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  124. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  125. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  126. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  127. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  128. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  129. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  130. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  131. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  132. package/kits/hub-game/package-lock.json +1 -1
  133. package/kits/hub-game/package.json +1 -1
  134. package/kits/hub-game/scripts/check.mjs +7 -4
  135. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  136. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  137. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  138. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  139. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  140. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  141. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  142. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  143. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  144. package/kits/hub-game/scripts/test-analytics.mjs +100 -6
  145. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  146. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  147. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  148. package/kits/hub-game/scripts/test-car.mjs +43 -0
  149. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  150. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  151. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  152. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  153. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  154. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  155. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  156. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  157. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  158. package/kits/hub-game/scripts/test-hub-ops.mjs +103 -0
  159. package/kits/hub-game/scripts/test-hub-trip.mjs +20 -1
  160. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  161. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  162. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  163. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  164. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  165. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  166. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  167. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  168. package/kits/hub-game/scripts/test-menu-client.mjs +1 -1
  169. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  170. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  171. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  172. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  173. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  174. package/kits/hub-game/scripts/test-resync.mjs +196 -0
  175. package/kits/hub-game/scripts/test-role-client.mjs +427 -0
  176. package/kits/hub-game/scripts/test-role.mjs +350 -0
  177. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  178. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  179. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  180. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  181. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  182. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  183. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  184. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  185. package/kits/hub-game/scripts/test-vehicle-client.mjs +168 -0
  186. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  187. package/kits/hub-game/scripts/test-world-labels.mjs +40 -0
  188. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  189. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  190. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  191. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  192. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  193. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +810 -0
  194. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  195. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  196. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  197. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  198. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +301 -0
  199. package/kits/multiplayer-3d/castle.json +4 -4
  200. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  201. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  202. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  203. package/kits/multiplayer-3d/package-lock.json +1 -1
  204. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  205. package/kits/physics-3d/CLAUDE.md +1 -1
  206. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  207. package/kits/physics-3d/castle.json +2 -2
  208. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  209. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  210. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  211. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  212. package/kits/physics-3d/engine3d/world3d.js +6 -3
  213. package/kits/physics-3d/package.json +1 -1
  214. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  215. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  216. package/kits/physics-3d/systems/physics3d.js +5 -2
  217. package/kits/real-time/castle.json +2 -2
  218. package/kits/real-time/code/client/messages.js +5 -0
  219. package/kits/real-time/code/server/session.js +28 -1
  220. package/kits/real-time/package-lock.json +1 -1
  221. package/package.json +5 -4
  222. package/vendor/three/LICENSE +21 -0
  223. package/vendor/three/build/three.core.js +58773 -0
  224. package/vendor/three/build/three.module.js +18251 -0
  225. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  226. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  227. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  228. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  229. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  230. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  231. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  232. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  233. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  234. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  235. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  236. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  237. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  238. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  239. package/vendor/three/package.json +134 -0
@@ -140,12 +140,12 @@ export function layoutCrowdNames(state, candidates, { now, view, obstacles = []
140
140
  const limit = tiny ? 0 : dense ? 2 : 1;
141
141
  let used = 0;
142
142
  for (const candidate of group) {
143
- const blocked = obstacles.some((box) => touches(candidate.box, box));
143
+ const blocked = obstacles.some((box) => box.rolePlayerId !== candidate.id && touches(candidate.box, box));
144
144
  const conflicts = chosenBoxes.some((box) => touches(candidate.box, box));
145
145
  let allowed = used < limit && !blocked && !conflicts;
146
146
  let waiting = false;
147
147
  if (allowed && state.suppressed.has(candidate.id)) {
148
- const separated = !obstacles.some((box) => touches(candidate.box, box, RESTORE_PX)) &&
148
+ const separated = !obstacles.some((box) => box.rolePlayerId !== candidate.id && touches(candidate.box, box, RESTORE_PX)) &&
149
149
  !chosenBoxes.some((box) => touches(candidate.box, box, RESTORE_PX));
150
150
  if (!separated) {
151
151
  state.clearSince.delete(candidate.id);
@@ -0,0 +1,109 @@
1
+ // v1.158: a ring (or compact grid) of basics, then paged place/original emotes.
2
+ import { panelPlacement } from './safeLayout.js';
3
+
4
+ export function makeEmoteWheel({ root, el, view, bands, trigger, pick, close }) {
5
+ const sheet = el('div', { position: 'absolute', display: 'none', width: '240px', boxSizing: 'border-box', padding: '4px', borderRadius: '24px', background: 'rgba(20,16,12,0.94)', color: '#fff', pointerEvents: 'auto', overflowY: 'auto', overscrollBehavior: 'contain', touchAction: 'pan-y', zIndex: '4' }, root);
6
+ const probe = el('div', { position: 'absolute', visibility: 'hidden', pointerEvents: 'none', paddingTop: 'env(safe-area-inset-top)', paddingRight: 'env(safe-area-inset-right)', paddingBottom: 'env(safe-area-inset-bottom)', paddingLeft: 'env(safe-area-inset-left)' }, root);
7
+ sheet.setAttribute('role', 'dialog');
8
+ sheet.setAttribute('aria-label', 'Emotes');
9
+ const controller = new AbortController();
10
+ const { signal } = controller;
11
+ let choices, page = 0, opened = false, drawn = '', resizeFrame = null;
12
+ const button = (parent, text, label, action) => {
13
+ const node = el('button', { boxSizing: 'border-box', minWidth: '44px', minHeight: '44px', border: '1px solid rgba(255,255,255,0.35)', borderRadius: '16px', background: 'rgba(255,255,255,0.08)', color: '#fff', font: '600 12px system-ui, sans-serif', cursor: 'pointer', padding: '2px', touchAction: 'manipulation' }, parent);
14
+ node.type = 'button';
15
+ node.textContent = text;
16
+ node.setAttribute('aria-label', label);
17
+ node.addEventListener('click', action);
18
+ return node;
19
+ };
20
+ const slot = (parent, [id, emoji, label], ground = false) => {
21
+ const node = button(parent, '', label, () => { close(); pick(id, ground); });
22
+ el('span', { display: 'block', fontSize: '22px', lineHeight: '24px' }, node).textContent = emoji;
23
+ el('span', { display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', lineHeight: '14px' }, node).textContent = label;
24
+ node.dataset.emote = id;
25
+ return node;
26
+ };
27
+ function layout() {
28
+ const v = { ...view() };
29
+ const css = globalThis.getComputedStyle?.(probe);
30
+ v.insets = Object.fromEntries(['top', 'right', 'bottom', 'left'].map((side) => [side, Math.max(v.insets[side], Number.parseFloat(css?.[`padding${side[0].toUpperCase()}${side.slice(1)}`]) || 0)]));
31
+ const obstacles = bands();
32
+ const place = (height, top) => panelPlacement({ left: (v.w - 240) / 2, right: (v.w + 240) / 2, top: (v.h - height) / 2, bottom: (v.h + height) / 2 }, v, { top, bottom: 12, left: 12, right: 12 }, obstacles, 240);
33
+ let placed = place(284, 64);
34
+ const ring = placed.h >= 284 && placed.w >= 240;
35
+ if (!ring) {
36
+ placed = place(148, 64);
37
+ if (placed.h < 148) {
38
+ // Actual HUD bands still reserve their space when the blanket top
39
+ // margin is reduced to the ordinary safe edge.
40
+ const compact = place(148, 12);
41
+ if (compact.h > placed.h) { placed = compact; }
42
+ }
43
+ }
44
+ const columns = ring ? 3 : 4;
45
+ const rows = ring ? 2 : Math.max(1, Math.min(2, Math.floor((placed.h - 52) / 48)));
46
+ return { placed, ring, columns, bodyHeight: ring ? 232 : (page ? rows : 2) * 48, pageSize: Math.min(6, columns * rows) };
47
+ }
48
+ function draw() {
49
+ if (!opened) { return; }
50
+ const { placed, ring, columns, bodyHeight, pageSize } = layout();
51
+ if (page) { page = Math.min(page, Math.ceil(choices.more.length / pageSize)); }
52
+ // Safe-layout notifications can follow our own DOM changes. Leave an
53
+ // unchanged drawing alone so those notifications settle.
54
+ const key = JSON.stringify([placed, ring, columns, bodyHeight, pageSize, page, choices]);
55
+ if (key === drawn) { return; }
56
+ drawn = key;
57
+ sheet.replaceChildren();
58
+ Object.assign(sheet.style, { width: `${placed.w}px`, left: `${placed.x}px`, top: `${placed.y}px`, height: `${bodyHeight + 52}px`, maxHeight: `${placed.h}px` });
59
+ const body = el('div', { position: 'relative', height: `${bodyHeight}px` }, sheet);
60
+ if (page === 0 && ring) {
61
+ choices.basics.forEach((entry, i) => {
62
+ const angle = i * Math.PI / 4 - Math.PI / 2;
63
+ const node = slot(body, entry, entry[0] === 'sit');
64
+ Object.assign(node.style, { position: 'absolute', width: '56px', height: '48px', left: `${88 + Math.cos(angle) * 86}px`, top: `${92 + Math.sin(angle) * 86}px` });
65
+ });
66
+ } else {
67
+ const entries = page ? choices.more.slice((page - 1) * pageSize, page * pageSize) : choices.basics;
68
+ const count = page ? columns : 4;
69
+ const width = (placed.w - 8 - (count - 1) * 6) / count;
70
+ entries.forEach((entry, i) => {
71
+ const node = slot(body, entry, !page && entry[0] === 'sit');
72
+ Object.assign(node.style, { position: 'absolute', width: `${width}px`, height: ring ? '48px' : '44px', left: `${i % count * (width + 6)}px`, top: `${Math.floor(i / count) * (ring ? 54 : 48) + (ring ? 62 : 0)}px` });
73
+ });
74
+ }
75
+ const nav = el('div', { display: 'flex', height: '44px', justifyContent: 'space-between', gap: '6px' }, sheet);
76
+ button(nav, page ? 'Basics' : 'More', page ? 'Basic emotes' : 'More emotes', () => { page = page ? 0 : 1; draw(); });
77
+ if (page && choices.more.length > pageSize) {
78
+ button(nav, 'Next', 'Next emotes', () => { page = page % Math.ceil(choices.more.length / pageSize) + 1; draw(); });
79
+ }
80
+ button(nav, 'Close', 'Close emotes', close);
81
+ sheet.querySelector?.('button')?.focus();
82
+ }
83
+ sheet.addEventListener('pointerdown', (event) => event.stopPropagation());
84
+ sheet.addEventListener('keydown', (event) => event.stopPropagation());
85
+ globalThis.addEventListener?.('pointerdown', (event) => {
86
+ if (opened && !sheet.contains(event.target) && event.target !== trigger) { close(); }
87
+ }, { capture: true, signal });
88
+ globalThis.addEventListener?.('keydown', (event) => {
89
+ if (opened && event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); close(); }
90
+ }, { capture: true, signal });
91
+ const resized = () => {
92
+ if (!opened || resizeFrame !== null) { return; }
93
+ resizeFrame = requestAnimationFrame(() => { resizeFrame = null; draw(); });
94
+ };
95
+ globalThis.addEventListener?.('resize', resized, { signal });
96
+ globalThis.addEventListener?.('orientationchange', resized, { signal });
97
+ return {
98
+ node: sheet,
99
+ // Chrome calls this again after its safe-layout cache refreshes.
100
+ layout: draw,
101
+ set(value) { choices = value; page = 0; if (opened) { draw(); } },
102
+ open(value) {
103
+ opened = value;
104
+ sheet.style.display = value ? 'block' : 'none';
105
+ if (value) { page = 0; drawn = ''; draw(); }
106
+ },
107
+ dispose() { opened = false; cancelAnimationFrame(resizeFrame); controller.abort(); sheet.remove(); probe.remove(); },
108
+ };
109
+ }
@@ -10,6 +10,8 @@ export const HAT_SETS = {
10
10
  hollow: ['bat-clip', 'witch', 'lantern', 'crooked-top'],
11
11
  sunny: ['straw', 'flower-crown', 'beekeeper', 'sunflower'],
12
12
  harbour: ['sailor', 'souwester', 'captain', 'lighthouse'],
13
+ services: ['police-cap', 'nurse-cap', 'fire-helmet', 'chef-toque'],
14
+ neighbourhood: ['delivery-cap', 'teacher-beret', 'hard-hat', 'baker-cap'],
13
15
  };
14
16
 
15
17
  export const HATS = Object.values(HAT_SETS).flat();
@@ -11,7 +11,7 @@ import * as AvatarCap from './avatarCap.js';
11
11
  import { mergeDictionary } from './interestCap.js';
12
12
  import * as Cabinets from './cabinets.js';
13
13
  import { firstJoinFor } from './firstJoin.js';
14
- import { deck, earnedNow, hub, localArrival, mergeHidden, receiveParty, wearingNow } from './state.js';
14
+ import { deck, earnedNow, hub, localArrival, mergeHidden, receiveParty, rolesNow, wearingNow } from './state.js';
15
15
  import { clearShot, receiveShot } from './shot.js';
16
16
  import * as Ballot from './ballot.js';
17
17
  import * as Rehello from './rehello.js';
@@ -23,6 +23,8 @@ import { setFpsTelemetry } from './fpsTelemetry.js';
23
23
  import { setLoadTelemetry } from './loadTelemetry.js';
24
24
  import { readQuality } from '../shared/quality.js';
25
25
  import { noteQualityInteraction } from './quality.js';
26
+ import { parseCar, vehicleOf } from '../shared/car.js';
27
+ import { pinRiders } from './riders.js';
26
28
  import { readDanceIdle } from '../shared/danceIdle.js';
27
29
 
28
30
  // Root-anchored: the deck's own castle.json once this kit is imported.
@@ -39,52 +41,65 @@ if (deck.build && kitBuild?.source === 'builtin' && typeof kitBuild.version ===
39
41
  ...(typeof kitBuild.digest === 'string' ? { hubGameBuiltinDigest: kitBuild.digest } : {}) });
40
42
  }
41
43
 
42
- if (castleJson?.hub?.pongTimeoutMs > 0) { deck.pongTimeoutMs = castleJson.hub.pongTimeoutMs; }
43
- else { delete deck.pongTimeoutMs; }
44
- deck.invite = (castleJson?.hub?.places?.main?.invite ?? castleJson?.hub?.invite) === true;
45
- deck.defaultEnvironment = castleJson?.hub?.defaultEnvironment !== false;
46
- deck.tiers = castleJson?.hub?.tiers === true;
47
- if (castleJson?.hub?.highOnly === true && deck.tiers) { deck.highOnly = true; }
48
- else { delete deck.highOnly; }
49
- if (castleJson?.hub?.quality !== undefined && deck.tiers) { deck.quality = readQuality(castleJson.hub.quality, true, []); }
50
- else { delete deck.quality; }
51
- if (castleJson?.hub?.safeInsets === true) { deck.safeInsets = true; }
52
- else { delete deck.safeInsets; }
53
- if (castleJson?.hub?.weakestTier === true) { deck.weakestTier = true; }
54
- else { delete deck.weakestTier; }
55
- if (castleJson?.hub?.weakestLookBake === true) { deck.weakestLookBake = true; }
56
- else { delete deck.weakestLookBake; }
57
- if (castleJson?.hub?.mergeFarAvatars === true) { deck.mergeFarAvatars = true; }
58
- else { delete deck.mergeFarAvatars; }
59
- if (castleJson?.hub?.lowActorDistance === true) { deck.lowActorDistance = true; }
60
- else { delete deck.lowActorDistance; }
61
- if (castleJson?.hub?.lowActorBudget === true) { deck.lowActorBudget = true; }
62
- else { delete deck.lowActorBudget; }
63
- if (castleJson?.hub?.companionIdle === true) { deck.companionIdle = true; }
64
- else { delete deck.companionIdle; }
65
- if (castleJson?.hub?.act === true) {deck.act = true;}
66
- else {delete deck.act;}
67
- deck.cues = castleJson?.hub?.cues === true;
68
- deck.playCards = castleJson?.hub?.playCards === true;
69
- deck.yourGames = castleJson?.hub?.yourGames === true;
70
- if (castleJson?.hub?.avatarColors === true) {
71
- deck.avatarColors = true;
72
- }
73
- deck.stuck = castleJson?.hub?.stuck === true;
74
- deck.labels = castleJson?.hub?.labels === 'near';
75
- // `hub.soundscape`: true, or an object with optional ground, ambience and UI.
76
- const soundscape = castleJson?.hub?.soundscape;
77
- deck.soundscape = soundscape === true || (soundscape && typeof soundscape === 'object' && !Array.isArray(soundscape)) ? {
78
- babble: soundscape.babble !== false,
79
- steps: soundscape.steps && typeof soundscape.steps === 'object' && !Array.isArray(soundscape.steps) ? soundscape.steps : soundscape.steps !== false,
80
- ...(typeof soundscape.zones === 'string' ? { zones: soundscape.zones } : {}),
81
- ...(soundscape.ambience && typeof soundscape.ambience === 'object' && !Array.isArray(soundscape.ambience) ? { ambience: soundscape.ambience } : {}),
82
- ...(Object.hasOwn(soundscape, 'ui') && typeof soundscape.ui === 'boolean' ? { ui: soundscape.ui } : {}),
83
- ...(Object.hasOwn(soundscape, 'cues') && typeof soundscape.cues === 'boolean' ? { cues: soundscape.cues } : {}),
84
- } : null;
85
- if (deck.soundscape?.cues === true) {
86
- hub.cueEvents = [];
44
+ // What the deck's `hub` block asks of the client, into `deck` (state.js).
45
+ // The page applies its own castle.json's block once, below; a host with no
46
+ // castle.json to glob (the native hub) applies the scene manifest's `deck`
47
+ // block instead (shared/deckFlags.js), and may apply a newer one later: every
48
+ // key is set or cleared each time, as from a fresh page.
49
+ export function applyDeck(hubBlock) {
50
+ const block = hubBlock && typeof hubBlock === 'object' && !Array.isArray(hubBlock) ? hubBlock : {};
51
+ if (block.pongTimeoutMs > 0) { deck.pongTimeoutMs = block.pongTimeoutMs; }
52
+ else { delete deck.pongTimeoutMs; }
53
+ deck.invite = (block.places?.main?.invite ?? block.invite) === true;
54
+ deck.defaultEnvironment = block.defaultEnvironment !== false;
55
+ deck.tiers = block.tiers === true;
56
+ if (block.highOnly === true && deck.tiers) { deck.highOnly = true; }
57
+ else { delete deck.highOnly; }
58
+ if (block.quality !== undefined && deck.tiers) { deck.quality = readQuality(block.quality, true, []); }
59
+ else { delete deck.quality; }
60
+ if (block.safeInsets === true) { deck.safeInsets = true; }
61
+ else { delete deck.safeInsets; }
62
+ if (block.weakestTier === true) { deck.weakestTier = true; }
63
+ else { delete deck.weakestTier; }
64
+ if (block.weakestLookBake === true) { deck.weakestLookBake = true; }
65
+ else { delete deck.weakestLookBake; }
66
+ if (block.mergeFarAvatars === true) { deck.mergeFarAvatars = true; }
67
+ else { delete deck.mergeFarAvatars; }
68
+ if (block.lowActorDistance === true) { deck.lowActorDistance = true; }
69
+ else { delete deck.lowActorDistance; }
70
+ if (block.lowActorBudget === true) { deck.lowActorBudget = true; }
71
+ else { delete deck.lowActorBudget; }
72
+ if (block.companionIdle === true) { deck.companionIdle = true; }
73
+ else { delete deck.companionIdle; }
74
+ if (block.act === true) {deck.act = true;}
75
+ else {delete deck.act;}
76
+ deck.cues = block.cues === true;
77
+ deck.playCards = block.playCards === true;
78
+ deck.yourGames = block.yourGames === true;
79
+ if (block.avatarColors === true) {
80
+ deck.avatarColors = true;
81
+ } else {
82
+ delete deck.avatarColors;
83
+ }
84
+ deck.stuck = block.stuck === true;
85
+ deck.labels = block.labels === 'near';
86
+ // `hub.soundscape`: true, or an object with optional ground, ambience and UI.
87
+ const soundscape = block.soundscape;
88
+ deck.soundscape = soundscape === true || (soundscape && typeof soundscape === 'object' && !Array.isArray(soundscape)) ? {
89
+ babble: soundscape.babble !== false,
90
+ steps: soundscape.steps && typeof soundscape.steps === 'object' && !Array.isArray(soundscape.steps) ? soundscape.steps : soundscape.steps !== false,
91
+ ...(typeof soundscape.zones === 'string' ? { zones: soundscape.zones } : {}),
92
+ ...(soundscape.ambience && typeof soundscape.ambience === 'object' && !Array.isArray(soundscape.ambience) ? { ambience: soundscape.ambience } : {}),
93
+ ...(Object.hasOwn(soundscape, 'ui') && typeof soundscape.ui === 'boolean' ? { ui: soundscape.ui } : {}),
94
+ ...(Object.hasOwn(soundscape, 'cues') && typeof soundscape.cues === 'boolean' ? { cues: soundscape.cues } : {}),
95
+ } : null;
96
+ if (deck.soundscape?.cues === true) {
97
+ hub.cueEvents = Array.isArray(hub.cueEvents) ? hub.cueEvents : [];
98
+ } else {
99
+ hub.cueEvents = null;
100
+ }
87
101
  }
102
+ applyDeck(castleJson?.hub);
88
103
 
89
104
  let files = null;
90
105
  // The scene and multiplayer system of the newest snapshot, for a message that
@@ -178,7 +193,14 @@ function wearMap(value) {
178
193
  return new Map(Object.entries(value && typeof value === 'object' ? value : {}));
179
194
  }
180
195
 
181
- export default {
196
+ const hooks = {
197
+ beforeReport(scene, local) {
198
+ if (Object.keys(hub.cars).length) {pinRiders(scene, local, hub.cars);}
199
+ },
200
+ report(scene, local, system) {
201
+ const mine = vehicleOf(hub.cars, system.net?.selfId?.());
202
+ if (!mine || mine.driver) {system.report(scene, local);}
203
+ },
182
204
  // Travel retains these hooks: decode offers from any opted-in destination.
183
205
  unpack: unpackFrame,
184
206
  // A place whose NPCs have minds (`hub.npcs`, contract §13) is joined like any
@@ -216,6 +238,9 @@ export default {
216
238
  hub.companion = { c: sanitise(msg.c), n: msg.n, ...(hub.companion?.stamps !== undefined ? { stamps: hub.companion.stamps } : {}) };
217
239
  }
218
240
  break;
241
+ case 'hub-emotes-for':
242
+ if ((!hub.place || hub.place.idle?.expression) && Array.isArray(msg.ids)) { hub.roleEmotes = msg.ids.filter((id) => typeof id === 'string'); }
243
+ break;
219
244
  case 'hub-menu':
220
245
  if ((!hub.place || hub.place.menu === true) && Number.isSafeInteger(msg.n) && msg.n >= 0 &&
221
246
  (!hub.menu || msg.n > hub.menu.n)) {
@@ -340,6 +365,10 @@ export default {
340
365
  hub.wearMe = wearMap(msg.hubWear);
341
366
  setWearing();
342
367
  break;
368
+ case 'hub-role':
369
+ hub.roleMe = wearMap(msg.hubRole);
370
+ hub.roles = rolesNow();
371
+ break;
343
372
  case 'hub-earned':
344
373
  // v1.53: earned items of players in a hidden pair this player may see.
345
374
  hub.earnedMe = wearMap(msg.hubEarned);
@@ -413,7 +442,7 @@ export default {
413
442
  // corrected position has reached Transform. A later WORLD is equivalent
414
443
  // on reconnect; the initial WORLD cannot qualify before hub-arrived.
415
444
  if (!hub.arrivalPlaced && hub.arrivedFacing !== null && (
416
- msg.k === 'w' ||
445
+ (msg.k === 'w' && msg.again !== 1) ||
417
446
  // Match multiplayer's clamp acceptance exactly. `packPlayer` puts 1/0
418
447
  // on the wire, while older composed fixtures may still carry true.
419
448
  (msg.ps ?? []).some((row) => row?.[0] === system?.net?.selfId?.() && Boolean(row[5]))
@@ -431,6 +460,7 @@ export default {
431
460
  hub.askClose?.();
432
461
  delete hub.ask;
433
462
  }
463
+ if (!msg.hubPlace.idle?.expression || (hub.place && hub.place.id !== msg.hubPlace.id)) { hub.roleEmotes = []; }
434
464
  hub.place = msg.hubPlace;
435
465
  if (hub.place.anonymousEntry !== true) {
436
466
  delete hub.guests;
@@ -543,6 +573,14 @@ export default {
543
573
  hub.tryAll = new Map();
544
574
  setWearing();
545
575
  }
576
+ // v1.157: snapshots clear only the shared block, as hubTry does.
577
+ if (msg.hubRole && typeof msg.hubRole === 'object') {
578
+ hub.roleAll = wearMap(msg.hubRole);
579
+ hub.roles = rolesNow();
580
+ } else if (msg.hubPlace && hub.roleAll.size > 0) {
581
+ hub.roleAll = new Map();
582
+ hub.roles = rolesNow();
583
+ }
546
584
  if ('hud' in msg) {
547
585
  hub.hud = msg.hud ?? null;
548
586
  }
@@ -584,6 +622,13 @@ export default {
584
622
  if (msg.hubKept && typeof msg.hubKept === 'object') {
585
623
  hub.keptFor = new Map(Object.entries(msg.hubKept));
586
624
  }
625
+ if (msg.hubCars && typeof msg.hubCars === 'object') {
626
+ hub.cars = Object.fromEntries(Object.entries(msg.hubCars).slice(0, 24).flatMap(([id, spec]) => {
627
+ const car = parseCar(spec);
628
+ return car ? [[id, { ...car, riders: Object.fromEntries(Object.entries(spec.riders ?? {}).filter(([seat, rider]) => Number.isInteger(Number(seat)) && Number(seat) > 0 && Number(seat) < car.seats.length && typeof rider === 'string')) }]] : [];
629
+ }));
630
+ }
631
+ else if (msg.hubPlace) {hub.cars = {};}
587
632
  // v1.6: only a place that turns idle play on sends these.
588
633
  if (msg.hubEmotes && typeof msg.hubEmotes === 'object') {
589
634
  hub.emotes = msg.hubEmotes;
@@ -626,3 +671,9 @@ export default {
626
671
  clearShot();
627
672
  },
628
673
  };
674
+ // `hookLayer.applyDeck` for a host that imports this layer itself (the native
675
+ // hub's kit bundle). Not enumerable, so composing the layers (real-time
676
+ // gameHooks.js) never copies it into the hooks a system calls.
677
+ Object.defineProperty(hooks, 'applyDeck', { value: applyDeck });
678
+
679
+ export default hooks;
@@ -0,0 +1,77 @@
1
+ // A host's Go (SDK `Hub.onGo`, contract v1.155): the host asks this place to
2
+ // take the player through one of its doors, e.g. a trip begun outside this
3
+ // page that hands back to the Town. The kit answers it like a fired pad: the
4
+ // same `goHub` trip (Hub.go, the door beat, the cover).
5
+ //
6
+ // Only one waits, the latest. It is taken once the place is settled (the
7
+ // first hello on this connection, placed, not held, not ending, the Doors
8
+ // list known) with no trip under way, and let go after HOST_GO_WAIT_MS, when
9
+ // a trip starts first, or when the door is not one of this place's listed
10
+ // doors -- which a cabinet (a classic deck) never is: the host plays those
11
+ // itself and never sends a Go for one. Nothing is persisted.
12
+
13
+ export const HOST_GO_WAIT_MS = 60000;
14
+
15
+ export function makeHostGo({ warn = (text) => console.warn(text) } = {}) {
16
+ let pending = null;
17
+ const drop = (why) => {
18
+ warn(`[hub-host-go] dropped a Go to ${JSON.stringify(pending.doorId)}: ${why}`);
19
+ pending = null;
20
+ };
21
+ return {
22
+ // A Go from the host. One that arrives during a trip is not queued
23
+ // behind it: the player is already going somewhere.
24
+ offer(go, { at, tripping }) {
25
+ if (!go || typeof go.doorId !== 'string' || !go.doorId) {
26
+ return;
27
+ }
28
+ if (tripping) {
29
+ warn(`[hub-host-go] ignored a Go to ${JSON.stringify(go.doorId)}: a trip is under way`);
30
+ return;
31
+ }
32
+ pending = {
33
+ doorId: go.doorId,
34
+ owner: typeof go.owner === 'string' ? go.owner : null,
35
+ title: typeof go.title === 'string' ? go.title : null,
36
+ party: Number.isInteger(go.party) && go.party > 0 ? go.party : 1,
37
+ at,
38
+ };
39
+ },
40
+ // Each frame: the trip to take now as a `hub-go` message for `goHub`, or
41
+ // null. `doors` is the place's Doors list (`hubDoors`: { id, title }).
42
+ take({ now, settled, tripping, result, doors }) {
43
+ if (!pending) {
44
+ return null;
45
+ }
46
+ if (now - pending.at > HOST_GO_WAIT_MS) {
47
+ drop('too old');
48
+ return null;
49
+ }
50
+ if (tripping) {
51
+ drop('a trip started first');
52
+ return null;
53
+ }
54
+ if (!settled || result) {
55
+ return null;
56
+ }
57
+ const row = (doors ?? []).find((d) => d?.id === pending.doorId);
58
+ if (!row) {
59
+ drop('no such door here');
60
+ return null;
61
+ }
62
+ const { doorId, owner, title, party } = pending;
63
+ pending = null;
64
+ return {
65
+ k: 'hub-go',
66
+ door: doorId,
67
+ key: null,
68
+ place: null,
69
+ scene: null,
70
+ title: title ?? row.title ?? doorId,
71
+ party,
72
+ ...(owner ? { owner } : {}),
73
+ };
74
+ },
75
+ pending: () => (pending ? { ...pending } : null),
76
+ };
77
+ }
@@ -0,0 +1,125 @@
1
+ // The decisions behind the People list and the Back control, as plain
2
+ // functions of their inputs: the hub system (`systems/hub.js`) runs them on
3
+ // the web, and a native host runs the same ones over its own state.
4
+
5
+ // An action from the People list (`together.rows`): the pointer on someone
6
+ // here (Find), an invitation into the party (Invite), or Join -- beside a
7
+ // party member or a friend in this layer (the place moves this player), into
8
+ // the layer of this place a friend is in (a jump), or to the door of the game
9
+ // a friend is inside. Report is `reportPerson`.
10
+ // net the connection (`send`)
11
+ // person a row: { playerId, userId, username, door, owner }
12
+ // action the row action's id
13
+ // together `makeTogether()` (Find)
14
+ // say(text) a toast
15
+ // jump(net, msg) a paced jump message (`HubSystem.sendJump`)
16
+ // jumpTo(friend) a jump into a friend's layer by `Hub.jump` ({ userId, username })
17
+ // doors the town's doors (`hub.doors`), for a title
18
+ // Returns whether it acted on anything.
19
+ export function personAction(net, person, action, { together, say, jump, jumpTo, doors = [] }) {
20
+ if (!net || !person) {
21
+ return false;
22
+ }
23
+ if (action === 'find' && person.playerId) {
24
+ together.find(person.playerId);
25
+ } else if (action === 'invite' && person.playerId) {
26
+ net.send({ k: 'hub-party', op: 'invite', player: person.playerId });
27
+ say(`Invited ${person.username ?? 'them'} to your party`);
28
+ } else if (action === 'goto' && person.playerId) {
29
+ jump(net, { k: 'hub-goto', player: person.playerId });
30
+ } else if (action === 'door' && person.door && person.owner) {
31
+ // A friend at home: the place sends this player through their House
32
+ // door with the owner (`hub-go` carrying `owner`), ending the visit here
33
+ // as any door's trip does. A host that predates the owner acquires this
34
+ // player's own House, as the pad would have.
35
+ jump(net, { k: 'hub-house-visit', door: person.door, owner: person.owner });
36
+ say(`Going to ${person.username ?? 'your friend'}'s House`);
37
+ } else if (action === 'door' && person.door) {
38
+ jump(net, { k: 'hub-door-jump', door: person.door });
39
+ // A friend inside the game is said to be; someone standing at the door
40
+ // is simply gone to.
41
+ if (person.playerId === null) {
42
+ const title = doors.find((d) => d.id === person.door)?.title ?? 'that game';
43
+ say(`${person.username ?? 'Your friend'} is inside ${title}`);
44
+ }
45
+ } else if (action === 'jump' && person.userId) {
46
+ jumpTo({ userId: person.userId, username: person.username });
47
+ } else {
48
+ return false;
49
+ }
50
+ return true;
51
+ }
52
+
53
+ // Reports a player to Castle (`Hub.report`), one at a time. `gate` holds
54
+ // `{ reporting, reportOff }`: a host that answers it is not available, or does
55
+ // not know the call, is asked no more. Returns the report's promise, or null
56
+ // when nothing was sent.
57
+ export function reportPerson(person, { report, gate, say }) {
58
+ if (gate.reporting || !person?.userId || typeof report !== 'function') {
59
+ return null;
60
+ }
61
+ gate.reporting = true;
62
+ return Promise.resolve(report(person.userId))
63
+ .then((answer) => {
64
+ if (answer?.status === 'ok') {
65
+ say('Reported. Thanks.');
66
+ return;
67
+ }
68
+ gate.reportOff = true;
69
+ say("Reporting isn't available here.");
70
+ })
71
+ .catch((err) => {
72
+ if (err?.code === 'UNKNOWN_COMMAND' || err?.code === 'CASTLE_HOST_UNAVAILABLE') {
73
+ gate.reportOff = true;
74
+ }
75
+ say("That report didn't go through. Try again later.");
76
+ })
77
+ .finally(() => {
78
+ gate.reporting = false;
79
+ });
80
+ }
81
+
82
+ // Whether the kit's Back control shows, and its words. A place that reports
83
+ // results is a game: it always has Back. A place that does not (a town) has
84
+ // Back only when it was reached through a door. Behind a host trail
85
+ // (`hubDepth > 0`) the host draws Back, except where the kit must
86
+ // (`kitBackNeeded`: old Android landscape hosts draw Exit deck instead).
87
+ // away a classic deck's away phase: the cover is down, Back is the only control
88
+ // idle no trip in progress
89
+ // pendingEnd a place's end still settling (null when none)
90
+ // hostTrail reached by a hub trip (`hubDepth > 0`)
91
+ // place the place's manifest, or null
92
+ // ticket the latest return ticket, or undefined
93
+ // kitBack `kitBackNeeded()`
94
+ export function backControl({ away, idle, pendingEnd, hostTrail, place, ticket, kitBack }) {
95
+ const inGame = Boolean(place?.result);
96
+ return {
97
+ show: Boolean((away || (idle && pendingEnd === null)) && (hostTrail ? place !== null && kitBack : inGame || Boolean(ticket))),
98
+ label: ticket?.title ?? (hostTrail && kitBack ? 'Back' : 'Again'),
99
+ };
100
+ }
101
+
102
+ // What a user's Back (the kit's control or the host's) does: it first closes
103
+ // the action overflow, then the place menu; in a game it quits the door
104
+ // (`hub-door-quit`) and goes back; anywhere else it goes back.
105
+ // Returns 'overflow' | 'menu' | 'quit' | 'back'.
106
+ export function backPress({ overflowOpen, menuOpen, inGame }) {
107
+ if (overflowOpen) {
108
+ return 'overflow';
109
+ }
110
+ if (menuOpen) {
111
+ return 'menu';
112
+ }
113
+ return inGame ? 'quit' : 'back';
114
+ }
115
+
116
+ // Which way back goes once the ticket is taken: through the host
117
+ // (`Hub.back`) for a hub trip's ticket, or with no ticket behind a host trail;
118
+ // a fresh or rejoined instance with no ticket; else the ticket's own place.
119
+ // Returns 'host' | 'instance' | 'ticket'.
120
+ export function backRoute({ ticket, hubDepth }) {
121
+ if (ticket?.hub || (!ticket && hubDepth > 0)) {
122
+ return 'host';
123
+ }
124
+ return ticket ? 'ticket' : 'instance';
125
+ }