castle-web-cli 0.4.229 → 0.4.230
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-prompts.d.ts +2 -0
- package/dist/agent-prompts.js +16 -8
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +21 -21
- package/dist/api.d.ts +28 -2
- package/dist/api.js +74 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +779 -3
- package/dist/castleJson.d.ts +44 -0
- package/dist/castleJson.js +131 -0
- package/dist/check.js +27 -1
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSessionChild.js +3 -1
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +229 -44
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +141 -31
- package/dist/index.js +3 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +125 -8
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +142 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +94 -13
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/webSourceSync.d.ts +2 -0
- package/dist/webSourceSync.js +2 -0
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +258 -52
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +5 -0
- package/kits/base/sdk/castle.js +3 -0
- package/kits/base/sdk/commands.d.ts +208 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +45 -1
- package/kits/base/sdk/multiplayer.js +106 -4
- package/kits/base/sdk/server/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +42 -1
- package/kits/base/sdk/server/storage.d.ts +55 -2
- package/kits/base/sdk/server/wrapper.d.ts +32 -2
- package/kits/base/sdk/server/wrapper.js +90 -11
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +146 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1001 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +241 -0
- package/kits/hub-game/code/client/hookLayer.js +230 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +131 -0
- package/kits/hub-game/code/client/talk.js +259 -0
- package/kits/hub-game/code/client/together.js +365 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +247 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1904 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +527 -0
- package/kits/hub-game/code/server/npcs.js +745 -0
- package/kits/hub-game/code/server/party.js +381 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2230 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1139 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +224 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +714 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +286 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-together.mjs +183 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +25 -5
- package/kits/physics-3d/CLAUDE.md +6 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/world3d.js +65 -1
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
// Arcade cabinets (contract v1.7): a door whose board carries `classic`.
|
|
2
|
+
// Server: `doors()` says so, `hub.go` tells the player's client rather than
|
|
3
|
+
// firing a pad, ghost is never asked to hold a cabinet's pad, the card goes
|
|
4
|
+
// to a player in range once per version inside a frame the host will carry,
|
|
5
|
+
// and the dev fixture. Client: the trip covers, leaves the session and waits
|
|
6
|
+
// (away); Back is the ordinary way back; every failure leaves a working
|
|
7
|
+
// state. `npm run check` runs it; it needs nothing installed.
|
|
8
|
+
|
|
9
|
+
import assert from 'node:assert/strict';
|
|
10
|
+
import { register } from 'node:module';
|
|
11
|
+
|
|
12
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
13
|
+
const sdkStub = 'export const Hub = globalThis.__tripHub;';
|
|
14
|
+
const packStub = `
|
|
15
|
+
export const loadPack = (...args) => globalThis.__tripLoadPack(...args);
|
|
16
|
+
export const cachedPacks = () => [];
|
|
17
|
+
export const matchesOwn = () => true;
|
|
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
|
+
const url = (code) => JSON.stringify('data:text/javascript,' + encodeURIComponent(code));
|
|
22
|
+
register(
|
|
23
|
+
'data:text/javascript,' +
|
|
24
|
+
encodeURIComponent(`
|
|
25
|
+
export async function resolve(specifier, context, next) {
|
|
26
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') {
|
|
27
|
+
return { url: ${url(sceneStub)}, shortCircuit: true };
|
|
28
|
+
}
|
|
29
|
+
if (specifier === 'castle-web-sdk') {
|
|
30
|
+
return { url: ${url(sdkStub)}, shortCircuit: true };
|
|
31
|
+
}
|
|
32
|
+
if (specifier.startsWith('@imports/castle.physics-2d/engine/')) {
|
|
33
|
+
return { url: ${url(mediaStub)}, shortCircuit: true };
|
|
34
|
+
}
|
|
35
|
+
if (specifier === '../client/pack.js') {
|
|
36
|
+
return { url: ${url(packStub)}, shortCircuit: true };
|
|
37
|
+
}
|
|
38
|
+
return next(specifier, context);
|
|
39
|
+
}`),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const calls = [];
|
|
43
|
+
const answers = {};
|
|
44
|
+
globalThis.__tripHub = {
|
|
45
|
+
go: async (doorId) => {
|
|
46
|
+
calls.push(['go', doorId]);
|
|
47
|
+
if (answers.goWait) {
|
|
48
|
+
await answers.goWait;
|
|
49
|
+
}
|
|
50
|
+
return answers.go;
|
|
51
|
+
},
|
|
52
|
+
back: async () => {
|
|
53
|
+
calls.push(['back']);
|
|
54
|
+
return answers.backs?.length ? answers.backs.shift() : answers.back;
|
|
55
|
+
},
|
|
56
|
+
cancel: async () => {
|
|
57
|
+
calls.push(['cancel']);
|
|
58
|
+
return { status: 'ok' };
|
|
59
|
+
},
|
|
60
|
+
onBack: () => () => {},
|
|
61
|
+
};
|
|
62
|
+
globalThis.__tripLoadPack = async (sha) => ({ id: `pack-${sha}`, sha256: sha, bytes: 10, ms: 1, cached: false, places: { main: { scene: 'scenes/main.scene', title: 'Town' } } });
|
|
63
|
+
|
|
64
|
+
const { layer } = await import('../code/server/hub.js');
|
|
65
|
+
const Cabinets = await import('../code/server/cabinets.js');
|
|
66
|
+
const { installSystem } = await import('../code/systems/hub.js');
|
|
67
|
+
const HubState = await import('../code/client/state.js');
|
|
68
|
+
const ClientCabinets = await import('../code/client/cabinets.js');
|
|
69
|
+
|
|
70
|
+
const warn = console.warn;
|
|
71
|
+
const log = console.log;
|
|
72
|
+
console.warn = () => {};
|
|
73
|
+
console.log = () => {};
|
|
74
|
+
let n = 0;
|
|
75
|
+
async function test(name, fn) {
|
|
76
|
+
try {
|
|
77
|
+
await fn();
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.warn = warn;
|
|
80
|
+
console.log = log;
|
|
81
|
+
console.error(`not ok: ${name}`);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
n += 1;
|
|
85
|
+
}
|
|
86
|
+
const flush = async () => {
|
|
87
|
+
for (let i = 0; i < 6; i += 1) {
|
|
88
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// ---- the place's server ----
|
|
93
|
+
|
|
94
|
+
globalThis.__hubTestActors = [
|
|
95
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
96
|
+
{ id: 'race-door', components: { HubDoor: { id: 'race', to: 'deck:race', title: 'Foot Race' }, Transform: { x: 50, y: 0, z: 50 } } },
|
|
97
|
+
{ id: 'cab-a-screen', components: { HubDoor: { id: 'cab-a', to: 'deck:classic', kind: 'cabinet', title: 'Friction' }, Transform: { x: 5, y: 1.4, z: 0 } } },
|
|
98
|
+
{ id: 'cab-b-screen', components: { HubDoor: { id: 'cab-b', to: 'deck:classic', kind: 'cabinet', title: 'Sentencle' }, Transform: { x: 100, y: 1.4, z: 0 } } },
|
|
99
|
+
];
|
|
100
|
+
const castleJson = { server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Town' } };
|
|
101
|
+
const PLAYERS = [
|
|
102
|
+
{ playerId: 'p1', userId: '101', username: 'ada', isAnonymous: false },
|
|
103
|
+
{ playerId: 'p2', userId: '102', username: 'bo', isAnonymous: false },
|
|
104
|
+
{ playerId: 'p3', userId: 'anon-1', username: 'guest', isAnonymous: true },
|
|
105
|
+
];
|
|
106
|
+
const PNG = (bytes) => `data:image/png;base64,${'A'.repeat(bytes)}`;
|
|
107
|
+
const classicBoard = (extra = {}) => ({
|
|
108
|
+
toDeckId: 'classic-1',
|
|
109
|
+
title: 'Gimme Friction Baby',
|
|
110
|
+
top: [],
|
|
111
|
+
classic: {
|
|
112
|
+
deckId: 'classic-1',
|
|
113
|
+
title: 'Gimme Friction Baby',
|
|
114
|
+
label: 'Daily Score',
|
|
115
|
+
daily: true,
|
|
116
|
+
better: 'higher',
|
|
117
|
+
cover: PNG(5000),
|
|
118
|
+
top: [
|
|
119
|
+
{ username: 'ada', score: '12.3K', photo: PNG(1000), frame: PNG(2500) },
|
|
120
|
+
{ username: 'zed', score: '9.1K', photo: null, frame: null },
|
|
121
|
+
],
|
|
122
|
+
...extra,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
function boot({ sessionId = 's-1', boards = null, hidden = null } = {}) {
|
|
127
|
+
const sent = [];
|
|
128
|
+
const hubCalls = [];
|
|
129
|
+
const hub = boards
|
|
130
|
+
? {
|
|
131
|
+
arrival: () => null,
|
|
132
|
+
async updatePad(input) {
|
|
133
|
+
hubCalls.push(['pad', input]);
|
|
134
|
+
return { status: 'gathering', members: [] };
|
|
135
|
+
},
|
|
136
|
+
async readResults(input) {
|
|
137
|
+
hubCalls.push(['read', input]);
|
|
138
|
+
const out = {};
|
|
139
|
+
for (const id of input.doorIds ?? []) {
|
|
140
|
+
if (boards[id]) {
|
|
141
|
+
out[id] = boards[id];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return { players: {}, boards: out };
|
|
145
|
+
},
|
|
146
|
+
...(hidden ? { hiddenPair: hidden } : {}),
|
|
147
|
+
}
|
|
148
|
+
: null;
|
|
149
|
+
const session = { sessionId, place: null, players: PLAYERS, hub, send: (playerId, data) => sent.push([playerId, data]), broadcast() {} };
|
|
150
|
+
let ctx = null;
|
|
151
|
+
const h = layer(castleJson, { ready: (c) => (ctx = c) }, {}, () => true);
|
|
152
|
+
h.sceneFor(session);
|
|
153
|
+
const players = new Map();
|
|
154
|
+
for (const { playerId } of PLAYERS) {
|
|
155
|
+
players.set(playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
156
|
+
}
|
|
157
|
+
const world = { timeMs: 0, players, bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
158
|
+
h.ready(world);
|
|
159
|
+
for (const { playerId } of PLAYERS) {
|
|
160
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar: 0, party: 1 });
|
|
161
|
+
}
|
|
162
|
+
const tick = async () => {
|
|
163
|
+
world.timeMs += 5000;
|
|
164
|
+
h.place(world, []);
|
|
165
|
+
await flush();
|
|
166
|
+
h.place(world, []);
|
|
167
|
+
h.step(world, []);
|
|
168
|
+
};
|
|
169
|
+
return { h, session, sent, hubCalls, world, tick, ctx: () => ctx };
|
|
170
|
+
}
|
|
171
|
+
const cards = (sent, playerId) => sent.filter(([to, m]) => m.k === 'hub-cabinet' && (!playerId || to === playerId));
|
|
172
|
+
|
|
173
|
+
await test('a place with no classic board is sent nothing new, and its doors say classic: false', async () => {
|
|
174
|
+
const t = boot({ boards: {} });
|
|
175
|
+
await t.tick();
|
|
176
|
+
assert.deepEqual(t.ctx().doors().map((d) => [d.id, d.classic]), [['race', false], ['cab-a', false], ['cab-b', false]]);
|
|
177
|
+
assert.equal(cards(t.sent).length, 0);
|
|
178
|
+
// A cabinet is never in the Doors list, board or no board.
|
|
179
|
+
assert.deepEqual(t.h.join().hubDoors, [{ id: 'race', title: 'Foot Race' }]);
|
|
180
|
+
// The doors are read as before; cabinets in a read of their own.
|
|
181
|
+
assert.deepEqual(t.hubCalls.filter(([k, input]) => k === 'read' && input.doorIds).map(([, input]) => input.doorIds), [['race'], ['cab-a', 'cab-b']]);
|
|
182
|
+
// Without a board, a cabinet is a door like any other to hub.go: ghost refuses.
|
|
183
|
+
assert.equal(JSON.stringify(t.h.join()).includes('cabinet'), false);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
await test('a classic deck nobody titled: the cabinet keeps the place\'s own title, on the door and on its card', async () => {
|
|
187
|
+
const t = boot({ boards: { 'cab-a': { ...classicBoard({ title: 'deck-07Zz' }), title: 'deck-07Zz' } } });
|
|
188
|
+
await t.tick();
|
|
189
|
+
assert.equal(t.ctx().doors().find((d) => d.id === 'cab-a').title, 'Friction');
|
|
190
|
+
assert.equal(cards(t.sent)[0][1].card.title, 'Friction');
|
|
191
|
+
// A title that only starts like the placeholder is a title.
|
|
192
|
+
assert.equal(Cabinets.deckTitle('deck-builder'), 'deck-builder');
|
|
193
|
+
assert.equal(Cabinets.deckTitle('deck-07Zz'), '');
|
|
194
|
+
assert.equal(Cabinets.deckTitle(null), '');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
await test('a classic board makes the door classic, takes its title, and its card goes once to each player in range', async () => {
|
|
198
|
+
const t = boot({ boards: { 'cab-a': classicBoard(), 'cab-b': classicBoard({ title: 'Sentencle', label: 'Daily Tries' }) } });
|
|
199
|
+
await t.tick();
|
|
200
|
+
const door = t.ctx().doors().find((d) => d.id === 'cab-a');
|
|
201
|
+
assert.equal(door.classic, true);
|
|
202
|
+
assert.equal(door.title, 'Gimme Friction Baby');
|
|
203
|
+
assert.equal(t.ctx().board('cab-a').classic.label, 'Daily Score');
|
|
204
|
+
// Everyone stands 5 m from cab-a and 100 m from cab-b.
|
|
205
|
+
const got = cards(t.sent);
|
|
206
|
+
assert.deepEqual(got.map(([to, m]) => [to, m.actor, m.door]).sort(), [['p1', 'cab-a-screen', 'cab-a'], ['p2', 'cab-a-screen', 'cab-a'], ['p3', 'cab-a-screen', 'cab-a']]);
|
|
207
|
+
const card = got[0][1].card;
|
|
208
|
+
assert.equal(card.title, 'Gimme Friction Baby');
|
|
209
|
+
assert.equal(card.label, 'Daily Score');
|
|
210
|
+
assert.equal(card.top.length, 2);
|
|
211
|
+
assert.equal(card.top[0].frame, PNG(2500));
|
|
212
|
+
assert.equal(card.top[1].photo, null);
|
|
213
|
+
assert.ok(JSON.stringify(got[0][1]).length < Cabinets.FRAME_MAX_BYTES);
|
|
214
|
+
// Nothing rides the snapshot or a delta.
|
|
215
|
+
assert.equal(JSON.stringify(t.h.join()).includes('data:image'), false);
|
|
216
|
+
assert.equal(JSON.stringify(t.h.delta() ?? {}).includes('data:image'), false);
|
|
217
|
+
// Not sent again while it is the same card.
|
|
218
|
+
t.sent.length = 0;
|
|
219
|
+
await t.tick();
|
|
220
|
+
assert.equal(cards(t.sent).length, 0);
|
|
221
|
+
// Walking up to the other cabinet brings its card, to that player alone.
|
|
222
|
+
t.world.players.get('p2').at = { x: 95, y: 1, z: 0 };
|
|
223
|
+
await t.tick();
|
|
224
|
+
assert.deepEqual(cards(t.sent).map(([to, m]) => [to, m.door]), [['p2', 'cab-b']]);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
await test('a changed card goes again only to players in range of it', async () => {
|
|
228
|
+
const boards = { 'cab-a': classicBoard() };
|
|
229
|
+
const t = boot({ boards });
|
|
230
|
+
await t.tick();
|
|
231
|
+
t.sent.length = 0;
|
|
232
|
+
t.world.players.get('p2').at = { x: -80, y: 1, z: 0 };
|
|
233
|
+
boards['cab-a'] = classicBoard({ top: [{ username: 'zed', score: '20K', photo: null, frame: null }] });
|
|
234
|
+
t.world.timeMs += 60000;
|
|
235
|
+
const real = Date.now;
|
|
236
|
+
Date.now = () => real() + 61000;
|
|
237
|
+
try {
|
|
238
|
+
await t.tick();
|
|
239
|
+
await t.tick();
|
|
240
|
+
} finally {
|
|
241
|
+
Date.now = real;
|
|
242
|
+
}
|
|
243
|
+
assert.deepEqual(cards(t.sent).map(([to]) => to).sort(), ['p1', 'p3']);
|
|
244
|
+
assert.equal(cards(t.sent)[0][1].card.top[0].score, '20K');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await test('a card too large for one frame loses pictures, frames first from the bottom, and malformed pictures are left out', async () => {
|
|
248
|
+
const big = (name) => ({ username: name, score: '1', photo: PNG(9000), frame: PNG(9000) });
|
|
249
|
+
const t = boot({ boards: { 'cab-a': classicBoard({ cover: PNG(20000), top: [big('a'), big('b'), big('c'), big('d'), big('e'), big('f')] }) } });
|
|
250
|
+
await t.tick();
|
|
251
|
+
const [, msg] = cards(t.sent, 'p1')[0];
|
|
252
|
+
assert.ok(new TextEncoder().encode(JSON.stringify({ t: 'm', d: msg })).length <= Cabinets.FRAME_MAX_BYTES);
|
|
253
|
+
assert.equal(msg.card.top.length, 5);
|
|
254
|
+
assert.equal(msg.card.cover, PNG(20000));
|
|
255
|
+
assert.equal(msg.card.top[0].photo, PNG(9000));
|
|
256
|
+
assert.equal(msg.card.top[4].frame, null);
|
|
257
|
+
assert.ok(msg.card.top.filter((row) => row.frame).length < 5);
|
|
258
|
+
const bad = boot({ boards: { 'cab-a': classicBoard({ cover: 'https://example.com/x.png', top: [{ username: 'x', score: 7, photo: 'javascript:alert(1)', frame: PNG(50000) }] }) } });
|
|
259
|
+
await bad.tick();
|
|
260
|
+
const card = cards(bad.sent, 'p1')[0][1].card;
|
|
261
|
+
assert.deepEqual([card.cover, card.top[0].photo, card.top[0].frame, card.top[0].score], [null, null, null, '7']);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
await test('cards stay inside the send budget: a crowd is served over several ticks', async () => {
|
|
265
|
+
const fat = { username: 'a', score: '1', photo: PNG(4000), frame: PNG(4000) };
|
|
266
|
+
const t = boot({ boards: { 'cab-a': classicBoard({ cover: PNG(20000), top: [fat, fat, fat, fat, fat] }) } });
|
|
267
|
+
// Forty players at the cabinet, each owed a ~56 KB card: 180 KB in hand.
|
|
268
|
+
for (let i = 0; i < 40; i += 1) {
|
|
269
|
+
t.world.players.set(`x${i}`, { at: { x: 5, y: 1, z: 1 }, facing: 0, body: { setTranslation() {} } });
|
|
270
|
+
t.h.message(t.session, { playerId: `x${i}` }, { k: 'hub-hello', avatar: 0, party: 1 });
|
|
271
|
+
}
|
|
272
|
+
await t.tick();
|
|
273
|
+
const first = cards(t.sent).length;
|
|
274
|
+
assert.ok(first >= 1 && first <= 4, `sent ${first}`);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
await test('a row naming a player a block hides from the viewer reads "someone", with no pictures', async () => {
|
|
278
|
+
const hidden = (a, b) => (a === 'p1' && b === 'p2') || (a === 'p2' && b === 'p1');
|
|
279
|
+
const t = boot({ boards: { 'cab-a': classicBoard() }, hidden });
|
|
280
|
+
await t.tick();
|
|
281
|
+
const p2 = cards(t.sent, 'p2')[0][1].card;
|
|
282
|
+
assert.deepEqual(p2.top[0], { username: 'someone', score: '12.3K', photo: null, frame: null });
|
|
283
|
+
assert.equal(cards(t.sent, 'p3')[0][1].card.top[0].username, 'ada');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
await test('hub.go on a classic door tells the signed-in player alone, fires no pad, and ghost holds no pad for it', async () => {
|
|
287
|
+
const t = boot({ boards: { 'cab-a': classicBoard() } });
|
|
288
|
+
await t.tick();
|
|
289
|
+
t.sent.length = 0;
|
|
290
|
+
t.ctx().pad('cab-a', ['p1', 'p3']);
|
|
291
|
+
t.ctx().pad('cab-b', ['p1']);
|
|
292
|
+
assert.equal(t.ctx().go('cab-a', ['p1', 'p3']), 'cab-a');
|
|
293
|
+
await flush();
|
|
294
|
+
assert.equal(t.hubCalls.filter(([k]) => k === 'pad').length, 0);
|
|
295
|
+
const go = t.sent.filter(([, m]) => m.k === 'hub-go');
|
|
296
|
+
assert.deepEqual(go, [['p1', { k: 'hub-go', door: 'cab-a', classic: true, key: null, place: null, scene: null, title: 'Gimme Friction Baby', party: 1 }]]);
|
|
297
|
+
// An anonymous player alone: nobody goes.
|
|
298
|
+
assert.equal(t.ctx().go('cab-a', ['p3']), null);
|
|
299
|
+
// The client's word that it stayed shut keeps hub.go from sending them again.
|
|
300
|
+
t.h.message(t.session, { playerId: 'p1' }, { k: 'hub-shut', door: 'cab-a' });
|
|
301
|
+
assert.equal(t.ctx().go('cab-a', ['p1']), null);
|
|
302
|
+
t.ctx().pad('cab-a', []);
|
|
303
|
+
assert.equal(t.ctx().go('cab-a', ['p1']), 'cab-a');
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
await test('the dev fixture: off, a cabinet is inert; on (a dev session only), it has a card and goes with `dev`', async () => {
|
|
307
|
+
const prod = boot({ sessionId: 's-1' });
|
|
308
|
+
prod.h.message(prod.session, { playerId: 'p1' }, { k: 'hub-dev-classic' });
|
|
309
|
+
await prod.tick();
|
|
310
|
+
assert.equal(prod.ctx().doors().some((d) => d.classic), false);
|
|
311
|
+
const t = boot({ sessionId: 'dev' });
|
|
312
|
+
await t.tick();
|
|
313
|
+
assert.equal(t.ctx().doors().some((d) => d.classic), false);
|
|
314
|
+
assert.equal(cards(t.sent).length, 0);
|
|
315
|
+
t.h.message(t.session, { playerId: 'p1' }, { k: 'hub-dev-classic' });
|
|
316
|
+
await t.tick();
|
|
317
|
+
assert.deepEqual(t.ctx().doors().map((d) => [d.id, d.classic]), [['race', false], ['cab-a', true], ['cab-b', true]]);
|
|
318
|
+
const mine = cards(t.sent, 'p1');
|
|
319
|
+
assert.equal(mine.length, 1);
|
|
320
|
+
assert.equal(mine[0][1].card.top.length, 5);
|
|
321
|
+
assert.ok(mine[0][1].card.cover.startsWith('data:image/svg+xml,'));
|
|
322
|
+
assert.ok(JSON.stringify(mine[0][1]).length < 20000);
|
|
323
|
+
t.sent.length = 0;
|
|
324
|
+
assert.equal(t.ctx().go('cab-a', ['p3']), 'cab-a');
|
|
325
|
+
assert.deepEqual(t.sent[0][1], { k: 'hub-go', door: 'cab-a', classic: true, key: null, place: null, scene: null, title: 'Friction', party: 1, dev: true });
|
|
326
|
+
// Off again: inert, and the card is taken back.
|
|
327
|
+
t.sent.length = 0;
|
|
328
|
+
t.h.message(t.session, { playerId: 'p1' }, { k: 'hub-dev-classic', on: false });
|
|
329
|
+
await t.tick();
|
|
330
|
+
assert.equal(t.ctx().doors().some((d) => d.classic), false);
|
|
331
|
+
assert.deepEqual(cards(t.sent, 'p1').map(([, m]) => m.card), [null]);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
await test('a client that joined afresh is sent its cards again; an avatar change is not', async () => {
|
|
335
|
+
const t = boot({ boards: { 'cab-a': classicBoard() } });
|
|
336
|
+
await t.tick();
|
|
337
|
+
t.sent.length = 0;
|
|
338
|
+
t.h.message(t.session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 2, party: 1, again: true });
|
|
339
|
+
await t.tick();
|
|
340
|
+
assert.equal(cards(t.sent, 'p1').length, 0);
|
|
341
|
+
t.h.message(t.session, { playerId: 'p1' }, { k: 'hub-hello', avatar: 2, party: 1 });
|
|
342
|
+
await t.tick();
|
|
343
|
+
assert.equal(cards(t.sent, 'p1').length, 1);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// ---- the client ----
|
|
347
|
+
|
|
348
|
+
await test('a card is a chip until the player taps it; the board closes on a tap, at another cabinet, or on walking away', () => {
|
|
349
|
+
const view = ClientCabinets.makeCardView();
|
|
350
|
+
assert.equal(ClientCabinets.cardMode(view, 'cab-a-screen'), 'chip');
|
|
351
|
+
ClientCabinets.tapCard(view);
|
|
352
|
+
assert.equal(ClientCabinets.cardMode(view, 'cab-a-screen'), 'board');
|
|
353
|
+
ClientCabinets.tapCard(view);
|
|
354
|
+
assert.equal(ClientCabinets.cardMode(view, 'cab-a-screen'), 'chip');
|
|
355
|
+
// Another cabinet's card comes up as a chip, and going back does not reopen.
|
|
356
|
+
ClientCabinets.tapCard(view);
|
|
357
|
+
assert.equal(ClientCabinets.cardMode(view, 'cab-b-screen'), 'chip');
|
|
358
|
+
assert.equal(ClientCabinets.cardMode(view, 'cab-a-screen'), 'chip');
|
|
359
|
+
// Walking away closes it.
|
|
360
|
+
ClientCabinets.tapCard(view);
|
|
361
|
+
assert.equal(ClientCabinets.cardMode(view, 'cab-a-screen'), 'board');
|
|
362
|
+
assert.equal(ClientCabinets.cardMode(view, null), 'chip');
|
|
363
|
+
assert.equal(ClientCabinets.cardMode(view, 'cab-a-screen'), 'chip');
|
|
364
|
+
// A tap with no card up opens nothing.
|
|
365
|
+
ClientCabinets.cardMode(view, null);
|
|
366
|
+
ClientCabinets.tapCard(view);
|
|
367
|
+
assert.equal(ClientCabinets.cardMode(view, 'cab-a-screen'), 'chip');
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
await test('the client keeps a card it is sent, takes it back, and offers only image data URIs', () => {
|
|
371
|
+
HubState.clear();
|
|
372
|
+
ClientCabinets.receive({ k: 'hub-cabinet', actor: 'cab-a-screen', door: 'cab-a', card: { title: 'T', label: '', cover: null, top: [] } });
|
|
373
|
+
assert.equal(HubState.hub.cabinets['cab-a-screen'].card.title, 'T');
|
|
374
|
+
const scene = { getActor: (id) => (id === 'cab-a-screen' ? { components: { Transform: { x: 5, y: 1.4, z: 0 } } } : null) };
|
|
375
|
+
const project = (_cam, x, y, z) => ({ x, y: y * 100 + z });
|
|
376
|
+
assert.equal(ClientCabinets.nearest(scene, { x: 40, z: 0 }, {}, {}, project), null);
|
|
377
|
+
const near = ClientCabinets.nearest(scene, { x: 4, z: 0 }, {}, {}, project);
|
|
378
|
+
assert.equal(near.id, 'cab-a-screen');
|
|
379
|
+
assert.equal(near.opacity, 1);
|
|
380
|
+
// Near means by the cabinet: past 5 m no card, fading in over the last 1.5.
|
|
381
|
+
assert.equal(ClientCabinets.nearest(scene, { x: 11, z: 0 }, {}, {}, project), null);
|
|
382
|
+
assert.ok(Math.abs(ClientCabinets.nearest(scene, { x: 9.25, z: 0 }, {}, {}, project).opacity - 0.5) < 1e-9);
|
|
383
|
+
assert.equal(ClientCabinets.imageOf('data:image/webp;base64,AAAA'), 'data:image/webp;base64,AAAA');
|
|
384
|
+
assert.equal(ClientCabinets.imageOf('https://example.com/a.png'), null);
|
|
385
|
+
assert.equal(ClientCabinets.imageOf(null), null);
|
|
386
|
+
ClientCabinets.receive({ k: 'hub-cabinet', actor: 'cab-a-screen', door: null, card: null });
|
|
387
|
+
assert.equal(HubState.hub.cabinets['cab-a-screen'], undefined);
|
|
388
|
+
HubState.clear();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
const handoff = (extra = {}) => ({ status: 'ok', url: 'wss://x', nonce: 'n', sessionId: 's', bundleHash: 'town', contentUrl: 'https://cdn/town.json', ...extra });
|
|
392
|
+
const classicOk = { status: 'ok', kind: 'classic', url: null, nonce: null, sessionId: null, bundleHash: '', contentUrl: null };
|
|
393
|
+
|
|
394
|
+
function setup() {
|
|
395
|
+
let system;
|
|
396
|
+
installSystem({ registerSystem: (s) => (system = s) });
|
|
397
|
+
system.chrome = { setCover(alpha) { system.cover = alpha; }, showBack(...args) { system.backShown = args; }, setToast() {} };
|
|
398
|
+
system.scenePath = 'scenes/main.scene';
|
|
399
|
+
system.sceneKey = 'scenes/main.scene';
|
|
400
|
+
const sent = [];
|
|
401
|
+
const mp = {
|
|
402
|
+
state: 'joining',
|
|
403
|
+
switched: [],
|
|
404
|
+
target: { mode: 'public' },
|
|
405
|
+
joinFailed: false,
|
|
406
|
+
net: { send: (m) => sent.push(m) },
|
|
407
|
+
switchSession(_scene, join) {
|
|
408
|
+
mp.switched.push(join);
|
|
409
|
+
mp.target = join;
|
|
410
|
+
mp.joinFailed = false;
|
|
411
|
+
mp.net = null;
|
|
412
|
+
},
|
|
413
|
+
joinState: () => mp.state,
|
|
414
|
+
release() {},
|
|
415
|
+
placed: () => false,
|
|
416
|
+
};
|
|
417
|
+
const scene = {
|
|
418
|
+
persistent: { hubTickets: [], hubResult: { title: 'Foot Race', outcome: 'win', at: Date.now() } },
|
|
419
|
+
multiplayer: mp,
|
|
420
|
+
content: null,
|
|
421
|
+
files: {},
|
|
422
|
+
mountsContent: true,
|
|
423
|
+
currentScenePath: 'scenes/main.scene',
|
|
424
|
+
setContent() {},
|
|
425
|
+
actorWith: () => null,
|
|
426
|
+
getActor: () => null,
|
|
427
|
+
getActors: () => [],
|
|
428
|
+
};
|
|
429
|
+
calls.length = 0;
|
|
430
|
+
for (const key of Object.keys(answers)) {
|
|
431
|
+
delete answers[key];
|
|
432
|
+
}
|
|
433
|
+
HubState.clear();
|
|
434
|
+
return { system, scene, mp, sent };
|
|
435
|
+
}
|
|
436
|
+
const GO = { k: 'hub-go', door: 'cab-a', classic: true, key: null, place: null, scene: null, title: 'Gimme Friction Baby', party: 1 };
|
|
437
|
+
async function toCover(system, scene, mp) {
|
|
438
|
+
await flush();
|
|
439
|
+
system.trip.startedAt -= 10000;
|
|
440
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
await test('a cabinet trip asks the host, then leaves the session and waits under the cover with a hub ticket', async () => {
|
|
444
|
+
const { system, scene, mp } = setup();
|
|
445
|
+
answers.go = classicOk;
|
|
446
|
+
HubState.hub.commands.push(GO);
|
|
447
|
+
system.runCommands(scene, 0);
|
|
448
|
+
assert.equal(system.trip.phase, 'opening');
|
|
449
|
+
await toCover(system, scene, mp);
|
|
450
|
+
assert.deepEqual(calls, [['go', 'cab-a']]);
|
|
451
|
+
assert.equal(system.trip.phase, 'away');
|
|
452
|
+
assert.equal(system.cover, 1);
|
|
453
|
+
// Out of the session, and into none: the multiplayer kit will not join.
|
|
454
|
+
assert.equal(mp.switched.length, 1);
|
|
455
|
+
assert.equal(mp.joinFailed, true);
|
|
456
|
+
assert.equal(mp.net, null);
|
|
457
|
+
// No scene swap and no content.
|
|
458
|
+
assert.equal(scene.requestedScene, undefined);
|
|
459
|
+
assert.equal(scene.requestedContent, undefined);
|
|
460
|
+
assert.equal(scene.persistent.hubDepth, 1);
|
|
461
|
+
assert.equal(scene.persistent.hubResult, undefined);
|
|
462
|
+
assert.equal(scene.persistent.hubTickets.length, 1);
|
|
463
|
+
assert.equal(scene.persistent.hubTickets[0].hub, true);
|
|
464
|
+
assert.equal(scene.persistent.hubTickets[0].door, 'cab-a');
|
|
465
|
+
// Nothing else starts while away, and the host draws Back.
|
|
466
|
+
HubState.hub.commands.push({ ...GO, door: 'cab-b' });
|
|
467
|
+
system.runCommands(scene, 0);
|
|
468
|
+
system.jump(scene, { userId: '5' });
|
|
469
|
+
assert.equal(system.trip.phase, 'away');
|
|
470
|
+
assert.deepEqual(calls, [['go', 'cab-a']]);
|
|
471
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
472
|
+
assert.equal(system.trip.phase, 'away');
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
await test('Back from a classic deck is the ordinary way back: Hub.back, a hub join, arriving at the cabinet', async () => {
|
|
476
|
+
const { system, scene, mp } = setup();
|
|
477
|
+
answers.go = classicOk;
|
|
478
|
+
system.goClassic(scene, GO);
|
|
479
|
+
await toCover(system, scene, mp);
|
|
480
|
+
answers.back = handoff();
|
|
481
|
+
system.back(scene);
|
|
482
|
+
assert.equal(system.trip.phase, 'opening');
|
|
483
|
+
await flush();
|
|
484
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
485
|
+
assert.deepEqual(calls, [['go', 'cab-a'], ['back']]);
|
|
486
|
+
assert.equal(system.trip.phase, 'committing');
|
|
487
|
+
assert.equal(mp.switched[1].mode, 'hub');
|
|
488
|
+
assert.equal(mp.joinFailed, false);
|
|
489
|
+
mp.state = 'joined';
|
|
490
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
491
|
+
assert.equal(system.trip.phase, 'loading');
|
|
492
|
+
assert.equal(scene.persistent.hubDepth, 0);
|
|
493
|
+
assert.equal(scene.requestedScene, 'scenes/main.scene');
|
|
494
|
+
assert.deepEqual(scene.persistent.hubArriving, { door: 'cab-a', party: 1, returning: true });
|
|
495
|
+
assert.equal(scene.persistent.hubTickets.length, 0);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
await test('every refusal keeps the door shut: unavailable, a host from before cabinets, a host with no doors', async () => {
|
|
499
|
+
for (const [answer, cancelled] of [[{ status: 'unavailable' }, false], [handoff(), true], [undefined, false]]) {
|
|
500
|
+
const { system, scene, mp, sent } = setup();
|
|
501
|
+
answers.go = answer;
|
|
502
|
+
system.goClassic(scene, GO);
|
|
503
|
+
await toCover(system, scene, mp);
|
|
504
|
+
assert.equal(system.trip.phase, 'revealing');
|
|
505
|
+
assert.ok(system.trip.shut);
|
|
506
|
+
assert.equal(mp.switched.length, 0);
|
|
507
|
+
assert.equal(scene.persistent.hubTickets.length, 0);
|
|
508
|
+
assert.equal(scene.persistent.hubDepth ?? 0, 0);
|
|
509
|
+
assert.deepEqual(sent, [{ k: 'hub-shut', door: 'cab-a' }]);
|
|
510
|
+
// An ordinary handoff the trip will not join is given back.
|
|
511
|
+
assert.equal(calls.some(([k]) => k === 'cancel'), cancelled);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
await test('a way back that cannot be made leaves the player away, ticket kept, to press Back again', async () => {
|
|
516
|
+
const { system, scene, mp } = setup();
|
|
517
|
+
answers.go = classicOk;
|
|
518
|
+
system.goClassic(scene, GO);
|
|
519
|
+
await toCover(system, scene, mp);
|
|
520
|
+
answers.back = { status: 'refused' };
|
|
521
|
+
system.back(scene);
|
|
522
|
+
await flush();
|
|
523
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
524
|
+
assert.equal(system.trip.phase, 'away');
|
|
525
|
+
assert.equal(scene.persistent.hubTickets.length, 1);
|
|
526
|
+
assert.equal(scene.persistent.hubDepth, 1);
|
|
527
|
+
assert.equal(mp.joinFailed, true);
|
|
528
|
+
// The host acquired the way back and then did not commit the join, twice.
|
|
529
|
+
answers.back = handoff();
|
|
530
|
+
system.back(scene);
|
|
531
|
+
await flush();
|
|
532
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
533
|
+
assert.equal(system.trip.phase, 'committing');
|
|
534
|
+
mp.state = 'failed';
|
|
535
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
536
|
+
await flush();
|
|
537
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
538
|
+
assert.equal(system.trip.phase, 'committing');
|
|
539
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
540
|
+
assert.equal(system.trip.phase, 'away');
|
|
541
|
+
assert.equal(scene.persistent.hubTickets.length, 1);
|
|
542
|
+
assert.equal(scene.persistent.hubDepth, 1);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
await test('a host that answers after the kit stopped waiting is followed: the player goes away then', async () => {
|
|
546
|
+
const { system, scene, mp } = setup();
|
|
547
|
+
let land;
|
|
548
|
+
answers.goWait = new Promise((resolve) => (land = resolve));
|
|
549
|
+
answers.go = classicOk;
|
|
550
|
+
system.goClassic(scene, GO);
|
|
551
|
+
await flush();
|
|
552
|
+
system.trip.startedAt -= 60000;
|
|
553
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
554
|
+
assert.equal(system.trip.phase, 'revealing');
|
|
555
|
+
assert.equal(scene.persistent.hubTickets.length, 0);
|
|
556
|
+
system.trip = null;
|
|
557
|
+
land();
|
|
558
|
+
await flush();
|
|
559
|
+
system.adoptLate(scene);
|
|
560
|
+
assert.equal(system.trip.phase, 'away');
|
|
561
|
+
assert.equal(scene.persistent.hubTickets.length, 1);
|
|
562
|
+
assert.equal(scene.persistent.hubDepth, 1);
|
|
563
|
+
assert.equal(mp.joinFailed, true);
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
await test('on the dev serve (the fixture) no host is asked, the kit draws Back, and Back rejoins the session left', async () => {
|
|
567
|
+
const { system, scene, mp } = setup();
|
|
568
|
+
system.goClassic(scene, { ...GO, dev: true });
|
|
569
|
+
await toCover(system, scene, mp);
|
|
570
|
+
assert.deepEqual(calls, []);
|
|
571
|
+
assert.equal(system.trip.phase, 'away');
|
|
572
|
+
assert.equal(scene.persistent.hubDepth ?? 0, 0);
|
|
573
|
+
assert.equal(scene.persistent.hubTickets[0].hub, undefined);
|
|
574
|
+
system.talk = { talking: () => false };
|
|
575
|
+
system.idle = { labels: () => [] };
|
|
576
|
+
Object.assign(system.chrome, { showPicker() {}, setHud() {}, setLabels() {}, setRibbon() {} });
|
|
577
|
+
globalThis.window ??= { innerWidth: 800, innerHeight: 600 };
|
|
578
|
+
system.drawChrome(scene, null, performance.now());
|
|
579
|
+
assert.deepEqual(system.backShown, [true, 'Back']);
|
|
580
|
+
system.back(scene);
|
|
581
|
+
system.stepTrip(scene, mp, null, performance.now());
|
|
582
|
+
assert.equal(system.trip.phase, 'loading');
|
|
583
|
+
assert.deepEqual(mp.switched[1], { mode: 'public' });
|
|
584
|
+
assert.equal(scene.requestedScene, 'scenes/main.scene');
|
|
585
|
+
assert.deepEqual(scene.persistent.hubArriving, { door: 'cab-a', party: 1, returning: true });
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
console.warn = warn;
|
|
589
|
+
console.log = log;
|
|
590
|
+
console.log(`ok: ${n} classic cabinet tests`);
|