castle-web-cli 0.4.207 → 0.4.209

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 (55) hide show
  1. package/dist/api.d.ts +5 -0
  2. package/dist/castle-host/host.js +151 -0
  3. package/dist/castleJson.d.ts +4 -0
  4. package/dist/castleJson.js +3 -1
  5. package/dist/devSessionServer.js +1 -0
  6. package/dist/editorConfig.d.ts +12 -0
  7. package/dist/editorConfig.js +72 -6
  8. package/dist/ide.d.ts +18 -0
  9. package/dist/ide.js +44 -1
  10. package/dist/init.js +1 -1
  11. package/dist/native/loop.js +1 -1
  12. package/dist/native/playtest-executor.js +36 -4
  13. package/dist/native/playtest-remote.d.ts +1 -0
  14. package/dist/native/playtest-remote.js +61 -5
  15. package/dist/native/playtest.d.ts +35 -2
  16. package/dist/native/playtest.js +162 -18
  17. package/dist/platformDoc.d.ts +1 -0
  18. package/dist/platformDoc.js +24 -3
  19. package/dist/playUrl.d.ts +3 -0
  20. package/dist/playUrl.js +12 -0
  21. package/dist/save-deck.js +1 -0
  22. package/dist/shell/assets/{index-b_bebkRb.css → index-BCrgYh76.css} +1 -1
  23. package/dist/shell/assets/{index-C6SXXPwm.js → index-DzLbNBc7.js} +68 -68
  24. package/dist/shell/index.html +2 -2
  25. package/kits/base/CLAUDE.md +1 -0
  26. package/kits/base/castle.json +1 -1
  27. package/kits/base/sdk/README.md +70 -7
  28. package/kits/base/sdk/castle.d.ts +1 -0
  29. package/kits/base/sdk/commands.d.ts +48 -0
  30. package/kits/base/sdk/commands.js +25 -0
  31. package/kits/base/sdk/multiplayer.d.ts +3 -0
  32. package/kits/base/sdk/multiplayer.js +13 -0
  33. package/kits/base/sdk/multiplayerVoice.d.ts +67 -0
  34. package/kits/base/sdk/multiplayerVoice.js +309 -0
  35. package/kits/base/sdk/transport.d.ts +2 -1
  36. package/kits/base/sdk/transport.js +15 -1
  37. package/kits/multiplayer-2d/castle.json +2 -2
  38. package/kits/multiplayer-2d/code/systems/multiplayer.js +7 -1
  39. package/kits/multiplayer-3d/castle.json +2 -2
  40. package/kits/multiplayer-3d/code/systems/multiplayer.js +8 -4
  41. package/kits/physics-2d/castle.json +1 -1
  42. package/kits/physics-2d/editors/SceneEditor.jsx +18 -4
  43. package/kits/physics-2d/systems/media.js +3 -5
  44. package/kits/physics-3d/castle.json +2 -2
  45. package/kits/physics-3d/engine3d/PxModelEditor.jsx +2 -2
  46. package/kits/physics-3d/engine3d/pxmodel.js +7 -0
  47. package/kits/real-time/CLAUDE.md +3 -0
  48. package/kits/real-time/castle.json +1 -1
  49. package/kits/real-time/code/client/connection.js +17 -2
  50. package/kits/real-time/code/client/gameHooks.js +5 -0
  51. package/kits/real-time/code/client/joinOverlay.js +23 -5
  52. package/kits/real-time/code/client/messages.js +4 -0
  53. package/kits/real-time/code/server/persist.js +19 -10
  54. package/kits/real-time/code/server/session.js +19 -0
  55. package/package.json +2 -2
@@ -10,6 +10,7 @@
10
10
  // differently and share no HUD.
11
11
 
12
12
  let element = null;
13
+ let failed = null;
13
14
 
14
15
  // Show or hide the overlay. Idempotent; cheap enough to call every frame.
