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
@@ -0,0 +1,187 @@
1
+ // A hub-entry link: the House deck and the Town's door decks are never opened
2
+ // on their own, so a direct link to one becomes the Town's link with
3
+ // `?route=hub-entry&slot=<target>`, which the host hands the deck as
4
+ // `Multiplayer.joinHint()` -> { routeId, slot }. `slot` is `house` (the
5
+ // player's own House) or `door:<doorId>` (that door of the Town).
6
+ //
7
+ // Read once per page load, and only on the first place this page enters at
8
+ // the root of the host's trail (no hub join, no door behind it, not a game).
9
+ // An invite arrival wins. Anything that moves the player first -- a trip, a
10
+ // session swap -- spends it unused. Nothing is persisted.
11
+
12
+ export const HUB_ENTRY_ROUTE = 'hub-entry';
13
+ // How long after the hint arrives the player may still be waiting to be
14
+ // placed before the link is let go: no late surprise trip.
15
+ export const HUB_ENTRY_WAIT_MS = 30000;
16
+ const DOOR_ID = /^[A-Za-z0-9_.-]{1,64}$/;
17
+
18
+ export function parseHubEntry(hint) {
19
+ if (!hint || typeof hint !== 'object' || hint.routeId !== HUB_ENTRY_ROUTE || typeof hint.slot !== 'string') {
20
+ return null;
21
+ }
22
+ if (hint.slot === 'house') {
23
+ return { kind: 'house' };
24
+ }
25
+ const door = /^door:(.+)$/.exec(hint.slot)?.[1];
26
+ return door && DOOR_ID.test(door) ? { kind: 'door', door } : null;
27
+ }
28
+
29
+ const SOLO_KINDS = new Set(['layer', 'exact']);
30
+
31
+ // What to do for a target, from what the client knows right now:
32
+ // `listed` the place's Doors rows (`hubDoors`: { id, title, solo?, need? }),
33
+ // `homes` the ids of its House doors (scene `HubDoor.to === 'deck:house'`),
34
+ // nearest first, `host` the host's door rows by id (`Hub.doors()`), or null
35
+ // where it has none, and `guest` true/false/null (null: not known).
36
+ // Returns { go: { door, title } } (a trip), { jump: row, toast } (onto the
37
+ // door's pad, as the Doors list's Go), { toast } (stay), or null (nothing).
38
+ export function planHubEntry(target, { listed = [], homes = [], host = null, guest = null } = {}) {
39
+ const row = (id) => listed.find((d) => d?.id === id) ?? null;
40
+ const usable = (id) => {
41
+ const h = host?.get(id);
42
+ return Boolean(row(id)) && (!h || h.enabled !== false);
43
+ };
44
+ const house = (preferred) => {
45
+ if (guest === true) {
46
+ return { toast: 'Sign in to have a House of your own' };
47
+ }
48
+ if (guest !== false) {
49
+ return null;
50
+ }
51
+ const door = [preferred, ...homes].find((id) => id && homes.includes(id) && usable(id));
52
+ return door ? { go: { door, title: row(door)?.title || 'Your House' } } : null;
53
+ };
54
+ if (target?.kind === 'house') {
55
+ return house(null);
56
+ }
57
+ if (target?.kind !== 'door') {
58
+ return null;
59
+ }
60
+ const door = row(target.door);
61
+ if (!door) {
62
+ return null;
63
+ }
64
+ if (homes.includes(door.id)) {
65
+ return house(door.id);
66
+ }
67
+ const title = door.title || 'That door';
68
+ // A link is for a signed-in player: a guest stays in the Town and is told
69
+ // where the door is; an account not known stays quietly.
70
+ if (guest === true) {
71
+ return { toast: `${title} is in the Town · sign in to play` };
72
+ }
73
+ if (guest !== false) {
74
+ return null;
75
+ }
76
+ const h = host?.get(door.id);
77
+ if (h?.enabled === false) {
78
+ return { toast: `${title} is closed right now` };
79
+ }
80
+ const need = Number.isInteger(door.need) && door.need > 1 ? door.need : null;
81
+ // A pad door takes only a group its pad fired (ghost refuses Hub.go
82
+ // otherwise), so a solo pad door is reached the way the Doors list does
83
+ // it: onto the pad, which the place launches by its own rules. A door the
84
+ // host places by layer or key takes one player straight through.
85
+ if (!need && h && SOLO_KINDS.has(h.placementKind)) {
86
+ return { go: { door: door.id, title } };
87
+ }
88
+ return { jump: door, toast: need ? `${title} needs ${need} players · wait on the pad for others` : null };
89
+ }
90
+
91
+ // The once-per-load state. `deps`: `joinHint()` (the SDK's), `extras(target)`
92
+ // -> Promise<{ guest, host }> read just before deciding, `act(target,
93
+ // extras)`, `current()` -> the context as it is now (asked again after
94
+ // `extras` resolves, right before acting; default: the last frame's), `now()`.
95
+ // `frame(ctx)` each frame, with `ctx`: `known` (the place has been named),
96
+ // `root` (still the page's first place, at the root, no trip yet), `net`
97
+ // (the current connection), `selfId` (its player id), `epoch` (bumped at
98
+ // every re-admission or identity change the client sees on any connection),
99
+ // `invited` (the arrival carried an invite), `settled` (hello sent, placed,
100
+ // not held, nothing pending).
101
+ export function makeHubEntry({ joinHint, extras = async () => ({}), act = () => {}, current = null, now = () => Date.now() }) {
102
+ let state = 'idle';
103
+ let target = null;
104
+ let readyAt = 0;
105
+ let net = null;
106
+ let selfId = null;
107
+ let epoch = null;
108
+ let latest = {};
109
+ const done = () => { state = 'done'; };
110
+ // False (and spent) when this is no longer the first entry it was read for.
111
+ const valid = (ctx) => {
112
+ if (ctx.current && !net) {net = ctx.current;}
113
+ if (ctx.selfId && !selfId) {selfId = ctx.selfId;}
114
+ if (ctx.epoch !== undefined && ctx.epoch !== null && epoch === null) {epoch = ctx.epoch;}
115
+ if (!ctx.root || ctx.invited || ctx.current && ctx.current !== net || ctx.selfId && ctx.selfId !== selfId ||
116
+ ctx.epoch !== undefined && ctx.epoch !== null && ctx.epoch !== epoch) {
117
+ done();
118
+ return false;
119
+ }
120
+ return true;
121
+ };
122
+ const read = ({ known = false, root = false, net: at = null, selfId: id = null, epoch: e = null, invited = false, settled = false } = {}) =>
123
+ ({ known, root, current: at, selfId: id, epoch: e, invited, settled });
124
+ return {
125
+ state: () => state,
126
+ frame(input = {}) {
127
+ if (state === 'done') {
128
+ return;
129
+ }
130
+ latest = input;
131
+ const ctx = read(input);
132
+ if (!ctx.known) {
133
+ if (ctx.current && !net) {net = ctx.current;}
134
+ return;
135
+ }
136
+ if (!valid(ctx)) {
137
+ return;
138
+ }
139
+ if (state === 'idle') {
140
+ state = 'asking';
141
+ let asked;
142
+ try {
143
+ asked = Promise.resolve(joinHint?.());
144
+ } catch {
145
+ asked = Promise.resolve(null);
146
+ }
147
+ asked.then((hint) => {
148
+ if (state !== 'asking') {return;}
149
+ target = parseHubEntry(hint);
150
+ if (!target) {done(); return;}
151
+ state = 'ready';
152
+ readyAt = now();
153
+ }, () => { if (state === 'asking') {done();} });
154
+ return;
155
+ }
156
+ if (state !== 'ready') {
157
+ return;
158
+ }
159
+ if (now() - readyAt > HUB_ENTRY_WAIT_MS) {
160
+ done();
161
+ return;
162
+ }
163
+ if (!ctx.settled) {
164
+ return;
165
+ }
166
+ state = 'deciding';
167
+ const chosen = target;
168
+ Promise.resolve().then(() => extras(chosen)).catch(() => ({})).then((info) => {
169
+ if (state !== 'deciding') {return;}
170
+ // Everything again, as it is now: the lookup took time.
171
+ let again;
172
+ try { again = read(current ? current() : latest); } catch { again = read({}); }
173
+ if (!again.known || !valid(again)) {
174
+ done();
175
+ return;
176
+ }
177
+ if (!again.settled) {
178
+ // Held, unplaced or reconnecting meanwhile: wait again, in budget.
179
+ state = now() - readyAt > HUB_ENTRY_WAIT_MS ? 'done' : 'ready';
180
+ return;
181
+ }
182
+ done();
183
+ act(chosen, info ?? {});
184
+ });
185
+ },
186
+ };
187
+ }
@@ -0,0 +1,148 @@
1
+ // The HUD surface: the HUD root's state (Back, the HUD's title and big line,
2
+ // the prompt pill, the toast and the Act/Jump pair) and its API, published as
3
+ // the `hud` UI tree root (`hudTree.js`, `uiTree.js`). No DOM and no window:
4
+ // the web chrome (`chrome.js`) draws each built root through `uiDom.js` (its
5
+ // `draw` hook) and a native host takes the same root from the UI tree sink.
6
+ //
7
+ // makeHudSurface({ landscape, safeInsets, onBack, promptBlocked, draw }):
8
+ // landscape the stage is landscape at the start (`setLandscape` after);
9
+ // safeInsets the place keeps its edges clear of the safe area;
10
+ // onBack() Back was pressed;
11
+ // promptBlocked() true while something sits over the prompt pill (the
12
+ // chrome: the doors list, or a talk panel with questions),
13
+ // read each time the prompt is synced;
14
+ // draw(tree) called with each root built (only when its state changed).
15
+ import { publishUiRoot } from './uiTree.js';
16
+ import { buildHud } from './hudTree.js';
17
+ import { firstPromptSentence } from './hudCopy.js';
18
+
19
+ // What the hub gives `setHud` each frame: the player's own HUD over the
20
+ // place's, and the seconds its timer reads at `simNow` (the simulation's ms,
21
+ // `Hub.simNow()`), never below 0; null with no timer. `hub` is the client
22
+ // hub state (`state.js` `hub`).
23
+ export function hudInputs(hub, simNow) {
24
+ const spec = hub.hudMe ?? hub.hud;
25
+ let timer = null;
26
+ if (spec?.timer?.since !== undefined) {
27
+ timer = Math.max(0, (simNow - spec.timer.since) / 1000);
28
+ } else if (spec?.timer?.until !== undefined) {
29
+ timer = Math.max(0, (spec.timer.until - simNow) / 1000);
30
+ }
31
+ return { spec, timer };
32
+ }
33
+
34
+ export function makeHudSurface({ landscape = false, safeInsets = false, onBack = () => {}, promptBlocked = () => false, draw = null } = {}) {
35
+ const state = {
36
+ view: { landscape: Boolean(landscape), safeInsets },
37
+ back: { show: false, label: 'Town' },
38
+ hud: { show: false, title: '', big: '', clock: null, prompt: '', promptShown: false },
39
+ toast: { text: '', wrap: false },
40
+ actPair: null,
41
+ on: { back: () => onBack() },
42
+ };
43
+ let key = '';
44
+ // The HUD timer's clock is read at the simulation time of the last
45
+ // `setHud` (`clockNow`, seconds), so the page's big line reads what
46
+ // `toFixed(1)` of the timer read. `timerClock` is the clock of the timer
47
+ // last seen: { rate, mark, clock }, kept while that timer is the same.
48
+ let clockNow = 0;
49
+ let timerClock = null;
50
+ let clockGen = 0;
51
+ let promptAsked = false;
52
+
53
+ // Said every frame by the setters: a string of the state, no serializing,
54
+ // so an unchanged frame builds and writes nothing.
55
+ function render() {
56
+ const { view, back: b, hud: d, toast: t, actPair: p } = state;
57
+ const big = d.clock ? `clock:${d.clock.gen}` : d.big;
58
+ const next = [view.landscape, b.show, b.label, d.show, d.title, big, d.prompt, d.promptShown, t.text, t.wrap, p ? `${p.show}${p.enabled}` : ''].join('\u0001');
59
+ if (next === key) {return;}
60
+ key = next;
61
+ const tree = buildHud(state);
62
+ publishUiRoot('hud', tree);
63
+ draw?.(tree);
64
+ }
65
+
66
+ // The big line's clock for a running timer, or null (no timer, or no sim
67
+ // time to read it at). The clock is absolute (`uiTree.js`): the timer's
68
+ // mark in simulation seconds and its rate, the same bytes for as long as
69
+ // the timer is the same. A new timer (another since/until, or rate) is a
70
+ // new generation; a server time correction changes nothing here.
71
+ function hudTimerClock(timer, timerSeconds, simNow) {
72
+ const rate = timer?.since !== undefined ? 1 : timer?.until !== undefined ? -1 : 0;
73
+ if (!rate || timerSeconds === null || timerSeconds === undefined || !Number.isFinite(simNow)) {return null;}
74
+ const mark = rate > 0 ? timer.since : timer.until;
75
+ if (!Number.isFinite(mark)) {return null;}
76
+ clockNow = simNow / 1000;
77
+ if (!timerClock || timerClock.rate !== rate || timerClock.mark !== mark) {
78
+ clockGen += 1;
79
+ timerClock = { rate, mark, clock: { gen: clockGen, t0: mark / 1000, v0: 0, rate } };
80
+ }
81
+ return timerClock.clock;
82
+ }
83
+
84
+ function syncPrompt() {
85
+ state.hud.promptShown = promptAsked && !promptBlocked();
86
+ render();
87
+ }
88
+
89
+ render();
90
+ return {
91
+ state,
92
+ render,
93
+ // The sim time (seconds) the page reads the HUD clock at.
94
+ clockNow: () => clockNow,
95
+ // Whether the prompt shows: what the place asked, unless something sits
96
+ // over it (`promptBlocked`).
97
+ syncPrompt,
98
+ // A turned or resized stage: Back clears the native exit corner; the HUD
99
+ // and toast narrow.
100
+ setLandscape(on) {
101
+ state.view.landscape = Boolean(on);
102
+ render();
103
+ },
104
+ showBack(show, label = 'Back') {
105
+ state.back.show = Boolean(show);
106
+ state.back.label = label;
107
+ render();
108
+ },
109
+ // Said every frame: the root is rebuilt only when its words change, so a
110
+ // frame that changes nothing writes nothing. `simNow` (the simulation's
111
+ // ms, `Hub.simNow()`), given with a running `spec.timer`, makes the big
112
+ // line an absolute `clock`: the root is sent again only when the timer
113
+ // itself changes (a start, a stop, another since/until), not ten times a
114
+ // second. Returns { big, clock }: the big line's words and the clock, if
115
+ // one runs (the page ticks it).
116
+ setHud(spec, timerSeconds, simNow) {
117
+ if (!spec) {
118
+ state.hud.show = false;
119
+ state.hud.clock = null;
120
+ promptAsked = false;
121
+ syncPrompt();
122
+ return { big: '', clock: null };
123
+ }
124
+ const big = spec.big ?? (timerSeconds !== null ? timerSeconds.toFixed(1) : '');
125
+ const prompt = firstPromptSentence(spec.text);
126
+ Object.assign(state.hud, { show: true, title: String(spec.title ?? ''), big: String(big), prompt });
127
+ state.hud.clock = spec.big === undefined || spec.big === null ? hudTimerClock(spec.timer, timerSeconds, simNow) : null;
128
+ promptAsked = Boolean(prompt);
129
+ syncPrompt();
130
+ return { big, clock: state.hud.clock };
131
+ },
132
+ setToast(text, { wrap = false } = {}) {
133
+ state.toast.text = text ? String(text) : '';
134
+ state.toast.wrap = Boolean(wrap);
135
+ render();
136
+ },
137
+ // The Act/Jump pair's state and handlers (`act.js`): { show, enabled,
138
+ // on: { jump, press, release, cancel } }, or null for none.
139
+ setActPair(pair) {
140
+ state.actPair = pair ?? null;
141
+ render();
142
+ },
143
+ // A host drops the root.
144
+ dispose() {
145
+ publishUiRoot('hud', null);
146
+ },
147
+ };
148
+ }
@@ -0,0 +1,96 @@
1
+ // The HUD root as a UI tree (schema v0 §11): Back, the HUD's title and big
2
+ // line, the prompt pill, the toast, and the Act/Jump pair. Pure: every input
3
+ // is in `state`, so the native host can build the same root from its own
4
+ // state, and the web chrome draws it through `uiDom.js` exactly as it drew
5
+ // these nodes by hand.
6
+ //
7
+ // state = {
8
+ // view: { landscape, safeInsets },
9
+ // back: { show, label },
10
+ // hud: { show, title, big, clock, prompt, promptShown },
11
+ // `clock`, when a timer runs: { gen, t0, v0, rate } in simulation
12
+ // seconds (schema §4.2, absolute); the big line then counts by
13
+ // itself, `s.1` and never below 0, and `big` is not drawn;
14
+ // toast: { text, wrap },
15
+ // actPair: null | { show, enabled, on: { jump, press, release, cancel } },
16
+ // on: { back },
17
+ // }
18
+ import { h } from './uiTree.js';
19
+
20
+ // HUD_COPY_STYLE (`hudCopy.js`) as tree style: a pill as wide as its words,
21
+ // at most its column, centred, wrapping anywhere.
22
+ const COPY = { bg: 'copy', radius: 14, pad: [4, 8], box: 'border', w: 'wrap', maxW: '100%', self: 'center', lh: 1.3, wrap: ['word', 'anywhere'] };
23
+ // An edge kept clear of the safe area only where the place asks for it.
24
+ const edge = (safeInsets, px) => (safeInsets ? [px, 0] : px);
25
+
26
+ export function buildActPair(pair, safeInsets = false) {
27
+ const show = Boolean(pair?.show);
28
+ const enabled = Boolean(pair?.enabled);
29
+ const on = pair?.on ?? {};
30
+ const button = { h: 48, w: 64, minH: 44, pad: 8, radius: 22, border: { w: 2, c: 'rgba(255,255,255,.55)' }, bg: 'rgba(20,16,12,.88)', color: '#fff', font: 'ui', size: 14, weight: 700, lh: 'normal', box: 'border', wrap: 'none', gone: !show };
31
+ return h('stack', {
32
+ key: 'actpair',
33
+ at: { anchor: 'bottomRight', bottom: [60, 50], right: edge(safeInsets, 14), rail: { name: 'right', order: 1 } },
34
+ style: { w: 134, h: 48, hit: 'none', gone: !show },
35
+ },
36
+ h('button', {
37
+ key: 'act', data: { hubAct: 'act' }, disabled: !enabled,
38
+ at: { anchor: 'topLeft', top: 0, left: 70 },
39
+ style: { ...button, opacity: enabled ? 1 : 0.5 },
40
+ on: { press: on.press, release: on.release, cancel: on.cancel },
41
+ }, 'Act'),
42
+ h('button', {
43
+ key: 'jump', data: { hubAct: 'jump' }, fire: 'down', keepFocus: true,
44
+ at: { anchor: 'topLeft', top: 0, left: 0 },
45
+ style: button,
46
+ on: { tap: on.jump },
47
+ }, 'Jump'));
48
+ }
49
+
50
+ export function buildHud(state) {
51
+ const view = state.view ?? {};
52
+ const landscape = Boolean(view.landscape);
53
+ const safeInsets = Boolean(view.safeInsets);
54
+ const back = state.back ?? {};
55
+ const hud = state.hud ?? {};
56
+ const toast = state.toast ?? {};
57
+ const big = hud.big ?? '';
58
+ const clock = hud.clock ? { gen: hud.clock.gen, t0: hud.clock.t0, v0: hud.clock.v0, rate: hud.clock.rate, fmt: 's.1', min: 0 } : null;
59
+ const toastText = toast.text ?? '';
60
+ const wrapToast = Boolean(toastText && toast.wrap);
61
+ return h('stack', { key: 'hud', style: { font: 'ui', size: 15, weight: 600, lh: 1.3, color: '#fff' } },
62
+ h('button', {
63
+ key: 'back', fire: 'down',
64
+ at: { anchor: 'topLeft', top: [12, 0], left: edge(safeInsets, landscape ? 76 : 12) },
65
+ style: { pad: [9, 16, 9, 12], radius: 22, border: { w: 1, c: 'line35' }, bg: 'chip', color: '#fff', gone: !back.show },
66
+ on: { tap: state.on?.back },
67
+ }, `‹ ${back.label ?? 'Back'}`),
68
+ h('column', {
69
+ key: 'hud',
70
+ at: { anchor: 'top', top: [12, 0] },
71
+ style: { maxW: landscape ? [{ vw: 42 }, { px: 420 }] : [{ vw: 70 }], talign: 'center', tshadow: 'outline', gone: !hud.show },
72
+ },
73
+ h('text', {
74
+ key: 'title', data: { hubCopy: 'subtitle' }, text: hud.title ?? '',
75
+ style: { ...COPY, size: 13, lines: 2, ellipsis: false, ls: 0.06, upper: true, gone: !hud.title },
76
+ }),
77
+ // The big line sits 4 px under the title (and 4 px down without one).
78
+ h('text', {
79
+ key: 'big', ...(clock ? { clock } : { text: big }),
80
+ style: { bg: 'copy', radius: 14, pad: [0, 8], box: 'border', w: 'wrap', maxW: '100%', self: 'center', mt: 4, wrap: 'anywhere', size: 56, weight: 800, lh: 1.05, gone: !big && !clock },
81
+ })),
82
+ h('text', {
83
+ key: 'prompt', hub: 'hud-prompt', data: { hubCopy: 'instruction' }, text: hud.prompt ?? '',
84
+ at: { anchor: 'bottom', bottom: [54, 48], left: [16, 0], right: [16, 0], z: 2 },
85
+ style: { ...COPY, size: 14, weight: 500, clip: false, maxW: [{ vw: 60 }, { px: 560 }, { vw: 100, sub: { l: 16, r: 16 } }], talign: 'center', gone: !hud.promptShown },
86
+ }),
87
+ h('text', {
88
+ key: 'toast', hub: 'toast', text: toastText,
89
+ at: { anchor: 'top', top: [12, 0], avoid: ['hud/hud', 'ask/card'] },
90
+ style: {
91
+ w: 'wrap', maxW: wrapToast ? [{ vw: 90 }, { px: 480 }] : landscape ? [{ vw: 42 }, { px: 420 }] : [{ vw: 100, px: -24 }], box: 'border',
92
+ talign: 'center', pad: [8, 14], radius: 8, bg: 'toast', size: 14, ...(wrapToast ? { wrap: 'anywhere' } : {}), gone: !toastText,
93
+ },
94
+ }),
95
+ state.actPair ? buildActPair(state.actPair, safeInsets) : null);
96
+ }
@@ -14,7 +14,9 @@ import { ensureActorModel } from './modelReady.js';
14
14
  import { Box3, Matrix4, Vector3 } from 'three';
