castle-web-cli 0.4.204 → 0.4.206

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 (134) hide show
  1. package/dist/agent-failures.d.ts +3 -1
  2. package/dist/agent-failures.js +19 -0
  3. package/dist/agent-prompts.d.ts +1 -0
  4. package/dist/agent-prompts.js +7 -2
  5. package/dist/agent.d.ts +3 -2
  6. package/dist/agent.js +29 -18
  7. package/dist/castle-host/host.d.ts +17 -0
  8. package/dist/castle-host/host.js +551 -4
  9. package/dist/devSessionStorage.js +65 -4
  10. package/dist/effortSupport.d.ts +7 -0
  11. package/dist/effortSupport.js +31 -0
  12. package/dist/imports.d.ts +1 -1
  13. package/dist/imports.js +59 -19
  14. package/dist/index.js +4 -3
  15. package/dist/init.d.ts +9 -1
  16. package/dist/init.js +64 -25
  17. package/dist/kitCatalog.d.ts +13 -0
  18. package/dist/kitCatalog.js +111 -0
  19. package/dist/platformDoc.js +7 -2
  20. package/dist/serve.js +35 -2
  21. package/dist/shell/assets/{index-DHzA0-Sj.js → index-hWQTC8q6.js} +5 -5
  22. package/dist/shell/index.html +1 -1
  23. package/dist/vitePlugins.js +19 -1
  24. package/kits/base/CLAUDE.md +2 -0
  25. package/kits/base/castle.json +1 -1
  26. package/kits/base/sdk/README.md +131 -0
  27. package/kits/base/sdk/agent.d.ts +6 -0
  28. package/kits/base/sdk/agent.js +70 -0
  29. package/kits/base/sdk/castle.d.ts +4 -0
  30. package/kits/base/sdk/castle.js +2 -0
  31. package/kits/base/sdk/commands.d.ts +106 -0
  32. package/kits/base/sdk/commands.js +21 -0
  33. package/kits/base/sdk/decks.d.ts +7 -0
  34. package/kits/base/sdk/decks.js +31 -0
  35. package/kits/base/sdk/runtime.d.ts +4 -2
  36. package/kits/base/sdk/runtime.js +51 -40
  37. package/kits/base/sdk/server/storage.d.ts +44 -0
  38. package/kits/base/sdk/server/storage.js +54 -0
  39. package/kits/base/sdk/transport.d.ts +5 -1
  40. package/kits/base/sdk/transport.js +106 -23
  41. package/kits/multiplayer-2d/castle.json +5 -4
  42. package/kits/multiplayer-2d/code/client/poses.js +7 -0
  43. package/kits/multiplayer-2d/code/server/limits.js +3 -0
  44. package/kits/multiplayer-2d/code/server/ownership.js +36 -8
  45. package/kits/multiplayer-2d/code/systems/multiplayer.js +23 -2
  46. package/kits/multiplayer-3d/CLAUDE.md +12 -1
  47. package/kits/multiplayer-3d/castle.json +5 -4
  48. package/kits/multiplayer-3d/code/client/avatars.js +7 -1
  49. package/kits/multiplayer-3d/code/client/poses.js +61 -1
  50. package/kits/multiplayer-3d/code/client/steer.js +383 -0
  51. package/kits/multiplayer-3d/code/server/limits.js +3 -0
  52. package/kits/multiplayer-3d/code/server/ownership.js +114 -18
  53. package/kits/multiplayer-3d/code/server/world.js +12 -4
  54. package/kits/multiplayer-3d/code/systems/multiplayer.js +315 -34
  55. package/kits/physics-2d/castle.json +1 -0
  56. package/kits/physics-3d/CLAUDE.md +65 -7
  57. package/kits/physics-3d/castle.json +4 -3
  58. package/kits/physics-3d/docs/pxmodel-format.md +916 -15
  59. package/kits/physics-3d/engine3d/PxModelEditor.jsx +2 -2
  60. package/kits/physics-3d/engine3d/artobjects.js +218 -0
  61. package/kits/physics-3d/engine3d/blob.js +1058 -0
  62. package/kits/physics-3d/engine3d/branches.js +300 -0
  63. package/kits/physics-3d/engine3d/cage.js +496 -0
  64. package/kits/physics-3d/engine3d/cageops.js +516 -0
  65. package/kits/physics-3d/engine3d/frame.js +669 -0
  66. package/kits/physics-3d/engine3d/look.js +675 -0
  67. package/kits/physics-3d/engine3d/materialpresets.js +486 -0
  68. package/kits/physics-3d/engine3d/modelEditorWorld.js +3 -2
  69. package/kits/physics-3d/engine3d/modelrefs.js +120 -0
  70. package/kits/physics-3d/engine3d/motion.js +560 -0
  71. package/kits/physics-3d/engine3d/objtext.js +37 -0
  72. package/kits/physics-3d/engine3d/optimize.js +1083 -0
  73. package/kits/physics-3d/engine3d/paint.js +674 -0
  74. package/kits/physics-3d/engine3d/partgeometry.js +467 -0
  75. package/kits/physics-3d/engine3d/paths.js +324 -0
  76. package/kits/physics-3d/engine3d/pxmodel.js +429 -26
  77. package/kits/physics-3d/engine3d/scatter.js +102 -0
  78. package/kits/physics-3d/engine3d/sculpt.js +1148 -0
  79. package/kits/physics-3d/engine3d/surfacedetail.js +267 -0
  80. package/kits/physics-3d/engine3d/sweep.js +480 -0
  81. package/kits/physics-3d/engine3d/thumbnails.js +6 -4
  82. package/kits/physics-3d/engine3d/world3d.js +119 -17
  83. package/kits/physics-3d/eslint.config.js +13 -0
  84. package/kits/physics-3d/models/parts/axe.pxmodel +40 -0
  85. package/kits/physics-3d/models/parts/backpack.pxmodel +47 -0
  86. package/kits/physics-3d/models/parts/barrel.pxmodel +22 -0
  87. package/kits/physics-3d/models/parts/bedroll.pxmodel +28 -0
  88. package/kits/physics-3d/models/parts/belt-pouch.pxmodel +22 -0
  89. package/kits/physics-3d/models/parts/bolt.pxmodel +10 -0
  90. package/kits/physics-3d/models/parts/bracer.pxmodel +26 -0
  91. package/kits/physics-3d/models/parts/chain-span.pxmodel +12 -0
  92. package/kits/physics-3d/models/parts/chimney.pxmodel +11 -0
  93. package/kits/physics-3d/models/parts/crate.pxmodel +44 -0
  94. package/kits/physics-3d/models/parts/crystal.pxmodel +22 -0
  95. package/kits/physics-3d/models/parts/door-arched.pxmodel +12 -0
  96. package/kits/physics-3d/models/parts/engine-block.pxmodel +39 -0
  97. package/kits/physics-3d/models/parts/exhaust-pipe.pxmodel +30 -0
  98. package/kits/physics-3d/models/parts/fence-span.pxmodel +10 -0
  99. package/kits/physics-3d/models/parts/fender.pxmodel +19 -0
  100. package/kits/physics-3d/models/parts/headlight.pxmodel +24 -0
  101. package/kits/physics-3d/models/parts/hood.pxmodel +17 -0
  102. package/kits/physics-3d/models/parts/horned-helmet.pxmodel +37 -0
  103. package/kits/physics-3d/models/parts/jerry-can.pxmodel +26 -0
  104. package/kits/physics-3d/models/parts/ladder.pxmodel +10 -0
  105. package/kits/physics-3d/models/parts/lamp.pxmodel +20 -0
  106. package/kits/physics-3d/models/parts/lantern.pxmodel +30 -0
  107. package/kits/physics-3d/models/parts/leaf-cluster.pxmodel +21 -0
  108. package/kits/physics-3d/models/parts/offroad-tire.pxmodel +48 -0
  109. package/kits/physics-3d/models/parts/pauldron.pxmodel +26 -0
  110. package/kits/physics-3d/models/parts/rivet.pxmodel +8 -0
  111. package/kits/physics-3d/models/parts/rock.pxmodel +21 -0
  112. package/kits/physics-3d/models/parts/roll-bar-light.pxmodel +26 -0
  113. package/kits/physics-3d/models/parts/round-shield.pxmodel +31 -0
  114. package/kits/physics-3d/models/parts/saddlebag.pxmodel +30 -0
  115. package/kits/physics-3d/models/parts/spoked-wheel.pxmodel +39 -0
  116. package/kits/physics-3d/models/parts/staff.pxmodel +33 -0
  117. package/kits/physics-3d/models/parts/stepping-stones.pxmodel +8 -0
  118. package/kits/physics-3d/models/parts/stone-base.pxmodel +10 -0
  119. package/kits/physics-3d/models/parts/sword.pxmodel +33 -0
  120. package/kits/physics-3d/models/parts/window-lit.pxmodel +13 -0
  121. package/kits/physics-3d/models/parts/wizard-hat.pxmodel +28 -0
  122. package/kits/physics-3d/models/templates/biped-stout.pxmodel +59 -0
  123. package/kits/physics-3d/models/templates/biped-tall.pxmodel +63 -0
  124. package/kits/physics-3d/models/templates/quadruped.pxmodel +52 -0
  125. package/kits/physics-3d/scripts/render/filmstrip.js +217 -0
  126. package/kits/physics-3d/scripts/render/index.html +20 -0
  127. package/kits/physics-3d/scripts/render/sheet.js +411 -0
  128. package/kits/physics-3d/scripts/render.mjs +646 -0
  129. package/kits/real-time/castle.json +2 -2
  130. package/kits/real-time/code/client/ownership.js +14 -4
  131. package/kits/real-time/code/client/smooth.js +2 -2
  132. package/kits/real-time/code/server/session.js +20 -4
  133. package/kits/turn-based/castle.json +1 -0
  134. package/package.json +2 -2
