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,835 @@
|
|
|
1
|
+
// The hub layer against a host with hub ops (`session.hub`): ghost's arrival,
|
|
2
|
+
// results and avatars read for arriving players, results reported, pads
|
|
3
|
+
// gathered and fired, door boards; and the dev serve's path left as it was.
|
|
4
|
+
// `npm run check` runs it; it needs nothing installed.
|
|
5
|
+
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import { register } from 'node:module';
|
|
8
|
+
|
|
9
|
+
// hub.js reads its scene through the multiplayer-3d kit; this test hands it one.
|
|
10
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
11
|
+
register(
|
|
12
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
13
|
+
export async function resolve(specifier, context, next) {
|
|
14
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') {
|
|
15
|
+
return { url: 'data:text/javascript,${encodeURIComponent(sceneStub)}', shortCircuit: true };
|
|
16
|
+
}
|
|
17
|
+
return next(specifier, context);
|
|
18
|
+
}
|
|
19
|
+
`)}`,
|
|
20
|
+
);
|
|
21
|
+
const { layer } = await import('../code/server/hub.js');
|
|
22
|
+
|
|
23
|
+
globalThis.__hubTestActors = [
|
|
24
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
25
|
+
{ id: 'race-door', components: { HubDoor: { id: 'race', to: 'race' }, Transform: { x: 5, y: 0, z: 5 } } },
|
|
26
|
+
];
|
|
27
|
+
const castleJson = {
|
|
28
|
+
server: { maxPlayers: 8 },
|
|
29
|
+
hub: {
|
|
30
|
+
contract: 1,
|
|
31
|
+
title: 'Town',
|
|
32
|
+
places: {
|
|
33
|
+
race: {
|
|
34
|
+
title: 'Foot Race',
|
|
35
|
+
scene: 'scenes/race.scene',
|
|
36
|
+
result: { outcomes: ['win', 'lose'], score: { unit: 'ms', better: 'lower', min: 0, max: 600000 } },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const sceneExists = (scene) => ['scenes/main.scene', 'scenes/race.scene'].includes(scene);
|
|
42
|
+
const flush = () => new Promise((resolve) => setImmediate(resolve));
|
|
43
|
+
|
|
44
|
+
const PLAYERS = [
|
|
45
|
+
{ playerId: 'p1', userId: '101', username: 'ada', isAnonymous: false },
|
|
46
|
+
{ playerId: 'p2', userId: '102', username: 'bo', isAnonymous: false },
|
|
47
|
+
{ playerId: 'p3', userId: 'anon-1', username: 'guest', isAnonymous: true },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
function sim() {
|
|
51
|
+
const players = new Map();
|
|
52
|
+
for (const { playerId } of PLAYERS) {
|
|
53
|
+
players.set(playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
54
|
+
}
|
|
55
|
+
return { timeMs: 0, players, bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function session({ hub = null, place = null, sessionId = 's-1' } = {}) {
|
|
59
|
+
const sent = [];
|
|
60
|
+
return {
|
|
61
|
+
sent,
|
|
62
|
+
session: {
|
|
63
|
+
sessionId,
|
|
64
|
+
place,
|
|
65
|
+
players: PLAYERS,
|
|
66
|
+
hub,
|
|
67
|
+
send: (playerId, data) => sent.push([playerId, data]),
|
|
68
|
+
broadcast() {},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function platformHub(answers = {}) {
|
|
74
|
+
const calls = [];
|
|
75
|
+
return {
|
|
76
|
+
calls,
|
|
77
|
+
hub: {
|
|
78
|
+
place: 'main',
|
|
79
|
+
title: 'Town',
|
|
80
|
+
result: null,
|
|
81
|
+
arrival: (playerId) => (playerId === 'p1' ? { fromDeckId: 'race-deck', doorId: 'race' } : null),
|
|
82
|
+
async reportResult(playerId, result) {
|
|
83
|
+
calls.push(['result', playerId, result]);
|
|
84
|
+
return { recorded: true };
|
|
85
|
+
},
|
|
86
|
+
async updatePad(input) {
|
|
87
|
+
calls.push(['pad', input]);
|
|
88
|
+
return input.fire ? { status: 'fired', members: [...input.memberUserIds] } : { status: 'gathering', members: [] };
|
|
89
|
+
},
|
|
90
|
+
async readResults(input) {
|
|
91
|
+
calls.push(['read', input]);
|
|
92
|
+
return answers.read?.(input) ?? { players: {}, boards: {} };
|
|
93
|
+
},
|
|
94
|
+
async wear(playerId, wearable) {
|
|
95
|
+
calls.push(['wear', playerId, wearable]);
|
|
96
|
+
if (answers.wear) {
|
|
97
|
+
return answers.wear(playerId, wearable);
|
|
98
|
+
}
|
|
99
|
+
return { wearable };
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function boot(s, hooks = {}) {
|
|
106
|
+
let ctx = null;
|
|
107
|
+
const arrived = [];
|
|
108
|
+
const deck = {
|
|
109
|
+
ready(hub) {
|
|
110
|
+
ctx = hub;
|
|
111
|
+
},
|
|
112
|
+
arrive(hub, group) {
|
|
113
|
+
arrived.push(...group);
|
|
114
|
+
},
|
|
115
|
+
...hooks,
|
|
116
|
+
};
|
|
117
|
+
const h = layer(castleJson, deck, {}, sceneExists);
|
|
118
|
+
h.sceneFor(s.session);
|
|
119
|
+
const world = sim();
|
|
120
|
+
h.ready(world);
|
|
121
|
+
return { h, world, arrived, ctx: () => ctx };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let n = 0;
|
|
125
|
+
async function test(name, fn) {
|
|
126
|
+
await fn();
|
|
127
|
+
n += 1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const hello = (h, s, playerId, extra = {}) =>
|
|
131
|
+
h.message(s.session, { playerId }, { k: 'hub-hello', avatar: 1, from: 'from-client', party: 1, ...extra });
|
|
132
|
+
|
|
133
|
+
await test("arrival, result and avatar come from ghost, not the client's hello", async () => {
|
|
134
|
+
const now = new Date().toISOString();
|
|
135
|
+
const p = platformHub({
|
|
136
|
+
read: (input) =>
|
|
137
|
+
input.userIds
|
|
138
|
+
? {
|
|
139
|
+
players: {
|
|
140
|
+
101: {
|
|
141
|
+
avatar: 3,
|
|
142
|
+
records: [],
|
|
143
|
+
recent: [
|
|
144
|
+
{ deckId: 'other-deck', title: 'Hill', outcome: 'lose', score: null, unit: null, at: now },
|
|
145
|
+
{ deckId: 'race-deck', title: 'Foot Race', outcome: 'win', score: 16900, unit: 'ms', better: 'lower', at: now },
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
boards: {},
|
|
150
|
+
}
|
|
151
|
+
: { players: {}, boards: { race: { title: 'Foot Race', unit: 'ms', better: 'lower', top: [{ userId: '101', username: 'ada', score: 16900, at: now }] } } },
|
|
152
|
+
});
|
|
153
|
+
const s = session({ hub: p.hub });
|
|
154
|
+
const { h, world, arrived, ctx } = boot(s);
|
|
155
|
+
hello(h, s, 'p1', { carry: { result: { title: 'Fake', outcome: 'win', score: 1, unit: 'ms' } } });
|
|
156
|
+
h.place(world);
|
|
157
|
+
// The read is in flight: the arrival waits for it.
|
|
158
|
+
assert.equal(arrived.length, 0);
|
|
159
|
+
assert.deepEqual(
|
|
160
|
+
p.calls.map((c) => c[1]),
|
|
161
|
+
[{ userIds: ['101'] }, { doorIds: ['race'] }],
|
|
162
|
+
);
|
|
163
|
+
await flush();
|
|
164
|
+
h.place(world);
|
|
165
|
+
assert.equal(arrived.length, 1);
|
|
166
|
+
assert.equal(arrived[0].from, 'race');
|
|
167
|
+
assert.equal(arrived[0].fromDeckId, 'race-deck');
|
|
168
|
+
assert.deepEqual(arrived[0].carry.result, {
|
|
169
|
+
title: 'Foot Race',
|
|
170
|
+
outcome: 'win',
|
|
171
|
+
score: 16900,
|
|
172
|
+
unit: 'ms',
|
|
173
|
+
better: 'lower',
|
|
174
|
+
verified: true,
|
|
175
|
+
});
|
|
176
|
+
assert.ok(s.sent.some(([id, d]) => id === 'p1' && d.k === 'hub-result' && d.result.verified === true));
|
|
177
|
+
assert.equal(h.join().hubAv.p1, 3);
|
|
178
|
+
assert.equal(ctx().board('race').top[0].score, 16900);
|
|
179
|
+
// The same choice again keeps the platform avatar; a new choice wins.
|
|
180
|
+
hello(h, s, 'p1');
|
|
181
|
+
assert.equal(h.join().hubAv.p1, 3);
|
|
182
|
+
hello(h, s, 'p1', { avatar: 2 });
|
|
183
|
+
assert.equal(h.join().hubAv.p1, 2);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
await test("a production door to another deck reads its title and group from ghost's board, its props until then", async () => {
|
|
187
|
+
const actors = globalThis.__hubTestActors;
|
|
188
|
+
globalThis.__hubTestActors = [
|
|
189
|
+
...actors,
|
|
190
|
+
{
|
|
191
|
+
id: 'hill-door',
|
|
192
|
+
components: {
|
|
193
|
+
HubDoor: { id: 'hill', to: 'deck:hill', title: 'Old Hill', minPlayers: 3, maxPlayers: 4 },
|
|
194
|
+
Transform: { x: -5, y: 0, z: 5 },
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
try {
|
|
199
|
+
const p = platformHub({
|
|
200
|
+
read: (input) =>
|
|
201
|
+
input.doorIds
|
|
202
|
+
? {
|
|
203
|
+
players: {},
|
|
204
|
+
boards: {
|
|
205
|
+
hill: { title: 'King of the Hill', minPlayers: 2, maxPlayers: 8, lateJoin: true, top: [] },
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
: { players: {}, boards: {} },
|
|
209
|
+
});
|
|
210
|
+
const s = session({ hub: p.hub });
|
|
211
|
+
const { h, world, ctx } = boot(s);
|
|
212
|
+
// A deck keeps the list it was handed at ready; it must see the board too.
|
|
213
|
+
const kept = ctx().doors().find((d) => d.id === 'hill');
|
|
214
|
+
const hill = () => kept;
|
|
215
|
+
// Before ghost answers: the props.
|
|
216
|
+
assert.deepEqual(
|
|
217
|
+
{ title: hill().title, minPlayers: hill().minPlayers, maxPlayers: hill().maxPlayers, lateJoin: hill().lateJoin },
|
|
218
|
+
{ title: 'Old Hill', minPlayers: 3, maxPlayers: 4, lateJoin: false },
|
|
219
|
+
);
|
|
220
|
+
hello(h, s, 'p1');
|
|
221
|
+
h.place(world);
|
|
222
|
+
await flush();
|
|
223
|
+
assert.deepEqual(
|
|
224
|
+
{ title: hill().title, minPlayers: hill().minPlayers, maxPlayers: hill().maxPlayers, lateJoin: hill().lateJoin },
|
|
225
|
+
{ title: 'King of the Hill', minPlayers: 2, maxPlayers: 8, lateJoin: true },
|
|
226
|
+
);
|
|
227
|
+
} finally {
|
|
228
|
+
globalThis.__hubTestActors = actors;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
await test("a board that leaves the group unsaid keeps the door's props", async () => {
|
|
233
|
+
const actors = globalThis.__hubTestActors;
|
|
234
|
+
globalThis.__hubTestActors = [
|
|
235
|
+
...actors,
|
|
236
|
+
{
|
|
237
|
+
id: 'hill-door',
|
|
238
|
+
components: {
|
|
239
|
+
HubDoor: { id: 'hill', to: 'deck:hill', title: 'Old Hill', minPlayers: 3, maxPlayers: 4, lateJoin: true },
|
|
240
|
+
Transform: { x: -5, y: 0, z: 5 },
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
];
|
|
244
|
+
try {
|
|
245
|
+
const p = platformHub({
|
|
246
|
+
read: (input) =>
|
|
247
|
+
input.doorIds
|
|
248
|
+
? { players: {}, boards: { hill: { title: null, minPlayers: null, maxPlayers: null, top: [] } } }
|
|
249
|
+
: { players: {}, boards: {} },
|
|
250
|
+
});
|
|
251
|
+
const s = session({ hub: p.hub });
|
|
252
|
+
const { h, world, ctx } = boot(s);
|
|
253
|
+
hello(h, s, 'p1');
|
|
254
|
+
h.place(world);
|
|
255
|
+
await flush();
|
|
256
|
+
const hill = ctx().doors().find((d) => d.id === 'hill');
|
|
257
|
+
assert.deepEqual(
|
|
258
|
+
{ title: hill.title, minPlayers: hill.minPlayers, maxPlayers: hill.maxPlayers, lateJoin: hill.lateJoin },
|
|
259
|
+
{ title: 'Old Hill', minPlayers: 3, maxPlayers: 4, lateJoin: true },
|
|
260
|
+
);
|
|
261
|
+
} finally {
|
|
262
|
+
globalThis.__hubTestActors = actors;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
await test('a player who jumped to a friend arrives beside them, facing them', async () => {
|
|
267
|
+
const s = session();
|
|
268
|
+
const { h, world } = boot(s);
|
|
269
|
+
hello(h, s, 'p2');
|
|
270
|
+
h.place(world);
|
|
271
|
+
// The friend has walked off somewhere.
|
|
272
|
+
const friend = world.players.get('p2');
|
|
273
|
+
friend.at = { x: 10, y: 1, z: 5 };
|
|
274
|
+
friend.facing = 0;
|
|
275
|
+
hello(h, s, 'p1', { near: '102' });
|
|
276
|
+
h.place(world);
|
|
277
|
+
const me = world.players.get('p1');
|
|
278
|
+
// Facing 0 looks along +z; beside is along x.
|
|
279
|
+
assert.ok(Math.abs(me.at.x - 11.6) < 1e-9 && Math.abs(me.at.z - 5) < 1e-9, JSON.stringify(me.at));
|
|
280
|
+
assert.ok(Math.abs(me.facing - Math.atan2(-1.6, 0)) < 1e-9);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
await test('a jump beside a friend takes a clear side, and none beside someone a block hides', async () => {
|
|
284
|
+
const actors = globalThis.__hubTestActors;
|
|
285
|
+
// A wall right of the friend (facing +z, right is +x).
|
|
286
|
+
globalThis.__hubTestActors = [
|
|
287
|
+
...actors,
|
|
288
|
+
{ id: 'wall', components: { Shape: { kind: 'box', width: 0.8, height: 4, depth: 6, solid: true }, Transform: { x: 11.8, y: 2, z: 5 } } },
|
|
289
|
+
// A big ball left of the friend, solid by its radius (not its height).
|
|
290
|
+
{ id: 'ball', components: { Solid: {}, Shape: { kind: 'sphere', radius: 2, height: 1 }, Transform: { x: 8.4, y: 2, z: 5 } } },
|
|
291
|
+
];
|
|
292
|
+
try {
|
|
293
|
+
const s = session();
|
|
294
|
+
const { h, world } = boot(s);
|
|
295
|
+
hello(h, s, 'p2');
|
|
296
|
+
h.place(world);
|
|
297
|
+
const friend = world.players.get('p2');
|
|
298
|
+
friend.at = { x: 10, y: 1, z: 5 };
|
|
299
|
+
friend.facing = 0;
|
|
300
|
+
hello(h, s, 'p1', { near: '102' });
|
|
301
|
+
h.place(world);
|
|
302
|
+
// Not into the wall nor the ball: a step further out, behind.
|
|
303
|
+
const me = world.players.get('p1').at;
|
|
304
|
+
assert.ok(Math.abs(me.x - 10) < 1e-9 && Math.abs(me.z - 2.6) < 1e-9, JSON.stringify(me));
|
|
305
|
+
} finally {
|
|
306
|
+
globalThis.__hubTestActors = actors;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const hub = platformHub().hub;
|
|
310
|
+
hub.hiddenPair = (a, b) => [a, b].sort().join() === 'p1,p2';
|
|
311
|
+
const s = session({ hub });
|
|
312
|
+
const { h, world } = boot(s);
|
|
313
|
+
hello(h, s, 'p2');
|
|
314
|
+
h.place(world);
|
|
315
|
+
await flush();
|
|
316
|
+
h.place(world);
|
|
317
|
+
world.players.get('p2').at = { x: 10, y: 1, z: 5 };
|
|
318
|
+
hello(h, s, 'p1', { near: '102' });
|
|
319
|
+
h.place(world);
|
|
320
|
+
await flush();
|
|
321
|
+
h.place(world);
|
|
322
|
+
const me = world.players.get('p1').at;
|
|
323
|
+
assert.ok(Math.hypot(me.x - 10, me.z - 5) > 3, JSON.stringify(me));
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
await test('a jump to a friend who is not here, or a bad id, arrives as usual', async () => {
|
|
327
|
+
const s = session();
|
|
328
|
+
const { h, world } = boot(s);
|
|
329
|
+
hello(h, s, 'p1', { near: '999' });
|
|
330
|
+
h.place(world);
|
|
331
|
+
const usual = { ...world.players.get('p1').at };
|
|
332
|
+
const s2 = session();
|
|
333
|
+
const b = boot(s2);
|
|
334
|
+
hello(b.h, s2, 'p1', { near: 'not an id' });
|
|
335
|
+
b.h.place(b.world);
|
|
336
|
+
assert.deepEqual(b.world.players.get('p1').at, usual);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
await test('a player with no arrival came from nowhere, and an anonymous one is not read', async () => {
|
|
340
|
+
const p = platformHub();
|
|
341
|
+
const s = session({ hub: p.hub });
|
|
342
|
+
const { h, world, arrived } = boot(s);
|
|
343
|
+
hello(h, s, 'p2');
|
|
344
|
+
hello(h, s, 'p3');
|
|
345
|
+
h.place(world);
|
|
346
|
+
await flush();
|
|
347
|
+
h.place(world);
|
|
348
|
+
assert.deepEqual(
|
|
349
|
+
arrived.map((g) => [g.playerId, g.from, g.carry]),
|
|
350
|
+
[
|
|
351
|
+
['p2', null, null],
|
|
352
|
+
['p3', null, null],
|
|
353
|
+
],
|
|
354
|
+
);
|
|
355
|
+
assert.deepEqual(p.calls.find((c) => c[0] === 'read')[1], { userIds: ['102'] });
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
await test('pads gather on change, fire with the gathered id, and the next gathering is new', async () => {
|
|
359
|
+
const p = platformHub();
|
|
360
|
+
const s = session({ hub: p.hub });
|
|
361
|
+
const { ctx } = boot(s);
|
|
362
|
+
const hub = ctx();
|
|
363
|
+
hub.pad('race', ['p1']);
|
|
364
|
+
hub.pad('race', ['p1']);
|
|
365
|
+
hub.pad('race', ['p1', 'p2', 'p3']);
|
|
366
|
+
const pads = p.calls.filter((c) => c[0] === 'pad').map((c) => c[1]);
|
|
367
|
+
assert.equal(pads.length, 2);
|
|
368
|
+
assert.deepEqual(pads[0].memberUserIds, ['101']);
|
|
369
|
+
assert.deepEqual(pads[1].memberUserIds, ['101', '102']);
|
|
370
|
+
const padId = pads[0].padId;
|
|
371
|
+
assert.equal(pads[1].padId, padId);
|
|
372
|
+
assert.equal(hub.go('race', ['p1', 'p2'], { instance: 'ignored' }), padId);
|
|
373
|
+
await flush();
|
|
374
|
+
const fire = p.calls.filter((c) => c[0] === 'pad').at(-1)[1];
|
|
375
|
+
assert.deepEqual(fire, { doorId: 'race', padId, memberUserIds: ['101', '102'], fire: true });
|
|
376
|
+
const gos = s.sent.filter(([, d]) => d.k === 'hub-go');
|
|
377
|
+
assert.deepEqual(
|
|
378
|
+
gos.map(([id, d]) => [id, d.pad, d.key, d.party]),
|
|
379
|
+
[
|
|
380
|
+
['p1', padId, null, 2],
|
|
381
|
+
['p2', padId, null, 2],
|
|
382
|
+
],
|
|
383
|
+
);
|
|
384
|
+
hub.pad('race', ['p1']);
|
|
385
|
+
assert.notEqual(p.calls.filter((c) => c[0] === 'pad').at(-1)[1].padId, padId);
|
|
386
|
+
assert.equal(hub.go('nope', ['p1']), null);
|
|
387
|
+
assert.equal(hub.go('race', ['p3']), null);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
await test('a fire whose answer is lost is retried on the same pad', async () => {
|
|
391
|
+
const p = platformHub();
|
|
392
|
+
let lose = true;
|
|
393
|
+
const update = p.hub.updatePad;
|
|
394
|
+
p.hub.updatePad = async (input) => {
|
|
395
|
+
const out = await update(input);
|
|
396
|
+
if (input.fire && lose) {
|
|
397
|
+
lose = false;
|
|
398
|
+
throw Object.assign(new Error('socket hang up'), { code: 'CAULDRON_STORAGE_TIMEOUT' });
|
|
399
|
+
}
|
|
400
|
+
return out;
|
|
401
|
+
};
|
|
402
|
+
const s = session({ hub: p.hub });
|
|
403
|
+
const { ctx } = boot(s);
|
|
404
|
+
const warn = console.warn;
|
|
405
|
+
console.warn = () => {};
|
|
406
|
+
try {
|
|
407
|
+
ctx().pad('race', ['p1', 'p2']);
|
|
408
|
+
const first = ctx().go('race', ['p1', 'p2']);
|
|
409
|
+
// While the fire is unanswered the gathering is left alone.
|
|
410
|
+
ctx().pad('race', ['p1']);
|
|
411
|
+
await flush();
|
|
412
|
+
assert.equal(ctx().go('race', ['p1', 'p2']), first);
|
|
413
|
+
await flush();
|
|
414
|
+
const fires = p.calls.filter((c) => c[0] === 'pad' && c[1].fire).map((c) => c[1].padId);
|
|
415
|
+
assert.deepEqual(fires, [first, first]);
|
|
416
|
+
assert.equal(p.calls.filter((c) => c[0] === 'pad' && !c[1].fire).length, 1);
|
|
417
|
+
ctx().pad('race', ['p1']);
|
|
418
|
+
assert.notEqual(p.calls.at(-1)[1].padId, first);
|
|
419
|
+
} finally {
|
|
420
|
+
console.warn = warn;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
await test('a lost fire answer survives an emptied pad, and ghost\'s later fired answer sends the group', async () => {
|
|
425
|
+
const p = platformHub();
|
|
426
|
+
const fired = new Set();
|
|
427
|
+
p.hub.updatePad = async (input) => {
|
|
428
|
+
p.calls.push(['pad', input]);
|
|
429
|
+
if (fired.has(input.padId)) {
|
|
430
|
+
return { status: 'fired', members: ['101', '102'] };
|
|
431
|
+
}
|
|
432
|
+
if (input.fire) {
|
|
433
|
+
fired.add(input.padId);
|
|
434
|
+
throw Object.assign(new Error('socket hang up'), { code: 'CAULDRON_STORAGE_TIMEOUT' });
|
|
435
|
+
}
|
|
436
|
+
return { status: 'gathering', members: [...input.memberUserIds] };
|
|
437
|
+
};
|
|
438
|
+
const s = session({ hub: p.hub });
|
|
439
|
+
const { ctx } = boot(s);
|
|
440
|
+
const warn = console.warn;
|
|
441
|
+
console.warn = () => {};
|
|
442
|
+
try {
|
|
443
|
+
const first = ctx().go('race', ['p1', 'p2']);
|
|
444
|
+
await flush();
|
|
445
|
+
ctx().pad('race', []);
|
|
446
|
+
await flush();
|
|
447
|
+
// Ghost said the pad had fired: the group is sent, once.
|
|
448
|
+
const gos = s.sent.filter(([, d]) => d.k === 'hub-go');
|
|
449
|
+
assert.deepEqual(gos.map(([id, d]) => [id, d.pad]), [['p1', first], ['p2', first]]);
|
|
450
|
+
ctx().pad('race', ['p1']);
|
|
451
|
+
await flush();
|
|
452
|
+
assert.equal(fired.size, 1);
|
|
453
|
+
assert.notEqual(p.calls.at(-1)[1].padId, first);
|
|
454
|
+
} finally {
|
|
455
|
+
console.warn = warn;
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
await test('a read slower than the arrival window reaches the deck through carry', async () => {
|
|
460
|
+
let answer;
|
|
461
|
+
const p = platformHub();
|
|
462
|
+
p.hub.readResults = (input) =>
|
|
463
|
+
input.userIds
|
|
464
|
+
? new Promise((resolve) => {
|
|
465
|
+
answer = resolve;
|
|
466
|
+
})
|
|
467
|
+
: Promise.resolve({ players: {}, boards: {} });
|
|
468
|
+
const s = session({ hub: p.hub });
|
|
469
|
+
const carried = [];
|
|
470
|
+
const { h, world, arrived } = boot(s, { carry: (_hub, playerId, carry) => carried.push([playerId, carry]) });
|
|
471
|
+
hello(h, s, 'p1');
|
|
472
|
+
h.place(world);
|
|
473
|
+
// Past the window, the group arrives without the result.
|
|
474
|
+
const realNow = Date.now;
|
|
475
|
+
Date.now = () => realNow() + 5000;
|
|
476
|
+
try {
|
|
477
|
+
h.place(world);
|
|
478
|
+
} finally {
|
|
479
|
+
Date.now = realNow;
|
|
480
|
+
}
|
|
481
|
+
assert.equal(arrived.length, 1);
|
|
482
|
+
assert.equal(arrived[0].carry, null);
|
|
483
|
+
answer({
|
|
484
|
+
players: { 101: { avatar: null, records: [], recent: [{ deckId: 'race-deck', title: 'Foot Race', outcome: 'lose', score: null, unit: null, at: new Date().toISOString() }] } },
|
|
485
|
+
boards: {},
|
|
486
|
+
});
|
|
487
|
+
await flush();
|
|
488
|
+
assert.equal(carried.length, 1);
|
|
489
|
+
assert.equal(carried[0][0], 'p1');
|
|
490
|
+
assert.equal(carried[0][1].result.outcome, 'lose');
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
await test('a choice changed and changed back while a read is in flight is kept', async () => {
|
|
494
|
+
let answer;
|
|
495
|
+
const p = platformHub();
|
|
496
|
+
p.hub.readResults = (input) =>
|
|
497
|
+
input.userIds
|
|
498
|
+
? new Promise((resolve) => {
|
|
499
|
+
answer = resolve;
|
|
500
|
+
})
|
|
501
|
+
: Promise.resolve({ players: {}, boards: {} });
|
|
502
|
+
const s = session({ hub: p.hub });
|
|
503
|
+
const { h, world } = boot(s);
|
|
504
|
+
hello(h, s, 'p2', { avatar: 1 });
|
|
505
|
+
h.place(world);
|
|
506
|
+
hello(h, s, 'p2', { avatar: 2 });
|
|
507
|
+
hello(h, s, 'p2', { avatar: 1 });
|
|
508
|
+
answer({ players: { 102: { avatar: 3, records: [], recent: [] } }, boards: {} });
|
|
509
|
+
await flush();
|
|
510
|
+
assert.equal(h.join().hubAv.p2, 1);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
await test('a result goes to the host once, and the player still sees it', async () => {
|
|
514
|
+
const p = platformHub();
|
|
515
|
+
const s = session({ hub: { ...p.hub, place: 'race' }, place: 'race' });
|
|
516
|
+
const { h, ctx } = boot(s);
|
|
517
|
+
hello(h, s, 'p1');
|
|
518
|
+
assert.equal(ctx().result('p1', { outcome: 'win', score: 16900 }), true);
|
|
519
|
+
assert.equal(ctx().result('p1', { outcome: 'win', score: 1 }), false);
|
|
520
|
+
await flush();
|
|
521
|
+
assert.deepEqual(
|
|
522
|
+
p.calls.filter((c) => c[0] === 'result'),
|
|
523
|
+
[['result', 'p1', { outcome: 'win', score: 16900 }]],
|
|
524
|
+
);
|
|
525
|
+
assert.ok(s.sent.some(([id, d]) => id === 'p1' && d.k === 'hub-result'));
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
await test('a refused op is logged, never thrown', async () => {
|
|
529
|
+
const p = platformHub();
|
|
530
|
+
p.hub.updatePad = async () => {
|
|
531
|
+
throw Object.assign(new Error('no pad door'), { code: 'CAULDRON_HUB_DOOR_NOT_FOUND' });
|
|
532
|
+
};
|
|
533
|
+
const s = session({ hub: p.hub });
|
|
534
|
+
const { ctx } = boot(s);
|
|
535
|
+
const warn = console.warn;
|
|
536
|
+
const warned = [];
|
|
537
|
+
console.warn = (m) => warned.push(m);
|
|
538
|
+
try {
|
|
539
|
+
ctx().pad('race', ['p1']);
|
|
540
|
+
ctx().pad('race', ['p1', 'p2']);
|
|
541
|
+
ctx().go('race', ['p1']);
|
|
542
|
+
await flush();
|
|
543
|
+
} finally {
|
|
544
|
+
console.warn = warn;
|
|
545
|
+
}
|
|
546
|
+
// Once per op and code.
|
|
547
|
+
assert.equal(warned.length, 2);
|
|
548
|
+
assert.match(warned[0], /pad refused \(CAULDRON_HUB_DOOR_NOT_FOUND\)/);
|
|
549
|
+
assert.match(warned[1], /go refused \(CAULDRON_HUB_DOOR_NOT_FOUND\)/);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
await test('without hub ops (the dev serve) the client hello is read as before', async () => {
|
|
553
|
+
const s = session({ sessionId: 'dev:town' });
|
|
554
|
+
const { h, world, arrived, ctx } = boot(s);
|
|
555
|
+
hello(h, s, 'p1', { from: 'race', carry: { result: { title: 'Foot Race', outcome: 'win', score: 5, unit: 'ms' } } });
|
|
556
|
+
h.place(world);
|
|
557
|
+
assert.equal(arrived[0].from, 'race');
|
|
558
|
+
assert.equal(arrived[0].fromDeckId, null);
|
|
559
|
+
assert.equal(arrived[0].carry.result.verified, false);
|
|
560
|
+
assert.equal(h.join().hubAv.p1, 1);
|
|
561
|
+
ctx().pad('race', ['p1']);
|
|
562
|
+
assert.equal(ctx().board('race'), null);
|
|
563
|
+
const key = ctx().go('race', ['p1']);
|
|
564
|
+
assert.match(key, /^hub\.race\./);
|
|
565
|
+
assert.ok(s.sent.some(([, d]) => d.k === 'hub-go' && d.key === key));
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
await test('a door that stayed shut is not fired again for that player until they step off its pad', async () => {
|
|
569
|
+
const p = platformHub();
|
|
570
|
+
const s = session({ hub: p.hub });
|
|
571
|
+
const { h, world, ctx } = boot(s);
|
|
572
|
+
const hub = ctx();
|
|
573
|
+
const fires = () => p.calls.filter((c) => c[0] === 'pad' && c[1].fire);
|
|
574
|
+
hub.pad('race', ['p1', 'p2']);
|
|
575
|
+
assert.ok(hub.go('race', ['p1', 'p2']));
|
|
576
|
+
await flush();
|
|
577
|
+
assert.equal(fires().length, 1);
|
|
578
|
+
// p1's trip failed: the door stayed shut, and p1 still stands on the pad.
|
|
579
|
+
h.message(s.session, { playerId: 'p1' }, { k: 'hub-shut', door: 'race' });
|
|
580
|
+
h.message(s.session, { playerId: 'p2' }, { k: 'hub-shut', door: 'nope' });
|
|
581
|
+
h.step(world);
|
|
582
|
+
const before = p.calls.length;
|
|
583
|
+
const labels = s.sent.filter(([id, d]) => id === 'p1' && d.k === 'hub-labels').at(-1)?.[1].labels;
|
|
584
|
+
assert.match(labels?.['race-door']?.text ?? '', /shut/);
|
|
585
|
+
assert.ok(!s.sent.some(([id, d]) => id === 'p2' && d.k === 'hub-labels'));
|
|
586
|
+
hub.pad('race', ['p1']);
|
|
587
|
+
assert.equal(hub.go('race', ['p1']), null, 'a shut door does not fire again for p1');
|
|
588
|
+
await flush();
|
|
589
|
+
assert.equal(fires().length, 1);
|
|
590
|
+
assert.ok(
|
|
591
|
+
p.calls.slice(before).every((c) => c[0] !== 'pad' || !c[1].memberUserIds.includes('101')),
|
|
592
|
+
'ghost does not gather p1 on the shut pad',
|
|
593
|
+
);
|
|
594
|
+
// Others on the pad still go; p1 is left out.
|
|
595
|
+
hub.pad('race', ['p1', 'p2']);
|
|
596
|
+
assert.ok(hub.go('race', ['p1', 'p2']));
|
|
597
|
+
await flush();
|
|
598
|
+
assert.deepEqual(fires().at(-1)[1].memberUserIds, ['102']);
|
|
599
|
+
// Stepping off clears it, and the label with it.
|
|
600
|
+
hub.pad('race', []);
|
|
601
|
+
h.step(world);
|
|
602
|
+
const cleared = s.sent.filter(([id, d]) => id === 'p1' && d.k === 'hub-labels').at(-1)[1].labels;
|
|
603
|
+
assert.equal(cleared['race-door'], undefined);
|
|
604
|
+
hub.pad('race', ['p1']);
|
|
605
|
+
assert.ok(hub.go('race', ['p1']));
|
|
606
|
+
await flush();
|
|
607
|
+
assert.deepEqual(fires().at(-1)[1].memberUserIds, ['101']);
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
await test('a door that stays shut after the player already stepped off holds nothing', async () => {
|
|
611
|
+
const p = platformHub();
|
|
612
|
+
const s = session({ hub: p.hub });
|
|
613
|
+
const { h, ctx } = boot(s);
|
|
614
|
+
const hub = ctx();
|
|
615
|
+
hub.pad('race', ['p1']);
|
|
616
|
+
assert.ok(hub.go('race', ['p1']));
|
|
617
|
+
await flush();
|
|
618
|
+
hub.pad('race', []);
|
|
619
|
+
h.message(s.session, { playerId: 'p1' }, { k: 'hub-shut', door: 'race' });
|
|
620
|
+
hub.pad('race', ['p1']);
|
|
621
|
+
assert.ok(hub.go('race', ['p1']), 'stepping back on may try the door again');
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
await test("a wearable comes from ghost's read, and the game's own goes to ghost", async () => {
|
|
625
|
+
const halo = { kind: 'halo', color: '#ffd700', rarity: 4 };
|
|
626
|
+
const p = platformHub({
|
|
627
|
+
read: (input) => (input.userIds ? { players: { 101: { avatar: 1, recent: [], records: [], wearable: halo }, 102: { avatar: 2, recent: [], records: [], wearable: null } }, boards: {} } : { players: {}, boards: {} }),
|
|
628
|
+
});
|
|
629
|
+
const s = session({ hub: p.hub });
|
|
630
|
+
const { h, world, ctx } = boot(s);
|
|
631
|
+
hello(h, s, 'p1');
|
|
632
|
+
hello(h, s, 'p2');
|
|
633
|
+
h.place(world);
|
|
634
|
+
await flush();
|
|
635
|
+
assert.deepEqual(h.join().hubWear, { p1: halo });
|
|
636
|
+
assert.equal(h.join().hubAv.p1, 1, 'the avatar index is read as before');
|
|
637
|
+
// The game's own goes to ghost for a signed-in player, once per change.
|
|
638
|
+
const aura = { kind: 'aura', color: '#00ff00', rarity: 9 };
|
|
639
|
+
assert.equal(ctx().wear('p2', aura), true);
|
|
640
|
+
assert.equal(ctx().wear('p2', aura), true);
|
|
641
|
+
// What ghost already holds is not sent again.
|
|
642
|
+
assert.equal(ctx().wear('p1', halo), true);
|
|
643
|
+
const wears = () => p.calls.filter((c) => c[0] === 'wear');
|
|
644
|
+
assert.deepEqual(wears(), [['wear', 'p2', aura]]);
|
|
645
|
+
assert.deepEqual(h.join().hubWear, { p1: halo, p2: aura });
|
|
646
|
+
// A guest's is this session's alone.
|
|
647
|
+
hello(h, s, 'p3');
|
|
648
|
+
assert.equal(ctx().wear('p3', aura), true);
|
|
649
|
+
assert.equal(wears().length, 1);
|
|
650
|
+
assert.deepEqual(h.join().hubWear.p3, aura);
|
|
651
|
+
// Clearing goes to ghost as null.
|
|
652
|
+
assert.equal(ctx().wear('p2', null), true);
|
|
653
|
+
assert.deepEqual(wears().at(-1), ['wear', 'p2', null]);
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
await test('a wearable the game puts on wins over a read that began before it', async () => {
|
|
657
|
+
let answer = null;
|
|
658
|
+
const p = platformHub({
|
|
659
|
+
read: (input) =>
|
|
660
|
+
input.userIds
|
|
661
|
+
? new Promise((resolve) => {
|
|
662
|
+
answer = () => resolve({ players: { 101: { avatar: 1, recent: [], records: [], wearable: { kind: 'halo', color: '#ffffff', rarity: 0 } } }, boards: {} });
|
|
663
|
+
})
|
|
664
|
+
: { players: {}, boards: {} },
|
|
665
|
+
});
|
|
666
|
+
const s = session({ hub: p.hub });
|
|
667
|
+
const { h, world, ctx } = boot(s);
|
|
668
|
+
hello(h, s, 'p1');
|
|
669
|
+
h.place(world);
|
|
670
|
+
const orbit = { kind: 'orbit', color: '#3366ff', rarity: 6 };
|
|
671
|
+
assert.equal(ctx().wear('p1', orbit), true);
|
|
672
|
+
answer();
|
|
673
|
+
await flush();
|
|
674
|
+
assert.deepEqual(h.join().hubWear, { p1: orbit });
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
await test('a refused wear is logged once and may be sent again', async () => {
|
|
678
|
+
const p = platformHub({
|
|
679
|
+
wear: async () => {
|
|
680
|
+
throw Object.assign(new Error('not a place'), { code: 'CAULDRON_HUB_WEAR_NOT_A_PLACE' });
|
|
681
|
+
},
|
|
682
|
+
});
|
|
683
|
+
const s = session({ hub: p.hub });
|
|
684
|
+
const { h, world, ctx } = boot(s);
|
|
685
|
+
hello(h, s, 'p1');
|
|
686
|
+
h.place(world);
|
|
687
|
+
await flush();
|
|
688
|
+
const warned = [];
|
|
689
|
+
const warn = console.warn;
|
|
690
|
+
console.warn = (text) => warned.push(text);
|
|
691
|
+
try {
|
|
692
|
+
const halo = { kind: 'halo', color: '#ffd700', rarity: 1 };
|
|
693
|
+
ctx().wear('p1', halo);
|
|
694
|
+
await flush();
|
|
695
|
+
ctx().wear('p1', halo);
|
|
696
|
+
await flush();
|
|
697
|
+
} finally {
|
|
698
|
+
console.warn = warn;
|
|
699
|
+
}
|
|
700
|
+
assert.equal(p.calls.filter((c) => c[0] === 'wear').length, 2);
|
|
701
|
+
assert.equal(warned.filter((w) => String(w).includes('wear refused')).length, 1);
|
|
702
|
+
// Kept in this place all the same.
|
|
703
|
+
assert.equal(h.join().hubWear.p1.kind, 'halo');
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
await test('an SDK without hub.wear keeps the wearable in this place only', async () => {
|
|
707
|
+
const p = platformHub();
|
|
708
|
+
delete p.hub.wear;
|
|
709
|
+
const s = session({ hub: p.hub });
|
|
710
|
+
const { h, world, ctx } = boot(s);
|
|
711
|
+
hello(h, s, 'p1');
|
|
712
|
+
h.place(world);
|
|
713
|
+
await flush();
|
|
714
|
+
assert.equal(ctx().wear('p1', { kind: 'halo', color: '#ffd700', rarity: 1 }), true);
|
|
715
|
+
assert.equal(h.join().hubWear.p1.kind, 'halo');
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
await test("hub.results is ghost's read of a player: kept from the arrival read, refreshed once a minute, copies", async () => {
|
|
719
|
+
const now = new Date().toISOString();
|
|
720
|
+
let reads = 0;
|
|
721
|
+
const p = platformHub({
|
|
722
|
+
read: (input) => {
|
|
723
|
+
if (!input.userIds) {
|
|
724
|
+
return { players: {}, boards: {} };
|
|
725
|
+
}
|
|
726
|
+
reads += 1;
|
|
727
|
+
return {
|
|
728
|
+
players: {
|
|
729
|
+
101: {
|
|
730
|
+
avatar: 1,
|
|
731
|
+
recent: [{ deckId: 'race-deck', place: 'main', title: 'Foot Race', outcome: 'win', score: 16900, unit: 'ms', better: 'lower', stats: { laps: 3 }, at: now, evil: 'x' }],
|
|
732
|
+
records: [{ deckId: 'race-deck', place: 'main', title: 'Foot Race', plays: reads, outcomes: { win: 2, lose: 1, draw: 0 }, bestScore: 16900, unit: 'ms', better: 'lower', winStreak: 2, lastOutcome: 'win', lastScore: 16900, lastAt: now }],
|
|
733
|
+
},
|
|
734
|
+
},
|
|
735
|
+
boards: {},
|
|
736
|
+
};
|
|
737
|
+
},
|
|
738
|
+
});
|
|
739
|
+
const s = session({ hub: p.hub });
|
|
740
|
+
const { h, world, ctx } = boot(s);
|
|
741
|
+
hello(h, s, 'p1');
|
|
742
|
+
h.place(world);
|
|
743
|
+
await flush();
|
|
744
|
+
h.place(world);
|
|
745
|
+
const first = ctx().results('p1');
|
|
746
|
+
assert.equal(first.recent[0].title, 'Foot Race');
|
|
747
|
+
assert.equal(first.recent[0].evil, undefined);
|
|
748
|
+
assert.equal(first.records[0].winStreak, 2);
|
|
749
|
+
// A copy: the deck cannot change the kit's.
|
|
750
|
+
first.records[0].plays = 999;
|
|
751
|
+
assert.notEqual(ctx().results('p1').records[0].plays, 999);
|
|
752
|
+
assert.equal(ctx().results('p3'), null);
|
|
753
|
+
// Another hello (an avatar change) keeps it.
|
|
754
|
+
hello(h, s, 'p1', { avatar: 2 });
|
|
755
|
+
assert.equal(ctx().results('p1').recent[0].title, 'Foot Race');
|
|
756
|
+
// A minute on, everyone here is read again in one read.
|
|
757
|
+
const realNow = Date.now;
|
|
758
|
+
Date.now = () => realNow() + 61000;
|
|
759
|
+
try {
|
|
760
|
+
const before = reads;
|
|
761
|
+
h.place(world);
|
|
762
|
+
await flush();
|
|
763
|
+
assert.equal(reads, before + 1);
|
|
764
|
+
assert.equal(ctx().results('p1').records[0].plays, reads);
|
|
765
|
+
} finally {
|
|
766
|
+
Date.now = realNow;
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
await test('an older read never replaces a newer one', async () => {
|
|
771
|
+
const H = await import('../code/server/history.js');
|
|
772
|
+
const h = { players: new Map([['p1', {}]]) };
|
|
773
|
+
H.take(h, 'p1', { recent: [], records: [{ plays: 2 }] }, 2000);
|
|
774
|
+
H.take(h, 'p1', { recent: [], records: [{ plays: 1 }] }, 1000);
|
|
775
|
+
assert.equal(H.results(h, 'p1').records[0].plays, 2);
|
|
776
|
+
H.take(h, 'p1', { recent: [], records: [{ plays: 3 }] }, 3000);
|
|
777
|
+
assert.equal(H.results(h, 'p1').records[0].plays, 3);
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
await test('a layer door fires no pad: each signed-in player is told to go', async () => {
|
|
781
|
+
const actors = globalThis.__hubTestActors;
|
|
782
|
+
globalThis.__hubTestActors = [
|
|
783
|
+
...actors,
|
|
784
|
+
{
|
|
785
|
+
id: 'cove-door',
|
|
786
|
+
components: {
|
|
787
|
+
HubDoor: { id: 'cove', to: 'deck:cove', kind: 'layer', title: 'Pebble Cove' },
|
|
788
|
+
Transform: { x: -5, y: 0, z: 5 },
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
];
|
|
792
|
+
const log = console.log;
|
|
793
|
+
const warn = console.warn;
|
|
794
|
+
console.log = () => {};
|
|
795
|
+
console.warn = () => {};
|
|
796
|
+
try {
|
|
797
|
+
const p = platformHub();
|
|
798
|
+
const s = session({ hub: p.hub });
|
|
799
|
+
const { ctx } = boot(s);
|
|
800
|
+
ctx().pad('cove', ['p1', 'p2']);
|
|
801
|
+
assert.equal(ctx().go('cove', ['p1', 'p2', 'p3']), 'cove');
|
|
802
|
+
await flush();
|
|
803
|
+
assert.equal(p.calls.filter((c) => c[0] === 'pad').length, 0);
|
|
804
|
+
const gos = s.sent.filter(([, d]) => d.k === 'hub-go');
|
|
805
|
+
assert.deepEqual(
|
|
806
|
+
gos.map(([id, d]) => [id, d.door, d.key, d.pad, d.classic, d.party]),
|
|
807
|
+
[
|
|
808
|
+
['p1', 'cove', null, undefined, undefined, 2],
|
|
809
|
+
['p2', 'cove', null, undefined, undefined, 2],
|
|
810
|
+
],
|
|
811
|
+
);
|
|
812
|
+
// A guest alone does not go; a pad door beside it still fires.
|
|
813
|
+
assert.equal(ctx().go('cove', ['p3']), null);
|
|
814
|
+
assert.notEqual(ctx().go('race', ['p1']), null);
|
|
815
|
+
await flush();
|
|
816
|
+
assert.equal(p.calls.filter((c) => c[0] === 'pad' && c[1].fire).length, 1);
|
|
817
|
+
} finally {
|
|
818
|
+
console.log = log;
|
|
819
|
+
console.warn = warn;
|
|
820
|
+
globalThis.__hubTestActors = actors;
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
await test("a goal label is one player's own; for everyone it is a sign", async () => {
|
|
825
|
+
const { setLabel } = await import('../code/server/labels.js');
|
|
826
|
+
const h = { labels: new Map(), labelsMe: new Map(), sim: { timeMs: 0 } };
|
|
827
|
+
setLabel(h, 'door', 'this way', { style: 'goal', to: ['p1'] });
|
|
828
|
+
setLabel(h, 'door', 'Race', { style: 'goal' });
|
|
829
|
+
assert.equal(h.labelsMe.get('p1').get('door').style, 'goal');
|
|
830
|
+
assert.equal(h.labels.get('door').style, 'sign');
|
|
831
|
+
setLabel(h, 'door', null, { to: ['p1'] });
|
|
832
|
+
assert.equal(h.labelsMe.get('p1').has('door'), false);
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
console.log(`hub ops: ${n} tests passed`);
|