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.
Files changed (92) hide show
  1. package/dist/castle-host/host.js +81 -0
  2. package/dist/devSaveStorage.d.ts +36 -0
  3. package/dist/devSaveStorage.js +469 -0
  4. package/dist/devSessionChild.js +22 -12
  5. package/dist/devSessionServer.js +8 -2
  6. package/dist/devSessionStorage.d.ts +9 -0
  7. package/dist/devSessionStorage.js +66 -1
  8. package/dist/init.js +1 -1
  9. package/dist/serve.js +5 -1
  10. package/dist/serverBundle.js +5 -3
  11. package/kits/base/castle.json +1 -1
  12. package/kits/base/sdk/README.md +148 -1
  13. package/kits/base/sdk/castle.d.ts +4 -0
  14. package/kits/base/sdk/castle.js +2 -0
  15. package/kits/base/sdk/commands.d.ts +15 -0
  16. package/kits/base/sdk/multiplayer.js +52 -4
  17. package/kits/base/sdk/save.d.ts +197 -0
  18. package/kits/base/sdk/save.js +525 -0
  19. package/kits/base/sdk/saveCoordinator.d.ts +39 -0
  20. package/kits/base/sdk/saveCoordinator.js +252 -0
  21. package/kits/base/sdk/server/storage.d.ts +3 -2
  22. package/kits/base/sdk/server/storage.js +25 -5
  23. package/kits/base/sdk/server/wrapper.d.ts +4 -0
  24. package/kits/base/sdk/server/wrapper.js +2 -0
  25. package/kits/base/sdk/store.d.ts +3 -2
  26. package/kits/base/sdk/store.js +5 -0
  27. package/kits/hub-game/CLAUDE.md +29 -4
  28. package/kits/hub-game/code/client/avatar.js +39 -0
  29. package/kits/hub-game/code/client/chat.js +12 -0
  30. package/kits/hub-game/code/client/chrome.js +237 -13
  31. package/kits/hub-game/code/client/grab.js +166 -7
  32. package/kits/hub-game/code/client/hats.js +26 -0
  33. package/kits/hub-game/code/client/hookLayer.js +36 -3
  34. package/kits/hub-game/code/client/hudClear.js +126 -0
  35. package/kits/hub-game/code/client/state.js +35 -1
  36. package/kits/hub-game/code/client/talk.js +10 -36
  37. package/kits/hub-game/code/client/tiers.js +505 -0
  38. package/kits/hub-game/code/client/together.js +144 -4
  39. package/kits/hub-game/code/client/wear.js +96 -14
  40. package/kits/hub-game/code/server/actors.js +5 -0
  41. package/kits/hub-game/code/server/grab.js +299 -13
  42. package/kits/hub-game/code/server/hub.js +162 -7
  43. package/kits/hub-game/code/server/manifest.js +80 -8
  44. package/kits/hub-game/code/server/npcs.js +21 -33
  45. package/kits/hub-game/code/server/party.js +75 -6
  46. package/kits/hub-game/code/server/say.js +8 -2
  47. package/kits/hub-game/code/server/wear.js +116 -11
  48. package/kits/hub-game/code/systems/hub.js +386 -21
  49. package/kits/hub-game/docs/contract.md +285 -19
  50. package/kits/hub-game/package.json +1 -1
  51. package/kits/hub-game/scripts/test-chat.mjs +32 -0
  52. package/kits/hub-game/scripts/test-grab-client.mjs +511 -0
  53. package/kits/hub-game/scripts/test-grab.mjs +857 -3
  54. package/kits/hub-game/scripts/test-hats.mjs +229 -0
  55. package/kits/hub-game/scripts/test-hub-trip.mjs +721 -0
  56. package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
  57. package/kits/hub-game/scripts/test-manifest.mjs +122 -1
  58. package/kits/hub-game/scripts/test-npcs.mjs +34 -24
  59. package/kits/hub-game/scripts/test-party.mjs +108 -4
  60. package/kits/hub-game/scripts/test-say.mjs +59 -2
  61. package/kits/hub-game/scripts/test-tiers.mjs +854 -0
  62. package/kits/hub-game/scripts/test-together.mjs +33 -1
  63. package/kits/hub-game/scripts/test-try-on.mjs +940 -0
  64. package/kits/physics-2d/CLAUDE.md +2 -0
  65. package/kits/physics-2d/castle.json +2 -2
  66. package/kits/physics-2d/engine/scene.js +127 -0
  67. package/kits/physics-2d/package.json +1 -1
  68. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +298 -0
  69. package/kits/physics-3d/CLAUDE.md +531 -0
  70. package/kits/physics-3d/behaviors/Player.jsx +437 -3
  71. package/kits/physics-3d/castle.json +3 -3
  72. package/kits/physics-3d/docs/pxmodel-format.md +4 -0
  73. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -1
  74. package/kits/physics-3d/engine3d/actornode.js +253 -0
  75. package/kits/physics-3d/engine3d/nearshadows.js +600 -0
  76. package/kits/physics-3d/engine3d/optimize.js +49 -0
  77. package/kits/physics-3d/engine3d/orbitinput.js +277 -0
  78. package/kits/physics-3d/engine3d/unchanged.js +153 -0
  79. package/kits/physics-3d/engine3d/world3d.js +525 -11
  80. package/kits/physics-3d/package.json +1 -1
  81. package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
  82. package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
  83. package/kits/physics-3d/scripts/test-camera-follow.mjs +543 -0
  84. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2105 -0
  85. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
  86. package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
  87. package/kits/physics-3d/scripts/test-static-actors.mjs +667 -0
  88. package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
  89. package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
  90. package/kits/physics-3d/scripts/test-steady-hover.mjs +633 -0
  91. package/kits/physics-3d/systems/physics3d.js +273 -9
  92. package/package.json +1 -1
@@ -378,6 +378,107 @@ await test("a game's end stays armed until the player is in another session", as
378
378
  assert.equal(system.pendingEnd, null);
379
379
  });
380
380
 
