castle-web-cli 0.4.243 → 0.4.244
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.
- package/dist/index.js +34 -3
- package/kits/hub-game/code/client/chrome.js +3 -1
- package/kits/hub-game/code/client/hookLayer.js +8 -0
- package/kits/hub-game/code/client/padCues.js +2 -0
- package/kits/hub-game/code/client/padReadability.js +6 -1
- package/kits/hub-game/code/client/signals.js +126 -0
- package/kits/hub-game/code/client/state.js +4 -0
- package/kits/hub-game/code/server/hub.js +19 -2
- package/kits/hub-game/code/server/npcs.js +4 -0
- package/kits/hub-game/code/server/party.js +3 -0
- package/kits/hub-game/code/server/signals.js +124 -0
- package/kits/hub-game/code/systems/hub.js +21 -2
- package/kits/hub-game/docs/contract.md +60 -0
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/test-pad-cues.mjs +6 -3
- package/kits/hub-game/scripts/test-signals.mjs +412 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -175,7 +175,7 @@ function availableKits() {
|
|
|
175
175
|
return FALLBACK_KITS;
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function usageText() {
|
|
179
179
|
const kits = availableKits();
|
|
180
180
|
const scaffoldKits = kits.filter((kit) => kit !== 'base' && kit !== 'real-time');
|
|
181
181
|
const initKits = [...scaffoldKits, 'none'].join(', ');
|
|
@@ -184,7 +184,7 @@ function usage() {
|
|
|
184
184
|
...kits.map((kit) => ` ${kit.padEnd(kitNameWidth)} ${KIT_DESCRIPTIONS[kit] ?? 'Scaffold kit.'}`),
|
|
185
185
|
` ${'none'.padEnd(kitNameWidth)} Minimal vite + canvas setup with the castle-web SDK and no kit.`,
|
|
186
186
|
].join('\n');
|
|
187
|
-
|
|
187
|
+
return `Usage:
|
|
188
188
|
castle-web init <dir> [--deck-id ID] [--card-id ID] [--kit NAME] [--port PORT] (kits: ${initKits}; default physics-2d)
|
|
189
189
|
castle-web init <dir> --remix <deckId> [--deck-id ID] [--card-id ID] [--port PORT] (starts from a published deck instead of a kit)
|
|
190
190
|
castle-web serve [dir] [--port PORT] [--host HOST] [--open] [--detach]
|
|
@@ -225,9 +225,29 @@ function usage() {
|
|
|
225
225
|
Kits:
|
|
226
226
|
${kitLines}
|
|
227
227
|
|
|
228
|
-
After init, read the scaffolded deck's CLAUDE.md (also AGENTS.md) for the kit's full author guide
|
|
228
|
+
After init, read the scaffolded deck's CLAUDE.md (also AGENTS.md) for the kit's full author guide.`;
|
|
229
|
+
}
|
|
230
|
+
function usage() {
|
|
231
|
+
console.log(usageText());
|
|
229
232
|
process.exit(1);
|
|
230
233
|
}
|
|
234
|
+
// `--help` / `-h` anywhere among a command's arguments -- after a `--`, or where a flag
|
|
235
|
+
// expects its value, too. Commands parse loosely (most ignore flags they don't take, and
|
|
236
|
+
// `--` is dropped before positionals are read), so any exception lets one through to the
|
|
237
|
+
// action; a literal path or value spelled `--help` is not worth that.
|
|
238
|
+
function wantsHelp() {
|
|
239
|
+
return args.slice(1).some((arg) => arg === '--help' || arg === '-h');
|
|
240
|
+
}
|
|
241
|
+
// The usage lines for `command` (and `git <sub>`), or the whole text when it has none.
|
|
242
|
+
function helpText() {
|
|
243
|
+
const text = usageText();
|
|
244
|
+
const sub = command === 'git' ? readPositionals()[0] : undefined;
|
|
245
|
+
const prefix = sub && !sub.startsWith('-') ? `castle-web git ${sub} ` : `castle-web ${command} `;
|
|
246
|
+
const lines = text.split('\n').filter((line) => line.trimStart().startsWith(prefix));
|
|
247
|
+
if (lines.length === 0)
|
|
248
|
+
return text;
|
|
249
|
+
return `Usage:\n${lines.join('\n')}`;
|
|
250
|
+
}
|
|
231
251
|
// `git init`'s own arguments, strictly: an unknown flag is an error rather than
|
|
232
252
|
// ignored, since a typo'd `--staging` would otherwise target production.
|
|
233
253
|
function parseGitInitArgs() {
|
|
@@ -529,6 +549,17 @@ async function main() {
|
|
|
529
549
|
console.log(getCliVersion());
|
|
530
550
|
return;
|
|
531
551
|
}
|
|
552
|
+
// Also before the switch, and before any command reads its arguments: no command
|
|
553
|
+
// knows --help, and most skip an unknown flag and run -- `save-deck --help` saved
|
|
554
|
+
// the deck. Asking for help never does anything else.
|
|
555
|
+
if (command === '--help' || command === '-h' || command === 'help') {
|
|
556
|
+
console.log(usageText());
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (wantsHelp()) {
|
|
560
|
+
console.log(helpText());
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
532
563
|
if (VERSION_COMMANDS.has(command) && (await gitVersionCommand(command)))
|
|
533
564
|
return;
|
|
534
565
|
switch (command) {
|
|
@@ -2261,6 +2261,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2261
2261
|
// A owns only this lazy, noninteractive caption. The projected surface
|
|
2262
2262
|
// participates in the shared registry but is placed last, yielding to
|
|
2263
2263
|
// every final control/card/label box rather than moving any of them.
|
|
2264
|
+
// v1.221: true only when the caption is drawn and visible this frame.
|
|
2264
2265
|
setPadContext(item) {
|
|
2265
2266
|
const blocked = pickerOpen || sayOpen || emotesOpen || peopleOpen || doorsOpen || talkOpen ||
|
|
2266
2267
|
!!textAsk?.card || !!placeMenu?.sheet || sound?.open || actionOverflow?.isOpen?.() ||
|
|
@@ -2269,7 +2270,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2269
2270
|
(cabinet.style.display !== 'none' && cabinet.dataset.drawn === 'board');
|
|
2270
2271
|
if (!item || blocked) {
|
|
2271
2272
|
if (padContext && padContext.node.style.visibility !== 'hidden') {padContext.node.style.visibility = 'hidden';}
|
|
2272
|
-
return;
|
|
2273
|
+
return false;
|
|
2273
2274
|
}
|
|
2274
2275
|
if (!padContext) {
|
|
2275
2276
|
const node = el('div', { position: 'absolute', left: '0px', top: '0px', width: 'max-content', maxWidth: 'min(70vw, 320px)',
|
|
@@ -2318,6 +2319,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2318
2319
|
}
|
|
2319
2320
|
const visibility = at ? '' : 'hidden';
|
|
2320
2321
|
if (node.style.visibility !== visibility) {node.style.visibility = visibility;}
|
|
2322
|
+
return Boolean(at);
|
|
2321
2323
|
},
|
|
2322
2324
|
clearPadContext() {
|
|
2323
2325
|
if (!padContext) {return;}
|
|
@@ -12,6 +12,7 @@ import * as AvatarCap from './avatarCap.js';
|
|
|
12
12
|
import { mergeDictionary } from './interestCap.js';
|
|
13
13
|
import * as Cabinets from './cabinets.js';
|
|
14
14
|
import { firstJoinFor } from './firstJoin.js';
|
|
15
|
+
import { signalReplay } from './signals.js';
|
|
15
16
|
import { deck, earnedNow, hub, holdShowsNow, idleNow, localArrival, mergeHidden, receiveParty, replayCleanup, rolesNow, wearingNow } from './state.js';
|
|
16
17
|
import { clearShot, receiveShot } from './shot.js';
|
|
17
18
|
import * as Ballot from './ballot.js';
|
|
@@ -326,6 +327,13 @@ const hooks = {
|
|
|
326
327
|
break;
|
|
327
328
|
case 'hub-arrived':
|
|
328
329
|
hub.arrivedFacing = typeof msg.facing === 'number' ? msg.facing : 0;
|
|
330
|
+
// v1.221: an arrival the place's `signal` hook hears: its first inputs.
|
|
331
|
+
hub.signalArrival = Number.isSafeInteger(msg.signals) ? { n: msg.signals, at: performance.now() } : null;
|
|
332
|
+
break;
|
|
333
|
+
case 'hub-signals':
|
|
334
|
+
// v1.221: a retained rehello: the same arrival, what is left of its
|
|
335
|
+
// window and the kinds already said (never a fresh allowance).
|
|
336
|
+
hub.signalArrival = signalReplay(msg);
|
|
329
337
|
break;
|
|
330
338
|
case 'hub-hold-face':
|
|
331
339
|
// v1.190: a hold with turnCamera, and its release, turn this player's
|
|
@@ -28,6 +28,8 @@ export function collectPadCues(actors, hidden) {
|
|
|
28
28
|
cues.push({ id: actor.id, x: c.Transform.x, z: c.Transform.z, radius: spec.radius,
|
|
29
29
|
y: (c.Transform.y ?? 0) + (shape?.kind === 'cylinder' ? (shape.height ?? 1) / 2 : 0) + 0.03,
|
|
30
30
|
title: explicit ? spec.title : doors.get(spec.door)?.title, door: !explicit,
|
|
31
|
+
// v1.221: the door a door pad's caption names (first-input signals).
|
|
32
|
+
...(explicit ? {} : { doorId: spec.door }),
|
|
31
33
|
cabinet: !explicit && doors.get(spec.door)?.kind === 'cabinet',
|
|
32
34
|
color: shape?.color ?? '#d9a441' });
|
|
33
35
|
}
|
|
@@ -15,8 +15,13 @@ export function makePadReadability(engine, options) {
|
|
|
15
15
|
rings?.frame(traveling ? null : active?.cue);
|
|
16
16
|
if (engine.hubPadContext === true) {
|
|
17
17
|
if (active !== previous || guest !== previousGuest) {text = padContextText(active, guest); previous = active; previousGuest = guest;}
|
|
18
|
-
|
|
18
|
+
// v1.221: the door whose caption chrome actually drew and shows this
|
|
19
|
+
// frame (not one hidden behind an open panel or left unplaced), for
|
|
20
|
+
// first-input signals.
|
|
21
|
+
const drawn = chrome.setPadContext(traveling || captionBlocked ? null : text) === true;
|
|
22
|
+
return drawn && typeof active?.cue.doorId === 'string' ? active.cue.doorId : null;
|
|
19
23
|
}
|
|
24
|
+
return null;
|
|
20
25
|
},
|
|
21
26
|
dispose() {
|
|
22
27
|
rings?.dispose();
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// v1.221: first-input signals (contract §12 "First-input signals"), the
|
|
2
|
+
// client's half. Only an arrival whose `hub-arrived` carried an arrival number
|
|
3
|
+
// (`signals`, sent only where the place's module has a `signal` hook) says
|
|
4
|
+
// anything, and then each of its first walk, first jump and first door prompt
|
|
5
|
+
// at most once, within WINDOW_MS of that arrival. Once all three are said or
|
|
6
|
+
// the window is over, a frame costs one comparison.
|
|
7
|
+
//
|
|
8
|
+
// `{ k: 'hub-signal', kind: 'move' | 'jump', a }` and
|
|
9
|
+
// `{ k: 'hub-signal', kind: 'prompt', a, door }`, `a` the arrival number they
|
|
10
|
+
// were armed with; the server checks each. A retained rehello is told the same
|
|
11
|
+
// arrival again (`hub-signals`, `signalReplay`): what is left of its window
|
|
12
|
+
// and what was already said.
|
|
13
|
+
|
|
14
|
+
export const WINDOW_MS = 120_000;
|
|
15
|
+
// What walks a player (`idle.js` MOVE_KEYS without Space, which jumps).
|
|
16
|
+
const WALK_KEYS = ['KeyW', 'KeyA', 'KeyS', 'KeyD', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
|
|
17
|
+
// The drag stick counts once it is this far over (`idle.js` `moving`).
|
|
18
|
+
const STICK_MIN = 0.15;
|
|
19
|
+
|
|
20
|
+
const KINDS = ['move', 'jump', 'prompt'];
|
|
21
|
+
|
|
22
|
+
// `hub-signals` as the hub's `signalArrival`: the arrival's number, its start
|
|
23
|
+
// moved back by the window already spent, and the kinds already said; null
|
|
24
|
+
// for anything malformed.
|
|
25
|
+
export function signalReplay(msg, now = performance.now()) {
|
|
26
|
+
if (!Number.isSafeInteger(msg?.n) || !Number.isFinite(msg.left) || msg.left <= 0 || msg.left > WINDOW_MS || !Array.isArray(msg.sent)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return { n: msg.n, at: now - (WINDOW_MS - msg.left), sent: KINDS.filter((kind) => msg.sent.includes(kind)) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function walking(keys, stick) {
|
|
33
|
+
if (keys && WALK_KEYS.some((code) => keys.has?.(code) === true)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return Boolean(stick?.active && Math.hypot(stick.x ?? 0, stick.y ?? 0) >= STICK_MIN);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The engine hears keys typed into a text field too (a chat line, a name):
|
|
40
|
+
// those are words, not a walk or a jump.
|
|
41
|
+
function typing(doc) {
|
|
42
|
+
const el = doc?.activeElement;
|
|
43
|
+
return Boolean(el && (el.isContentEditable || el.closest?.('input, textarea, select')));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function makeSignals(doc = globalThis.document) {
|
|
47
|
+
// { arrival, move, jump, prompt, done } for the arrival being said
|
|
48
|
+
let record = null;
|
|
49
|
+
// A tap is a jump the Player behavior takes (`moveInput.consumeJump`)
|
|
50
|
+
// before this runs, so it is noted as it is taken. Ours stays the outermost
|
|
51
|
+
// wrapper: Act's own (`act.js`) adds its Jump button's press to what it
|
|
52
|
+
// wrapped, so one put over ours is wrapped again. Act and idle wrap a
|
|
53
|
+
// controls object once, so the chain does not grow.
|
|
54
|
+
let wrapper = null;
|
|
55
|
+
let tapped = false;
|
|
56
|
+
function watch(input) {
|
|
57
|
+
if (!input || typeof input.consumeJump !== 'function' || input.consumeJump === wrapper) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const consume = input.consumeJump;
|
|
61
|
+
wrapper = function consumeJump(...args) {
|
|
62
|
+
const had = consume.apply(this, args);
|
|
63
|
+
if (had) {
|
|
64
|
+
tapped = true;
|
|
65
|
+
}
|
|
66
|
+
return had;
|
|
67
|
+
};
|
|
68
|
+
input.consumeJump = wrapper;
|
|
69
|
+
}
|
|
70
|
+
const up = (net) => !net.closed?.() && (!net.status || net.status().state === 'connected');
|
|
71
|
+
return {
|
|
72
|
+
// Whether a door prompt shown now would still be said (so the caller
|
|
73
|
+
// need not collect one).
|
|
74
|
+
wantsPrompt: (arrival) => Boolean(arrival && record?.arrival === arrival && !record.done && !record.prompt),
|
|
75
|
+
// Each frame. `arrival`: the hub's `signalArrival`, or null (no hook, no
|
|
76
|
+
// arrival yet, a trip). `prompt`: a door id whose prompt is up, or null.
|
|
77
|
+
frame(net, arrival, now, { keys, stick, prompt }) {
|
|
78
|
+
if (!arrival) {
|
|
79
|
+
tapped = false;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (record?.arrival !== arrival) {
|
|
83
|
+
const said = Array.isArray(arrival.sent) ? arrival.sent : [];
|
|
84
|
+
record = { arrival, move: said.includes('move'), jump: said.includes('jump'), prompt: said.includes('prompt'), done: false };
|
|
85
|
+
record.done = record.move && record.jump && record.prompt;
|
|
86
|
+
tapped = false;
|
|
87
|
+
}
|
|
88
|
+
if (record.done) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (now - arrival.at >= WINDOW_MS) {
|
|
92
|
+
record.done = true;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!net) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!record.jump) {
|
|
99
|
+
watch(stick);
|
|
100
|
+
}
|
|
101
|
+
const tap = tapped;
|
|
102
|
+
tapped = false;
|
|
103
|
+
const typed = (!record.move || !record.jump) && keys?.size > 0 && typing(doc);
|
|
104
|
+
const move = !record.move && walking(typed ? null : keys, stick);
|
|
105
|
+
const jump = !record.jump && (tap || (!typed && keys?.has?.('Space') === true));
|
|
106
|
+
const door = !record.prompt && typeof prompt === 'string' && prompt ? prompt : null;
|
|
107
|
+
// Said only while the connection can carry it; otherwise kept for later.
|
|
108
|
+
if (!(move || jump || door) || !up(net)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (move) {
|
|
112
|
+
record.move = true;
|
|
113
|
+
net.send({ k: 'hub-signal', kind: 'move', a: arrival.n });
|
|
114
|
+
}
|
|
115
|
+
if (jump) {
|
|
116
|
+
record.jump = true;
|
|
117
|
+
net.send({ k: 'hub-signal', kind: 'jump', a: arrival.n });
|
|
118
|
+
}
|
|
119
|
+
if (door) {
|
|
120
|
+
record.prompt = true;
|
|
121
|
+
net.send({ k: 'hub-signal', kind: 'prompt', a: arrival.n, door });
|
|
122
|
+
}
|
|
123
|
+
record.done = record.move && record.jump && record.prompt;
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -170,6 +170,9 @@ export const hub = {
|
|
|
170
170
|
// the facing the place gave this player on arrival, or null until it has,
|
|
171
171
|
// and whether the camera has been turned to it
|
|
172
172
|
arrivedFacing: null,
|
|
173
|
+
// v1.221: this connection's latest arrival under a place's `signal` hook,
|
|
174
|
+
// { n, at (performance.now()) }, or null (first-input signals)
|
|
175
|
+
signalArrival: null,
|
|
173
176
|
// v1.165: this client's newest clamped pose row while it matters to a car
|
|
174
177
|
// (`hookLayer` state, vehicle.js `placedHeading`)
|
|
175
178
|
selfClamp: null,
|
|
@@ -323,6 +326,7 @@ export function clear() {
|
|
|
323
326
|
}
|
|
324
327
|
hub.cabinets = {};
|
|
325
328
|
hub.arrivedFacing = null;
|
|
329
|
+
hub.signalArrival = null;
|
|
326
330
|
hub.arrivalPlaced = false;
|
|
327
331
|
hub.faced = false;
|
|
328
332
|
hub.commands.length = 0;
|
|
@@ -60,6 +60,7 @@ import * as WriterLease from './writerLease.js';
|
|
|
60
60
|
import * as ArrivalPose from './arrivalPose.js';
|
|
61
61
|
import * as Observe from './observe.js';
|
|
62
62
|
import * as Wallet from './wallet.js';
|
|
63
|
+
import * as Signals from './signals.js';
|
|
63
64
|
import { makeAnonymousEntry } from './anonymousEntry.js';
|
|
64
65
|
import { doorPoint } from '../client/doorFrame.js';
|
|
65
66
|
|
|
@@ -433,6 +434,11 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
|
|
|
433
434
|
notifyVisibility(h, player.playerId);
|
|
434
435
|
return;
|
|
435
436
|
}
|
|
437
|
+
// v1.221: telemetry only, so heard during a progress read as well.
|
|
438
|
+
if (data?.k === 'hub-signal' && Signals.on(h)) {
|
|
439
|
+
Signals.message(h, player, data, () => doors(h).map((door) => door.id));
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
436
442
|
if (data?.k === 'hub-hello') {
|
|
437
443
|
LoadAbandon.hello(h, player?.playerId);
|
|
438
444
|
hello(h, player, data);
|
|
@@ -1489,6 +1495,9 @@ function hello(h, player, data, synthetic = false) {
|
|
|
1489
1495
|
// holds none of the cabinet cards it was sent (v1.7).
|
|
1490
1496
|
if (data.again !== true) {
|
|
1491
1497
|
replaySent(h, player.playerId, data.resume === true);
|
|
1498
|
+
// v1.221: a retained rehello's page may have reloaded: the current
|
|
1499
|
+
// arrival's first-input allowance, never a new one.
|
|
1500
|
+
if (known?.arrived) {Signals.replay(h, player.playerId);}
|
|
1492
1501
|
Idle.joinedAfresh(h, player.playerId, data.resume === true);
|
|
1493
1502
|
if (h.manifest.act === true) {Act.replay(h, player.playerId);}
|
|
1494
1503
|
h.vehicleDeparting?.delete(player.playerId);
|
|
@@ -2584,6 +2593,7 @@ function forget(h, playerId) {
|
|
|
2584
2593
|
}
|
|
2585
2594
|
Party.forget(h, playerId);
|
|
2586
2595
|
Say.forget(h, playerId);
|
|
2596
|
+
Signals.forget(h, playerId);
|
|
2587
2597
|
if (h.ballotState) {
|
|
2588
2598
|
Ballot.forget(h, playerId);
|
|
2589
2599
|
}
|
|
@@ -2724,7 +2734,9 @@ function finishSignUp(h, playerId, signUp, cancel = false) {
|
|
|
2724
2734
|
h.hooks.arrive?.(h.ctx, [signUp.member]);
|
|
2725
2735
|
settle(h, playerId);
|
|
2726
2736
|
const body = h.sim.players.get(playerId);
|
|
2727
|
-
|
|
2737
|
+
// v1.221: a signal hook's arrival number starts this arrival's first inputs.
|
|
2738
|
+
const signals = Signals.arrived(h, playerId);
|
|
2739
|
+
if (body) {h.session?.send(playerId, { k: 'hub-arrived', facing: body.facing, ...(signals ? { signals } : {}) });}
|
|
2728
2740
|
} catch (err) {
|
|
2729
2741
|
console.warn(`[hub] signup arrival failed: ${err?.message ?? err}`);
|
|
2730
2742
|
} finally {
|
|
@@ -2878,7 +2890,9 @@ function arrivals(h) {
|
|
|
2878
2890
|
if (Math.hypot(body.at.x - was.x, body.at.z - was.z) > HOLD_SLACK) {
|
|
2879
2891
|
settle(h, playerId);
|
|
2880
2892
|
}
|
|
2881
|
-
|
|
2893
|
+
// v1.221: a signal hook's arrival number starts this arrival's first inputs.
|
|
2894
|
+
const signals = Signals.arrived(h, playerId);
|
|
2895
|
+
h.session?.send(playerId, { k: 'hub-arrived', facing: body.facing, ...(signals ? { signals } : {}) });
|
|
2882
2896
|
}
|
|
2883
2897
|
if (h.players.get(playerId)?.endAgain) {
|
|
2884
2898
|
delete h.players.get(playerId).endAgain;
|
|
@@ -3758,6 +3772,7 @@ function doorJump(h, player, data) {
|
|
|
3758
3772
|
placeAt(h, player.playerId, { x: at.x, y: standingY(h, { ...at, y: 1.2 }), z: at.z }, facing);
|
|
3759
3773
|
settle(h, player.playerId);
|
|
3760
3774
|
h.session?.send(player.playerId, { k: 'hub-jumped', facing });
|
|
3775
|
+
Signals.emit(h, player.playerId, { kind: 'press', door: door.id });
|
|
3761
3776
|
}
|
|
3762
3777
|
|
|
3763
3778
|
// Join on a friend at home in their House (§5): through that door into the
|
|
@@ -3785,6 +3800,7 @@ function houseVisit(h, player, data) {
|
|
|
3785
3800
|
h.jumpAt.set(playerId, now);
|
|
3786
3801
|
tellWent(h, [playerId], door.id);
|
|
3787
3802
|
sendGo(h, playerId, { k: 'hub-go', door: door.id, key: null, place: null, scene: null, title: door.title, party: 1, owner });
|
|
3803
|
+
Signals.emit(h, playerId, { kind: 'press', door: door.id });
|
|
3788
3804
|
}
|
|
3789
3805
|
|
|
3790
3806
|
// "Stuck?" (v1.33): whether this place puts a player back at its arrival for
|
|
@@ -4487,6 +4503,7 @@ function gather(h, door, playerIds) {
|
|
|
4487
4503
|
return;
|
|
4488
4504
|
}
|
|
4489
4505
|
const on = new Set(playerIds ?? []);
|
|
4506
|
+
if (Signals.on(h)) {Signals.pad(h, door, h.padDoors.get(door), on);}
|
|
4490
4507
|
h.padDoors.set(door, on);
|
|
4491
4508
|
h.padOccupancy?.reportedAt.set(door, h.sim.timeMs);
|
|
4492
4509
|
for (const [playerId, entry] of h.shut) {
|
|
@@ -37,6 +37,7 @@ import { EMOTES } from './idle.js';
|
|
|
37
37
|
import { npcDisplayText } from '../npcDisplayText.js';
|
|
38
38
|
import { warnOnce } from './actors.js';
|
|
39
39
|
import { readNpcTurnsAtOnce } from './manifest.js';
|
|
40
|
+
import * as Signals from './signals.js';
|
|
40
41
|
|
|
41
42
|
// v1.47: a crowd answers a gesture without calling a mind.
|
|
42
43
|
const REACT_RANGE_M = 6;
|
|
@@ -666,6 +667,9 @@ function open(h, n, playerId, npcId) {
|
|
|
666
667
|
}
|
|
667
668
|
state.talking = talking;
|
|
668
669
|
h.ctx.track?.(playerId, 'npc_chat_count', { subject: 9, value: 1 });
|
|
670
|
+
// v1.221: a companion's id carries its owner's player id; it is named
|
|
671
|
+
// only as 'companion'.
|
|
672
|
+
Signals.emit(h, playerId, { kind: 'talk', npc: npc.owner ? 'companion' : npc.id });
|
|
669
673
|
// A new conversation can ask again for what an earlier one finished.
|
|
670
674
|
const participant = n.participants.get(playerId);
|
|
671
675
|
if (participant) {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// member) and by player id for a guest, who is a member only while here.
|
|
12
12
|
|
|
13
13
|
// The most players one party holds.
|
|
14
|
+
import * as Signals from './signals.js';
|
|
14
15
|
export const PARTY_MAX = 8;
|
|
15
16
|
// An invitation and a proposed door wait this long for an answer.
|
|
16
17
|
const INVITE_MS = 60000;
|
|
@@ -258,6 +259,8 @@ export function toPad(d, playerId, door, n) {
|
|
|
258
259
|
const at = padPoint(h, door, n, playerId) ?? d.front(door);
|
|
259
260
|
d.placeAt(h, playerId, { x: at.x, y: d.standingY(h, { ...at, y: 1.2 }), z: at.z }, facing);
|
|
260
261
|
h.session?.send(playerId, { k: 'hub-jumped', facing });
|
|
262
|
+
// v1.221: a party Go or Go-yes is the player's press for this door.
|
|
263
|
+
Signals.emit(h, playerId, { kind: 'press', door: door.id });
|
|
261
264
|
return true;
|
|
262
265
|
}
|
|
263
266
|
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// v1.221: first-input signals (contract §4 `signal`, §12 "First-input
|
|
2
|
+
// signals"). A place whose module defines a `signal` hook hears a fixed
|
|
3
|
+
// vocabulary of a player's first moments, never free text:
|
|
4
|
+
//
|
|
5
|
+
// { kind: 'move' } their first walk input } from the client,
|
|
6
|
+
// { kind: 'jump' } their first jump } each at most once
|
|
7
|
+
// { kind: 'prompt', door } the first door prompt shown } an arrival, within
|
|
8
|
+
// } WINDOW_MS of it
|
|
9
|
+
// { kind: 'talk', npc } a conversation opened (an NPC actor id, or
|
|
10
|
+
// 'companion' for the player's own companion)
|
|
11
|
+
// { kind: 'press', door } they were put at a door they asked for (a door
|
|
12
|
+
// jump, a party Go or Go-yes, a friend's House)
|
|
13
|
+
// { kind: 'pad', door } the place's `hub.pad` first counted them on a
|
|
14
|
+
// door's pad
|
|
15
|
+
//
|
|
16
|
+
// Without the hook nothing is kept, sent or called: an older kit, which knows
|
|
17
|
+
// no such hook, simply never calls it.
|
|
18
|
+
|
|
19
|
+
const CLIENT_KINDS = new Set(['move', 'jump', 'prompt']);
|
|
20
|
+
// The client signals belong to this long after an arrival.
|
|
21
|
+
export const WINDOW_MS = 120_000;
|
|
22
|
+
const own = (data, keys) => Object.keys(data).every((key) => keys.includes(key));
|
|
23
|
+
|
|
24
|
+
export function on(h) {
|
|
25
|
+
return typeof h.hooks?.signal === 'function';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// A hook that throws or rejects never reaches the kit; it is said once. Call
|
|
29
|
+
// it after the kit's own work for the event is done.
|
|
30
|
+
export function emit(h, playerId, signal) {
|
|
31
|
+
if (!on(h)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const failed = () => {
|
|
35
|
+
if (!h.signalFailed) {
|
|
36
|
+
h.signalFailed = true;
|
|
37
|
+
console.warn('[hub] signal hook failed');
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
const result = h.hooks.signal(h.ctx, playerId, Object.freeze({ ...signal }));
|
|
42
|
+
result?.catch?.(failed);
|
|
43
|
+
} catch {
|
|
44
|
+
failed();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// A genuine arrival (the place's `arrive` hook has heard it): the client
|
|
49
|
+
// signals start again for this player. A rehello or a retained resume is not
|
|
50
|
+
// one. Returns the arrival's number for `hub-arrived`, or null without a hook.
|
|
51
|
+
export function arrived(h, playerId) {
|
|
52
|
+
if (!on(h)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
h.signalN = (h.signalN ?? 0) + 1;
|
|
56
|
+
(h.signalArrivals ??= new Map()).set(playerId, { n: h.signalN, at: Date.now(), sent: new Set() });
|
|
57
|
+
return h.signalN;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The client's `{ k: 'hub-signal', kind, a, door? }`, from a present sender
|
|
61
|
+
// whose arrival is still in its window; the sender comes from the session,
|
|
62
|
+
// never the payload. `a` is the arrival number the client was armed with: one
|
|
63
|
+
// from an earlier arrival (a rejoin race) is dropped before the kind is spent.
|
|
64
|
+
// Once and window checks come before any door lookup.
|
|
65
|
+
// `doorIds()`: the ids of this place's doors.
|
|
66
|
+
export function message(h, player, data, doorIds) {
|
|
67
|
+
const playerId = player?.playerId;
|
|
68
|
+
const arrival = typeof playerId === 'string' ? h.signalArrivals?.get(playerId) : null;
|
|
69
|
+
if (!arrival || !on(h) || Date.now() - arrival.at >= WINDOW_MS) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
if (data.a !== arrival.n) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const kind = data.kind;
|
|
77
|
+
if (!CLIENT_KINDS.has(kind) || arrival.sent.has(kind)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Spent before it is checked further: a bad one costs its sender the kind.
|
|
81
|
+
arrival.sent.add(kind);
|
|
82
|
+
if (!h.players.get(playerId)?.arrived || !h.session?.players.some((p) => p.playerId === playerId) || !h.sim?.players.has(playerId)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (kind !== 'prompt') {
|
|
86
|
+
if (own(data, ['k', 'kind', 'a'])) {
|
|
87
|
+
emit(h, playerId, { kind });
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const door = data.door;
|
|
92
|
+
if (own(data, ['k', 'kind', 'a', 'door']) && typeof door === 'string' && doorIds().includes(door)) {
|
|
93
|
+
emit(h, playerId, { kind: 'prompt', door });
|
|
94
|
+
}
|
|
95
|
+
} catch {
|
|
96
|
+
// Refused wire data, including throwing accessors, is silent.
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// A retained rehello or resume (a reloaded page, a rejoined socket) is not an
|
|
101
|
+
// arrival: it is told the current arrival's number, what of its window is
|
|
102
|
+
// left and the kinds already spent, so it can say what is left and nothing
|
|
103
|
+
// more. Neither the window nor the allowance starts again.
|
|
104
|
+
export function replay(h, playerId) {
|
|
105
|
+
const arrival = on(h) ? h.signalArrivals?.get(playerId) : null;
|
|
106
|
+
const left = arrival ? WINDOW_MS - (Date.now() - arrival.at) : 0;
|
|
107
|
+
if (left <= 0 || arrival.sent.size >= CLIENT_KINDS.size) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
h.session?.send(playerId, { k: 'hub-signals', n: arrival.n, left, sent: [...arrival.sent] });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function forget(h, playerId) {
|
|
114
|
+
h.signalArrivals?.delete(playerId);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// `hub.pad(door, playerIds)`: who is on `door`'s pad now that was not before.
|
|
118
|
+
export function pad(h, door, before, on) {
|
|
119
|
+
for (const playerId of on) {
|
|
120
|
+
if (typeof playerId === 'string' && h.players.get(playerId)?.arrived && !before?.has(playerId)) {
|
|
121
|
+
emit(h, playerId, { kind: 'pad', door });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -5,6 +5,7 @@ import { kitBackNeeded } from '../client/backVisibility.js';
|
|
|
5
5
|
import { cancelArrivalShot, faceArrivalCamera } from '../client/arrivalCamera.js';
|
|
6
6
|
import { makeDoorErrors } from '../client/doorErrors.js';
|
|
7
7
|
import { makeVisibility } from '../client/visibility.js';
|
|
8
|
+
import { makeSignals } from '../client/signals.js';
|
|
8
9
|
import { makeInvites } from '../client/invites.js';
|
|
9
10
|
import { makeHubEntry, planHubEntry } from '../client/hubEntry.js';
|
|
10
11
|
import { makeHostGo } from '../client/hostGo.js';
|
|
@@ -856,6 +857,13 @@ class HubSystem {
|
|
|
856
857
|
delete this.companionTappedUntil;
|
|
857
858
|
}
|
|
858
859
|
this.drawChrome(scene, local, now);
|
|
860
|
+
// v1.221: first-input signals, only for an arrival the place's `signal`
|
|
861
|
+
// hook hears (its `hub-arrived` carried a number).
|
|
862
|
+
if (Hub.hub.signalArrival || this.signals) {
|
|
863
|
+
this.signals ??= makeSignals();
|
|
864
|
+
this.signals.frame(mp.net ?? null, this.trip ? null : Hub.hub.signalArrival, now,
|
|
865
|
+
{ keys: scene.keys, stick: scene.moveInput, prompt: this.signalDoor });
|
|
866
|
+
}
|
|
859
867
|
if (Hub.hub.place?.actions === true || Hub.hub.place?.anonymousEntry === true) {
|
|
860
868
|
this.actionsDrawn = true;
|
|
861
869
|
const hud = Hub.hub.hudMe ?? Hub.hub.hud;
|
|
@@ -3865,6 +3873,10 @@ class HubSystem {
|
|
|
3865
3873
|
drawChrome(scene, local, now) {
|
|
3866
3874
|
const chrome = this.chrome;
|
|
3867
3875
|
const place = Hub.hub.place;
|
|
3876
|
+
// v1.221: a door whose prompt is drawn this frame, while the arrival's
|
|
3877
|
+
// first prompt is still to be said (first-input signals).
|
|
3878
|
+
this.signalDoor = null;
|
|
3879
|
+
const wantsPrompt = this.signals?.wantsPrompt(Hub.hub.signalArrival) === true;
|
|
3868
3880
|
const idle = !this.trip;
|
|
3869
3881
|
const tickets = scene.persistent.hubTickets;
|
|
3870
3882
|
const ticket = tickets[tickets.length - 1];
|
|
@@ -3895,7 +3907,11 @@ class HubSystem {
|
|
|
3895
3907
|
const askVisible = town && !this.askInput && !this.menuInput && !this.actionInput && this.decor?.opened() !== true &&
|
|
3896
3908
|
chrome.askShowable?.() !== false;
|
|
3897
3909
|
const ask = askVisible ? this.ask(now) : null;
|
|
3898
|
-
|
|
3910
|
+
const shownAsk = askVisible ? this.askSlot.display(ask, askAt, askPads, now) : null;
|
|
3911
|
+
chrome.setAsk?.(shownAsk);
|
|
3912
|
+
if (wantsPrompt && typeof shownAsk?.door === 'string') {
|
|
3913
|
+
this.signalDoor = shownAsk.door;
|
|
3914
|
+
}
|
|
3899
3915
|
this.retireExpiredAsk(ask);
|
|
3900
3916
|
this.startBeside(scene, local, town, now);
|
|
3901
3917
|
// A friend or party member went through a door: say so, and offer to follow.
|
|
@@ -4347,8 +4363,11 @@ class HubSystem {
|
|
|
4347
4363
|
context: engine.hubPadContext, ring: engine.hubPadRing, spawn: engine.hubSpawnRing };
|
|
4348
4364
|
}
|
|
4349
4365
|
const selfId = scene.multiplayer?.net?.selfId?.();
|
|
4350
|
-
this.padReadability.frame(scene.actors, Hub.hub.hidden, local?.components.Transform, Boolean(this.trip),
|
|
4366
|
+
const captioned = this.padReadability.frame(scene.actors, Hub.hub.hidden, local?.components.Transform, Boolean(this.trip),
|
|
4351
4367
|
this.carded || this.decor?.opened() === true, selfId != null && Hub.hub.guests?.has?.(selfId) === true);
|
|
4368
|
+
if (captioned && !this.signalDoor && this.signals?.wantsPrompt(Hub.hub.signalArrival)) {
|
|
4369
|
+
this.signalDoor = captioned;
|
|
4370
|
+
}
|
|
4352
4371
|
}
|
|
4353
4372
|
|
|
4354
4373
|
// A town's world labels under `hub.labels: "near"` (v1.43): the plate and
|
|
@@ -228,6 +228,7 @@ of any of these. Every hook gets `hub`, the place's context, first:
|
|
|
228
228
|
| `sit(hub, playerId, seatId)` | v1.6, a place with `idle.seats`: a player asked to sit on seat actor `seatId` (§6). v1.158 `idle.expression` also calls this with `seatId: null` for sit-anywhere, independently of `idle.seats`. Return `false` to refuse; a hook that throws refuses |
|
|
229
229
|
| `action(hub, playerId, id)` | v1.74, a place with `actions: true`: an arrived, connected player pressed an id in their current offer, carrying a safe-integer `n` equal to that offer's current version (§9). Stale, removed, another player's, malformed or over-budget presses are silently dropped. Six presses/s with a burst of eight per player; dropped or refused presses spend tokens too. The return is ignored; throws and rejections are contained and logged once. Async hooks are neither serialised nor cancelled when the player leaves. |
|
|
230
230
|
| `menu(hub, playerId, id)` | v1.79, only with `menu: true`: an arrived, connected player picked an item in their current, last-sent menu with its safe-integer `n`, or closed the sheet (`id: "close"`). Stale, unknown, malformed and over-budget picks are dropped; readOnly refuses item picks but still delivers close. Six attempts/s, burst eight per player, including dropped presses. Return ignored; throws/rejections contained and logged once. Async hooks are neither serialised nor cancelled on leave. |
|
|
231
|
+
| `signal(hub, playerId, signal)` | v1.221, optional; defining it is the opt-in (no manifest key): one of a fixed vocabulary of a player's first moments (§12 "First-input signals"). From the client, each at most once per arrival and only within 120 s of it: `{ kind: 'move' }` (first walk input), `{ kind: 'jump' }` (first jump), `{ kind: 'prompt', door }` (the first door prompt shown: a question card offering a door, or a door pad's `hubPadContext` caption). From the kit, every time: `{ kind: 'talk', npc }` (a conversation opened by the Talk button or Act; `npc` is the NPC's actor id, or `'companion'` for the player's own companion), `{ kind: 'press', door }` (the player was put at a door they asked for: the Doors list's or a question card's Go, a People row, a party Go or Go-yes, a friend's House) and `{ kind: 'pad', door }` (the place's `hub.pad` first names them on that door's pad). `signal` is a fresh frozen object; no field is free text. Called after the kit's own work for the event; the return value is ignored, and a hook that throws or rejects is logged once and changes nothing. A kit older than v1.221 never calls it |
|
|
231
232
|
| `answer(hub, playerId, id, text)` | v1.75, only in a place with `ask: true`: that arrived, connected player answered their last-sent and still-current prompt; `text` is the exact string they typed, or `null` for Cancel (§9). The prompt is consumed and its close queued before the hook runs. Refused text on a current id/version consumes the prompt and calls the hook with null; it is never passed on. Two attempts/s, burst four per player; stale, malformed, oversized and dropped messages spend tokens too. Return ignored; throws and rejections contained and logged once without the text or error details. A place must never show what a player typed to another player. |
|
|
232
233
|
| `decor(hub, playerId, op)` | v1.67, a place with `decor`: an offered button or an open catalogue's validated edit (§10 Decorating). The deck checks ownership, stock and collisions and applies the edit; the kit moves or spawns nothing |
|
|
233
234
|
| `ballot(hub, playerId, { face, line, option, mode })` | v1.68, a place with `ballot`: a player tapped the choice card (§6). `face` a player id on their card or null, `line` a manifest line id or null, `option` an option id of the card or null, `mode` the card's mode then. The kit has already checked it against the card that player was last sent and limited it; the hook decides what it means (a line for the card's `feed`, a vote to count). Its return is ignored; a hook that throws is logged |
|
|
@@ -3696,6 +3697,64 @@ place never keeps a stale hidden or visible. A place may pause its own guidance
|
|
|
3696
3697
|
visible. This does not itself reconnect, arrive, leave or change progression;
|
|
3697
3698
|
the existing `resume` hook remains independent.
|
|
3698
3699
|
|
|
3700
|
+
### First-input signals (v1.221, opt-in by hook)
|
|
3701
|
+
|
|
3702
|
+
A place whose module exports a `signal` hook (§4) opts in; there is no
|
|
3703
|
+
manifest key, and an older kit simply never calls the hook. On each genuine
|
|
3704
|
+
arrival there (the arrival the place's `arrive` hook hears, not a rehello or a
|
|
3705
|
+
retained resume) the kit numbers the arrival and adds it to that player's
|
|
3706
|
+
`hub-arrived` as `signals: <n>`. A place without the hook sends
|
|
3707
|
+
`hub-arrived` exactly as before, and its clients send nothing.
|
|
3708
|
+
|
|
3709
|
+
For such an arrival, and only within 120 s of it, the client sends each of
|
|
3710
|
+
these at most once:
|
|
3711
|
+
|
|
3712
|
+
- `{ k: 'hub-signal', kind: 'move', a }`: the first walk input (a walk key,
|
|
3713
|
+
or the drag stick past 0.15);
|
|
3714
|
+
- `{ k: 'hub-signal', kind: 'jump', a }`: the first jump (Space, a tap the
|
|
3715
|
+
Player behavior takes, or Act's Jump);
|
|
3716
|
+
- `{ k: 'hub-signal', kind: 'prompt', a, door }`: the first door prompt
|
|
3717
|
+
shown, which is a question card that offers a door (`again`, a friend's
|
|
3718
|
+
`play`, Your games) or a door pad's caption (`engine.hubPadContext`) once
|
|
3719
|
+
the chrome has actually drawn it visible (not behind an open panel, not
|
|
3720
|
+
left unplaced). A party's
|
|
3721
|
+
proposal card names no door and is not one. A Town's pad words drawn as
|
|
3722
|
+
world labels are not a prompt either: the kit does not watch labels. A
|
|
3723
|
+
Town sees a player step onto a pad as `pad` below.
|
|
3724
|
+
|
|
3725
|
+
Keys typed into a text field count as neither a walk nor a jump. A signal is
|
|
3726
|
+
only marked sent once it went out on a connected socket during that arrival;
|
|
3727
|
+
once all three are sent or the 120 s are over, the client's per-frame check is
|
|
3728
|
+
one comparison. `a` is the arrival number the client was armed with.
|
|
3729
|
+
|
|
3730
|
+
A retained rehello or resume (a rejoined socket, or a page reloaded onto a
|
|
3731
|
+
retained body) is not an arrival. While the current arrival has window and
|
|
3732
|
+
kinds left, the server answers it with `{ k: 'hub-signals', n, left, sent }`:
|
|
3733
|
+
the same arrival number, the milliseconds left of its window and the kinds
|
|
3734
|
+
already spent. The client arms from that and says only what is left; neither
|
|
3735
|
+
the window nor the allowance starts again.
|
|
3736
|
+
|
|
3737
|
+
The server takes each from a present sender whose current arrival is still in
|
|
3738
|
+
its 120 s, named by the session and never by the payload, at most once per kind
|
|
3739
|
+
per arrival. A signal whose `a` is not the current arrival's number (one sent
|
|
3740
|
+
from an earlier arrival's record across a rejoin) is dropped before it spends
|
|
3741
|
+
anything; the once check comes next, before any door lookup, so a repeat costs
|
|
3742
|
+
one lookup. `move` and `jump` carry no other field; `prompt` must name one of the
|
|
3743
|
+
place's doors. Anything else is ignored silently. It is heard during a
|
|
3744
|
+
progress read too, as telemetry.
|
|
3745
|
+
|
|
3746
|
+
The kit adds three of its own, on every occurrence: `talk` when a conversation
|
|
3747
|
+
opens (`hub-npc-open`, or Act's Talk), `press` once it has put a player at a
|
|
3748
|
+
door they asked for (a door jump, a party Go or Go-yes, a friend's House
|
|
3749
|
+
visit), and `pad` when `hub.pad` first names a player on a door's pad. The hook
|
|
3750
|
+
runs after the kit's own work for that event.
|
|
3751
|
+
|
|
3752
|
+
Limits. A Town's pad words drawn as world labels are not a `prompt`; party
|
|
3753
|
+
proposals name no door, so their card is not one either. `talk`, `press` and
|
|
3754
|
+
`pad` are the server's own and fire every time, with no window or once rule; a
|
|
3755
|
+
place that keeps a bounded trace (the Town keeps 120 s) keeps only its own
|
|
3756
|
+
window of them. `move`, `jump` and `prompt` are best-effort: once per arrival,
|
|
3757
|
+
and lost if the socket drops while one is in flight.
|
|
3699
3758
|
|
|
3700
3759
|
A first home unlock (v1.70, §11) sends private `{ k: 'hub-home-unlock' }`
|
|
3701
3760
|
to its player only, announcing "Sent to your house". It carries no item and
|
|
@@ -5312,6 +5371,7 @@ a deck written before them remains valid.
|
|
|
5312
5371
|
|
|
5313
5372
|
| date | change |
|
|
5314
5373
|
| --- | --- |
|
|
5374
|
+
| 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. |
|
|
5315
5375
|
| 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. |
|
|
5316
5376
|
| 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. |
|
|
5317
5377
|
| 2026-11-17 (v1.218) | Kit-internal, server only, no deck-facing key or API and no wire change: §5 two bodies never start on one spot. A body admitted with no pose where another body takes the scene spawn or the slot its lone arrival would take starts where that arrival will put it (the arrival slot if free, else the free spot beside it; one helper decides both) before its WORLD goes out, so that WORLD is the one placement its client makes, at once; arriving alone it stays there while the spot is still free, and a group with such a member takes the row's slots in the order its members stand along it. An arrival slot (an arrival, and the arrival a fall or a Stuck? unstick puts a player at) or stored pose (cold `resumePose`, arrival pose, retained visit) that another body takes is likewise stepped off on every place, not only on authored floors (`ground.none: true`); a free slot or pose is used exactly. A body takes a spot when it is nearer than two radii and overlaps it in height (one on a floor above or below does not), and only while its player is on the roster (real-time admits a joiner before it removes the bodies of players who left that tick). A group row's later slots are held where a body would stand in them. The search uses the place's own body size and treats a spot past the ground slab's edge (`ground.half`, 100 m by default) as unsupported unless an authored solid holds it; when every candidate fails the slot is shared, as before. Ground-backed places (the Town) kept the spawn for everyone, so two lone joiners stood on exactly the same point; on each client the two capsules were coaxial, Rapier pushed the local one into the ground under the other's avatar, and it could not walk until one left (Nov 17 Market check, reproduced locally). A stepped-off cold restore still reaches its client as the restore always has. Tests: `test-placeat-server` stepoff, arrivalFree and arrivalTaken (WORLD before hello, reports and corrections on: the client moves once), restoreFree, restoreOccupied; `test-standing` slab edge, floors, a leaver on the same tick and an elevated row, `test-rehello` and `test-stuck` updated; physics-3d `test-coaxial-escape`. |
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"precheck": "node scripts/test-back-visibility.mjs && node scripts/test-landscape-layout.mjs && node scripts/test-safe-layout.mjs && node scripts/test-safe-caption.mjs && node scripts/test-safe-prompt.mjs && node scripts/test-safe-act.mjs && node scripts/test-action-observers.mjs && node scripts/test-crowd-names.mjs && node scripts/test-default-environment.mjs && node scripts/test-default-environment-root.mjs",
|
|
8
|
-
"check": "eslint . && npm run test:anonymous-entry && node scripts/test-manifest.mjs && node scripts/test-push-visit.mjs && node scripts/test-act.mjs && node scripts/test-act-client.mjs && node scripts/test-act-core.mjs && node scripts/test-act-gate.mjs && node scripts/test-loading-cover.mjs && node scripts/test-frame-batch.mjs && node scripts/test-invites.mjs && node scripts/test-invites-client.mjs && node scripts/test-analytics.mjs && node scripts/test-device-class.mjs && node scripts/test-door-analytics.mjs && node scripts/test-fps-telemetry.mjs && node scripts/test-load-abandon.mjs && node scripts/test-track-queue.mjs && node scripts/test-build.mjs && node scripts/test-decor.mjs && node scripts/test-actions.mjs && node scripts/test-resume-action-order.mjs && node scripts/test-actions-client.mjs && node scripts/test-action-layout.mjs && node scripts/test-ask-slot.mjs && node scripts/test-placement-cache.mjs && node scripts/test-ask.mjs && node scripts/test-ask-client.mjs && node scripts/test-menu.mjs && node scripts/test-held-offers.mjs && node scripts/test-menu-client.mjs && node scripts/test-companion.mjs && node scripts/test-companion-chat.mjs && node scripts/test-companion-client.mjs && node scripts/test-visibility.mjs && node scripts/test-rehello.mjs && node scripts/test-rejoin-yaw.mjs && node scripts/test-resync.mjs && node scripts/test-writer-lease.mjs && node scripts/test-writer-lease-server.mjs && node scripts/test-resume-pose.mjs && node scripts/test-resume-held.mjs && node scripts/test-arrival-pose.mjs && node scripts/test-arrival-pose-server.mjs && node scripts/test-arrival-pose-server.mjs clinic && node scripts/test-arrival-pose-server.mjs cove && node scripts/test-arrival-pose-server.mjs fishing && node scripts/test-arrival-pose-server.mjs plot && node scripts/test-arrival-pose-server.mjs runway && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs clinic && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs cove && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs fishing && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs plot && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs runway && POSE_REPLACE=1 POSE_PLAIN=1 POSE_RESULT=1 node scripts/test-arrival-pose-server.mjs && POSE_LINE=1 node scripts/test-arrival-pose-server.mjs && node scripts/test-resume-pose-server.mjs && node scripts/test-placeat-server.mjs && node scripts/test-resume-pose-server.mjs same-layer && node scripts/test-progress-reset.mjs && node scripts/test-decor-client.mjs && node scripts/test-yours.mjs && node scripts/test-yours-chrome.mjs && node scripts/test-npcs.mjs && node scripts/test-avatar.mjs && node scripts/test-avatar-colors.mjs && node scripts/test-avatar-models.mjs && node scripts/test-avatar-wire.mjs && node scripts/test-avatar-share.mjs && node scripts/test-far-avatars.mjs && node scripts/test-avatar-cap.mjs && node scripts/test-picker.mjs && node scripts/test-friend-bests.mjs && node scripts/test-hub-ops.mjs && node scripts/test-storage-limit.mjs && node scripts/test-wallet.mjs && node scripts/test-hub-leaving.mjs && node scripts/test-standing.mjs && node scripts/test-observed.mjs && node scripts/test-actors.mjs && node scripts/test-grab.mjs && node scripts/test-grab-client.mjs && node scripts/test-grab-orbit.mjs && node scripts/test-idle.mjs && node scripts/test-car.mjs && node scripts/test-vehicle.mjs && node scripts/test-vehicle-client.mjs && node scripts/test-disguise.mjs && node scripts/test-town-day.mjs && node scripts/test-disguise-client.mjs && node scripts/test-emote-bubble.mjs && node scripts/test-emote-wheel.mjs && node scripts/test-shot.mjs && node scripts/test-vis.mjs && node scripts/test-keys.mjs && node scripts/test-attention.mjs && node scripts/test-hub-trip.mjs && node scripts/test-hub-entry.mjs && node scripts/test-host-go.mjs && node scripts/test-no-trips.mjs && node scripts/test-pack.mjs && node scripts/test-interest.mjs && node scripts/test-relations-among.mjs && node scripts/test-relations-refresh.mjs && node scripts/test-fresh-friends.mjs && node scripts/test-cells.mjs && node scripts/test-interest-cells.mjs && node scripts/test-interest-cap.mjs && node scripts/test-object-entry.mjs && node scripts/test-interest-client.mjs && node scripts/test-blocks.mjs && node scripts/test-hub-idle.mjs && node scripts/test-ban-join.mjs && node scripts/test-door.mjs && node scripts/test-door-stay.mjs && node scripts/test-door-stay-client.mjs && node scripts/test-door-jump.mjs && node scripts/test-together.mjs && node scripts/test-hub-controls.mjs && node scripts/test-party.mjs && node scripts/test-say.mjs && node scripts/test-ballot.mjs && node scripts/test-chat.mjs && node scripts/test-no-forms.mjs && node scripts/test-classic.mjs && node scripts/test-actor-budget.mjs && node scripts/test-quality.mjs && node scripts/test-high-only.mjs && node scripts/test-tiers.mjs && node scripts/test-tiers-render.mjs && node scripts/test-tier-cells.mjs && node scripts/test-hats.mjs && node scripts/test-try-on.mjs && node scripts/test-replay.mjs && node scripts/test-replay-client.mjs && node scripts/test-role.mjs && node scripts/test-role-client.mjs && node scripts/test-hold-show.mjs && node scripts/test-hold-show-client.mjs && node scripts/test-earned.mjs && node scripts/test-earned-client.mjs && node scripts/test-celebrate.mjs && node scripts/test-celebrate-client.mjs && node scripts/test-spin.mjs && node scripts/test-hud-clear.mjs && node scripts/test-labels.mjs && node scripts/test-world-labels.mjs && node scripts/test-pad-occupancy.mjs && node scripts/test-pad-cues.mjs && node scripts/test-stuck.mjs && node scripts/test-toast-band.mjs && node scripts/test-soundscape.mjs && node scripts/test-weakest-tier.mjs && node scripts/test-hud-rate.mjs && node scripts/test-ui-tree.mjs && node scripts/test-hud-surface.mjs && node scripts/test-talk-surface.mjs && node scripts/test-action-rail-surface.mjs && node scripts/test-dock-surface.mjs && node scripts/test-ballot-surface.mjs && node scripts/test-menu-surface.mjs && node scripts/test-emote-surface.mjs && node scripts/test-quick-chat-surface.mjs && node scripts/test-text-ask-surface.mjs && node scripts/test-stuck-surface.mjs && node scripts/test-sound-surface.mjs && node scripts/test-ask-surface.mjs && node scripts/test-picker-surface.mjs && node scripts/test-corner-surface.mjs && node scripts/test-apply-deck.mjs && node tools/hubScene/test/export-fixture.mjs && node --test tools/hubScene/test/upload.test.mjs && node --input-type=module -e \"const { bundleProject } = await import('../../cli/dist/bundle.js'); await bundleProject('.');\"",
|
|
8
|
+
"check": "eslint . && npm run test:anonymous-entry && node scripts/test-manifest.mjs && node scripts/test-push-visit.mjs && node scripts/test-act.mjs && node scripts/test-act-client.mjs && node scripts/test-act-core.mjs && node scripts/test-act-gate.mjs && node scripts/test-loading-cover.mjs && node scripts/test-frame-batch.mjs && node scripts/test-invites.mjs && node scripts/test-invites-client.mjs && node scripts/test-analytics.mjs && node scripts/test-device-class.mjs && node scripts/test-door-analytics.mjs && node scripts/test-fps-telemetry.mjs && node scripts/test-load-abandon.mjs && node scripts/test-track-queue.mjs && node scripts/test-build.mjs && node scripts/test-decor.mjs && node scripts/test-actions.mjs && node scripts/test-resume-action-order.mjs && node scripts/test-actions-client.mjs && node scripts/test-action-layout.mjs && node scripts/test-ask-slot.mjs && node scripts/test-placement-cache.mjs && node scripts/test-ask.mjs && node scripts/test-ask-client.mjs && node scripts/test-menu.mjs && node scripts/test-held-offers.mjs && node scripts/test-menu-client.mjs && node scripts/test-companion.mjs && node scripts/test-companion-chat.mjs && node scripts/test-companion-client.mjs && node scripts/test-visibility.mjs && node scripts/test-signals.mjs && node scripts/test-rehello.mjs && node scripts/test-rejoin-yaw.mjs && node scripts/test-resync.mjs && node scripts/test-writer-lease.mjs && node scripts/test-writer-lease-server.mjs && node scripts/test-resume-pose.mjs && node scripts/test-resume-held.mjs && node scripts/test-arrival-pose.mjs && node scripts/test-arrival-pose-server.mjs && node scripts/test-arrival-pose-server.mjs clinic && node scripts/test-arrival-pose-server.mjs cove && node scripts/test-arrival-pose-server.mjs fishing && node scripts/test-arrival-pose-server.mjs plot && node scripts/test-arrival-pose-server.mjs runway && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs clinic && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs cove && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs fishing && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs plot && POSE_REPLACE=1 node scripts/test-arrival-pose-server.mjs runway && POSE_REPLACE=1 POSE_PLAIN=1 POSE_RESULT=1 node scripts/test-arrival-pose-server.mjs && POSE_LINE=1 node scripts/test-arrival-pose-server.mjs && node scripts/test-resume-pose-server.mjs && node scripts/test-placeat-server.mjs && node scripts/test-resume-pose-server.mjs same-layer && node scripts/test-progress-reset.mjs && node scripts/test-decor-client.mjs && node scripts/test-yours.mjs && node scripts/test-yours-chrome.mjs && node scripts/test-npcs.mjs && node scripts/test-avatar.mjs && node scripts/test-avatar-colors.mjs && node scripts/test-avatar-models.mjs && node scripts/test-avatar-wire.mjs && node scripts/test-avatar-share.mjs && node scripts/test-far-avatars.mjs && node scripts/test-avatar-cap.mjs && node scripts/test-picker.mjs && node scripts/test-friend-bests.mjs && node scripts/test-hub-ops.mjs && node scripts/test-storage-limit.mjs && node scripts/test-wallet.mjs && node scripts/test-hub-leaving.mjs && node scripts/test-standing.mjs && node scripts/test-observed.mjs && node scripts/test-actors.mjs && node scripts/test-grab.mjs && node scripts/test-grab-client.mjs && node scripts/test-grab-orbit.mjs && node scripts/test-idle.mjs && node scripts/test-car.mjs && node scripts/test-vehicle.mjs && node scripts/test-vehicle-client.mjs && node scripts/test-disguise.mjs && node scripts/test-town-day.mjs && node scripts/test-disguise-client.mjs && node scripts/test-emote-bubble.mjs && node scripts/test-emote-wheel.mjs && node scripts/test-shot.mjs && node scripts/test-vis.mjs && node scripts/test-keys.mjs && node scripts/test-attention.mjs && node scripts/test-hub-trip.mjs && node scripts/test-hub-entry.mjs && node scripts/test-host-go.mjs && node scripts/test-no-trips.mjs && node scripts/test-pack.mjs && node scripts/test-interest.mjs && node scripts/test-relations-among.mjs && node scripts/test-relations-refresh.mjs && node scripts/test-fresh-friends.mjs && node scripts/test-cells.mjs && node scripts/test-interest-cells.mjs && node scripts/test-interest-cap.mjs && node scripts/test-object-entry.mjs && node scripts/test-interest-client.mjs && node scripts/test-blocks.mjs && node scripts/test-hub-idle.mjs && node scripts/test-ban-join.mjs && node scripts/test-door.mjs && node scripts/test-door-stay.mjs && node scripts/test-door-stay-client.mjs && node scripts/test-door-jump.mjs && node scripts/test-together.mjs && node scripts/test-hub-controls.mjs && node scripts/test-party.mjs && node scripts/test-say.mjs && node scripts/test-ballot.mjs && node scripts/test-chat.mjs && node scripts/test-no-forms.mjs && node scripts/test-classic.mjs && node scripts/test-actor-budget.mjs && node scripts/test-quality.mjs && node scripts/test-high-only.mjs && node scripts/test-tiers.mjs && node scripts/test-tiers-render.mjs && node scripts/test-tier-cells.mjs && node scripts/test-hats.mjs && node scripts/test-try-on.mjs && node scripts/test-replay.mjs && node scripts/test-replay-client.mjs && node scripts/test-role.mjs && node scripts/test-role-client.mjs && node scripts/test-hold-show.mjs && node scripts/test-hold-show-client.mjs && node scripts/test-earned.mjs && node scripts/test-earned-client.mjs && node scripts/test-celebrate.mjs && node scripts/test-celebrate-client.mjs && node scripts/test-spin.mjs && node scripts/test-hud-clear.mjs && node scripts/test-labels.mjs && node scripts/test-world-labels.mjs && node scripts/test-pad-occupancy.mjs && node scripts/test-pad-cues.mjs && node scripts/test-stuck.mjs && node scripts/test-toast-band.mjs && node scripts/test-soundscape.mjs && node scripts/test-weakest-tier.mjs && node scripts/test-hud-rate.mjs && node scripts/test-ui-tree.mjs && node scripts/test-hud-surface.mjs && node scripts/test-talk-surface.mjs && node scripts/test-action-rail-surface.mjs && node scripts/test-dock-surface.mjs && node scripts/test-ballot-surface.mjs && node scripts/test-menu-surface.mjs && node scripts/test-emote-surface.mjs && node scripts/test-quick-chat-surface.mjs && node scripts/test-text-ask-surface.mjs && node scripts/test-stuck-surface.mjs && node scripts/test-sound-surface.mjs && node scripts/test-ask-surface.mjs && node scripts/test-picker-surface.mjs && node scripts/test-corner-surface.mjs && node scripts/test-apply-deck.mjs && node tools/hubScene/test/export-fixture.mjs && node --test tools/hubScene/test/upload.test.mjs && node --input-type=module -e \"const { bundleProject } = await import('../../cli/dist/bundle.js'); await bundleProject('.');\"",
|
|
9
9
|
"format": "prettier --write \"code/**/*.js\" \"scripts/**/*.mjs\" castle.json package.json",
|
|
10
10
|
"test:grab-carry": "node scripts/test-grab-orbit.mjs",
|
|
11
11
|
"test:anonymous-entry": "node scripts/test-signin-client.mjs && node scripts/test-anonymous-entry.mjs"
|
|
@@ -256,15 +256,18 @@ caption.size = { w: 180, h: 70 };
|
|
|
256
256
|
const obstacle = document.createElement('div');
|
|
257
257
|
obstacle.rect = { left: 0, right: 844, top: 0, bottom: 390 };
|
|
258
258
|
chrome.safeSurface('full-screen-hud', obstacle, 'text');
|
|
259
|
-
|
|
259
|
+
// v1.221: setPadContext says whether the caption is drawn and visible.
|
|
260
|
+
assert.equal(chrome.setPadContext(text), false, 'an unplaced caption is not shown');
|
|
260
261
|
assert.equal(caption.style.visibility, 'hidden', 'no slot suppresses the caption');
|
|
261
262
|
chrome.safeSurface('full-screen-hud', null);
|
|
262
|
-
chrome.setPadContext(text);
|
|
263
|
+
assert.equal(chrome.setPadContext(text), true, 'a placed caption is shown');
|
|
263
264
|
assert.equal(caption.style.visibility, '');
|
|
265
|
+
assert.equal(chrome.setPadContext(null), false);
|
|
266
|
+
chrome.setPadContext(text);
|
|
264
267
|
const panel = document.createElement('div');
|
|
265
268
|
panel.rect = { left: 0, right: 100, top: 0, bottom: 100 };
|
|
266
269
|
chrome.safeSurface('invite-dialog', panel, 'card');
|
|
267
|
-
chrome.setPadContext(text);
|
|
270
|
+
assert.equal(chrome.setPadContext(text), false, 'a caption behind an open panel is not shown');
|
|
268
271
|
assert.equal(caption.style.visibility, 'hidden', 'any registered open panel hides the caption');
|
|
269
272
|
chrome.safeSurface('invite-dialog', null);
|
|
270
273
|
// v1.217: an open cabinet board hides the caption and is opaque; the chip
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
// v1.221: first-input signals cross the real client helper / layer message
|
|
2
|
+
// boundary (contract §4 `signal`, §12 "First-input signals").
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { register } from 'node:module';
|
|
5
|
+
|
|
6
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
7
|
+
export async function resolve(specifier, context, next) {
|
|
8
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: 'data:text/javascript,export const readScene = () => globalThis.__hubTestActors;', shortCircuit: true };
|
|
9
|
+
if (context.parentURL?.includes('/kits/base/sdk/') && specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
|
|
10
|
+
return next(specifier, context);
|
|
11
|
+
}
|
|
12
|
+
`)}`);
|
|
13
|
+
const { layer } = await import('../code/server/hub.js');
|
|
14
|
+
const Manifest = await import('../code/server/manifest.js');
|
|
15
|
+
const { makeSignals, signalReplay, walking, WINDOW_MS } = await import('../code/client/signals.js');
|
|
16
|
+
const { collectPadCues } = await import('../code/client/padCues.js');
|
|
17
|
+
const { makePadReadability } = await import('../code/client/padReadability.js');
|
|
18
|
+
|
|
19
|
+
const actors = [
|
|
20
|
+
{ id: 'player', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
21
|
+
{ id: 'door-gems', components: { HubDoor: { id: 'gems', to: 'deck:gems', title: 'Gem Rush' }, Transform: { x: 0, y: 1.4, z: -28 } } },
|
|
22
|
+
{ id: 'pad-gems', components: { HubPad: { door: 'gems', radius: 2 }, Transform: { x: 0, y: 0, z: -24 } } },
|
|
23
|
+
{ id: 'rowan', components: { HubNpc: { name: 'Rowan' }, Transform: { x: 1, y: 1, z: 0 } } },
|
|
24
|
+
];
|
|
25
|
+
const players = [
|
|
26
|
+
{ playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
|
|
27
|
+
{ playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false },
|
|
28
|
+
];
|
|
29
|
+
const json = (keys = {}) => ({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Town', ...keys } });
|
|
30
|
+
const npcBody = { translation: () => ({ x: 1, y: 1, z: 0 }), setNextKinematicTranslation() {}, setNextKinematicRotation() {} };
|
|
31
|
+
const realNow = Date.now;
|
|
32
|
+
let clock = 1_800_000_000_000;
|
|
33
|
+
Date.now = () => clock;
|
|
34
|
+
function boot(options = {}) {
|
|
35
|
+
const sent = [], heard = [], messages = [], order = [];
|
|
36
|
+
let hub;
|
|
37
|
+
const hooks = {
|
|
38
|
+
ready(ctx) { hub = ctx; },
|
|
39
|
+
message(ctx, player, data) { messages.push([player.playerId, data]); },
|
|
40
|
+
...(options.hook === null ? {} : { signal: options.hook ?? ((ctx, id, signal) => { heard.push([id, signal]); order.push(`signal:${signal.kind}`); }) }),
|
|
41
|
+
};
|
|
42
|
+
globalThis.__hubTestActors = structuredClone(actors);
|
|
43
|
+
const server = layer(json(options.keys ?? {}), hooks, {}, () => true, () => null, null, { createBody: () => ({ setEnabled() {}, setNextKinematicTranslation() {}, setNextKinematicRotation() {} }), removeActor() {} });
|
|
44
|
+
const session = { sessionId: 'dev', players: [...players], hub: null, send(id, msg) { sent.push([id, structuredClone(msg)]); order.push(`send:${msg.k}`); }, broadcast(msg) { sent.push(['all', structuredClone(msg)]); } };
|
|
45
|
+
const world = { timeMs: 0, scenePath: 'scenes/main.scene', objects: new Map(), bodies: new Map([['rowan', npcBody]]), players: new Map(players.map((p) => [p.playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }])) };
|
|
46
|
+
server.sceneFor(session);
|
|
47
|
+
server.ready(world);
|
|
48
|
+
const say = (id, data) => server.message(session, { playerId: id }, data);
|
|
49
|
+
if (options.hello !== false) {
|
|
50
|
+
for (const id of ['p1', 'p2']) {say(id, { k: 'hub-hello', avatar: 0, party: 2 });}
|
|
51
|
+
server.place(world);
|
|
52
|
+
}
|
|
53
|
+
const tick = (ms = 50) => { world.timeMs += ms; server.place(world); server.step(world, []); };
|
|
54
|
+
const arrivedMsg = (id) => sent.filter(([to, m]) => to === id && m.k === 'hub-arrived').at(-1)?.[1];
|
|
55
|
+
// The arrival number this player's client holds now (hub-arrived or a replay).
|
|
56
|
+
const armed = (id) => {
|
|
57
|
+
const m = sent.filter(([to, msg]) => to === id && (msg.k === 'hub-arrived' || msg.k === 'hub-signals')).at(-1)?.[1];
|
|
58
|
+
return m?.k === 'hub-signals' ? m.n : m?.signals;
|
|
59
|
+
};
|
|
60
|
+
const sig = (id, kind, more = {}) => say(id, { k: 'hub-signal', kind, a: armed(id), ...more });
|
|
61
|
+
return { server, session, world, hub, sent, heard, messages, order, say, tick, arrivedMsg, armed, sig };
|
|
62
|
+
}
|
|
63
|
+
const kinds = (heard) => heard.map(([id, s]) => `${id}:${s.kind}${s.door ? `:${s.door}` : ''}${s.npc ? `:${s.npc}` : ''}`);
|
|
64
|
+
|
|
65
|
+
// No manifest key: `signals` stays unknown to the manifest, and a place
|
|
66
|
+
// without the hook sends `hub-arrived` exactly as before.
|
|
67
|
+
assert.ok(Manifest.readManifest(json({ signals: true })).errors.length > 0);
|
|
68
|
+
{
|
|
69
|
+
const on = boot(), off = boot({ hook: null });
|
|
70
|
+
assert.ok(Number.isSafeInteger(on.arrivedMsg('p1').signals));
|
|
71
|
+
assert.notEqual(on.arrivedMsg('p1').signals, on.arrivedMsg('p2').signals);
|
|
72
|
+
assert.deepEqual(off.arrivedMsg('p1'), { k: 'hub-arrived', facing: 0 });
|
|
73
|
+
assert.deepEqual(off.sent.filter(([, m]) => m.k !== 'hub-arrived'), on.sent.filter(([, m]) => m.k !== 'hub-arrived'));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Each client kind at most once per arrival, from a present sender only.
|
|
77
|
+
{
|
|
78
|
+
const r = boot();
|
|
79
|
+
for (let i = 0; i < 3; i++) {
|
|
80
|
+
r.sig('p1', 'move');
|
|
81
|
+
r.sig('p1', 'jump');
|
|
82
|
+
r.sig('p1', 'prompt', { door: 'gems' });
|
|
83
|
+
}
|
|
84
|
+
r.sig('p2', 'jump');
|
|
85
|
+
assert.deepEqual(kinds(r.heard), ['p1:move', 'p1:jump', 'p1:prompt:gems', 'p2:jump']);
|
|
86
|
+
assert.ok(Object.isFrozen(r.heard[0][1]));
|
|
87
|
+
const before = r.heard.length;
|
|
88
|
+
// Kit-only kinds, unknown kinds, a named other player and strangers do nothing.
|
|
89
|
+
for (const data of [{ kind: 'run' }, { kind: 'talk', npc: 'rowan' }, { kind: 'press', door: 'gems' }, { kind: 'pad', door: 'gems' }, { kind: ['move'] }, { kind: null }, {}]) {
|
|
90
|
+
r.say('p2', { k: 'hub-signal', a: r.armed('p2'), ...data });
|
|
91
|
+
}
|
|
92
|
+
r.sig('stranger', 'move');
|
|
93
|
+
r.say('p2', new Proxy({ k: 'hub-signal' }, { get(t, key) { if (key === 'kind') {throw Error('accessor');} return t[key]; } }));
|
|
94
|
+
assert.equal(r.heard.length, before);
|
|
95
|
+
// A bad payload spends its kind: no second try, no door scan.
|
|
96
|
+
r.sig('p2', 'move', { text: 'PRIVATE' }); r.sig('p2', 'move');
|
|
97
|
+
r.sig('p2', 'prompt', { door: 'nope' }); r.sig('p2', 'prompt', { door: 'gems' });
|
|
98
|
+
assert.equal(r.heard.length, before);
|
|
99
|
+
// [2] A rehello, an avatar change or a retained resume is not an arrival.
|
|
100
|
+
r.say('p1', { k: 'hub-hello', avatar: 1, again: true }); r.tick();
|
|
101
|
+
r.say('p1', { k: 'hub-hello', avatar: 0 }); r.tick();
|
|
102
|
+
r.say('p1', { k: 'hub-hello', avatar: 0, resume: true }); r.tick();
|
|
103
|
+
for (const kind of ['move', 'jump']) {r.sig('p1', kind);}
|
|
104
|
+
r.sig('p1', 'prompt', { door: 'gems' });
|
|
105
|
+
assert.equal(r.heard.length, before);
|
|
106
|
+
assert.equal(r.messages.length, 0, 'the kit consumes hub-signal');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// [2] The once check comes before any door lookup: repeats never scan doors.
|
|
110
|
+
{
|
|
111
|
+
const r = boot();
|
|
112
|
+
let scans = 0;
|
|
113
|
+
r.sig('p1', 'prompt', { door: 'gems' });
|
|
114
|
+
const fake = new Proxy({ k: 'hub-signal', kind: 'prompt', a: r.armed('p1'), door: 'gems' }, { get(target, key) { if (key === 'door') {scans++;} return target[key]; } });
|
|
115
|
+
for (let i = 0; i < 50; i++) {r.say('p1', fake);}
|
|
116
|
+
assert.equal(scans, 0);
|
|
117
|
+
assert.equal(r.heard.length, 1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Only within 120 s of the arrival; a new arrival starts again.
|
|
121
|
+
{
|
|
122
|
+
const r = boot();
|
|
123
|
+
clock += WINDOW_MS - 1;
|
|
124
|
+
r.sig('p1', 'move');
|
|
125
|
+
clock += 1;
|
|
126
|
+
r.sig('p1', 'jump');
|
|
127
|
+
r.sig('p2', 'move');
|
|
128
|
+
assert.deepEqual(kinds(r.heard), ['p1:move']);
|
|
129
|
+
// Leaving and arriving again is a new arrival with a new number.
|
|
130
|
+
const was = r.arrivedMsg('p1').signals;
|
|
131
|
+
const body = r.world.players.get('p1');
|
|
132
|
+
r.session.players = r.session.players.filter((p) => p.playerId !== 'p1');
|
|
133
|
+
r.world.players.delete('p1');
|
|
134
|
+
r.tick();
|
|
135
|
+
r.session.players = [...players];
|
|
136
|
+
r.world.players.set('p1', body);
|
|
137
|
+
r.say('p1', { k: 'hub-hello', avatar: 0, party: 1 }); r.tick(); r.tick(500);
|
|
138
|
+
const now = r.arrivedMsg('p1')?.signals;
|
|
139
|
+
assert.ok(Number.isSafeInteger(now) && now !== was, 'a fresh arrival is numbered again');
|
|
140
|
+
r.sig('p1', 'jump');
|
|
141
|
+
assert.deepEqual(kinds(r.heard), ['p1:move', 'p1:jump']);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// [round 2] A signal armed with an earlier arrival's number is dropped before
|
|
145
|
+
// it spends anything; the current arrival's own is taken.
|
|
146
|
+
{
|
|
147
|
+
const r = boot();
|
|
148
|
+
const old = r.armed('p1');
|
|
149
|
+
const body = r.world.players.get('p1');
|
|
150
|
+
r.session.players = r.session.players.filter((p) => p.playerId !== 'p1');
|
|
151
|
+
r.world.players.delete('p1');
|
|
152
|
+
r.tick();
|
|
153
|
+
r.session.players = [...players];
|
|
154
|
+
r.world.players.set('p1', body);
|
|
155
|
+
r.say('p1', { k: 'hub-hello', avatar: 0, party: 1 }); r.tick(); r.tick(500);
|
|
156
|
+
const now = r.armed('p1');
|
|
157
|
+
assert.notEqual(now, old);
|
|
158
|
+
r.say('p1', { k: 'hub-signal', kind: 'jump', a: old }); // in flight from the old record
|
|
159
|
+
r.say('p1', { k: 'hub-signal', kind: 'jump' }); // no number at all
|
|
160
|
+
r.say('p1', { k: 'hub-signal', kind: 'jump', a: String(now) });
|
|
161
|
+
assert.equal(r.heard.length, 0);
|
|
162
|
+
r.say('p1', { k: 'hub-signal', kind: 'jump', a: now });
|
|
163
|
+
assert.deepEqual(kinds(r.heard), ['p1:jump']);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// [round 2] A reloaded page on a retained body is told the same arrival, what
|
|
167
|
+
// is left of its window and what was spent; it says only what is left, and
|
|
168
|
+
// neither the window nor the allowance starts again.
|
|
169
|
+
{
|
|
170
|
+
const r = boot();
|
|
171
|
+
const n = r.armed('p1');
|
|
172
|
+
r.sig('p1', 'move');
|
|
173
|
+
clock += 30_000;
|
|
174
|
+
r.say('p1', { k: 'hub-hello', avatar: 0, party: 1 }); r.tick(); // a reload: a fresh page, same body
|
|
175
|
+
const replay = r.sent.filter(([to, m]) => to === 'p1' && m.k === 'hub-signals').at(-1)?.[1];
|
|
176
|
+
assert.deepEqual(replay, { k: 'hub-signals', n, left: WINDOW_MS - 30_000, sent: ['move'] });
|
|
177
|
+
assert.equal(r.arrivedMsg('p1').signals, n, 'no new arrival');
|
|
178
|
+
// The reloaded client, armed from the replay.
|
|
179
|
+
const page = makeSignals();
|
|
180
|
+
const arrival = signalReplay(replay, 5000);
|
|
181
|
+
assert.deepEqual(arrival, { n, at: 5000 - 30_000, sent: ['move'] });
|
|
182
|
+
page.frame({ send: (data) => r.say('p1', data) }, arrival, 5000, { keys: new Set(['KeyW', 'Space']), stick: null, prompt: null });
|
|
183
|
+
assert.deepEqual(kinds(r.heard), ['p1:move', 'p1:jump'], 'only what was left');
|
|
184
|
+
// A resume hello replays too, with the spent kinds; the window is not renewed.
|
|
185
|
+
clock += 89_999;
|
|
186
|
+
r.say('p1', { k: 'hub-hello', avatar: 0, resume: true }); r.tick();
|
|
187
|
+
const again = r.sent.filter(([to, m]) => to === 'p1' && m.k === 'hub-signals').at(-1)[1];
|
|
188
|
+
assert.deepEqual(again, { k: 'hub-signals', n, left: 1, sent: ['move', 'jump'] });
|
|
189
|
+
clock += 1;
|
|
190
|
+
r.sig('p1', 'prompt', { door: 'gems' });
|
|
191
|
+
assert.equal(r.heard.length, 2, 'the window ends when it always would');
|
|
192
|
+
// Past the window, or with everything spent, nothing is replayed.
|
|
193
|
+
const count = r.sent.filter(([, m]) => m.k === 'hub-signals').length;
|
|
194
|
+
r.say('p1', { k: 'hub-hello', avatar: 0, resume: true }); r.tick();
|
|
195
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, resume: true }); r.tick();
|
|
196
|
+
assert.equal(r.sent.filter(([, m]) => m.k === 'hub-signals').length, count);
|
|
197
|
+
const full = boot();
|
|
198
|
+
for (const kind of ['move', 'jump']) {full.sig('p1', kind);}
|
|
199
|
+
full.sig('p1', 'prompt', { door: 'gems' });
|
|
200
|
+
full.say('p1', { k: 'hub-hello', avatar: 0, resume: true }); full.tick();
|
|
201
|
+
assert.equal(full.sent.some(([, m]) => m.k === 'hub-signals'), false);
|
|
202
|
+
// An avatar change is not a reload.
|
|
203
|
+
const avatar = boot();
|
|
204
|
+
avatar.say('p1', { k: 'hub-hello', avatar: 1, again: true }); avatar.tick();
|
|
205
|
+
assert.equal(avatar.sent.some(([, m]) => m.k === 'hub-signals'), false);
|
|
206
|
+
// Malformed replays arm nothing.
|
|
207
|
+
for (const bad of [null, {}, { n: 1, left: 0, sent: [] }, { n: 1, left: WINDOW_MS + 1, sent: [] }, { n: '1', left: 5, sent: [] }, { n: 1, left: 5 }]) {
|
|
208
|
+
assert.equal(signalReplay(bad, 0), null);
|
|
209
|
+
}
|
|
210
|
+
assert.deepEqual(signalReplay({ n: 1, left: 5, sent: ['jump', 'talk', 7] }, 0).sent, ['jump']);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Before arrival nothing is heard.
|
|
214
|
+
{
|
|
215
|
+
const r = boot({ hello: false });
|
|
216
|
+
r.sig('p1', 'move');
|
|
217
|
+
r.say('p1', { k: 'hub-hello', avatar: 0, party: 1 });
|
|
218
|
+
r.sig('p1', 'move');
|
|
219
|
+
assert.equal(r.heard.length, 0);
|
|
220
|
+
r.tick();
|
|
221
|
+
r.sig('p1', 'move');
|
|
222
|
+
assert.deepEqual(kinds(r.heard), ['p1:move']);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// press after the jump's own work, from a door jump and a party Go / Go-yes;
|
|
226
|
+
// pad when newly counted; talk when a conversation opens.
|
|
227
|
+
{
|
|
228
|
+
const r = boot();
|
|
229
|
+
r.say('p1', { k: 'hub-door-jump', door: 'gems' });
|
|
230
|
+
assert.deepEqual(r.order.slice(-2), ['send:hub-jumped', 'signal:press'], 'the hook runs after the jump');
|
|
231
|
+
r.say('p1', { k: 'hub-door-jump', door: 'gems' }); // within a second: refused, so silent
|
|
232
|
+
r.say('p2', { k: 'hub-door-jump', door: 'nope' });
|
|
233
|
+
r.hub.pad('gems', ['p1']);
|
|
234
|
+
r.hub.pad('gems', ['p1', 'p2', 'ghost', 7]);
|
|
235
|
+
r.hub.pad('gems', ['p2']);
|
|
236
|
+
r.hub.pad('gems', ['p1', 'p2']);
|
|
237
|
+
r.say('p2', { k: 'hub-npc-open', npc: 'rowan' });
|
|
238
|
+
r.say('p2', { k: 'hub-npc-open', npc: 'nobody' });
|
|
239
|
+
assert.deepEqual(kinds(r.heard), ['p1:press:gems', 'p1:pad:gems', 'p2:pad:gems', 'p1:pad:gems', 'p2:talk:rowan']);
|
|
240
|
+
}
|
|
241
|
+
{
|
|
242
|
+
const r = boot();
|
|
243
|
+
const party = (id, data) => r.say(id, { k: 'hub-party', ...data });
|
|
244
|
+
party('p1', { op: 'invite', player: 'p2' }); r.tick();
|
|
245
|
+
party('p2', { op: 'accept', from: 'p1' }); r.tick();
|
|
246
|
+
party('p1', { op: 'go', door: 'gems' }); r.tick();
|
|
247
|
+
const proposal = r.sent.filter(([to, m]) => to === 'p2' && m.k === 'hub-party').at(-1)[1].proposal;
|
|
248
|
+
party('p2', { op: 'go-yes', id: proposal.id });
|
|
249
|
+
assert.deepEqual(kinds(r.heard), ['p1:press:gems', 'p2:press:gems']);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// A throwing or rejecting hook is logged once and never reaches the kit.
|
|
253
|
+
{
|
|
254
|
+
const warns = [];
|
|
255
|
+
const warn = console.warn;
|
|
256
|
+
console.warn = (line) => warns.push(String(line));
|
|
257
|
+
try {
|
|
258
|
+
const r = boot({ hook() { throw Error('PRIVATE'); } });
|
|
259
|
+
assert.doesNotThrow(() => r.sig('p1', 'move'));
|
|
260
|
+
assert.doesNotThrow(() => r.say('p1', { k: 'hub-door-jump', door: 'gems' }));
|
|
261
|
+
assert.doesNotThrow(() => r.hub.pad('gems', ['p1']));
|
|
262
|
+
assert.doesNotThrow(() => r.say('p2', { k: 'hub-npc-open', npc: 'rowan' }));
|
|
263
|
+
assert.ok(r.sent.some(([id, msg]) => id === 'p2' && msg.k === 'hub-npc' && msg.open === true), 'the conversation still opens');
|
|
264
|
+
assert.ok(r.sent.some(([id, msg]) => id === 'p1' && msg.k === 'hub-jumped'), 'the jump still happens');
|
|
265
|
+
const rejecting = boot({ hook: () => Promise.reject(Error('PRIVATE')) });
|
|
266
|
+
rejecting.sig('p1', 'jump');
|
|
267
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
268
|
+
assert.equal(warns.filter((line) => line.includes('signal hook failed')).length, 2, 'once per place');
|
|
269
|
+
assert.ok(warns.every((line) => !line.includes('PRIVATE')));
|
|
270
|
+
} finally {
|
|
271
|
+
console.warn = warn;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Without the hook: nothing is kept or called, and hub-signal is an unknown message.
|
|
276
|
+
{
|
|
277
|
+
const off = boot({ hook: null });
|
|
278
|
+
off.sig('p1', 'move');
|
|
279
|
+
off.say('p1', { k: 'hub-door-jump', door: 'gems' });
|
|
280
|
+
off.hub.pad('gems', ['p1']);
|
|
281
|
+
off.say('p2', { k: 'hub-npc-open', npc: 'rowan' });
|
|
282
|
+
assert.deepEqual(off.messages.map(([id, m]) => [id, m.k, m.kind]), [['p1', 'hub-signal', 'move']]);
|
|
283
|
+
assert.equal(off.sent.some(([, m]) => m.k === 'hub-signals'), false);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// The client helper.
|
|
287
|
+
{
|
|
288
|
+
assert.equal(walking(new Set(['KeyW']), null), true);
|
|
289
|
+
assert.equal(walking(new Set(['Space']), null), false);
|
|
290
|
+
assert.equal(walking(null, { active: true, x: 0.1, y: 0.1 }), false);
|
|
291
|
+
assert.equal(walking(null, { active: true, x: 0, y: -0.2 }), true);
|
|
292
|
+
assert.equal(walking(null, { active: false, x: 0, y: -1 }), false);
|
|
293
|
+
|
|
294
|
+
const out = [];
|
|
295
|
+
let state = 'connected', statusReads = 0;
|
|
296
|
+
const net = { send: (data) => out.push(data), status: () => { statusReads++; return { state }; } };
|
|
297
|
+
const keys = new Set();
|
|
298
|
+
let pending = false;
|
|
299
|
+
const stick = { active: false, x: 0, y: 0, consumeJump() { const had = pending; pending = false; return had; } };
|
|
300
|
+
const original = stick.consumeJump;
|
|
301
|
+
const s = makeSignals();
|
|
302
|
+
let t = 1000;
|
|
303
|
+
let arrival = { n: 1, at: t };
|
|
304
|
+
const frame = (o = {}) => s.frame(o.net ?? net, Object.hasOwn(o, 'arrival') ? o.arrival : arrival, o.now ?? t, { keys, stick, prompt: null, ...o });
|
|
305
|
+
// (b) No arrival number (no hook): nothing wrapped, nothing sent.
|
|
306
|
+
keys.add('KeyW');
|
|
307
|
+
frame({ arrival: null, prompt: 'gems' });
|
|
308
|
+
assert.equal(stick.consumeJump, original);
|
|
309
|
+
assert.equal(out.length, 0);
|
|
310
|
+
// [3] With the socket down nothing is marked sent; it goes once it is up.
|
|
311
|
+
state = 'reconnecting'; frame();
|
|
312
|
+
assert.equal(out.length, 0);
|
|
313
|
+
state = 'connected'; frame(); frame();
|
|
314
|
+
assert.deepEqual(out, [{ k: 'hub-signal', kind: 'move', a: 1 }]);
|
|
315
|
+
// A tap the Player behavior takes is a jump, once.
|
|
316
|
+
pending = true;
|
|
317
|
+
assert.equal(stick.consumeJump(), true, 'the wrapper hands the tap on');
|
|
318
|
+
frame(); keys.add('Space'); frame();
|
|
319
|
+
assert.deepEqual(out.slice(1), [{ k: 'hub-signal', kind: 'jump', a: 1 }]);
|
|
320
|
+
// (a) The first door prompt only, once; nothing is collected after it.
|
|
321
|
+
assert.equal(s.wantsPrompt(arrival), true);
|
|
322
|
+
frame({ prompt: 'gems' }); frame({ prompt: 'race' }); frame({ prompt: 'gems' });
|
|
323
|
+
assert.deepEqual(out.slice(2), [{ k: 'hub-signal', kind: 'prompt', a: 1, door: 'gems' }]);
|
|
324
|
+
assert.equal(s.wantsPrompt(arrival), false);
|
|
325
|
+
// (a) All three sent: a frame costs nothing, not even a status read.
|
|
326
|
+
const reads = statusReads;
|
|
327
|
+
for (let i = 0; i < 100; i++) {frame({ prompt: 'gems' });}
|
|
328
|
+
assert.equal(statusReads, reads);
|
|
329
|
+
assert.equal(out.length, 3);
|
|
330
|
+
// [3] A reconnect that is not an arrival (same record) says nothing again;
|
|
331
|
+
// only a new arrival number does.
|
|
332
|
+
frame({ arrival });
|
|
333
|
+
assert.equal(out.length, 3);
|
|
334
|
+
arrival = { n: 2, at: t };
|
|
335
|
+
keys.clear();
|
|
336
|
+
frame();
|
|
337
|
+
assert.equal(out.length, 3, 'nothing pressed yet for the new arrival');
|
|
338
|
+
keys.add('ArrowUp'); frame();
|
|
339
|
+
assert.deepEqual(out.at(-1), { k: 'hub-signal', kind: 'move', a: 2 });
|
|
340
|
+
// (a) Past 120 s nothing is said, and the check goes quiet.
|
|
341
|
+
keys.add('Space');
|
|
342
|
+
frame({ now: t + WINDOW_MS });
|
|
343
|
+
assert.equal(out.length, 4);
|
|
344
|
+
const quiet = statusReads;
|
|
345
|
+
frame({ now: t + WINDOW_MS + 5, prompt: 'gems' });
|
|
346
|
+
assert.equal(statusReads, quiet);
|
|
347
|
+
assert.equal(out.length, 4);
|
|
348
|
+
// Nothing to say: no status read either.
|
|
349
|
+
const s4 = makeSignals();
|
|
350
|
+
let reads4 = 0;
|
|
351
|
+
const net4 = { send() { throw Error('nothing to send'); }, status: () => { reads4++; return { state: 'connected' }; } };
|
|
352
|
+
for (let i = 0; i < 10; i++) {s4.frame(net4, { n: 9, at: t }, t, { keys: new Set(), stick: null, prompt: null });}
|
|
353
|
+
assert.equal(reads4, 0);
|
|
354
|
+
// Another wrapper over ours (Act's) is wrapped again: its own presses count.
|
|
355
|
+
const s2 = makeSignals();
|
|
356
|
+
const acted = { active: false, x: 0, y: 0, consumeJump: () => false };
|
|
357
|
+
const out2 = [];
|
|
358
|
+
const net2 = { send: (data) => out2.push(data) };
|
|
359
|
+
const a2 = { n: 3, at: t };
|
|
360
|
+
s2.frame(net2, a2, t, { keys: new Set(), stick: acted, prompt: null });
|
|
361
|
+
let actJump = false;
|
|
362
|
+
const inner = acted.consumeJump;
|
|
363
|
+
acted.consumeJump = () => { const own = actJump; actJump = false; return inner() || own; };
|
|
364
|
+
s2.frame(net2, a2, t, { keys: new Set(), stick: acted, prompt: null });
|
|
365
|
+
actJump = true; acted.consumeJump();
|
|
366
|
+
s2.frame(net2, a2, t, { keys: new Set(), stick: acted, prompt: null });
|
|
367
|
+
assert.deepEqual(out2, [{ k: 'hub-signal', kind: 'jump', a: 3 }]);
|
|
368
|
+
// Keys typed into a text field are words, not a walk or a jump.
|
|
369
|
+
const field = { closest: (sel) => sel.includes('input') ? field : null };
|
|
370
|
+
const typingDoc = { activeElement: field };
|
|
371
|
+
const s3 = makeSignals(typingDoc);
|
|
372
|
+
const out3 = [];
|
|
373
|
+
const net3 = { send: (data) => out3.push(data) };
|
|
374
|
+
const a3 = { n: 4, at: t };
|
|
375
|
+
s3.frame(net3, a3, t, { keys: new Set(['KeyW', 'Space']), stick: null, prompt: null });
|
|
376
|
+
assert.deepEqual(out3, []);
|
|
377
|
+
typingDoc.activeElement = null;
|
|
378
|
+
s3.frame(net3, a3, t, { keys: new Set(['KeyW', 'Space']), stick: null, prompt: null });
|
|
379
|
+
assert.deepEqual(out3, [{ k: 'hub-signal', kind: 'move', a: 4 }, { k: 'hub-signal', kind: 'jump', a: 4 }]);
|
|
380
|
+
// The client's messages are the server's: a real layer hears them.
|
|
381
|
+
const r = boot();
|
|
382
|
+
const toLayer = makeSignals();
|
|
383
|
+
const layerNet = { send: (data) => r.say('p1', data) };
|
|
384
|
+
toLayer.frame(layerNet, { n: r.arrivedMsg('p1').signals, at: t }, t, { keys: new Set(['ArrowUp', 'Space']), stick: null, prompt: 'gems' });
|
|
385
|
+
assert.deepEqual(kinds(r.heard), ['p1:move', 'p1:jump', 'p1:prompt:gems']);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// A door pad's caption names its door; an explicit cue names none.
|
|
389
|
+
{
|
|
390
|
+
const cues = collectPadCues([
|
|
391
|
+
{ id: 'door-gems', components: { HubDoor: { id: 'gems', title: 'Gem Rush' } } },
|
|
392
|
+
{ id: 'pad-gems', components: { HubPad: { door: 'gems', radius: 2 }, Transform: { x: 0, z: 0 } } },
|
|
393
|
+
{ id: 'cue', components: { HubPadCue: { radius: 1, title: 'Quick' }, Transform: { x: 10, z: 0 } } },
|
|
394
|
+
]);
|
|
395
|
+
assert.deepEqual(cues.map((cue) => cue.doorId), ['gems', undefined]);
|
|
396
|
+
// The door counts only when chrome says it drew the caption visibly.
|
|
397
|
+
let shows = true;
|
|
398
|
+
const readable = makePadReadability({ hubPadContext: true }, { chrome: { setPadContext: (item) => Boolean(item) && shows, clearPadContext() {} } });
|
|
399
|
+
const actorsNow = [
|
|
400
|
+
{ id: 'door-gems', components: { HubDoor: { id: 'gems', title: 'Gem Rush' } } },
|
|
401
|
+
{ id: 'pad-gems', components: { HubPad: { door: 'gems', radius: 2 }, Transform: { x: 0, z: 0 } } },
|
|
402
|
+
];
|
|
403
|
+
assert.equal(readable.frame(actorsNow, new Set(), { x: 0, z: 2.5 }, false), 'gems');
|
|
404
|
+
assert.equal(readable.frame(actorsNow, new Set(), { x: 0, z: 2.5 }, true), null, 'not while traveling');
|
|
405
|
+
assert.equal(readable.frame(actorsNow, new Set(), { x: 0, z: 2.5 }, false, true), null, 'not while the caption is blocked');
|
|
406
|
+
assert.equal(readable.frame(actorsNow, new Set(), { x: 0, z: 30 }, false), null);
|
|
407
|
+
shows = false;
|
|
408
|
+
assert.equal(readable.frame(actorsNow, new Set(), { x: 0, z: 2.5 }, false), null, 'a caption chrome hid or could not place is not a prompt');
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
Date.now = realNow;
|
|
412
|
+
console.log('signals: ok');
|