castle-web-cli 0.4.254 → 0.4.256

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 (29) hide show
  1. package/kits/hub-game/code/client/chrome.js +94 -27
  2. package/kits/hub-game/code/client/crowdNames.js +3 -2
  3. package/kits/hub-game/code/client/hudTree.js +16 -4
  4. package/kits/hub-game/code/client/nameTagLayout.js +46 -0
  5. package/kits/hub-game/code/client/role.js +4 -2
  6. package/kits/hub-game/code/client/safeLayout.js +1 -0
  7. package/kits/hub-game/code/client/worldLabels.js +54 -8
  8. package/kits/hub-game/code/systems/hub.js +90 -12
  9. package/kits/hub-game/docs/contract.md +10 -2
  10. package/kits/hub-game/scripts/fixtures/hud-surface.json +63 -63
  11. package/kits/hub-game/scripts/fixtures/talk-surface.json +4 -4
  12. package/kits/hub-game/scripts/test-actions-client.mjs +13 -3
  13. package/kits/hub-game/scripts/test-disguise-client.mjs +1 -1
  14. package/kits/hub-game/scripts/test-hud-clear.mjs +16 -10
  15. package/kits/hub-game/scripts/test-hud-defects-dom.mjs +59 -0
  16. package/kits/hub-game/scripts/test-hud-surface.mjs +31 -4
  17. package/kits/hub-game/scripts/test-placement-cache.mjs +87 -0
  18. package/kits/hub-game/scripts/test-prompt-portrait-dom.mjs +128 -0
  19. package/kits/hub-game/scripts/test-quality.mjs +1 -1
  20. package/kits/hub-game/scripts/test-role-client.mjs +82 -6
  21. package/kits/hub-game/scripts/test-talk-surface.mjs +3 -0
  22. package/kits/hub-game/scripts/test-world-labels.mjs +81 -0
  23. package/kits/multiplayer-3d/CLAUDE.md +13 -0
  24. package/kits/multiplayer-3d/castle.json +3 -3
  25. package/kits/multiplayer-3d/code/client/resumeGate.js +70 -8
  26. package/kits/multiplayer-3d/code/systems/multiplayer.js +3 -0
  27. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +133 -1
  28. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +39 -0
  29. package/package.json +1 -1
@@ -49,6 +49,7 @@ import { padCuesEnabled } from '../client/padCues.js';
49
49
  import { readPadArrival } from '../client/padCueArrival.js';
50
50
  import { makePadReadability } from '../client/padReadability.js';
51
51
  import { crowdNamesFor, layoutCrowdNames, readableSpriteBox, spriteBox } from '../client/crowdNames.js';
52
+ import { projectNameTag } from '../client/nameTagLayout.js';
52
53
  import { doorPoint } from '../client/doorFrame.js';
53
54
  import * as Avatar from '../client/avatar.js';
54
55
  import * as Celebrate from '../client/celebrate.js';
@@ -451,12 +452,13 @@ class HubSystem {
451
452
  if (geometry.resized) {
452
453
  (this.crowdNameScales ??= new Map()).set(sprite, geometry.resized);
453
454
  }
455
+ const box = this.playerNameBox(sprite, cam, this.nameTagFrame?.view ?? frame.view) ?? geometry.box;
454
456
  candidates.push({
455
457
  id: String(playerId),
456
458
  friend: Boolean(friendIds && userId && friendIds.has(String(userId))),
457
459
  distance: frame.local ? Math.hypot(at.x - frame.local.x, at.z - frame.local.z) : Infinity,
458
460
  at,
459
- box: geometry.box,
461
+ box,
460
462
  });
461
463
  sprites.set(String(playerId), sprite);
462
464
  }
@@ -508,6 +510,44 @@ class HubSystem {
508
510
  }
509
511
  }
510
512
 