@@ -11,23 +11,29 @@
11
11
  // adding the id on every render frame.
12
12
  const ASK_EVERY_MS = 120;
13
13
 
14
+ // An object this client let go of, or had taken from it, is not asked for again
15
+ // for this long. It matches the server's minimum hold, and it stops an object at
16
+ // the edge of reach going back and forth between claim and release.
17
+ const RECLAIM_MS = 500;
18
+
14
19
  // Create the ownership state one client system keeps. A scene load replaces it,
15
20
  // because actor ids belong to the loaded scene.
16
21
  export function makeOwnership() {
17
22
  return {
18
23
  mine: new Set(), // object ids the server has granted this player
19
24
  asked: new Map(), // id -> when it was last asked for, to space the asks out
25
+ released: new Map(), // id -> when this client last lost it
20
26
  };
21
27
  }
22
28
 
23
29
  // Apply a server handover list. A grant adds the id to `mine`; any other owner
24
30
  // removes it, so this client stops simulating that object on the same frame.
25
- export function applyHandovers(own, handovers, selfId) {
31
+ export function applyHandovers(own, handovers, selfId, now = performance.now()) {
26
32
  for (const [id, playerId] of handovers ?? []) {
27
33
  if (playerId === selfId) {
28
34
  own.mine.add(id);
29
- } else {
30
- own.mine.delete(id);
35
+ } else if (own.mine.delete(id)) {
36
+ own.released.set(id, now);
31
37
  }
32
38
  }
33
39
  }
@@ -52,6 +58,9 @@ export function toClaim(own, objects, me, others, now, reach) {
52
58
  if (now - (own.asked.get(id) ?? -Infinity) < ASK_EVERY_MS) {
53
59
  continue;
54
60
  }
61
+ if (now - (own.released.get(id) ?? -Infinity) < RECLAIM_MS) {
62
+ continue;
63
+ }
55
64
  const distance = reach.distanceBetween(me, at);
56
65
  if (distance > reach.radius) {
57
66
  continue;
@@ -72,7 +81,7 @@ export function toClaim(own, objects, me, others, now, reach) {
72
81
 
73
82
  // Return owned objects that have moved out of reach and remove them from `mine`.
74
83
  // The connection includes these ids in the next rate-limited movement report.
75
- export function toRelease(own, objects, me, reach) {
84
+ export function toRelease(own, objects, me, reach, now = performance.now()) {
76
85
  const ids = [];
77
86
  for (const [id, at] of objects) {
78
87
  if (!own.mine.has(id)) {
@@ -89,6 +98,7 @@ export function toRelease(own, objects, me, reach) {
89
98
  // Stop local simulation as soon as the release is queued for the server.
90
99
  ids.push(id);
91
100
  own.mine.delete(id);
101
+ own.released.set(id, now);
92
102
  }
93
103
  return ids;
94
104
  }
@@ -47,8 +47,8 @@ export function smooth(store, id, target, dt, poses) {
47
47
  }
48
48
 
49
49
  // Drop one displayed pose. The next `smooth` starts from its target. Called when
50
- // a player leaves, or when this client claims an object it had been drawing from
51
- // network samples.
50
+ // a player leaves, or when an object stops being drawn from network samples
51
+ // because this client owns it or simulates it itself.
52
52
  export function forget(store, id) {
53
53
  store.delete(id);
54
54
  }
@@ -30,7 +30,8 @@ const GHOST_MS = 2000;
30
30
  // per-index `epsilonAt` the delta comparison reads
31
31
  // world createSimulation, step, objectPoses, restorePoses
32
32
  // players addPlayer, removePlayer, setPose, playerPoses
33
- // ownership claim, release, setObjectPoses, sweepOwners, ownerships
33
+ // ownership claim, release, setObjectPoses, sweepOwners, ownerships,
34
+ // and optionally acks
34
35
  // game the deck's hooks, from `gameHooks.js`
35
36
  // sim the simulation, null until it is built
36
37
  // building the pending simulation, from `createSimulation`
@@ -50,7 +51,8 @@ const GHOST_MS = 2000;
50
51
  // send only what changed
51
52
  // waitingForWorld players who have joined but have not been sent the world
52
53
  // handovers ownership changes since the last broadcast, as
53
- // [objectId, playerId|0]
54
+ // [objectId, playerId|0, ...], the rest of each row the
55
+ // kit's own
54
56
  function newServer(parts) {
55
57
  return {
56
58
  ...parts,
@@ -245,7 +247,9 @@ function tick(server, session) {
245
247
 
246
248
  // A new player gets the whole world and the current ownerships. Sending the
247
249
  // ownerships with that first snapshot stops the client from simulating an
248
- // object somebody else already holds.
250
+ // object somebody else already holds. The kit's `ownerships` rows may carry
251
+ // more than the owner: the 3D kit sends each object's velocity, epoch and
252
+ // whether it is asleep, so a moving object is still moving on arrival.
249
253
  // A new player also gets every actor that is gone and their own saved block,
250
254
  // which their client restores before it plays.
251
255
  for (const playerId of server.waitingForWorld) {
@@ -468,13 +472,24 @@ function broadcastDelta(server, session, snapshot) {
468
472
  const gone = server.newlyGone;
469
473
  server.newlyGone = [];
470
474
 
475
+ // Acknowledgements of the owners' reports applied since the last broadcast,
476
+ // from a kit that sends them.
477
+ const ack = server.ownership.acks?.(server.sim) ?? [];
478
+
471
479
  // Only a moved pose makes the next save worth making.
472
480
  server.moved = server.moved || ps.length > 0 || os.length > 0;
473
481
 
474
482
  // A changed deck block is its own reason to broadcast, including on a tick
475
483
  // where no pose and no ownership moved.
476
484
  const block = server.game.delta?.(server.sim) ?? null;
477
- if (ps.length === 0 && os.length === 0 && own.length === 0 && gone.length === 0 && !block) {
485
+ if (
486
+ ps.length === 0 &&
487
+ os.length === 0 &&
488
+ own.length === 0 &&
489
+ gone.length === 0 &&
490
+ ack.length === 0 &&
491
+ !block
492
+ ) {
478
493
  return;
479
494
  }
480
495
  session.broadcast({
@@ -484,6 +499,7 @@ function broadcastDelta(server, session, snapshot) {
484
499
  os,
485
500
  own,
486
501
  ...(gone.length ? { gone } : {}),
502
+ ...(ack.length ? { ack } : {}),
487
503
  ...block,
488
504
  });
489
505
  }
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "title": "turn-based",
3
+ "description": "Turn-based. The Scene Editor, with players taking turns and each seeing state only they can see.",
3
4
  "editor": {
4
5
  "defaultPlayFile": "scenes/main.scene"
5
6
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.204",
3
+ "version": "0.4.206",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"
@@ -12,7 +12,7 @@
12
12
  "scripts": {
13
13
  "build": "rm -rf dist && tsc && chmod +x dist/index.js && vite build && cp -R src/castle-host dist/castle-host && chmod -R u+w kits 2>/dev/null; rm -rf kits && cp -R ../kits kits && chmod -R u+w kits && rm -rf kits/*/imports",
14
14
  "dev": "tsc --watch",
15
- "check": "node ../scripts/sync-shared.mjs --check && node ../scripts/tests/icon-registry.mjs && node ../scripts/tests/sandbox-graphql-fields.mjs && node ../scripts/tests/kit-package-json.mjs && node ../scripts/tests/router-fences.mjs && node ../scripts/tests/task-account.mjs && eslint . && jscpd && tsc --noEmit && tsc --noEmit -p src/shell/tsconfig.json"
15
+ "check": "node ../scripts/sync-shared.mjs --check && node ../scripts/tests/icon-registry.mjs && node ../scripts/tests/sandbox-graphql-fields.mjs && node ../scripts/tests/kit-package-json.mjs && node ../scripts/tests/kit-catalog.mjs && node ../scripts/tests/router-fences.mjs && node ../scripts/tests/task-account.mjs && node ../scripts/tests/effort-support.mjs && eslint . && jscpd && tsc --noEmit && tsc --noEmit -p src/shell/tsconfig.json"
16
16
  },
17
17
  "jscpd": {
18
18
  "path": [