castle-web-cli 0.4.149 → 0.4.151

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 (49) hide show
  1. package/dist/agent.d.ts +1 -0
  2. package/dist/agent.js +12 -4
  3. package/dist/api.d.ts +45 -1
  4. package/dist/api.js +34 -2
  5. package/dist/castle-host/host.d.ts +17 -0
  6. package/dist/castle-host/host.js +10 -7
  7. package/dist/castleJson.d.ts +15 -0
  8. package/dist/castleJson.js +36 -0
  9. package/dist/devSessionChild.d.ts +1 -0
  10. package/dist/devSessionChild.js +129 -0
  11. package/dist/devSessionServer.d.ts +19 -0
  12. package/dist/devSessionServer.js +511 -0
  13. package/dist/headlessCover.js +28 -0
  14. package/dist/index.js +8 -8
  15. package/dist/init.js +9 -1
  16. package/dist/list-decks.js +7 -6
  17. package/dist/native/playtest-remote.d.ts +3 -0
  18. package/dist/native/playtest-remote.js +113 -0
  19. package/dist/preview.d.ts +1 -1
  20. package/dist/preview.js +4 -2
  21. package/dist/save-deck.js +82 -16
  22. package/dist/serve.js +245 -88
  23. package/dist/serveSecurity.d.ts +7 -1
  24. package/dist/serveSecurity.js +61 -10
  25. package/dist/serverBundle.d.ts +8 -0
  26. package/dist/serverBundle.js +82 -0
  27. package/dist/shell/assets/{index-BzFzFtEP.js → index-Dlhc3eZW.js} +42 -42
  28. package/dist/shell/assets/index-DwezawBs.css +1 -0
  29. package/dist/shell/index.html +2 -2
  30. package/kits/blank/.castle/agent/children.json +1 -0
  31. package/kits/blank/.castle/agent/messages.json +9 -0
  32. package/kits/blank/.castle/agent/pending-sends.json +1 -0
  33. package/kits/blank/.castle/agent/tasks/index.md +2 -0
  34. package/kits/blank/.castle/docs/platform.md +36 -0
  35. package/kits/blank/castle.json +5 -2
  36. package/kits/blank/node_modules/.vite/deps/_metadata.json +8 -0
  37. package/kits/blank/node_modules/.vite/deps/package.json +3 -0
  38. package/kits/physics-2d/behaviors/Collider.jsx +1 -2
  39. package/kits/physics-2d/behaviors/Joints.jsx +1 -1
  40. package/kits/physics-2d/castle.json +1 -1
  41. package/kits/physics-2d/editors/BlueprintLibrary.jsx +33 -3
  42. package/kits/physics-2d/editors/SceneEditor.jsx +171 -57
  43. package/kits/physics-2d/editors/SingleEditor.jsx +6 -0
  44. package/kits/physics-2d/engine/blueprint.js +106 -14
  45. package/kits/physics-2d/engine/scene.js +9 -2
  46. package/kits/physics-2d/engine/ui.jsx +30 -2
  47. package/kits/physics-2d/engine/ui.module.css +59 -0
  48. package/package.json +1 -1
  49. package/dist/shell/assets/index-DN8HQBnW.css +0 -1
@@ -6,7 +6,7 @@
6
6
  // panel propagates to every scene that places it. Shared by the runtime
7
7
  // (`scene.js`, so play mode and `PlayOnly` resolve blueprints too) and the
8
8
  // editors (which also mint/fork/migrate/cascade-delete blueprint files).
9
- import { resolveDeckFile } from 'castle-web-sdk';
9
+ import { deckPrefixOf, IMPORTS_DIR, IMPORTS_PREFIX, resolveDeckFile } from 'castle-web-sdk';
10
10
  import { formatJson } from './files';
11
11
  import { DEFAULT_RESOLUTION, TRANSPARENT, serializeCompact } from './pxart';
12
12
  import { cardSize, dedupeActorId } from './scene';
@@ -29,6 +29,15 @@ export function isImportedPath(path) {
29
29
  return typeof path === 'string' && path.startsWith('imports/');
30
30
  }
31
31
 
32
+ // Which import owns a file, by the alias it was installed under:
33
+ // `imports/castle.physics-2d/blueprints/ball.scene` -> `castle.physics-2d`.
34
+ // Null for a file of this deck's own. For naming the source in the UI, so takes
35
+ // a whole-deck key rather than a ref.
36
+ export function importAliasOf(path) {
37
+ const prefix = deckPrefixOf(path ?? '');
38
+ return prefix ? prefix.slice(IMPORTS_DIR.length + 1, -1) : null;
39
+ }
40
+
32
41
  // Per-property inherit metadata for a behavior prop. Behaviors opt a prop out
