castle-web-cli 0.4.230 → 0.4.232
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/castle-host/host.js +81 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +22 -12
- package/dist/devSessionServer.js +8 -2
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/init.js +1 -1
- package/dist/serve.js +5 -1
- package/dist/serverBundle.js +5 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +148 -1
- package/kits/base/sdk/castle.d.ts +4 -0
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +15 -0
- package/kits/base/sdk/multiplayer.js +52 -4
- 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/storage.d.ts +3 -2
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +4 -0
- package/kits/base/sdk/server/wrapper.js +2 -0
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/hub-game/CLAUDE.md +29 -4
- package/kits/hub-game/code/client/avatar.js +39 -0
- package/kits/hub-game/code/client/chat.js +12 -0
- package/kits/hub-game/code/client/chrome.js +237 -13
- package/kits/hub-game/code/client/grab.js +166 -7
- package/kits/hub-game/code/client/hats.js +26 -0
- package/kits/hub-game/code/client/hookLayer.js +36 -3
- package/kits/hub-game/code/client/hudClear.js +126 -0
- package/kits/hub-game/code/client/state.js +35 -1
- package/kits/hub-game/code/client/talk.js +10 -36
- package/kits/hub-game/code/client/tiers.js +505 -0
- package/kits/hub-game/code/client/together.js +144 -4
- package/kits/hub-game/code/client/wear.js +96 -14
- package/kits/hub-game/code/server/actors.js +5 -0
- package/kits/hub-game/code/server/grab.js +299 -13
- package/kits/hub-game/code/server/hub.js +162 -7
- package/kits/hub-game/code/server/manifest.js +80 -8
- package/kits/hub-game/code/server/npcs.js +21 -33
- package/kits/hub-game/code/server/party.js +75 -6
- package/kits/hub-game/code/server/say.js +8 -2
- package/kits/hub-game/code/server/wear.js +116 -11
- package/kits/hub-game/code/systems/hub.js +386 -21
- package/kits/hub-game/docs/contract.md +285 -19
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/test-chat.mjs +32 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +511 -0
- package/kits/hub-game/scripts/test-grab.mjs +857 -3
- package/kits/hub-game/scripts/test-hats.mjs +229 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +721 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
- package/kits/hub-game/scripts/test-manifest.mjs +122 -1
- package/kits/hub-game/scripts/test-npcs.mjs +34 -24
- package/kits/hub-game/scripts/test-party.mjs +108 -4
- package/kits/hub-game/scripts/test-say.mjs +59 -2
- package/kits/hub-game/scripts/test-tiers.mjs +854 -0
- package/kits/hub-game/scripts/test-together.mjs +33 -1
- package/kits/hub-game/scripts/test-try-on.mjs +940 -0
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +127 -0
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +298 -0
- package/kits/physics-3d/CLAUDE.md +531 -0
- package/kits/physics-3d/behaviors/Player.jsx +437 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +4 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -1
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/optimize.js +49 -0
- package/kits/physics-3d/engine3d/orbitinput.js +277 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +525 -11
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
- package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +543 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2105 -0
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +667 -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/scripts/test-steady-hover.mjs +633 -0
- package/kits/physics-3d/systems/physics3d.js +273 -9
- package/package.json +1 -1
|
@@ -5,7 +5,8 @@ import assert from 'node:assert/strict';
|
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import os from 'node:os';
|
|
7
7
|
import path from 'node:path';
|
|
8
|
-
import { checkResult, GRAB_DEFAULTS, publicPlace, readManifest } from '../code/server/manifest.js';
|
|
8
|
+
import { checkResult, GRAB_DEFAULTS, GRAB_REACH_LIMITS, publicPlace, readManifest } from '../code/server/manifest.js';
|
|
9
|
+
import { GRAB_REACH as SERVER_GRAB_REACH } from '../code/server/grab.js';
|
|
9
10
|
import { resolvePlace } from '../code/server/place.js';
|
|
10
11
|
|
|
11
12
|
const kit = JSON.parse(fs.readFileSync(new URL('../castle.json', import.meta.url), 'utf8'));
|
|
@@ -53,6 +54,26 @@ test('unknown keys are refused, not ignored', () => {
|
|
|
53
54
|
assert.match(errors.join('\n'), /hub\.maxPlayer is not part/);
|
|
54
55
|
});
|
|
55
56
|
|
|
57
|
+
test("tiers: the deck's, true or false", () => {
|
|
58
|
+
assert.deepEqual(readManifest(base({ tiers: true }), has).errors, []);
|
|
59
|
+
assert.deepEqual(readManifest(base({ tiers: false }), has).errors, []);
|
|
60
|
+
assert.match(readManifest(base({ tiers: 'yes' }), has).errors.join(), /hub\.tiers must be true or false/);
|
|
61
|
+
const { errors } = readManifest(base({ places: { arena: { title: 'Arena', scene: 'scenes/arena.scene', tiers: true } } }), has);
|
|
62
|
+
assert.match(errors.join('\n'), /hub\.places\.arena\.tiers is not part/);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("cues: the deck's, true or false, and off unless asked for", () => {
|
|
66
|
+
assert.deepEqual(readManifest(base({ cues: true }), has).errors, []);
|
|
67
|
+
assert.deepEqual(readManifest(base({ cues: false }), has).errors, []);
|
|
68
|
+
assert.match(readManifest(base({ cues: 'yes' }), has).errors.join(), /hub\.cues must be true or false/);
|
|
69
|
+
const { errors } = readManifest(base({ places: { arena: { title: 'Arena', scene: 'scenes/arena.scene', cues: true } } }), has);
|
|
70
|
+
assert.match(errors.join('\n'), /hub\.places\.arena\.cues is not part/);
|
|
71
|
+
// The server reads it off the manifest: on only for `true`.
|
|
72
|
+
assert.equal(readManifest(base({ cues: true }), has).manifest.cues, true);
|
|
73
|
+
assert.equal(readManifest(base({ cues: false }), has).manifest.cues, false);
|
|
74
|
+
assert.equal(readManifest(base(), has).manifest.cues, false);
|
|
75
|
+
});
|
|
76
|
+
|
|
56
77
|
test('player counts', () => {
|
|
57
78
|
assert.match(readManifest(base({ minPlayers: 5, maxPlayers: 4 }), has).errors.join(), /more than maxPlayers/);
|
|
58
79
|
assert.match(readManifest(base({ maxPlayers: 12 }), has).errors.join(), /server\.maxPlayers/);
|
|
@@ -125,6 +146,104 @@ test('grab (v1.3): true is the defaults, an object sets any of them, off is none
|
|
|
125
146
|
assert.ok(!('grab' in publicPlace('main', place(undefined).manifest.places.main)));
|
|
126
147
|
});
|
|
127
148
|
|
|
149
|
+
test('grab.reach and grab.steady (v1.22): kept only when set, bounded, and the rest unchanged', () => {
|
|
150
|
+
const place = (grab) => readManifest(base({ grab }), has);
|
|
151
|
+
// Left out, or steady false: exactly the place, and the client message, of before.
|
|
152
|
+
for (const grab of [true, {}, { throwSpeed: 6 }, { steady: false }]) {
|
|
153
|
+
const read = place(grab).manifest.places.main.grab;
|
|
154
|
+
assert.ok(!('reach' in read) && !('steady' in read));
|
|
155
|
+
assert.deepEqual(Object.keys(publicPlace('main', place(grab).manifest.places.main).grab), Object.keys(GRAB_DEFAULTS));
|
|
156
|
+
}
|
|
157
|
+
assert.deepEqual(place({ steady: false }).manifest.places.main.grab, GRAB_DEFAULTS);
|
|
158
|
+
assert.deepEqual(place({ steady: true, reach: 2.2, throwSpeed: 6 }).manifest.places.main.grab, {
|
|
159
|
+
...GRAB_DEFAULTS,
|
|
160
|
+
throwSpeed: 6,
|
|
161
|
+
reach: 2.2,
|
|
162
|
+
steady: true,
|
|
163
|
+
});
|
|
164
|
+
assert.deepEqual(publicPlace('main', place({ steady: true, reach: 2.2 }).manifest.places.main).grab, {
|
|
165
|
+
...GRAB_DEFAULTS,
|
|
166
|
+
reach: 2.2,
|
|
167
|
+
steady: true,
|
|
168
|
+
});
|
|
169
|
+
assert.deepEqual(GRAB_REACH_LIMITS.slice(0, 2), [1.6, 3]);
|
|
170
|
+
assert.equal(place({ reach: 1.6 }).manifest.places.main.grab.reach, 1.6);
|
|
171
|
+
assert.equal(place({ reach: 3 }).manifest.places.main.grab.reach, 3);
|
|
172
|
+
assert.deepEqual(place({ reach: 3 }).errors, []);
|
|
173
|
+
for (const reach of [1.5, 3.1, 4, -1, '2', Number.NaN, null, true]) {
|
|
174
|
+
assert.match(place({ reach }).errors.join(), /grab\.reach must be a number of metres from 1\.6 to 3/);
|
|
175
|
+
}
|
|
176
|
+
for (const steady of ['yes', 1, null, {}]) {
|
|
177
|
+
assert.match(place({ steady }).errors.join(), /grab\.steady must be true or false/);
|
|
178
|
+
}
|
|
179
|
+
assert.match(place({ reachh: 2 }).errors.join(), /hub\.grab\.reachh is not part/);
|
|
180
|
+
// The top of the reach stays inside the server's own GRAB_REACH.
|
|
181
|
+
assert.ok(GRAB_REACH_LIMITS[1] < SERVER_GRAB_REACH);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('hud.clear (v1.26): a place carries it only when true, and one without it is read and sent as before', () => {
|
|
185
|
+
const read = (hud, rest = {}) => readManifest(base(hud === undefined ? rest : { hud, ...rest }), has);
|
|
186
|
+
const before = read(undefined, { grab: true, idle: true, result: {} });
|
|
187
|
+
// Left out, empty, or false: exactly the place, and the client message, of before.
|
|
188
|
+
for (const hud of [undefined, {}, { clear: false }]) {
|
|
189
|
+
const { errors, manifest } = read(hud, { grab: true, idle: true, result: {} });
|
|
190
|
+
assert.deepEqual(errors, []);
|
|
191
|
+
assert.ok(!('hud' in manifest.places.main));
|
|
192
|
+
assert.deepEqual(manifest, before.manifest);
|
|
193
|
+
const sent = publicPlace('main', manifest.places.main);
|
|
194
|
+
assert.ok(!('hud' in sent));
|
|
195
|
+
assert.deepEqual(sent, publicPlace('main', before.manifest.places.main));
|
|
196
|
+
assert.equal(JSON.stringify(sent), JSON.stringify(publicPlace('main', before.manifest.places.main)), 'the same keys in the same order');
|
|
197
|
+
}
|
|
198
|
+
assert.deepEqual(Object.keys(publicPlace('main', before.manifest.places.main)), ['contract', 'id', 'title', 'scene', 'controller', 'maxDurationSec', 'grab', 'idle', 'result']);
|
|
199
|
+
// Asked: on the place, and told to the client.
|
|
200
|
+
const asked = read({ clear: true }, { grab: true, idle: true, result: {} });
|
|
201
|
+
assert.deepEqual(asked.errors, []);
|
|
202
|
+
assert.deepEqual(asked.manifest.places.main.hud, { clear: true });
|
|
203
|
+
const sent = publicPlace('main', asked.manifest.places.main);
|
|
204
|
+
assert.deepEqual(sent.hud, { clear: true });
|
|
205
|
+
const { hud: _hud, ...rest } = sent;
|
|
206
|
+
assert.deepEqual(rest, publicPlace('main', before.manifest.places.main), 'nothing else of the message moves');
|
|
207
|
+
// A place's own, in a deck of several: one asks, the other is as it was.
|
|
208
|
+
const two = readManifest(base({ places: { arena: { title: 'Arena', scene: 'scenes/race.scene', hud: { clear: true } } } }), has);
|
|
209
|
+
assert.deepEqual(two.errors, []);
|
|
210
|
+
assert.deepEqual(two.manifest.places.arena.hud, { clear: true });
|
|
211
|
+
assert.ok(!('hud' in two.manifest.places.main));
|
|
212
|
+
// Anything else is refused, not ignored.
|
|
213
|
+
for (const clear of ['yes', 1, 0, null, {}, []]) {
|
|
214
|
+
assert.match(read({ clear }).errors.join(), /hub\.hud\.clear must be true or false/);
|
|
215
|
+
assert.equal(read({ clear }).manifest, null);
|
|
216
|
+
}
|
|
217
|
+
for (const hud of [true, false, 'clear', 1, null, []]) {
|
|
218
|
+
assert.match(read(hud).errors.join(), /hub\.hud must be an object/);
|
|
219
|
+
}
|
|
220
|
+
assert.match(read({ clear: true, big: 32 }).errors.join(), /hub\.hud\.big is not part/);
|
|
221
|
+
assert.match(read({ Clear: true }).errors.join(), /hub\.hud\.Clear is not part/);
|
|
222
|
+
assert.match(
|
|
223
|
+
readManifest(base({ places: { arena: { title: 'Arena', scene: 'scenes/race.scene', hud: { clear: 'on' } } } }), has).errors.join(),
|
|
224
|
+
/places\.arena\.hud\.clear must be true or false/,
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('grab.keepHeld (v1.25): kept only when true, true or false, and the rest unchanged', () => {
|
|
229
|
+
const place = (grab) => readManifest(base({ grab }), has);
|
|
230
|
+
for (const grab of [true, {}, { throwSpeed: 6 }, { keepHeld: false }]) {
|
|
231
|
+
const read = place(grab).manifest.places.main.grab;
|
|
232
|
+
assert.ok(!('keepHeld' in read));
|
|
233
|
+
assert.deepEqual(Object.keys(publicPlace('main', place(grab).manifest.places.main).grab), Object.keys(GRAB_DEFAULTS));
|
|
234
|
+
}
|
|
235
|
+
assert.deepEqual(place({ keepHeld: true }).manifest.places.main.grab, { ...GRAB_DEFAULTS, keepHeld: true });
|
|
236
|
+
assert.deepEqual(publicPlace('main', place({ keepHeld: true, steady: true }).manifest.places.main).grab, {
|
|
237
|
+
...GRAB_DEFAULTS,
|
|
238
|
+
steady: true,
|
|
239
|
+
keepHeld: true,
|
|
240
|
+
});
|
|
241
|
+
for (const keepHeld of ['yes', 1, null, {}]) {
|
|
242
|
+
assert.match(place({ keepHeld }).errors.join(), /grab\.keepHeld must be true or false/);
|
|
243
|
+
}
|
|
244
|
+
assert.match(place({ keepheld: true }).errors.join(), /hub\.grab\.keepheld is not part/);
|
|
245
|
+
});
|
|
246
|
+
|
|
128
247
|
test('results are checked against the declared shape', () => {
|
|
129
248
|
const { manifest } = readManifest(
|
|
130
249
|
base({ result: { outcomes: ['win', 'lose'], score: { min: 0, max: 100 }, stats: { kart: 'string' } } }),
|
|
@@ -180,6 +299,8 @@ test('npcs name a shared-character route', () => {
|
|
|
180
299
|
assert.match(readManifest(base({ npcs: { route: 'plain' } }, { server, characterBundle }), has).errors[0], /characters: "shared"/);
|
|
181
300
|
assert.match(readManifest(base({ npcs: { route: 'town', turnsPerMinute: 0 } }, { server, characterBundle }), has).errors[0], /turnsPerMinute/);
|
|
182
301
|
assert.match(readManifest(base({ npcs: { route: 'town', disclosure: 'everyone' } }, { server, characterBundle }), has).errors[0], /disclosure/);
|
|
302
|
+
// Read, and never acted on: a player's conversation is theirs alone.
|
|
303
|
+
assert.equal(readManifest(base({ npcs: { route: 'town', disclosure: 'world' } }, { server, characterBundle }), has).manifest.places.main.npcs.disclosure, 'participants');
|
|
183
304
|
assert.match(readManifest(base({ npcs: { route: 'town', slot: 'a b' } }, { server, characterBundle }), has).errors[0], /slot/);
|
|
184
305
|
assert.match(readManifest(base({ npcs: { route: 'town', budget: 3 } }, { server, characterBundle }), has).errors[0], /not part of the hub contract/);
|
|
185
306
|
assert.match(readManifest(base({ npcs: { route: 'town' } }, { server }), has).errors[0], /characterBundle/);
|
|
@@ -197,7 +197,7 @@ await test('in a world, words to a mind are said by their own socket, never a me
|
|
|
197
197
|
assert.equal(w.lines.length, before);
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
-
await test('a turn is admitted only for the player talking, with
|
|
200
|
+
await test('a turn is admitted only for the player talking, with no listener', async () => {
|
|
201
201
|
const w = world();
|
|
202
202
|
w.at('a', 0, 2);
|
|
203
203
|
w.at('b', 1, 1);
|
|
@@ -206,16 +206,20 @@ await test('a turn is admitted only for the player talking, with a near audience
|
|
|
206
206
|
await w.npcs.onTurn(t);
|
|
207
207
|
assert.equal(t.rejected, 'HUB_NPC_NOT_TALKING');
|
|
208
208
|
w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
// A listener, however near, would be handed the speaker's words by ghost.
|
|
210
|
+
for (const audience of [['far'], ['b']]) {
|
|
211
|
+
t = turn({ speaker: 'a', audience });
|
|
212
|
+
await w.npcs.onTurn(t);
|
|
213
|
+
assert.equal(t.rejected, 'HUB_NPC_AUDIENCE');
|
|
214
|
+
assert.equal(t.sent, 0);
|
|
215
|
+
}
|
|
212
216
|
t = turn({ speaker: 'a', disclosure: 'world' });
|
|
213
217
|
await w.npcs.onTurn(t);
|
|
214
218
|
assert.equal(t.rejected, 'HUB_NPC_AUDIENCE');
|
|
215
219
|
t = turn({ speaker: 'a', characterId: 'innkeeper' });
|
|
216
220
|
await w.npcs.onTurn(t);
|
|
217
221
|
assert.equal(t.rejected, 'HUB_NPC_UNKNOWN');
|
|
218
|
-
t = turn({ speaker: 'a'
|
|
222
|
+
t = turn({ speaker: 'a' });
|
|
219
223
|
await w.npcs.onTurn(t);
|
|
220
224
|
assert.equal(t.rejected, null);
|
|
221
225
|
assert.equal(t.sent, 1);
|
|
@@ -225,19 +229,21 @@ await test('a turn is admitted only for the player talking, with a near audience
|
|
|
225
229
|
assert.equal(second.rejected, 'HUB_NPC_BUSY');
|
|
226
230
|
});
|
|
227
231
|
|
|
228
|
-
await test(
|
|
232
|
+
await test('a reply is shown to its speaker only, once', async () => {
|
|
229
233
|
const w = world();
|
|
230
234
|
w.at('a', 0, 2);
|
|
231
235
|
w.at('b', 1, 1);
|
|
232
236
|
w.at('c', -1, 1);
|
|
233
237
|
w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
|
|
234
|
-
await w.npcs.onTurn(turn({ speaker: 'a'
|
|
238
|
+
await w.npcs.onTurn(turn({ speaker: 'a' }));
|
|
235
239
|
// Another player's read of a's operation reveals nothing.
|
|
236
240
|
await w.npcs.onRead(statusRead('c', 'op1', 'secret'));
|
|
237
241
|
assert.equal(w.labels.length, 0);
|
|
238
242
|
await w.npcs.onRead(statusRead('a', 'op1', 'Hello there!'));
|
|
239
243
|
assert.equal(w.labels.length, 1);
|
|
240
|
-
|
|
244
|
+
// b stands beside them and is sent nothing.
|
|
245
|
+
assert.deepEqual(w.labels[0].to, ['a']);
|
|
246
|
+
assert.equal(w.labels[0].about, 'a');
|
|
241
247
|
assert.match(w.labels[0].text, /Rowan: Hello there!/);
|
|
242
248
|
await w.npcs.onRead(statusRead('a', 'op1', 'Hello there!'));
|
|
243
249
|
assert.equal(w.labels.length, 1);
|
|
@@ -528,26 +534,30 @@ await test("hub.label is what it was before NPCs; only an NPC's speech is long a
|
|
|
528
534
|
assert.equal(h.labels.size, 2);
|
|
529
535
|
});
|
|
530
536
|
|
|
531
|
-
await test('
|
|
537
|
+
await test('the open message names no hearing range and never a wider disclosure', async () => {
|
|
538
|
+
const w = world();
|
|
539
|
+
w.h.place.npcs.disclosure = 'world';
|
|
540
|
+
w.at('a', 0, 2);
|
|
541
|
+
w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
|
|
542
|
+
const opened = w.sent.find((m) => m.k === 'hub-npc' && m.open);
|
|
543
|
+
// An older client lists the players within `hearRange` as listeners.
|
|
544
|
+
assert.equal(opened.hearRange, 0);
|
|
545
|
+
assert.equal(opened.disclosure, 'participants');
|
|
546
|
+
const wide = turn({ speaker: 'a', disclosure: 'world' });
|
|
547
|
+
await w.npcs.onTurn(wide);
|
|
548
|
+
assert.equal(wide.rejected, 'HUB_NPC_AUDIENCE');
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
await test('a reply is not drawn for a speaker who has left', async () => {
|
|
532
552
|
const w = world();
|
|
533
|
-
const pairs = new Map([['a', new Set(['b'])], ['b', new Set(['a'])]]);
|
|
534
|
-
w.h.blockedPairs = () => pairs;
|
|
535
553
|
w.at('a', 0, 2);
|
|
536
554
|
w.at('b', 1, 1);
|
|
537
|
-
w.at('c', -1, 1);
|
|
538
555
|
w.npcs.message({ playerId: 'a' }, { k: 'hub-npc-open', npc: 'greeter' });
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
await w.npcs.onTurn(turn({ speaker: 'a', audience: ['c'], operationId: 'op2' }));
|
|
545
|
-
pairs.set('a', new Set(['b', 'c']));
|
|
546
|
-
pairs.set('c', new Set(['a']));
|
|
547
|
-
await w.npcs.onRead(statusRead('a', 'op2', 'Hello, a.'));
|
|
548
|
-
const reply = w.labels.at(-1);
|
|
549
|
-
assert.deepEqual(reply.to, ['a']);
|
|
550
|
-
assert.equal(reply.about, 'a', 'and marked as about a, for later arrivals');
|
|
556
|
+
await w.npcs.onTurn(turn({ speaker: 'a' }));
|
|
557
|
+
w.h.sim.players.delete('a');
|
|
558
|
+
const before = w.labels.length;
|
|
559
|
+
await w.npcs.onRead(statusRead('a', 'op1', 'Hello, a.'));
|
|
560
|
+
assert.equal(w.labels.length, before);
|
|
551
561
|
});
|
|
552
562
|
|
|
553
563
|
await test("blocks: the kit's line naming a player is marked as about them", async () => {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// installed.
|
|
7
7
|
|
|
8
8
|
import assert from 'node:assert/strict';
|
|
9
|
+
import { padPoint, proposalDoor } from '../code/server/party.js';
|
|
9
10
|
import { register } from 'node:module';
|
|
10
11
|
|
|
11
12
|
const sceneStub = 'export const readScene = () => globalThis.__hubTestActors ?? [];';
|
|
@@ -126,7 +127,7 @@ let n = 0;
|
|
|
126
127
|
// others are asked, and the place can see how many it waits on.
|
|
127
128
|
party(b, 'p1', { op: 'go', door: 'race' });
|
|
128
129
|
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.hypot(at(b, 'p1').x + 22, at(b, 'p1').z) <= 1 + 1e-9, `on the pad: ${JSON.stringify(at(b, 'p1'))}`);
|
|
130
131
|
assert.ok(Math.abs(b.world.players.get('p1').facing - (270 * Math.PI) / 180) < 1e-9, 'facing the door');
|
|
131
132
|
const proposal = told(b, 'p2').proposal;
|
|
132
133
|
assert.deepEqual(proposal, { id: proposal.id, door: 'race', by: 'p1', username: 'ada', asked: true });
|
|
@@ -140,7 +141,8 @@ let n = 0;
|
|
|
140
141
|
party(b, 'g4', { op: 'go-no', id: proposal.id });
|
|
141
142
|
party(b, 'g4', { op: 'go-yes', id: proposal.id });
|
|
142
143
|
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 + 22, at(b, 'p2').z) <= 1 + 1e-9);
|
|
145
|
+
assert.ok(Math.hypot(at(b, 'p2').x - at(b, 'p1').x, at(b, 'p2').z - at(b, 'p1').z) >= 1.1 - 1e-9, 'clear of the proposer by more than two bodies');
|
|
144
146
|
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
147
|
assert.ok(Math.hypot(at(b, 'g4').x, at(b, 'g4').z) < 3, 'the one who said no stayed');
|
|
146
148
|
assert.equal(b.ctx().coming('race'), 0);
|
|
@@ -204,12 +206,93 @@ let n = 0;
|
|
|
204
206
|
{
|
|
205
207
|
const b = boot();
|
|
206
208
|
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'))}`);
|
|
209
|
+
assert.ok(Math.hypot(at(b, 'p1').x + 22, at(b, 'p1').z) <= 1 + 1e-9, `on the pad: ${JSON.stringify(at(b, 'p1'))}`);
|
|
208
210
|
b.h.message(b.session, { playerId: 'p2' }, { k: 'hub-door-jump', door: 'gems' });
|
|
209
211
|
assert.ok(Math.abs(at(b, 'p2').z + 21) < 1e-9, '7 m in front of a door with no pad');
|
|
210
212
|
n += 1;
|
|
211
213
|
}
|
|
212
214
|
|
|
215
|
+
// A crowded pad: each newcomer is put where there is most room, never on
|
|
216
|
+
// someone, for as long as the pad has room.
|
|
217
|
+
{
|
|
218
|
+
const b = boot();
|
|
219
|
+
const realNow = Date.now;
|
|
220
|
+
const ids = ['p1', 'p2', 'g4'];
|
|
221
|
+
const placed = [];
|
|
222
|
+
for (let i = 0; i < 3; i += 1) {
|
|
223
|
+
Date.now = () => realNow() + 3000 * (i + 1);
|
|
224
|
+
b.h.message(b.session, { playerId: ids[i] }, { k: 'hub-door-jump', door: 'race' });
|
|
225
|
+
placed.push({ ...at(b, ids[i]) });
|
|
226
|
+
}
|
|
227
|
+
Date.now = realNow;
|
|
228
|
+
for (let i = 0; i < placed.length; i += 1) {
|
|
229
|
+
assert.ok(Math.hypot(placed[i].x + 22, placed[i].z) <= 2, `on the pad: ${JSON.stringify(placed[i])}`);
|
|
230
|
+
for (let j = 0; j < i; j += 1) {
|
|
231
|
+
assert.ok(Math.hypot(placed[i].x - placed[j].x, placed[i].z - placed[j].z) >= 0.9, `not touching: ${JSON.stringify(placed)}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
n += 1;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// padPoint itself: the middle and the inner ring taken, the outer ring; every
|
|
238
|
+
// spot taken, the one with the most room.
|
|
239
|
+
{
|
|
240
|
+
const door = { id: 'race', t: { x: 0, z: 0, rotationY: 0 } };
|
|
241
|
+
const pad = { id: 'pad', components: { HubPad: { door: 'race', radius: 2.3 }, Transform: { x: 0, z: 0 } } };
|
|
242
|
+
const players = new Map();
|
|
243
|
+
const h = { actors: [pad], hidden: new Set(), sim: { players } };
|
|
244
|
+
players.set('c', { at: { x: 0, z: 0 } });
|
|
245
|
+
for (let i = 0; i < 6; i += 1) {
|
|
246
|
+
const a = (i * 2 * Math.PI) / 6;
|
|
247
|
+
players.set(`r${i}`, { at: { x: Math.sin(a) * 1.15, z: Math.cos(a) * 1.15 } });
|
|
248
|
+
}
|
|
249
|
+
const at = padPoint(h, door, 0, 'me');
|
|
250
|
+
const r = Math.hypot(at.x, at.z);
|
|
251
|
+
assert.ok(r > 1.5 && r <= 2.3, `the outer ring: ${JSON.stringify(at)}`);
|
|
252
|
+
// Less than PAD_CLEAR_M from its inner neighbours on a 2.3 m pad, but not touching anyone.
|
|
253
|
+
assert.ok([...players.values()].every((p) => Math.hypot(p.at.x - at.x, p.at.z - at.z) >= 0.9), 'touching nobody');
|
|
254
|
+
for (let i = 0; i < 6; i += 1) {
|
|
255
|
+
const a = ((i + 0.5) * 2 * Math.PI) / 6;
|
|
256
|
+
players.set(`o${i}`, { at: { x: Math.sin(a) * 1.75, z: Math.cos(a) * 1.75 } });
|
|
257
|
+
}
|
|
258
|
+
const last = padPoint(h, door, 0, 'me');
|
|
259
|
+
assert.ok(Math.hypot(last.x, last.z) <= 2.3, 'still on the pad');
|
|
260
|
+
n += 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// A spot on the pad that someone stands on is not used: a body put inside
|
|
264
|
+
// another is pushed off the pad. And a jump holds the body where it was put
|
|
265
|
+
// for a moment, so move reports still in flight cannot drag it back off.
|
|
266
|
+
{
|
|
267
|
+
const b = boot();
|
|
268
|
+
const realNow = Date.now;
|
|
269
|
+
for (let i = 0; i < 12; i += 1) {
|
|
270
|
+
// Each try a few seconds on: past the place's jump limit and the last hold.
|
|
271
|
+
Date.now = () => realNow() + 3000 * (i + 1);
|
|
272
|
+
b.h.place(b.world, []);
|
|
273
|
+
Object.assign(at(b, 'p2'), { x: -21.1, z: 0 });
|
|
274
|
+
Object.assign(at(b, 'p1'), { x: 0, z: 0 });
|
|
275
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-door-jump', door: 'race' });
|
|
276
|
+
const me = { ...at(b, 'p1') };
|
|
277
|
+
assert.ok(Math.hypot(me.x + 22, me.z) <= 1 + 1e-9, 'on the pad');
|
|
278
|
+
// More than two bodies' width: put down touching them, physics would push one off the pad.
|
|
279
|
+
assert.ok(Math.hypot(me.x - at(b, 'p2').x, me.z - at(b, 'p2').z) >= 0.9, `clear of the player on a ring spot: ${JSON.stringify(me)}`);
|
|
280
|
+
// A stale report moves the body toward where it came from: the hold puts it back.
|
|
281
|
+
Object.assign(at(b, 'p1'), { x: me.x + 1.5, z: me.z + 1 });
|
|
282
|
+
b.h.place(b.world, []);
|
|
283
|
+
assert.ok(Math.hypot(at(b, 'p1').x - me.x, at(b, 'p1').z - me.z) < 0.01, 'kept where the jump put it');
|
|
284
|
+
assert.ok(!b.h.join().held.includes('p1'), 'not a hold: the client keeps its input and what it carries');
|
|
285
|
+
}
|
|
286
|
+
// The hold ends by itself.
|
|
287
|
+
Date.now = () => realNow() + 3000 * 14;
|
|
288
|
+
b.h.place(b.world, []);
|
|
289
|
+
Object.assign(at(b, 'p1'), { x: 5, z: 5 });
|
|
290
|
+
b.h.place(b.world, []);
|
|
291
|
+
assert.deepEqual([at(b, 'p1').x, at(b, 'p1').z], [5, 5], 'free to walk again');
|
|
292
|
+
Date.now = realNow;
|
|
293
|
+
n += 1;
|
|
294
|
+
}
|
|
295
|
+
|
|
213
296
|
// No invitation across a block; no parties in a game; no go without a party.
|
|
214
297
|
{
|
|
215
298
|
const b = boot({ hiddenPair: (x, y) => [x, y].sort().join() === 'p1,p2' });
|
|
@@ -259,7 +342,7 @@ let n = 0;
|
|
|
259
342
|
const first = told(b, 'p2').proposal.id;
|
|
260
343
|
party(b, 'p2', { op: 'go', door: 'race' });
|
|
261
344
|
tick(b);
|
|
262
|
-
assert.ok(Math.hypot(at(b, 'p2').x + 22, at(b, 'p2').z) <= 1, 'on the pad');
|
|
345
|
+
assert.ok(Math.hypot(at(b, 'p2').x + 22, at(b, 'p2').z) <= 1 + 1e-9, 'on the pad');
|
|
263
346
|
assert.equal(b.ctx().coming('race'), 0, 'nobody is left to answer');
|
|
264
347
|
assert.equal(told(b, 'p1').proposal, null);
|
|
265
348
|
party(b, 'p1', { op: 'go', door: 'race' });
|
|
@@ -283,4 +366,25 @@ let n = 0;
|
|
|
283
366
|
n += 1;
|
|
284
367
|
}
|
|
285
368
|
|
|
369
|
+
// Cues (contract v1.23): the door of a player's live proposal, for "Let's
|
|
370
|
+
// play…" -- the proposer's and each member still asked, nobody else's, and
|
|
371
|
+
// not once it is answered or has run out.
|
|
372
|
+
{
|
|
373
|
+
const now = Date.now();
|
|
374
|
+
const h = {
|
|
375
|
+
players: new Map([['p1', { userId: '101' }], ['p2', { userId: '102' }], ['p3', { userId: '103' }], ['g4', { userId: null }]]),
|
|
376
|
+
party: {
|
|
377
|
+
of: new Map([['u:101', 'party-1'], ['u:102', 'party-1'], ['u:103', 'party-1'], ['p:g4', 'party-2']]),
|
|
378
|
+
proposals: new Map(),
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
const doors = () => ['p1', 'p2', 'p3', 'g4', 'nobody'].map((id) => proposalDoor(h, id));
|
|
382
|
+
assert.deepEqual(doors(), [null, null, null, null, null], 'no proposal');
|
|
383
|
+
h.party.proposals.set('party-1', { id: 1, door: 'race', by: 'p1', until: now + 45000, asked: new Set(['p2']) });
|
|
384
|
+
assert.deepEqual(doors(), ['race', 'race', null, null, null], 'the proposer and the member still asked');
|
|
385
|
+
h.party.proposals.get('party-1').until = now - 1;
|
|
386
|
+
assert.deepEqual(doors(), [null, null, null, null, null], 'run out');
|
|
387
|
+
n += 1;
|
|
388
|
+
}
|
|
389
|
+
|
|
286
390
|
console.log(`test-party: ${n} passed`);
|
|
@@ -25,6 +25,7 @@ const { makeSay, REACTIONS } = await import('../code/client/say.js');
|
|
|
25
25
|
globalThis.__hubTestActors = [
|
|
26
26
|
{ id: 'spawn', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
27
27
|
{ id: 'door-race', components: { HubDoor: { id: 'race', to: 'race' }, Transform: { x: -28, y: 1.4, z: 0, rotationY: 90 } } },
|
|
28
|
+
{ id: 'door-gems', components: { HubDoor: { id: 'gems', to: 'race', title: 'Gem Rush' }, Transform: { x: 60, y: 1.4, z: 0, rotationY: 270 } } },
|
|
28
29
|
];
|
|
29
30
|
const castleJson = {
|
|
30
31
|
server: { maxPlayers: 8 },
|
|
@@ -37,8 +38,8 @@ const castleJson = {
|
|
|
37
38
|
const sceneExists = (scene) => ['scenes/main.scene', 'scenes/race.scene'].includes(scene);
|
|
38
39
|
const ROSTER = ['p1', 'p2', 'p3'].map((playerId, i) => ({ playerId, userId: String(101 + i), username: playerId }));
|
|
39
40
|
|
|
40
|
-
function boot({ sessionId = 'dev:test', hiddenPair = null } = {}) {
|
|
41
|
-
const h = layer(castleJson, {}, {}, sceneExists);
|
|
41
|
+
function boot({ sessionId = 'dev:test', hiddenPair = null, cues = undefined } = {}) {
|
|
42
|
+
const h = layer(cues === undefined ? castleJson : { ...castleJson, hub: { ...castleJson.hub, cues } }, {}, {}, sceneExists);
|
|
42
43
|
const sent = [];
|
|
43
44
|
const session = {
|
|
44
45
|
sessionId,
|
|
@@ -66,6 +67,8 @@ function boot({ sessionId = 'dev:test', hiddenPair = null } = {}) {
|
|
|
66
67
|
const say = (b, playerId, data) => b.h.message(b.session, { playerId }, { k: 'hub-say', ...data });
|
|
67
68
|
const said = (b) => b.sent.filter(([, msg]) => msg.k === 'hub-said');
|
|
68
69
|
|
|
70
|
+
// The phrase id the kit once had and no longer does.
|
|
71
|
+
const GONE = 'join';
|
|
69
72
|
let n = 0;
|
|
70
73
|
|
|
71
74
|
// A reaction and a phrase go to everyone; text, an unknown id and a game's
|
|
@@ -116,6 +119,51 @@ let n = 0;
|
|
|
116
119
|
n += 1;
|
|
117
120
|
}
|
|
118
121
|
|
|
122
|
+
// Cues (contract v1.23). "Let's play" names the door of the speaker's open
|
|
123
|
+
// party proposal first; a deck without cues names the door they stand by, as
|
|
124
|
+
// it always did.
|
|
125
|
+
const party = (b, playerId, data) => b.h.message(b.session, { playerId }, { k: 'hub-party', ...data });
|
|
126
|
+
for (const cues of [true, false, undefined]) {
|
|
127
|
+
const b = boot({ cues });
|
|
128
|
+
party(b, 'p1', { op: 'invite', player: 'p2' });
|
|
129
|
+
party(b, 'p2', { op: 'accept', from: 'p1' });
|
|
130
|
+
party(b, 'p1', { op: 'go', door: 'race' });
|
|
131
|
+
// p2 was asked and has not answered; they stand by another door, p3 by none.
|
|
132
|
+
Object.assign(b.world.players.get('p2').at, { x: 55, z: 0 });
|
|
133
|
+
say(b, 'p2', { p: 'play' });
|
|
134
|
+
say(b, 'p1', { p: 'play' });
|
|
135
|
+
say(b, 'p3', { p: 'play' });
|
|
136
|
+
assert.deepEqual(said(b).map(([, msg]) => msg.door), cues ? ['race', 'race', null] : ['gems', 'race', null], `cues ${cues}`);
|
|
137
|
+
// Answered: the proposal is no longer p2's, who names the door they stand by.
|
|
138
|
+
b.h.place(b.world, []);
|
|
139
|
+
b.h.step(b.world, []);
|
|
140
|
+
const id = b.sent.filter(([to, msg]) => to === 'p2' && msg.k === 'hub-party').at(-1)[1].proposal.id;
|
|
141
|
+
party(b, 'p2', { op: 'go-no', id });
|
|
142
|
+
const realNow = Date.now;
|
|
143
|
+
Date.now = () => realNow() + 5000;
|
|
144
|
+
say(b, 'p2', { p: 'play' });
|
|
145
|
+
Date.now = realNow;
|
|
146
|
+
assert.equal(said(b).at(-1)[1].door, 'gems', `cues ${cues}: answered`);
|
|
147
|
+
n += 1;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// There is no `join` phrase, with cues or without: it is an unknown id like
|
|
151
|
+
// any other, whatever came before it and whatever it carries. And a `door` a
|
|
152
|
+
// client puts on "Let's play" is never read.
|
|
153
|
+
for (const cues of [true, false, undefined]) {
|
|
154
|
+
const b = boot({ cues });
|
|
155
|
+
party(b, 'p1', { op: 'invite', player: 'p2' });
|
|
156
|
+
party(b, 'p2', { op: 'accept', from: 'p1' });
|
|
157
|
+
b.h.message(b.session, { playerId: 'p1' }, { k: 'hub-door-jump', door: 'race' });
|
|
158
|
+
say(b, 'p1', { p: GONE, door: 'race', to: ['p2', 'p3'] });
|
|
159
|
+
say(b, 'p1', { p: GONE });
|
|
160
|
+
assert.deepEqual(said(b), [], `cues ${cues}: join is refused`);
|
|
161
|
+
Object.assign(b.world.players.get('p3').at, { x: 0, z: 0 });
|
|
162
|
+
say(b, 'p3', { p: 'play', door: 'race' });
|
|
163
|
+
assert.deepEqual(said(b), [['*', { k: 'hub-said', player: 'p3', p: 'play', door: null }]], 'the door a client names is ignored');
|
|
164
|
+
n += 1;
|
|
165
|
+
}
|
|
166
|
+
|
|
119
167
|
// The client words what was said: bubbles, the feed, and "Over here!" heard.
|
|
120
168
|
{
|
|
121
169
|
HubState.hub.place = { title: 'Town', result: null };
|
|
@@ -141,6 +189,15 @@ let n = 0;
|
|
|
141
189
|
s.frame(30000, 'me', () => 'bo');
|
|
142
190
|
s.clear();
|
|
143
191
|
assert.deepEqual(s.feed(), []);
|
|
192
|
+
// A phrase the kit does not have (`join`, say) is skipped, cues or not.
|
|
193
|
+
for (const cues of [true, false]) {
|
|
194
|
+
HubState.deck.cues = cues;
|
|
195
|
+
const plays = [];
|
|
196
|
+
HubState.hub.saidEvents.push({ player: 'p2', p: GONE, door: 'race' }, { player: 'me', p: GONE, door: 'race' });
|
|
197
|
+
s.frame(40000, 'me', () => 'bo', () => {}, (...args) => plays.push(args));
|
|
198
|
+
assert.deepEqual([plays, s.feed(), s.labels(scene, { id: 'local' }, null, null, (cam, x) => ({ x, y: 0 }), 'me')], [[], [], []], `cues ${cues}`);
|
|
199
|
+
}
|
|
200
|
+
HubState.deck.cues = false;
|
|
144
201
|
HubState.hub.place = null;
|
|
145
202
|
HubState.hub.doors = [];
|
|
146
203
|
n += 1;
|