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.
Files changed (75) hide show
  1. package/dist/agent.js +87 -4
  2. package/dist/api.d.ts +1 -0
  3. package/dist/api.js +5 -0
  4. package/dist/bundle.js +2 -1
  5. package/dist/castleJson.d.ts +1 -0
  6. package/dist/check.js +14 -6
  7. package/dist/devSessionServer.d.ts +6 -0
  8. package/dist/devSessionServer.js +23 -1
  9. package/dist/filesChanged.js +7 -3
  10. package/dist/importUpdateHook.d.ts +31 -0
  11. package/dist/importUpdateHook.js +135 -0
  12. package/dist/importUpdateHookRunner.d.ts +2 -0
  13. package/dist/importUpdateHookRunner.js +24 -0
  14. package/dist/imports.js +56 -6
  15. package/dist/index.js +58 -7
  16. package/dist/init.d.ts +1 -0
  17. package/dist/init.js +6 -1
  18. package/dist/native/loop.js +29 -9
  19. package/dist/platformDoc.js +4 -4
  20. package/dist/remix.js +4 -1
  21. package/dist/serve.js +133 -32
  22. package/dist/serverBundle.js +1 -1
  23. package/dist/versions.d.ts +14 -0
  24. package/dist/versions.js +21 -0
  25. package/dist/vitePlugins.d.ts +1 -0
  26. package/dist/vitePlugins.js +18 -0
  27. package/kits/multiplayer-2d/CLAUDE.md +9 -2
  28. package/kits/multiplayer-2d/blueprints/crate.scene +32 -4
  29. package/kits/multiplayer-2d/blueprints/other-player.scene +31 -4
  30. package/kits/multiplayer-2d/blueprints/player.scene +38 -6
  31. package/kits/multiplayer-2d/blueprints/wall.scene +25 -3
  32. package/kits/multiplayer-2d/castle.json +3 -3
  33. package/kits/multiplayer-2d/test/two-client-test.mjs +4 -4
  34. package/kits/multiplayer-3d/CLAUDE.md +5 -2
  35. package/kits/multiplayer-3d/castle.json +3 -3
  36. package/kits/multiplayer-3d/scenes/main.scene +128 -0
  37. package/kits/physics-2d/CLAUDE.md +11 -5
  38. package/kits/physics-2d/behaviors/Camera.jsx +5 -6
  39. package/kits/physics-2d/behaviors/Goal.jsx +5 -2
  40. package/kits/physics-2d/behaviors/Joints.jsx +4 -3
  41. package/kits/physics-2d/behaviors/Layout.jsx +120 -3
  42. package/kits/physics-2d/behaviors/Sprite.jsx +9 -9
  43. package/kits/physics-2d/behaviors/Style.jsx +22 -15
  44. package/kits/physics-2d/behaviors/Text.jsx +7 -6
  45. package/kits/physics-2d/blueprints/ball.scene +27 -5
  46. package/kits/physics-2d/blueprints/block.scene +16 -3
  47. package/kits/physics-2d/blueprints/cauldron.scene +3 -1
  48. package/kits/physics-2d/blueprints/crate.scene +23 -4
  49. package/kits/physics-2d/blueprints/goal.scene +12 -2
  50. package/kits/physics-2d/blueprints/text.scene +13 -3
  51. package/kits/physics-2d/castle.json +2 -1
  52. package/kits/physics-2d/editors/SceneEditor.jsx +26 -2
  53. package/kits/physics-2d/editors/SelectionOverlay.jsx +27 -20
  54. package/kits/physics-2d/engine/blueprint.js +111 -54
  55. package/kits/physics-2d/engine/blueprintCore.js +59 -0
  56. package/kits/physics-2d/engine/collider.js +28 -17
  57. package/kits/physics-2d/engine/layout.js +61 -0
  58. package/kits/physics-2d/engine/layoutOriginMigration.js +223 -0
  59. package/kits/physics-2d/engine/physics/PhysicsSystem.js +11 -7
  60. package/kits/physics-2d/engine/physics/controls.js +4 -8
  61. package/kits/physics-2d/engine/physics/matterBridge.js +13 -8
  62. package/kits/physics-2d/engine/scene.js +38 -34
  63. package/kits/physics-2d/engine/spriteGeometry.js +17 -9
  64. package/kits/physics-2d/engine/tap.js +4 -3
  65. package/kits/physics-2d/scenes/main.scene +59 -6
  66. package/kits/physics-2d/scenes/sandbox.scene +69 -7
  67. package/kits/physics-2d/scripts/onUpdate.mjs +199 -0
  68. package/kits/real-time/castle.json +2 -2
  69. package/kits/real-time/code/server/persist.js +14 -0
  70. package/kits/turn-based/CLAUDE.md +12 -7
  71. package/kits/turn-based/blueprints/board.scene +3 -1
  72. package/kits/turn-based/blueprints/square.scene +3 -1
  73. package/kits/turn-based/castle.json +5 -3
  74. package/kits/turn-based/code/behaviors/Board.jsx +33 -21
  75. package/package.json +1 -1