513
+ playerNameBox(sprite, cam, view) {
514
+ if (!cam.matrixWorldInverse || !cam.projectionMatrix) {return null;}
515
+ const area = view.world ?? (this.nameTagArea ??= { left: 0, top: 0 });
516
+ if (!view.world) {
517
+ area.right = area.width = view.w;
518
+ area.bottom = area.height = view.h;
519
+ }
520
+ this.nameTagGeometry ??= new WeakMap();
521
+ let box = this.nameTagGeometry.get(sprite);
522
+ if (!box) {this.nameTagGeometry.set(sprite, box = {});}
523
+ return projectNameTag(sprite, cam, area, this.nameTagPoint ??= cam.position.clone(), box);
524
+ }
525
+
526
+ // Multiplayer has now moved the tags, and the town/crowd passes have
527
+ // settled their visibility and scale. Use the pose that is about to draw.
528
+ finishNameLabels(scene) {
529
+ const frame = this.nameTagFrame;
530
+ const cam = scene.three?.camera;
531
+ const tags = scene.multiplayer?.avatars?.tags;
532
+ if (frame?.scene !== scene || !cam || !tags?.size) {return;}
533
+ const boxes = (this.nameTagBoxes ??= new Map());
534
+ boxes.clear();
535
+ for (const [id, tag] of tags) {
536
+ const sprite = tag?.sprite;
537
+ if (id === 'self' || !sprite?.visible || sprite.material?.visible === false || !(sprite.material?.opacity > 0)) {continue;}
538
+ const box = this.playerNameBox(sprite, cam, frame.view);
539
+ if (box) {boxes.set(String(id), box);}
540
+ }
541
+ if (!frame.idle) {return;}
542
+ const local = scene.actorWith('Player');
543
+ this.chrome.syncRoleLabels?.(this.markItems(scene, local, cam, frame.view), null, true, 'mark:');
544
+ if (Hub.hub.roles.size && scene.data?.engine?.hubCrowdNames !== true) {
545
+ this.chrome.syncRoleLabels?.(roleItems(scene, local, cam, frame.view, Hub.hub.roles, project));
546
+ }
547
+ this.chrome.setWorldNameTags?.(boxes);
548
+ this.worldNameTagsSent = true;
549
+ }
550
+
511
551
  invalidateCrowdNames(scene) {
512
552
  // Without current geometry and authorization E cannot associate a name
513
553
  // or count with an avatar. Remove all visit-local decisions and finish
@@ -537,6 +577,7 @@ class HubSystem {
537
577
 
538
578
  afterBehaviors(scene, dt) {
539
579
  // Snapshot layout before any of this frame's chrome setters write DOM.
580
+ this.nameTagFrame = null;
540
581
  const canvas = scene.three?.renderer?.domElement;
541
582
  this.frameCanvas = this.chrome?.beginLayoutFrame?.(canvas) ?? canvas?.getBoundingClientRect?.();
542
583
  this.act?.beginLayoutFrame?.();
@@ -894,7 +935,9 @@ class HubSystem {
894
935
  this.ballot.frame(this.carded ? cardFor(mp.net ?? null) : null, Hub.hub.place?.ballot?.lines ?? [], mp.net?.selfId?.() ?? null, Hub.simNow(), box ? box.bottom : 0);
895
936
  }
896
937
  this.chrome.safeSurface?.('ballot', this.ballot?.surface?.());
897
- this.chrome.flushWorldLabels?.();
938
+ // Crowd selection needs the ordinary label boxes before it picks names.
939
+ // Other places do the DOM pass once, after multiplayer moves the tags.
940
+ if (this.lateFor !== scene || !this.nameTagFrame || scene.data?.engine?.hubCrowdNames === true) {this.chrome.flushWorldLabels?.();}
898
941
  this.reportLoad(mp);
899
942
  this.measure(scene, mp, now);
900
943
  if (this.lateFor !== scene) {this.endLayoutFrame();}
@@ -1056,8 +1099,13 @@ class HubSystem {
1056
1099
  this.applyVisibility(s);
1057
1100
  this.applyWear(s);
1058
1101
  this.applyCars(s);
1102
+ s.three?.camera?.updateWorldMatrix?.(true, false);
1059
1103
  this.fadeNames(s);
1060
1104
  this.applyDisguise(s);
1105
+ if (this.nameTagFrame?.scene === s) {
1106
+ this.finishNameLabels(s);
1107
+ this.chrome.flushWorldLabels?.();
1108
+ }
1061
1109
  },
1062
1110
  });
1063
1111
  // Device tiers run as a system of their own, registered only in a deck
@@ -4081,10 +4129,20 @@ class HubSystem {
4081
4129
  if (canvas?.width > 0 && canvas.height > 0) {view.world = canvas;}
4082
4130
  }
4083
4131
  chrome.setWorldViewport?.(view.world ?? null);
4132
+ // Last frame's names stop counting; a place that never had any is not told.
4133
+ if (this.worldNameTagsSent) {
4134
+ chrome.setWorldNameTags?.(null);
4135
+ this.worldNameTagsSent = false;
4136
+ }
4137
+ const canvas = this.frameCanvas;
4138
+ this.nameTagFrame = { scene, idle, view: !view.world && canvas?.width > 0 && canvas.height > 0 ? { ...view, world: canvas } : view };
4084
4139
  const labels = [];
4085
4140
  const padOccupancy = scene.data?.engine?.hubPadOccupancy === true;
4086
4141
  const crowdNames = scene.data?.engine?.hubCrowdNames === true;
4087
- if (crowdNames && cam?.parent === null && cam.matrixWorldAutoUpdate === true) {
4142
+ // Label depths and the late name-tag pass must use the same camera pose.
4143
+ if (typeof cam?.updateWorldMatrix === 'function') {
4144
+ cam.updateWorldMatrix(true, false);
4145
+ } else if (cam?.parent === null && cam.matrixWorldAutoUpdate === true) {
4088
4146
  cam.updateMatrixWorld();
4089
4147
  }
4090
4148
  let worldLabelCount = 0;
@@ -4148,11 +4206,12 @@ class HubSystem {
4148
4206
  const box = labelBox(screen.x, screen.y, chrome.measureLabel(label.text, speech, npc, pad), npc, view, chrome.hudClearBox?.() ?? null, chrome.hudPromptBox?.() ?? null);
4149
4207
  if (!box) {continue;}
4150
4208
  const item = chromeItem(id, label.text, speech, npc, box, opacity);
4209
+ item.depth = screen.depth;
4151
4210
  if (Hub.deck.quality) {item.actorId = id;}
4152
4211
  if (pad) {item.padOccupancy = true;}
4153
4212
  labels.push(item);
4154
4213
  } else {
4155
- labels.push({ id, x: screen.x, y: screen.y, text: label.text, speech: label.style === 'speech', npc: label.npc === true, opacity });
4214
+ labels.push({ id, x: screen.x, y: screen.y, depth: screen.depth, text: label.text, speech: label.style === 'speech', npc: label.npc === true, opacity });
4156
4215
  }
4157
4216
  }
4158
4217
  }
