castle-web-cli 0.4.193 → 0.4.195
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/agent-prompts.d.ts +1 -0
- package/dist/agent-prompts.js +14 -5
- package/dist/agent.js +101 -4
- package/dist/api.d.ts +1 -0
- package/dist/api.js +5 -0
- package/dist/bundle.js +2 -1
- package/dist/castleJson.d.ts +1 -2
- package/dist/castleJson.js +0 -39
- package/dist/check.js +14 -6
- package/dist/devSessionFrameBudget.d.ts +14 -0
- package/dist/devSessionFrameBudget.js +64 -0
- package/dist/devSessionServer.d.ts +6 -0
- package/dist/devSessionServer.js +38 -1
- package/dist/editorConfig.d.ts +1 -1
- package/dist/editorConfig.js +12 -4
- package/dist/filesChanged.js +7 -3
- package/dist/ide.js +28 -59
- package/dist/importUpdateHook.d.ts +31 -0
- package/dist/importUpdateHook.js +135 -0
- package/dist/importUpdateHookRunner.d.ts +2 -0
- package/dist/importUpdateHookRunner.js +24 -0
- package/dist/imports.js +58 -10
- package/dist/index.js +58 -7
- package/dist/init.d.ts +1 -0
- package/dist/init.js +15 -9
- package/dist/multiplayerDoc.d.ts +1 -0
- package/dist/multiplayerDoc.js +228 -0
- package/dist/native/loop.js +29 -9
- package/dist/platformDoc.d.ts +1 -0
- package/dist/platformDoc.js +25 -6
- package/dist/remix.js +4 -1
- package/dist/scriptErrors.d.ts +23 -0
- package/dist/scriptErrors.js +147 -0
- package/dist/serve.js +366 -36
- package/dist/serverBundle.js +1 -1
- package/dist/shell/assets/index-kMH1qj6D.js +449 -0
- package/dist/shell/index.html +1 -1
- package/dist/versions.d.ts +14 -0
- package/dist/versions.js +21 -0
- package/dist/viteClientStub.d.ts +18 -0
- package/dist/viteClientStub.js +193 -0
- package/dist/vitePlugins.d.ts +1 -0
- package/dist/vitePlugins.js +18 -0
- package/kits/base/CLAUDE.md +3 -3
- package/kits/base/castle.json +1 -3
- package/kits/base/sdk/README.md +17 -0
- package/kits/multiplayer-2d/CLAUDE.md +9 -2
- package/kits/multiplayer-2d/blueprints/crate.scene +32 -4
- package/kits/multiplayer-2d/blueprints/other-player.scene +31 -4
- package/kits/multiplayer-2d/blueprints/player.scene +38 -6
- package/kits/multiplayer-2d/blueprints/wall.scene +25 -3
- package/kits/multiplayer-2d/castle.json +3 -12
- package/kits/multiplayer-2d/test/two-client-test.mjs +4 -4
- package/kits/multiplayer-3d/CLAUDE.md +5 -2
- package/kits/multiplayer-3d/castle.json +3 -11
- package/kits/multiplayer-3d/scenes/main.scene +128 -0
- package/kits/physics-2d/CLAUDE.md +16 -11
- package/kits/physics-2d/behaviors/Camera.jsx +5 -6
- package/kits/physics-2d/behaviors/Goal.jsx +5 -2
- package/kits/physics-2d/behaviors/Joints.jsx +4 -3
- package/kits/physics-2d/behaviors/Layout.jsx +120 -3
- package/kits/physics-2d/behaviors/Sprite.jsx +9 -9
- package/kits/physics-2d/behaviors/Style.jsx +22 -15
- package/kits/physics-2d/behaviors/Text.jsx +7 -6
- package/kits/physics-2d/blueprints/ball.scene +27 -5
- package/kits/physics-2d/blueprints/block.scene +16 -3
- package/kits/physics-2d/blueprints/cauldron.scene +3 -1
- package/kits/physics-2d/blueprints/crate.scene +23 -4
- package/kits/physics-2d/blueprints/goal.scene +12 -2
- package/kits/physics-2d/blueprints/text.scene +13 -3
- package/kits/physics-2d/castle.json +2 -11
- package/kits/physics-2d/editors/SceneEditor.jsx +68 -5
- package/kits/physics-2d/editors/SelectionOverlay.jsx +27 -20
- package/kits/physics-2d/editors/behaviorRegistry.js +8 -2
- package/kits/physics-2d/engine/ErrorOverlay.jsx +69 -0
- package/kits/physics-2d/engine/ScenePlayer.jsx +2 -67
- package/kits/physics-2d/engine/blueprint.js +111 -54
- package/kits/physics-2d/engine/blueprintCore.js +59 -0
- package/kits/physics-2d/engine/collider.js +28 -17
- package/kits/physics-2d/engine/layout.js +61 -0
- package/kits/physics-2d/engine/layoutOriginMigration.js +223 -0
- package/kits/physics-2d/engine/liveReload.js +5 -4
- package/kits/physics-2d/engine/physics/PhysicsSystem.js +11 -7
- package/kits/physics-2d/engine/physics/controls.js +4 -8
- package/kits/physics-2d/engine/physics/matterBridge.js +13 -8
- package/kits/physics-2d/engine/scene.js +38 -34
- package/kits/physics-2d/engine/spriteGeometry.js +17 -9
- package/kits/physics-2d/engine/tap.js +4 -3
- package/kits/physics-2d/scenes/main.scene +59 -6
- package/kits/physics-2d/scenes/sandbox.scene +69 -7
- package/kits/physics-2d/scripts/onUpdate.mjs +199 -0
- package/kits/physics-3d/castle.json +0 -11
- package/kits/real-time/castle.json +2 -8
- package/kits/real-time/code/server/persist.js +14 -0
- package/kits/turn-based/CLAUDE.md +18 -10
- package/kits/turn-based/blueprints/board.scene +3 -1
- package/kits/turn-based/blueprints/square.scene +3 -1
- package/kits/turn-based/castle.json +3 -14
- package/kits/turn-based/code/behaviors/Board.jsx +33 -21
- package/package.json +1 -1
- package/dist/shell/assets/index-ColHKJYj.js +0 -449
|
@@ -13,7 +13,8 @@ This kit adds no engine and no editors. What it holds:
|
|
|
13
13
|
- `room.js` -- the room, and the clock it reads. The part a deck keeps.
|
|
14
14
|
- `code/server/index.js` -- the starter game: two seats claim squares on a
|
|
15
15
|
4x4 board, and the fuller board wins. Rules, not bookkeeping, so a deck
|
|
16
|
-
rewrites this
|
|
16
|
+
rewrites this once on its way to being its own game -- after that the file is
|
|
17
|
+
the creator's, not a starter to go back to.
|
|
17
18
|
- `code/behaviors/Board.jsx`, `Square.jsx`, `scenes/main.scene`,
|
|
18
19
|
`blueprints/`, `drawings/square.sprite` -- that game's client half.
|
|
19
20
|
- `testing.js` -- a `MultiplayerServerSession` double, a movable clock, the room
|
|
@@ -30,17 +31,20 @@ This kit adds no engine and no editors. What it holds:
|
|
|
30
31
|
game to change.
|
|
31
32
|
- **A scaffolded deck is already a playable game.** `castle.json` points
|
|
32
33
|
`server.main` at `imports/castle.turn-based/code/server/index.js` -- two seats
|
|
33
|
-
claiming squares -- and `scenes/main.scene` is its board.
|
|
34
|
-
|
|
34
|
+
claiming squares -- and `scenes/main.scene` is its board. Run
|
|
35
|
+
`castle-web serve`, open the printed shell URL in two tabs, and open the Play
|
|
36
|
+
panel in each before changing anything. If you use `.castle/serve.json`'s
|
|
37
|
+
`contentPlayUrl` directly, open `/index.html?edit=0`; its bare origin is the
|
|
38
|
+
edit surface, where multiplayer does not join.
|
|
35
39
|
- **Making a different game means writing the server.** Add `server/index.js` to
|
|
36
40
|
the deck, point `server.main` at it, and keep the room:
|
|
37
41
|
`createRoom({ seats, idleMs, graceMs })` from
|
|
38
42
|
`@imports/castle.turn-based/room.js`. Copy the kit's server as the starting
|
|
39
43
|
point -- it is the shape a game of this kind has.
|
|
40
|
-
- `room.joinAsync(session, player)`
|
|
41
|
-
`{ table }`. One table per
|
|
42
|
-
the join to use: it reads
|
|
43
|
-
`room.join` cannot.
|
|
44
|
+
- `room.joinAsync(session, player)` returns `{ table }` and
|
|
45
|
+
`room.leave(session, player)` returns `{ table, saved }`. One table per
|
|
46
|
+
`session.sessionId`, made on demand. `joinAsync` is the join to use: it reads
|
|
47
|
+
the saved table first, which the synchronous `room.join` cannot.
|
|
44
48
|
- **A claimed square shows its holder's avatar.** The state carries `users`,
|
|
45
49
|
seat -> userId, and `Board.jsx` swaps the square's `Sprite.file` for the
|
|
46
50
|
avatar from `castle.physics-2d`'s `engine/avatarArt.js`; a holder with no
|
|
@@ -94,8 +98,10 @@ spectators, departures, session freshness. Every number, every rule and every
|
|
|
94
98
|
message is the deck's.
|
|
95
99
|
|
|
96
100
|
The starter game in `code/server/index.js` is a deck's to replace, and replacing
|
|
97
|
-
it is the normal path
|
|
98
|
-
|
|
101
|
+
it is the normal path the FIRST time a deck becomes its own game -- never a way
|
|
102
|
+
to fix or reset a deck that already has one, whose `server/index.js` is the
|
|
103
|
+
creator's work and only ever gets targeted edits: write `server/index.js`, point
|
|
104
|
+
`server.main` at it, and the room stays. It is the shape such a server takes -- rule functions, then the
|
|
99
105
|
session callbacks:
|
|
100
106
|
|
|
101
107
|
```js
|
|
@@ -177,6 +183,7 @@ export default {
|
|
|
177
183
|
deck that has to keep showing a departed player's name for the length of a hand
|
|
178
184
|
copies the name into its own state when it deals.
|
|
179
185
|
- `table.seatNames()` -> `{ [seat]: name | null }`, ready to send.
|
|
186
|
+
- `table.seatUsers()` -> `{ [seat]: userId | null }`, ready to persist or send.
|
|
180
187
|
- `table.spectatorCount(session)` -- people in the session holding no seat.
|
|
181
188
|
- `table.keepAlive()` -- stamp the idle clock and save the table. **Past every
|
|
182
189
|
rejection, never before one.** A rematch is the deck's own
|
|
@@ -265,7 +272,8 @@ is no runner. Run it from the deck directory, with the kit's `testing.js` as the
|
|
|
265
272
|
node --import ./imports/castle.turn-based/testing.js tools/check.mjs
|
|
266
273
|
```
|
|
267
274
|
|
|
268
|
-
Put that in the deck's `package.json` as a `
|
|
275
|
+
Put that in the deck's `package.json` as a `test:room` script; `init` already
|
|
276
|
+
writes `check` for `castle-web check`. Without the `--import`, `node` has
|
|
269
277
|
never heard of `@imports/` and cannot import the very server module the tests
|
|
270
278
|
exist to check.
|
|
271
279
|
|
|
@@ -1,34 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"title": "turn-based",
|
|
3
3
|
"editor": {
|
|
4
|
-
"hiddenPaths": [],
|
|
5
|
-
"visiblePaths": [
|
|
6
|
-
"code/**",
|
|
7
|
-
"room.js",
|
|
8
|
-
"testing.js",
|
|
9
|
-
"scenes/**",
|
|
10
|
-
"blueprints/**",
|
|
11
|
-
"drawings/**",
|
|
12
|
-
"theme.style",
|
|
13
|
-
"fonts.generated.js"
|
|
14
|
-
],
|
|
15
4
|
"defaultPlayFile": "scenes/main.scene"
|
|
16
5
|
},
|
|
17
6
|
"imports": {
|
|
18
7
|
"castle.physics-2d": {
|
|
19
8
|
"deckId": "ckRZGFW4iPrx",
|
|
20
|
-
"version": "2026-09-
|
|
9
|
+
"version": "2026-09-16T21:17:53.144Z"
|
|
21
10
|
},
|
|
22
11
|
"castle.base": {
|
|
23
12
|
"deckId": "yRcmH4_aYllE",
|
|
24
|
-
"version": "2026-09-
|
|
13
|
+
"version": "2026-09-11T20:21:04.335Z"
|
|
25
14
|
}
|
|
26
15
|
},
|
|
27
16
|
"main": "main.jsx",
|
|
28
17
|
"autoUpdateWhenImported": true,
|
|
29
18
|
"deckId": "K6-Xs7dCoMVi",
|
|
30
19
|
"cardId": "Kh_08IYATpC3",
|
|
31
|
-
"publishedVersion": "2026-09-
|
|
20
|
+
"publishedVersion": "2026-09-17T20:55:48.861Z",
|
|
32
21
|
"server": {
|
|
33
22
|
"main": "code/server/index.js",
|
|
34
23
|
"maxPlayers": 8,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Client behavior for the starter claim-squares game.
|
|
2
|
-
// Board supplies the scene update and
|
|
3
|
-
// multiplayer session, send square claims, tint actors and format status text.
|
|
2
|
+
// Board supplies the scene update and screen-space drawing hooks. The helpers
|
|
3
|
+
// join a multiplayer session, send square claims, tint actors and format status text.
|
|
4
4
|
|
|
5
5
|
import { Multiplayer } from 'castle-web-sdk';
|
|
6
6
|
import { avatarSpritePath } from '@imports/castle.physics-2d/engine/avatarArt';
|
|
@@ -15,16 +15,7 @@ const UNCLAIMED_TINT = '#ffffffff';
|
|
|
15
15
|
const RETRY_SECONDS = 6;
|
|
16
16
|
|
|
17
17
|
// The status overlay sits above the grid, which starts at y=170 on the card.
|
|
18
|
-
const
|
|
19
|
-
position: 'absolute',
|
|
20
|
-
left: 0,
|
|
21
|
-
top: 96,
|
|
22
|
-
width: '100%',
|
|
23
|
-
textAlign: 'center',
|
|
24
|
-
fontFamily: 'system-ui, sans-serif',
|
|
25
|
-
fontSize: 22,
|
|
26
|
-
color: '#c7cfdd',
|
|
27
|
-
};
|
|
18
|
+
const STATUS_Y = 96;
|
|
28
19
|
|
|
29
20
|
// The scene attaches Board to its board actor. The behavior reads input and
|
|
30
21
|
// server state while the actor supplies storage that lasts across frames.
|
|
@@ -51,10 +42,19 @@ export class Board {
|
|
|
51
42
|
paintSquares(scene, game.state);
|
|
52
43
|
}
|
|
53
44
|
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
// Screen-space card units keep the HUD fixed above the board and out of the
|
|
46
|
+
// camera transform. The actor's Layout spans the 500-unit card width.
|
|
47
|
+
drawUi(actor, scene, ctx) {
|
|
48
|
+
const text = statusLine(clientState(actor));
|
|
49
|
+
if (!text) return;
|
|
50
|
+
ctx.save();
|
|
51
|
+
ctx.fillStyle = '#c7cfdd';
|
|
52
|
+
ctx.font = `22px ${scene.font}`;
|
|
53
|
+
ctx.textAlign = 'center';
|
|
54
|
+
ctx.textBaseline = 'top';
|
|
55
|
+
const width = actor.components.Layout.width;
|
|
56
|
+
ctx.fillText(text, width / 2, STATUS_Y, width - 40);
|
|
57
|
+
ctx.restore();
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -82,7 +82,7 @@ function joinSession(game) {
|
|
|
82
82
|
// Claims require authoritative validation, so the local solo fallback
|
|
83
83
|
// cannot run this game. Start another public join after a delay.
|
|
84
84
|
if (connection.isSolo) {
|
|
85
|
-
return retryJoin(game);
|
|
85
|
+
return retryJoin(game, soloRetryStatus(connection.soloReason));
|
|
86
86
|
}
|
|
87
87
|
// The connection remains on actor.runtime for later tap messages.
|
|
88
88
|
game.connection = connection;
|
|
@@ -95,17 +95,29 @@ function joinSession(game) {
|
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
97
|
})
|
|
98
|
-
//
|
|
99
|
-
|
|
98
|
+
// Solo outcomes resolve above. A rejection is a transport or connection
|
|
99
|
+
// failure, so name it instead of making it look like a full table.
|
|
100
|
+
.catch((error) => {
|
|
101
|
+
const code = error?.code ?? 'MULTIPLAYER_CONNECTION_FAILED';
|
|
102
|
+
const message = error?.message ?? String(error);
|
|
103
|
+
console.warn(`[multiplayer] join failed: ${code}: ${message}`);
|
|
104
|
+
retryJoin(game, `multiplayer unavailable: ${code}`);
|
|
105
|
+
});
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
// Show the retry status and defer the next public join by a fixed interval.
|
|
103
|
-
function retryJoin(game) {
|
|
109
|
+
function retryJoin(game, status) {
|
|
104
110
|
// `statusLine` displays `waiting` while the timer runs.
|
|
105
|
-
game.waiting =
|
|
111
|
+
game.waiting = `${status} - trying again in a moment`;
|
|
106
112
|
setTimeout(() => joinSession(game), RETRY_SECONDS * 1000);
|
|
107
113
|
}
|
|
108
114
|
|
|
115
|
+
function soloRetryStatus(reason) {
|
|
116
|
+
if (reason === 'private_deck') return 'this deck is private';
|
|
117
|
+
if (reason === 'no_server_bundle') return 'publish the deck to enable multiplayer';
|
|
118
|
+
return 'no multiplayer table is available';
|
|
119
|
+
}
|
|
120
|
+
|
|
109
121
|
// Forward every square tap to the authoritative rules in code/server/index.js.
|
|
110
122
|
// The server validates turn, seat, index, occupancy and game status.
|
|
111
123
|
function readTaps(scene, game) {
|