381
+ await test("the town's server replaced under a player who came back through a door: the join the runtime began with is made again", async () => {
382
+ const closedNet = (error = null) => ({ closed: () => true, closeError: () => error });
383
+ const run = ({ target, depth = 0, place = { title: 'Town' }, tickets = [], error = null, root }) => {
384
+ const { system, scene } = setup();
385
+ const switched = [];
386
+ scene.multiplayer = { target, net: null, switchSession: (sc, join, opts) => switched.push([join, opts ?? null]) };
387
+ scene.persistent.hubDepth = depth;
388
+ scene.persistent.hubTickets = tickets;
389
+ if (root) {
390
+ scene.persistent.hubRootJoin = root;
391
+ }
392
+ HubState.hub.place = place;
393
+ system.lastNet = closedNet(error);
394
+ system.watchSession(scene, scene.multiplayer);
395
+ return { system, switched };
396
+ };
397
+ // Back in the town by a hub join (its handoff spent), and the session ends.
398
+ let r = run({ target: { mode: 'hub', handoff: { sessionId: 'town-1' } } });
399
+ assert.deepEqual(r.switched, [[{ mode: 'public' }, null]]);
400
+ assert.equal(r.system.toast.text, 'Reconnecting…');
401
+ assert.equal(r.system.lastNet, null, 'once');
402
+ r = run({ target: { mode: 'hub', handoff: {} }, root: { mode: 'named', key: 'k' } });
403
+ assert.deepEqual(r.switched, [[{ mode: 'named', key: 'k' }, null]]);
404
+ // A join the multiplayer kit makes again by itself: left to it.
405
+ assert.deepEqual(run({ target: { mode: 'public' } }).switched, []);
406
+ // In a game, or barred from the hub: not this.
407
+ assert.deepEqual(run({ target: { mode: 'hub', handoff: {} }, place: { title: 'Foot Race', result: {} } }).switched, []);
408
+ assert.deepEqual(run({ target: { mode: 'hub', handoff: {} }, error: 'CAULDRON_HUB_BANNED' }).switched, []);
409
+ assert.deepEqual(calls.filter((c) => c[0] === 'back'), []);
410
+ // A trip of ours closes the old connection: not an ending.
411
+ const { system, scene } = setup();
412
+ const switched = [];
413
+ scene.multiplayer = { target: { mode: 'hub', handoff: {} }, net: null, switchSession: (...a) => switched.push(a) };
414
+ system.lastNet = closedNet();
415
+ system.trip = { phase: 'covering' };
416
+ system.watchSession(scene, scene.multiplayer);
417
+ assert.deepEqual(switched, []);
418
+ HubState.hub.place = null;
419
+ });
420
+
421
+ await test('a place behind a door whose server is replaced under a player: left by its way back, once', async () => {
422
+ const closedNet = (error = null) => ({ closed: () => true, closeError: () => error });
423
+ const run = ({ depth = 1, place = { title: 'Pebble Cove' }, tickets, error = null }) => {
424
+ const { system, scene } = setup();
425
+ const switched = [];
426
+ scene.multiplayer = { target: { mode: 'hub', handoff: { sessionId: 'cove-1' } }, net: null, switchSession: (sc, join, opts) => switched.push([join, opts ?? null]) };
427
+ scene.persistent.hubDepth = depth;
428
+ scene.persistent.hubTickets = tickets ?? [{ scene: 'scenes/main.scene', title: 'Town', door: 'cove', hub: true, join: { mode: 'public' } }];
429
+ HubState.hub.place = place;
430
+ answers.back = handoff();
431
+ system.lastNet = closedNet(error);
432
+ system.watchSession(scene, scene.multiplayer);
433
+ return { system, scene, switched };
434
+ };
435
+ const backs = () => calls.filter((c) => c[0] === 'back').length;
436
+
437
+ // A place that is not a game, reached through a door: Hub.back, no rejoin.
438
+ let r = run({});
439
+ await flush();
440
+ assert.equal(backs(), 1);
441
+ assert.deepEqual(r.switched, []);
442
+ assert.equal(r.system.toast.text, 'This place was updated. Back to Town…');
443
+ assert.equal(r.system.trip?.target.hubStep, -1, 'the way back is a hub trip');
444
+ assert.equal(HubState.hub.place, null, 'what the dead session drew is gone');
445
+ // While that way back is pending the close is not acted on again, even with
446
+ // the dead connection still there.
447
+ r.system.lastNet = closedNet();
448
+ r.system.watchSession(r.scene, r.scene.multiplayer);
449
+ r.system.watchSession(r.scene, r.scene.multiplayer);
450
+ await flush();
451
+ assert.equal(backs(), 1);
452
+ assert.deepEqual(r.switched, []);
453
+ // After a way back that was refused, the close is not seen again: the
454
+ // multiplayer kit holds no connection, and Back is left to the host's control.
455
+ r.system.trip = null;
456
+ r.system.watchSession(r.scene, r.scene.multiplayer);
457
+ await flush();
458
+ assert.equal(backs(), 1);
459
+
460
+ // No ticket in this runtime (the host's trail holds the trip): still Hub.back.
461
+ r = run({ tickets: [] });
462
+ await flush();
463
+ assert.equal(backs(), 1);
464
+ assert.equal(r.system.toast.text, 'This place was updated. Going back…');
465
+
466
+ // A game behind a door is left as it always was.
467
+ r = run({ place: { title: 'Foot Race', result: {} } });
468
+ await flush();
469
+ assert.equal(backs(), 1);
470
+ assert.equal(r.system.toast.text, 'The game ended');
471
+ assert.deepEqual(r.switched, []);
472
+
473
+ // Barred from the hub: nothing is asked.
474
+ r = run({ error: 'CAULDRON_HUB_BANNED' });
475
+ await flush();
476
+ assert.equal(backs(), 0);
477
+ assert.deepEqual(r.switched, []);
478
+ assert.equal(r.system.trip, null);
479
+ HubState.hub.place = null;
480
+ });
481
+
381
482
  await test("a game's end waits out a pending join, settles once it resolves elsewhere, and retries after a failed one", async () => {
382
483
  const { system, scene } = setup();
383
484
  const backs = [];
@@ -1234,6 +1335,92 @@ await test('People: a game lists who may be reported, only where the host runs t
1234
1335
  HubState.hub.whereAt = {};
1235
1336
  });
1236
1337
 
1338
+ await test('a sent chat line says whom it reached', async () => {
1339
+ const { system } = setup();
1340
+ let status = 'sent';
1341
+ system.chat.send = (text, done) => done(status);
1342
+ system.chatReach = ['bo', 'amy'];
1343
+ system.saying({ text: 'hello' });
1344
+ assert.equal(system.toast.text, 'Sent to bo, amy');
1345
+ system.chatReach = ['a', 'b', 'c', 'd', 'e'];
1346
+ system.saying({ text: 'hello' });
1347
+ assert.equal(system.toast.text, 'Sent to a, b, c +2');
1348
+ status = 'none';
1349
+ system.saying({ text: 'hello' });
1350
+ assert.equal(system.toast.text, 'Nobody here can read that. Follow each other to chat.');
1351
+ });
1352
+
1353
+ await test('the invite button beside someone: steady at the edge of range, kept for a friend, says it was sent', async () => {
1354
+ const together = makeTogether();
1355
+ const at = { p2: { x: 2, z: 0 }, p4: { x: 30, z: 0 } };
1356
+ const scene = {
1357
+ multiplayer: {
1358
+ net: { others: () => new Map([['p2', 'bo'], ['p4', 'amy']]), userId: (id) => ({ p2: '102', p4: '104' })[id] ?? null, send() {} },
1359
+ avatars: { actors: new Map([['p2', 'a2'], ['p4', 'a4']]) },
1360
+ },
1361
+ getActor: (id) => ({ components: { Transform: at[id === 'a2' ? 'p2' : 'p4'] } }),
1362
+ };
1363
+ HubState.hub.place = { title: 'Town', result: null };
1364
+ HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
1365
+ const local = { components: { Transform: { x: 0, y: 1, z: 0 } } };
1366
+ const friends = [{ userId: '104', username: 'amy', here: true }];
1367
+ together.frame(scene.multiplayer, friends, true, 0);
1368
+ const who = (now) => together.beside(scene, local, now)?.playerId ?? null;
1369
+ assert.equal(who(1000), null, 'not at once');
1370
+ assert.equal(who(2600), 'p2', 'after standing by them a moment');
1371
+ // A step back past the near distance and in again: the button does not blink.
1372
+ at.p2.x = 2.6;
1373
+ assert.equal(who(2700), 'p2', 'still about');
1374
+ at.p2.x = 2.1;
1375
+ assert.equal(who(2800), 'p2');
1376
+ assert.equal(who(11000), null, 'not a friend: the offer ends');
1377
+ // Walked right off and back: offered again after a moment.
1378
+ at.p2.x = 9;
1379
+ assert.equal(who(11100), null);
1380
+ at.p2.x = 2;
1381
+ assert.equal(who(11200), null);
1382
+ assert.equal(who(12800), 'p2');
1383
+ // A press: the button says so, then leaves that player alone for a while.
1384
+ together.invited('p2', 12900);
1385
+ assert.deepEqual(together.beside(scene, local, 13000), { d: 2, playerId: 'p2', username: 'bo', sent: true });
1386
+ assert.equal(who(18000), null, 'not offered again straight away');
1387
+ assert.equal(who(44000), null, 'the old offer has run out by then');
1388
+ // A friend's stays for as long as they stand there.
1389
+ at.p2.x = 30;
1390
+ at.p4.x = 1.5;
1391
+ assert.equal(who(50000), null);
1392
+ assert.equal(who(52000), 'p4');
1393
+ assert.equal(who(90000), 'p4', 'a friend beside the player is always offered');
1394
+ // Someone whose offer ran out is not in the way of the next one along.
1395
+ at.p4.x = 30;
1396
+ at.p2.x = 3;
1397
+ assert.equal(who(100000), null);
1398
+ at.p2.x = 2;
1399
+ assert.equal(who(100100), null);
1400
+ assert.equal(who(101700), 'p2');
1401
+ assert.equal(who(111000), null, "bo's offer ends");
1402
+ at.p2.x = 3;
1403
+ at.p4.x = 1;
1404
+ assert.equal(who(111100), null);
1405
+ assert.equal(who(112700), 'p4', 'amy, though bo still stands near');
1406
+ together.invited('p4', 112800);
1407
+ assert.equal(together.beside(scene, local, 113000).sent, true);
1408
+ at.p2.x = 9;
1409
+ assert.equal(who(117000), null);
1410
+ at.p2.x = 2;
1411
+ assert.equal(who(117100), null);
1412
+ assert.equal(who(118700), 'p2', 'bo walked off and back: offered, though amy was just invited');
1413
+ at.p2.x = 30;
1414
+ at.p4.x = 1.5;
1415
+ assert.equal(who(150000), null);
1416
+ assert.equal(who(152000), 'p4');
1417
+ // In the party: nothing to offer.
1418
+ HubState.hub.party = { members: ['p4'], away: 0, invite: null, proposal: null };
1419
+ assert.equal(who(153000), null);
1420
+ HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
1421
+ HubState.hub.place = null;
1422
+ });
1423
+
1237
1424
  await test('start next to a friend: once, on walking in, when a friend is here and the player has not walked off', async () => {
1238
1425
  const { system, scene } = setup();
1239
1426
  const sent = [];
@@ -1290,6 +1477,27 @@ await test('start next to a friend: once, on walking in, when a friend is here a
1290
1477
  assert.deepEqual(system.together.arrivals(), [{ playerId: 'p9', username: 'zed' }]);
1291
1478
  assert.deepEqual(system.together.arrivals(), []);
1292
1479
 
1480
+ // A friend who goes through a door is named to those left behind, with Follow.
1481
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race', late: true }];
1482
+ system.together.frame(scene.multiplayer, [...friends, { userId: '109', username: 'zed', here: true }], true, 48000);
1483
+ HubState.hub.wentEvents.push({ k: 'hub-went', players: ['p9'], door: 'race' }, { k: 'hub-went', players: ['p2'], door: 'race' });
1484
+ for (const went of HubState.hub.wentEvents.splice(0)) {
1485
+ const name = went.players.map((id) => system.together.lately(id)).find(Boolean);
1486
+ if (name) {
1487
+ system.playAsk = { from: went.players[0], name, door: went.door, until: performance.now() + 45000, went: true };
1488
+ }
1489
+ }
1490
+ assert.deepEqual([system.ask().text, system.ask().yes], ['zed went into Foot Race', 'Follow'], 'bo is no friend: only zed is named');
1491
+ // A door that takes no late joiners: told where they are, with no Follow.
1492
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }];
1493
+ assert.deepEqual([system.ask().text, system.ask().yes, system.ask().no], ['zed went into Foot Race · back soon', 'OK', 'Go to the door']);
1494
+ sent.length = 0;
1495
+ system.jumpSentAt = -Infinity;
1496
+ system.answer(scene, system.ask(), true);
1497
+ assert.deepEqual(sent, [], 'OK stays put');
1498
+ system.playAsk = null;
1499
+ HubState.hub.doors = [];
1500
+
1293
1501
  // A jump the player asks for ends a pending start, and one sent on the
1294
1502
  // heels of another waits its turn rather than being dropped by the place.
1295
1503
  system.startNear = { until: 99999, at: null, asked: false };
@@ -1305,6 +1513,519 @@ await test('start next to a friend: once, on walking in, when a friend is here a
1305
1513
  HubState.hub.jumpedTo = null;
1306
1514
  });
1307
1515
 
1516
+ // Cues (contract v1.23): everything below is behind `hub.cues` in the deck's
1517
+ // castle.json (`Hub.deck.cues`). Each test runs the same steps with it off
1518
+ // and asserts the kit does exactly what it did.
1519
+
1520
+ // A chrome that records what the hub system hands it.
1521
+ function cueChrome(system) {
1522
+ const seen = { toast: '', say: null, ask: null };
1523
+ system.chrome = {
1524
+ showBack() {}, showPicker() {}, setFriends() {}, setDoors() {}, setPeople() {}, setHud() {}, setLabels() {}, setRibbon() {},
1525
+ setToast(text) { seen.toast = text; },
1526
+ setSay(say) { seen.say = say; },
1527
+ setAsk(ask) { seen.ask = ask; },
1528
+ };
1529
+ system.talk = { talking: () => false };
1530
+ globalThis.window ??= { innerWidth: 400, innerHeight: 800 };
1531
+ return seen;
1532
+ }
1533
+ // What is sent to the place, but for the once-a-second `hub-where`.
1534
+ function townNet(scene, roster, ids, sent = []) {
1535
+ scene.multiplayer.net = { others: () => roster, userId: (id) => ids[id] ?? null, send: (msg) => msg.k !== 'hub-where' && sent.push(msg), selfId: () => 'me' };
1536
+ return sent;
1537
+ }
1538
+ const resetTown = () => {
1539
+ HubState.deck.cues = false;
1540
+ HubState.hub.place = null;
1541
+ HubState.hub.doors = [];
1542
+ HubState.hub.arrivedFacing = null;
1543
+ HubState.hub.jumpedTo = null;
1544
+ HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
1545
+ HubState.hub.saidEvents.length = 0;
1546
+ };
1547
+
1548
+ // The host names a friend only once its heartbeat (about every 15 s) has told
1549
+ // it both players are in the town, so one ask made at first sight comes back
1550
+ // empty. A town driven a quarter second at a time: `script(now, roster, ids)`
1551
+ // changes who is here, `names(now)` is whom the host would name then.
1552
+ // `blocked(now)` is when no ask can be sent (the multiplayer join is pending).
1553
+ async function friendsRun({ cues, until, script = () => {}, names = () => [], roster = new Map(), ids = {}, blocked = () => false }) {
1554
+ const { system, scene } = setup();
1555
+ HubState.deck.cues = cues;
1556
+ HubState.hub.place = { id: 'main', title: 'Town' };
1557
+ const mp = mpStub(scene, 'joined');
1558
+ mp.net = { others: () => roster, userId: (id) => ids[id] ?? null, send() {} };
1559
+ const asks = [];
1560
+ const arrived = [];
1561
+ let n = 0;
1562
+ for (let now = 0; now <= until; now += 250) {
1563
+ script(now, roster, ids);
1564
+ answers.friends = { status: 'ok', friends: names(now) };
1565
+ mp.state = blocked(now) ? 'joining' : 'joined';
1566
+ system.askFriends(scene, mp, now);
1567
+ system.together.frame(mp, system.friendsAll, true, now);
1568
+ for (const who of system.together.arrivals()) {
1569
+ arrived.push([now, who.username, who.here === true]);
1570
+ }
1571
+ const made = calls.filter((c) => c[0] === 'friends').length;
1572
+ if (made > n) {
1573
+ asks.push(now);
1574
+ n = made;
1575
+ }
1576
+ await flush();
1577
+ }
1578
+ return { asks, arrived, system };
1579
+ }
1580
+ const amy = { userId: '104', username: 'amy', here: true };
1581
+ const comes = (at, playerId, name, userId) => (now, roster, ids) => {
1582
+ if (now === at) {
1583
+ roster.set(playerId, name);
1584
+ ids[playerId] = userId;
1585
+ }
1586
+ };
1587
+
1588
+ await test('cues: a friend the host names only once its heartbeat has run is announced on that answer (about 11 s in), not at the 20 s ask; without cues the 20 s cadence alone', async () => {
1589
+ try {
1590
+ // amy comes in at 21 s; the host knows she is here from 31 s.
1591
+ const late = { until: 61000, script: comes(21000, 'p4', 'amy', '104'), names: (now) => (now >= 31000 ? [amy] : []) };
1592
+ const on = await friendsRun({ cues: true, ...late });
1593
+ assert.deepEqual(on.asks, [0, 20000, 22000, 24000, 30000, 36000, 56000], 'asked again 1, 3, 9 and 15 s after she is seen; named on the last');
1594
+ assert.deepEqual(on.arrived, [[36250, 'amy', false]], 'announced on the answer that names her');
1595
+ const off = await friendsRun({ cues: false, ...late });
1596
+ assert.deepEqual(off.asks, [0, 20000, 40000, 60000]);
1597
+ assert.deepEqual(off.arrived, [[40250, 'amy', false]]);
1598
+ assert.equal(off.system.friendsEarlyAt, -Infinity);
1599
+ assert.equal(off.system.together.due([], 99999), false, 'without cues nothing is ever due');
1600
+
1601
+ // The player's own arrival: amy was here already, and it is the player's
1602
+ // presence the host lacks until 10 s in. Those here count from then.
1603
+ const here = { until: 40000, roster: new Map([['p4', 'amy']]), ids: { p4: '104' }, names: (now) => (now >= 10000 ? [amy] : []) };
1604
+ const mine = await friendsRun({ cues: true, ...here });
1605
+ assert.deepEqual(mine.asks, [0, 1000, 3000, 9000, 15000, 35000]);
1606
+ assert.deepEqual(mine.arrived, [[15250, 'amy', true]], 'the friend already here, told once the host names her');
1607
+ const plain = await friendsRun({ cues: false, ...here });
1608
+ assert.deepEqual([plain.asks, plain.arrived], [[0, 20000, 40000], []], 'without cues: the cadence, and one here all along is not announced');
1609
+ } finally {
1610
+ resetTown();
1611
+ }
1612
+ });
1613
+
1614
+ await test('cues: the extra friends asks are bounded: four for someone never named, two in any 8 s however many come in, none once they leave, none without a user id', async () => {
1615
+ try {
1616
+ // A stranger the host never names: four asks, then the 20 s cadence.
1617
+ const never = await friendsRun({ cues: true, until: 80000, script: comes(21000, 'p9', 'zed', '109') });
1618
+ assert.deepEqual(never.asks, [0, 20000, 22000, 24000, 30000, 36000, 56000, 76000]);
1619
+ assert.deepEqual(never.arrived, []);
1620
+
1621
+ // They leave mid-schedule: the asks stop with them.
1622
+ const gone = await friendsRun({
1623
+ cues: true,
1624
+ until: 50000,
1625
+ script: (now, roster, ids) => {
1626
+ comes(21000, 'p9', 'zed', '109')(now, roster, ids);
1627
+ if (now === 28000) {
1628
+ roster.delete('p9');
1629
+ }
1630
+ },
1631
+ });
1632
+ assert.deepEqual(gone.asks, [0, 20000, 22000, 24000, 44000]);
1633
+
1634
+ // A busy town, someone new every second for a minute: two extra asks in
1635
+ // any 8 s at most, 2 s apart, so 16 in a minute at the very most, never an
1636
+ // ask per arrival.
1637
+ const busy = await friendsRun({
1638
+ cues: true,
1639
+ until: 100000,
1640
+ script: (now, roster, ids) => {
1641
+ if (now >= 21000 && now < 81000 && now % 1000 === 0) {
1642
+ roster.set(`s${now}`, 'someone');
1643
+ ids[`s${now}`] = `u${now}`;
1644
+ }
1645
+ },
1646
+ });
1647
+ // (the first two are the cadence's own, at 0 and 20 s)
1648
+ const extra = busy.asks.slice(2);
1649
+ assert.ok(extra.slice(1).every((at, i) => at - extra[i] >= 2000), `never two extra asks inside 2 s: ${busy.asks}`);
1650
+ assert.ok(extra.slice(2).every((at, i) => at - extra[i] >= 8000), `never three extra asks inside 8 s: ${busy.asks}`);
1651
+ assert.ok(extra[0] - busy.asks[1] >= 1000, 'nor one on the heels of the cadence');
1652
+ assert.ok(busy.asks.filter((at) => at >= 21000 && at < 81000).length <= 16, `at most 16 in the minute: ${busy.asks}`);
1653
+ assert.ok(busy.asks.filter((at) => at >= 21000 && at < 81000).length >= 12, 'and it does keep asking through it');
1654
+
1655
+ // Seen just before the cadence's own ask: the extra one keeps 1 s clear of it.
1656
+ const heels = await friendsRun({ cues: true, until: 30000, script: comes(19500, 'p9', 'zed', '109') });
1657
+ assert.deepEqual(heels.asks, [0, 20000, 21000, 23000, 29000], `${heels.asks}`);
1658
+ // Seen a little earlier, the extra ask comes first and is the cadence's
1659
+ // own too: the next of those is 20 s after it, never on its heels.
1660
+ const first = await friendsRun({ cues: true, until: 30000, script: comes(18250, 'p9', 'zed', '109') });
1661
+ assert.deepEqual(first.asks, [0, 19250, 21250, 27250], `${first.asks}`);
1662
+
1663
+ // An ask that cannot be sent (a trip, a join pending) spends nothing: the
1664
+ // bounds are counted from the asks really made. Blocked from 1 to 4.5 s
1665
+ // with a stranger here from the start (the review's case), then for a
1666
+ // stretch in the middle of a later schedule.
1667
+ const spaced = (asks, regular) => {
1668
+ const extra = asks.filter((at) => !regular.includes(at));
1669
+ assert.ok(extra.slice(1).every((at, i) => at - extra[i] >= 2000), `two extra asks inside 2 s: ${asks}`);
1670
+ assert.ok(extra.slice(2).every((at, i) => at - extra[i] >= 8000), `three extra asks inside 8 s: ${asks}`);
1671
+ assert.ok(asks.slice(1).every((at, i) => at - asks[i] >= 1000), `two asks inside 1 s: ${asks}`);
1672
+ };
1673
+ const held = await friendsRun({ cues: true, until: 40000, roster: new Map([['p9', 'zed']]), ids: { p9: '109' }, blocked: (now) => now >= 1000 && now < 4500 });
1674
+ assert.deepEqual(held.asks, [0, 4500, 9000, 15000, 35000], `${held.asks}`);
1675
+ spaced(held.asks, [0, 35000]);
1676
+ const mid = await friendsRun({ cues: true, until: 62000, script: comes(21000, 'p9', 'zed', '109'), blocked: (now) => now >= 24000 && now < 33500 });
1677
+ assert.deepEqual(mid.asks, [0, 20000, 22000, 33500, 36000, 56000], `the steps missed are not owed: ${mid.asks}`);
1678
+ spaced(mid.asks, [0, 20000, 56000]);
1679
+ const off = await friendsRun({ cues: false, until: 45000, roster: new Map([['p9', 'zed']]), ids: { p9: '109' }, blocked: (now) => now >= 19000 && now < 22500 });
1680
+ assert.deepEqual(off.asks, [0, 22500, 42500], 'without cues: the cadence, late by the block, as it always was');
1681
+
1682
+ // Never while an ask is out, and no ask for a player with no user id.
1683
+ const guest = await friendsRun({ cues: true, until: 45000, script: (now, roster) => now === 21000 && roster.set('g1', 'guest') });
1684
+ assert.deepEqual(guest.asks, [0, 20000, 40000]);
1685
+ const { system, scene } = setup();
1686
+ HubState.deck.cues = true;
1687
+ HubState.hub.place = { id: 'main', title: 'Town' };
1688
+ const mp = mpStub(scene, 'joined');
1689
+ mp.net = { others: () => new Map([['p9', 'zed']]), userId: () => '109', send() {} };
1690
+ answers.friends = { status: 'ok', friends: [] };
1691
+ for (let now = 0; now <= 30000; now += 250) {
1692
+ system.askFriends(scene, mp, now);
1693
+ system.together.frame(mp, system.friendsAll, true, now);
1694
+ }
1695
+ assert.equal(calls.filter((c) => c[0] === 'friends').length, 1, 'the first ask never landed: nothing more is asked');
1696
+ await flush();
1697
+ } finally {
1698
+ resetTown();
1699
+ }
1700
+ });
1701
+
1702
+ await test('cues: a friend already here is told once the host names them, once, pointed to, never over another toast or "You\'re next to"; without cues not at all', async () => {
1703
+ const friends = [{ userId: '104', username: 'amy', here: true }];
1704
+ const boot = (cues) => {
1705
+ const { system, scene } = setup();
1706
+ HubState.deck.cues = cues;
1707
+ HubState.hub.place = { title: 'Town', result: null };
1708
+ HubState.hub.arrivedFacing = 0;
1709
+ const seen = cueChrome(system);
1710
+ const sent = townNet(scene, new Map([['p2', 'bo'], ['p4', 'amy']]), { p2: '102', p4: '104' });
1711
+ const pings = [];
1712
+ const ping = system.together.ping;
1713
+ system.together.ping = (...args) => (pings.push(args), ping(...args));
1714
+ const local = { components: { Transform: { x: 0, y: 1, z: 9 } } };
1715
+ const step = (now, list) => {
1716
+ system.together.frame(scene.multiplayer, list, true, now);
1717
+ system.drawChrome(scene, local, now);
1718
+ };
1719
+ return { system, scene, seen, sent, pings, step };
1720
+ };
1721
+ try {
1722
+ for (const cues of [true, false]) {
1723
+ // Came in by a door (no start beside a friend): amy was here already.
1724
+ const b = boot(cues);
1725
+ b.step(1000, null);
1726
+ assert.equal(b.seen.toast, '', 'the host has not said who the friends are');
1727
+ b.step(3000, friends);
1728
+ assert.equal(b.seen.toast, cues ? 'amy is here · People to join' : '', `cues ${cues}`);
1729
+ assert.deepEqual(b.pings, cues ? [['p4', 3000, true]] : []);
1730
+ // Once: not again while she stays, however often the host answers.
1731
+ b.system.toast = { text: '', until: 0 };
1732
+ b.step(9000, friends);
1733
+ b.step(30000, [...friends]);
1734
+ assert.equal(b.seen.toast, '');
1735
+ assert.equal(b.pings.length, cues ? 1 : 0);
1736
+ // bo is no friend: never told.
1737
+ assert.ok(!b.pings.some(([id]) => id === 'p2'));
1738
+ }
1739
+
1740
+ // Another toast is up (the result line of the game just left): it waits.
1741
+ const waits = boot(true);
1742
+ waits.system.toast = { text: 'Back from Foot Race', until: 5000 };
1743
+ waits.step(3000, friends);
1744
+ waits.step(4900, friends);
1745
+ assert.deepEqual([waits.seen.toast, waits.pings], ['Back from Foot Race', []]);
1746
+ waits.step(5100, friends);
1747
+ assert.equal(waits.seen.toast, 'amy is here · People to join');
1748
+
1749
+ // Walked in, and put beside her: "You're next to amy" says it, and "is here" never follows.
1750
+ const beside = boot(true);
1751
+ beside.system.startNear = { until: 12000, at: null, asked: false };
1752
+ beside.step(1000, null);
1753
+ beside.step(3000, friends);
1754
+ assert.deepEqual(beside.sent.filter((m) => m.k === 'hub-goto'), [{ k: 'hub-goto', player: 'p4' }]);
1755
+ assert.equal(beside.seen.toast, '');
1756
+ HubState.hub.jumpedTo = 'p4';
1757
+ beside.step(3300, friends);
1758
+ assert.equal(beside.seen.toast, "You're next to amy");
1759
+ beside.system.toast = { text: '', until: 0 };
1760
+ beside.step(8000, friends);
1761
+ beside.step(20000, friends);
1762
+ assert.deepEqual([beside.seen.toast, beside.pings], ['', []]);
1763
+
1764
+ // She left while another toast was up: nothing is said of someone not here.
1765
+ for (const gone of ['left', 'unfriended']) {
1766
+ const b = boot(true);
1767
+ b.system.toast = { text: 'Back from Foot Race', until: 5000 };
1768
+ b.step(3000, friends);
1769
+ assert.equal(b.system.hereCues.length, 1, 'queued behind the toast');
1770
+ if (gone === 'left') {
1771
+ b.scene.multiplayer.net.others = () => new Map([['p2', 'bo']]);
1772
+ }
1773
+ b.step(4000, gone === 'left' ? friends : []);
1774
+ b.step(5100, gone === 'left' ? friends : []);
1775
+ b.step(9000, gone === 'left' ? friends : []);
1776
+ assert.deepEqual([b.seen.toast, b.pings, b.system.hereCues], ['', [], []], gone);
1777
+ }
1778
+
1779
+ // Walked in, the place never answered the start beside her: told when that gives up.
1780
+ const lost = boot(true);
1781
+ lost.system.startNear = { until: 12000, at: null, asked: false };
1782
+ lost.step(1000, null);
1783
+ lost.step(3000, friends);
1784
+ lost.step(11000, friends);
1785
+ assert.equal(lost.seen.toast, '');
1786
+ lost.step(12100, friends);
1787
+ assert.equal(lost.seen.toast, 'amy is here · People to join');
1788
+ } finally {
1789
+ resetTown();
1790
+ }
1791
+ });
1792
+
1793
+ await test('cues (v1.29): back from a game the same game is offered again, with the party when there is one; without cues nothing is asked', async () => {
1794
+ try {
1795
+ for (const cues of [true, false]) {
1796
+ const { system, scene } = setup();
1797
+ HubState.deck.cues = cues;
1798
+ HubState.hub.place = { title: 'Town', result: null };
1799
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }, { id: 'solo', title: 'Summit Sprint', solo: true }];
1800
+ const seen = cueChrome(system);
1801
+ system.chrome.setCover = () => {};
1802
+ const sent = townNet(scene, new Map([['p2', 'bo']]), { p2: '102' });
1803
+ const back = (door, returning = true) => {
1804
+ scene.persistent.hubResult = { title: 'Foot Race', outcome: 'win' };
1805
+ const at = performance.now();
1806
+ system.finishTrip(scene, { n: 1, startedAt: at, marks: { covered: at, arrived: at, firstFrame: at, revealed: at }, target: { arrive: { door, party: 1, returning } } });
1807
+ system.drawChrome(scene, null, performance.now());
1808
+ };
1809
+ back('race');
1810
+ if (!cues) {
1811
+ assert.deepEqual([system.againAsk, seen.ask], [null, null]);
1812
+ continue;
1813
+ }
1814
+ assert.deepEqual([seen.ask.kind, seen.ask.text, seen.ask.yes, seen.ask.no], ['again', 'Play Foot Race again?', 'Play again', 'Not now']);
1815
+ // Not now: gone, and not put again.
1816
+ system.answer(scene, seen.ask, false);
1817
+ system.drawChrome(scene, null, performance.now());
1818
+ assert.deepEqual([seen.ask, sent], [null, []]);
1819
+ // Play again, alone: onto the pad.
1820
+ back('race');
1821
+ system.jumpSentAt = -Infinity;
1822
+ system.answer(scene, seen.ask, true);
1823
+ assert.deepEqual(sent.splice(0), [{ k: 'hub-door-jump', door: 'race' }]);
1824
+ assert.equal(system.againAsk, null);
1825
+ // In a party: the Doors list's Go together, which asks the party.
1826
+ HubState.hub.party = { members: ['p2'], away: 0, invite: null, proposal: null };
1827
+ back('race');
1828
+ assert.deepEqual([seen.ask.text, seen.ask.yes], ['Play Foot Race again together?', 'Go together']);
1829
+ system.answer(scene, seen.ask, true);
1830
+ assert.deepEqual(sent.splice(0), [{ k: 'hub-party', op: 'go', door: 'race' }]);
1831
+ // A solo game is never "together".
1832
+ back('solo');
1833
+ assert.deepEqual([seen.ask.text, seen.ask.yes], ['Play Summit Sprint again?', 'Play again']);
1834
+ // An invitation or a party's proposal is asked first.
1835
+ HubState.hub.party = { members: null, away: 0, invite: { from: 'p2', username: 'bo' }, proposal: null };
1836
+ system.drawChrome(scene, null, performance.now());
1837
+ assert.equal(seen.ask.kind, 'invite');
1838
+ HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
1839
+ // A door the town no longer has, an arrival that is not a return, and
1840
+ // an offer whose time is up: nothing.
1841
+ back('gone');
1842
+ assert.equal(seen.ask, null);
1843
+ system.againAsk = null;
1844
+ back('race', false);
1845
+ assert.deepEqual([system.againAsk, seen.ask], [null, null]);
1846
+ // An answer to an offer that is no longer the one up does nothing: its
1847
+ // time ran out, or a later return replaced it.
1848
+ back('race');
1849
+ const old = seen.ask;
1850
+ back('solo');
1851
+ system.jumpSentAt = -Infinity;
1852
+ system.answer(scene, old, true);
1853
+ assert.deepEqual([sent.splice(0), system.againAsk?.door], [[], 'solo']);
1854
+ const late = seen.ask;
1855
+ system.againAsk.until = performance.now() - 1;
1856
+ system.drawChrome(scene, null, performance.now());
1857
+ assert.equal(seen.ask, null);
1858
+ system.answer(scene, late, true);
1859
+ assert.deepEqual(sent.splice(0), []);
1860
+ // Back with no result to tell (Back before the game ended): still asked.
1861
+ scene.persistent.hubResult = null;
1862
+ const at = performance.now();
1863
+ system.finishTrip(scene, { n: 1, startedAt: at, marks: { covered: at, arrived: at, firstFrame: at, revealed: at }, target: { arrive: { door: 'race', party: 1, returning: true } } });
1864
+ system.drawChrome(scene, null, performance.now());
1865
+ assert.equal(seen.ask.text, 'Play Foot Race again?');
1866
+ }
1867
+ } finally {
1868
+ delete globalThis.__hubTrips;
1869
+ resetTown();
1870
+ }
1871
+ });
1872
+
1873
+ await test('cues: the chat field says who reads it or why it is off, and chat peers are asked for when someone comes in; without cues the chat part is what it was', async () => {
1874
+ try {
1875
+ for (const cues of [true, false]) {
1876
+ const { system, scene } = setup();
1877
+ HubState.deck.cues = cues;
1878
+ HubState.hub.place = { title: 'Town', result: null };
1879
+ const seen = cueChrome(system);
1880
+ const roster = new Map([['p2', 'bo'], ['p4', 'amy']]);
1881
+ townNet(scene, roster, { p2: '102', p4: '104' });
1882
+ const soon = [];
1883
+ const chat = { canChat: true, peers: ['104'], incoming: [], available: () => true, frame() {}, soon: (now) => soon.push(now) };
1884
+ system.chat = chat;
1885
+ const hint = (placeholder, label) => (cues ? { placeholder, label } : {});
1886
+ system.drawChrome(scene, null, 1000);
1887
+ assert.deepEqual(seen.say.chat, { input: true, note: 'Chat reaches amy', ...hint('To your follows…', 'Message · only players you follow each other with') });
1888
+ chat.peers = [];
1889
+ system.drawChrome(scene, null, 1100);
1890
+ // v1.29: with cues, one field and one sentence whatever the reason, so
1891
+ // neither tells which it is; without, the notes are what they were.
1892
+ const why = 'Typed chat is for friends who follow each other. Emotes work with everyone.';
1893
+ const nobody = 'Chat is for players who follow each other. None of yours are here now · the phrases above reach everyone.';
1894
+ assert.deepEqual(seen.say.chat, cues ? { input: false, note: why, placeholder: 'Friends only', label: why } : { input: false, note: nobody });
1895
+ chat.canChat = false;
1896
+ system.drawChrome(scene, null, 1200);
1897
+ const off = "Chat isn't available on this account";
1898
+ assert.deepEqual(seen.say.chat, cues ? { input: false, note: why, placeholder: 'Friends only', label: why } : { input: false, note: off });
1899
+ assert.ok(['To your follows…', 'Friends only'].every((text) => text.length <= 20), 'fits the field');
1900
+ assert.ok(!/\b(age|old|13|young|adult|child|kid)/i.test(why), 'never an age');
1901
+
1902
+ // The roster: everyone at the first frame, then only someone new.
1903
+ assert.deepEqual(soon, cues ? [1000] : []);
1904
+ roster.set('p9', 'zed');
1905
+ system.drawChrome(scene, null, 2000);
1906
+ system.drawChrome(scene, null, 2100);
1907
+ roster.delete('p2');
1908
+ system.drawChrome(scene, null, 2200);
1909
+ assert.deepEqual(soon, cues ? [1000, 2000] : [], `cues ${cues}`);
1910
+
1911
+ // A game behind one of the town's doors is drawn by the town's client:
1912
+ // its chat is left exactly as it was, cues or not.
1913
+ HubState.hub.place = { title: 'Foot Race', result: { outcomes: ['win'] } };
1914
+ chat.canChat = true;
1915
+ chat.peers = ['104'];
1916
+ roster.set('p7', 'eve');
1917
+ system.drawChrome(scene, null, 3000);
1918
+ assert.deepEqual(seen.say.chat, { input: true, note: 'Chat reaches amy' });
1919
+ assert.deepEqual(soon, cues ? [1000, 2000] : []);
1920
+ }
1921
+ } finally {
1922
+ resetTown();
1923
+ }
1924
+ });
1925
+
1926
+ // A phrase id the kit does not have.
1927
+ const GONE = 'join';
1928
+ await test('Doors > Go sends what it always did, cues or not: a jump alone, a proposal to a party here, a jump to a solo door; an unknown phrase heard is nothing', async () => {
1929
+ const friends = [{ userId: '104', username: 'amy', here: true }];
1930
+ try {
1931
+ for (const cues of [true, false]) {
1932
+ const { system, scene } = setup();
1933
+ HubState.deck.cues = cues;
1934
+ HubState.hub.place = { title: 'Town', result: null };
1935
+ HubState.hub.doors = [{ id: 'race', title: 'Foot Race' }, { id: 'summit', title: 'Summit Sprint', solo: true }];
1936
+ const seen = cueChrome(system);
1937
+ const sent = townNet(scene, new Map([['p2', 'bo'], ['p4', 'amy']]), { p2: '102', p4: '104' });
1938
+ HubState.hub.party = { members: null, away: 0, invite: null, proposal: null };
1939
+ system.together.frame(scene.multiplayer, friends, true, 1000);
1940
+ system.goDoor(scene, { id: 'race', title: 'Foot Race' });
1941
+ HubState.hub.party = { members: ['p2'], away: 0, invite: null, proposal: null };
1942
+ system.goDoor(scene, { id: 'race', title: 'Foot Race' });
1943
+ system.jumpSentAt = -Infinity;
1944
+ system.goDoor(scene, { id: 'summit', title: 'Summit Sprint', solo: true });
1945
+ assert.deepEqual(sent, [{ k: 'hub-door-jump', door: 'race' }, { k: 'hub-party', op: 'go', door: 'race' }, { k: 'hub-door-jump', door: 'summit' }], `cues ${cues}`);
1946
+ system.toast = { text: '', until: 0 };
1947
+ HubState.hub.saidEvents.push({ k: 'hub-said', player: 'p2', p: GONE, door: 'race' }, { k: 'hub-said', player: 'p4', p: GONE, door: 'race' });
1948
+ system.drawChrome(scene, null, performance.now());
1949
+ system.drawChrome(scene, null, performance.now());
1950
+ assert.deepEqual([seen.ask, system.say.feed()], [null, []]);
1951
+ }
1952
+ } finally {
1953
+ resetTown();
1954
+ }
1955
+ });
1956
+
1957
+ await test('cues: a party that gains a member says so; not the party a session is first told of, not a member back from a game; without cues nothing', async () => {
1958
+ const set = (members, away = 0, invite = null) => {
1959
+ HubState.hub.party = { members, away, invite, proposal: null };
1960
+ };
1961
+ try {
1962
+ for (const cues of [true, false]) {
1963
+ const { system, scene } = setup();
1964
+ HubState.deck.cues = cues;
1965
+ HubState.hub.place = { title: 'Town', result: null };
1966
+ const seen = cueChrome(system);
1967
+ const roster = new Map([['p2', 'bo'], ['p4', 'amy'], ['p9', 'zed']]);
1968
+ const sent = townNet(scene, roster, { p2: '102', p4: '104', p9: '109' });
1969
+ let now = performance.now();
1970
+ const draw = () => {
1971
+ now += 100;
1972
+ system.toast = { text: '', until: 0 };
1973
+ system.drawChrome(scene, null, now);
1974
+ return seen.toast;
1975
+ };
1976
+ const say = (text) => (cues ? text : '');
1977
+
1978
+ // The first word of a session is the party the player already had.
1979
+ set(['p2']);
1980
+ assert.equal(draw(), '', 'the first snapshot');
1981
+ set(['p2', 'p4']);
1982
+ assert.equal(draw(), say('amy joined your party'), `cues ${cues}`);
1983
+ assert.equal(draw(), '', 'once');
1984
+ // A member away in a game, and back (a new player id): no news.
1985
+ set(['p2'], 1);
1986
+ assert.equal(draw(), '');
1987
+ roster.set('p4b', 'amy');
1988
+ set(['p2', 'p4b'], 0);
1989
+ assert.equal(draw(), '', 'back from a game');
1990
+ set(null);
1991
+ assert.equal(draw(), '');
1992
+
1993
+ // Accepting an invitation: the player joined theirs.
1994
+ set(null, 0, { from: 'p2', username: 'bo' });
1995
+ assert.equal(draw(), '');
1996
+ assert.equal(seen.ask.text, 'bo invited you to their party');
1997
+ system.answer(scene, seen.ask, true);
1998
+ assert.deepEqual(sent.at(-1), { k: 'hub-party', op: 'accept', from: 'p2' });
1999
+ assert.equal(system.partyAccepted === null, !cues);
2000
+ set(['p2', 'p9']);
2001
+ assert.equal(draw(), say("You joined bo's party"));
2002
+ set(null);
2003
+ draw();
2004
+ // Someone accepted this player's: they joined.
2005
+ set(['p9']);
2006
+ assert.equal(draw(), say('zed joined your party'));
2007
+ set(null);
2008
+ draw();
2009
+
2010
+ // Inside a session's first moments, and for a party carried through a
2011
+ // door, the first members told are the ones the player had.
2012
+ system.partySettleUntil = now + 5000;
2013
+ set(['p2']);
2014
+ assert.equal(draw(), '', 'the first moments');
2015
+ set(null);
2016
+ now += 6000;
2017
+ draw();
2018
+ system.partyCarryUntil = now + 30000;
2019
+ set(['p2']);
2020
+ assert.equal(draw(), '', 'the party carried in');
2021
+ set(['p2', 'p9']);
2022
+ assert.equal(draw(), say('zed joined your party'), 'and a join after it is news');
2023
+ }
2024
+ } finally {
2025
+ resetTown();
2026
+ }
2027
+ });
2028
+
1308
2029
  console.warn = warn;
1309
2030
  console.log = log;
1310
2031
  console.log(`hub trips: ${n} tests passed`);