@@ -1,3 +1,5 @@
1
+ import { layoutRect } from '../engine/layout';
2
+
1
3
  // Goal: a sensor zone that counts when a physics body enters it, and flashes
2
4
  // green briefly. Demonstrates the physics collision callbacks + a Collider with
3
5
  // `isTrigger: true`. Put it on an actor with a Layout and a trigger Collider.
@@ -19,13 +21,14 @@ export class Goal {
19
21
  }
20
22
 
21
23
  draw(actor, scene, ctx) {
22
- const layout = actor.components.Layout;
24
+ const box = layoutRect(actor.components.Layout);
25
+ if (!box) return;
23
26
  const lit = (actor.runtime.flashUntil ?? 0) > scene.time;
24
27
  ctx.save();
25
28
  ctx.strokeStyle = lit ? '#5ac54f' : 'rgba(255, 235, 87, 0.9)';
26
29
  ctx.lineWidth = 4;
27
30
  ctx.setLineDash([6, 4]);
28
- ctx.strokeRect(layout.x + 2, layout.y + 2, layout.width - 4, layout.height - 4);
31
+ ctx.strokeRect(box.x + 2, box.y + 2, box.width - 4, box.height - 4);
29
32
  ctx.restore();
30
33
  }
31
34
  }
@@ -1,7 +1,8 @@
1
1
  import React, { useState } from 'react';
2
2
  import { Panel, SelectField, NumberField, CheckboxField, Button } from '../engine/ui';
3
3
  import { SpriteField } from '../engine/spriteField';
4
- import { centerOf, inActorWorldSpace } from '../engine/physics/controls';
4
+ import { layoutCenter } from '../engine/layout';
5
+ import { inActorWorldSpace } from '../engine/physics/controls';
5
6
  import { JOINT_TYPES } from '../engine/physics/joints';
6
7
  import { drawJointArt } from '../engine/physics/jointArt';
7
8
 
