castle-web-cli 0.4.228 → 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 +11 -3
- package/dist/agent-prompts.js +153 -53
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +43 -33
- package/dist/api.d.ts +47 -2
- package/dist/api.js +85 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +779 -3
- package/dist/castleJson.d.ts +59 -0
- package/dist/castleJson.js +267 -3
- package/dist/check.js +27 -1
- package/dist/cloudGit.d.ts +20 -1
- package/dist/cloudGit.js +267 -10
- 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 +145 -33
- package/dist/index.js +8 -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 +145 -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/sourceLineage.d.ts +42 -0
- package/dist/sourceLineage.js +380 -0
- package/dist/webSourceSync.d.ts +11 -0
- package/dist/webSourceSync.js +26 -9
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +301 -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 +6 -1
- 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 +86 -6
- package/kits/base/sdk/multiplayer.js +157 -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 +49 -2
- package/kits/base/sdk/server/storage.d.ts +55 -2
- package/kits/base/sdk/server/wrapper.d.ts +85 -6
- package/kits/base/sdk/server/wrapper.js +393 -30
- 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,286 @@
|
|
|
1
|
+
// Parties in a town (contract §5, v1.10): invite and accept, a party's state
|
|
2
|
+
// told to each member, a door proposed to the party putting each member who
|
|
3
|
+
// says yes on its pad, `hub.coming`, a member kept while away through a door,
|
|
4
|
+
// and a jump to a door landing on its pad. A game has none of it, and an
|
|
5
|
+
// invitation never crosses a block. `npm run check` runs it; it needs nothing
|
|
6
|
+
// installed.
|
|
7
|
+
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import { register } from 'node:module';
|
|
10
|
+
|
|
11
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
12
|
+
register(
|
|
13
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
14
|
+
export async function resolve(specifier, context, next) {
|
|
15
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') {
|
|
16
|
+
return { url: 'data:text/javascript,${encodeURIComponent(sceneStub)}', shortCircuit: true };
|
|
17
|
+
}
|
|
18
|
+
return next(specifier, context);
|
|
19
|
+
}
|
|
20
|
+
`)}`,
|
|
21
|
+
);
|
|
22
|
+
const { layer } = await import('../code/server/hub.js');
|
|
23
|
+
|
|
24
|
+
globalThis.__hubTestActors = [
|
|
25
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
26
|
+
{ id: 'door-race', components: { HubDoor: { id: 'race', to: 'race' }, Transform: { x: -28, y: 1.4, z: 0, rotationY: 90 } } },
|
|
27
|
+
{ id: 'pad-race', components: { HubPad: { door: 'race', radius: 2 }, Transform: { x: -22, y: 0, z: 0 } } },
|
|
28
|
+
{ id: 'door-gems', components: { HubDoor: { id: 'gems', to: 'race', title: 'Gem Rush' }, Transform: { x: 0, y: 1.4, z: -28, rotationY: 0 } } },
|
|
29
|
+
];
|
|
30
|
+
const castleJson = {
|
|
31
|
+
server: { maxPlayers: 8 },
|
|
32
|
+
hub: {
|
|
33
|
+
contract: 1,
|
|
34
|
+
title: 'Town',
|
|
35
|
+
places: {
|
|
36
|
+
race: {
|
|
37
|
+
title: 'Foot Race',
|
|
38
|
+
scene: 'scenes/race.scene',
|
|
39
|
+
result: { outcomes: ['win', 'lose'], score: { unit: 'ms', better: 'lower', min: 0, max: 600000 } },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const sceneExists = (scene) => ['scenes/main.scene', 'scenes/race.scene'].includes(scene);
|
|
45
|
+
const ROSTER = [
|
|
46
|
+
{ playerId: 'p1', userId: '101', username: 'ada' },
|
|
47
|
+
{ playerId: 'p2', userId: '102', username: 'bo' },
|
|
48
|
+
{ playerId: 'p3', userId: '103', username: 'cy' },
|
|
49
|
+
{ playerId: 'g4', userId: null, username: 'guest' },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
function boot({ sessionId = 'dev:test', hiddenPair = null } = {}) {
|
|
53
|
+
let ctx = null;
|
|
54
|
+
const h = layer(castleJson, { ready: (hub) => (ctx = hub) }, {}, sceneExists);
|
|
55
|
+
const sent = [];
|
|
56
|
+
const session = {
|
|
57
|
+
sessionId,
|
|
58
|
+
players: [...ROSTER],
|
|
59
|
+
send: (playerId, msg) => sent.push([playerId, msg]),
|
|
60
|
+
broadcast() {},
|
|
61
|
+
...(hiddenPair
|
|
62
|
+
? {
|
|
63
|
+
hub: {
|
|
64
|
+
place: 'main',
|
|
65
|
+
arrival: () => null,
|
|
66
|
+
readResults: async () => ({ players: {}, boards: {} }),
|
|
67
|
+
updatePad: async () => ({ status: 'gathering', members: [] }),
|
|
68
|
+
reportResult: async () => ({ recorded: false }),
|
|
69
|
+
hiddenPair,
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
: {}),
|
|
73
|
+
};
|
|
74
|
+
h.sceneFor(session);
|
|
75
|
+
const players = new Map();
|
|
76
|
+
const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
77
|
+
for (const { playerId } of ROSTER) {
|
|
78
|
+
players.set(playerId, body());
|
|
79
|
+
}
|
|
80
|
+
const world = { timeMs: 0, players, bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
81
|
+
h.ready(world);
|
|
82
|
+
const b = { h, session, world, sent, ctx: () => ctx, body };
|
|
83
|
+
for (const { playerId } of ROSTER) {
|
|
84
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar: 0 });
|
|
85
|
+
}
|
|
86
|
+
tick(b, 5000);
|
|
87
|
+
sent.length = 0;
|
|
88
|
+
return b;
|
|
89
|
+
}
|
|
90
|
+
// One server tick, `aheadMs` later than the clock says.
|
|
91
|
+
function tick(b, aheadMs = 0) {
|
|
92
|
+
const realNow = Date.now;
|
|
93
|
+
Date.now = () => realNow() + aheadMs;
|
|
94
|
+
try {
|
|
95
|
+
b.h.place(b.world, []);
|
|
96
|
+
b.h.step(b.world, []);
|
|
97
|
+
} finally {
|
|
98
|
+
Date.now = realNow;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const party = (b, playerId, data) => b.h.message(b.session, { playerId }, { k: 'hub-party', ...data });
|
|
102
|
+
const told = (b, playerId) => b.sent.filter(([to, msg]) => to === playerId && msg.k === 'hub-party').at(-1)?.[1] ?? null;
|
|
103
|
+
const at = (b, playerId) => b.world.players.get(playerId).at;
|
|
104
|
+
|
|
105
|
+
let n = 0;
|
|
106
|
+
|
|
107
|
+
// Invite, accept: a party of two, each told the other; a third joins it.
|
|
108
|
+
{
|
|
109
|
+
const b = boot();
|
|
110
|
+
party(b, 'p1', { op: 'invite', player: 'p2' });
|
|
111
|
+
tick(b);
|
|
112
|
+
assert.deepEqual(told(b, 'p2').invite, { from: 'p1', username: 'ada' });
|
|
113
|
+
assert.equal(told(b, 'p1'), null, 'the inviter is told nothing yet');
|
|
114
|
+
party(b, 'p2', { op: 'accept', from: 'p1' });
|
|
115
|
+
tick(b);
|
|
116
|
+
assert.deepEqual(told(b, 'p1').members, ['p2']);
|
|
117
|
+
assert.deepEqual(told(b, 'p2').members, ['p1']);
|
|
118
|
+
assert.equal(told(b, 'p2').invite, null);
|
|
119
|
+
party(b, 'p2', { op: 'invite', player: 'g4' });
|
|
120
|
+
party(b, 'g4', { op: 'accept', from: 'p2' });
|
|
121
|
+
tick(b);
|
|
122
|
+
assert.deepEqual(told(b, 'p1').members.sort(), ['g4', 'p2']);
|
|
123
|
+
n += 1;
|
|
124
|
+
|
|
125
|
+
// A door proposed to the party: the proposer is on its pad at once, the
|
|
126
|
+
// others are asked, and the place can see how many it waits on.
|
|
127
|
+
party(b, 'p1', { op: 'go', door: 'race' });
|
|
128
|
+
tick(b);
|
|
129
|
+
assert.ok(Math.hypot(at(b, 'p1').x + 22, at(b, 'p1').z) <= 1, `on the pad: ${JSON.stringify(at(b, 'p1'))}`);
|
|
130
|
+
assert.ok(Math.abs(b.world.players.get('p1').facing - (270 * Math.PI) / 180) < 1e-9, 'facing the door');
|
|
131
|
+
const proposal = told(b, 'p2').proposal;
|
|
132
|
+
assert.deepEqual(proposal, { id: proposal.id, door: 'race', by: 'p1', username: 'ada', asked: true });
|
|
133
|
+
assert.equal(told(b, 'p1').proposal.asked, false);
|
|
134
|
+
assert.equal(b.ctx().coming('race'), 2);
|
|
135
|
+
assert.equal(b.ctx().coming('gems'), 0);
|
|
136
|
+
n += 1;
|
|
137
|
+
|
|
138
|
+
// Yes lands on the pad, on a spot of its own; no stays put; nobody is asked twice.
|
|
139
|
+
party(b, 'p2', { op: 'go-yes', id: proposal.id });
|
|
140
|
+
party(b, 'g4', { op: 'go-no', id: proposal.id });
|
|
141
|
+
party(b, 'g4', { op: 'go-yes', id: proposal.id });
|
|
142
|
+
tick(b);
|
|
143
|
+
assert.ok(Math.hypot(at(b, 'p2').x + 22, at(b, 'p2').z) <= 1);
|
|
144
|
+
assert.ok(Math.hypot(at(b, 'p2').x - at(b, 'p1').x, at(b, 'p2').z - at(b, 'p1').z) > 0.5, 'not on top of the proposer');
|
|
145
|
+
assert.ok(Math.hypot(at(b, 'g4').x, at(b, 'g4').z) < 3, 'the one who said no stayed');
|
|
146
|
+
assert.equal(b.ctx().coming('race'), 0);
|
|
147
|
+
assert.equal(told(b, 'p2').proposal, null);
|
|
148
|
+
n += 1;
|
|
149
|
+
|
|
150
|
+
// A signed-in member who leaves the layer (through the door) is kept as
|
|
151
|
+
// away, and is back in the party on return; a guest who leaves is gone.
|
|
152
|
+
b.world.players.delete('p2');
|
|
153
|
+
b.world.players.delete('g4');
|
|
154
|
+
b.session.players = b.session.players.filter((p) => !['p2', 'g4'].includes(p.playerId));
|
|
155
|
+
tick(b);
|
|
156
|
+
assert.deepEqual(told(b, 'p1').members, []);
|
|
157
|
+
assert.equal(told(b, 'p1').away, 1);
|
|
158
|
+
b.session.players.push({ playerId: 'p2b', userId: '102', username: 'bo' });
|
|
159
|
+
b.world.players.set('p2b', b.body());
|
|
160
|
+
b.h.message(b.session, { playerId: 'p2b' }, { k: 'hub-hello', avatar: 0 });
|
|
161
|
+
tick(b, 5000);
|
|
162
|
+
tick(b, 5000);
|
|
163
|
+
assert.deepEqual(told(b, 'p1').members, ['p2b']);
|
|
164
|
+
assert.deepEqual(told(b, 'p2b').members, ['p1']);
|
|
165
|
+
n += 1;
|
|
166
|
+
|
|
167
|
+
// Leave: a party of one is no party.
|
|
168
|
+
party(b, 'p2b', { op: 'leave' });
|
|
169
|
+
tick(b);
|
|
170
|
+
assert.equal(told(b, 'p1').members, null);
|
|
171
|
+
assert.equal(told(b, 'p2b').members, null);
|
|
172
|
+
n += 1;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// A proposal nobody answers, and an invitation nobody answers, run out.
|
|
176
|
+
{
|
|
177
|
+
const b = boot();
|
|
178
|
+
party(b, 'p1', { op: 'invite', player: 'p2' });
|
|
179
|
+
party(b, 'p2', { op: 'accept', from: 'p1' });
|
|
180
|
+
party(b, 'p1', { op: 'go', door: 'race' });
|
|
181
|
+
party(b, 'p3', { op: 'invite', player: 'g4' });
|
|
182
|
+
tick(b);
|
|
183
|
+
assert.equal(b.ctx().coming('race'), 1);
|
|
184
|
+
tick(b, 31000);
|
|
185
|
+
{
|
|
186
|
+
const realNow = Date.now;
|
|
187
|
+
Date.now = () => realNow() + 31000;
|
|
188
|
+
try {
|
|
189
|
+
assert.equal(b.ctx().coming('race'), 0, 'the pad is held 20 s');
|
|
190
|
+
} finally {
|
|
191
|
+
Date.now = realNow;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
assert.equal(told(b, 'p2').proposal.door, 'race', 'the question stays up 45 s');
|
|
195
|
+
tick(b, 46000);
|
|
196
|
+
assert.equal(told(b, 'p2').proposal, null);
|
|
197
|
+
assert.deepEqual(told(b, 'g4').invite, { from: 'p3', username: 'cy' }, 'an invitation waits a minute');
|
|
198
|
+
tick(b, 61000);
|
|
199
|
+
assert.equal(told(b, 'g4').invite, null);
|
|
200
|
+
n += 1;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Alone, Doors > Go lands on the pad too; a door with no pad, in front of it.
|
|
204
|
+
{
|
|
205
|
+
const b = boot();
|
|
206
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-door-jump', door: 'race' });
|
|
207
|
+
assert.ok(Math.hypot(at(b, 'p1').x + 22, at(b, 'p1').z) <= 1, `on the pad: ${JSON.stringify(at(b, 'p1'))}`);
|
|
208
|
+
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-door-jump', door: 'gems' });
|
|
209
|
+
assert.ok(Math.abs(at(b, 'p2').z + 21) < 1e-9, '7 m in front of a door with no pad');
|
|
210
|
+
n += 1;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// No invitation across a block; no parties in a game; no go without a party.
|
|
214
|
+
{
|
|
215
|
+
const b = boot({ hiddenPair: (x, y) => [x, y].sort().join() === 'p1,p2' });
|
|
216
|
+
party(b, 'p1', { op: 'invite', player: 'p2' });
|
|
217
|
+
party(b, 'p3', { op: 'go', door: 'race' });
|
|
218
|
+
tick(b);
|
|
219
|
+
assert.equal(told(b, 'p2'), null);
|
|
220
|
+
assert.ok(Math.hypot(at(b, 'p3').x, at(b, 'p3').z) < 3, 'no party: go does nothing');
|
|
221
|
+
const game = boot({ sessionId: 'dev:hub.race.abc123' });
|
|
222
|
+
party(game, 'p1', { op: 'invite', player: 'p2' });
|
|
223
|
+
tick(game);
|
|
224
|
+
assert.equal(told(game, 'p2'), null);
|
|
225
|
+
n += 1;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// An answer is to what was shown: a yes to an older proposal moves nobody to
|
|
229
|
+
// the door that replaced it, and an accept names its inviter. A party holds
|
|
230
|
+
// a pad once a minute, however often it proposes.
|
|
231
|
+
{
|
|
232
|
+
const b = boot();
|
|
233
|
+
party(b, 'p1', { op: 'invite', player: 'p2' });
|
|
234
|
+
party(b, 'p2', { op: 'accept', from: 'p3' });
|
|
235
|
+
tick(b);
|
|
236
|
+
assert.equal(told(b, 'p1'), null, 'an accept naming someone else joins nothing');
|
|
237
|
+
party(b, 'p2', { op: 'accept', from: 'p1' });
|
|
238
|
+
party(b, 'p1', { op: 'go', door: 'race' });
|
|
239
|
+
tick(b);
|
|
240
|
+
const first = told(b, 'p2').proposal.id;
|
|
241
|
+
assert.equal(b.ctx().coming('race'), 1);
|
|
242
|
+
party(b, 'p1', { op: 'go', door: 'gems' });
|
|
243
|
+
party(b, 'p2', { op: 'go-yes', id: first });
|
|
244
|
+
tick(b);
|
|
245
|
+
assert.ok(Math.hypot(at(b, 'p2').x, at(b, 'p2').z) < 3, 'a yes to the old proposal goes nowhere');
|
|
246
|
+
assert.equal(told(b, 'p2').proposal.door, 'gems');
|
|
247
|
+
assert.equal(b.ctx().coming('gems'), 0, 'the second proposal in a minute holds no pad');
|
|
248
|
+
n += 1;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// A member who picks the door the party is already going to has said yes:
|
|
252
|
+
// they are put on the pad and no second proposal is made.
|
|
253
|
+
{
|
|
254
|
+
const b = boot();
|
|
255
|
+
party(b, 'p1', { op: 'invite', player: 'p2' });
|
|
256
|
+
party(b, 'p2', { op: 'accept', from: 'p1' });
|
|
257
|
+
party(b, 'p1', { op: 'go', door: 'race' });
|
|
258
|
+
tick(b);
|
|
259
|
+
const first = told(b, 'p2').proposal.id;
|
|
260
|
+
party(b, 'p2', { op: 'go', door: 'race' });
|
|
261
|
+
tick(b);
|
|
262
|
+
assert.ok(Math.hypot(at(b, 'p2').x + 22, at(b, 'p2').z) <= 1, 'on the pad');
|
|
263
|
+
assert.equal(b.ctx().coming('race'), 0, 'nobody is left to answer');
|
|
264
|
+
assert.equal(told(b, 'p1').proposal, null);
|
|
265
|
+
party(b, 'p1', { op: 'go', door: 'race' });
|
|
266
|
+
tick(b);
|
|
267
|
+
assert.notEqual(told(b, 'p2').proposal?.id, first, 'a new proposal, once the first was answered');
|
|
268
|
+
n += 1;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// A member a block hides from the proposer hears nothing of the proposal.
|
|
272
|
+
{
|
|
273
|
+
const b = boot({ hiddenPair: (x, y) => [x, y].sort().join() === 'p1,p2' });
|
|
274
|
+
party(b, 'p3', { op: 'invite', player: 'p1' });
|
|
275
|
+
party(b, 'p1', { op: 'accept', from: 'p3' });
|
|
276
|
+
party(b, 'p3', { op: 'invite', player: 'p2' });
|
|
277
|
+
party(b, 'p2', { op: 'accept', from: 'p3' });
|
|
278
|
+
party(b, 'p1', { op: 'go', door: 'race' });
|
|
279
|
+
tick(b);
|
|
280
|
+
assert.equal(told(b, 'p2').proposal, null);
|
|
281
|
+
assert.deepEqual(told(b, 'p2').members, ['p3']);
|
|
282
|
+
assert.equal(told(b, 'p3').proposal.username, 'ada');
|
|
283
|
+
n += 1;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
console.log(`test-party: ${n} passed`);
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Quick reactions and phrases (contract §6, v1.11): a reaction is an index
|
|
2
|
+
// into the kit's emoji and a phrase an id of the kit's; the server carries no
|
|
3
|
+
// text, names the door a "Let's play" speaker stands by, limits each player,
|
|
4
|
+
// and tells nobody a block hides the speaker from. The client words them.
|
|
5
|
+
// `npm run check` runs it; it needs nothing installed.
|
|
6
|
+
|
|
7
|
+
import assert from 'node:assert/strict';
|
|
8
|
+
import { register } from 'node:module';
|
|
9
|
+
|
|
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
|
+
const HubState = await import('../code/client/state.js');
|
|
23
|
+
const { makeSay, REACTIONS } = await import('../code/client/say.js');
|
|
24
|
+
|
|
25
|
+
globalThis.__hubTestActors = [
|
|
26
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
27
|
+
{ id: 'door-race', components: { HubDoor: { id: 'race', to: 'race' }, Transform: { x: -28, y: 1.4, z: 0, rotationY: 90 } } },
|
|
28
|
+
];
|
|
29
|
+
const castleJson = {
|
|
30
|
+
server: { maxPlayers: 8 },
|
|
31
|
+
hub: {
|
|
32
|
+
contract: 1,
|
|
33
|
+
title: 'Town',
|
|
34
|
+
places: { race: { title: 'Foot Race', scene: 'scenes/race.scene', result: { outcomes: ['win', 'lose'] } } },
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const sceneExists = (scene) => ['scenes/main.scene', 'scenes/race.scene'].includes(scene);
|
|
38
|
+
const ROSTER = ['p1', 'p2', 'p3'].map((playerId, i) => ({ playerId, userId: String(101 + i), username: playerId }));
|
|
39
|
+
|
|
40
|
+
function boot({ sessionId = 'dev:test', hiddenPair = null } = {}) {
|
|
41
|
+
const h = layer(castleJson, {}, {}, sceneExists);
|
|
42
|
+
const sent = [];
|
|
43
|
+
const session = {
|
|
44
|
+
sessionId,
|
|
45
|
+
players: ROSTER,
|
|
46
|
+
send: (playerId, msg) => sent.push([playerId, msg]),
|
|
47
|
+
broadcast: (msg) => sent.push(['*', msg]),
|
|
48
|
+
...(hiddenPair
|
|
49
|
+
? { hub: { place: 'main', arrival: () => null, readResults: async () => ({ players: {}, boards: {} }), updatePad: async () => ({}), reportResult: async () => ({}), hiddenPair } }
|
|
50
|
+
: {}),
|
|
51
|
+
};
|
|
52
|
+
h.sceneFor(session);
|
|
53
|
+
const players = new Map(ROSTER.map(({ playerId }) => [playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } }]));
|
|
54
|
+
const world = { timeMs: 0, players, bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
55
|
+
h.ready(world);
|
|
56
|
+
for (const { playerId } of ROSTER) {
|
|
57
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar: 0 });
|
|
58
|
+
}
|
|
59
|
+
const realNow = Date.now;
|
|
60
|
+
Date.now = () => realNow() + 5000;
|
|
61
|
+
h.place(world, []);
|
|
62
|
+
Date.now = realNow;
|
|
63
|
+
sent.length = 0;
|
|
64
|
+
return { h, session, world, sent };
|
|
65
|
+
}
|
|
66
|
+
const say = (b, playerId, data) => b.h.message(b.session, { playerId }, { k: 'hub-say', ...data });
|
|
67
|
+
const said = (b) => b.sent.filter(([, msg]) => msg.k === 'hub-said');
|
|
68
|
+
|
|
69
|
+
let n = 0;
|
|
70
|
+
|
|
71
|
+
// A reaction and a phrase go to everyone; text, an unknown id and a game's
|
|
72
|
+
// phrase in a town go nowhere.
|
|
73
|
+
{
|
|
74
|
+
const b = boot();
|
|
75
|
+
say(b, 'p1', { r: 2 });
|
|
76
|
+
say(b, 'p2', { p: 'here' });
|
|
77
|
+
say(b, 'p3', { p: 'gg' });
|
|
78
|
+
say(b, 'p3', { p: 'nonsense', text: 'hello' });
|
|
79
|
+
say(b, 'p3', { r: 99 });
|
|
80
|
+
say(b, 'p3', { text: 'free text' });
|
|
81
|
+
assert.deepEqual(said(b), [
|
|
82
|
+
['*', { k: 'hub-said', player: 'p1', r: 2 }],
|
|
83
|
+
['*', { k: 'hub-said', player: 'p2', p: 'here' }],
|
|
84
|
+
]);
|
|
85
|
+
n += 1;
|
|
86
|
+
|
|
87
|
+
// "Let's play" names the door the speaker stands by, or none.
|
|
88
|
+
say(b, 'p3', { p: 'play' });
|
|
89
|
+
Object.assign(b.world.players.get('p3').at, { x: -22, z: 2 });
|
|
90
|
+
say(b, 'p3', { p: 'play' });
|
|
91
|
+
assert.deepEqual(said(b).slice(2).map(([, msg]) => msg.door), [null, 'race']);
|
|
92
|
+
n += 1;
|
|
93
|
+
|
|
94
|
+
// A burst of three, then no more until the limit refills.
|
|
95
|
+
say(b, 'p1', { r: 0 });
|
|
96
|
+
say(b, 'p1', { r: 0 });
|
|
97
|
+
say(b, 'p1', { r: 0 });
|
|
98
|
+
assert.equal(said(b).filter(([, msg]) => msg.player === 'p1').length, 3);
|
|
99
|
+
n += 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Never across a block: the hidden player is not told, everyone else is.
|
|
103
|
+
{
|
|
104
|
+
const b = boot({ hiddenPair: (x, y) => [x, y].sort().join() === 'p1,p2' });
|
|
105
|
+
say(b, 'p1', { r: 1 });
|
|
106
|
+
assert.deepEqual(said(b).map(([to]) => to).sort(), ['p1', 'p3']);
|
|
107
|
+
n += 1;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// A game has its own phrases.
|
|
111
|
+
{
|
|
112
|
+
const b = boot({ sessionId: 'dev:hub.race.abc123' });
|
|
113
|
+
say(b, 'p1', { p: 'gg' });
|
|
114
|
+
say(b, 'p1', { p: 'play' });
|
|
115
|
+
assert.deepEqual(said(b).map(([, msg]) => msg.p), ['gg']);
|
|
116
|
+
n += 1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// The client words what was said: bubbles, the feed, and "Over here!" heard.
|
|
120
|
+
{
|
|
121
|
+
HubState.hub.place = { title: 'Town', result: null };
|
|
122
|
+
HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
|
|
123
|
+
const s = makeSay();
|
|
124
|
+
assert.deepEqual(s.phrases().map(([id]) => id), ['here', 'play', 'wait', 'yes', 'no']);
|
|
125
|
+
const heard = [];
|
|
126
|
+
HubState.hub.saidEvents.push({ player: 'p2', p: 'play', door: 'race' }, { player: 'p2', p: 'here' }, { player: 'me', r: 0 }, { player: 'p9', p: 'here' }, { player: 'p2', p: 'bogus' });
|
|
127
|
+
s.frame(1000, 'me', (id) => ({ p2: 'bo' })[id] ?? null, (id) => heard.push(id));
|
|
128
|
+
assert.deepEqual(s.feed().map((line) => line.text), ["bo: Let's play Foot Race", 'bo: Over here!']);
|
|
129
|
+
assert.deepEqual(heard, ['p2'], 'a player this client does not know is not heard');
|
|
130
|
+
const scene = { multiplayer: { avatars: { actors: new Map([['p2', 'a2']]) } }, getActor: (id) => ({ components: { Transform: { x: id === 'a2' ? 5 : 0, y: 1, z: 0 } } }) };
|
|
131
|
+
const items = s.labels(scene, { id: 'local' }, null, null, (cam, x) => ({ x, y: 0 }), 'me');
|
|
132
|
+
assert.deepEqual(items.map((i) => [i.id, i.text]), [['said:p2', 'Over here!'], ['react:me', REACTIONS[0]]]);
|
|
133
|
+
s.frame(20000, 'me', () => null);
|
|
134
|
+
assert.deepEqual([s.feed(), s.labels(scene, { id: 'local' }, null, null, () => null, 'me')], [[], []]);
|
|
135
|
+
// A chat line is a bubble and a feed line; another player's can be reported.
|
|
136
|
+
s.chat(21000, 'p2', 'bo', { id: 'm1', text: 'hello there', mine: false }, 6000);
|
|
137
|
+
s.chat(21000, 'me', 'You', { id: 'm2', text: 'hi', mine: true }, 6000);
|
|
138
|
+
assert.deepEqual(s.feed(), [{ text: 'bo: hello there', id: 'm1' }, { text: 'You: hi', id: null }]);
|
|
139
|
+
// Leaving the place leaves what was said there.
|
|
140
|
+
HubState.hub.saidEvents.push({ player: 'p2', p: 'here' });
|
|
141
|
+
s.frame(30000, 'me', () => 'bo');
|
|
142
|
+
s.clear();
|
|
143
|
+
assert.deepEqual(s.feed(), []);
|
|
144
|
+
HubState.hub.place = null;
|
|
145
|
+
HubState.hub.doors = [];
|
|
146
|
+
n += 1;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
console.log(`test-say: ${n} passed`);
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Finding someone in a town (contract §5): a client asks where players are
|
|
2
|
+
// (`hub-where`) and is told each one's spot and the place's words for it --
|
|
3
|
+
// on a door's pad, near a door, what the place's `where` hook calls it --
|
|
4
|
+
// and Join puts a player beside another (`hub-goto`). A game answers neither,
|
|
5
|
+
// nothing crosses a block, and a held player stays put. `npm run check` runs
|
|
6
|
+
// it; it needs nothing installed.
|
|
7
|
+
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import { register } from 'node:module';
|
|
10
|
+
|
|
11
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
12
|
+
register(
|
|
13
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
14
|
+
export async function resolve(specifier, context, next) {
|
|
15
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') {
|
|
16
|
+
return { url: 'data:text/javascript,${encodeURIComponent(sceneStub)}', shortCircuit: true };
|
|
17
|
+
}
|
|
18
|
+
return next(specifier, context);
|
|
19
|
+
}
|
|
20
|
+
`)}`,
|
|
21
|
+
);
|
|
22
|
+
const { layer } = await import('../code/server/hub.js');
|
|
23
|
+
|
|
24
|
+
globalThis.__hubTestActors = [
|
|
25
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
26
|
+
{ id: 'door-race', components: { HubDoor: { id: 'race', to: 'race' }, Transform: { x: -28, y: 1.4, z: 0, rotationY: 90 } } },
|
|
27
|
+
{ id: 'pad-race', components: { HubPad: { door: 'race', radius: 2 }, Transform: { x: -22, y: 0, z: 0 } } },
|
|
28
|
+
{ id: 'crate', components: { Solid: {}, Shape: { kind: 'box', width: 1, height: 2, depth: 1 }, Transform: { x: 11.6, y: 1, z: 10 } } },
|
|
29
|
+
];
|
|
30
|
+
const castleJson = {
|
|
31
|
+
server: { maxPlayers: 8 },
|
|
32
|
+
hub: {
|
|
33
|
+
contract: 1,
|
|
34
|
+
title: 'Town',
|
|
35
|
+
places: {
|
|
36
|
+
race: {
|
|
37
|
+
title: 'Foot Race',
|
|
38
|
+
scene: 'scenes/race.scene',
|
|
39
|
+
result: { outcomes: ['win', 'lose'], score: { unit: 'ms', better: 'lower', min: 0, max: 600000 } },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const sceneExists = (scene) => ['scenes/main.scene', 'scenes/race.scene'].includes(scene);
|
|
45
|
+
const PLAYERS = [
|
|
46
|
+
{ playerId: 'p1', userId: '101', username: 'ada' },
|
|
47
|
+
{ playerId: 'p2', userId: '102', username: 'bo' },
|
|
48
|
+
{ playerId: 'p3', userId: '103', username: 'cy' },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
function boot({ sessionId = 'dev:test', hooks = {}, hiddenPair = null } = {}) {
|
|
52
|
+
let ctx = null;
|
|
53
|
+
const h = layer(castleJson, { ...hooks, ready: (hub) => (ctx = hub) }, {}, sceneExists);
|
|
54
|
+
const sent = [];
|
|
55
|
+
const session = {
|
|
56
|
+
sessionId,
|
|
57
|
+
players: PLAYERS,
|
|
58
|
+
send: (playerId, msg) => sent.push([playerId, msg]),
|
|
59
|
+
broadcast() {},
|
|
60
|
+
...(hiddenPair
|
|
61
|
+
? {
|
|
62
|
+
hub: {
|
|
63
|
+
place: 'main',
|
|
64
|
+
arrival: () => null,
|
|
65
|
+
readResults: async () => ({ players: {}, boards: {} }),
|
|
66
|
+
updatePad: async () => ({ status: 'gathering', members: [] }),
|
|
67
|
+
reportResult: async () => ({ recorded: false }),
|
|
68
|
+
hiddenPair,
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
: {}),
|
|
72
|
+
};
|
|
73
|
+
h.sceneFor(session);
|
|
74
|
+
const players = new Map();
|
|
75
|
+
for (const { playerId } of PLAYERS) {
|
|
76
|
+
players.set(playerId, { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
77
|
+
}
|
|
78
|
+
const world = { timeMs: 0, players, bodies: new Map(), scenePath: 'scenes/main.scene' };
|
|
79
|
+
h.ready(world);
|
|
80
|
+
for (const { playerId } of PLAYERS) {
|
|
81
|
+
h.message(session, { playerId }, { k: 'hub-hello', avatar: 0 });
|
|
82
|
+
}
|
|
83
|
+
// Everyone arrives once the group wait has passed.
|
|
84
|
+
const realNow = Date.now;
|
|
85
|
+
Date.now = () => realNow() + 5000;
|
|
86
|
+
h.place(world, []);
|
|
87
|
+
Date.now = realNow;
|
|
88
|
+
sent.length = 0;
|
|
89
|
+
return { h, session, world, sent, ctx: () => ctx };
|
|
90
|
+
}
|
|
91
|
+
const at = (b, playerId) => b.world.players.get(playerId).at;
|
|
92
|
+
const put = (b, playerId, x, z) => Object.assign(at(b, playerId), { x, z });
|
|
93
|
+
const whereOf = (b) => b.sent.filter(([, msg]) => msg.k === 'hub-where').at(-1);
|
|
94
|
+
|
|
95
|
+
let n = 0;
|
|
96
|
+
|
|
97
|
+
// Where: on a pad, the place's own words, near a door, or nothing.
|
|
98
|
+
{
|
|
99
|
+
const b = boot({ hooks: { where: (hub, spot) => (spot.x > 5 ? 'Lucky Lane' : null) } });
|
|
100
|
+
put(b, 'p2', -21, 0.5);
|
|
101
|
+
put(b, 'p3', 9, 9);
|
|
102
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-where', ids: ['p2', 'p3', 'p1', 'nobody', 7] });
|
|
103
|
+
const [to, msg] = whereOf(b);
|
|
104
|
+
assert.equal(to, 'p1');
|
|
105
|
+
assert.deepEqual(msg.at, {
|
|
106
|
+
p2: { x: -21, z: 0.5, where: 'on the Foot Race pad', door: 'race', on: true },
|
|
107
|
+
p3: { x: 9, z: 9, where: 'Lucky Lane', door: null },
|
|
108
|
+
});
|
|
109
|
+
n += 1;
|
|
110
|
+
|
|
111
|
+
// Asked again at once: no second answer.
|
|
112
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-where', ids: ['p2'] });
|
|
113
|
+
assert.equal(b.sent.filter(([, m]) => m.k === 'hub-where').length, 1);
|
|
114
|
+
n += 1;
|
|
115
|
+
|
|
116
|
+
// Near a door, and nowhere in particular.
|
|
117
|
+
put(b, 'p2', -24, 4);
|
|
118
|
+
put(b, 'p3', 0, 3);
|
|
119
|
+
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-where', ids: ['p3'] });
|
|
120
|
+
assert.deepEqual(whereOf(b)[1].at, { p3: { x: 0, z: 3, where: null, door: null } });
|
|
121
|
+
b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-where', ids: ['p2'] });
|
|
122
|
+
assert.deepEqual(whereOf(b)[1].at, { p2: { x: -24, z: 4, where: 'near Foot Race', door: 'race' } });
|
|
123
|
+
n += 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Join puts a player beside the other, facing them, and tells their camera.
|
|
127
|
+
{
|
|
128
|
+
const b = boot();
|
|
129
|
+
put(b, 'p2', 10, 10);
|
|
130
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
|
|
131
|
+
const me = b.world.players.get('p1');
|
|
132
|
+
// The first spot (to p2's right, x + 1.6) is inside the crate: the next one.
|
|
133
|
+
assert.ok(Math.abs(me.at.x - 8.4) < 1e-9 && Math.abs(me.at.z - 10) < 1e-9, `beside: ${JSON.stringify(me.at)}`);
|
|
134
|
+
assert.ok(Math.abs(me.facing - Math.PI / 2) < 1e-9, 'faces them');
|
|
135
|
+
assert.equal(me.clamped, true);
|
|
136
|
+
assert.deepEqual(b.sent.at(-1), ['p1', { k: 'hub-jumped', facing: me.facing, to: 'p2' }]);
|
|
137
|
+
n += 1;
|
|
138
|
+
|
|
139
|
+
// A second jump within a second, a jump to oneself or to nobody: ignored.
|
|
140
|
+
put(b, 'p3', -10, -10);
|
|
141
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p3' });
|
|
142
|
+
assert.ok(Math.abs(me.at.x - 8.4) < 1e-9, 'still beside p2');
|
|
143
|
+
b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-goto', player: 'p3' });
|
|
144
|
+
b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-goto', player: 'ghost' });
|
|
145
|
+
assert.deepEqual([at(b, 'p3').x, at(b, 'p3').z], [-10, -10]);
|
|
146
|
+
n += 1;
|
|
147
|
+
|
|
148
|
+
// A held player stays where the place holds them.
|
|
149
|
+
b.ctx().hold('p3', { x: -10, y: 1, z: -10 });
|
|
150
|
+
b.h.message(b.session, { playerId: 'p3' }, { k: 'hub-goto', player: 'p2' });
|
|
151
|
+
assert.deepEqual([at(b, 'p3').x, at(b, 'p3').z], [-10, -10]);
|
|
152
|
+
n += 1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// A block hides both ways: no answer about, and no jump to, a hidden player.
|
|
156
|
+
{
|
|
157
|
+
const b = boot({ hiddenPair: (a, c) => [a, c].sort().join() === 'p1,p2' });
|
|
158
|
+
put(b, 'p2', 10, 10);
|
|
159
|
+
put(b, 'p3', 5, 5);
|
|
160
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-where', ids: ['p2', 'p3'] });
|
|
161
|
+
assert.deepEqual(Object.keys(whereOf(b)[1].at), ['p3']);
|
|
162
|
+
put(b, 'p1', 0, 0);
|
|
163
|
+
// A held caller (a sitter is one) is not let go by a jump at a blocked
|
|
164
|
+
// player, any more than by one at nobody: the block shows nothing.
|
|
165
|
+
b.ctx().hold('p1', { x: 0, y: 1, z: 0 });
|
|
166
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
|
|
167
|
+
assert.deepEqual([at(b, 'p1').x, at(b, 'p1').z], [0, 0]);
|
|
168
|
+
n += 1;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// A game answers neither.
|
|
172
|
+
{
|
|
173
|
+
const b = boot({ sessionId: 'dev:hub.race.abc123' });
|
|
174
|
+
put(b, 'p2', 10, 10);
|
|
175
|
+
put(b, 'p1', 0, 0);
|
|
176
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-where', ids: ['p2'] });
|
|
177
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-goto', player: 'p2' });
|
|
178
|
+
assert.equal(whereOf(b), undefined);
|
|
179
|
+
assert.deepEqual([at(b, 'p1').x, at(b, 'p1').z], [0, 0]);
|
|
180
|
+
n += 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
console.log(`test-together: ${n} passed`);
|
|
@@ -7,26 +7,26 @@
|
|
|
7
7
|
"imports": {
|
|
8
8
|
"castle.real-time": {
|
|
9
9
|
"deckId": "xFVr-afOLuUQ",
|
|
10
|
-
"version": "2026-
|
|
10
|
+
"version": "2026-10-03T11:33:47.833Z"
|
|
11
11
|
},
|
|
12
12
|
"castle.physics-3d": {
|
|
13
13
|
"deckId": "JH0SclbPVP0y",
|
|
14
|
-
"version": "2026-
|
|
14
|
+
"version": "2026-10-03T09:17:32.572Z"
|
|
15
15
|
},
|
|
16
16
|
"castle.physics-2d": {
|
|
17
17
|
"deckId": "ckRZGFW4iPrx",
|
|
18
|
-
"version": "2026-
|
|
18
|
+
"version": "2026-10-03T04:25:18.207Z",
|
|
19
19
|
"via": "castle.physics-3d"
|
|
20
20
|
},
|
|
21
21
|
"castle.base": {
|
|
22
22
|
"deckId": "yRcmH4_aYllE",
|
|
23
|
-
"version": "2026-
|
|
23
|
+
"version": "2026-10-03T11:33:43.975Z"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"autoUpdateWhenImported": true,
|
|
27
27
|
"deckId": "ZwA_P_-VO-Qh",
|
|
28
28
|
"cardId": "bvRmCzyUpt_a",
|
|
29
|
-
"publishedVersion": "2026-
|
|
29
|
+
"publishedVersion": "2026-10-03T13:23:59.648Z",
|
|
30
30
|
"main": "main.jsx",
|
|
31
31
|
"server": {
|
|
32
32
|
"main": "code/server/index.js",
|