castle-web-cli 0.4.242 → 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/agent-prompts.js +4 -4
- package/dist/index.js +44 -3
- package/dist/platformDoc.js +1 -0
- package/dist/versionPrune.d.ts +62 -0
- package/dist/versionPrune.js +513 -0
- package/dist/versionStore.d.ts +2 -0
- package/dist/versionStore.js +64 -0
- package/dist/versions.js +6 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +2 -1
- package/kits/base/sdk/server/hub.js +5 -1
- package/kits/base/sdk/server/platformHandle.d.ts +2 -0
- 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 +65 -1
- 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
|
@@ -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');
|