33
42
  // of inheritance via `static propertyMeta = { propName: { inherit: false } }`
34
43
  // (see behaviors/Layout.jsx for x/y/rotation); anything absent defaults to
@@ -90,6 +99,40 @@ function resolveRefsIn(props, files, fromPath) {
90
99
  }
91
100
  }
92
101
 
102
+ // The inverse, for the write side. A resolved key is a fact about the whole
103
+ // deck; a stored ref is relative to the file holding it. So components moving
104
+ // INTO `toPath` have to be restated from there, or they name a different file
105
+ // -- or none -- the next time anything reads them.
106
+ //
107
+ // Same traversal and the same duck-typing guard as the read: only a string that
108
+ // names a real file is a ref. That guard bites harder here (a false positive
109
+ // persists rather than dirtying an object), but the two sides have to agree on
110
+ // what a ref is, and this is all either of them has to go on.
111
+ function reprojectRefsIn(props, files, toPath) {
112
+ for (const [key, value] of Object.entries(props ?? {})) {
113
+ if (typeof value === 'string' && value) {
114
+ if (files?.[value] === undefined) continue;
115
+ const ref = refFor(value, toPath);
116
+ if (ref !== value) props[key] = ref;
117
+ } else if (value && typeof value === 'object' && !Array.isArray(value)) {
118
+ reprojectRefsIn(value, files, toPath);
119
+ }
120
+ }
121
+ }
122
+
123
+ // A files-map key as a file at `toPath` has to write it: relative when the key
124
+ // is in that file's own deck, `@imports/...` when it is in another's. Left
125
+ // alone otherwise -- including a key already written relative, which is why
126
+ // this is safe on components that were never resolved.
127
+ function refFor(key, toPath) {
128
+ const prefix = deckPrefixOf(toPath);
129
+ if (prefix && key.startsWith(prefix)) return key.slice(prefix.length);
130
+ if (key.startsWith(`${IMPORTS_DIR}/`)) {
131
+ return `${IMPORTS_PREFIX}${key.slice(IMPORTS_DIR.length + 1)}`;
132
+ }
133
+ return key;
134
+ }
135
+
93
136
  // Resolve a blueprint's template from the LIVE files map -- the load-bearing
94
137
  // call for live propagation. Returns null when the file is missing, deleted,
95
138
  // or malformed (a dangling `blueprint` ref degrades to "no template" rather
@@ -292,7 +335,13 @@ export function setBlueprintTemplateComponents(files, blueprintPath, components)
292
335
  return null;
293
336
  }
294
337
  if (!data?.actors?.[0]) return null;
295
- data.actors[0].components = components;
338
+ // Callers hand back what they read, and reads resolve (`resolveTemplateRefs`).
339
+ // Storing that verbatim is only harmless for a blueprint of this deck's own,
340
+ // where resolving was the identity; inside an import it puts a whole-deck key
341
+ // where a ref belongs. Cloned first -- the caller's object is the caller's.
342
+ const next = structuredClone(components);
343
+ for (const props of Object.values(next ?? {})) reprojectRefsIn(props, files, blueprintPath);
344
+ data.actors[0].components = next;
296
345
  return formatJson(data);
297
346
  }
298
347
 
@@ -304,12 +353,21 @@ export function mintBlueprintFile(files, components) {
304
353
  const existing = listBlueprints(files);
305
354
  const name = mintBlueprintName(existing.map((blueprint) => blueprint.name));
306
355
  const path = mintBlueprintPath(existing.map((blueprint) => blueprint.path));
307
- return { path, name, text: formatBlueprintFileText(name, components) };
356
+ // The components may describe a file this one is not: new-blueprint-from-actor
357
+ // hands over an import's template, merged, and merging read it -- so its refs
358
+ // are whole-deck keys. Restate them from `path` before they are written, the
359
+ // same as any other write. Callers minting their own deck-root components pass
360
+ // through untouched, and so does a ref to a file being minted alongside this
361
+ // one, which is not in `files` to be recognised yet.
362
+ const next = structuredClone(components);
363
+ for (const props of Object.values(next ?? {})) reprojectRefsIn(props, files, path);
364
+ return { path, name, text: formatBlueprintFileText(name, next) };
308
365
  }