@@ -4168,11 +4227,11 @@ class HubSystem {
4168
4227
  for (const { id, at, label } of placed) {
4169
4228
  if (!party.has(id) || labels.some((item) => (item.actorId ?? item.id) === id)) {continue;}
4170
4229
  const screen = project(cam, at.x, at.y + 1.6, at.z, view);
4171
- if (screen) {labels.push({ id, x: screen.x, y: screen.y, text: label.text, speech: label.style === 'speech', npc: label.npc === true, opacity: 1 });}
4230
+ if (screen) {labels.push({ id, x: screen.x, y: screen.y, depth: screen.depth, text: label.text, speech: label.style === 'speech', npc: label.npc === true, opacity: 1 });}
4172
4231
  }
4173
4232
  // v1.168: marks and role labels count under the same cap; a culled
4174
4233
  // bystander's are dropped. Drawn later, after the world labels.
4175
- const tags = qualityTags(scene, local, this.markItems(scene, local, cam, view), roleItems(scene, local, cam, view, Hub.hub.roles, project));
4234
+ const tags = qualityTags(scene, local, this.markItems(scene, local, cam, view, false), roleItems(scene, local, cam, view, Hub.hub.roles, project));
4176
4235
  qualityTagItems = splitTags(capWorldLabels(labels, placed, lt, quality.labels, party, tags), labels, tags);
4177
4236
  }
4178
4237
  }
