castle-web-cli 0.4.192 → 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 +14 -0
- package/dist/api.js +13 -1
- 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/native/playtest-remote.js +53 -5
- package/dist/native/playtest.d.ts +11 -0
- package/dist/native/playtest.js +91 -5
- 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
package/dist/serve.js
CHANGED
|
@@ -18,6 +18,7 @@ import * as config from './config.js';
|
|
|
18
18
|
import { graphql as castleGraphql } from './api.js';
|
|
19
19
|
import { executeCommand } from './castle-host/host.js';
|
|
20
20
|
import { ServeSecurity } from './serveSecurity.js';
|
|
21
|
+
import { atomicWriteFileSync } from './atomicFile.js';
|
|
21
22
|
import { isSameOriginUpgrade } from './wsOrigin.js';
|
|
22
23
|
import { createAssetCompression } from './assetCompression.js';
|
|
23
24
|
import { resolveServerConfig } from './castleJson.js';
|
|
@@ -40,18 +41,59 @@ export function appendCapped(file, line) {
|
|
|
40
41
|
// logging must never take the serve down
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
const PORT_PROBE_TIMEOUT_MS = 300;
|
|
45
|
+
const PORT_PROBE_FREE_ERRORS = new Set([
|
|
46
|
+
'ECONNREFUSED',
|
|
47
|
+
'EHOSTUNREACH',
|
|
48
|
+
'EADDRNOTAVAIL',
|
|
49
|
+
'EAFNOSUPPORT',
|
|
50
|
+
]);
|
|
51
|
+
// A wildcard or localhost serve is reached as http://localhost:<port>, which
|
|
52
|
+
// resolves to either loopback family, so a listener on just one of them still
|
|
53
|
+
// makes the port unusable (two decks answered on one hostname that way).
|
|
54
|
+
function connectProbeHosts(host) {
|
|
55
|
+
return !host || host === 'localhost' || host === '0.0.0.0' || host === '::'
|
|
56
|
+
? ['127.0.0.1', '::1']
|
|
57
|
+
: [host];
|
|
58
|
+
}
|
|
59
|
+
function canConnectToPort(port, host) {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const socket = net.createConnection({ port, host });
|
|
62
|
+
socket.setTimeout(PORT_PROBE_TIMEOUT_MS);
|
|
63
|
+
socket.once('connect', () => {
|
|
64
|
+
socket.destroy();
|
|
65
|
+
resolve(true);
|
|
66
|
+
});
|
|
67
|
+
// A loopback connect that neither completes nor is refused is
|
|
68
|
+
// indeterminate; treat it as occupied so findFreePort moves on and an
|
|
69
|
+
// explicit port fails here rather than deeper in vite.
|
|
70
|
+
socket.once('timeout', () => {
|
|
71
|
+
socket.destroy();
|
|
72
|
+
resolve(true);
|
|
73
|
+
});
|
|
74
|
+
socket.once('error', (error) => {
|
|
75
|
+
if (error.code && PORT_PROBE_FREE_ERRORS.has(error.code))
|
|
76
|
+
resolve(false);
|
|
77
|
+
else
|
|
78
|
+
reject(error);
|
|
49
79
|
});
|
|
50
80
|
});
|
|
51
81
|
}
|
|
52
|
-
async function
|
|
82
|
+
async function isPortFree(port, host) {
|
|
83
|
+
for (const probeHost of connectProbeHosts(host)) {
|
|
84
|
+
if (await canConnectToPort(port, probeHost))
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
async function requireFreePort(port, host) {
|
|
90
|
+
if (await isPortFree(port, host))
|
|
91
|
+
return;
|
|
92
|
+
throw new Error(`Port ${port} is already in use. Try another port with --port <n>.`);
|
|
93
|
+
}
|
|
94
|
+
async function findFreePort(startPort, host) {
|
|
53
95
|
for (let port = startPort; port < startPort + 100; port += 1) {
|
|
54
|
-
if (await isPortFree(port))
|
|
96
|
+
if (await isPortFree(port, host))
|
|
55
97
|
return port;
|
|
56
98
|
}
|
|
57
99
|
throw new Error(`No free port found starting from ${startPort}`);
|
|
@@ -383,8 +425,7 @@ window.__castleShellOrigin=(function(){
|
|
|
383
425
|
res.end(JSON.stringify({ path: `${LEGACY_CONTENT_WS_PATH}?ticket=${ticket}` }));
|
|
384
426
|
return;
|
|
385
427
|
}
|
|
386
|
-
if (reqPath === '/__castle/auth' ||
|
|
387
|
-
reqPath === '/__castle/context') {
|
|
428
|
+
if (reqPath === '/__castle/auth' || reqPath === '/__castle/context') {
|
|
388
429
|
res.writeHead(404).end();
|
|
389
430
|
return;
|
|
390
431
|
}
|
|
@@ -557,13 +598,64 @@ function readServeJson(projectDir) {
|
|
|
557
598
|
return null;
|
|
558
599
|
}
|
|
559
600
|
}
|
|
601
|
+
function removeServeJsonIfOwned(serveJsonPath, pid) {
|
|
602
|
+
try {
|
|
603
|
+
const before = fs.statSync(serveJsonPath);
|
|
604
|
+
const info = JSON.parse(fs.readFileSync(serveJsonPath, 'utf8'));
|
|
605
|
+
if (info.pid !== pid)
|
|
606
|
+
return;
|
|
607
|
+
const after = fs.statSync(serveJsonPath);
|
|
608
|
+
if (before.dev !== after.dev || before.ino !== after.ino)
|
|
609
|
+
return;
|
|
610
|
+
// The final stat-to-unlink race remains, but this narrow window is accepted.
|
|
611
|
+
fs.unlinkSync(serveJsonPath);
|
|
612
|
+
}
|
|
613
|
+
catch {
|
|
614
|
+
// Missing, malformed, or replaced by another serve: leave it alone.
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
function removeStaleServeJson(serveJsonPath) {
|
|
618
|
+
try {
|
|
619
|
+
const raw = fs.readFileSync(serveJsonPath, 'utf8');
|
|
620
|
+
let pid = null;
|
|
621
|
+
try {
|
|
622
|
+
const info = JSON.parse(raw);
|
|
623
|
+
if (typeof info.pid === 'number' && Number.isInteger(info.pid) && info.pid > 0) {
|
|
624
|
+
pid = info.pid;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
catch {
|
|
628
|
+
// An unreadable record cannot name a live owner.
|
|
629
|
+
}
|
|
630
|
+
if (pid !== null) {
|
|
631
|
+
if (isPidAlive(pid))
|
|
632
|
+
return;
|
|
633
|
+
removeServeJsonIfOwned(serveJsonPath, pid);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
// Do not unlink a valid record that replaced the malformed one we read.
|
|
637
|
+
if (fs.readFileSync(serveJsonPath, 'utf8') === raw)
|
|
638
|
+
fs.unlinkSync(serveJsonPath);
|
|
639
|
+
}
|
|
640
|
+
catch {
|
|
641
|
+
// No stale record to remove, or another process changed it concurrently.
|
|
642
|
+
}
|
|
643
|
+
}
|
|
560
644
|
function isPidAlive(pid) {
|
|
561
645
|
try {
|
|
562
646
|
process.kill(pid, 0);
|
|
563
647
|
return true;
|
|
564
648
|
}
|
|
649
|
+
catch (error) {
|
|
650
|
+
return error.code === 'EPERM';
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
function readLogTail(logPath, maxLines) {
|
|
654
|
+
try {
|
|
655
|
+
return fs.readFileSync(logPath, 'utf8').trimEnd().split(/\r?\n/).slice(-maxLines).join('\n');
|
|
656
|
+
}
|
|
565
657
|
catch {
|
|
566
|
-
return
|
|
658
|
+
return '';
|
|
567
659
|
}
|
|
568
660
|
}
|
|
569
661
|
// Return the live serve already owning this deck, if any. Lets repeated
|
|
@@ -633,6 +725,9 @@ export async function serve(dir, options = {}) {
|
|
|
633
725
|
return;
|
|
634
726
|
}
|
|
635
727
|
}
|
|
728
|
+
const explicitPort = options.port ? Number.parseInt(options.port, 10) : undefined;
|
|
729
|
+
if (explicitPort !== undefined)
|
|
730
|
+
await requireFreePort(explicitPort, options.host);
|
|
636
731
|
// --detach is kept for back-compat. Agent evals (and any harness running
|
|
637
732
|
// castle-web in a context that can't manage a foreground process) should
|
|
638
733
|
// prefer the CASTLE_WEB_CLI_DETACH=1 env var instead.
|
|
@@ -693,8 +788,8 @@ export async function serve(dir, options = {}) {
|
|
|
693
788
|
// already destroyed / inaccessible
|
|
694
789
|
}
|
|
695
790
|
}
|
|
696
|
-
const startPort =
|
|
697
|
-
const port =
|
|
791
|
+
const startPort = explicitPort ?? DEFAULT_PORT;
|
|
792
|
+
const port = explicitPort ?? (await findFreePort(startPort, options.host));
|
|
698
793
|
const security = new ServeSecurity(port);
|
|
699
794
|
// Local WebSocket server for SDK communication
|
|
700
795
|
const castleDir = path.join(projectDir, '.castle');
|
|
@@ -716,12 +811,7 @@ export async function serve(dir, options = {}) {
|
|
|
716
811
|
const screenshotsDir = path.join(castleDir, 'screenshots');
|
|
717
812
|
const serveJsonPath = path.join(castleDir, 'serve.json');
|
|
718
813
|
process.on('exit', () => {
|
|
719
|
-
|
|
720
|
-
fs.unlinkSync(serveJsonPath);
|
|
721
|
-
}
|
|
722
|
-
catch {
|
|
723
|
-
// already removed / never written
|
|
724
|
-
}
|
|
814
|
+
removeServeJsonIfOwned(serveJsonPath, process.pid);
|
|
725
815
|
});
|
|
726
816
|
process.on('SIGINT', () => process.exit());
|
|
727
817
|
process.on('SIGTERM', () => process.exit());
|
|
@@ -910,7 +1000,9 @@ export async function serve(dir, options = {}) {
|
|
|
910
1000
|
// Bring content up first so `--open` cannot race an iframe against a port
|
|
911
1001
|
// that is not listening yet. Vite opens the shell from inside `vite.listen()`.
|
|
912
1002
|
await vite.listen();
|
|
913
|
-
|
|
1003
|
+
// Atomic so a replacement lands under a new inode: the owned-removal check
|
|
1004
|
+
// in removeServeJsonIfOwned compares inodes to tell a rewrite apart.
|
|
1005
|
+
atomicWriteFileSync(serveJsonPath, JSON.stringify({
|
|
914
1006
|
port,
|
|
915
1007
|
// Kept for older CLI commands: they connect to this port's root path.
|
|
916
1008
|
// New clients use wsPath. Both routes reach the same noServer WSS.
|
|
@@ -990,13 +1082,9 @@ async function serveDetached(projectDir, options) {
|
|
|
990
1082
|
if (!fs.existsSync(castleDir))
|
|
991
1083
|
fs.mkdirSync(castleDir, { recursive: true });
|
|
992
1084
|
const serveJsonPath = path.join(castleDir, 'serve.json');
|
|
993
|
-
// Clear stale
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
997
|
-
catch {
|
|
998
|
-
// no stale serve.json — fine
|
|
999
|
-
}
|
|
1085
|
+
// Clear only a stale record. A live serve owns its file even when this
|
|
1086
|
+
// explicit invocation is going to attempt a second serve for the deck.
|
|
1087
|
+
removeStaleServeJson(serveJsonPath);
|
|
1000
1088
|
const logPath = path.join(castleDir, 'serve.log');
|
|
1001
1089
|
const logFd = fs.openSync(logPath, 'a');
|
|
1002
1090
|
// Re-exec this CLI with the same args minus --detach. process.argv[0] is
|
|
@@ -1027,16 +1115,29 @@ async function serveDetached(projectDir, options) {
|
|
|
1027
1115
|
stdio: ['ignore', logFd, logFd],
|
|
1028
1116
|
env: childEnv,
|
|
1029
1117
|
});
|
|
1030
|
-
child.unref();
|
|
1031
1118
|
fs.closeSync(logFd);
|
|
1032
|
-
|
|
1033
|
-
|
|
1119
|
+
const childPid = child.pid;
|
|
1120
|
+
if (childPid === undefined)
|
|
1121
|
+
throw new Error('detached serve did not start a child process');
|
|
1122
|
+
child.unref();
|
|
1123
|
+
// Import auto-update happens in the child before it binds and can be slow on
|
|
1124
|
+
// the network. Wait while that child is alive, with a generous final bound.
|
|
1125
|
+
const deadline = Date.now() + 120_000;
|
|
1034
1126
|
while (Date.now() < deadline) {
|
|
1127
|
+
if (!isPidAlive(childPid)) {
|
|
1128
|
+
const tail = readLogTail(logPath, 10);
|
|
1129
|
+
throw new Error(`Detached serve process ${childPid} exited before writing ${serveJsonPath}.\n` +
|
|
1130
|
+
`Last lines of ${logPath}:\n${tail || '(no log output)'}`);
|
|
1131
|
+
}
|
|
1035
1132
|
if (fs.existsSync(serveJsonPath)) {
|
|
1036
1133
|
try {
|
|
1037
1134
|
const info = JSON.parse(fs.readFileSync(serveJsonPath, 'utf8'));
|
|
1135
|
+
if (info.pid !== childPid || typeof info.port !== 'number') {
|
|
1136
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1038
1139
|
console.log(`Started serve in background: http://localhost:${info.port}`);
|
|
1039
|
-
console.log(`PID: ${
|
|
1140
|
+
console.log(`PID: ${childPid}`);
|
|
1040
1141
|
console.log(`Logs: ${logPath}`);
|
|
1041
1142
|
return;
|
|
1042
1143
|
}
|
|
@@ -1046,7 +1147,7 @@ async function serveDetached(projectDir, options) {
|
|
|
1046
1147
|
}
|
|
1047
1148
|
await new Promise((r) => setTimeout(r, 200));
|
|
1048
1149
|
}
|
|
1049
|
-
throw new Error(`Detached serve did not write ${serveJsonPath} within
|
|
1150
|
+
throw new Error(`Detached serve did not write ${serveJsonPath} within 120s; check ${logPath} for startup errors.`);
|
|
1050
1151
|
}
|
|
1051
1152
|
// Answered by the SERVE itself (the agent server owns the warm Chromium),
|
|
1052
1153
|
// unlike screenshot_request which a browser tab answers -- so no
|
package/dist/serverBundle.js
CHANGED
|
@@ -69,7 +69,7 @@ export async function bundleServerModule(projectDir, config, minify) {
|
|
|
69
69
|
assetsInlineLimit: Number.MAX_SAFE_INTEGER,
|
|
70
70
|
rollupOptions: {
|
|
71
71
|
input: VIRTUAL_ENTRY,
|
|
72
|
-
output: { format: 'es',
|
|
72
|
+
output: { format: 'es', codeSplitting: false },
|
|
73
73
|
},
|
|
74
74
|
},
|
|
75
75
|
});
|
package/dist/versions.d.ts
CHANGED
|
@@ -35,6 +35,20 @@ export declare function pendingChanges(projectDir: string): {
|
|
|
35
35
|
path: string;
|
|
36
36
|
kind: ChangeKind;
|
|
37
37
|
}[];
|
|
38
|
+
/**
|
|
39
|
+
* Put the working tree back at head, throwing away everything not saved. The
|
|
40
|
+
* paths it touched, as a list.
|
|
41
|
+
*
|
|
42
|
+
* `applyVersionRestore` cannot express this: head IS the target, so it returns
|
|
43
|
+
* `alreadyThere` without looking at the tree. This is the rollback for an
|
|
44
|
+
* operation that saved a version and then wrote deck files -- see
|
|
45
|
+
* importUpdateHook.ts, where a kit's migration failing halfway has to leave the
|
|
46
|
+
* deck's own files exactly as the update found them.
|
|
47
|
+
*
|
|
48
|
+
* The cover is exempt for the same reason it is everywhere else (it is dirty by
|
|
49
|
+
* construction), which `pendingChanges` already handles.
|
|
50
|
+
*/
|
|
51
|
+
export declare function discardPendingChanges(projectDir: string): string[];
|
|
38
52
|
/**
|
|
39
53
|
* The deck's history newest first. From head (no `fromId`): the chain forward
|
|
40
54
|
* from head -- marked `later` -- then head, then its ancestors. From a named
|
package/dist/versions.js
CHANGED
|
@@ -155,6 +155,27 @@ export function pendingChanges(projectDir) {
|
|
|
155
155
|
.filter(([path]) => isReportableChange(path))
|
|
156
156
|
.map(([path, change]) => ({ path, kind: changeKind(change) }));
|
|
157
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Put the working tree back at head, throwing away everything not saved. The
|
|
160
|
+
* paths it touched, as a list.
|
|
161
|
+
*
|
|
162
|
+
* `applyVersionRestore` cannot express this: head IS the target, so it returns
|
|
163
|
+
* `alreadyThere` without looking at the tree. This is the rollback for an
|
|
164
|
+
* operation that saved a version and then wrote deck files -- see
|
|
165
|
+
* importUpdateHook.ts, where a kit's migration failing halfway has to leave the
|
|
166
|
+
* deck's own files exactly as the update found them.
|
|
167
|
+
*
|
|
168
|
+
* The cover is exempt for the same reason it is everywhere else (it is dirty by
|
|
169
|
+
* construction), which `pendingChanges` already handles.
|
|
170
|
+
*/
|
|
171
|
+
export function discardPendingChanges(projectDir) {
|
|
172
|
+
const headFiles = store.parentManifest(projectDir, store.readHead(projectDir));
|
|
173
|
+
const actions = pendingChanges(projectDir)
|
|
174
|
+
.map(({ path: rel }) => [rel, headFiles[rel] ?? null])
|
|
175
|
+
.sort((a, b) => a[0].localeCompare(b[0]));
|
|
176
|
+
applyRestore(projectDir, actions);
|
|
177
|
+
return actions.map(([rel]) => rel);
|
|
178
|
+
}
|
|
158
179
|
function toSummary(version, later) {
|
|
159
180
|
return {
|
|
160
181
|
id: version.id,
|
package/dist/vitePlugins.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
export declare function importsAliasPlugin(): Plugin;
|
|
3
3
|
export declare function sdkAliasPlugin(): Plugin;
|
|
4
|
+
export declare function singleFileBuildCompatPlugin(): Plugin;
|
|
4
5
|
export declare function forksOverlayPlugin(): Plugin;
|
|
5
6
|
export declare function sceneFilesPlugin(): Plugin;
|
package/dist/vitePlugins.js
CHANGED
|
@@ -89,6 +89,24 @@ export function sdkAliasPlugin() {
|
|
|
89
89
|
},
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
+
// vite-plugin-singlefile still writes Rollup's deprecated inlineDynamicImports
|
|
93
|
+
// option. Rolldown's equivalent keeps the one-chunk output without the warning.
|
|
94
|
+
export function singleFileBuildCompatPlugin() {
|
|
95
|
+
return {
|
|
96
|
+
name: 'castle-single-file-build-compat',
|
|
97
|
+
enforce: 'post',
|
|
98
|
+
config(config) {
|
|
99
|
+
const output = config.build?.rollupOptions?.output;
|
|
100
|
+
if (!output)
|
|
101
|
+
return;
|
|
102
|
+
const outputs = Array.isArray(output) ? output : [output];
|
|
103
|
+
for (const options of outputs) {
|
|
104
|
+
delete options.inlineDynamicImports;
|
|
105
|
+
options.codeSplitting = false;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
92
110
|
// `<path>?raw` -> ['<path>', '?raw']; no query -> ['<path>', ''].
|
|
93
111
|
function splitQuery(id) {
|
|
94
112
|
const at = id.indexOf('?');
|
|
@@ -67,8 +67,11 @@ then `Smoothing.smooth(…)`. File names stay lowercase.
|
|
|
67
67
|
Identity comes from `player.playerId` / `player.userId`, never from a body.
|
|
68
68
|
- The kit ships `code/systems/multiplayer.js`, the frame loop. A deck that writes
|
|
69
69
|
its own file of that path gets its own instead; most decks should not.
|
|
70
|
-
- Two players is the test that matters: `castle-web serve`,
|
|
71
|
-
two tabs
|
|
70
|
+
- Two players is the test that matters: run `castle-web serve`, open the shell
|
|
71
|
+
URL it prints in two tabs, and open the Play panel in each. If you use
|
|
72
|
+
`.castle/serve.json`'s `contentPlayUrl` directly, open `/index.html?edit=0`;
|
|
73
|
+
its bare origin is the edit surface, where multiplayer does not join. The room
|
|
74
|
+
persists in deck storage across serve restarts; a fresh one
|
|
72
75
|
means removing its `world:<room>`, `game:<room>` and `player:<room>:*` rows
|
|
73
76
|
(the local serve's room is `dev`).
|
|
74
77
|
|
|
@@ -172,6 +175,10 @@ node ../../cli/dist/index.js serve . --port 5762 --detach
|
|
|
172
175
|
node test/two-client-test.mjs
|
|
173
176
|
```
|
|
174
177
|
|
|
178
|
+
The test resolves `playwright-core` from this repo's `cli/package.json`, so run
|
|
179
|
+
the repo's normal `npm install` first; no machine-specific checkout path or
|
|
180
|
+
global Playwright install is required.
|
|
181
|
+
|
|
175
182
|
The room's state persists, so crates stay where the last run pushed them. Each
|
|
176
183
|
client publishes what it believes about the room on `globalThis.__multiplayer`,
|
|
177
184
|
which is what the test reads.
|
|
@@ -3,10 +3,38 @@
|
|
|
3
3
|
"actors": [
|
|
4
4
|
{
|
|
5
5
|
"components": {
|
|
6
|
-
"Layout": {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
"Layout": {
|
|
7
|
+
"width": 44,
|
|
8
|
+
"height": 44,
|
|
9
|
+
"z": 2,
|
|
10
|
+
"originX": 0,
|
|
11
|
+
"originY": 0
|
|
12
|
+
},
|
|
13
|
+
"Box": {
|
|
14
|
+
"color": "#bd9354",
|
|
15
|
+
"edge": "#7a5c31",
|
|
16
|
+
"radius": 3
|
|
17
|
+
},
|
|
18
|
+
"Collider": {
|
|
19
|
+
"shapes": [
|
|
20
|
+
{
|
|
21
|
+
"type": "box",
|
|
22
|
+
"x": 0.5,
|
|
23
|
+
"y": 0.5,
|
|
24
|
+
"w": 1,
|
|
25
|
+
"h": 1
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"friction": 0.3,
|
|
29
|
+
"frictionStatic": 0.4,
|
|
30
|
+
"bounciness": 0
|
|
31
|
+
},
|
|
32
|
+
"RigidBody": {
|
|
33
|
+
"bodyType": "dynamic",
|
|
34
|
+
"gravityScale": 0,
|
|
35
|
+
"drag": 0.09,
|
|
36
|
+
"angularDrag": 2
|
|
37
|
+
}
|
|
10
38
|
}
|
|
11
39
|
}
|
|
12
40
|
]
|
|
@@ -3,10 +3,37 @@
|
|
|
3
3
|
"actors": [
|
|
4
4
|
{
|
|
5
5
|
"components": {
|
|
6
|
-
"Layout": {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
"Layout": {
|
|
7
|
+
"width": 34,
|
|
8
|
+
"height": 34,
|
|
9
|
+
"z": 3,
|
|
10
|
+
"originX": 0,
|
|
11
|
+
"originY": 0
|
|
12
|
+
},
|
|
13
|
+
"Box": {
|
|
14
|
+
"color": "#ff79c6",
|
|
15
|
+
"edge": "#8c3f6b",
|
|
16
|
+
"radius": 17,
|
|
17
|
+
"showFacing": true
|
|
18
|
+
},
|
|
19
|
+
"Collider": {
|
|
20
|
+
"shapes": [
|
|
21
|
+
{
|
|
22
|
+
"type": "circle",
|
|
23
|
+
"x": 0.5,
|
|
24
|
+
"y": 0.5,
|
|
25
|
+
"r": 0.5
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"friction": 0.05,
|
|
29
|
+
"bounciness": 0
|
|
30
|
+
},
|
|
31
|
+
"RigidBody": {
|
|
32
|
+
"bodyType": "kinematic",
|
|
33
|
+
"gravityScale": 0,
|
|
34
|
+
"drag": 0,
|
|
35
|
+
"freezeRotation": true
|
|
36
|
+
}
|
|
10
37
|
}
|
|
11
38
|
}
|
|
12
39
|
]
|
|
@@ -3,12 +3,44 @@
|
|
|
3
3
|
"actors": [
|
|
4
4
|
{
|
|
5
5
|
"components": {
|
|
6
|
-
"Layout": {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
"Layout": {
|
|
7
|
+
"width": 34,
|
|
8
|
+
"height": 34,
|
|
9
|
+
"z": 3,
|
|
10
|
+
"originX": 0,
|
|
11
|
+
"originY": 0
|
|
12
|
+
},
|
|
13
|
+
"Box": {
|
|
14
|
+
"color": "#8be9fd",
|
|
15
|
+
"edge": "#3f7f8c",
|
|
16
|
+
"radius": 17,
|
|
17
|
+
"showFacing": true
|
|
18
|
+
},
|
|
19
|
+
"Collider": {
|
|
20
|
+
"shapes": [
|
|
21
|
+
{
|
|
22
|
+
"type": "circle",
|
|
23
|
+
"x": 0.5,
|
|
24
|
+
"y": 0.5,
|
|
25
|
+
"r": 0.5
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"friction": 0.05,
|
|
29
|
+
"bounciness": 0
|
|
30
|
+
},
|
|
31
|
+
"RigidBody": {
|
|
32
|
+
"bodyType": "dynamic",
|
|
33
|
+
"gravityScale": 0,
|
|
34
|
+
"drag": 0.3,
|
|
35
|
+
"freezeRotation": true
|
|
36
|
+
},
|
|
37
|
+
"Player": {
|
|
38
|
+
"speed": 4
|
|
39
|
+
},
|
|
40
|
+
"AnalogStick": {
|
|
41
|
+
"speed": 4,
|
|
42
|
+
"maxRadius": 70
|
|
43
|
+
}
|
|
12
44
|
}
|
|
13
45
|
}
|
|
14
46
|
]
|
|
@@ -3,9 +3,31 @@
|
|
|
3
3
|
"actors": [
|
|
4
4
|
{
|
|
5
5
|
"components": {
|
|
6
|
-
"Layout": {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
"Layout": {
|
|
7
|
+
"width": 100,
|
|
8
|
+
"height": 24,
|
|
9
|
+
"z": 1,
|
|
10
|
+
"originX": 0,
|
|
11
|
+
"originY": 0
|
|
12
|
+
},
|
|
13
|
+
"Box": {
|
|
14
|
+
"color": "#2b2d3d",
|
|
15
|
+
"edge": "#3d4159",
|
|
16
|
+
"radius": 2
|
|
17
|
+
},
|
|
18
|
+
"Collider": {
|
|
19
|
+
"shapes": [
|
|
20
|
+
{
|
|
21
|
+
"type": "box",
|
|
22
|
+
"x": 0.5,
|
|
23
|
+
"y": 0.5,
|
|
24
|
+
"w": 1,
|
|
25
|
+
"h": 1
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"friction": 0.1,
|
|
29
|
+
"bounciness": 0
|
|
30
|
+
}
|
|
9
31
|
}
|
|
10
32
|
}
|
|
11
33
|
]
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"imports": {
|
|
16
16
|
"castle.real-time": {
|
|
17
17
|
"deckId": "xFVr-afOLuUQ",
|
|
18
|
-
"version": "2026-09-
|
|
18
|
+
"version": "2026-09-16T21:18:06.448Z"
|
|
19
19
|
},
|
|
20
20
|
"castle.physics-2d": {
|
|
21
21
|
"deckId": "ckRZGFW4iPrx",
|
|
22
|
-
"version": "2026-09-
|
|
22
|
+
"version": "2026-09-16T21:17:53.144Z"
|
|
23
23
|
},
|
|
24
24
|
"castle.base": {
|
|
25
25
|
"deckId": "yRcmH4_aYllE",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
},
|
|
36
36
|
"deckId": "oiFu96LkwZ09",
|
|
37
37
|
"cardId": "nkJgrvrCby3H",
|
|
38
|
-
"publishedVersion": "2026-09-
|
|
38
|
+
"publishedVersion": "2026-09-16T21:20:14.363Z"
|
|
39
39
|
}
|
|
@@ -7,10 +7,10 @@ import path from 'path';
|
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { createRequire } from 'module';
|
|
9
9
|
|
|
10
|
-
const require = createRequire('/
|
|
11
|
-
// Playwright
|
|
12
|
-
//
|
|
13
|
-
const { chromium } = require('playwright');
|
|
10
|
+
const require = createRequire(new URL('../../../cli/package.json', import.meta.url));
|
|
11
|
+
// Playwright is a CLI dependency. Workspace browser automation is restricted to
|
|
12
|
+
// Castle decks, and both pages opened here are this served deck.
|
|
13
|
+
const { chromium } = require('playwright-core');
|
|
14
14
|
|
|
15
15
|
const deckDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
16
16
|
|
|
@@ -99,8 +99,11 @@ File names stay lowercase.
|
|
|
99
99
|
Identity comes from `player.playerId` / `player.userId`, never from a body.
|
|
100
100
|
- The kit ships `code/systems/multiplayer.js`, the frame loop. A deck that writes
|
|
101
101
|
its own file of that path gets its own instead; most decks should not.
|
|
102
|
-
- Two players is the test that matters: `castle-web serve`,
|
|
103
|
-
two tabs
|
|
102
|
+
- Two players is the test that matters: run `castle-web serve`, open the shell
|
|
103
|
+
URL it prints in two tabs, and open the Play panel in each. If you use
|
|
104
|
+
`.castle/serve.json`'s `contentPlayUrl` directly, open `/index.html?edit=0`;
|
|
105
|
+
its bare origin is the edit surface, where multiplayer does not join. The room
|
|
106
|
+
persists in deck storage across serve restarts; a fresh one
|
|
104
107
|
means removing its `world:<room>`, `game:<room>` and `player:<room>:*` rows
|
|
105
108
|
(the local serve's room is `dev`).
|
|
106
109
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"imports": {
|
|
15
15
|
"castle.real-time": {
|
|
16
16
|
"deckId": "xFVr-afOLuUQ",
|
|
17
|
-
"version": "2026-09-
|
|
17
|
+
"version": "2026-09-16T21:18:06.448Z"
|
|
18
18
|
},
|
|
19
19
|
"castle.physics-3d": {
|
|
20
20
|
"deckId": "JH0SclbPVP0y",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"castle.physics-2d": {
|
|
24
24
|
"deckId": "ckRZGFW4iPrx",
|
|
25
|
-
"version": "2026-09-
|
|
25
|
+
"version": "2026-09-16T21:17:53.144Z",
|
|
26
26
|
"via": "castle.physics-3d"
|
|
27
27
|
},
|
|
28
28
|
"castle.base": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"autoUpdateWhenImported": true,
|
|
34
34
|
"deckId": "ZwA_P_-VO-Qh",
|
|
35
35
|
"cardId": "bvRmCzyUpt_a",
|
|
36
|
-
"publishedVersion": "2026-09-
|
|
36
|
+
"publishedVersion": "2026-09-16T21:20:24.084Z",
|
|
37
37
|
"main": "main.jsx",
|
|
38
38
|
"server": {
|
|
39
39
|
"main": "code/server/index.js",
|