castle-web-cli 0.4.208 → 0.4.210
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/api.d.ts +5 -0
- package/dist/castle-host/host.js +234 -0
- package/dist/castleJson.d.ts +4 -0
- package/dist/castleJson.js +3 -1
- package/dist/devSessionServer.js +1 -0
- package/dist/editorConfig.d.ts +12 -0
- package/dist/editorConfig.js +72 -6
- package/dist/init.js +1 -1
- package/dist/modulePreload.d.ts +14 -0
- package/dist/modulePreload.js +150 -0
- package/dist/native/loop.js +1 -1
- package/dist/native/playtest-executor.js +36 -4
- package/dist/native/playtest-remote.d.ts +1 -0
- package/dist/native/playtest-remote.js +61 -5
- package/dist/native/playtest.d.ts +35 -2
- package/dist/native/playtest.js +162 -18
- package/dist/platformDoc.d.ts +1 -0
- package/dist/platformDoc.js +24 -3
- package/dist/playUrl.d.ts +3 -0
- package/dist/playUrl.js +12 -0
- package/dist/save-deck.js +1 -0
- package/dist/serve.js +2 -0
- package/dist/shell/assets/{index-b_bebkRb.css → index-BCrgYh76.css} +1 -1
- package/dist/shell/assets/{index-C6SXXPwm.js → index-DzLbNBc7.js} +68 -68
- package/dist/shell/index.html +2 -2
- package/kits/base/CLAUDE.md +1 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +70 -7
- package/kits/base/sdk/castle.d.ts +1 -0
- package/kits/base/sdk/commands.d.ts +78 -0
- package/kits/base/sdk/commands.js +25 -0
- package/kits/base/sdk/multiplayer.d.ts +3 -0
- package/kits/base/sdk/multiplayer.js +13 -0
- package/kits/base/sdk/multiplayerVoice.d.ts +91 -0
- package/kits/base/sdk/multiplayerVoice.js +424 -0
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +15 -1
- package/kits/multiplayer-2d/castle.json +2 -2
- package/kits/multiplayer-2d/code/systems/multiplayer.js +7 -1
- package/kits/multiplayer-3d/castle.json +2 -2
- package/kits/multiplayer-3d/code/systems/multiplayer.js +8 -4
- package/kits/physics-2d/castle.json +1 -1
- package/kits/physics-2d/editors/SceneEditor.jsx +18 -4
- package/kits/physics-2d/systems/media.js +3 -5
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/engine3d/PxModelEditor.jsx +2 -2
- package/kits/physics-3d/engine3d/pxmodel.js +7 -0
- package/kits/real-time/CLAUDE.md +3 -0
- package/kits/real-time/castle.json +1 -1
- package/kits/real-time/code/client/connection.js +17 -2
- package/kits/real-time/code/client/gameHooks.js +5 -0
- package/kits/real-time/code/client/joinOverlay.js +23 -5
- package/kits/real-time/code/client/messages.js +4 -0
- package/kits/real-time/code/server/persist.js +19 -10
- package/kits/real-time/code/server/session.js +19 -0
- package/package.json +2 -2
package/kits/real-time/CLAUDE.md
CHANGED
|
@@ -30,6 +30,9 @@ imports these modules from here directly.
|
|
|
30
30
|
- `restore(sim, saved)` receives the last `save` result before `ready`. Storage
|
|
31
31
|
is keyed by deck, so the deck must be published; `castle-web serve` brokers it
|
|
32
32
|
as the deck's creator.
|
|
33
|
+
- **A failed room read does not start the room.** No hook runs and nothing is
|
|
34
|
+
saved, so the stored room is kept; players see a message to reload. An
|
|
35
|
+
unpublished deck's reads count as empty, not failed.
|
|
33
36
|
- A pose is an opaque array of numbers here, so anything reading inside one takes
|
|
34
37
|
the kit's `code/client/poses.js` as an argument. That is the seam to use when
|
|
35
38
|
something genuinely needs a lower level.
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Multiplayer } from 'castle-web-sdk';
|
|
6
6
|
import * as Messages from './messages.js';
|
|
7
|
+
import { showLoadFailed } from './joinOverlay.js';
|
|
7
8
|
|
|
8
9
|
const SEND_MS = 1000 / Messages.MOVE_HZ;
|
|
9
10
|
|
|
@@ -33,14 +34,28 @@ function makeNet(connection) {
|
|
|
33
34
|
// Join the deck's public session and return the interface its client system
|
|
34
35
|
// uses. The SDK assigns the session and supplies authenticated roster names, so
|
|
35
36
|
// a deck message carries no sender-chosen username.
|
|
36
|
-
|
|
37
|
+
//
|
|
38
|
+
// `onArrival(msg)` sees each message the moment it arrives, before it is
|
|
39
|
+
// queued, and returning true keeps it out of the queue. It runs whether or not
|
|
40
|
+
// frames do: a hidden tab stops `requestAnimationFrame`, so a reply left in the
|
|
41
|
+
// queue would wait until the tab is shown again.
|
|
42
|
+
export async function connectSession({ onLog = () => {}, onArrival = () => false } = {}) {
|
|
37
43
|
const connection = await Multiplayer.join({ mode: 'public' });
|
|
38
44
|
const net = makeNet(connection);
|
|
39
45
|
|
|
40
46
|
// Messages are queued with this page's clock at arrival. The client system
|
|
41
47
|
// drains the queue on its own frame and pairs `localMs` with the message's `t`
|
|
42
48
|
// in `clock.js`.
|
|
43
|
-
connection.onMessage((data) =>
|
|
49
|
+
connection.onMessage((data) => {
|
|
50
|
+
if (data?.k === Messages.UNLOADED) {
|
|
51
|
+
showLoadFailed();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const msg = { ...data, localMs: performance.now() };
|
|
55
|
+
if (!onArrival(msg)) {
|
|
56
|
+
net.inbox.push(msg);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
44
59
|
connection.onRoster(({ players, you }) => {
|
|
45
60
|
// The roster arrives after the connection, so this is the first point at
|
|
46
61
|
// which the local player's own name can be read.
|
|
@@ -18,6 +18,11 @@ const modules = {
|
|
|
18
18
|
// The 2D and 3D multiplayer systems import this value and call the hooks at the
|
|
19
19
|
// stages listed below.
|
|
20
20
|
//
|
|
21
|
+
// arrive(msg, system) a message that is neither STATE nor WORLD,
|
|
22
|
+
// the moment it arrives, with or without
|
|
23
|
+
// frames. Returning true handles it there, and
|
|
24
|
+
// it skips the queue and `message`. It runs
|
|
25
|
+
// outside a frame, so it has no scene
|
|
21
26
|
// message(scene, msg, system) a message that is neither STATE nor WORLD,
|
|
22
27
|
// after the queue is drained
|
|
23
28
|
// state(scene, msg, system) a STATE or WORLD message, after the kit has
|
|
@@ -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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
45
|
-
(card ?? document.body).appendChild(
|
|
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
|
|
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
|
|
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
|
|
101
|
-
|
|
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.
|
|
3
|
+
"version": "0.4.210",
|
|
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": [
|