castle-web-cli 0.4.229 → 0.4.231
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 +860 -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/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +25 -13
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +237 -46
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- 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 +126 -9
- 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 +99 -14
- 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 +406 -53
- 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 +9 -0
- package/kits/base/sdk/castle.js +5 -0
- package/kits/base/sdk/commands.d.ts +223 -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 +158 -8
- package/kits/base/sdk/save.d.ts +197 -0
- package/kits/base/sdk/save.js +525 -0
- package/kits/base/sdk/saveCoordinator.d.ts +39 -0
- package/kits/base/sdk/saveCoordinator.js +252 -0
- 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 +58 -4
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +36 -2
- package/kits/base/sdk/server/wrapper.js +92 -11
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- 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 +149 -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 +1035 -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 +376 -0
- package/kits/hub-game/code/client/hookLayer.js +236 -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 +143 -0
- package/kits/hub-game/code/client/talk.js +233 -0
- package/kits/hub-game/code/client/tiers.js +480 -0
- package/kits/hub-game/code/client/together.js +440 -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 +248 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1998 -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 +554 -0
- package/kits/hub-game/code/server/npcs.js +733 -0
- package/kits/hub-game/code/server/party.js +439 -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 +2347 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1209 -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-client.mjs +328 -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 +1518 -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 +270 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +724 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +369 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-tiers.mjs +666 -0
- package/kits/hub-game/scripts/test-together.mjs +215 -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/CLAUDE.md +2 -0
- 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 +117 -5
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
- package/kits/physics-3d/CLAUDE.md +285 -1
- package/kits/physics-3d/behaviors/Player.jsx +74 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -5
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +527 -5
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
- package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
- package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
- package/kits/physics-3d/systems/physics3d.js +187 -5
- 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,518 @@
|
|
|
1
|
+
// Idle play (contract §6, v1.6), the server's half: a client's `hub-emote` is
|
|
2
|
+
// checked (a kit emote, a player who is here, one every 2 s, the place's
|
|
3
|
+
// `emote` hook) and latched for everyone; `hub-sit` holds a player on a free
|
|
4
|
+
// seat near them and `hub-stand`, the place's own hold or release, or leaving
|
|
5
|
+
// gets them up; `hub.sound` plays a declared file at an actor, within bounds.
|
|
6
|
+
// A place without `idle` is sent exactly what it was. `npm run check` runs it;
|
|
7
|
+
// it needs nothing installed.
|
|
8
|
+
|
|
9
|
+
import assert from 'node:assert/strict';
|
|
10
|
+
import { register } from 'node:module';
|
|
11
|
+
|
|
12
|
+
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
13
|
+
register(
|
|
14
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
15
|
+
export async function resolve(specifier, context, next) {
|
|
16
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') {
|
|
17
|
+
return { url: 'data:text/javascript,${encodeURIComponent(sceneStub)}', shortCircuit: true };
|
|
18
|
+
}
|
|
19
|
+
return next(specifier, context);
|
|
20
|
+
}
|
|
21
|
+
`)}`,
|
|
22
|
+
);
|
|
23
|
+
const { layer } = await import('../code/server/hub.js');
|
|
24
|
+
const Idle = await import('../code/server/idle.js');
|
|
25
|
+
const Manifest = await import('../code/server/manifest.js');
|
|
26
|
+
const ClientIdle = await import('../code/client/idle.js');
|
|
27
|
+
|
|
28
|
+
const bench = { kind: 'box', width: 2.4, height: 0.5, depth: 0.6 };
|
|
29
|
+
globalThis.__hubTestActors = [
|
|
30
|
+
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
31
|
+
{ id: 'bench-a', components: { Transform: { x: 1, y: 0.25, z: 0, rotationY: 90 }, Shape: bench, Solid: {}, HubSeat: { face: 180 } } },
|
|
32
|
+
{ id: 'bench-b', components: { Transform: { x: -1, y: 0.25, z: 0 }, Shape: bench, Solid: {}, HubSeat: {} } },
|
|
33
|
+
{ id: 'stool', components: { Transform: { x: 0, y: 0, z: 1 }, HubSeat: { height: 1.2 } } },
|
|
34
|
+
{ id: 'cart', components: { Transform: { x: 0, y: 0.25, z: -1 }, Shape: bench, Body: { type: 'kinematic' }, HubSeat: {} } },
|
|
35
|
+
{ id: 'far-bench', components: { Transform: { x: 20, y: 0.25, z: 0 }, Shape: bench, HubSeat: {} } },
|
|
36
|
+
{ id: 'jukebox', components: { Transform: { x: 3, y: 1, z: 3 }, Shape: { kind: 'box' } } },
|
|
37
|
+
{ id: 'lamp', components: { Transform: { x: -3, y: 1, z: 3 }, Shape: { kind: 'box' } } },
|
|
38
|
+
{ id: 'door-a', components: { Transform: { x: 0, y: 1, z: -20 }, HubDoor: { id: 'a', to: 'game' } } },
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const SOUNDS = ['sounds/juke.mp3', 'sounds/ding.wav'];
|
|
42
|
+
|
|
43
|
+
function boot(options = {}) {
|
|
44
|
+
const idle = 'idle' in options ? options.idle : { emotes: true, seats: true, sounds: SOUNDS };
|
|
45
|
+
const hooks = options.hooks ?? {};
|
|
46
|
+
const json = {
|
|
47
|
+
server: { maxPlayers: 8 },
|
|
48
|
+
hub: {
|
|
49
|
+
contract: 1,
|
|
50
|
+
title: 'Town',
|
|
51
|
+
...(idle === undefined ? {} : { idle }),
|
|
52
|
+
places: { game: { title: 'Game', scene: 'scenes/game.scene', result: {} } },
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
let hub = null;
|
|
56
|
+
const sent = [];
|
|
57
|
+
const broadcasts = [];
|
|
58
|
+
const h = layer(json, { ...hooks, ready: (x) => (hub = x) }, {}, () => true);
|
|
59
|
+
const players = [
|
|
60
|
+
{ playerId: 'p1', username: 'ada' },
|
|
61
|
+
{ playerId: 'p2', username: 'bo' },
|
|
62
|
+
];
|
|
63
|
+
const session = {
|
|
64
|
+
sessionId: 'dev',
|
|
65
|
+
players,
|
|
66
|
+
hub: null,
|
|
67
|
+
send: (id, d) => sent.push([id, d]),
|
|
68
|
+
broadcast: (d) => broadcasts.push(d),
|
|
69
|
+
};
|
|
70
|
+
h.sceneFor(session);
|
|
71
|
+
const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
72
|
+
const world = {
|
|
73
|
+
timeMs: 0,
|
|
74
|
+
players: new Map([
|
|
75
|
+
['p1', body()],
|
|
76
|
+
['p2', body()],
|
|
77
|
+
]),
|
|
78
|
+
bodies: new Map(),
|
|
79
|
+
objects: new Map(),
|
|
80
|
+
scenePath: 'scenes/main.scene',
|
|
81
|
+
};
|
|
82
|
+
h.ready(world);
|
|
83
|
+
for (const p of players) {
|
|
84
|
+
h.message(session, p, { k: 'hub-hello', avatar: 0, party: 2 });
|
|
85
|
+
}
|
|
86
|
+
h.place(world);
|
|
87
|
+
for (const p of world.players.values()) {
|
|
88
|
+
p.at = { x: 0, y: 1, z: 0 };
|
|
89
|
+
}
|
|
90
|
+
const say = (playerId, data) => h.message(session, { playerId }, data);
|
|
91
|
+
const tick = (ms = 50) => {
|
|
92
|
+
world.timeMs += ms;
|
|
93
|
+
h.place(world);
|
|
94
|
+
h.step(world, []);
|
|
95
|
+
};
|
|
96
|
+
return { h, hub, world, sent, broadcasts, say, tick, session };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const warn = console.warn;
|
|
100
|
+
const warned = [];
|
|
101
|
+
console.warn = (...args) => warned.push(args.join(' '));
|
|
102
|
+
let n = 0;
|
|
103
|
+
function test(name, fn) {
|
|
104
|
+
try {
|
|
105
|
+
fn();
|
|
106
|
+
} catch (err) {
|
|
107
|
+
console.warn = warn;
|
|
108
|
+
console.error(`FAIL ${name}`);
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
n += 1;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// --- the manifest -------------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
test('idle: true is emotes and seats; an object turns each part on; absent is no key at all', () => {
|
|
117
|
+
const read = (idle) => Manifest.readManifest({ hub: { contract: 1, title: 'T', ...(idle === undefined ? {} : { idle }) } });
|
|
118
|
+
assert.deepEqual(read(true).manifest.places.main.idle, { emotes: true, seats: true, sounds: [] });
|
|
119
|
+
assert.deepEqual(read({ seats: true }).manifest.places.main.idle, { emotes: false, seats: true, sounds: [] });
|
|
120
|
+
assert.deepEqual(read({ sounds: ['a/b.mp3'] }).manifest.places.main.idle, { emotes: false, seats: false, sounds: ['a/b.mp3'] });
|
|
121
|
+
for (const off of [undefined, false, {}]) {
|
|
122
|
+
const place = read(off).manifest.places.main;
|
|
123
|
+
assert.equal('idle' in place, false);
|
|
124
|
+
assert.equal('idle' in Manifest.publicPlace('main', place), false);
|
|
125
|
+
}
|
|
126
|
+
assert.deepEqual(Manifest.publicPlace('main', read(true).manifest.places.main).idle, { emotes: true, seats: true, sounds: [] });
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('idle: unknown keys, wrong types and bad sound paths are check errors', () => {
|
|
130
|
+
const errors = (idle) => Manifest.readManifest({ hub: { contract: 1, title: 'T', idle } }).errors;
|
|
131
|
+
assert.match(errors({ emotes: true, chairs: true }).join(), /idle\.chairs is not part/);
|
|
132
|
+
assert.match(errors({ emotes: 'yes' }).join(), /idle\.emotes must be true or false/);
|
|
133
|
+
assert.match(errors(3).join(), /idle must be true, false or an object/);
|
|
134
|
+
for (const sounds of [['../x.mp3'], ['a.ogg'], ['a.mp3', 'a.mp3'], 'a.mp3', ['/a.mp3'], Array(17).fill(0).map((_, i) => `s${i}.mp3`)]) {
|
|
135
|
+
assert.match(errors({ sounds }).join(), /idle\.sounds must be/, JSON.stringify(sounds));
|
|
136
|
+
}
|
|
137
|
+
assert.deepEqual(errors({ sounds: ['sounds/a.mp3', 'imports/kit/b.wav', 'c.m4a'] }), []);
|
|
138
|
+
// Upper-case extensions are not bundled by the engine's media glob.
|
|
139
|
+
for (const file of ['sounds/a.MP3', 'b.Wav', 'c.M4A']) {
|
|
140
|
+
assert.match(errors({ sounds: [file] }).join(), /idle\.sounds must be/, file);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// --- a place that does not opt in --------------------------------------------
|
|
145
|
+
|
|
146
|
+
test('a place without idle is sent exactly what it was, whatever clients and the place ask', () => {
|
|
147
|
+
const quiet = boot({ idle: undefined });
|
|
148
|
+
const busy = boot({ idle: undefined });
|
|
149
|
+
const join = quiet.h.join();
|
|
150
|
+
assert.deepEqual(Object.keys(join), [
|
|
151
|
+
'hubPlace',
|
|
152
|
+
'hubAv',
|
|
153
|
+
'hud',
|
|
154
|
+
'hidden',
|
|
155
|
+
'held',
|
|
156
|
+
'labels',
|
|
157
|
+
'tints',
|
|
158
|
+
'marks',
|
|
159
|
+
'hubDoors',
|
|
160
|
+
'spawned',
|
|
161
|
+
'spawnTemplates',
|
|
162
|
+
]);
|
|
163
|
+
assert.equal('idle' in join.hubPlace, false);
|
|
164
|
+
busy.say('p1', { k: 'hub-emote', id: 'wave' });
|
|
165
|
+
busy.say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
166
|
+
busy.say('p2', { k: 'hub-stand' });
|
|
167
|
+
assert.equal(busy.hub.emote('p1', 'wave'), false);
|
|
168
|
+
assert.equal(busy.hub.sound('jukebox', SOUNDS[0], { loop: true }), false);
|
|
169
|
+
assert.equal(busy.hub.sound('jukebox', SOUNDS[1]), false);
|
|
170
|
+
assert.equal(busy.hub.seat('p1'), null);
|
|
171
|
+
for (const run of [quiet, busy]) {
|
|
172
|
+
run.tick();
|
|
173
|
+
}
|
|
174
|
+
assert.equal(JSON.stringify(busy.h.join()), JSON.stringify(quiet.h.join()));
|
|
175
|
+
assert.equal(JSON.stringify(busy.h.delta()), JSON.stringify(quiet.h.delta()));
|
|
176
|
+
quiet.tick();
|
|
177
|
+
busy.tick();
|
|
178
|
+
assert.equal(JSON.stringify(busy.h.delta()), JSON.stringify(quiet.h.delta()));
|
|
179
|
+
assert.deepEqual(busy.sent, quiet.sent);
|
|
180
|
+
assert.deepEqual(busy.broadcasts, []);
|
|
181
|
+
assert.equal(busy.world.players.get('p1').at.x, 0);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('a place turns on only the parts it names: each rides the snapshot alone', () => {
|
|
185
|
+
const join = (idle) => Object.keys(boot({ idle }).h.join()).filter((k) => k.startsWith('hubE') || k.startsWith('hubSe') || k.startsWith('hubSo'));
|
|
186
|
+
assert.deepEqual(join({ emotes: true }), ['hubEmotes']);
|
|
187
|
+
assert.deepEqual(join({ seats: true }), ['hubSeated']);
|
|
188
|
+
assert.deepEqual(join({ sounds: SOUNDS }), ['hubSounds']);
|
|
189
|
+
assert.deepEqual(join(true), ['hubEmotes', 'hubSeated']);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// --- emotes -------------------------------------------------------------------
|
|
193
|
+
|
|
194
|
+
test('an emote is latched for everyone with when it began and ends, then dropped', () => {
|
|
195
|
+
const { h, say, tick, world } = boot();
|
|
196
|
+
h.delta();
|
|
197
|
+
say('p1', { k: 'hub-emote', id: 'wave' });
|
|
198
|
+
const d = h.delta();
|
|
199
|
+
assert.deepEqual(d.hubEmotes, { p1: { id: 'wave', at: world.timeMs, until: world.timeMs + Idle.EMOTES.wave } });
|
|
200
|
+
assert.equal(h.delta(), null);
|
|
201
|
+
world.timeMs += Idle.EMOTES.wave;
|
|
202
|
+
assert.deepEqual(h.delta().hubEmotes, {});
|
|
203
|
+
tick();
|
|
204
|
+
assert.equal(h.join().hubEmotes.p1, undefined);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('emotes: unknown ids, malformed messages and a player who has not arrived are refused', () => {
|
|
208
|
+
const { h, hub, say } = boot();
|
|
209
|
+
for (const id of ['moonwalk', '', null, 7, 'toString', '__proto__']) {
|
|
210
|
+
say('p1', { k: 'hub-emote', id });
|
|
211
|
+
}
|
|
212
|
+
say('nobody', { k: 'hub-emote', id: 'wave' });
|
|
213
|
+
assert.deepEqual(h.join().hubEmotes, {});
|
|
214
|
+
assert.equal(hub.emote('p1', 'moonwalk'), false);
|
|
215
|
+
assert.equal(hub.emote('nobody', 'wave'), false);
|
|
216
|
+
assert.deepEqual(h.join().hubEmotes, {});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('emotes: one every 2 s per player', () => {
|
|
220
|
+
const { h, say, world } = boot();
|
|
221
|
+
say('p1', { k: 'hub-emote', id: 'wave' });
|
|
222
|
+
world.timeMs += 500;
|
|
223
|
+
say('p1', { k: 'hub-emote', id: 'dance' });
|
|
224
|
+
say('p2', { k: 'hub-emote', id: 'cheer' });
|
|
225
|
+
assert.equal(h.join().hubEmotes.p1.id, 'wave');
|
|
226
|
+
assert.equal(h.join().hubEmotes.p2.id, 'cheer');
|
|
227
|
+
world.timeMs += Idle.EMOTE_EVERY_MS - 500;
|
|
228
|
+
say('p1', { k: 'hub-emote', id: 'dance' });
|
|
229
|
+
assert.equal(h.join().hubEmotes.p1.id, 'dance');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('emotes: the place hook vetoes with false, and a hook that throws vetoes too; hub.emote is the place’s own', () => {
|
|
233
|
+
const calls = [];
|
|
234
|
+
const { h, hub, say, world } = boot({ hooks: { emote: (x, playerId, id) => (calls.push([playerId, id]), id !== 'bow') } });
|
|
235
|
+
say('p1', { k: 'hub-emote', id: 'bow' });
|
|
236
|
+
assert.deepEqual(h.join().hubEmotes, {});
|
|
237
|
+
world.timeMs += Idle.EMOTE_EVERY_MS;
|
|
238
|
+
say('p1', { k: 'hub-emote', id: 'spin' });
|
|
239
|
+
assert.equal(h.join().hubEmotes.p1.id, 'spin');
|
|
240
|
+
assert.deepEqual(calls, [
|
|
241
|
+
['p1', 'bow'],
|
|
242
|
+
['p1', 'spin'],
|
|
243
|
+
]);
|
|
244
|
+
// The place's own call skips the hook and the rate.
|
|
245
|
+
assert.equal(hub.emote('p1', 'bow'), true);
|
|
246
|
+
assert.equal(h.join().hubEmotes.p1.id, 'bow');
|
|
247
|
+
assert.equal(calls.length, 2);
|
|
248
|
+
world.timeMs += 10;
|
|
249
|
+
assert.equal(hub.emote('p1', 'cheer'), true);
|
|
250
|
+
const broken = boot({
|
|
251
|
+
hooks: {
|
|
252
|
+
emote: () => {
|
|
253
|
+
throw new Error('boom');
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
broken.say('p1', { k: 'hub-emote', id: 'wave' });
|
|
258
|
+
assert.deepEqual(broken.h.join().hubEmotes, {});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('emotes: a refused emote spends the cooldown, so the hook is asked at most once every 2 s', () => {
|
|
262
|
+
let asked = 0;
|
|
263
|
+
const { h, say, world } = boot({ hooks: { emote: () => ((asked += 1), false) } });
|
|
264
|
+
for (let i = 0; i < 10; i += 1) {
|
|
265
|
+
say('p1', { k: 'hub-emote', id: 'wave' });
|
|
266
|
+
}
|
|
267
|
+
assert.equal(asked, 1);
|
|
268
|
+
const broken = boot({
|
|
269
|
+
hooks: {
|
|
270
|
+
emote: () => {
|
|
271
|
+
asked += 1;
|
|
272
|
+
throw new Error('boom');
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
for (let i = 0; i < 10; i += 1) {
|
|
277
|
+
broken.say('p1', { k: 'hub-emote', id: 'wave' });
|
|
278
|
+
}
|
|
279
|
+
assert.equal(asked, 2);
|
|
280
|
+
world.timeMs += Idle.EMOTE_EVERY_MS;
|
|
281
|
+
say('p1', { k: 'hub-emote', id: 'wave' });
|
|
282
|
+
assert.equal(asked, 3);
|
|
283
|
+
assert.deepEqual(h.join().hubEmotes, {});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('emotes: a place with seats only ignores them', () => {
|
|
287
|
+
const { h, hub, say } = boot({ idle: { seats: true } });
|
|
288
|
+
say('p1', { k: 'hub-emote', id: 'wave' });
|
|
289
|
+
assert.equal(hub.emote('p1', 'wave'), false);
|
|
290
|
+
assert.equal('hubEmotes' in h.join(), false);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// --- seats --------------------------------------------------------------------
|
|
294
|
+
|
|
295
|
+
test('sitting near a free seat holds the player on it, facing its way, until they stand', () => {
|
|
296
|
+
const calls = [];
|
|
297
|
+
const { h, hub, say, tick, world } = boot({ hooks: { sit: (x, ...args) => calls.push(args) } });
|
|
298
|
+
say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
299
|
+
assert.deepEqual(calls, [['p1', 'bench-a']]);
|
|
300
|
+
assert.equal(hub.seat('p1'), 'bench-a');
|
|
301
|
+
const body = world.players.get('p1');
|
|
302
|
+
// On top of the bench (0.25 + 0.25), a standing body's height above it.
|
|
303
|
+
assert.deepEqual(body.at, { x: 1, y: 0.5 + Idle.SIT_BODY, z: 0 });
|
|
304
|
+
assert.ok(Math.abs(body.facing - Math.PI) < 1e-9);
|
|
305
|
+
assert.deepEqual(h.join().hubSeated, { p1: 'bench-a' });
|
|
306
|
+
assert.deepEqual(h.join().held, ['p1']);
|
|
307
|
+
// The hold keeps them there.
|
|
308
|
+
body.at = { x: 3, y: 1.35, z: 0 };
|
|
309
|
+
tick();
|
|
310
|
+
assert.equal(body.at.x, 1);
|
|
311
|
+
// A seat with no face faces its own turn; one with a height is held there.
|
|
312
|
+
say('p2', { k: 'hub-sit', seat: 'stool' });
|
|
313
|
+
assert.deepEqual(world.players.get('p2').at, { x: 0, y: 1.2, z: 1 });
|
|
314
|
+
world.timeMs += 1000;
|
|
315
|
+
say('p1', { k: 'hub-stand' });
|
|
316
|
+
assert.equal(hub.seat('p1'), null);
|
|
317
|
+
assert.deepEqual(h.join().hubSeated, { p2: 'stool' });
|
|
318
|
+
assert.deepEqual(h.join().held, ['p2']);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test('seats: one player per seat; too far, not a seat, hidden, or vetoed is refused', () => {
|
|
322
|
+
const { h, hub, say, world } = boot({ hooks: { sit: (x, playerId, seatId) => seatId !== 'bench-b' } });
|
|
323
|
+
say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
324
|
+
say('p2', { k: 'hub-sit', seat: 'bench-a' });
|
|
325
|
+
assert.equal(hub.seat('p2'), null);
|
|
326
|
+
world.timeMs += 1000;
|
|
327
|
+
say('p2', { k: 'hub-sit', seat: 'bench-b' });
|
|
328
|
+
say('p2', { k: 'hub-sit', seat: 'far-bench' });
|
|
329
|
+
world.timeMs += 1000;
|
|
330
|
+
say('p2', { k: 'hub-sit', seat: 'jukebox' });
|
|
331
|
+
say('p2', { k: 'hub-sit', seat: { id: 'stool' } });
|
|
332
|
+
hub.hide('stool');
|
|
333
|
+
say('p2', { k: 'hub-sit', seat: 'stool' });
|
|
334
|
+
assert.equal(hub.seat('p2'), null);
|
|
335
|
+
assert.deepEqual(h.join().hubSeated, { p1: 'bench-a' });
|
|
336
|
+
// The first sitter gets up; the seat is free again.
|
|
337
|
+
world.timeMs += 1000;
|
|
338
|
+
say('p1', { k: 'hub-stand' });
|
|
339
|
+
world.players.get('p2').at = { x: 0, y: 1, z: 0 };
|
|
340
|
+
say('p2', { k: 'hub-sit', seat: 'bench-a' });
|
|
341
|
+
assert.equal(hub.seat('p2'), 'bench-a');
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test('seats: a sit is checked again after the hook, which may have held, ended or seated someone', () => {
|
|
345
|
+
// The hook holds the player itself: its hold stands, no seat.
|
|
346
|
+
let run = boot({ hooks: { sit: (x, playerId) => x.hold(playerId, { x: 5, y: 1, z: 5 }) } });
|
|
347
|
+
run.say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
348
|
+
assert.equal(run.hub.seat('p1'), null);
|
|
349
|
+
assert.deepEqual(run.world.players.get('p1').at, { x: 5, y: 1, z: 5 });
|
|
350
|
+
assert.deepEqual(run.h.join().held, ['p1']);
|
|
351
|
+
// The hook ends the player's visit.
|
|
352
|
+
run = boot({ hooks: { sit: (x, playerId) => x.end([playerId]) } });
|
|
353
|
+
run.say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
354
|
+
assert.equal(run.hub.seat('p1'), null);
|
|
355
|
+
assert.deepEqual(run.h.join().held, []);
|
|
356
|
+
// The hook hides the seat.
|
|
357
|
+
run = boot({ hooks: { sit: (x, playerId, seatId) => x.hide(seatId) } });
|
|
358
|
+
run.say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
359
|
+
assert.equal(run.hub.seat('p1'), null);
|
|
360
|
+
// The hook seats someone else there first (a sit that re-enters).
|
|
361
|
+
let inner = false;
|
|
362
|
+
run = boot({
|
|
363
|
+
hooks: {
|
|
364
|
+
sit: (x, playerId) => {
|
|
365
|
+
if (playerId === 'p1' && !inner) {
|
|
366
|
+
inner = true;
|
|
367
|
+
run.say('p2', { k: 'hub-sit', seat: 'bench-a' });
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
run.say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
373
|
+
assert.equal(run.hub.seat('p2'), 'bench-a');
|
|
374
|
+
assert.equal(run.hub.seat('p1'), null);
|
|
375
|
+
assert.deepEqual(run.h.join().hubSeated, { p2: 'bench-a' });
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test('seats: an actor that can move (a dynamic or kinematic Body) is not a seat', () => {
|
|
379
|
+
const { hub, say } = boot();
|
|
380
|
+
say('p1', { k: 'hub-sit', seat: 'cart' });
|
|
381
|
+
assert.equal(hub.seat('p1'), null);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test('seats: hub-sit and hub-stand are rate-limited per player', () => {
|
|
385
|
+
const { hub, say } = boot();
|
|
386
|
+
for (let i = 0; i < 6; i += 1) {
|
|
387
|
+
say('p1', { k: 'hub-sit', seat: i % 2 ? 'bench-b' : 'bench-a' });
|
|
388
|
+
}
|
|
389
|
+
// Three went through (a, b, a); the rest were dropped.
|
|
390
|
+
assert.equal(hub.seat('p1'), 'bench-a');
|
|
391
|
+
say('p1', { k: 'hub-stand' });
|
|
392
|
+
assert.equal(hub.seat('p1'), 'bench-a');
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
test('seats and the place’s holds: a held player cannot sit; the place’s hold or release gets a sitter up', () => {
|
|
396
|
+
const { h, hub, say, tick, world } = boot();
|
|
397
|
+
hub.hold('p2');
|
|
398
|
+
say('p2', { k: 'hub-sit', seat: 'bench-b' });
|
|
399
|
+
assert.equal(hub.seat('p2'), null);
|
|
400
|
+
hub.release('p2');
|
|
401
|
+
say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
402
|
+
hub.release('p1');
|
|
403
|
+
tick();
|
|
404
|
+
assert.equal(hub.seat('p1'), null);
|
|
405
|
+
assert.deepEqual(h.join().hubSeated, {});
|
|
406
|
+
assert.deepEqual(h.join().held, []);
|
|
407
|
+
// Held by the place while sitting: they stay put, held, but the seat is free.
|
|
408
|
+
world.timeMs += 1000;
|
|
409
|
+
world.players.get('p1').at = { x: 0, y: 1, z: 0 };
|
|
410
|
+
say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
411
|
+
assert.equal(hub.seat('p1'), 'bench-a');
|
|
412
|
+
hub.hold('p1');
|
|
413
|
+
tick();
|
|
414
|
+
assert.equal(hub.seat('p1'), null);
|
|
415
|
+
assert.deepEqual(h.join().held, ['p1']);
|
|
416
|
+
say('p1', { k: 'hub-stand' });
|
|
417
|
+
assert.deepEqual(h.join().held, ['p1']);
|
|
418
|
+
world.players.get('p2').at = { x: 1, y: 1, z: 0 };
|
|
419
|
+
say('p2', { k: 'hub-sit', seat: 'bench-a' });
|
|
420
|
+
assert.equal(hub.seat('p2'), 'bench-a');
|
|
421
|
+
// A game's end stands a sitter.
|
|
422
|
+
hub.end(['p2']);
|
|
423
|
+
tick();
|
|
424
|
+
assert.equal(hub.seat('p2'), null);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test('seats: a sitter who leaves frees the seat; a hidden seat stands its sitter', () => {
|
|
428
|
+
const { h, hub, say, tick, world, session } = boot();
|
|
429
|
+
say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
430
|
+
say('p2', { k: 'hub-sit', seat: 'bench-b' });
|
|
431
|
+
world.players.delete('p1');
|
|
432
|
+
session.players.splice(0, 1);
|
|
433
|
+
tick();
|
|
434
|
+
assert.deepEqual(h.join().hubSeated, { p2: 'bench-b' });
|
|
435
|
+
hub.hide('bench-b');
|
|
436
|
+
tick();
|
|
437
|
+
assert.equal(hub.seat('p2'), null);
|
|
438
|
+
assert.deepEqual(h.join().held, []);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test('seats: a sitter who jumps to a door gets up first', () => {
|
|
442
|
+
const { hub, say, world } = boot();
|
|
443
|
+
say('p1', { k: 'hub-sit', seat: 'bench-a' });
|
|
444
|
+
say('p1', { k: 'hub-door-jump', door: 'a' });
|
|
445
|
+
assert.equal(hub.seat('p1'), null);
|
|
446
|
+
assert.ok(world.players.get('p1').at.z < -10);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
// --- sounds -------------------------------------------------------------------
|
|
450
|
+
|
|
451
|
+
test('a loop is latched at its actor until stopped; one-shots are broadcast', () => {
|
|
452
|
+
const { h, hub, broadcasts, world } = boot();
|
|
453
|
+
h.delta();
|
|
454
|
+
assert.equal(hub.sound('jukebox', SOUNDS[0], { loop: true, volume: 0.6, radius: 12 }), true);
|
|
455
|
+
assert.deepEqual(h.delta().hubSounds, { jukebox: { file: SOUNDS[0], volume: 0.6, radius: 12, since: world.timeMs } });
|
|
456
|
+
assert.equal(hub.sound('lamp', SOUNDS[1], { volume: 3, radius: 500 }), true);
|
|
457
|
+
assert.deepEqual(broadcasts, [{ k: 'hub-sound', actor: 'lamp', file: SOUNDS[1], volume: 1, radius: Idle.RADIUS.max }]);
|
|
458
|
+
assert.equal(hub.sound('jukebox', null), true);
|
|
459
|
+
assert.deepEqual(h.delta().hubSounds, {});
|
|
460
|
+
// A one-shot at an actor replaces the loop playing there.
|
|
461
|
+
assert.equal(hub.sound('jukebox', SOUNDS[0], { loop: true }), true);
|
|
462
|
+
assert.equal(hub.sound('lamp', SOUNDS[0], { loop: true }), true);
|
|
463
|
+
assert.equal(hub.sound('jukebox', SOUNDS[1]), true);
|
|
464
|
+
assert.deepEqual(Object.keys(h.delta().hubSounds), ['lamp']);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
test('sounds: an undeclared file, an unknown actor, too many loops or one-shots are refused', () => {
|
|
468
|
+
const { h, hub, broadcasts } = boot();
|
|
469
|
+
assert.equal(hub.sound('jukebox', 'sounds/other.mp3', { loop: true }), false);
|
|
470
|
+
assert.equal(hub.sound('nobody', SOUNDS[0], { loop: true }), false);
|
|
471
|
+
assert.deepEqual(h.join().hubSounds, {});
|
|
472
|
+
for (const id of ['spawn', 'bench-a', 'bench-b', 'stool']) {
|
|
473
|
+
assert.equal(hub.sound(id, SOUNDS[0], { loop: true }), true);
|
|
474
|
+
}
|
|
475
|
+
assert.equal(hub.sound('lamp', SOUNDS[0], { loop: true }), false);
|
|
476
|
+
// Replacing a loop at an actor that has one is fine.
|
|
477
|
+
assert.equal(hub.sound('stool', SOUNDS[1], { loop: true }), true);
|
|
478
|
+
assert.equal(Object.keys(h.join().hubSounds).length, Idle.MAX_LOOPS);
|
|
479
|
+
let played = 0;
|
|
480
|
+
for (let i = 0; i < Idle.SHOT_BURST + 3; i += 1) {
|
|
481
|
+
played += hub.sound('lamp', SOUNDS[1]) ? 1 : 0;
|
|
482
|
+
}
|
|
483
|
+
assert.equal(played, Idle.SHOT_BURST);
|
|
484
|
+
assert.equal(broadcasts.length, Idle.SHOT_BURST);
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test('sounds: a place that declares none refuses them', () => {
|
|
488
|
+
const { h, hub, broadcasts } = boot({ idle: true });
|
|
489
|
+
assert.equal(hub.sound('jukebox', SOUNDS[0], { loop: true }), false);
|
|
490
|
+
assert.equal(hub.sound('jukebox', SOUNDS[0]), false);
|
|
491
|
+
assert.equal('hubSounds' in h.join(), false);
|
|
492
|
+
assert.deepEqual(broadcasts, []);
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
// --- the client's drawing -------------------------------------------------------
|
|
496
|
+
|
|
497
|
+
test('every emote starts and ends at rest, and moves between', () => {
|
|
498
|
+
for (const [id] of ClientIdle.EMOTES) {
|
|
499
|
+
const seconds = Idle.EMOTES[id] / 1000;
|
|
500
|
+
for (const u of [0, 1]) {
|
|
501
|
+
const p = ClientIdle.emotePose(id, u, u * seconds);
|
|
502
|
+
for (const [k, v] of Object.entries(p)) {
|
|
503
|
+
const turn = k === 'ry' ? Math.abs(Math.sin(v)) : Math.abs(v);
|
|
504
|
+
assert.ok(turn < 1e-9, `${id} ${k} at ${u}: ${v}`);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
const mid = ClientIdle.emotePose(id, 0.4, 0.4 * seconds);
|
|
508
|
+
assert.ok(Object.values(mid).some((v) => Math.abs(v) > 0.01), id);
|
|
509
|
+
}
|
|
510
|
+
assert.deepEqual(
|
|
511
|
+
ClientIdle.EMOTES.map(([id]) => id),
|
|
512
|
+
Object.keys(Idle.EMOTES),
|
|
513
|
+
);
|
|
514
|
+
assert.equal(ClientIdle.emotePose('moonwalk', 0.5, 1), null);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
console.warn = warn;
|
|
518
|
+
console.log(`test-idle: ${n} passed`);
|