@@ -4196,7 +4255,7 @@ class HubSystem {
4196
4255
  chrome.setPointers?.(pointers.map((point) => offsetWorldPoint(point, view)));
4197
4256
  if (cam && idle) {
4198
4257
  if (qualityTagItems) {labels.push(...qualityTagItems);} else {
4199
- labels.push(...this.markItems(scene, local, cam, view));
4258
+ labels.push(...this.markItems(scene, local, cam, view, false));
4200
4259
  labels.push(...roleItems(scene, local, cam, view, Hub.hub.roles, project));
4201
4260
  }
4202
4261
  labels.push(...this.idle.labels(scene, local, cam, view, project));
@@ -4412,13 +4471,14 @@ class HubSystem {
4412
4471
  const screen = candidates.has(id) ? project(cam, at.x, at.y + 1.6, at.z, view) : null;
4413
4472
  const box = screen ? labelBox(screen.x, screen.y, chrome.measureLabel(label.text, speech, npc, pad), npc, view, hud, prompt) : null;
4414
4473
  items.push({ id, kind, pick, d: candidates.has(id) ? Math.hypot(at.x - lt.x, at.z - lt.z) : Infinity, mine: Object.hasOwn(mine, id), box });
4415
- drawn.set(id, { text: label.text, speech, npc, box, pad });
4474
+ drawn.set(id, { text: label.text, speech, npc, box, pad, depth: screen?.depth });
4416
4475
  }
4417
4476
  const out = [];
4418
4477
  for (const [id, opacity] of (defaults ? relevantLabels(state, items, view, now) : near(state, items, view, now))) {
4419
4478
  const d = drawn.get(id);
4420
4479
  if (!d?.box) {continue;}
4421
4480
  const item = chromeItem(id, d.text, d.speech, d.npc, d.box, opacity);
4481
+ item.depth = d.depth;
4422
4482
  if (Hub.deck.quality) {
4423
4483
  item.actorId = id;
4424
4484
  // Admission by the near-label rule grants the exemption, regardless
@@ -4464,7 +4524,7 @@ class HubSystem {
4464
4524
 
4465
4525
  // The tags the place put over players (`hub.mark`): over this player's own
4466
4526
  // body and over each other player's avatar, above the name tag.
4467
- markItems(scene, local, cam, view) {
4527
+ markItems(scene, local, cam, view, namesReady = true) {
4468
4528
  const mp = scene.multiplayer;
4469
4529
  const self = mp?.net?.selfId?.() ?? null;
4470
4530
  const out = [];
@@ -4472,9 +4532,27 @@ class HubSystem {
4472
4532
  if (disguiseTags(self, playerId)) {continue;}
4473
4533
  const actorId = playerId === self ? local?.id : mp?.avatars?.actors?.get(playerId);
4474
4534
  const at = actorId ? scene.getActor(actorId)?.components.Transform : null;
4475
- const screen = at ? project(cam, at.x, at.y + 1.95, at.z, view) : null;
4535
+ if (!at) {continue;}
4536
+ const tag = namesReady && playerId !== self ? mp?.avatars?.tags?.get(playerId)?.sprite : null;
4537
+ if (tag && (!tag.visible || tag.material?.visible === false || !(tag.material?.opacity > 0))) {continue;}
4538
+ // The kit hides this player's own name; the own mark sits where that
4539
+ // name would be drawn, not a fixed 1.95 m up (which floats far above
4540
+ // the head on a phone and, turned, under the HUD where the world layout
4541
+ // drops it). The point comes from this frame's body at multiplayer-3d's
4542
+ // own-tag height (`showSelf` passes no `tagHeight`: nameTags.js
4543
+ // HEIGHT_ABOVE), so a sprite multiplayer stopped placing (a vehicle
4544
+ // passenger skips the report) cannot hold the mark at an old pose; the
4545
+ // sprite gives only its drawn size.
4546
+ const own = playerId === self ? mp?.avatars?.tags?.get('self')?.sprite : null;
4547
+ const up = cam.matrixWorld?.elements;
4548
+ const half = (tag ?? own) && up ? Math.abs((tag ?? own).scale.y) / 2 : 0;
4549
+ const p = tag?.position ?? (playerId === self ? { x: at.x, y: at.y + 1.25, z: at.z } : null);
4550
+ const screen = p && up
4551
+ ? project(cam, p.x + up[4] * half, p.y + up[5] * half, p.z + up[6] * half, view)
4552
+ : project(cam, at.x, at.y + 1.95, at.z, view);
4476
4553
  if (screen) {
4477
- out.push({ id: `mark:${playerId}`, x: screen.x, y: screen.y, text: mark.text || '●', color: mark.color });
4554
+ out.push({ id: `mark:${playerId}`, x: screen.x, y: screen.y - (p && up ? 4 : 0), text: mark.text || '●', color: mark.color,
4555
+ opacity: tag?.material?.opacity ?? 1, ...(playerId === self ? { own: true } : {}) });
4478
4556
  }
4479
4557
  }
4480
4558
  return out;
@@ -4734,7 +4812,7 @@ function project(cam, x, y, z, view) {
4734
4812
  if (v.z > 1 || v.z < -1) {
4735
4813
  return null;
4736
4814
  }
4737
- return mapWorldPoint({ x: ((v.x + 1) / 2) * view.w, y: ((1 - v.y) / 2) * view.h }, view);
4815
+ return mapWorldPoint({ x: ((v.x + 1) / 2) * view.w, y: ((1 - v.y) / 2) * view.h, depth: v.z }, view);
4738
4816
  }
4739
4817
 
4740
4818
  function statsWanted() {
@@ -2073,8 +2073,15 @@ While an NPC conversation offers suggestion or choice buttons, those buttons
2073
2073
  are the next action: the bottom prompt hides until they close. Toasts yield
2074
2074
  when they cannot fit clear of those buttons.
2075
2075
  The wire/API stays unchanged; the client omits later sentences without adding
2076
- an ellipsis. Door authors write only the next action, about 48 characters;
2077
- story belongs in NPC talk or a later prompt. Dev serving warns on wrapping,
2076
+ an ellipsis. Door authors write only the next action, about 48 characters,
2077
+ and fewer for a phone held upright: there, in a place laid out by the safe
2078
+ layout (`hub.safeInsets`, or Act), the pill may take the whole row and is
2079
+ narrowed to the lane beside the bottom-right control column in the frame it
2080
+ is shown. That lane is about 314 px of a 390 px view beside Emote and Quick
2081
+ chat (about 40 characters) and about 232 px where the pill stands beside the
2082
+ Jump/Act pair, as in a place without Emote (about 32 characters). Elsewhere,
2083
+ and in landscape, it keeps to 60% of the width (234 px upright on 390). Story
2084
+ belongs in NPC talk or a later prompt. Dev serving warns on wrapping,
2078
2085
  and the layout check reports it as a failure. Existing overlong first sentences
2079
2086
  remain fully readable by wrapping in the bottom pill until their authors
2080
2087
  shorten them; the kit never silently clips a sentence. Empty prompts have no pill.
@@ -5421,6 +5428,7 @@ a deck written before them remains valid.
5421
5428
 
5422
5429
  | date | change |
5423
5430
  | --- | --- |
5431
+ | 2026-11-19 | §9 the next-action prompt on a phone held upright is no longer capped at 60% of the view's width (234 px on a 390 px phone, about 30 characters), which wrapped it on 34 of 58 doors in the Nov 19 every-door pass, wherever the safe layout places it (`hub.safeInsets` or Act): it may take the row less 16 px a side (at most 560 px), the safe layout narrows it to the lane beside the control column, and a prompt shown or reworded is placed in that frame rather than at the layout's next 500 ms pass. A place without the safe layout keeps the 60% cap, since nothing would move the prompt off Grab or the column. A 40-character sentence now stays on one line on a 360 px phone beside Emote; beside the Jump/Act pair (17 of 58 doors, those without Emote) the lane is about 232 px at 390, about 32 characters. Landscape keeps its 60% cap. Copy longer than about 40 characters still wraps upright, and door authors shorten it. No key, API or wire change. Test: `test-prompt-portrait-dom`. |
5424
5432
  | 2026-11-18 (v1.221) | §4/§12 first-input signals: a place that exports a `signal(hub, playerId, { kind, npc?, door? })` hook hears `move`, `jump` and the first door `prompt` from the client (each at most once per arrival, within 120 s of it; `hub-arrived` carries the arrival's `signals` number only where the hook exists, each `hub-signal` carries it back as `a`, and a retained rehello is answered `hub-signals` with that arrival's remaining window and spent kinds) and the kit's own `talk`, `press` (door jump, party Go/Go-yes, House visit) and `pad` (`hub.pad` step-on). A fixed vocabulary of authored ids, no free text and no manifest key. Without the hook: no wrapper, message, state, hook dispatch or wire field. |
5425
5433
  | 2026-11-18 (v1.220) | §"A place replaced under its players" copy: when the ending is seen as the player comes back from away (`multiplayer.returning()`), the line is "<this place's title> closed while you were away. Back to <the place left>…" ("This place closed while you were away…" with no title) instead of "This place was updated", which was not true for an owner's House left empty past its reconnect window. A player who was present still sees the updated line. Copy only: no key, API or wire change. |
5426
5434
  | 2026-11-18 (v1.219) | §12 page visibility after a rejoin: a client whose connection is not up forgets the state it last sent and sends its current state once it is connected again (a send into a socket that died unseen, as on an app switch, no longer leaves the server holding a stale hidden); the server takes a rejoin's first `hub-visibility` even when it repeats the kept value, then coalesces as before. An avatar-change hello is not a rejoin. No new key or wire field. |