castle-web-cli 0.4.237 → 0.4.239
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +24 -0
- package/dist/bundle.js +447 -4
- package/dist/bundleLatin1.d.ts +6 -0
- package/dist/bundleLatin1.js +333 -0
- package/dist/castle-host/host.d.ts +10 -1
- package/dist/castle-host/host.js +133 -9
- package/dist/castleJson.d.ts +2 -0
- package/dist/castleJson.js +1 -0
- package/dist/deckExports.d.ts +35 -0
- package/dist/deckExports.js +365 -0
- package/dist/importCheckHook.d.ts +1 -0
- package/dist/importCheckHook.js +1 -1
- package/dist/index.js +21 -0
- package/dist/init.js +2 -1
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +9 -0
- package/dist/platformDoc.js +2 -1
- package/dist/playPagePolicy.d.ts +1 -0
- package/dist/playPagePolicy.js +8 -3
- package/dist/roomLogs.d.ts +39 -0
- package/dist/roomLogs.js +166 -0
- package/dist/save-deck.js +4 -0
- package/kits/base/CLAUDE.md +1 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +113 -2
- package/kits/base/sdk/castle.d.ts +6 -2
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +56 -1
- package/kits/base/sdk/commands.js +29 -1
- package/kits/base/sdk/hub.d.ts +17 -0
- package/kits/base/sdk/hub.js +33 -9
- package/kits/base/sdk/localCache.d.ts +27 -0
- package/kits/base/sdk/localCache.js +115 -0
- package/kits/base/sdk/localCacheStore.d.ts +15 -0
- package/kits/base/sdk/localCacheStore.js +358 -0
- package/kits/base/sdk/multiplayer.js +30 -0
- package/kits/base/sdk/rooms.d.ts +11 -0
- package/kits/base/sdk/rooms.js +22 -0
- package/kits/base/sdk/store.d.ts +8 -2
- package/kits/base/sdk/store.js +5 -1
- package/kits/base/sdk/transport.d.ts +1 -0
- package/kits/base/sdk/transport.js +4 -5
- package/kits/hub-game/CLAUDE.md +22 -2
- package/kits/hub-game/castle.json +8 -5
- package/kits/hub-game/code/client/act.js +66 -91
- package/kits/hub-game/code/client/actCore.js +134 -0
- package/kits/hub-game/code/client/car.js +35 -0
- package/kits/hub-game/code/client/chrome.js +208 -381
- package/kits/hub-game/code/client/crowdNames.js +2 -2
- package/kits/hub-game/code/client/emoteWheel.js +109 -0
- package/kits/hub-game/code/client/hats.js +2 -0
- package/kits/hub-game/code/client/hookLayer.js +99 -48
- package/kits/hub-game/code/client/hostGo.js +77 -0
- package/kits/hub-game/code/client/hubControls.js +125 -0
- package/kits/hub-game/code/client/hubEntry.js +187 -0
- package/kits/hub-game/code/client/hudSurface.js +148 -0
- package/kits/hub-game/code/client/hudTree.js +96 -0
- package/kits/hub-game/code/client/idle.js +59 -13
- package/kits/hub-game/code/client/invites.js +13 -4
- package/kits/hub-game/code/client/menuIcons.js +8 -0
- package/kits/hub-game/code/client/menuRows.js +8 -2
- package/kits/hub-game/code/client/noTrips.js +38 -0
- package/kits/hub-game/code/client/qualityEntry.js +6 -1
- package/kits/hub-game/code/client/rehello.js +3 -1
- package/kits/hub-game/code/client/riders.js +26 -0
- package/kits/hub-game/code/client/role.js +79 -0
- package/kits/hub-game/code/client/safeLayout.js +32 -3
- package/kits/hub-game/code/client/sound.js +10 -3
- package/kits/hub-game/code/client/soundscape.js +2 -2
- package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
- package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
- package/kits/hub-game/code/client/soundscapeCues.js +2 -1
- package/kits/hub-game/code/client/state.js +19 -0
- package/kits/hub-game/code/client/stuck.js +2 -1
- package/kits/hub-game/code/client/talkSurface.js +178 -0
- package/kits/hub-game/code/client/talkTree.js +238 -0
- package/kits/hub-game/code/client/tiers.js +8 -5
- package/kits/hub-game/code/client/uiDom.js +600 -0
- package/kits/hub-game/code/client/uiTree.js +359 -0
- package/kits/hub-game/code/client/vehicle.js +156 -0
- package/kits/hub-game/code/client/wear.js +27 -5
- package/kits/hub-game/code/client/worldLabels.js +13 -3
- package/kits/hub-game/code/client/yours.js +10 -3
- package/kits/hub-game/code/server/actors.js +4 -3
- package/kits/hub-game/code/server/analytics.js +61 -18
- package/kits/hub-game/code/server/decor.js +56 -16
- package/kits/hub-game/code/server/doorAnalytics.js +2 -5
- package/kits/hub-game/code/server/hub.js +261 -46
- package/kits/hub-game/code/server/idle.js +118 -5
- package/kits/hub-game/code/server/loadAbandon.js +2 -5
- package/kits/hub-game/code/server/manifest.js +46 -4
- package/kits/hub-game/code/server/npcs.js +4 -2
- package/kits/hub-game/code/server/players.js +3 -0
- package/kits/hub-game/code/server/role.js +142 -0
- package/kits/hub-game/code/server/standing.js +6 -4
- package/kits/hub-game/code/server/trackQueue.js +29 -0
- package/kits/hub-game/code/server/vehicle.js +126 -0
- package/kits/hub-game/code/shared/car.js +52 -0
- package/kits/hub-game/code/shared/deckFlags.js +34 -0
- package/kits/hub-game/code/shared/deviceClass.js +39 -0
- package/kits/hub-game/code/shared/expression.js +9 -0
- package/kits/hub-game/code/systems/hub.js +281 -86
- package/kits/hub-game/docs/analytics.md +15 -3
- package/kits/hub-game/docs/contract.md +352 -14
- package/kits/hub-game/docs/vehicle-preset.md +132 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
- package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
- package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
- package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
- package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
- package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
- package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
- package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
- package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
- package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
- package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
- package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
- package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
- package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
- package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
- package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
- package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
- package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
- package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
- package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
- package/kits/hub-game/package-lock.json +1 -1
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/check.mjs +7 -4
- package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
- package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
- package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
- package/kits/hub-game/scripts/gen-hats.mjs +46 -2
- package/kits/hub-game/scripts/gen-role.mjs +80 -0
- package/kits/hub-game/scripts/test-act-core.mjs +167 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
- package/kits/hub-game/scripts/test-actors.mjs +48 -0
- package/kits/hub-game/scripts/test-analytics.mjs +100 -6
- package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
- package/kits/hub-game/scripts/test-ballot.mjs +2 -0
- package/kits/hub-game/scripts/test-car.mjs +43 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
- package/kits/hub-game/scripts/test-decor.mjs +77 -0
- package/kits/hub-game/scripts/test-device-class.mjs +83 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
- package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
- package/kits/hub-game/scripts/test-hats.mjs +5 -4
- package/kits/hub-game/scripts/test-host-go.mjs +265 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
- package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +103 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +20 -1
- package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
- package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
- package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
- package/kits/hub-game/scripts/test-idle.mjs +347 -1
- package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
- package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
- package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
- package/kits/hub-game/scripts/test-manifest.mjs +30 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +1 -1
- package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-quality.mjs +13 -0
- package/kits/hub-game/scripts/test-rehello.mjs +258 -3
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
- package/kits/hub-game/scripts/test-resync.mjs +196 -0
- package/kits/hub-game/scripts/test-role-client.mjs +427 -0
- package/kits/hub-game/scripts/test-role.mjs +350 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
- package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
- package/kits/hub-game/scripts/test-standing.mjs +15 -1
- package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
- package/kits/hub-game/scripts/test-tiers.mjs +13 -0
- package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
- package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +168 -0
- package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +40 -0
- package/kits/hub-game/scripts/test-yours.mjs +33 -0
- package/kits/hub-game/tools/hubScene/export.mjs +613 -0
- package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
- package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
- package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +810 -0
- package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
- package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
- package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
- package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +301 -0
- package/kits/multiplayer-3d/castle.json +4 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
- package/kits/multiplayer-3d/code/client/steer.js +3 -1
- package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
- package/kits/physics-3d/CLAUDE.md +1 -1
- package/kits/physics-3d/behaviors/Player.jsx +37 -27
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
- package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
- package/kits/physics-3d/engine3d/playerRun.js +6 -1
- package/kits/physics-3d/engine3d/pxmodel.js +6 -1
- package/kits/physics-3d/engine3d/world3d.js +6 -3
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/play/behaviors/Player.js +40 -28
- package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/messages.js +5 -0
- package/kits/real-time/code/server/session.js +28 -1
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +5 -4
- package/vendor/three/LICENSE +21 -0
- package/vendor/three/build/three.core.js +58773 -0
- package/vendor/three/build/three.module.js +18251 -0
- package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
- package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
- package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
- package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
- package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
- package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
- package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
- package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
- package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
- package/vendor/three/package.json +134 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
// Roles (contract §11, v1.157), real server layer and wire.
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { register } from 'node:module';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
8
|
+
const avatarsStub = 'export function dropMissing() {}';
|
|
9
|
+
register(
|
|
10
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
11
|
+
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
const stubs = {
|
|
14
|
+
'@imports/castle.multiplayer-3d/code/server/sceneBodies.js': 'data:text/javascript,${encodeURIComponent(sceneStub)}',
|
|
15
|
+
'@imports/castle.multiplayer-3d/code/client/avatars.js': 'data:text/javascript,${encodeURIComponent(avatarsStub)}',
|
|
16
|
+
'castle-web-sdk': ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)},
|
|
17
|
+
};
|
|
18
|
+
export async function resolve(specifier, context, next) {
|
|
19
|
+
if (['pxmodel', 'optimize', 'look', 'lookbake'].some((m) => specifier === '@imports/castle.physics-3d/engine3d/' + m)) return { url: ${JSON.stringify(new URL('./fixtures/engine-models-stub.mjs', import.meta.url).href)}, shortCircuit: true };
|
|
20
|
+
if (specifier === '@imports/castle.physics-3d/engine3d/orbitlens.js') return { url: ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)}, shortCircuit: true };
|
|
21
|
+
if (stubs[specifier]) {
|
|
22
|
+
return { url: stubs[specifier], shortCircuit: true };
|
|
23
|
+
}
|
|
24
|
+
return next(specifier, context);
|
|
25
|
+
}
|
|
26
|
+
// The hook layer reads the deck's castle.json through the bundler.
|
|
27
|
+
export async function load(url, context, next) {
|
|
28
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
29
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
30
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
31
|
+
}
|
|
32
|
+
return next(url, context);
|
|
33
|
+
}
|
|
34
|
+
`)}`,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
async function kit(root) {
|
|
38
|
+
const at = (file) => pathToFileURL(path.join(root, file)).href;
|
|
39
|
+
return {
|
|
40
|
+
layer: (await import(at('code/server/hub.js'))).layer,
|
|
41
|
+
hookLayer: (await import(at('code/client/hookLayer.js'))).default,
|
|
42
|
+
State: await import(at('code/client/state.js')),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const here = await kit(path.join(import.meta.dirname, '..'));
|
|
47
|
+
|
|
48
|
+
globalThis.__hubTestActors = [
|
|
49
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
50
|
+
{ id: 'sign', components: { Transform: { x: 2, y: 1, z: 0 }, Shape: { kind: 'box', width: 1, height: 1, depth: 1, color: '#808080' } } },
|
|
51
|
+
];
|
|
52
|
+
const castleJson = { server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Hat Shop', result: {} } };
|
|
53
|
+
const sceneExists = () => true;
|
|
54
|
+
const flush = () => new Promise((resolve) => setImmediate(resolve));
|
|
55
|
+
|
|
56
|
+
const ROSTER = [
|
|
57
|
+
{ playerId: 'p1', userId: '101', username: 'ada', isAnonymous: false },
|
|
58
|
+
{ playerId: 'p2', userId: '102', username: 'bo', isAnonymous: false },
|
|
59
|
+
{ playerId: 'p3', userId: 'anon-1', username: 'guest', isAnonymous: true },
|
|
60
|
+
];
|
|
61
|
+
const halo = { kind: 'halo', color: '#ffd700', rarity: 4 };
|
|
62
|
+
|
|
63
|
+
// A place on a fake session, with everything it writes kept in `log` in the
|
|
64
|
+
// order it wrote it: snapshots, deltas, messages to one player, ghost calls,
|
|
65
|
+
// the deck's hooks and warnings. `hides(x, y)` is the host's block answer.
|
|
66
|
+
function room(layer, { hides = null, saved = { 101: halo, 102: null }, roster = ROSTER, keys = {} } = {}) {
|
|
67
|
+
const log = [];
|
|
68
|
+
const calls = [];
|
|
69
|
+
const players = roster.map((p) => ({ ...p }));
|
|
70
|
+
const platform = {
|
|
71
|
+
place: 'main',
|
|
72
|
+
title: 'Town',
|
|
73
|
+
result: null,
|
|
74
|
+
arrival: () => null,
|
|
75
|
+
async reportResult() {
|
|
76
|
+
return { recorded: true };
|
|
77
|
+
},
|
|
78
|
+
async updatePad() {
|
|
79
|
+
return { status: 'gathering', members: [] };
|
|
80
|
+
},
|
|
81
|
+
async readResults(input) {
|
|
82
|
+
calls.push(['read', input]);
|
|
83
|
+
log.push(['ghost-read', JSON.stringify(input)]);
|
|
84
|
+
const out = {};
|
|
85
|
+
for (const id of input.userIds ?? []) {
|
|
86
|
+
out[id] = { avatar: 1, recent: [], records: [], wearable: saved[id] ?? null };
|
|
87
|
+
}
|
|
88
|
+
return { players: out, boards: {} };
|
|
89
|
+
},
|
|
90
|
+
async wear(playerId, wearable) {
|
|
91
|
+
calls.push(['wear', playerId, wearable]);
|
|
92
|
+
log.push(['ghost-wear', playerId, JSON.stringify(wearable)]);
|
|
93
|
+
return { wearable };
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
if (hides) {
|
|
97
|
+
platform.hiddenPair = hides;
|
|
98
|
+
}
|
|
99
|
+
const session = {
|
|
100
|
+
sessionId: 's-1',
|
|
101
|
+
place: null,
|
|
102
|
+
players,
|
|
103
|
+
hub: platform,
|
|
104
|
+
send: (playerId, data) => log.push(['send', playerId, JSON.stringify(data)]),
|
|
105
|
+
broadcast: (data) => log.push(['broadcast', JSON.stringify(data)]),
|
|
106
|
+
};
|
|
107
|
+
let ctx = null;
|
|
108
|
+
const deck = {
|
|
109
|
+
ready: (hub) => (ctx = hub),
|
|
110
|
+
arrive: (hub, group) => log.push(['arrive', JSON.stringify(group)]),
|
|
111
|
+
leave: (hub, playerId) => log.push(['leave', playerId]),
|
|
112
|
+
step: () => log.push(['step']),
|
|
113
|
+
shutdown: () => log.push(['shutdown']),
|
|
114
|
+
resume() {},
|
|
115
|
+
};
|
|
116
|
+
const h = layer({ ...castleJson, hub: { ...castleJson.hub, ...keys } }, deck, {}, sceneExists);
|
|
117
|
+
h.sceneFor(session);
|
|
118
|
+
const world = { timeMs: 0, players: new Map(), bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
119
|
+
const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
120
|
+
h.ready(world);
|
|
121
|
+
return {
|
|
122
|
+
h,
|
|
123
|
+
session,
|
|
124
|
+
log,
|
|
125
|
+
calls,
|
|
126
|
+
world,
|
|
127
|
+
hub: () => ctx,
|
|
128
|
+
// The WORLD snapshot a joiner gets, and the delta everyone does.
|
|
129
|
+
join() {
|
|
130
|
+
const snapshot = h.join();
|
|
131
|
+
log.push(['join', JSON.stringify(snapshot)]);
|
|
132
|
+
return snapshot;
|
|
133
|
+
},
|
|
134
|
+
delta() {
|
|
135
|
+
const delta = h.delta();
|
|
136
|
+
log.push(['delta', JSON.stringify(delta)]);
|
|
137
|
+
return delta;
|
|
138
|
+
},
|
|
139
|
+
async tick(ms = 50) {
|
|
140
|
+
world.timeMs += ms;
|
|
141
|
+
h.place(world);
|
|
142
|
+
// Ghost's arrival read answers, and the next tick places who it was for.
|
|
143
|
+
await flush();
|
|
144
|
+
world.timeMs += ms;
|
|
145
|
+
h.place(world);
|
|
146
|
+
h.step(world);
|
|
147
|
+
},
|
|
148
|
+
enter(playerId) {
|
|
149
|
+
this.body(playerId);
|
|
150
|
+
this.hello(playerId);
|
|
151
|
+
},
|
|
152
|
+
// The two halves of coming in: a body in the simulation (and a place in
|
|
153
|
+
// the roster, for one who went), and the client's hello.
|
|
154
|
+
body(playerId) {
|
|
155
|
+
world.players.set(playerId, body());
|
|
156
|
+
if (!players.some((p) => p.playerId === playerId)) {
|
|
157
|
+
players.push({ ...(roster.find((p) => p.playerId === playerId) ?? { playerId, userId: null, username: playerId, isAnonymous: true }) });
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
hello(playerId, extra = {}) {
|
|
161
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar: 1, from: null, party: 1, ...extra });
|
|
162
|
+
},
|
|
163
|
+
exit(playerId) {
|
|
164
|
+
world.players.delete(playerId);
|
|
165
|
+
const at = players.findIndex((p) => p.playerId === playerId);
|
|
166
|
+
if (at >= 0) {
|
|
167
|
+
players.splice(at, 1);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
shutdown: () => h.shutdown(),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const police = { id: 'police', label: 'Police', color: '#22335a', hat: 'police-cap', top: 'vest', tool: 'torch' };
|
|
175
|
+
const doctor = { id: 'doctor', label: 'Doctor', color: '#42a6c0', hat: 'nurse-cap', top: 'scrubs', tool: 'bag' };
|
|
176
|
+
let count = 0;
|
|
177
|
+
async function test(name, fn) { await fn(); count += 1; console.log(`ok: ${name}`); }
|
|
178
|
+
const boot = async (options) => {
|
|
179
|
+
const r = room(here.layer, options);
|
|
180
|
+
for (const id of ['p1', 'p2', 'p3']) { r.enter(id); }
|
|
181
|
+
await r.tick(); r.delta(); r.log.length = 0;
|
|
182
|
+
return r;
|
|
183
|
+
};
|
|
184
|
+
const alone = (r) => r.log.filter((e) => e[0] === 'send' && JSON.parse(e[2]).k === 'hub-role').map((e) => [e[1], JSON.parse(e[2]).hubRole]);
|
|
185
|
+
|
|
186
|
+
await test('validation, trimmed label, lowercased colour, no mutation on refusal, warn once', async () => {
|
|
187
|
+
const r = await boot(); r.hub().role('p1', police); r.delta();
|
|
188
|
+
const warned = [], original = console.warn;
|
|
189
|
+
console.warn = (line) => warned.push(line);
|
|
190
|
+
try {
|
|
191
|
+
for (const bad of [false, [], 3, 'police', {}, { ...police, id: 'Police' }, { ...police, id: 'a'.repeat(25) },
|
|
192
|
+
{ ...police, id: 'a_b' }, { ...police, label: '' }, { ...police, label: ' ' }, { ...police, label: 'a'.repeat(17) },
|
|
193
|
+
...['\n', '\r', '\t', '\0', '\u007f', '\u0085', '\u2028', '\u2029'].map((c) => ({ ...police, label: `A${c}B` })),
|
|
194
|
+
{ ...police, label: 4 }, { ...police, color: '#fff' }, { ...police, color: 'red' }, { ...police, extra: 1 },
|
|
195
|
+
...['hat', 'top', 'tool'].flatMap((key) => [null, undefined, 'constructor', 'unknown'].map((value) => ({ ...police, [key]: value }))),
|
|
196
|
+
]) {
|
|
197
|
+
assert.equal(r.hub().role('p1', bad), false, JSON.stringify(bad));
|
|
198
|
+
assert.deepEqual(r.hub().roleOf('p1'), police);
|
|
199
|
+
}
|
|
200
|
+
for (let i = 0; i < 2; i += 1) { assert.equal(r.hub().role('missing', police), false); }
|
|
201
|
+
assert.equal(warned.length, 2);
|
|
202
|
+
} finally { console.warn = original; }
|
|
203
|
+
assert.equal(r.hub().role('p1', { id: 'a', label: ' A ', color: '#ABCDEF' }), true);
|
|
204
|
+
assert.deepEqual(r.hub().roleOf('p1'), { id: 'a', label: 'A', color: '#abcdef' });
|
|
205
|
+
assert.equal(r.hub().role('p1', { ...police, label: '😀'.repeat(16) }), true);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
await test('set/copy, same-spec suppression, whole-block latch, null and omitted clear, no ghost writes', async () => {
|
|
209
|
+
const r = await boot();
|
|
210
|
+
assert.equal(r.hub().roleOf('p1'), null); assert.equal(r.hub().roleOf('missing'), null);
|
|
211
|
+
const input = { ...police }; assert.equal(r.hub().role('p1', input), true); input.label = 'mutated';
|
|
212
|
+
const copy = r.hub().roleOf('p1'); copy.label = 'mutated';
|
|
213
|
+
assert.deepEqual(r.hub().roleOf('p1'), police);
|
|
214
|
+
assert.deepEqual(r.delta(), { hubRole: { p1: police } });
|
|
215
|
+
assert.equal(r.hub().role('p1', { tool: 'torch', top: 'vest', color: '#22335A', label: ' Police ', hat: 'police-cap', id: 'police' }), true);
|
|
216
|
+
assert.equal(r.delta(), null); assert.deepEqual(r.join().hubRole, { p1: police });
|
|
217
|
+
r.hub().role('p2', doctor); assert.deepEqual(r.delta().hubRole, { p1: police, p2: doctor });
|
|
218
|
+
r.hub().role('p1'); assert.deepEqual(r.delta().hubRole, { p2: doctor });
|
|
219
|
+
r.hub().role('p2', null); assert.deepEqual(r.delta(), { hubRole: {} });
|
|
220
|
+
assert.equal(r.delta(), null); assert.ok(!('hubRole' in r.join()));
|
|
221
|
+
assert.deepEqual(r.calls.filter((call) => call[0] === 'wear'), []);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
await test('before-hello body accepted, orphan pruned, leave and shutdown clear', async () => {
|
|
225
|
+
const r = room(here.layer); r.body('p1'); r.body('p2');
|
|
226
|
+
assert.equal(r.hub().role('p1', police), true); assert.equal(r.hub().role('p2', doctor), true);
|
|
227
|
+
assert.deepEqual(r.hub().roleOf('p1'), police); assert.ok(!('hubRole' in r.join()));
|
|
228
|
+
r.exit('p2'); r.hello('p1'); await r.tick(); assert.deepEqual(r.join().hubRole, { p1: police });
|
|
229
|
+
r.body('p2'); r.hello('p2'); await r.tick(); assert.equal(r.hub().roleOf('p2'), null);
|
|
230
|
+
r.hub().role('p2', doctor); r.delta(); r.exit('p1'); await r.tick();
|
|
231
|
+
assert.equal(r.hub().roleOf('p1'), null); assert.deepEqual(r.delta().hubRole, { p2: doctor });
|
|
232
|
+
r.body('early'); r.hub().role('early', police); await r.shutdown();
|
|
233
|
+
assert.deepEqual(r.delta().hubRole, {}); assert.equal(r.hub().roleOf('early'), null);
|
|
234
|
+
assert.ok(!('hubRole' in r.join()));
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
await test('retained reconnect keeps role, hides absent body, clears on account change', async () => {
|
|
238
|
+
const r = await boot({ keys: { resume: { keep: true } } });
|
|
239
|
+
r.hub().role('p1', police); r.delta(); r.exit('p1'); await r.tick();
|
|
240
|
+
assert.deepEqual(r.hub().roleOf('p1'), police); assert.deepEqual(r.delta().hubRole, {});
|
|
241
|
+
r.body('p1'); r.hello('p1', { resume: true }); await r.tick();
|
|
242
|
+
assert.deepEqual(r.hub().roleOf('p1'), police); assert.deepEqual(r.join().hubRole, { p1: police });
|
|
243
|
+
assert.equal(r.log.filter((e) => e[0] === 'leave').length, 0);
|
|
244
|
+
r.session.players.find((p) => p.playerId === 'p1').userId = '999'; await r.tick();
|
|
245
|
+
assert.equal(r.hub().roleOf('p1'), null);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
await test('restartRetainedAsFresh clears roles', async () => {
|
|
249
|
+
const r = await boot({ keys: { resume: { keep: true }, resumeVisibility: true } });
|
|
250
|
+
r.hub().role('p3', doctor); r.delta(); r.exit('p3'); await r.tick();
|
|
251
|
+
r.body('p3'); r.hello('p3', { resume: true }); await r.tick();
|
|
252
|
+
assert.equal(r.hub().roleOf('p3'), null);
|
|
253
|
+
assert.ok(r.log.some((e) => e[0] === 'leave' && e[1] === 'p3'));
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
await test('blocked pairs: per-viewer maps, equality suppression, fresh replay including empty clears', async () => {
|
|
257
|
+
const r = await boot({ hides: (a, b) => [a, b].sort().join() === 'p1,p2' });
|
|
258
|
+
r.hub().role('p1', police); r.hub().role('p3', doctor); await r.tick();
|
|
259
|
+
assert.deepEqual(r.delta().hubRole, { p3: doctor });
|
|
260
|
+
assert.deepEqual(alone(r), [['p1', { p1: police }], ['p3', { p1: police }]]);
|
|
261
|
+
r.hub().role('p1', police); await r.tick(); assert.equal(alone(r).length, 2);
|
|
262
|
+
r.hello('p3'); await r.tick(); assert.deepEqual(alone(r).at(-1), ['p3', { p1: police }]);
|
|
263
|
+
r.hub().role('p1', null); await r.tick(); assert.deepEqual(alone(r).slice(-2), [['p1', {}], ['p3', {}]]);
|
|
264
|
+
r.hello('p3'); await r.tick(); assert.deepEqual(alone(r).at(-1), ['p3', {}]);
|
|
265
|
+
here.State.clear();
|
|
266
|
+
for (const e of r.log) {
|
|
267
|
+
if (e[0] === 'send' && e[1] === 'p2') { here.hookLayer.message({}, JSON.parse(e[2])); }
|
|
268
|
+
}
|
|
269
|
+
assert.equal(here.State.hub.roles.has('p1'), false);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
await test('role-less snapshot/delta/message bytes unchanged after role blocks stripped from same story', async () => {
|
|
273
|
+
async function story(use) {
|
|
274
|
+
const r = await boot(); r.join(); r.delta();
|
|
275
|
+
if (use) { r.hub().role('p1', police); }
|
|
276
|
+
r.delta(); await r.tick(); r.join();
|
|
277
|
+
if (use) { r.hub().role('p1', null); }
|
|
278
|
+
r.delta(); await r.tick(); r.delta(); return r;
|
|
279
|
+
}
|
|
280
|
+
const quiet = await story(false), loud = await story(true);
|
|
281
|
+
assert.ok(!JSON.stringify(quiet.log).includes('hubRole'));
|
|
282
|
+
const stripped = loud.log.map((e) => {
|
|
283
|
+
if (!['join', 'delta'].includes(e[0])) { return e; }
|
|
284
|
+
const msg = JSON.parse(e[1]); if (msg) { delete msg.hubRole; }
|
|
285
|
+
return [e[0], JSON.stringify(e[0] === 'delta' && msg && !Object.keys(msg).length ? null : msg)];
|
|
286
|
+
});
|
|
287
|
+
assert.deepEqual(stripped, quiet.log); assert.deepEqual(loud.calls, quiet.calls);
|
|
288
|
+
});
|
|
289
|
+
await test('retained roster-only drop keeps state without broadcasting a stale body; expiry clears', async () => {
|
|
290
|
+
const r = await boot({ keys: { resume: { keep: true } } });
|
|
291
|
+
r.hub().role('p1', police); r.delta();
|
|
292
|
+
r.session.players.splice(r.session.players.findIndex((p) => p.playerId === 'p1'), 1);
|
|
293
|
+
await r.tick();
|
|
294
|
+
assert.deepEqual(r.hub().roleOf('p1'), police);
|
|
295
|
+
assert.deepEqual(r.delta().hubRole, {});
|
|
296
|
+
r.world.players.delete('p1'); await r.tick();
|
|
297
|
+
const realNow = Date.now, future = realNow() + 61000;
|
|
298
|
+
Date.now = () => future;
|
|
299
|
+
try { await r.tick(); } finally { Date.now = realNow; }
|
|
300
|
+
r.body('p1'); r.hello('p1', { resume: true }); await r.tick();
|
|
301
|
+
assert.equal(r.hub().roleOf('p1'), null);
|
|
302
|
+
});
|
|
303
|
+
await test('role changes during a roster-only drop retain the owner for reads and pruning', async () => {
|
|
304
|
+
for (const pruneFirst of [false, true]) {
|
|
305
|
+
const r = await boot({ keys: { resume: { keep: true } } });
|
|
306
|
+
r.hub().role('p1', police); r.delta();
|
|
307
|
+
const [player] = r.session.players.splice(r.session.players.findIndex((p) => p.playerId === 'p1'), 1);
|
|
308
|
+
await r.tick();
|
|
309
|
+
assert.equal(r.hub().role('p1', doctor), true);
|
|
310
|
+
assert.deepEqual(r.hub().roleOf('p1'), doctor);
|
|
311
|
+
assert.equal(r.join().hubRole, undefined);
|
|
312
|
+
r.session.players.push(player);
|
|
313
|
+
if (pruneFirst) {
|
|
314
|
+
assert.deepEqual(r.join().hubRole, { p1: doctor });
|
|
315
|
+
}
|
|
316
|
+
assert.deepEqual(r.hub().roleOf('p1'), doctor);
|
|
317
|
+
assert.deepEqual(r.join().hubRole, { p1: doctor });
|
|
318
|
+
r.session.players.splice(r.session.players.indexOf(player), 1);
|
|
319
|
+
r.hub().role('p1', police);
|
|
320
|
+
r.session.players.push({ ...player, userId: 'different-account' });
|
|
321
|
+
if (pruneFirst) {
|
|
322
|
+
assert.equal(r.join().hubRole, undefined);
|
|
323
|
+
}
|
|
324
|
+
assert.equal(r.hub().roleOf('p1'), null);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
await test('a first role, or one after a clear, given during a roster-only drop belongs to the returning account', async () => {
|
|
328
|
+
for (const clearFirst of [false, true]) {
|
|
329
|
+
const r = await boot({ keys: { resume: { keep: true } } });
|
|
330
|
+
if (clearFirst) {
|
|
331
|
+
r.hub().role('p1', police); r.delta();
|
|
332
|
+
}
|
|
333
|
+
const [player] = r.session.players.splice(r.session.players.findIndex((p) => p.playerId === 'p1'), 1);
|
|
334
|
+
await r.tick();
|
|
335
|
+
if (clearFirst) {
|
|
336
|
+
assert.equal(r.hub().role('p1', null), true);
|
|
337
|
+
}
|
|
338
|
+
assert.equal(r.hub().role('p1', doctor), true);
|
|
339
|
+
r.session.players.push(player);
|
|
340
|
+
await r.tick();
|
|
341
|
+
assert.deepEqual(r.hub().roleOf('p1'), doctor);
|
|
342
|
+
assert.deepEqual(r.join().hubRole, { p1: doctor });
|
|
343
|
+
r.session.players.splice(r.session.players.indexOf(player), 1);
|
|
344
|
+
r.hub().role('p1', null);
|
|
345
|
+
r.hub().role('p1', police);
|
|
346
|
+
r.session.players.push({ ...player, userId: 'different-account' });
|
|
347
|
+
assert.equal(r.hub().roleOf('p1'), null);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
console.log(`test-role: ${count} passed`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
|
-
import { makeSafeLayout, overlaps, reservedCorners, safePlacement, panelPlacement, stackPlacement } from '../code/client/safeLayout.js';
|
|
2
|
+
import { besideColumn, makeSafeLayout, overlaps, reservedCorners, safePlacement, panelPlacement, stackPlacement } from '../code/client/safeLayout.js';
|
|
3
3
|
import { makeChrome } from '../code/client/chrome.js';
|
|
4
4
|
import { actionLayout } from '../code/client/actionLayout.js';
|
|
5
5
|
import { fakeDom } from './fixtures/fake-dom.mjs';
|
|
@@ -45,6 +45,21 @@ assert.deepEqual(safePlacement(rectangle({ x: 12, y: 70, w: 90, h: 36 }), zero),
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// v1.127 Act and Jump join the bottom-right column; the standing HUD prompt
|
|
49
|
+
// narrows into the lane beside it (portrait 390 wide, measured in Foot Race),
|
|
50
|
+
// or lifts above it when no lane of 160 px is left.
|
|
51
|
+
{
|
|
52
|
+
const phone = { w: 390, h: 844, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
53
|
+
const column = [rectangle({ x: 314, y: 728, w: 64, h: 48 }), rectangle({ x: 244, y: 728, w: 64, h: 48 }), rectangle({ x: 334, y: 782, w: 44, h: 44 })];
|
|
54
|
+
const prompt = rectangle({ x: 78, y: 745, w: 234, h: 44 });
|
|
55
|
+
const lane = besideColumn(safePlacement(prompt, phone), phone, {}, column);
|
|
56
|
+
assert.deepEqual(lane, { x: 6, y: 745, w: 232, h: 44 });
|
|
57
|
+
assert(column.every((box) => !overlaps(rectangle(lane), box)));
|
|
58
|
+
const narrow = besideColumn(safePlacement(prompt, phone), phone, {}, [rectangle({ x: 150, y: 728, w: 228, h: 48 })]);
|
|
59
|
+
assert.deepEqual(narrow, { x: 78, y: 678, w: 234, h: 44 });
|
|
60
|
+
assert.deepEqual(besideColumn({ x: 78, y: 500, w: 234, h: 44 }, phone, {}, column), { x: 78, y: 500, w: 234, h: 44 }, 'clear prompt untouched');
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
// F keeps every offer, and opted-in edges use max(margin, inset), not inset+margin.
|
|
49
64
|
const offers = [{ w: 80, h: 44 }, { w: 90, h: 44 }, { w: 100, h: 44 }];
|
|
50
65
|
const placed = actionLayout({ view: { w: 844, h: 390 }, safe: { left: 40, right: 48 }, offers, edgeMax: true });
|
|
@@ -112,6 +127,40 @@ const before = legacy();
|
|
|
112
127
|
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
113
128
|
}
|
|
114
129
|
}
|
|
130
|
+
|
|
131
|
+
// A card that fits itself (the landscape character strip) is never moved or
|
|
132
|
+
// narrowed around the controls it covers.
|
|
133
|
+
{
|
|
134
|
+
const dom = fakeDom({ viewW: 844, viewH: 390 });
|
|
135
|
+
const root = document.createElement('div'); dom.body.append(root);
|
|
136
|
+
root.contains = (node) => { for (let p = node; p; p = p.parent) {if (p === root) {return true;}} return false; };
|
|
137
|
+
const box = (node, at) => {
|
|
138
|
+
node.getBoundingClientRect = () => {
|
|
139
|
+
const [dx, dy] = (node.style.translate || '0 0').split(' ').map(Number.parseFloat);
|
|
140
|
+
const w = Math.min(at.w, Number.parseFloat(node.style.maxWidth) || Infinity);
|
|
141
|
+
return { ...rectangle({ x: at.x + dx, y: at.y + dy, w, h: at.h }), width: w, height: at.h };
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
const talk = document.createElement('button'), card = document.createElement('div');
|
|
145
|
+
root.append(talk); root.append(card);
|
|
146
|
+
box(talk, { x: 516, y: 300, w: 210, h: 44 }); box(card, { x: 36, y: 233, w: 772, h: 145 });
|
|
147
|
+
const previous = globalThis.getComputedStyle;
|
|
148
|
+
globalThis.getComputedStyle = (element) => ({ ...element.styles, paddingLeft: '0px', paddingRight: '0px', paddingTop: '0px', paddingBottom: '0px' });
|
|
149
|
+
try {
|
|
150
|
+
let pinned = false;
|
|
151
|
+
const controller = makeSafeLayout({ root, entries: () => [{ id: 'talk', node: talk, kind: 'control' },
|
|
152
|
+
{ id: 'character-card', node: card, kind: 'card', pinned }] });
|
|
153
|
+
const moved = controller.report().boxes.find((b) => b.id === 'character-card');
|
|
154
|
+
assert(moved.x !== 36 || moved.y !== 233 || moved.w !== 772, 'an unpinned card is moved around the talk button (how the strip left the screen)');
|
|
155
|
+
pinned = true;
|
|
156
|
+
const report = controller.report();
|
|
157
|
+
assert.deepEqual(report.boxes.find((b) => b.id === 'character-card'), { id: 'character-card', kind: 'card', x: 36, y: 233, w: 772, h: 145 });
|
|
158
|
+
assert.equal(card.style.translate ?? '', ''); assert.equal(card.style.maxWidth ?? '', '');
|
|
159
|
+
controller.dispose();
|
|
160
|
+
} finally {
|
|
161
|
+
if (previous === undefined) {delete globalThis.getComputedStyle;} else {globalThis.getComputedStyle = previous;}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
115
164
|
console.log('safe layout: insets, both host corners, clipping, overflow parity, no drift and dormant DOM passed');
|
|
116
165
|
|
|
117
166
|
{
|
|
@@ -639,7 +639,7 @@ const quietPage = () => ({ contexts: audio.contexts.length, win: win.listeners.l
|
|
|
639
639
|
const src = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
640
640
|
assert.equal(src.match(/makeSoundscape\(/g)?.length, 1);
|
|
641
641
|
assert.equal(src.match(/this\.hearPlace\(/g)?.length, 1);
|
|
642
|
-
assert.match(src, /\n {4}if \(Hub\.deck\.soundscape && !this\.soundscape\) \{\n {6}this\.hearPlace\(\);\n {4}\}/);
|
|
642
|
+
assert.match(src, /\n {4}if \(Hub\.deck\.soundscape && !this\.soundscape\) \{\n {6}this\.hearPlace\(scene\);\n {4}\}/);
|
|
643
643
|
// The frame: the place's sounds are asked for with the control's level
|
|
644
644
|
// only in a deck with the key, and exactly as they were without it.
|
|
645
645
|
assert.match(
|
|
@@ -650,7 +650,7 @@ const quietPage = () => ({ contexts: audio.contexts.length, win: win.listeners.l
|
|
|
650
650
|
assert.equal(src.match(/soundControl/g)?.length, 1);
|
|
651
651
|
// Every other mention is the opt-in completion hook, inside `hearPlace`,
|
|
652
652
|
// or puts one away in `dispose`.
|
|
653
|
-
const body = src.slice(src.indexOf('\n hearPlace() {'), src.indexOf('\n }\n', src.indexOf('\n hearPlace() {')));
|
|
653
|
+
const body = src.slice(src.indexOf('\n hearPlace(scene) {'), src.indexOf('\n }\n', src.indexOf('\n hearPlace(scene) {')));
|
|
654
654
|
const outside = src.replace(body, '');
|
|
655
655
|
assert.deepEqual(outside.match(/[^\n]*\bsoundscape\b[^\n]*/g)?.map((line) => line.trim()).filter((line) => !line.startsWith('//')), [
|
|
656
656
|
"import { makeSoundscape } from '../client/soundscape.js';",
|
|
@@ -677,7 +677,9 @@ const quietPage = () => ({ contexts: audio.contexts.length, win: win.listeners.l
|
|
|
677
677
|
|
|
678
678
|
test('the hook layer reads the key from the deck, and nothing else of the client asks for it', () => {
|
|
679
679
|
const hooks = fs.readFileSync(new URL('../code/client/hookLayer.js', import.meta.url), 'utf8');
|
|
680
|
-
|
|
680
|
+
// applyDeck reads it off the hub block: the page's castle.json, or the native manifest's copy.
|
|
681
|
+
assert.match(hooks, /applyDeck\(castleJson\?\.hub\);/);
|
|
682
|
+
assert.match(hooks, /\n const soundscape = block\.soundscape;\n deck\.soundscape = soundscape === true \|\| \(soundscape && typeof soundscape === 'object' && !Array\.isArray\(soundscape\)\) \? \{/);
|
|
681
683
|
assert.doesNotMatch(hooks.slice(hooks.indexOf('let files = null;')).replace(/case 'hub-cue':[\s\S]*?break;/, ''), /soundscape/, 'only the opted-in cue message reads the soundscape key after load');
|
|
682
684
|
// Nothing on the wire: neither server half knows the word beyond the manifest's reading of it.
|
|
683
685
|
for (const file of fs.readdirSync(new URL('../code/server/', import.meta.url))) {
|
|
@@ -736,6 +738,23 @@ test('sound.js without a master: the loop and the one-shot at the volumes they a
|
|
|
736
738
|
r.sound.dispose();
|
|
737
739
|
});
|
|
738
740
|
|
|
741
|
+
test('sound.js: a horn (v1.160) plays from its driver and stays as loud while it sounds', () => {
|
|
742
|
+
const r = soundRig();
|
|
743
|
+
const actors = { jukebox: { components: { Transform: { x: 5, y: 0, z: 0 } } }, avatar2: { components: { Transform: { x: 0, y: 0, z: 5 } } }, me: r.local };
|
|
744
|
+
r.local.id = 'me';
|
|
745
|
+
r.scene.getActor = (id) => actors[id] ?? null;
|
|
746
|
+
r.scene.multiplayer = { net: { selfId: () => 'p1' }, avatars: { actors: new Map([['p2', 'avatar2']]) } };
|
|
747
|
+
State.hub.soundEvents.push({ k: 'hub-sound', player: 'p2', file: 'sounds/ding.wav', volume: 1, radius: 20 });
|
|
748
|
+
r.sound.frame(r.scene, r.local, true);
|
|
749
|
+
assert.equal(r.els[1].volume, 0.75, "another driver's horn, 5 m off");
|
|
750
|
+
r.sound.frame(r.scene, r.local, true);
|
|
751
|
+
assert.equal(r.els[1].volume, 0.75, 'not silenced on the next frame');
|
|
752
|
+
State.hub.soundEvents.push({ k: 'hub-sound', player: 'p1', file: 'sounds/ding.wav', volume: 1, radius: 20 });
|
|
753
|
+
r.sound.frame(r.scene, r.local, true);
|
|
754
|
+
assert.equal(r.els[2].volume, 1, 'your own horn, at your own body');
|
|
755
|
+
r.sound.dispose();
|
|
756
|
+
});
|
|
757
|
+
|
|
739
758
|
test('sound.js with a master (only a deck with the key gives one): scaled, silent at 0, hushed at once', () => {
|
|
740
759
|
const r = soundRig();
|
|
741
760
|
r.sound.frame(r.scene, r.local, true, 0.5);
|
|
@@ -1250,7 +1269,7 @@ function world() {
|
|
|
1250
1269
|
return { actors, add, avatars, scene, mp, local: actors.get('me') };
|
|
1251
1270
|
}
|
|
1252
1271
|
|
|
1253
|
-
function rig({ options = { babble: true, steps: true }, kept = {}, active = true, loudestLoop, cueVoices, createOfflineContext, context } = {}) {
|
|
1272
|
+
function rig({ options = { babble: true, steps: true }, kept = {}, active = true, loudestLoop, cueVoices, createOfflineContext, context, lowMemory = false } = {}) {
|
|
1254
1273
|
State.clear();
|
|
1255
1274
|
const from = audio.contexts.length;
|
|
1256
1275
|
const doc = fakeTarget();
|
|
@@ -1259,7 +1278,7 @@ function rig({ options = { babble: true, steps: true }, kept = {}, active = true
|
|
|
1259
1278
|
const storage = fakeStorage(kept);
|
|
1260
1279
|
const hides = [];
|
|
1261
1280
|
const nav = { userActivation: { hasBeenActive: active } };
|
|
1262
|
-
const made = S.makeSoundscape(options, { storage, doc, win: page, nav, random: () => 0.5, onHide: () => hides.push(1), loudestLoop, cueVoices, createOfflineContext, ...(context ? { audio: { getAudioContext: () => context } } : {}) });
|
|
1281
|
+
const made = S.makeSoundscape(options, { storage, doc, win: page, nav, random: () => 0.5, onHide: () => hides.push(1), loudestLoop, cueVoices, createOfflineContext, lowMemory, ...(context ? { audio: { getAudioContext: () => context } } : {}) });
|
|
1263
1282
|
const w = world();
|
|
1264
1283
|
let clock = 1000;
|
|
1265
1284
|
const r = {
|
|
@@ -2220,6 +2239,8 @@ test('the place\'s own sound files wait for the gesture too: nothing is started
|
|
|
2220
2239
|
r.chrome.onEmote((id) => heard.push(['emote', id]));
|
|
2221
2240
|
r.chrome.setEmotes([['wave', '👋']]);
|
|
2222
2241
|
r.made.find((node) => node.attrs['aria-label'] === 'wave').press();
|
|
2242
|
+
// Questions are drawn in an open conversation (a closed panel is not redrawn).
|
|
2243
|
+
r.chrome.openTalk('Mabel');
|
|
2223
2244
|
r.chrome.talkAsks(['Tell me'], (ask) => heard.push(['ask', ask]));
|
|
2224
2245
|
r.made.find((node) => node.tag === 'button' && node.textContent === 'Tell me').press();
|
|
2225
2246
|
r.chrome.setDoors([{ id: 'd', title: 'Door', solo: true }]);
|
|
@@ -4169,8 +4190,8 @@ test('v1.49: animal voices never overlap, end on the audio clock, and scheduled
|
|
|
4169
4190
|
// Exercise both orders within the SAME engine frame, with completion
|
|
4170
4191
|
// running last as it does in the real registered system list.
|
|
4171
4192
|
const hearPlace = r.system.hearPlace;
|
|
4172
|
-
r.system.hearPlace = () => {
|
|
4173
|
-
hearPlace.call(r.system);
|
|
4193
|
+
r.system.hearPlace = (scene) => {
|
|
4194
|
+
hearPlace.call(r.system, scene);
|
|
4174
4195
|
const soundscape = r.system.soundscape;
|
|
4175
4196
|
const frame = soundscape.frame;
|
|
4176
4197
|
soundscape.frame = (...args) => {
|
|
@@ -4869,6 +4890,102 @@ async function flushBakes() {
|
|
|
4869
4890
|
for (let i = 0; i < 12; i += 1) { await Promise.resolve(); }
|
|
4870
4891
|
}
|
|
4871
4892
|
|
|
4893
|
+
await asyncTest('low-memory soundscape: dependency reaches ambience through the public factory', async () => {
|
|
4894
|
+
const offline = fakeOfflineFactory();
|
|
4895
|
+
const r = rig({ lowMemory: true, options: { babble: false, steps: false,
|
|
4896
|
+
ambience: { default: 'crowd', beds: { dock: 'harbour', stall: 'market' } } }, createOfflineContext: offline.factory });
|
|
4897
|
+
r.frame();
|
|
4898
|
+
await flushBakes();
|
|
4899
|
+
offline.renders[0].ctx.finish();
|
|
4900
|
+
await flushBakes();
|
|
4901
|
+
assert.equal(offline.renders.length, 1);
|
|
4902
|
+
r.made.dispose();
|
|
4903
|
+
});
|
|
4904
|
+
|
|
4905
|
+
await asyncTest('low-memory prebake: only current heavy bed, evict on switch, quiet and re-entry', async () => {
|
|
4906
|
+
const ctx = poolContext();
|
|
4907
|
+
const offline = fakeOfflineFactory();
|
|
4908
|
+
const ambient = makeAmbience({ default: 'crowd', beds: { dock: 'harbour', stall: 'market' } },
|
|
4909
|
+
ambienceDeps({ lowMemory: true, createOfflineContext: offline.factory }));
|
|
4910
|
+
const frame = (name, near = noSpot) => ambient.frame(ctx, ctx.destination, name, near);
|
|
4911
|
+
frame('crowd');
|
|
4912
|
+
await flushBakes();
|
|
4913
|
+
offline.renders[0].ctx.finish();
|
|
4914
|
+
await flushBakes();
|
|
4915
|
+
frame('crowd');
|
|
4916
|
+
const crowd = ctx.made('source').find((source) => source.buffer?.duration === LOOP_S.crowd);
|
|
4917
|
+
assert(crowd);
|
|
4918
|
+
assert.equal(offline.renders.length, 1, 'other mapped zones never prewarm');
|
|
4919
|
+
frame('market');
|
|
4920
|
+
assert.equal(crowd.buffer, null, 'stopped playback drops its native buffer reference');
|
|
4921
|
+
await flushBakes();
|
|
4922
|
+
assert.equal(offline.renders.length, 2);
|
|
4923
|
+
offline.renders[1].ctx.finish();
|
|
4924
|
+
await flushBakes();
|
|
4925
|
+
frame('market', { bed: 'harbour', gain: 0.4 });
|
|
4926
|
+
const market = ctx.made('source').find((source) => source.buffer?.duration === LOOP_S.market);
|
|
4927
|
+
assert(market);
|
|
4928
|
+
await flushBakes();
|
|
4929
|
+
assert.equal(offline.renders.length, 2, 'secondary heavy spot uses the live generator');
|
|
4930
|
+
ambient.quiet();
|
|
4931
|
+
assert.equal(market.buffer, null);
|
|
4932
|
+
frame('crowd');
|
|
4933
|
+
await flushBakes();
|
|
4934
|
+
assert.equal(offline.renders.length, 3, 'inactive fulfilled promise was evicted');
|
|
4935
|
+
ambient.quiet();
|
|
4936
|
+
offline.renders[2].ctx.finish();
|
|
4937
|
+
await flushBakes();
|
|
4938
|
+
frame('crowd');
|
|
4939
|
+
await flushBakes();
|
|
4940
|
+
assert.equal(offline.renders.length, 4, 'quiet also evicts a running bed on completion');
|
|
4941
|
+
offline.renders[3].ctx.finish();
|
|
4942
|
+
await flushBakes();
|
|
4943
|
+
ambient.quiet();
|
|
4944
|
+
});
|
|
4945
|
+
|
|
4946
|
+
await asyncTest('low-memory prebake: obsolete in-flight work cannot retain or start playback', async () => {
|
|
4947
|
+
const ctx = poolContext();
|
|
4948
|
+
const offline = fakeOfflineFactory();
|
|
4949
|
+
const ambient = makeAmbience({}, ambienceDeps({ lowMemory: true, createOfflineContext: offline.factory }));
|
|
4950
|
+
ambient.frame(ctx, ctx.destination, 'crowd', noSpot);
|
|
4951
|
+
await flushBakes();
|
|
4952
|
+
ambient.frame(ctx, ctx.destination, 'market', noSpot);
|
|
4953
|
+
ambient.frame(ctx, ctx.destination, 'harbour', noSpot);
|
|
4954
|
+
await flushBakes();
|
|
4955
|
+
assert.equal(offline.renders.length, 1, 'cannot cancel an active OfflineAudioContext');
|
|
4956
|
+
offline.renders[0].ctx.finish();
|
|
4957
|
+
await flushBakes();
|
|
4958
|
+
assert.equal(offline.renders.length, 2, 'queued obsolete market bake was removed');
|
|
4959
|
+
assert.equal(offline.renders[1].length / offline.renders[1].sampleRate, LEAD_IN_S + LOOP_S.harbour + XFADE_S);
|
|
4960
|
+
offline.renders[1].ctx.finish();
|
|
4961
|
+
await flushBakes();
|
|
4962
|
+
ambient.frame(ctx, ctx.destination, 'harbour', noSpot);
|
|
4963
|
+
const loops = ctx.made('source').filter((source) => source.loop && source.buffer?.duration > 10);
|
|
4964
|
+
assert.equal(loops.length, 1);
|
|
4965
|
+
assert.equal(loops[0].buffer.duration, LOOP_S.harbour);
|
|
4966
|
+
ambient.quiet();
|
|
4967
|
+
});
|
|
4968
|
+
|
|
4969
|
+
await asyncTest('low-memory prebake: a nearby spot warms only while in the current light zone', async () => {
|
|
4970
|
+
const ctx = poolContext();
|
|
4971
|
+
const offline = fakeOfflineFactory();
|
|
4972
|
+
const ambient = makeAmbience({ spots: { Stall: 'market' } }, ambienceDeps({ lowMemory: true, createOfflineContext: offline.factory }));
|
|
4973
|
+
ambient.frame(ctx, ctx.destination, 'square', noSpot);
|
|
4974
|
+
await flushBakes();
|
|
4975
|
+
assert.equal(offline.renders.length, 0);
|
|
4976
|
+
ambient.frame(ctx, ctx.destination, 'square', { bed: 'market', gain: 0.45 });
|
|
4977
|
+
await flushBakes();
|
|
4978
|
+
assert.equal(offline.renders.length, 1);
|
|
4979
|
+
offline.renders[0].ctx.finish();
|
|
4980
|
+
await flushBakes();
|
|
4981
|
+
ambient.frame(ctx, ctx.destination, 'square', { bed: 'market', gain: 0.45 });
|
|
4982
|
+
const source = ctx.made('source').find((node) => node.buffer?.duration === LOOP_S.market);
|
|
4983
|
+
assert(source);
|
|
4984
|
+
ambient.frame(ctx, ctx.destination, 'square', noSpot);
|
|
4985
|
+
assert.equal(source.buffer, null);
|
|
4986
|
+
ambient.quiet();
|
|
4987
|
+
});
|
|
4988
|
+
|
|
4872
4989
|
await asyncTest('prebake: current zone first, only referenced heavy defaults/zones/spots, one render at a time', async () => {
|
|
4873
4990
|
const ctx = poolContext();
|
|
4874
4991
|
const offline = fakeOfflineFactory();
|
|
@@ -207,9 +207,23 @@ await test('other Players exports pass through unchanged', () => {
|
|
|
207
207
|
const wrapped = hubPlayers({});
|
|
208
208
|
assert.deepEqual(Object.keys(wrapped).sort(), Object.keys(Players).sort());
|
|
209
209
|
for (const key of Object.keys(Players)) {
|
|
210
|
-
if (key !== 'addPlayer') assert.equal(wrapped[key], Players[key], key);
|
|
210
|
+
if (key !== 'addPlayer' && key !== 'setPose') assert.equal(wrapped[key], Players[key], key);
|
|
211
211
|
}
|
|
212
212
|
});
|
|
213
|
+
await test('setPose passes a report through unless the hub refuses it (a car rider, v1.160)', () => {
|
|
214
|
+
const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, movedAt: 0 });
|
|
215
|
+
const sim = { timeMs: 1000, players: new Map([['walker', body()], ['rider', body()]]) };
|
|
216
|
+
const report = { p: [0.1, 1, 0, 1.5] };
|
|
217
|
+
const refusing = hubPlayers({ allowPlayerPose: (id) => id !== 'rider' });
|
|
218
|
+
refusing.setPose(sim, 'walker', report);
|
|
219
|
+
refusing.setPose(sim, 'rider', report);
|
|
220
|
+
assert.equal(sim.players.get('walker').facing, 1.5, 'an allowed report is the multiplayer kit\'s own');
|
|
221
|
+
assert.equal(sim.players.get('rider').facing, 0, 'a refused report changes nothing');
|
|
222
|
+
assert.equal(sim.players.get('rider').at.x, 0);
|
|
223
|
+
// A hub that never decides (no vehicle preset in use) passes every report on.
|
|
224
|
+
hubPlayers({}).setPose(sim, 'rider', report);
|
|
225
|
+
assert.equal(sim.players.get('rider').facing, 1.5);
|
|
226
|
+
});
|
|
213
227
|
await test('uninitialised hub state cannot lower a body', async () => {
|
|
214
228
|
globalThis.__standingActors = [spawn];
|
|
215
229
|
globalThis.__standingGround = {};
|