castle-web-cli 0.4.230 → 0.4.231

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) 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/kits/base/castle.json +1 -1
  11. package/kits/base/sdk/README.md +148 -1
  12. package/kits/base/sdk/castle.d.ts +4 -0
  13. package/kits/base/sdk/castle.js +2 -0
  14. package/kits/base/sdk/commands.d.ts +15 -0
  15. package/kits/base/sdk/multiplayer.js +52 -4
  16. package/kits/base/sdk/save.d.ts +197 -0
  17. package/kits/base/sdk/save.js +525 -0
  18. package/kits/base/sdk/saveCoordinator.d.ts +39 -0
  19. package/kits/base/sdk/saveCoordinator.js +252 -0
  20. package/kits/base/sdk/server/storage.d.ts +3 -2
  21. package/kits/base/sdk/server/storage.js +25 -5
  22. package/kits/base/sdk/server/wrapper.d.ts +4 -0
  23. package/kits/base/sdk/server/wrapper.js +2 -0
  24. package/kits/base/sdk/store.d.ts +3 -2
  25. package/kits/base/sdk/store.js +5 -0
  26. package/kits/hub-game/CLAUDE.md +4 -1
  27. package/kits/hub-game/code/client/chrome.js +43 -9
  28. package/kits/hub-game/code/client/grab.js +142 -7
  29. package/kits/hub-game/code/client/hookLayer.js +7 -1
  30. package/kits/hub-game/code/client/state.js +13 -1
  31. package/kits/hub-game/code/client/talk.js +10 -36
  32. package/kits/hub-game/code/client/tiers.js +480 -0
  33. package/kits/hub-game/code/client/together.js +78 -3
  34. package/kits/hub-game/code/server/grab.js +3 -2
  35. package/kits/hub-game/code/server/hub.js +99 -5
  36. package/kits/hub-game/code/server/manifest.js +34 -7
  37. package/kits/hub-game/code/server/npcs.js +21 -33
  38. package/kits/hub-game/code/server/party.js +64 -6
  39. package/kits/hub-game/code/systems/hub.js +133 -16
  40. package/kits/hub-game/docs/contract.md +84 -14
  41. package/kits/hub-game/package.json +1 -1
  42. package/kits/hub-game/scripts/test-grab-client.mjs +328 -0
  43. package/kits/hub-game/scripts/test-hub-trip.mjs +208 -0
  44. package/kits/hub-game/scripts/test-manifest.mjs +47 -1
  45. package/kits/hub-game/scripts/test-npcs.mjs +34 -24
  46. package/kits/hub-game/scripts/test-party.mjs +87 -4
  47. package/kits/hub-game/scripts/test-tiers.mjs +666 -0
  48. package/kits/hub-game/scripts/test-together.mjs +33 -1
  49. package/kits/physics-2d/CLAUDE.md +2 -0
  50. package/kits/physics-2d/castle.json +2 -2
  51. package/kits/physics-2d/engine/scene.js +92 -0
  52. package/kits/physics-2d/package.json +1 -1
  53. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +254 -0
  54. package/kits/physics-3d/CLAUDE.md +279 -0
  55. package/kits/physics-3d/behaviors/Player.jsx +74 -1
  56. package/kits/physics-3d/castle.json +3 -3
  57. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +1 -1
  58. package/kits/physics-3d/engine3d/actornode.js +253 -0
  59. package/kits/physics-3d/engine3d/nearshadows.js +600 -0
  60. package/kits/physics-3d/engine3d/unchanged.js +153 -0
  61. package/kits/physics-3d/engine3d/world3d.js +465 -7
  62. package/kits/physics-3d/package.json +1 -1
  63. package/kits/physics-3d/scripts/test-camera-follow.mjs +533 -0
  64. package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
  65. package/kits/physics-3d/scripts/test-static-actors.mjs +662 -0
  66. package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
  67. package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
  68. package/kits/physics-3d/systems/physics3d.js +182 -3
  69. package/package.json +1 -1
@@ -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 a near audience', async () => {
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
- t = turn({ speaker: 'a', audience: ['far'] });
210
- await w.npcs.onTurn(t);
211
- assert.equal(t.rejected, 'HUB_NPC_AUDIENCE');
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', audience: ['b'] });
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("a reply is shown to the turn's audience only, once", async () => {
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', audience: ['b'] }));
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
- assert.deepEqual(new Set(w.labels[0].to), new Set(['a', 'b']));
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('blocks: a listener hidden from the speaker is refused, and a reply never reaches one', async () => {
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
- const hidden = turn({ speaker: 'a', audience: ['b'] });
540
- await w.npcs.onTurn(hidden);
541
- assert.equal(hidden.rejected, 'HUB_NPC_AUDIENCE');
542
- assert.equal(hidden.sent, 0);
543
- // Admitted with c alone; a block between a and c before the reply keeps it from c.
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 } 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' });