castle-web-cli 0.4.231 → 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/serverBundle.js +5 -3
- package/kits/hub-game/CLAUDE.md +26 -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 +194 -4
- package/kits/hub-game/code/client/grab.js +31 -7
- package/kits/hub-game/code/client/hats.js +26 -0
- package/kits/hub-game/code/client/hookLayer.js +30 -3
- package/kits/hub-game/code/client/hudClear.js +126 -0
- package/kits/hub-game/code/client/state.js +22 -0
- package/kits/hub-game/code/client/tiers.js +31 -6
- package/kits/hub-game/code/client/together.js +66 -1
- 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 +296 -11
- package/kits/hub-game/code/server/hub.js +63 -2
- package/kits/hub-game/code/server/manifest.js +48 -3
- package/kits/hub-game/code/server/party.js +11 -0
- 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 +253 -5
- package/kits/hub-game/docs/contract.md +204 -8
- 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 +186 -3
- 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 +513 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
- package/kits/hub-game/scripts/test-manifest.mjs +75 -0
- package/kits/hub-game/scripts/test-party.mjs +22 -1
- package/kits/hub-game/scripts/test-say.mjs +59 -2
- package/kits/hub-game/scripts/test-tiers.mjs +190 -2
- package/kits/hub-game/scripts/test-try-on.mjs +940 -0
- package/kits/physics-2d/castle.json +1 -1
- package/kits/physics-2d/engine/scene.js +35 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +44 -0
- package/kits/physics-3d/CLAUDE.md +252 -0
- package/kits/physics-3d/behaviors/Player.jsx +363 -2
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/docs/pxmodel-format.md +4 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -0
- package/kits/physics-3d/engine3d/optimize.js +49 -0
- package/kits/physics-3d/engine3d/orbitinput.js +277 -0
- package/kits/physics-3d/engine3d/world3d.js +81 -25
- 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 +12 -2
- 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-static-actors.mjs +6 -1
- package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
- package/kits/physics-3d/scripts/test-steady-hover.mjs +633 -0
- package/kits/physics-3d/systems/physics3d.js +91 -6
- package/package.json +1 -1
|
@@ -1513,6 +1513,519 @@ await test('start next to a friend: once, on walking in, when a friend is here a
|
|
|
1513
1513
|
HubState.hub.jumpedTo = null;
|
|
1514
1514
|
});
|
|
1515
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
|
+
|
|
1516
2029
|
console.warn = warn;
|
|
1517
2030
|
console.log = log;
|
|
1518
2031
|
console.log(`hub trips: ${n} tests passed`);
|