castle-web-cli 0.4.193 → 0.4.194
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.js +87 -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 -0
- package/dist/check.js +14 -6
- package/dist/devSessionServer.d.ts +6 -0
- package/dist/devSessionServer.js +23 -1
- package/dist/filesChanged.js +7 -3
- 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 +56 -6
- package/dist/index.js +58 -7
- package/dist/init.d.ts +1 -0
- package/dist/init.js +6 -1
- package/dist/native/loop.js +29 -9
- package/dist/platformDoc.js +4 -4
- package/dist/remix.js +4 -1
- package/dist/serve.js +133 -32
- package/dist/serverBundle.js +1 -1
- package/dist/versions.d.ts +14 -0
- package/dist/versions.js +21 -0
- package/dist/vitePlugins.d.ts +1 -0
- package/dist/vitePlugins.js +18 -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 -3
- 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 -3
- package/kits/multiplayer-3d/scenes/main.scene +128 -0
- package/kits/physics-2d/CLAUDE.md +11 -5
- 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 -1
- package/kits/physics-2d/editors/SceneEditor.jsx +26 -2
- package/kits/physics-2d/editors/SelectionOverlay.jsx +27 -20
- 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/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/real-time/castle.json +2 -2
- package/kits/real-time/code/server/persist.js +14 -0
- package/kits/turn-based/CLAUDE.md +12 -7
- package/kits/turn-based/blueprints/board.scene +3 -1
- package/kits/turn-based/blueprints/square.scene +3 -1
- package/kits/turn-based/castle.json +5 -3
- package/kits/turn-based/code/behaviors/Board.jsx +33 -21
- package/package.json +1 -1
|
@@ -1,13 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "Sandbox",
|
|
3
3
|
"background": "#161a2b",
|
|
4
|
-
"physics": {
|
|
4
|
+
"physics": {
|
|
5
|
+
"gravity": 1
|
|
6
|
+
},
|
|
5
7
|
"actors": [
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
{
|
|
9
|
+
"id": "floor",
|
|
10
|
+
"blueprint": "blueprints/block.scene",
|
|
11
|
+
"components": {
|
|
12
|
+
"Layout": {
|
|
13
|
+
"x": 250,
|
|
14
|
+
"y": 670,
|
|
15
|
+
"width": 500,
|
|
16
|
+
"height": 60
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "leftWall",
|
|
22
|
+
"blueprint": "blueprints/block.scene",
|
|
23
|
+
"components": {
|
|
24
|
+
"Layout": {
|
|
25
|
+
"x": 25,
|
|
26
|
+
"y": 350,
|
|
27
|
+
"width": 50,
|
|
28
|
+
"height": 700
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "rightWall",
|
|
34
|
+
"blueprint": "blueprints/block.scene",
|
|
35
|
+
"components": {
|
|
36
|
+
"Layout": {
|
|
37
|
+
"x": 475,
|
|
38
|
+
"y": 350,
|
|
39
|
+
"width": 50,
|
|
40
|
+
"height": 700
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "crate1",
|
|
46
|
+
"blueprint": "blueprints/crate.scene",
|
|
47
|
+
"components": {
|
|
48
|
+
"Layout": {
|
|
49
|
+
"x": 174,
|
|
50
|
+
"y": 324
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "crate2",
|
|
56
|
+
"blueprint": "blueprints/crate.scene",
|
|
57
|
+
"components": {
|
|
58
|
+
"Layout": {
|
|
59
|
+
"x": 254,
|
|
60
|
+
"y": 204
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "crate3",
|
|
66
|
+
"blueprint": "blueprints/crate.scene",
|
|
67
|
+
"components": {
|
|
68
|
+
"Layout": {
|
|
69
|
+
"x": 324,
|
|
70
|
+
"y": 324
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
12
74
|
]
|
|
13
75
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// This kit's `onUpdate` hook: the CLI runs it in a deck whose pin on the kit has
|
|
3
|
+
// just moved (castle.json `onUpdate`, see the CLI's `importUpdateHook.ts`).
|
|
4
|
+
//
|
|
5
|
+
// The one thing it does today is state a pre-origin deck's top-left anchoring
|
|
6
|
+
// outright, so the center-origin default can't move anything --
|
|
7
|
+
// `engine/layoutOriginMigration.js` holds the whole decision, this file is only
|
|
8
|
+
// the disk. The version the deck was pinned at is the gate: an omitted origin is
|
|
9
|
+
// ambiguous on disk, and the pin is the only thing that says which way it was
|
|
10
|
+
// meant.
|
|
11
|
+
//
|
|
12
|
+
// Also runnable by hand, which is how a deck on a `builtin` pin (never
|
|
13
|
+
// auto-updated) or a deck someone hand-synced gets migrated:
|
|
14
|
+
//
|
|
15
|
+
// node <repo>/kits/physics-2d/scripts/onUpdate.mjs --deck . --from <ISO> [--to <ISO>] [--dry-run] [--force]
|
|
16
|
+
|
|
17
|
+
import * as fs from 'fs';
|
|
18
|
+
import * as path from 'path';
|
|
19
|
+
import { pathToFileURL } from 'url';
|
|
20
|
+
import {
|
|
21
|
+
LAST_TOP_LEFT_PUBLISHED_VERSION,
|
|
22
|
+
needsTopLeftStamp,
|
|
23
|
+
stampTopLeftOrigin,
|
|
24
|
+
} from '../engine/layoutOriginMigration.js';
|
|
25
|
+
|
|
26
|
+
const IMPORTS_DIR = 'imports';
|
|
27
|
+
const FORKS_DIR = 'forks';
|
|
28
|
+
// Not deck content: build output, dependencies, runtime state, history.
|
|
29
|
+
const SKIP_DIRS = new Set(['node_modules', '.castle', '.git', 'dist']);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Every `.scene` in the deck as whole-deck key -> text, plus the map of forked
|
|
33
|
+
* imported paths.
|
|
34
|
+
*
|
|
35
|
+
* The runtime globs every `.scene` in the deck, so a scene is wherever the deck
|
|
36
|
+
* put it (`levels/2.scene` is as real as `scenes/main.scene`) and every one of
|
|
37
|
+
* them has to be walked. Imported scenes are read too, unwritable as they are: a
|
|
38
|
+
* template's text is what says whether an instance inherits an origin from it.
|
|
39
|
+
*
|
|
40
|
+
* A fork's text is keyed at the imported path it OVERLAYS, because that is the
|
|
41
|
+
* path every ref in the deck names; `forks` remembers where it is actually
|
|
42
|
+
* written.
|
|
43
|
+
*/
|
|
44
|
+
function collectSceneFiles(deckDir) {
|
|
45
|
+
const files = {};
|
|
46
|
+
const forks = {};
|
|
47
|
+
const walk = (absDir, relDir) => {
|
|
48
|
+
let entries;
|
|
49
|
+
try {
|
|
50
|
+
entries = fs.readdirSync(absDir, { withFileTypes: true });
|
|
51
|
+
} catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
56
|
+
const rel = relDir ? `${relDir}/${entry.name}` : entry.name;
|
|
57
|
+
if (entry.isDirectory()) {
|
|
58
|
+
walk(path.join(absDir, entry.name), rel);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (!entry.name.endsWith('.scene')) continue;
|
|
62
|
+
const text = fs.readFileSync(path.join(absDir, entry.name), 'utf-8');
|
|
63
|
+
if (rel.startsWith(`${FORKS_DIR}/`)) {
|
|
64
|
+
const imported = `${IMPORTS_DIR}/${rel.slice(FORKS_DIR.length + 1)}`;
|
|
65
|
+
files[imported] = text;
|
|
66
|
+
forks[imported] = rel;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
files[rel] = text;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
walk(deckDir, '');
|
|
73
|
+
return { files, forks };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// The writes, applied. `imports/` is refused here as well as excluded upstream:
|
|
77
|
+
// a hook writing into somebody else's deck is the one mistake worth being unable
|
|
78
|
+
// to make by accident.
|
|
79
|
+
function applyWrites(deckDir, writes) {
|
|
80
|
+
for (const { path: rel, text } of writes) {
|
|
81
|
+
if (rel.startsWith(`${IMPORTS_DIR}/`)) {
|
|
82
|
+
throw new Error(`refusing to write ${rel}: files under ${IMPORTS_DIR}/ belong to their own deck`);
|
|
83
|
+
}
|
|
84
|
+
fs.writeFileSync(path.join(deckDir, rel), text, 'utf-8');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// A `Layout` built in code has no file to stamp, so it takes the new default at
|
|
89
|
+
// runtime and this migration cannot help it. Read-only: point at them and let a
|
|
90
|
+
// person read the code.
|
|
91
|
+
function inlineLayoutFiles(deckDir) {
|
|
92
|
+
const dir = path.join(deckDir, 'behaviors');
|
|
93
|
+
let names;
|
|
94
|
+
try {
|
|
95
|
+
names = fs.readdirSync(dir);
|
|
96
|
+
} catch {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
return names
|
|
100
|
+
.filter((name) => name.endsWith('.jsx') || name.endsWith('.js'))
|
|
101
|
+
.filter((name) => {
|
|
102
|
+
try {
|
|
103
|
+
return fs.readFileSync(path.join(dir, name), 'utf-8').includes('spawnActor(');
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
.map((name) => `behaviors/${name}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function summarize(stats, writes) {
|
|
112
|
+
const parts = [
|
|
113
|
+
`${writes.length} file${writes.length === 1 ? '' : 's'}`,
|
|
114
|
+
`${stats.templates} blueprint template${stats.templates === 1 ? '' : 's'}`,
|
|
115
|
+
`${stats.instances} instance${stats.instances === 1 ? '' : 's'}`,
|
|
116
|
+
];
|
|
117
|
+
if (stats.orphans > 0) parts.push(`${stats.orphans} un-migrated actor${stats.orphans === 1 ? '' : 's'}`);
|
|
118
|
+
return parts.join(', ');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The hook. Idempotent by construction: a stamped deck has an explicit origin
|
|
123
|
+
* everywhere the stamp goes, so a second run finds nothing to write -- which is
|
|
124
|
+
* what makes it safe after an `update-import --revert` and after a rolled-back
|
|
125
|
+
* failure.
|
|
126
|
+
*/
|
|
127
|
+
export default async function onUpdate({ deckDir, alias = 'castle.physics-2d', from, to, log = console.log, dryRun = false, force = false } = {}) {
|
|
128
|
+
if (!deckDir) throw new Error('onUpdate needs a deckDir');
|
|
129
|
+
if (!force && !needsTopLeftStamp({ from, to })) {
|
|
130
|
+
log(
|
|
131
|
+
`layout origin: nothing to do (${from} -> ${to}; the default changed after ${LAST_TOP_LEFT_PUBLISHED_VERSION}).`,
|
|
132
|
+
);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const { files, forks } = collectSceneFiles(deckDir);
|
|
136
|
+
const { writes, stats } = stampTopLeftOrigin(files, { forks });
|
|
137
|
+
for (const skipped of stats.unparseable) log(`layout origin: skipped ${skipped} (not valid JSON).`);
|
|
138
|
+
if (writes.length === 0) {
|
|
139
|
+
log(`layout origin: already explicit in all ${stats.considered} scene file(s); nothing written.`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (dryRun) {
|
|
143
|
+
log(`layout origin: WOULD write ${summarize(stats, writes)}:`);
|
|
144
|
+
for (const { path: rel } of writes) log(`layout origin: ${rel}`);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
applyWrites(deckDir, writes);
|
|
148
|
+
log(
|
|
149
|
+
`layout origin: wrote explicit originX/originY 0 into ${summarize(stats, writes)} -- ` +
|
|
150
|
+
`nothing moved, ${alias} now reads them the same way it always did. ` +
|
|
151
|
+
'Convert a blueprint to a center origin from the inspector when you want to; ' +
|
|
152
|
+
'`castle-web list-versions` names the version saved just before this, and ' +
|
|
153
|
+
'`castle-web restore-version <id>` puts these files back.',
|
|
154
|
+
);
|
|
155
|
+
const inline = inlineLayoutFiles(deckDir);
|
|
156
|
+
if (inline.length > 0) {
|
|
157
|
+
log(
|
|
158
|
+
`layout origin: check inline Layouts in ${inline.join(', ')} -- a Layout built in code has no ` +
|
|
159
|
+
'file to stamp and takes the new center default.',
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// -- direct CLI ---------------------------------------------------------------
|
|
165
|
+
|
|
166
|
+
function flag(name) {
|
|
167
|
+
return process.argv.includes(`--${name}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function value(name, fallback) {
|
|
171
|
+
const at = process.argv.indexOf(`--${name}`);
|
|
172
|
+
return at >= 0 && process.argv[at + 1] ? process.argv[at + 1] : fallback;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function main() {
|
|
176
|
+
const from = value('from');
|
|
177
|
+
if (!from && !flag('force')) {
|
|
178
|
+
console.error(
|
|
179
|
+
'Usage: node scripts/onUpdate.mjs [--deck DIR] --from ISO [--to ISO] [--dry-run] [--force]\n' +
|
|
180
|
+
'--from is the kit version the deck was pinned at; it is what decides whether an absent ' +
|
|
181
|
+
'origin meant top-left. --force runs anyway.',
|
|
182
|
+
);
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
await onUpdate({
|
|
186
|
+
deckDir: path.resolve(value('deck', '.')),
|
|
187
|
+
from,
|
|
188
|
+
to: value('to', new Date().toISOString()),
|
|
189
|
+
dryRun: flag('dry-run'),
|
|
190
|
+
force: flag('force'),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
|
|
195
|
+
main().catch((e) => {
|
|
196
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
197
|
+
process.exit(1);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"imports": {
|
|
10
10
|
"castle.base": {
|
|
11
11
|
"deckId": "yRcmH4_aYllE",
|
|
12
|
-
"version": "2026-09-
|
|
12
|
+
"version": "2026-09-11T20:21:04.335Z"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"autoUpdateWhenImported": true,
|
|
16
16
|
"deckId": "xFVr-afOLuUQ",
|
|
17
17
|
"cardId": "w6G45sy3_P_m",
|
|
18
|
-
"publishedVersion": "2026-09-
|
|
18
|
+
"publishedVersion": "2026-09-16T21:18:06.448Z"
|
|
19
19
|
}
|
|
@@ -91,12 +91,26 @@ async function write(session, values, operation) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
let announced = false;
|
|
94
|
+
let unpublishedStorageAnnounced = false;
|
|
94
95
|
|
|
95
96
|
// Operations that have already reported a failure, so a broken setup is named
|
|
96
97
|
// once.
|
|
97
98
|
const reported = new Set();
|
|
98
99
|
|
|
99
100
|
function report(operation, error) {
|
|
101
|
+
if (
|
|
102
|
+
error?.code === 'CAULDRON_STORAGE_UNAVAILABLE' &&
|
|
103
|
+
String(error?.message ?? '').startsWith('Storage needs a published deck.')
|
|
104
|
+
) {
|
|
105
|
+
if (!unpublishedStorageAnnounced) {
|
|
106
|
+
unpublishedStorageAnnounced = true;
|
|
107
|
+
console.info(
|
|
108
|
+
'[persist] deck storage is off until the deck is published (save-deck); ' +
|
|
109
|
+
'the room will not persist across serve restarts.'
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
100
114
|
if (reported.has(operation)) {
|
|
101
115
|
return;
|
|
102
116
|
}
|
|
@@ -30,17 +30,20 @@ This kit adds no engine and no editors. What it holds:
|
|
|
30
30
|
game to change.
|
|
31
31
|
- **A scaffolded deck is already a playable game.** `castle.json` points
|
|
32
32
|
`server.main` at `imports/castle.turn-based/code/server/index.js` -- two seats
|
|
33
|
-
claiming squares -- and `scenes/main.scene` is its board.
|
|
34
|
-
|
|
33
|
+
claiming squares -- and `scenes/main.scene` is its board. Run
|
|
34
|
+
`castle-web serve`, open the printed shell URL in two tabs, and open the Play
|
|
35
|
+
panel in each before changing anything. If you use `.castle/serve.json`'s
|
|
36
|
+
`contentPlayUrl` directly, open `/index.html?edit=0`; its bare origin is the
|
|
37
|
+
edit surface, where multiplayer does not join.
|
|
35
38
|
- **Making a different game means writing the server.** Add `server/index.js` to
|
|
36
39
|
the deck, point `server.main` at it, and keep the room:
|
|
37
40
|
`createRoom({ seats, idleMs, graceMs })` from
|
|
38
41
|
`@imports/castle.turn-based/room.js`. Copy the kit's server as the starting
|
|
39
42
|
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.
|
|
43
|
+
- `room.joinAsync(session, player)` returns `{ table }` and
|
|
44
|
+
`room.leave(session, player)` returns `{ table, saved }`. One table per
|
|
45
|
+
`session.sessionId`, made on demand. `joinAsync` is the join to use: it reads
|
|
46
|
+
the saved table first, which the synchronous `room.join` cannot.
|
|
44
47
|
- **A claimed square shows its holder's avatar.** The state carries `users`,
|
|
45
48
|
seat -> userId, and `Board.jsx` swaps the square's `Sprite.file` for the
|
|
46
49
|
avatar from `castle.physics-2d`'s `engine/avatarArt.js`; a holder with no
|
|
@@ -177,6 +180,7 @@ export default {
|
|
|
177
180
|
deck that has to keep showing a departed player's name for the length of a hand
|
|
178
181
|
copies the name into its own state when it deals.
|
|
179
182
|
- `table.seatNames()` -> `{ [seat]: name | null }`, ready to send.
|
|
183
|
+
- `table.seatUsers()` -> `{ [seat]: userId | null }`, ready to persist or send.
|
|
180
184
|
- `table.spectatorCount(session)` -- people in the session holding no seat.
|
|
181
185
|
- `table.keepAlive()` -- stamp the idle clock and save the table. **Past every
|
|
182
186
|
rejection, never before one.** A rematch is the deck's own
|
|
@@ -265,7 +269,8 @@ is no runner. Run it from the deck directory, with the kit's `testing.js` as the
|
|
|
265
269
|
node --import ./imports/castle.turn-based/testing.js tools/check.mjs
|
|
266
270
|
```
|
|
267
271
|
|
|
268
|
-
Put that in the deck's `package.json` as a `
|
|
272
|
+
Put that in the deck's `package.json` as a `test:room` script; `init` already
|
|
273
|
+
writes `check` for `castle-web check`. Without the `--import`, `node` has
|
|
269
274
|
never heard of `@imports/` and cannot import the very server module the tests
|
|
270
275
|
exist to check.
|
|
271
276
|
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
"hiddenPaths": [],
|
|
5
5
|
"visiblePaths": [
|
|
6
6
|
"code/**",
|
|
7
|
+
"server/**",
|
|
8
|
+
"behaviors/**",
|
|
7
9
|
"room.js",
|
|
8
10
|
"testing.js",
|
|
9
11
|
"scenes/**",
|
|
@@ -17,18 +19,18 @@
|
|
|
17
19
|
"imports": {
|
|
18
20
|
"castle.physics-2d": {
|
|
19
21
|
"deckId": "ckRZGFW4iPrx",
|
|
20
|
-
"version": "2026-09-
|
|
22
|
+
"version": "2026-09-16T21:17:53.144Z"
|
|
21
23
|
},
|
|
22
24
|
"castle.base": {
|
|
23
25
|
"deckId": "yRcmH4_aYllE",
|
|
24
|
-
"version": "2026-09-
|
|
26
|
+
"version": "2026-09-11T20:21:04.335Z"
|
|
25
27
|
}
|
|
26
28
|
},
|
|
27
29
|
"main": "main.jsx",
|
|
28
30
|
"autoUpdateWhenImported": true,
|
|
29
31
|
"deckId": "K6-Xs7dCoMVi",
|
|
30
32
|
"cardId": "Kh_08IYATpC3",
|
|
31
|
-
"publishedVersion": "2026-09-
|
|
33
|
+
"publishedVersion": "2026-09-16T21:20:29.544Z",
|
|
32
34
|
"server": {
|
|
33
35
|
"main": "code/server/index.js",
|
|
34
36
|
"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) {
|