15
15
  import { hub, simNow } from './state.js';
16
16
  import { allActors } from './quality.js';
17
+ import { vehicleOf } from '../shared/car.js';
17
18
  import { danceIdlePose } from '../shared/danceIdle.js';
19
+ import { EXPRESSION_EMOTES } from '../shared/expression.js';
18
20
 
19
21
  // The kit's emotes, in the picker's order, with the emoji drawn over the head.
20
22
  // The server holds the same ids and durations (`EMOTES` in server/idle.js).
@@ -26,12 +28,27 @@ export const EMOTES = [
26
28
  ['spin', '🌀'],
27
29
  ];
28
30
  const EMOJI = Object.fromEntries(EMOTES);
31
+ export function emoteDefinition(id) {
32
+ if (Object.hasOwn(EMOJI, id)) { return { emoji: EMOJI[id], motion: id }; }
33
+ if (!hub.place?.idle?.expression) { return null; }
34
+ return (Object.hasOwn(EXPRESSION_EMOTES, id) ? { ...EXPRESSION_EMOTES[id], motion: id } : hub.place.idle.expression.roleEmotes.find((role) => role.id === id)) ?? null;
35
+ }
36
+
37
+ export function expressionChoices(expression, grants) {
38
+ const basics = ['wave', 'sit', 'sleep', 'eat', 'dance', 'cry', 'laugh', 'point'].map((id) =>
39
+ [id, id === 'sit' ? '🪑' : EMOJI[id] ?? EXPRESSION_EMOTES[id].emoji, id[0].toUpperCase() + id.slice(1)]);
40
+ const more = ['cheer', 'bow', 'spin'].map((id) => [id, EMOJI[id], id[0].toUpperCase() + id.slice(1)]);
41
+ for (const role of expression.roleEmotes) {
42
+ if (grants.includes(role.id)) { more.push([role.id, role.emoji, role.label]); }
43
+ }
44
+ return { basics, more };
45
+ }
29
46
  // A seat is offered within this many flat metres of its footprint (a long