309
366
 
310
367
  // Split a resolved component's props into { inherited, overridden } by each
311
- // prop's propertyMeta. Used by migration and fork to decide what belongs in a
312
- // new blueprint template vs. what must stay an explicit instance value.
368
+ // prop's propertyMeta. Used by migration and by new-blueprint-from-actor to
369
+ // decide what belongs in a new blueprint template vs. what must stay an
370
+ // explicit instance value.
313
371
  function splitByInherit(Behavior, props) {
314
372
  const inherited = {};
315
373
  const overridden = {};
@@ -587,7 +645,11 @@ export function placeBlueprintInstance(sceneData, files, blueprintPath, position
587
645
  // Reparent the instance to the new blueprint, keeping only its non-inherited
588
646
  // prop values (Layout position et al) as instance overrides -- everything
589
647
  // else now matches the new template exactly, so no override is needed for it.
590
- export function forkActorToBlueprint(files, behaviors, sceneData, actorId) {
648
+ //
649
+ // Additive and local: a NEW file, and only the one actor follows it. Not to be
650
+ // confused with forking, which is a file operation on somebody else's file --
651
+ // same path, this deck's bytes, and every instance in the deck follows.
652
+ export function newBlueprintFromActor(files, behaviors, sceneData, actorId) {
591
653
  const next = structuredClone(sceneData);
592
654
  const actor = next.actors?.find((candidate) => candidate.id === actorId);
593
655
  if (!actor) return null;
@@ -633,13 +695,38 @@ function parseSceneFiles(files) {
633
695
  return out;
634
696
  }
635
697
 
636
- // Every `scenes/*.scene` file's actor count referencing a blueprint, for the
637
- // delete-confirm dialog and the library's per-blueprint badge.
638
- export function countBlueprintInstances(files, blueprintPath) {
698
+ // Whether an actor is an instance of the blueprint at whole-deck key
699
+ // `blueprintPath`. An actor's `blueprint` is a ref as WRITTEN in the scene at
700
+ // `fromPath`, so the two are not comparable as strings: an instance of an
701
+ // import's blueprint placed in this deck says `@imports/<alias>/...` and matches
702
+ // no key at all, and an actor in the import's OWN scene says a bare
703
+ // `blueprints/ball.scene` that matches this deck's same-named blueprint instead.
704
+ export function actorUsesBlueprint(actor, blueprintPath, fromPath) {
705
+ if (!actor?.blueprint || !blueprintPath) return false;
706
+ return resolveDeckFile(actor.blueprint, fromPath) === blueprintPath;
707
+ }
708
+
709
+ // How many placed actors reference a blueprint. The deck's own `scenes/` by
710
+ // default, which is what the delete-confirm needs: it promises how many actors
711
+ // a delete removes, and the cascade only rewrites this deck's files.
712
+ //
713
+ // `alsoScenePath` adds one more scene to the scan, for the inspector's badge.
714
+ // The open scene can belong to an import, and a badge reading "0 actors" over a
715
+ // scene visibly full of them is just wrong -- even though none of those actors
716
+ // is this deck's to delete.
717
+ export function countBlueprintInstances(files, blueprintPath, alsoScenePath) {
718
+ const scenes = parseSceneFiles(files);
719
+ if (alsoScenePath && !scenes.some((scene) => scene.path === alsoScenePath)) {
720
+ try {
721
+ scenes.push({ path: alsoScenePath, data: JSON.parse(files?.[alsoScenePath] ?? '') });
722
+ } catch {
723
+ // Mid-edit invalid JSON just doesn't count, as in `parseSceneFiles`.
724
+ }
725
+ }
639
726
  let count = 0;
640
- for (const { data } of parseSceneFiles(files)) {
727
+ for (const { path, data } of scenes) {
641
728
  for (const actor of data?.actors ?? []) {
642
- if (actor?.blueprint === blueprintPath) count += 1;
729
+ if (actorUsesBlueprint(actor, blueprintPath, path)) count += 1;
643
730
  }
644
731
  }
645
732
  return count;
@@ -655,7 +742,7 @@ export function cascadeDeleteBlueprint(files, blueprintPath) {
655
742
  const writes = [];
656
743
  for (const { path, data } of parseSceneFiles(files)) {
657
744
  const actors = data.actors ?? [];
658
- const filtered = actors.filter((actor) => actor?.blueprint !== blueprintPath);
745
+ const filtered = actors.filter((actor) => !actorUsesBlueprint(actor, blueprintPath, path));
659
746
  if (filtered.length !== actors.length) {
660
747
  writes.push({ path, text: formatJson({ ...data, actors: filtered }) });
661
748
  }
@@ -738,9 +825,14 @@ export function renameBlueprintCascade(files, blueprintPath, nextName) {
738
825
  const writes = [{ path: nextPath, text: formatBlueprintFileText(name, components) }];
739
826
  for (const { path, data } of parseSceneFiles(files)) {
740
827
  const actors = data.actors ?? [];
741
- if (!actors.some((actor) => actor?.blueprint === blueprintPath)) continue;
828
+ if (!actors.some((actor) => actorUsesBlueprint(actor, blueprintPath, path))) continue;
829
+ // `nextPath` is a whole-deck key and an actor's `blueprint` is a ref, so it
830
+ // has to be restated from the scene that will hold it -- the same as any
831
+ // other ref being written (`reprojectRefsIn`).
742
832
  const rewritten = actors.map((actor) =>
743
- actor?.blueprint === blueprintPath ? { ...actor, blueprint: nextPath } : actor
833
+ actorUsesBlueprint(actor, blueprintPath, path)
834
+ ? { ...actor, blueprint: refFor(nextPath, path) }
835
+ : actor
744
836
  );
745
837
  writes.push({ path, text: formatJson({ ...data, actors: rewritten }) });
746
838
  }
@@ -1,6 +1,6 @@
1
1
  import { resolveDeckFile } from 'castle-web-sdk';
2
2
  import { initialFiles, parseJsonFile } from './files';
3
- import { getBlueprintTemplate, mergeComponents } from './blueprint';
3
+ import { actorUsesBlueprint, getBlueprintTemplate, mergeComponents } from './blueprint';
4
4
  import { getColliderRect, intersects, spriteIsEmpty } from './collider';
5
5
  import { systemInstallers } from './systemRegistry';
6
6
 
@@ -156,6 +156,13 @@ export class SceneRuntime {
156
156
  return this.actors.get(actorId);
157
157
  }
158
158
 
159
+ // `actorUsesBlueprint` against this scene's own path. Behaviors get the scene
160
+ // handed to `draw`, so this is how they answer "is the hotbar's selection mine"
161
+ // without having to know where the scene lives.
162
+ usesBlueprint(actor, blueprintPath) {
163
+ return actorUsesBlueprint(actor, blueprintPath, this.scenePath);
164
+ }
165
+
159
166
  getActors() {
160
167
  return [...this.actors.values()].sort((a, b) => {
161
168
  const az = getLayout(a)?.z ?? 0;
@@ -417,7 +424,7 @@ export class SceneRuntime {
417
424
  // Per-actor transform: Layout's `rotation` (degrees) rotates every draw
418
425
  // behavior of the actor about its center.
419
426
  ctx.save();
420
- if (dimBlueprintPath && actor.blueprint !== dimBlueprintPath) {
427
+ if (dimBlueprintPath && !this.usesBlueprint(actor, dimBlueprintPath)) {
421
428
  ctx.globalAlpha = 0.2;
422
429
  }
423
430
  applyLayoutRotation(ctx, getLayout(actor));
@@ -231,6 +231,13 @@ const icons = {
231
231
  clone: faClone,
232
232
  code: faCode,
233
233
  // FA5 has no faCodeFork (that's the FA6 name); faCodeBranch is the fork glyph.
234
+ //
235
+ // Reserved for forking a FILE -- taking this deck's own version of one an
236
+ // import owns -- which is what it means in the shell's file tree and editor
237
+ // banner too. Nothing in this kit draws it since the actor action became
238
+ // `clone`; kept because a deck or a kit pinned to an older physics-2d may
239
+ // still ask for it by name, and an unused entry costs less than a missing
240
+ // glyph on somebody else's screen.
234
241
  'code-fork': faCodeBranch,
235
242
  'dot-circle': faDotCircle,
236
243
  'draw-polygon': faDrawPolygon,
@@ -316,6 +323,10 @@ export function BehaviorPanel({
316
323
  enabled = true,
317
324
  onToggleEnabled = null,
318
325
  dragging = false,
326
+ // The inspected file can't be written. Only the panel's BODY is blocked: the
327
+ // header's collapse and drag, and the View source link, read rather than
328
+ // write, and are most of what a file you can't edit is still good for.
329
+ readOnly = false,
319
330
  children,
320
331
  }) {
321
332
  const value = React.useMemo(
@@ -329,8 +340,20 @@ export function BehaviorPanel({
329
340
  enabled,
330
341
  onToggleEnabled,
331
342
  dragging,
343
+ readOnly,
332
344
  }),
333
- [summary, collapsed, onToggle, handleProps, onViewSource, onRemove, enabled, onToggleEnabled, dragging]
345
+ [
346
+ summary,
347
+ collapsed,
348
+ onToggle,
349
+ handleProps,
350
+ onViewSource,
351
+ onRemove,
352
+ enabled,
353
+ onToggleEnabled,
354
+ dragging,
355
+ readOnly,
356
+ ]
334
357
  );
335
358
  return <BehaviorPanelContext.Provider value={value}>{children}</BehaviorPanelContext.Provider>;
336
359
  }
@@ -431,7 +454,12 @@ export function Panel({ title, action, children, overridden = false }) {
431
454
  </div>
432
455
  )}
433
456
  {collapsed ? null : (
434
- <div className={cx(styles.panelBody, behavior?.enabled === false && styles.panelBodyOff)}>
457
+ <div
458
+ className={cx(
459
+ styles.panelBody,
460
+ behavior?.enabled === false && styles.panelBodyOff,
461
+ behavior?.readOnly && styles.inspectorFieldsLocked
462
+ )}>
435
463
  {children}
436
464
  </div>
437
465
  )}
@@ -1045,6 +1045,65 @@
1045
1045
  background: var(--castle-inspector-input-bg);
1046
1046
  }
1047
1047
 
1048
+ /* An import's blueprint: still selectable so the name can be read and copied,
1049
+ but the hover and focus borders would offer an edit that won't be taken. */
1050
+ .blueprintNameInputLocked,
1051
+ .blueprintNameInputLocked:hover,
1052
+ .blueprintNameInputLocked:focus {
1053
+ border-color: transparent;
1054
+ background: transparent;
1055
+ color: var(--castle-text-dim);
1056
+ cursor: default;
1057
+ }
1058
+
1059
+ /* Whose blueprint this is, above the inspector when the hotbar's selection
1060
+ belongs to an import. The shell's editor banner describes the OPEN file, so
1061
+ it says nothing about a blueprint selected inside a scene; this fills that
1062
+ gap and uses the same wording. The column is narrow, so the text ellipsizes
1063
+ and the full path is on the title attribute. */
1064
+ .blueprintProvenance {
1065
+ display: flex;
1066
+ align-items: center;
1067
+ gap: 6px;
1068
+ padding: 8px;
1069
+ border-bottom: 1px solid var(--castle-inspector-divider);
1070
+ background: var(--castle-inspector-bg);
1071
+ color: var(--castle-text-dim);
1072
+ font-size: 12px;
1073
+ }
1074
+
1075
+ .blueprintProvenanceChip {
1076
+ flex: 0 0 auto;
1077
+ padding: 2px 8px;
1078
+ border: 1px solid var(--castle-inspector-divider);
1079
+ border-radius: 999px;
1080
+ background: var(--castle-workspace-bg);
1081
+ letter-spacing: 0.02em;
1082
+ line-height: 1.4;
1083
+ }
1084
+
1085
+ /* A forked blueprint is editable, so its chip should not read like the locked
1086
+ one -- same distinction the shell's banner makes. */
1087
+ .blueprintProvenanceForked {
1088
+ color: var(--castle-inspector-text);
1089
+ }
1090
+
1091
+ .blueprintProvenanceText {
1092
+ min-width: 0;
1093
+ overflow: hidden;
1094
+ text-overflow: ellipsis;
1095
+ white-space: nowrap;
1096
+ }
1097
+
1098
+ /* A behavior panel's fields when the inspected file can't be written -- an
1099
+ import's blueprint. Just the fields: the panel header keeps View source and
1100
+ its collapse toggle, which read rather than write. Same treatment the pxart
1101
+ editor gives its read-only panels (.drawingReadOnly). */
1102
+ .inspectorFieldsLocked {
1103
+ opacity: 0.45;
1104
+ pointer-events: none;
1105
+ }
1106
+
1048
1107
  .stageWrap {
1049
1108
  grid-column: 1;
1050
1109
  grid-row: 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.149",
3
+ "version": "0.4.151",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "castle-web": "./dist/index.js"