15
16
  export function showJoinOverlay(visible) {
@@ -24,13 +25,27 @@ export function showJoinOverlay(visible) {
24
25
  if (element) {
25
26
  return;
26
27
  }
28
+ element = cover('Joining…');
29
+ }
30
+
31
+ // Cover the card with a message that the room could not be loaded. It stays
32
+ // until the page is reloaded; `showJoinOverlay` does not remove it.
33
+ export function showLoadFailed() {
34
+ if (typeof document === 'undefined' || failed) {
35
+ return;
36
+ }
37
+ failed = cover('This room couldn’t be loaded. Reload the page to try again.');
38
+ }
39
+
40
+ // A new overlay element over the card, or over the page when there is no card.
41
+ function cover(text) {
27
42
  const card = document.querySelector('#castle-card, [data-castle-card]');
28
43
  if (card && getComputedStyle(card).position === 'static') {
29
44
  card.style.position = 'relative';
30
45
  }
31
- element = document.createElement('div');
32
- element.setAttribute('data-castle-join-overlay', '');
33
- element.style.cssText = [
46
+ const overlay = document.createElement('div');
47
+ overlay.setAttribute('data-castle-join-overlay', '');
48
+ overlay.style.cssText = [
34
49
  card ? 'position:absolute' : 'position:fixed',
35
50
  'inset:0',
36
51
  'display:flex',
@@ -39,8 +54,11 @@ export function showJoinOverlay(visible) {
39
54
  'background:#0a0a0a',
40
55
  'color:#fff',
41
56
  'font:500 15px/1.4 system-ui,sans-serif',
57
+ 'padding:16px',
58
+ 'text-align:center',
42
59
  'z-index:2147483646',
43
60
  ].join(';');
44
- element.textContent = 'Joining…';
45
- (card ?? document.body).appendChild(element);
61
+ overlay.textContent = text;
62
+ (card ?? document.body).appendChild(overlay);
63
+ return overlay;
46
64
  }
@@ -19,6 +19,10 @@ export const STATE = 's';
19
19
  // session removes it for everyone, for good.
20
20
  export const GONE = 'g';
21
21
 
22
+ // The room's saved state could not be read, so the session will not start it:
23
+ // `{ k: UNLOADED }`. The page has to be reloaded.
24
+ export const UNLOADED = 'x';
25
+
22
26
  // Movement reports run below the render rate and below the platform's roughly
23
27
  // 30-message-per-second client cap. A second report inside one server tick would
24
28
  // be overwritten before the simulation read it.
@@ -12,18 +12,22 @@
12
12
  // own room; every public shard shares one.
13
13
  //
14
14
  // The server owns `deck` scope once a deck publishes a server. An unpublished
15
- // deck has no storage at all, so a failure is reported and the session runs on
16
- // without persistence.
15
+ // deck has no storage at all, so its reads come back empty and the session runs
16
+ // on without persistence. Any other failed read is not an empty room: a room
17
+ // started from it would save over the real one.
17
18
 
18
19
  // The room a session persists under.
19
20
  export function roomOf(session) {
20
21
  return session.mode === 'public' ? 'public' : session.sessionId;
21
22
  }
22
23
 
23
- // Read one room's world and deck block. A world saved before the gone list
24
- // existed is a bare pose array.
24
+ // Read one room's world and deck block, or null when the read failed. A world
25
+ // saved before the gone list existed is a bare pose array.
25
26
  export async function loadRoom(session, room) {
26
27
  const saved = await read(session, [`world:${room}`, `game:${room}`], 'loadRoom');
28
+ if (!saved) {
29
+ return null;
30
+ }
27
31
  const world = saved[`world:${room}`];
28
32
  return {
29
33
  world: Array.isArray(world) ? { poses: world, gone: [] } : (world ?? null),
@@ -36,7 +40,7 @@ export async function loadRoom(session, room) {
36
40
  export async function loadPlayer(session, room, userId) {
37
41
  const key = playerKey(room, userId);
38
42
  const saved = await read(session, [key], 'loadPlayer');
39
- const row = saved[key];
43
+ const row = saved?.[key];
40
44
  if (Array.isArray(row)) {
41
45
  return { pose: row, state: null };
42
46
  }
@@ -71,12 +75,13 @@ function playerKey(room, userId) {
71
75
  return `player:${room}:${userId}`;
72
76
  }
73
77
 
78
+ // The stored values by key, or null when the read failed.
74
79
  async function read(session, keys, operation) {
75
80
  try {
76
81
  return await session.storage.deck.get(keys);
77
82
  } catch (error) {
78
83
  report(operation, error);
79
- return {};
84
+ return isUnpublished(error) ? {} : null;
80
85
  }
81
86
  }
82
87
 
@@ -97,16 +102,20 @@ let unpublishedStorageAnnounced = false;
97
102
  // once.
98
103
  const reported = new Set();
99
104
 
100
- function report(operation, error) {
101
- if (
105
+ function isUnpublished(error) {
106
+ return (
102
107
  error?.code === 'CAULDRON_STORAGE_UNAVAILABLE' &&
103
108
  String(error?.message ?? '').startsWith('Storage needs a published deck.')
104
- ) {
109
+ );
110
+ }
111
+
112
+ function report(operation, error) {
113
+ if (isUnpublished(error)) {
105
114
  if (!unpublishedStorageAnnounced) {
106
115
  unpublishedStorageAnnounced = true;
107
116
  console.info(
108
117
  '[persist] deck storage is off until the deck is published (save-deck); ' +
109
- 'the room will not persist across serve restarts.'
118
+ 'the room will not persist across serve restarts.',
110
119
  );
111
120
  }
112
121
  return;
@@ -34,6 +34,8 @@ const GHOST_MS = 2000;
34
34
  // and optionally acks
35
35
  // game the deck's hooks, from `gameHooks.js`
36
36
  // sim the simulation, null until it is built
37
+ // unloaded whether the saved room could not be read, which leaves
38
+ // `sim` null for good
37
39
  // building the pending simulation, from `createSimulation`
38
40
  // session the Castle session, from the first callback carrying one
39
41
  // room the storage room this session persists under
@@ -57,6 +59,7 @@ function newServer(parts) {
57
59
  return {
58
60
  ...parts,
59
61
  sim: null,
62
+ unloaded: false,
60
63
  building: null,
61
64
  session: null,
62
65
  room: '',
@@ -100,6 +103,10 @@ export function makeSession(parts) {
100
103
  onPlayerJoin(session, player) {
101
104
  attach(server, session);
102
105
  console.log(`[${server.label}] join ${player.username} (${player.playerId})`);
106
+ if (server.unloaded) {
107
+ session.send(player.playerId, { k: Messages.UNLOADED });
108
+ return;
109
+ }
103
110
 
104
111
  // The saved pose is read now, so the body this player is given on a later
105
112
  // tick can start there.
@@ -146,10 +153,19 @@ function attach(server, session) {
146
153
  // Finish the simulation: read the saved room, run the deck's restore and ready
147
154
  // hooks, and apply the saved object poses. `server.sim` is assigned last, so the
148
155
  // first WORLD snapshot anybody receives is the restored one.
156
+ //
157
+ // A room whose read failed is never started. With no simulation there are no
158
+ // ticks and no saves, so the stored room is left as it was.
149
159
  async function buildWorld(server) {
150
160
  try {
151
161
  const created = await server.building;
152
162
  const saved = await Persist.loadRoom(server.session, server.room);
163
+ if (!saved) {
164
+ server.unloaded = true;
165
+ server.session.broadcast({ k: Messages.UNLOADED });
166
+ console.error(`[${server.label}] room ${server.room} could not be read; it is not started`);
167
+ return;
168
+ }
153
169
  server.game.restore?.(created, saved.game);
154
170
 
155
171
  // Invoke the deck's ready hook with the built world before the first tick.
@@ -178,6 +194,9 @@ async function buildWorld(server) {
178
194
  // Route one client message. Movement reports update the simulation, and other
179
195
  // message kinds go to the deck hook.
180
196
  function receive(server, session, player, data) {
197
+ if (server.unloaded) {
198
+ return;
199
+ }
181
200
  if (data?.k === Messages.GONE) {
182
201
  markGone(server, data.id);
183
202
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.207",
3
+ "version": "0.4.209",
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/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"
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/sdk-readme-limits.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": [