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,108 @@
|
|
|
1
|
+
// hubControls.js: the People list's actions, Report and the Back control's
|
|
2
|
+
// decisions as plain functions, the way the hub system and a native host
|
|
3
|
+
// both run them.
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import { backControl, backPress, backRoute, personAction, reportPerson } from '../code/client/hubControls.js';
|
|
6
|
+
|
|
7
|
+
// personAction
|
|
8
|
+
function rig() {
|
|
9
|
+
const log = [];
|
|
10
|
+
const net = { send: (m) => log.push(['send', m]) };
|
|
11
|
+
const opts = {
|
|
12
|
+
together: { find: (id) => log.push(['find', id]) },
|
|
13
|
+
say: (t) => log.push(['say', t]),
|
|
14
|
+
jump: (n, m) => log.push(['jump', n === net, m]),
|
|
15
|
+
jumpTo: (f) => log.push(['jumpTo', f]),
|
|
16
|
+
doors: [{ id: 'race', title: 'Foot Race' }],
|
|
17
|
+
};
|
|
18
|
+
return { log, net, opts };
|
|
19
|
+
}
|
|
20
|
+
{
|
|
21
|
+
const { log, net, opts } = rig();
|
|
22
|
+
assert.equal(personAction(net, { playerId: 'p2' }, 'find', opts), true);
|
|
23
|
+
assert.deepEqual(log.at(-1), ['find', 'p2']);
|
|
24
|
+
personAction(net, { playerId: 'p2', username: 'Bo' }, 'invite', opts);
|
|
25
|
+
assert.deepEqual(log.slice(-2), [['send', { k: 'hub-party', op: 'invite', player: 'p2' }], ['say', 'Invited Bo to your party']]);
|
|
26
|
+
personAction(net, { playerId: 'p3' }, 'invite', opts);
|
|
27
|
+
assert.deepEqual(log.at(-1), ['say', 'Invited them to your party']);
|
|
28
|
+
personAction(net, { playerId: 'p2' }, 'goto', opts);
|
|
29
|
+
assert.deepEqual(log.at(-1), ['jump', true, { k: 'hub-goto', player: 'p2' }]);
|
|
30
|
+
personAction(net, { playerId: null, username: 'Cy', door: 'house', owner: '7' }, 'door', opts);
|
|
31
|
+
assert.deepEqual(log.slice(-2), [['jump', true, { k: 'hub-house-visit', door: 'house', owner: '7' }], ['say', "Going to Cy's House"]]);
|
|
32
|
+
personAction(net, { playerId: null, door: 'race' }, 'door', opts);
|
|
33
|
+
assert.deepEqual(log.slice(-2), [['jump', true, { k: 'hub-door-jump', door: 'race' }], ['say', 'Your friend is inside Foot Race']]);
|
|
34
|
+
personAction(net, { playerId: null, username: 'Di', door: 'gone' }, 'door', opts);
|
|
35
|
+
assert.deepEqual(log.at(-1), ['say', 'Di is inside that game']);
|
|
36
|
+
const before = log.length;
|
|
37
|
+
personAction(net, { playerId: 'p4', door: 'race' }, 'door', opts);
|
|
38
|
+
assert.equal(log.length, before + 1, 'someone at the door is simply gone to');
|
|
39
|
+
personAction(net, { userId: '42', username: 'Ed', playerId: null }, 'jump', opts);
|
|
40
|
+
assert.deepEqual(log.at(-1), ['jumpTo', { userId: '42', username: 'Ed' }]);
|
|
41
|
+
const quiet = log.length;
|
|
42
|
+
assert.equal(personAction(null, { playerId: 'p2' }, 'find', opts), false, 'no connection');
|
|
43
|
+
assert.equal(personAction(net, null, 'find', opts), false, 'no person');
|
|
44
|
+
assert.equal(personAction(net, { playerId: null }, 'find', opts), false, 'Find needs someone here');
|
|
45
|
+
assert.equal(personAction(net, { door: 'race' }, 'goto', opts), false);
|
|
46
|
+
assert.equal(personAction(net, { playerId: 'p2' }, 'jump', opts), false, 'a user jump needs a user');
|
|
47
|
+
assert.equal(personAction(net, { playerId: 'p2' }, 'report', opts), false, 'Report is reportPerson');
|
|
48
|
+
assert.equal(log.length, quiet);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// reportPerson
|
|
52
|
+
{
|
|
53
|
+
const said = [];
|
|
54
|
+
const say = (t) => said.push(t);
|
|
55
|
+
const gate = { reporting: false, reportOff: false };
|
|
56
|
+
let resolve;
|
|
57
|
+
const asked = [];
|
|
58
|
+
const report = (id) => {asked.push(id); return new Promise((r) => {resolve = r;});};
|
|
59
|
+
const first = reportPerson({ userId: '9' }, { report, gate, say });
|
|
60
|
+
assert(first && gate.reporting);
|
|
61
|
+
assert.equal(reportPerson({ userId: '10' }, { report, gate, say }), null, 'one at a time');
|
|
62
|
+
resolve({ status: 'ok' }); await first;
|
|
63
|
+
assert.deepEqual(asked, ['9']); assert.deepEqual(said, ['Reported. Thanks.']); assert.equal(gate.reporting, false);
|
|
64
|
+
assert.equal(reportPerson({ userId: null }, { report, gate, say }), null, 'needs a user');
|
|
65
|
+
assert.equal(reportPerson({ userId: '9' }, { report: undefined, gate, say }), null, 'needs the host call');
|
|
66
|
+
await reportPerson({ userId: '9' }, { report: async () => ({ status: 'nope' }), gate, say });
|
|
67
|
+
assert.equal(gate.reportOff, true); assert.equal(said.at(-1), "Reporting isn't available here.");
|
|
68
|
+
gate.reportOff = false;
|
|
69
|
+
await reportPerson({ userId: '9' }, { report: async () => {throw Object.assign(new Error('x'), { code: 'NETWORK' });}, gate, say });
|
|
70
|
+
assert.equal(gate.reportOff, false, 'a failed report may be tried again');
|
|
71
|
+
assert.equal(said.at(-1), "That report didn't go through. Try again later.");
|
|
72
|
+
for (const code of ['UNKNOWN_COMMAND', 'CASTLE_HOST_UNAVAILABLE']) {
|
|
73
|
+
gate.reportOff = false;
|
|
74
|
+
await reportPerson({ userId: '9' }, { report: async () => {throw Object.assign(new Error('x'), { code });}, gate, say });
|
|
75
|
+
assert.equal(gate.reportOff, true, `${code} turns reports off`);
|
|
76
|
+
}
|
|
77
|
+
assert.equal(gate.reporting, false);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// backControl: who shows Back, and its words.
|
|
81
|
+
{
|
|
82
|
+
const town = { id: 'main' }, game = { id: 'race', result: {} };
|
|
83
|
+
const base = { away: false, idle: true, pendingEnd: null, hostTrail: false, place: town, ticket: undefined, kitBack: false };
|
|
84
|
+
const b = (over) => backControl({ ...base, ...over });
|
|
85
|
+
assert.deepEqual(b({}), { show: false, label: 'Again' }, 'a town root has no Back');
|
|
86
|
+
assert.deepEqual(b({ place: game }), { show: true, label: 'Again' }, 'a game played on its own: Again');
|
|
87
|
+
assert.deepEqual(b({ ticket: { title: 'Town' } }), { show: true, label: 'Town' }, 'reached through a door');
|
|
88
|
+
assert.equal(b({ place: game, idle: false }).show, false, 'not during a trip');
|
|
89
|
+
assert.equal(b({ place: game, idle: false, away: true }).show, true, 'away: Back is the only control');
|
|
90
|
+
assert.equal(b({ place: game, pendingEnd: 1 }).show, false, 'not while an end settles');
|
|
91
|
+
assert.equal(b({ place: game, pendingEnd: 0 }).show, false);
|
|
92
|
+
assert.deepEqual(b({ hostTrail: true, place: game }), { show: false, label: 'Again' }, 'the host draws Back');
|
|
93
|
+
assert.deepEqual(b({ hostTrail: true, place: game, kitBack: true }), { show: true, label: 'Back' }, 'old Android landscape host');
|
|
94
|
+
assert.equal(b({ hostTrail: true, place: null, kitBack: true }).show, false, 'no place, no Back');
|
|
95
|
+
assert.deepEqual(b({ hostTrail: true, kitBack: true, ticket: { title: 'Harbour' } }), { show: true, label: 'Harbour' });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// backPress and backRoute: what a Back does.
|
|
99
|
+
assert.equal(backPress({ overflowOpen: true, menuOpen: true, inGame: true }), 'overflow');
|
|
100
|
+
assert.equal(backPress({ overflowOpen: false, menuOpen: true, inGame: true }), 'menu');
|
|
101
|
+
assert.equal(backPress({ overflowOpen: undefined, menuOpen: undefined, inGame: true }), 'quit');
|
|
102
|
+
assert.equal(backPress({ overflowOpen: false, menuOpen: false, inGame: false }), 'back');
|
|
103
|
+
assert.equal(backRoute({ ticket: { hub: true }, hubDepth: 0 }), 'host');
|
|
104
|
+
assert.equal(backRoute({ ticket: undefined, hubDepth: 2 }), 'host');
|
|
105
|
+
assert.equal(backRoute({ ticket: undefined, hubDepth: 0 }), 'instance');
|
|
106
|
+
assert.equal(backRoute({ ticket: undefined, hubDepth: undefined }), 'instance');
|
|
107
|
+
assert.equal(backRoute({ ticket: { scene: 'scenes/main.scene' }, hubDepth: 3 }), 'ticket');
|
|
108
|
+
console.log('Hub controls: People actions, one-at-a-time Report, Back shown and its words, Back press and route passed');
|
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
// Tests for a hub-entry link (code/client/hubEntry.js and its wiring in
|
|
2
|
+
// code/systems/hub.js): `?route=hub-entry&slot=house|door:<id>` on the Town,
|
|
3
|
+
// read once per page load through `Multiplayer.joinHint()`. `npm run check`
|
|
4
|
+
// runs this.
|
|
5
|
+
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import { register } from 'node:module';
|
|
8
|
+
|
|
9
|
+
const sdkStub = `
|
|
10
|
+
export const Hub = globalThis.__entryHub;
|
|
11
|
+
export const User = { getCurrent: async () => globalThis.__entryUser() };
|
|
12
|
+
export const Multiplayer = { joinHint: async () => globalThis.__entryHint() };
|
|
13
|
+
`;
|
|
14
|
+
const packStub = `
|
|
15
|
+
export const loadPack = () => Promise.reject(new Error('no packs here'));
|
|
16
|
+
export const cachedPacks = () => [];
|
|
17
|
+
export const matchesOwn = () => false;
|
|
18
|
+
export const resolveDeckDoor = () => Promise.reject(new Error('no dev decks here'));
|
|
19
|
+
`;
|
|
20
|
+
const mediaStub = 'export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};';
|
|
21
|
+
register(
|
|
22
|
+
'data:text/javascript,' +
|
|
23
|
+
encodeURIComponent(`
|
|
24
|
+
import { readFile } from 'node:fs/promises';
|
|
25
|
+
import { fileURLToPath } from 'node:url';
|
|
26
|
+
export async function resolve(specifier, context, next) {
|
|
27
|
+
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 };
|
|
28
|
+
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 };
|
|
29
|
+
if (specifier === '@imports/castle.real-time/code/client/messages.js') return { url: ${JSON.stringify(new URL('../../real-time/code/client/messages.js', import.meta.url).href)}, shortCircuit: true };
|
|
30
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
|
|
31
|
+
if (specifier === 'castle-web-sdk') return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(sdkStub))}, shortCircuit: true };
|
|
32
|
+
if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(mediaStub))}, shortCircuit: true };
|
|
33
|
+
if (specifier === '../client/pack.js') return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(packStub))}, shortCircuit: true };
|
|
34
|
+
return next(specifier, context);
|
|
35
|
+
}
|
|
36
|
+
export async function load(url, context, next) {
|
|
37
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
38
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
39
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
40
|
+
}
|
|
41
|
+
return next(url, context);
|
|
42
|
+
}`),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const calls = [];
|
|
46
|
+
let hint = null;
|
|
47
|
+
let hintError = null;
|
|
48
|
+
let hints = 0;
|
|
49
|
+
let user = { userId: '101', isAnonymous: false };
|
|
50
|
+
let hostDoors = null;
|
|
51
|
+
globalThis.__entryHint = () => {
|
|
52
|
+
hints += 1;
|
|
53
|
+
if (hintError) {throw hintError;}
|
|
54
|
+
return hint;
|
|
55
|
+
};
|
|
56
|
+
globalThis.__entryUser = () => user;
|
|
57
|
+
globalThis.__entryHub = {
|
|
58
|
+
go: async (doorId, ...options) => { calls.push(['go', doorId, ...options]); return { status: 'full', url: null, nonce: null }; },
|
|
59
|
+
back: async () => ({ status: 'not_found' }),
|
|
60
|
+
cancel: async () => ({ status: 'ok' }),
|
|
61
|
+
doors: async () => { calls.push(['doors']); return hostDoors ?? { status: 'unavailable', doors: null }; },
|
|
62
|
+
onBack: () => () => {},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const { parseHubEntry, planHubEntry, makeHubEntry, HUB_ENTRY_WAIT_MS } = await import('../code/client/hubEntry.js');
|
|
66
|
+
const { installSystem } = await import('../code/systems/hub.js');
|
|
67
|
+
const HubState = await import('../code/client/state.js');
|
|
68
|
+
|
|
69
|
+
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
70
|
+
const flush = async () => { for (let i = 0; i < 6; i += 1) {await tick();} };
|
|
71
|
+
|
|
72
|
+
let n = 0;
|
|
73
|
+
const log = console.log;
|
|
74
|
+
const warn = console.warn;
|
|
75
|
+
console.log = () => {};
|
|
76
|
+
console.warn = () => {};
|
|
77
|
+
async function test(name, fn) {
|
|
78
|
+
try {
|
|
79
|
+
await fn();
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.log = log;
|
|
82
|
+
console.warn = warn;
|
|
83
|
+
console.error(`not ok: ${name}`);
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
n += 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ---- parse and plan ----
|
|
90
|
+
|
|
91
|
+
await test('parse: house, door:<id>, and everything else is nothing', () => {
|
|
92
|
+
assert.deepEqual(parseHubEntry({ routeId: 'hub-entry', slot: 'house' }), { kind: 'house' });
|
|
93
|
+
assert.deepEqual(parseHubEntry({ routeId: 'hub-entry', slot: 'door:door-prism' }), { kind: 'door', door: 'door-prism' });
|
|
94
|
+
for (const bad of [null, undefined, 'house', {}, { routeId: 'town', slot: 'house' }, { routeId: 'hub-entry', slot: 'garden' },
|
|
95
|
+
{ routeId: 'hub-entry', slot: 'door:' }, { routeId: 'hub-entry', slot: 'door:a b' }, { routeId: 'hub-entry', slot: 7 },
|
|
96
|
+
{ routeId: 'hub-entry', slot: `door:${'x'.repeat(65)}` }]) {
|
|
97
|
+
assert.equal(parseHubEntry(bad), null, JSON.stringify(bad));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const listed = [
|
|
102
|
+
{ id: 'home-1', title: 'Home' }, { id: 'home-2', title: 'Home' },
|
|
103
|
+
{ id: 'door-prism', title: 'Prism', solo: true }, { id: 'door-duo', title: 'Duo Dash', need: 2 },
|
|
104
|
+
{ id: 'door-plaza', title: 'Plaza' },
|
|
105
|
+
];
|
|
106
|
+
const homes = ['home-2', 'home-1'];
|
|
107
|
+
|
|
108
|
+
await test('plan: house goes through the nearest listed House door for a signed-in player', () => {
|
|
109
|
+
assert.deepEqual(planHubEntry({ kind: 'house' }, { listed, homes, guest: false }), { go: { door: 'home-2', title: 'Home' } });
|
|
110
|
+
const host = new Map([['home-2', { doorId: 'home-2', placementKind: 'owner', enabled: false }]]);
|
|
111
|
+
assert.deepEqual(planHubEntry({ kind: 'house' }, { listed, homes, host, guest: false }), { go: { door: 'home-1', title: 'Home' } }, 'a disabled one is skipped');
|
|
112
|
+
assert.equal(planHubEntry({ kind: 'house' }, { listed: [], homes, guest: false }), null, 'no listed House door: stay');
|
|
113
|
+
assert.equal(planHubEntry({ kind: 'house' }, { listed, homes: [], guest: false }), null);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await test('plan: a guest stays in the Town with a toast; an unknown account stays quietly', () => {
|
|
117
|
+
assert.deepEqual(planHubEntry({ kind: 'house' }, { listed, homes, guest: true }), { toast: 'Sign in to have a House of your own' });
|
|
118
|
+
assert.equal(planHubEntry({ kind: 'house' }, { listed, homes, guest: null }), null);
|
|
119
|
+
assert.deepEqual(planHubEntry({ kind: 'door', door: 'home-1' }, { listed, homes, guest: true }), { toast: 'Sign in to have a House of your own' });
|
|
120
|
+
assert.deepEqual(planHubEntry({ kind: 'door', door: 'home-1' }, { listed, homes, guest: false }), { go: { door: 'home-1', title: 'Home' } }, 'a named House door is that House door');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
await test('plan: doors -- pad doors are the Doors list jump, layer/exact solo doors a trip', () => {
|
|
124
|
+
const me = { listed, homes, guest: false };
|
|
125
|
+
assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-prism' }, me), { jump: listed[2], toast: null }, 'no host rows: onto the pad');
|
|
126
|
+
const host = new Map([
|
|
127
|
+
['door-prism', { doorId: 'door-prism', placementKind: 'pad', enabled: true }],
|
|
128
|
+
['door-plaza', { doorId: 'door-plaza', placementKind: 'layer', enabled: true }],
|
|
129
|
+
['door-duo', { doorId: 'door-duo', placementKind: 'layer', enabled: true }],
|
|
130
|
+
]);
|
|
131
|
+
assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-prism' }, { ...me, host }), { jump: listed[2], toast: null }, 'a pad takes only a fired group');
|
|
132
|
+
assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-plaza' }, { ...me, host }), { go: { door: 'door-plaza', title: 'Plaza' } });
|
|
133
|
+
assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-duo' }, { ...me, host }),
|
|
134
|
+
{ jump: listed[3], toast: 'Duo Dash needs 2 players · wait on the pad for others' }, 'a pair door is never a solo trip');
|
|
135
|
+
assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-plaza' }, { ...me, host: new Map([['door-plaza', { placementKind: 'layer', enabled: false }]]) }),
|
|
136
|
+
{ toast: 'Plaza is closed right now' });
|
|
137
|
+
assert.equal(planHubEntry({ kind: 'door', door: 'door-nope' }, { ...me, host }), null, 'an unknown door is ignored');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
await test('plan: a guest never trips or jumps for a door link; an unknown account stays quietly', () => {
|
|
141
|
+
const host = new Map([
|
|
142
|
+
['door-prism', { doorId: 'door-prism', placementKind: 'pad', enabled: true }],
|
|
143
|
+
['door-plaza', { doorId: 'door-plaza', placementKind: 'layer', enabled: true }],
|
|
144
|
+
]);
|
|
145
|
+
assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-plaza' }, { listed, homes, host, guest: true }), { toast: 'Plaza is in the Town · sign in to play' });
|
|
146
|
+
assert.deepEqual(planHubEntry({ kind: 'door', door: 'door-prism' }, { listed, homes, host, guest: true }), { toast: 'Prism is in the Town · sign in to play' });
|
|
147
|
+
assert.equal(planHubEntry({ kind: 'door', door: 'door-plaza' }, { listed, homes, host, guest: null }), null);
|
|
148
|
+
assert.equal(planHubEntry({ kind: 'door', door: 'door-nope' }, { listed, homes, host, guest: true }), null, 'an unknown door is still silent');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// ---- the once-per-load state ----
|
|
152
|
+
|
|
153
|
+
await test('state: asks once, waits for settled, acts once; later frames do nothing', async () => {
|
|
154
|
+
let asked = 0;
|
|
155
|
+
const acted = [];
|
|
156
|
+
const entry = makeHubEntry({ joinHint: async () => { asked += 1; return { routeId: 'hub-entry', slot: 'house' }; }, act: (t) => acted.push(t) });
|
|
157
|
+
const net = {};
|
|
158
|
+
entry.frame({ known: false, root: true, net });
|
|
159
|
+
assert.equal(asked, 0, 'not before the place is named');
|
|
160
|
+
entry.frame({ known: true, root: true, net });
|
|
161
|
+
await flush();
|
|
162
|
+
entry.frame({ known: true, root: true, net, settled: false });
|
|
163
|
+
await flush();
|
|
164
|
+
assert.equal(acted.length, 0);
|
|
165
|
+
entry.frame({ known: true, root: true, net, settled: true });
|
|
166
|
+
await flush();
|
|
167
|
+
assert.deepEqual(acted, [{ kind: 'house' }]);
|
|
168
|
+
for (let i = 0; i < 3; i++) { entry.frame({ known: true, root: true, net, settled: true }); await flush(); }
|
|
169
|
+
assert.equal(asked, 1);
|
|
170
|
+
assert.equal(acted.length, 1);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
await test('state: a trip, an invite, a session swap or a timeout spends it', async () => {
|
|
174
|
+
const cases = [
|
|
175
|
+
(e, net) => e.frame({ known: true, root: false, net, settled: true }),
|
|
176
|
+
(e, net) => e.frame({ known: true, root: true, net, invited: true, settled: true }),
|
|
177
|
+
(e) => e.frame({ known: true, root: true, net: {}, settled: true }),
|
|
178
|
+
];
|
|
179
|
+
for (const spend of cases) {
|
|
180
|
+
const acted = [];
|
|
181
|
+
const entry = makeHubEntry({ joinHint: async () => ({ routeId: 'hub-entry', slot: 'house' }), act: (t) => acted.push(t) });
|
|
182
|
+
const net = {};
|
|
183
|
+
entry.frame({ known: true, root: true, net });
|
|
184
|
+
await flush();
|
|
185
|
+
spend(entry, net);
|
|
186
|
+
entry.frame({ known: true, root: true, net, settled: true });
|
|
187
|
+
await flush();
|
|
188
|
+
assert.equal(acted.length, 0);
|
|
189
|
+
assert.equal(entry.state(), 'done');
|
|
190
|
+
}
|
|
191
|
+
let clock = 0;
|
|
192
|
+
const acted = [];
|
|
193
|
+
const late = makeHubEntry({ joinHint: async () => ({ routeId: 'hub-entry', slot: 'house' }), act: (t) => acted.push(t), now: () => clock });
|
|
194
|
+
late.frame({ known: true, root: true, net: {} });
|
|
195
|
+
await flush();
|
|
196
|
+
clock = HUB_ENTRY_WAIT_MS + 1;
|
|
197
|
+
late.frame({ known: true, root: true, settled: true });
|
|
198
|
+
await flush();
|
|
199
|
+
assert.equal(acted.length, 0, 'no late surprise trip');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
await test('state: an old host (UNKNOWN_COMMAND, a throw) or no hint ends quietly', async () => {
|
|
203
|
+
for (const joinHint of [async () => { throw Object.assign(new Error('x'), { code: 'UNKNOWN_COMMAND' }); }, () => { throw new Error('sync'); }, async () => null, undefined]) {
|
|
204
|
+
const acted = [];
|
|
205
|
+
const entry = makeHubEntry({ joinHint, act: (t) => acted.push(t) });
|
|
206
|
+
entry.frame({ known: true, root: true, net: {} });
|
|
207
|
+
await flush();
|
|
208
|
+
entry.frame({ known: true, root: true, net: {}, settled: true });
|
|
209
|
+
await flush();
|
|
210
|
+
assert.equal(acted.length, 0);
|
|
211
|
+
assert.equal(entry.state(), 'done');
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
await test('state: the root place going away while deciding cancels the act', async () => {
|
|
216
|
+
const acted = [];
|
|
217
|
+
let release;
|
|
218
|
+
const entry = makeHubEntry({ joinHint: async () => ({ routeId: 'hub-entry', slot: 'door:door-prism' }), act: (t) => acted.push(t),
|
|
219
|
+
extras: () => new Promise((resolve) => { release = resolve; }) });
|
|
220
|
+
const net = {};
|
|
221
|
+
entry.frame({ known: true, root: true, net });
|
|
222
|
+
await flush();
|
|
223
|
+
entry.frame({ known: true, root: true, net, settled: true });
|
|
224
|
+
await flush();
|
|
225
|
+
entry.frame({ known: true, root: false, net, settled: true });
|
|
226
|
+
release({});
|
|
227
|
+
await flush();
|
|
228
|
+
assert.equal(acted.length, 0);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
await test('state: a re-admission or new player id on the same net spends it', async () => {
|
|
232
|
+
for (const change of [{ epoch: 1 }, { selfId: 'p2' }]) {
|
|
233
|
+
const acted = [];
|
|
234
|
+
const entry = makeHubEntry({ joinHint: async () => ({ routeId: 'hub-entry', slot: 'house' }), act: (t) => acted.push(t) });
|
|
235
|
+
const net = {};
|
|
236
|
+
entry.frame({ known: true, root: true, net, selfId: 'p1', epoch: 0 });
|
|
237
|
+
await flush();
|
|
238
|
+
entry.frame({ known: true, root: true, net, selfId: 'p1', epoch: 0, ...change, settled: true });
|
|
239
|
+
await flush();
|
|
240
|
+
assert.equal(acted.length, 0, JSON.stringify(change));
|
|
241
|
+
assert.equal(entry.state(), 'done');
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
await test('state: the context is checked again after the lookup; held meanwhile waits, a new epoch spends', async () => {
|
|
246
|
+
const net = {};
|
|
247
|
+
let now = { known: true, root: true, net, selfId: 'p1', epoch: 0, settled: true };
|
|
248
|
+
let release;
|
|
249
|
+
const acted = [];
|
|
250
|
+
const entry = makeHubEntry({ joinHint: async () => ({ routeId: 'hub-entry', slot: 'house' }), act: (t) => acted.push(t),
|
|
251
|
+
extras: () => new Promise((resolve) => { release = resolve; }), current: () => now });
|
|
252
|
+
entry.frame(now);
|
|
253
|
+
await flush();
|
|
254
|
+
entry.frame(now);
|
|
255
|
+
await flush();
|
|
256
|
+
now = { ...now, settled: false };
|
|
257
|
+
release({});
|
|
258
|
+
await flush();
|
|
259
|
+
assert.equal(acted.length, 0, 'held during the lookup: not yet');
|
|
260
|
+
assert.equal(entry.state(), 'ready');
|
|
261
|
+
now = { ...now, settled: true };
|
|
262
|
+
entry.frame(now);
|
|
263
|
+
await flush();
|
|
264
|
+
release({});
|
|
265
|
+
await flush();
|
|
266
|
+
assert.deepEqual(acted, [{ kind: 'house' }], 'acts once settled again');
|
|
267
|
+
|
|
268
|
+
const spent = [];
|
|
269
|
+
let now2 = { known: true, root: true, net, selfId: 'p1', epoch: 0, settled: true };
|
|
270
|
+
const other = makeHubEntry({ joinHint: async () => ({ routeId: 'hub-entry', slot: 'house' }), act: (t) => spent.push(t),
|
|
271
|
+
extras: () => new Promise((resolve) => { release = resolve; }), current: () => now2 });
|
|
272
|
+
other.frame(now2);
|
|
273
|
+
await flush();
|
|
274
|
+
other.frame(now2);
|
|
275
|
+
await flush();
|
|
276
|
+
now2 = { ...now2, epoch: 1 };
|
|
277
|
+
release({});
|
|
278
|
+
await flush();
|
|
279
|
+
assert.equal(spent.length, 0);
|
|
280
|
+
assert.equal(other.state(), 'done');
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// ---- the system ----
|
|
284
|
+
|
|
285
|
+
function setup({ slot = 'house', depth = 0, target = { mode: 'public' } } = {}) {
|
|
286
|
+
let system;
|
|
287
|
+
installSystem({ registerSystem: (s) => (system = s) });
|
|
288
|
+
HubState.clear();
|
|
289
|
+
calls.length = 0;
|
|
290
|
+
hints = 0;
|
|
291
|
+
hint = slot === null ? null : { routeId: 'hub-entry', slot };
|
|
292
|
+
hintError = null;
|
|
293
|
+
user = { userId: '101', isAnonymous: false };
|
|
294
|
+
hostDoors = null;
|
|
295
|
+
const sent = [];
|
|
296
|
+
const net = { selfId: () => 'p1', send: (m) => sent.push(m), closed: () => false };
|
|
297
|
+
const actors = new Map([
|
|
298
|
+
['me', { id: 'me', components: { Player: {}, Transform: { x: 0, z: 0 } } }],
|
|
299
|
+
['d1', { id: 'd1', components: { HubDoor: { id: 'home-1', to: 'deck:house' }, Transform: { x: 30, z: 0 } } }],
|
|
300
|
+
['d2', { id: 'd2', components: { HubDoor: { id: 'home-2', to: 'deck:house' }, Transform: { x: 5, z: 0 } } }],
|
|
301
|
+
['d3', { id: 'd3', components: { HubDoor: { id: 'door-prism', to: 'deck:prism' }, Transform: { x: 0, z: 9 } } }],
|
|
302
|
+
]);
|
|
303
|
+
const scene = {
|
|
304
|
+
persistent: { hubTickets: [], ...(depth ? { hubDepth: depth } : {}) },
|
|
305
|
+
multiplayer: { target, net, placed: () => true },
|
|
306
|
+
content: null,
|
|
307
|
+
files: {},
|
|
308
|
+
actors,
|
|
309
|
+
actorWith: (c) => [...actors.values()].find((a) => a.components[c]) ?? null,
|
|
310
|
+
getActor: (id) => actors.get(id) ?? null,
|
|
311
|
+
getActors: () => [...actors.values()],
|
|
312
|
+
setContent() {},
|
|
313
|
+
};
|
|
314
|
+
system.chrome = { setCover() {}, showBack() {}, setToast() {} };
|
|
315
|
+
system.scenePath = 'scenes/main.scene';
|
|
316
|
+
system.scene = scene;
|
|
317
|
+
system.helloNet = net;
|
|
318
|
+
HubState.hub.place = { id: 'main', title: 'Town', result: null };
|
|
319
|
+
HubState.hub.doors = listed;
|
|
320
|
+
const local = scene.actorWith('Player');
|
|
321
|
+
const frame = async (times = 3) => {
|
|
322
|
+
for (let i = 0; i < times; i++) {
|
|
323
|
+
system.hubEntryFrame(scene, scene.multiplayer, local);
|
|
324
|
+
await flush();
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
return { system, scene, net, sent, frame };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
await test('system: slot=house trips a signed-in player to their own House by the nearest Home door, once', async () => {
|
|
331
|
+
const { system, frame } = setup();
|
|
332
|
+
await frame();
|
|
333
|
+
assert.equal(hints, 1);
|
|
334
|
+
assert.deepEqual(calls.filter((c) => c[0] === 'go'), [['go', 'home-2']], 'own House: no owner');
|
|
335
|
+
assert.ok(system.trip, 'a trip is under way');
|
|
336
|
+
system.trip = null;
|
|
337
|
+
await frame();
|
|
338
|
+
assert.equal(hints, 1, 'joinHint is read once per load');
|
|
339
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 1, 'never again after the trip');
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
await test('system: a guest stays in the Town with a toast', async () => {
|
|
343
|
+
const { system, frame, sent } = setup();
|
|
344
|
+
user = { userId: '777', isAnonymous: true };
|
|
345
|
+
await frame();
|
|
346
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
|
|
347
|
+
assert.equal(system.trip, null);
|
|
348
|
+
assert.equal(system.toast.text, 'Sign in to have a House of your own');
|
|
349
|
+
assert.equal(sent.length, 0);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
await test('system: slot=door:<pad door> is the Doors list jump onto its pad', async () => {
|
|
353
|
+
const { system, frame, sent } = setup({ slot: 'door:door-prism' });
|
|
354
|
+
hostDoors = { status: 'ok', doors: [{ doorId: 'door-prism', placementKind: 'pad', enabled: true }] };
|
|
355
|
+
await frame();
|
|
356
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
357
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0, 'ghost would refuse Hub.go on an unfired pad');
|
|
358
|
+
assert.deepEqual(sent.filter((m) => m.k === 'hub-door-jump'), [{ k: 'hub-door-jump', door: 'door-prism' }]);
|
|
359
|
+
assert.match(system.toast.text, /Prism/);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
await test('system: a pair door jumps to its pad and says it needs players', async () => {
|
|
363
|
+
const { system, frame, sent } = setup({ slot: 'door:door-duo' });
|
|
364
|
+
await frame();
|
|
365
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
366
|
+
assert.deepEqual(sent.filter((m) => m.k === 'hub-door-jump'), [{ k: 'hub-door-jump', door: 'door-duo' }]);
|
|
367
|
+
assert.equal(system.toast.text, 'Duo Dash needs 2 players · wait on the pad for others');
|
|
368
|
+
assert.equal(system.trip, null);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
await test('system: a solo layer door is a trip through it', async () => {
|
|
372
|
+
const { system, frame } = setup({ slot: 'door:door-plaza' });
|
|
373
|
+
hostDoors = { status: 'ok', doors: [{ doorId: 'door-plaza', placementKind: 'layer', enabled: true }] };
|
|
374
|
+
await frame();
|
|
375
|
+
assert.deepEqual(calls.filter((c) => c[0] === 'go'), [['go', 'door-plaza']]);
|
|
376
|
+
assert.ok(system.trip);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
await test('system: an invite arrival wins over the link', async () => {
|
|
380
|
+
const { system, frame, sent } = setup();
|
|
381
|
+
system.invites = { carried: () => true, dispose() {}, frame() {} };
|
|
382
|
+
await frame();
|
|
383
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
|
|
384
|
+
assert.equal(sent.length, 0);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
await test('system: not at the root (behind a door, a hub join, a trip already) never reads the hint', async () => {
|
|
388
|
+
for (const opts of [{ depth: 1 }, { target: { mode: 'hub', handoff: {} } }]) {
|
|
389
|
+
const { frame } = setup(opts);
|
|
390
|
+
await frame();
|
|
391
|
+
assert.equal(hints, 0, JSON.stringify(opts));
|
|
392
|
+
assert.equal(calls.length, 0);
|
|
393
|
+
}
|
|
394
|
+
const { system, frame } = setup();
|
|
395
|
+
system.tripCount = 1;
|
|
396
|
+
await frame();
|
|
397
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
|
|
398
|
+
const game = setup();
|
|
399
|
+
HubState.hub.place = { id: 'main', title: 'Race', result: { kind: 'score' } };
|
|
400
|
+
await game.frame();
|
|
401
|
+
assert.equal(hints, 0, 'a game is not the Town');
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
await test('system: unknown slots and old hosts change nothing', async () => {
|
|
405
|
+
for (const slot of ['garden', 'door:door-nope', null]) {
|
|
406
|
+
const { system, frame, sent } = setup({ slot });
|
|
407
|
+
await frame();
|
|
408
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
|
|
409
|
+
assert.equal(sent.length, 0);
|
|
410
|
+
assert.equal(system.toast.text, '');
|
|
411
|
+
}
|
|
412
|
+
const { system, frame } = setup();
|
|
413
|
+
hintError = Object.assign(new Error('unknown'), { code: 'UNKNOWN_COMMAND' });
|
|
414
|
+
await frame();
|
|
415
|
+
assert.equal(calls.length, 0);
|
|
416
|
+
assert.equal(system.trip, null);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
await test('system: a reconnect on a new connection before placement spends it', async () => {
|
|
420
|
+
const { system, scene, frame } = setup();
|
|
421
|
+
system.helloNet = null;
|
|
422
|
+
await frame(1);
|
|
423
|
+
const fresh = { selfId: () => 'p9', send() {}, closed: () => false };
|
|
424
|
+
scene.multiplayer.net = fresh;
|
|
425
|
+
system.helloNet = fresh;
|
|
426
|
+
await frame();
|
|
427
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
await test('system: a guest with a door link stays in the Town, told where the door is', async () => {
|
|
431
|
+
for (const [slot, title, doors] of [['door:door-plaza', 'Plaza', [{ doorId: 'door-plaza', placementKind: 'layer', enabled: true }]],
|
|
432
|
+
['door:door-prism', 'Prism', [{ doorId: 'door-prism', placementKind: 'pad', enabled: true }]]]) {
|
|
433
|
+
const { system, frame, sent } = setup({ slot });
|
|
434
|
+
user = { userId: '777', isAnonymous: true };
|
|
435
|
+
hostDoors = { status: 'ok', doors };
|
|
436
|
+
await frame();
|
|
437
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0, slot);
|
|
438
|
+
assert.equal(sent.filter((m) => m.k === 'hub-door-jump').length, 0, slot);
|
|
439
|
+
assert.equal(system.trip, null);
|
|
440
|
+
assert.equal(system.toast.text, `${title} is in the Town · sign in to play`);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
await test('system: a reconnect on the same net (re-admission or new player id) spends it', async () => {
|
|
445
|
+
{
|
|
446
|
+
const { system, frame } = setup();
|
|
447
|
+
system.helloNet = null;
|
|
448
|
+
await frame(1);
|
|
449
|
+
system.admitEpoch = 1; // what sayHello does on a re-admission it sees
|
|
450
|
+
system.helloNet = system.scene.multiplayer.net;
|
|
451
|
+
await frame();
|
|
452
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0, 'epoch');
|
|
453
|
+
}
|
|
454
|
+
{
|
|
455
|
+
const { system, net, frame } = setup();
|
|
456
|
+
system.helloNet = null;
|
|
457
|
+
await frame(1);
|
|
458
|
+
net.selfId = () => 'p2';
|
|
459
|
+
system.helloNet = net;
|
|
460
|
+
await frame();
|
|
461
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0, 'selfId');
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
await test('system: a held player is not jumped; the link waits for the hold to end', async () => {
|
|
466
|
+
const { system, frame, sent } = setup({ slot: 'door:door-prism' });
|
|
467
|
+
HubState.hub.held.add('p1');
|
|
468
|
+
await frame(4);
|
|
469
|
+
assert.equal(sent.filter((m) => m.k === 'hub-door-jump').length, 0, 'the server would refuse a held jump');
|
|
470
|
+
assert.notEqual(system.hubEntry.state(), 'done', 'not spent while held');
|
|
471
|
+
HubState.hub.held.delete('p1');
|
|
472
|
+
await frame();
|
|
473
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
474
|
+
assert.deepEqual(sent.filter((m) => m.k === 'hub-door-jump'), [{ k: 'hub-door-jump', door: 'door-prism' }]);
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
await test('system: held during the doors lookup waits; acts once the hold ends', async () => {
|
|
478
|
+
const { frame, sent } = setup({ slot: 'door:door-prism' });
|
|
479
|
+
let release;
|
|
480
|
+
const doors = globalThis.__entryHub.doors;
|
|
481
|
+
globalThis.__entryHub.doors = () => new Promise((resolve) => { release = resolve; });
|
|
482
|
+
try {
|
|
483
|
+
await frame(2);
|
|
484
|
+
assert.ok(release, 'lookup started');
|
|
485
|
+
HubState.hub.held.add('p1');
|
|
486
|
+
release({ status: 'ok', doors: [{ doorId: 'door-prism', placementKind: 'pad', enabled: true }] });
|
|
487
|
+
await flush();
|
|
488
|
+
assert.equal(sent.filter((m) => m.k === 'hub-door-jump').length, 0);
|
|
489
|
+
HubState.hub.held.delete('p1');
|
|
490
|
+
release = null;
|
|
491
|
+
await frame(2);
|
|
492
|
+
release?.({ status: 'ok', doors: [{ doorId: 'door-prism', placementKind: 'pad', enabled: true }] });
|
|
493
|
+
await flush();
|
|
494
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
495
|
+
assert.deepEqual(sent.filter((m) => m.k === 'hub-door-jump'), [{ k: 'hub-door-jump', door: 'door-prism' }]);
|
|
496
|
+
} finally {
|
|
497
|
+
globalThis.__entryHub.doors = doors;
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
await test('system: a re-admission while the first hello waits (an invite check) spends it', async () => {
|
|
502
|
+
const { system, scene, net, frame } = setup();
|
|
503
|
+
const queue = [];
|
|
504
|
+
net.drain = () => queue.splice(0);
|
|
505
|
+
scene.multiplayer.joined = true; // the join's own WORLD is already drained
|
|
506
|
+
system.helloNet = null; // the invite check holds the first hello back
|
|
507
|
+
await frame(2);
|
|
508
|
+
assert.equal(hints, 1, 'the hint is pending');
|
|
509
|
+
queue.push({ k: 'w' }); // the session gives this connection a body again
|
|
510
|
+
net.drain();
|
|
511
|
+
system.helloNet = net;
|
|
512
|
+
await frame();
|
|
513
|
+
assert.equal(calls.filter((c) => c[0] === 'go').length, 0, 'no House trip after a re-admission');
|
|
514
|
+
assert.equal(system.hubEntry.state(), 'done');
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
await test('system: without a re-admission the delayed first hello still acts', async () => {
|
|
518
|
+
const { system, scene, net, frame } = setup();
|
|
519
|
+
net.drain = () => [];
|
|
520
|
+
scene.multiplayer.joined = true;
|
|
521
|
+
system.helloNet = null;
|
|
522
|
+
await frame(2);
|
|
523
|
+
net.drain();
|
|
524
|
+
system.helloNet = net;
|
|
525
|
+
await frame();
|
|
526
|
+
assert.deepEqual(calls.filter((c) => c[0] === 'go'), [['go', 'home-2']]);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
console.log = log;
|
|
530
|
+
console.warn = warn;
|
|
531
|
+
console.log(`ok: ${n} hub-entry tests`);
|