30
47
  // bench is offered along its whole length, not only near its middle).
31
48
  export const SIT_OFFER_M = 1.5;
32
49
  // A sitter's model drops this far and tips back this much (radians).
33
50
  export const SEAT_DROP_M = 0.45;
34
- const SEAT_TILT = -0.1;
51
+ export const SEAT_TILT = -0.1;
35
52
  // Lying uses a feet-origin model, centred lengthwise and face up.
36
53
  const LIE_DROP_M = 0.6;
37
54
  const LIE_OFFSET_M = 0.7;
@@ -73,6 +90,16 @@ export function emotePose(id, u, s) {
73
90
  return { y: Math.abs(Math.sin(Math.PI * u * 3)) * 0.55, rx: -0.18 * e, ry: 0, rz: 0 };
74
91
  case 'bow':
75
92
  return { y: 0, rx: Math.sin(Math.PI * u) * 0.8, ry: 0, rz: 0 };
93
+ case 'sleep':
94
+ return { y: -0.12 * e, rx: 0, ry: 0, rz: (0.32 + Math.sin(s * TAU * 0.2) * 0.08) * e };
95
+ case 'eat':
96
+ return { y: 0, rx: (0.12 + Math.sin(s * TAU * 1.8) * 0.12) * e, ry: 0, rz: 0 };
97
+ case 'cry':
98
+ return { y: -0.06 * e, rx: 0.3 * e, ry: 0, rz: Math.sin(s * TAU * 5) * 0.08 * e };
99
+ case 'laugh':
100
+ return { y: Math.abs(Math.sin(s * TAU * 2.4)) * 0.12 * e, rx: (-0.2 + Math.sin(s * TAU * 2.4) * 0.1) * e, ry: 0, rz: 0 };
101
+ case 'point':
102
+ return { y: 0, rx: 0.24 * e, ry: 0.2 * e, rz: 0 };
76
103
  case 'spin':
77
104
  return { y: Math.sin(Math.PI * u) * 0.2, rx: 0, ry: TAU * smooth(u), rz: 0 };
78
105
  default:
@@ -94,8 +121,9 @@ export function makeIdle(chrome) {
94
121
  jumped: false,
95
122
  watched: null,
96
123
  };
97
- chrome.onEmote?.((id) => {
98
- t.emote = id;
124
+ chrome.onEmote?.((id, ground = false) => {
125
+ t.sitHere = ground;
126
+ t.emote = ground ? null : id;
99
127
  });
100
128
  chrome.onSit?.(() => {
101
129
  t.sitPressed = true;
@@ -116,23 +144,34 @@ function frame(t, scene, mp, local, canAct, sceneKey) {
116
144
  const net = mp.net ?? null;
117
145
  const self = net?.selfId?.() ?? null;
118
146
  watchJump(t, scene);
119
- const emote = t.emote;
147
+ const emote = t.emote, sitHere = t.sitHere;
120
148
  t.emote = null;
121
- const can = Boolean(idle && canAct && net && self && local?.components.Transform);
122
- t.chrome.setEmotes?.(can && idle.emotes ? EMOTES : null);
123
- if (can && idle.emotes && emote && EMOJI[emote]) {
149
+ t.sitHere = false;
150
+ const can = Boolean(!vehicleOf(hub.cars, self) && idle && canAct && net && self && local?.components.Transform);
151
+ t.chrome.setEmotes?.(can && idle.emotes ? EMOTES : null, can && idle.expression ? expressionChoices(idle.expression, hub.roleEmotes) : null);
152
+ if (can && idle.emotes && emote && emoteDefinition(emote) && (!idle.expression?.roleEmotes.some((role) => role.id === emote) || hub.roleEmotes.includes(emote))) {
124
153
  net.send({ k: 'hub-emote', id: emote });
125
154
  }
126
- if (!can || !idle.seats) {
155
+ if (!can || !(idle.seats || idle.expression)) {
127
156
  // Nothing kept from a time the player could not act.
128
157
  t.sitPressed = false;
129
158
  t.jumped = false;
130
159
  t.standWanted = false;
160
+ t.sitHereWanted = null;
131
161
  t.chrome.sitPrompt?.(null);
132
162
  return;
133
163
  }
134
164
  const now = performance.now();
135
165
  const mine = Object.hasOwn(hub.seated, self) ? hub.seated[self] : null;
166
+ if (idle.expression) {
167
+ if (sitHere) { t.sitHereWanted = { until: now + 1600, sentAt: -Infinity }; }
168
+ const wanted = t.sitHereWanted;
169
+ if (mine || t.jumped || moving(scene) || (wanted && now >= wanted.until)) { t.sitHereWanted = null; }
170
+ else if (wanted && now - wanted.sentAt >= RESEND_MS) {
171
+ wanted.sentAt = now;
172
+ net.send({ k: 'hub-sit-here' });
173
+ }
174
+ } else { t.sitHereWanted = null; }
136
175
  if (mine) {
137
176
  t.chrome.sitPrompt?.('Stand');
138
177
  // A Stand press or a tap to jump is kept until it is sent (a resend
@@ -152,7 +191,7 @@ function frame(t, scene, mp, local, canAct, sceneKey) {
152
191
  const pressed = t.sitPressed;
153
192
  t.sitPressed = false;
154
193
  // A player the place holds still cannot sit.
155
- const seat = hub.held.has(self) ? null : nearestSeat(t, scene, local, self, sceneKey);
194
+ const seat = !idle.seats || hub.held.has(self) ? null : nearestSeat(t, scene, local, self, sceneKey);
156
195
  t.chrome.sitPrompt?.(seat ? (scene.getActor(seat)?.components.HubSeat?.pose === 'lie' ? 'Lie down' : 'Sit') : null);
157
196
  if (seat && pressed && now - t.sentAt >= RESEND_MS) {
158
197
  t.sentAt = now;
@@ -279,7 +318,7 @@ function draw(t, scene, local) {
279
318
  for (const [, actorId, e] of emoteActors(scene, local)) {
280
319
  const span = e.until - e.at;
281
320
  const u = span > 0 ? (now - e.at) / span : 1;
282
- const pose = actorId && u >= 0 && u < 1 ? emotePose(e.id, u, (now - e.at) / 1000) : null;
321
+ const pose = actorId && u >= 0 && u < 1 ? emotePose(emoteDefinition(e.id)?.motion, u, (now - e.at) / 1000) : null;
283
322
  if (pose) {
284
323
  add(actorId, pose);
285
324
  }
@@ -289,14 +328,20 @@ function draw(t, scene, local) {
289
328
  const playerIds = new Set([scene.multiplayer?.net?.selfId?.(), ...(scene.multiplayer?.avatars?.actors?.keys?.() ?? [])]);
290
329
  if (hub.danceIdle) {for (const playerId of playerIds) {
291
330
  const actorId = actorOf(scene, local, playerId);
292
- if (!actorId || poses.has(actorId) || hub.hidden.has(actorId) || hub.seated[playerId] || hub.held.has(playerId)) {continue;}
331
+ if (!actorId || poses.has(actorId) || hub.hidden.has(actorId) || hub.seated[playerId] || hub.held.has(playerId) || vehicleOf(hub.cars, playerId)) {continue;}
293
332
  const pose = danceIdlePose(hub.danceIdle, hub.sounds, scene.getActor(actorId)?.components.Transform, now);
294
333
  if (pose) {add(actorId, pose);}
295
334
  }}
335
+ for (const [driver, car] of Object.entries(hub.cars)) {
336
+ for (const playerId of [driver, ...Object.values(car.riders ?? {})]) {
337
+ const actorId = actorOf(scene, local, playerId);
338
+ if (actorId) {poses.set(actorId, { y: -SEAT_DROP_M, rx: SEAT_TILT, ry: 0, rz: 0 });}
339
+ }
340
+ }
296
341
  for (const playerId of Object.keys(hub.seated)) {
297
342
  const actorId = actorOf(scene, local, playerId);
298
343
  if (actorId) {
299
- const lie = scene.getActor(hub.seated[playerId])?.components.HubSeat?.pose === 'lie';
344
+ const lie = !(hub.place?.idle?.expression && hub.seated[playerId] === 'ground') && scene.getActor(hub.seated[playerId])?.components.HubSeat?.pose === 'lie';
300
345
  // Front is +Z: -90 degrees puts the face up and head behind the seat.
301
346
  // Feet-origin models are about 1.4 m tall; +0.7 Z centres that length.
302
347
  // Cancel the standing rig's yOffset below: the back rests near the top
@@ -356,6 +401,7 @@ function release(t) {
356
401
  restore(rig);
357
402
  }
358
403
  t.touched.clear();
404
+ t.sitHereWanted = null;
359
405
  t.seatsFor = null;
360
406
  }
361
407
 
@@ -366,7 +412,7 @@ function labels(scene, local, cam, view, project) {
366
412
  for (const [id, actorId, e] of emoteActors(scene, local)) {
367
413
  const span = e.until - e.at;
368
414
  const u = span > 0 ? (now - e.at) / span : 1;
369
- const emoji = EMOJI[e.id];
415
+ const emoji = emoteDefinition(e.id)?.emoji;
370
416
  const at = actorId && emoji && u >= 0 && u < 1 ? scene.getActor(actorId)?.components.Transform : null;
371
417
  if (!at) {
372
418
  continue;
@@ -85,12 +85,19 @@ export function makeInvites(api, target, route, now = () => Date.now(), notify =
85
85
  return control;
86
86
  }
87
87
  async function createShare() {
88
- const read = identity, asked = epoch;
88
+ // A deck without the Character rail never calls canInvite, so the socket
89
+ // that frame() follows names the account instead.
90
+ const read = identity, asked = epoch, net = read?.net ?? connection, self = net?.selfId?.();
91
+ const own = read ? read.userId : net?.userId?.(self);
89
92
  const { allowed, userId } = await hostAllows(api);
90
- // A socket change, reset or new identity while asking cancels the share.
91
- if (disposed || epoch !== asked || identity !== read) {return;}
92
- if (!allowed || userId !== null && userId !== String(read?.userId)) {
93
+ // A socket change, reset or new identity while asking cancels the share,
94
+ // and so does a recovery that changed this socket's player or account.
95
+ if (disposed || epoch !== asked || identity !== read || !read && (connection !== net || net?.closed?.())) {return;}
96
+ if (net?.selfId?.() !== self || String(net?.userId?.(self)) !== String(own)) {return;}
97
+ if (!allowed || userId !== null && userId !== String(own)) {
93
98
  if (read && identity === read) { read.host = false; read.hostAt = now(); }
99
+ // The host refused this player a link: say so rather than do nothing.
100
+ if (!allowed) {panel('Sharing is unavailable here.');}
94
101
  return;
95
102
  }
96
103
  const name = String(title() ?? '').trim().replace(/\s+/g, ' ').slice(0, 120);
@@ -210,6 +217,8 @@ export function makeInvites(api, target, route, now = () => Date.now(), notify =
210
217
  },
211
218
  landed() { if (destination !== null) { landed = true; } },
212
219
  accepted() { return destination !== null; },
220
+ // This connection's arrival carried an invite (a placement or a route).
221
+ carried() { return carriedInvite || destination !== null; },
213
222
  pointer(scene) {
214
223
  if (!destination || now() >= pointerUntil) {return null;}
215
224
  const mp = scene.multiplayer, net = mp?.net;
@@ -27,6 +27,14 @@ const PATHS = {
27
27
  souwester: 'M5 5h14l2 10 2 4H1l2-4z',
28
28
  captain: 'M3 6h18l-2 8H5zM4 14h16v4H4zM8 18h14v3H8z',
29
29
  lighthouse: 'M9 2h6v4H9zM7 6h10l3 16H4z',
30
+ 'police-cap': 'M5 6h14l1 6H4zM2 12h15l5 3H2zM10 7h4v3h-4z',
31
+ 'nurse-cap': 'M4 8l8-4 8 4v8H4zM11 7h2v2h2v2h-2v2h-2v-2H9V9h2z',
32
+ 'fire-helmet': 'M5 14a7 7 0 0 1 14 0zM1 14h22v3H1zM11 7h2v5h-2z',
33
+ 'chef-toque': 'M6 13a4 4 0 0 1 1-8a5 5 0 0 1 10 0a4 4 0 0 1 1 8zM6 13h12v6H6z',
34
+ 'delivery-cap': 'M4 14V9a8 8 0 0 1 16 0v5H4M4 14h19v3H4zM10 8h4v3h-4z',
35
+ 'teacher-beret': 'M2 11c0-4 6-6 11-6s9 2 9 5-4 4-10 4-10-1-10-3zM6 14h12v3H6zM12 2h2v3h-2z',
36
+ 'hard-hat': 'M4 15a8 8 0 0 1 16 0zM1 15h22v3H1zM11 7h2v4h-2z',
37
+ 'baker-cap': 'M4 10a8 5 0 0 1 16 0v4H4zM3 14h18v3H3z',
30
38
  };
31
39
  export function menuIcon(icon) {
32
40
  const path = PATHS[icon];