@@ -55,12 +56,12 @@ export class Joints {
55
56
  const emphasized =
56
57
  options.colliderOverlayIds?.includes(actor.id) ||
57
58
  scene.usesBlueprint(actor, options.dimBlueprintPath);
58
- const a = centerOf(actor.components.Layout);
59
+ const a = layoutCenter(actor.components.Layout);
59
60
  inActorWorldSpace(ctx, actor.components.Layout, (g) => {
60
61
  for (const joint of list) {
61
62
  const target = joint?.target && scene.getActor(joint.target);
62
63
  if (!target || target.id === actor.id) continue;
63
- const b = centerOf(target.components.Layout);
64
+ const b = layoutCenter(target.components.Layout);
64
65
  // hidden shows as a faint line in the editor, nothing in play.
65
66
  let render = joint.render ?? 'line';
66
67
  if (editing && render === 'hidden') render = 'line';
@@ -1,3 +1,35 @@
1
+ import React from 'react';
2
+ import {
3
+ DEFAULT_ORIGIN_X,
4
+ DEFAULT_ORIGIN_Y,
5
+ layoutOriginX,
6
+ layoutOriginY,
7
+ layoutRect,
8
+ } from '../engine/layout';
9
+ import { Panel, SelectField } from '../engine/ui';
10
+ import { AutoFields } from '../engine/autoInspector';
11
+
12
+ // Origin picker: the two common anchors. Custom fractions still work in data;
13
+ // SelectField prepends an off-list value so it stays visible if one shows up.
14
+ const ORIGIN_PRESETS = [
15
+ {
16
+ value: `${DEFAULT_ORIGIN_X},${DEFAULT_ORIGIN_Y}`,
17
+ label: 'Center',
18
+ x: DEFAULT_ORIGIN_X,
19
+ y: DEFAULT_ORIGIN_Y,
20
+ },
21
+ { value: '0,0', label: 'Top left', x: 0, y: 0 },
22
+ ];
23
+
24
+ function originKey(x, y) {
25
+ return `${x},${y}`;
26
+ }
27
+
28
+ function findPreset(x, y) {
29
+ const key = originKey(x, y);
30
+ return ORIGIN_PRESETS.find((preset) => preset.value === key) ?? null;
31
+ }
32
+
1
33
  export class Layout {
2
34
  static behaviorName = 'Layout';
3
35
 
@@ -8,6 +40,13 @@ export class Layout {
8
40
  rotation: 0,
9
41
  width: 50,
10
42
  height: 50,
43
+ // Which point of the box `x`/`y` names, as a fraction of the box from its
44
+ // own top-left: `0, 0` top-left, `0.5, 0.5` center (the default, and what
45
+ // an absent origin means -- see DEFAULT_ORIGIN_* in engine/layout.js),
46
+ // `1, 1` bottom-right. Not clamped. Rotation still pivots on the box
47
+ // CENTER -- the origin anchors position only.
48
+ originX: DEFAULT_ORIGIN_X,
49
+ originY: DEFAULT_ORIGIN_Y,
11
50
  // Show the Layout box (the invisible frame the sprite fills and the collider
12
51
  // derives from) as a dashed outline, in editor and play. Per-actor toggle.
13
52
  debug: false,
@@ -25,7 +64,10 @@ export class Layout {
25
64
  // on spawn), and a blueprint edit to its own template x/y/z/rotation only
26
65
  // affects newly placed instances, never moves ones already placed. Because
27
66
  // they're always instance-local, they're also never surfaced as blueprint
28
- // "overrides" in the inspector. width/height default to inherited (absent).
67
+ // "overrides" in the inspector. width/height default to inherited (absent),
68
+ // and so does the origin: it describes the KIND of thing (a ball is placed by
69
+ // its center), so it belongs on the blueprint -- with a per-instance override
70
+ // available like any other inherited prop.
29
71
  //
30
72
  // Size is width/height in card units -- the same space you compose in. A
31
73
  // user-facing scaleX/scaleY (relative to the sprite's native pixels) was
@@ -49,12 +91,87 @@ export class Layout {
49
91
  // so it reads separately from the solid collider debug and the selection box.
50
92
  draw(actor, scene, ctx) {
51
93
  if (!this.props.debug) return;
52
- const { x, y, width, height } = this.props;
94
+ const rect = layoutRect(this.props);
53
95
  ctx.save();
54
96
  ctx.strokeStyle = 'rgba(190, 178, 255, 0.75)';
55
97
  ctx.setLineDash([4, 3]);
56
98
  ctx.lineWidth = 1.5;
57
- ctx.strokeRect(x + 0.5, y + 0.5, width - 1, height - 1);
99
+ ctx.strokeRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1, rect.height - 1);
58
100
  ctx.restore();
59
101
  }
102
+
103
+ // Hand-written rather than AutoInspector's default, only for the origin: a
104
+ // Top left / Center select is clearer than two bare fraction fields, and it
105
+ // has to rewrite x/y alongside the origin (see OriginFields).
106
+ static Inspector({ component, setComponent, override }) {
107
+ return (
108
+ <Panel title="Layout" overridden={override?.anyOverridden()}>
109
+ <AutoFields
110
+ defaultProps={Layout.defaultProps}
111
+ meta={Layout.propertyMeta}
112
+ component={component}
113
+ setComponent={setComponent}
114
+ exclude={['originX', 'originY']}
115
+ override={override}
116
+ />
117
+ <OriginFields component={component} setComponent={setComponent} override={override} />
118
+ </Panel>
119
+ );
120
+ }
121
+ }
122
+
123
+ // Changing the origin moves x/y by exactly as much as it moved the anchor, so
124
+ // the box stays where it is on the card -- picking "Center" on a placed actor is
125
+ // a re-anchoring, not a move.
126
+ function OriginFields({ component, setComponent, override }) {
127
+ const originX = layoutOriginX(component);
128
+ const originY = layoutOriginY(component);
129
+ const preset = findPreset(originX, originY);
130
+ const value = preset?.value ?? originKey(originX, originY);
131
+ const setOrigin = (nextX, nextY) => {
132
+ const width = component.width ?? 0;
133
+ const height = component.height ?? 0;
134
+ setComponent({
135
+ originX: nextX,
136
+ originY: nextY,
137
+ x: (component.x ?? 0) + (nextX - originX) * width,
138
+ y: (component.y ?? 0) + (nextY - originY) * height,
139
+ });
140
+ };
141
+ const originOverridden = Boolean(
142
+ override?.isOverridden?.('originX') || override?.isOverridden?.('originY')
143
+ );
144
+ const baselineX = layoutOriginX({ originX: override?.baseline?.('originX') });
145
+ const baselineY = layoutOriginY({ originY: override?.baseline?.('originY') });
146
+ const baselinePreset = findPreset(baselineX, baselineY);
147
+ return (
148
+ <SelectField
149
+ label="Origin"
150
+ value={value}
151
+ options={ORIGIN_PRESETS}
152
+ onChange={(next) => {
153
+ const chosen = ORIGIN_PRESETS.find((preset) => preset.value === next);
154
+ if (!chosen) return;
155
+ setOrigin(chosen.x, chosen.y);
156
+ }}
157
+ overridden={originOverridden}
158
+ defaultValue={baselinePreset?.label ?? originKey(baselineX, baselineY)}
159
+ onReset={
160
+ originOverridden
161
+ ? () => {
162
+ const width = component.width ?? 0;
163
+ const height = component.height ?? 0;
164
+ // Keep the box put, then drop the origin overrides so the
165
+ // blueprint's values show through again.
166
+ setComponent({
167
+ x: (component.x ?? 0) + (baselineX - originX) * width,
168
+ y: (component.y ?? 0) + (baselineY - originY) * height,
169
+ });
170
+ override.reset('originX');
171
+ override.reset('originY');
172
+ }
173
+ : undefined
174
+ }
175
+ />
176
+ );
60
177
  }
@@ -215,13 +215,13 @@ function validTileSize(value) {
215
215
  // using the same per-edge-rounding discipline as the box snap in `draw`, so
216
216
  // neighboring tiles within this actor land on identical device pixels with
217
217
  // no hairline seams.
218
- function drawTilesSnapped(ctx, canvas, artSize, tileSize, layout, transform, x0, y0, rx0, ry0, rx1, ry1) {
218
+ function drawTilesSnapped(ctx, canvas, artSize, tileSize, dest, transform, x0, y0, rx0, ry0, rx1, ry1) {
219
219
  const cellHeight = validTileSize(tileSize);
220
220
  const cellWidth = cellHeight * (artSize.width / artSize.height);
221
221
  const cellDeviceWidth = cellWidth * transform.a;
222
222
  const cellDeviceHeight = cellHeight * transform.d;
223
- const cols = Math.ceil(layout.width / cellWidth);
224
- const rows = Math.ceil(layout.height / cellHeight);
223
+ const cols = Math.ceil(dest.width / cellWidth);
224
+ const rows = Math.ceil(dest.height / cellHeight);
225
225
  ctx.save();
226
226
  ctx.beginPath();
227
227
  ctx.rect(rx0, ry0, rx1 - rx0, ry1 - ry0);
@@ -240,19 +240,19 @@ function drawTilesSnapped(ctx, canvas, artSize, tileSize, layout, transform, x0,
240
240
 
241
241
  // Rotated actors have no axis-aligned device edges to snap to, so tile
242
242
  // unsnapped in card units, matching the unsnapped stretch fallback in `draw`.
243
- function drawTilesUnsnapped(ctx, canvas, artSize, tileSize, layout) {
243
+ function drawTilesUnsnapped(ctx, canvas, artSize, tileSize, dest) {
244
244
  const cellHeight = validTileSize(tileSize);
245
245
  const cellWidth = cellHeight * (artSize.width / artSize.height);
246
- const cols = Math.ceil(layout.width / cellWidth);
247
- const rows = Math.ceil(layout.height / cellHeight);
246
+ const cols = Math.ceil(dest.width / cellWidth);
247
+ const rows = Math.ceil(dest.height / cellHeight);
248
248
  ctx.save();
249
249
  ctx.beginPath();
250
- ctx.rect(layout.x, layout.y, layout.width, layout.height);
250
+ ctx.rect(dest.x, dest.y, dest.width, dest.height);
251
251
  ctx.clip();
252
252
  for (let row = 0; row < rows; row++) {
253
- const ty = layout.y + row * cellHeight;
253
+ const ty = dest.y + row * cellHeight;
254
254
  for (let col = 0; col < cols; col++) {
255
- const tx = layout.x + col * cellWidth;
255
+ const tx = dest.x + col * cellWidth;
256
256
  ctx.drawImage(canvas, tx, ty, cellWidth, cellHeight);
257
257
  }
258
258
  }
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { layoutRect } from '../engine/layout';
2
3
  import { PaletteColorField } from '../engine/paletteField';
3
4
  import { NumberField, Panel } from '../engine/ui';
4
5
  import { AutoFields, overrideProps } from '../engine/autoInspector';
@@ -153,12 +154,12 @@ function contentPaintsStyle(actor) {
153
154
  }
154
155
 
155
156
  function paintStyleChrome(actor, ctx, props) {
156
- const layout = actor.components.Layout;
157
- if (!layout || !props) return;
157
+ const box = layoutRect(actor.components.Layout);
158
+ if (!box || !props) return;
158
159
  const { background, border, borderWidth, borderRadius, opacity } = props;
159
160
  const alpha = Number.isFinite(opacity) ? Math.min(1, Math.max(0, opacity)) : 1;
160
161
  const bw = Math.max(0, Number(borderWidth) || 0);
161
- const radius = clampRadius(borderRadius, layout.width, layout.height);
162
+ const radius = clampRadius(borderRadius, box.width, box.height);
162
163
  const shadow = resolveShadow(props);
163
164
  const hasFill = Boolean(background);
164
165
  const hasBorder = Boolean(border) && bw > 0;
@@ -174,12 +175,12 @@ function paintStyleChrome(actor, ctx, props) {
174
175
  }
175
176
  if (hasFill) {
176
177
  ctx.fillStyle = background;
177
- fillRoundRect(ctx, layout.x, layout.y, layout.width, layout.height, radius);
178
+ fillRoundRect(ctx, box.x, box.y, box.width, box.height, radius);
178
179
  } else if (shadow) {
179
180
  // Shadow needs a filled path; use a near-invisible fill when there's no
180
181
  // background so the drop shadow still casts.
181
182
  ctx.fillStyle = 'rgba(0, 0, 0, 0.01)';
182
- fillRoundRect(ctx, layout.x, layout.y, layout.width, layout.height, radius);
183
+ fillRoundRect(ctx, box.x, box.y, box.width, box.height, radius);
183
184
  }
184
185
  if (shadow) {
185
186
  ctx.shadowColor = 'transparent';
@@ -195,10 +196,10 @@ function paintStyleChrome(actor, ctx, props) {
195
196
  // the same amount so the outer curve still matches the fill's corner.
196
197
  strokeRoundRect(
197
198
  ctx,
198
- layout.x + inset,
199
- layout.y + inset,
200
- Math.max(0, layout.width - bw),
201
- Math.max(0, layout.height - bw),
199
+ box.x + inset,
200
+ box.y + inset,
201
+ Math.max(0, box.width - bw),
202
+ Math.max(0, box.height - bw),
202
203
  Math.max(0, radius - inset)
203
204
  );
204
205
  }
@@ -251,15 +252,21 @@ export function stylePadding(actor) {
251
252
  return Number.isFinite(pad) ? Math.max(0, pad) : 0;
252
253
  }
253
254
 
254
- /** Layout box inset by Style.padding, or the layout itself when padding is 0. */
255
+ /**
256
+ * The world-space rect content draws into: the actor's Layout box (origin
257
+ * applied) inset by Style.padding. Always a real rect, never the `layout`
258
+ * component itself -- callers read `.x`/`.y` as a top-left, which a Layout with
259
+ * a non-zero origin is not.
260
+ */
255
261
  export function styleContentBox(actor, layout) {
262
+ const box = layoutRect(layout);
256
263
  const pad = stylePadding(actor);
257
- if (!(pad > 0) || !layout) return layout;
264
+ if (!box || !(pad > 0)) return box;
258
265
  return {
259
- x: layout.x + pad,
260
- y: layout.y + pad,
261
- width: Math.max(0, layout.width - pad * 2),
262
- height: Math.max(0, layout.height - pad * 2),
266
+ x: box.x + pad,
267
+ y: box.y + pad,
268
+ width: Math.max(0, box.width - pad * 2),
269
+ height: Math.max(0, box.height - pad * 2),
263
270
  };
264
271
  }
265
272
 
@@ -1,5 +1,6 @@
1
1
  import { writeFile } from 'castle-web-sdk';
2
2
  import React from 'react';
3
+ import { layoutRect } from '../engine/layout';
3
4
  import { drawTextBlock } from '../engine/text';
4
5
  import { PaletteColorField } from '../engine/paletteField';
5
6
  import {
@@ -56,8 +57,8 @@ export class Text {
56
57
  }
57
58
 
58
59
  paint(actor, scene, ctx) {
59
- const layout = actor.components.Layout;
60
- if (!layout) return;
60
+ const box = layoutRect(actor.components.Layout);
61
+ if (!box) return;
61
62
  const {
62
63
  text,
63
64
  font,
@@ -73,10 +74,10 @@ export class Text {
73
74
  ctx.save();
74
75
  ctx.globalAlpha *= styleOpacity(actor);
75
76
  drawTextBlock(ctx, {
76
- x: layout.x,
77
- y: layout.y,
78
- width: layout.width,
79
- height: layout.height,
77
+ x: box.x,
78
+ y: box.y,
79
+ width: box.width,
80
+ height: box.height,
80
81
  text,
81
82
  size,
82
83
  font: resolveTextFont(font),
@@ -3,11 +3,33 @@
3
3
  "actors": [
4
4
  {
5
5
  "components": {
6
- "Layout": { "width": 44, "height": 44, "z": 2 },
7
- "Sprite": { "file": "drawings/cauldron.sprite", "mode": "fit" },
8
- "Collider": { "shape": "circle", "width": 40, "height": 40, "bounciness": 0.6, "friction": 0.05 },
9
- "RigidBody": { "bodyType": "dynamic", "gravityScale": 1, "drag": 0.005 },
10
- "Slingshot": { "speed": 0.1, "maxDrag": 200 }
6
+ "Layout": {
7
+ "width": 44,
8
+ "height": 44,
9
+ "z": 2,
10
+ "originX": 0.5,
11
+ "originY": 0.5
12
+ },
13
+ "Sprite": {
14
+ "file": "drawings/cauldron.sprite",
15
+ "mode": "fit"
16
+ },
17
+ "Collider": {
18
+ "shape": "circle",
19
+ "width": 40,
20
+ "height": 40,
21
+ "bounciness": 0.6,
22
+ "friction": 0.05
23
+ },
24
+ "RigidBody": {
25
+ "bodyType": "dynamic",
26
+ "gravityScale": 1,
27
+ "drag": 0.005
28
+ },
29
+ "Slingshot": {
30
+ "speed": 0.1,
31
+ "maxDrag": 200
32
+ }
11
33
  }
12
34
  }
13
35
  ]
@@ -3,9 +3,22 @@
3
3
  "actors": [
4
4
  {
5
5
  "components": {
6
- "Layout": { "width": 100, "height": 40, "z": 1 },
7
- "Sprite": { "file": "drawings/block.sprite", "mode": "tile", "tileSize": 20 },
8
- "Collider": { "bounciness": 0.4, "friction": 0.2 }
6
+ "Layout": {
7
+ "width": 100,
8
+ "height": 40,
9
+ "z": 1,
10
+ "originX": 0.5,
11
+ "originY": 0.5
12
+ },
13
+ "Sprite": {
14
+ "file": "drawings/block.sprite",
15
+ "mode": "tile",
16
+ "tileSize": 20
17
+ },
18
+ "Collider": {
19
+ "bounciness": 0.4,
20
+ "friction": 0.2
21
+ }
9
22
  }
10
23
  }
11
24
  ]
@@ -6,7 +6,9 @@
6
6
  "Layout": {
7
7
  "width": 100,
8
8
  "height": 100,
9
- "z": 1
9
+ "z": 1,
10
+ "originX": 0.5,
11
+ "originY": 0.5
10
12
  },
11
13
  "Sprite": {
12
14
  "file": "drawings/cauldron.sprite"
@@ -3,10 +3,29 @@
3
3
  "actors": [
4
4
  {
5
5
  "components": {
6
- "Layout": { "width": 48, "height": 48, "z": 2 },
7
- "Sprite": { "file": "drawings/block.sprite", "mode": "fit" },
8
- "Collider": { "shape": "box", "width": 46, "height": 46, "bounciness": 0.2, "friction": 0.3 },
9
- "RigidBody": { "bodyType": "dynamic", "gravityScale": 1, "drag": 0.02 },
6
+ "Layout": {
7
+ "width": 48,
8
+ "height": 48,
9
+ "z": 2,
10
+ "originX": 0.5,
11
+ "originY": 0.5
12
+ },
13
+ "Sprite": {
14
+ "file": "drawings/block.sprite",
15
+ "mode": "fit"
16
+ },
17
+ "Collider": {
18
+ "shape": "box",
19
+ "width": 46,
20
+ "height": 46,
21
+ "bounciness": 0.2,
22
+ "friction": 0.3
23
+ },
24
+ "RigidBody": {
25
+ "bodyType": "dynamic",
26
+ "gravityScale": 1,
27
+ "drag": 0.02
28
+ },
10
29
  "Draggable": {}
11
30
  }
12
31
  }
@@ -3,8 +3,18 @@
3
3
  "actors": [
4
4
  {
5
5
  "components": {
6
- "Layout": { "width": 110, "height": 34, "z": 3 },
7
- "Collider": { "width": 110, "height": 34, "isTrigger": true },
6
+ "Layout": {
7
+ "width": 110,
8
+ "height": 34,
9
+ "z": 3,
10
+ "originX": 0.5,
11
+ "originY": 0.5
12
+ },
13
+ "Collider": {
14
+ "width": 110,
15
+ "height": 34,
16
+ "isTrigger": true
17
+ },
8
18
  "Goal": {}
9
19
  }
10
20
  }
@@ -3,9 +3,19 @@
3
3
  "actors": [
4
4
  {
5
5
  "components": {
6
- "Layout": { "width": 280, "height": 50, "z": 5 },
7
- "Style": { "padding": 8 },
8
- "Text": { "text": "Your text goes here" }
6
+ "Layout": {
7
+ "width": 280,
8
+ "height": 50,
9
+ "z": 5,
10
+ "originX": 0.5,
11
+ "originY": 0.5
12
+ },
13
+ "Style": {
14
+ "padding": 8
15
+ },
16
+ "Text": {
17
+ "text": "Your text goes here"
18
+ }
9
19
  }
10
20
  }
11
21
  ]
@@ -75,8 +75,9 @@
75
75
  "cardId": "_oBFbAW6DxsO",
76
76
  "main": "main.jsx",
77
77
  "autoUpdateWhenImported": true,
78
+ "onUpdate": "scripts/onUpdate.mjs",
78
79
  "title": "physics-2d",
79
- "publishedVersion": "2026-09-13T17:33:26.446Z",
80
+ "publishedVersion": "2026-09-16T21:17:53.144Z",
80
81
  "imports": {
81
82
  "castle.base": {
82
83
  "deckId": "yRcmH4_aYllE",
@@ -45,6 +45,7 @@ import {
45
45
  placeBlueprintInstance,
46
46
  renameBlueprintCascade,
47
47
  setBlueprintName,
48
+ setBlueprintOriginCascade,
48
49
  setBlueprintTemplateComponents,
49
50
  setInstanceComponent,
50
51
  } from '../engine/blueprint';
@@ -453,11 +454,34 @@ export function SceneEditor({
453
454
  if (onChangeFile) onChangeFile(selectedBlueprintPath, nextText);
454
455
  else void writeFile(selectedBlueprintPath, nextText);
455
456
  };
457
+ // The Layout origin is the one template prop whose edit MOVES existing
458
+ // instances: it changes what their own stored x/y means. So it goes through
459
+ // the cascade, which re-anchors every instance in every scene of this deck in
460
+ // the same gesture, and the writes land the way `renameCommit`'s do -- the
461
+ // open scene through history (so undo covers it), the rest as file writes.
462
+ const commitBlueprintOrigin = (nextProps) => {
463
+ if (blueprintLocked || !selectedBlueprintPath || !hotbarBlueprint) return;
464
+ const result = setBlueprintOriginCascade(files, selectedBlueprintPath, nextProps);
465
+ if (!result) return;
466
+ // Instances here move too. If this scene can't be written, refuse rather
467
+ // than shift the other scenes' instances and leave these behind.
468
+ if (readOnly && result.writes.some((write) => write.path === path)) return;
469
+ for (const write of result.writes) {
470
+ if (write.path === path) history.commit(write.text);
471
+ else if (onChangeFile) onChangeFile(write.path, write.text);
472
+ else void writeFile(write.path, write.text);
473
+ }
474
+ };
456
475
  const blueprintActions = {
457
- setComponent: (behaviorName, nextProps) =>
476
+ setComponent: (behaviorName, nextProps) => {
477
+ if (behaviorName === 'Layout' && ('originX' in nextProps || 'originY' in nextProps)) {
478
+ commitBlueprintOrigin(nextProps);
479
+ return;
480
+ }
458
481
  updateBlueprintTemplate((components) => {
459
482
  components[behaviorName] = { ...(components[behaviorName] ?? {}), ...nextProps };
460
- }),
483
+ });
484
+ },
461
485
  // Brings expected siblings along, as the actor path does -- a lone Draggable
462
486
  // is silently inert without a Collider.
463
487
  addBehavior: (behaviorName) => {