castle-web-cli 0.4.84 → 0.4.86

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 (90) hide show
  1. package/dist/ide.js +35 -13
  2. package/dist/shell/assets/{index-BOgm5T3W.js → index-BJLaUTJE.js} +21 -21
  3. package/dist/shell/index.html +1 -1
  4. package/kits/basic-2d/CLAUDE.md +3 -3
  5. package/kits/basic-2d/behaviors/Collider.jsx +172 -26
  6. package/kits/basic-2d/behaviors/Layout.jsx +24 -0
  7. package/kits/basic-2d/editors/PlayOnly.jsx +11 -9
  8. package/kits/basic-2d/editors/SceneEditor.jsx +49 -16
  9. package/kits/basic-2d/editors/SelectionOverlay.jsx +21 -11
  10. package/kits/basic-2d/editors/behaviorRegistry.js +9 -3
  11. package/kits/basic-2d/engine/behaviorExtensions.js +28 -0
  12. package/kits/basic-2d/engine/collider.js +60 -6
  13. package/kits/basic-2d/engine/scene.js +28 -2
  14. package/kits/basic-2d/engine/systemRegistry.js +12 -0
  15. package/kits/basic-2d/engine/ui.jsx +2 -0
  16. package/kits/basic-2d/main.jsx +3 -2
  17. package/kits/physics-2d/.prettierrc +8 -0
  18. package/kits/physics-2d/CLAUDE.md +329 -0
  19. package/kits/physics-2d/behaviors/Camera.jsx +43 -0
  20. package/kits/physics-2d/behaviors/Collider.jsx +213 -0
  21. package/kits/physics-2d/behaviors/Goal.jsx +29 -0
  22. package/kits/physics-2d/behaviors/Layout.jsx +53 -0
  23. package/kits/physics-2d/behaviors/Sprite.jsx +352 -0
  24. package/kits/physics-2d/behaviors/tint.js +47 -0
  25. package/kits/physics-2d/blueprints/ball.scene +14 -0
  26. package/kits/physics-2d/blueprints/block.scene +12 -0
  27. package/kits/physics-2d/blueprints/cauldron.scene +18 -0
  28. package/kits/physics-2d/blueprints/crate.scene +14 -0
  29. package/kits/physics-2d/blueprints/goal.scene +12 -0
  30. package/kits/physics-2d/castle.json +13 -0
  31. package/kits/physics-2d/docs/pxart-format.md +377 -0
  32. package/kits/physics-2d/drawings/block.pxart +25 -0
  33. package/kits/physics-2d/drawings/cauldron.pxart +113 -0
  34. package/kits/physics-2d/editors/BlueprintLibrary.jsx +247 -0
  35. package/kits/physics-2d/editors/ErrorBoundary.jsx +59 -0
  36. package/kits/physics-2d/editors/PlayOnly.jsx +31 -0
  37. package/kits/physics-2d/editors/PxArtEditor.jsx +954 -0
  38. package/kits/physics-2d/editors/SceneEditor.jsx +1696 -0
  39. package/kits/physics-2d/editors/SelectionOverlay.jsx +909 -0
  40. package/kits/physics-2d/editors/SingleEditor.jsx +122 -0
  41. package/kits/physics-2d/editors/behaviorRegistry.js +30 -0
  42. package/kits/physics-2d/editors/editorHistory.js +157 -0
  43. package/kits/physics-2d/editors/inspectorSheet.js +13 -0
  44. package/kits/physics-2d/editors/pixelCanvas.js +11 -0
  45. package/kits/physics-2d/editors/pixelEditorChrome.jsx +74 -0
  46. package/kits/physics-2d/editors/pixelGeometry.js +140 -0
  47. package/kits/physics-2d/editors/pixelInspector.jsx +633 -0
  48. package/kits/physics-2d/editors/pxArtEditorModel.js +732 -0
  49. package/kits/physics-2d/editors/pxArtPlayback.js +92 -0
  50. package/kits/physics-2d/editors/pxArtTimeline.jsx +752 -0
  51. package/kits/physics-2d/editors/pxArtTimeline.module.css +506 -0
  52. package/kits/physics-2d/editors/pxArtTools.js +232 -0
  53. package/kits/physics-2d/editors/useArtboardFit.js +102 -0
  54. package/kits/physics-2d/engine/ScenePlayer.jsx +196 -0
  55. package/kits/physics-2d/engine/SceneUI.jsx +59 -0
  56. package/kits/physics-2d/engine/assets.js +15 -0
  57. package/kits/physics-2d/engine/autoInspector.jsx +70 -0
  58. package/kits/physics-2d/engine/behaviorExtensions.js +28 -0
  59. package/kits/physics-2d/engine/blueprint.js +521 -0
  60. package/kits/physics-2d/engine/collider.js +200 -0
  61. package/kits/physics-2d/engine/files.js +117 -0
  62. package/kits/physics-2d/engine/liveReload.js +88 -0
  63. package/kits/physics-2d/engine/pxart.js +1032 -0
  64. package/kits/physics-2d/engine/pxartSmooth.js +222 -0
  65. package/kits/physics-2d/engine/scene.js +685 -0
  66. package/kits/physics-2d/engine/spriteGeometry.js +32 -0
  67. package/kits/physics-2d/engine/systemRegistry.js +12 -0
  68. package/kits/physics-2d/engine/ui.jsx +688 -0
  69. package/kits/physics-2d/engine/ui.module.css +2287 -0
  70. package/kits/physics-2d/eslint.config.js +71 -0
  71. package/kits/physics-2d/index.html +24 -0
  72. package/kits/physics-2d/main.jsx +24 -0
  73. package/kits/physics-2d/package-lock.json +2706 -0
  74. package/kits/physics-2d/package.json +42 -0
  75. package/kits/physics-2d/physics/PhysicsSystem.js +290 -0
  76. package/kits/physics-2d/physics/behaviors/AnalogStick.jsx +101 -0
  77. package/kits/physics-2d/physics/behaviors/Draggable.jsx +79 -0
  78. package/kits/physics-2d/physics/behaviors/RigidBody.jsx +55 -0
  79. package/kits/physics-2d/physics/behaviors/Slingshot.jsx +118 -0
  80. package/kits/physics-2d/physics/controls.js +79 -0
  81. package/kits/physics-2d/physics/extensions/collider.js +15 -0
  82. package/kits/physics-2d/physics/index.js +26 -0
  83. package/kits/physics-2d/physics/matterBridge.js +126 -0
  84. package/kits/physics-2d/pnpm-lock.yaml +1761 -0
  85. package/kits/physics-2d/scenes/main.scene +12 -0
  86. package/kits/physics-2d/scenes/sandbox.scene +13 -0
  87. package/kits/physics-2d/scripts/draw.mjs +121 -0
  88. package/kits/physics-2d/systems/physics.js +8 -0
  89. package/kits/physics-2d/vite.config.js +1 -0
  90. package/package.json +1 -1
@@ -0,0 +1,247 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { renderSpriteFrame } from '../engine/pxart';
3
+ import { screenToCard } from '../engine/scene';
4
+ import { countBlueprintInstances, listBlueprints } from '../engine/blueprint';
5
+ import { ConfirmDialog, ContextMenu, cx, Icon, styles } from '../engine/ui';
6
+
7
+ const DRAG_THRESHOLD = 4;
8
+
9
+ // Deck-level blueprint library / hotbar: lists `blueprints/*.scene` (replacing
10
+ // the old scene-local stamp system). Mirrors castle-client's belt: TAP a slot
11
+ // to select the blueprint for editing in the sidebar; DRAG a slot onto the
12
+ // canvas to place a new instance; right-click for a delete option.
13
+ export function BlueprintLibrary({
14
+ files,
15
+ sprites,
16
+ canvasRef,
17
+ editCameraRef,
18
+ isPlaying,
19
+ selectedBlueprintPath,
20
+ instanceBlueprintPath,
21
+ onSelectBlueprint,
22
+ onAddActor,
23
+ dragPlace,
24
+ onDeleteBlueprint,
25
+ }) {
26
+ const blueprints = listBlueprints(files);
27
+ const dragRef = useRef(null);
28
+ const suppressClickRef = useRef(false);
29
+ const [dragPreview, setDragPreview] = useState(null);
30
+ const [contextMenu, setContextMenu] = useState(null);
31
+ const [confirmDelete, setConfirmDelete] = useState(null);
32
+
33
+ const onSlotContextMenu = (event, blueprint) => {
34
+ if (isPlaying) return;
35
+ event.preventDefault();
36
+ event.stopPropagation();
37
+ setContextMenu({ blueprint, x: event.clientX, y: event.clientY });
38
+ };
39
+
40
+ const onSlotPointerDown = (event, blueprint) => {
41
+ if (isPlaying || event.button !== 0) return;
42
+ event.preventDefault();
43
+ const drag = {
44
+ blueprint,
45
+ pointerId: event.pointerId,
46
+ startX: event.clientX,
47
+ startY: event.clientY,
48
+ moved: false,
49
+ onStage: false,
50
+ };
51
+ dragRef.current = drag;
52
+ try {
53
+ event.currentTarget.setPointerCapture(event.pointerId);
54
+ } catch {
55
+ // Window listeners still finish the drag if capture is unavailable.
56
+ }
57
+ const onMove = (moveEvent) => {
58
+ if (moveEvent.pointerId !== drag.pointerId) return;
59
+ if (!drag.moved && Math.hypot(moveEvent.clientX - drag.startX, moveEvent.clientY - drag.startY) > DRAG_THRESHOLD) {
60
+ drag.moved = true;
61
+ }
62
+ if (!drag.moved) return;
63
+ const position = eventToStagePoint(moveEvent, canvasRef, editCameraRef);
64
+ if (position) {
65
+ // Over the stage: the drag becomes a REAL placed instance immediately,
66
+ // so it grid-snaps and renders exactly like the actor it is. The
67
+ // floating thumbnail only exists off-stage.
68
+ if (drag.onStage) {
69
+ dragPlace.move(position);
70
+ } else {
71
+ drag.onStage = true;
72
+ setDragPreview(null);
73
+ dragPlace.enter(blueprint.path, position);
74
+ }
75
+ } else {
76
+ if (drag.onStage) {
77
+ drag.onStage = false;
78
+ dragPlace.leave();
79
+ }
80
+ setDragPreview({ blueprint, x: moveEvent.clientX, y: moveEvent.clientY, overStage: false });
81
+ }
82
+ };
83
+ const onUp = (upEvent) => {
84
+ if (upEvent.pointerId !== drag.pointerId) return;
85
+ window.removeEventListener('pointermove', onMove);
86
+ window.removeEventListener('pointerup', onUp);
87
+ window.removeEventListener('pointercancel', onUp);
88
+ dragRef.current = null;
89
+ setDragPreview(null);
90
+ if (!drag.moved) return;
91
+ suppressClickRef.current = true;
92
+ // Cancelled drags (pointercancel) count as a release off-stage.
93
+ if (drag.onStage && upEvent.type !== 'pointercancel') dragPlace.drop();
94
+ else if (drag.onStage) dragPlace.leave();
95
+ };
96
+ window.addEventListener('pointermove', onMove);
97
+ window.addEventListener('pointerup', onUp);
98
+ window.addEventListener('pointercancel', onUp);
99
+ };
100
+
101
+ return (
102
+ <div className={styles.bpHotbar} aria-label="Blueprints">
103
+ <button
104
+ type="button"
105
+ className={styles.bpActionSlot}
106
+ aria-label="Add actor"
107
+ title="New blueprint"
108
+ onClick={onAddActor}
109
+ disabled={isPlaying}>
110
+ <Icon name="plus" />
111
+ </button>
112
+ {blueprints.map((blueprint) => (
113
+ <button
114
+ key={blueprint.path}
115
+ type="button"
116
+ className={cx(
117
+ styles.bpSlot,
118
+ selectedBlueprintPath === blueprint.path && styles.bpSlotSelected,
119
+ selectedBlueprintPath !== blueprint.path &&
120
+ instanceBlueprintPath === blueprint.path &&
121
+ styles.bpSlotInstance
122
+ )}
123
+ title={`${blueprint.name} -- click to edit, drag to place`}
124
+ disabled={isPlaying}
125
+ onPointerDown={(event) => onSlotPointerDown(event, blueprint)}
126
+ onContextMenu={(event) => onSlotContextMenu(event, blueprint)}
127
+ onClick={() => {
128
+ if (suppressClickRef.current) {
129
+ suppressClickRef.current = false;
130
+ return;
131
+ }
132
+ onSelectBlueprint(blueprint.path);
133
+ }}>
134
+ <BlueprintThumbnail blueprint={blueprint} sprites={sprites} />
135
+ </button>
136
+ ))}
137
+ {dragPreview ? <BlueprintDragPreview preview={dragPreview} sprites={sprites} /> : null}
138
+ {contextMenu ? (
139
+ <ContextMenu
140
+ x={contextMenu.x}
141
+ y={contextMenu.y}
142
+ onClose={() => setContextMenu(null)}
143
+ items={[
144
+ {
145
+ key: 'delete',
146
+ label: `Delete ${contextMenu.blueprint.name}...`,
147
+ onClick: () => setConfirmDelete(contextMenu.blueprint),
148
+ },
149
+ ]}
150
+ />
151
+ ) : null}
152
+ {confirmDelete ? (
153
+ <DeleteBlueprintConfirm
154
+ files={files}
155
+ blueprint={confirmDelete}
156
+ onCancel={() => setConfirmDelete(null)}
157
+ onConfirm={() => {
158
+ onDeleteBlueprint(confirmDelete.path);
159
+ setConfirmDelete(null);
160
+ }}
161
+ />
162
+ ) : null}
163
+ </div>
164
+ );
165
+ }
166
+
167
+ function DeleteBlueprintConfirm({ files, blueprint, onCancel, onConfirm }) {
168
+ const count = countBlueprintInstances(files, blueprint.path);
169
+ const instanceText = count === 1 ? '1 placed actor' : `${count} placed actors`;
170
+ return (
171
+ <ConfirmDialog
172
+ title={`Delete ${blueprint.name}?`}
173
+ message={
174
+ count > 0
175
+ ? `This removes ${blueprint.name} and ${instanceText} across every scene in the deck. This can't be undone.`
176
+ : `${blueprint.name} has no placed actors. This can't be undone.`
177
+ }
178
+ confirmLabel="Delete"
179
+ onCancel={onCancel}
180
+ onConfirm={onConfirm}
181
+ />
182
+ );
183
+ }
184
+
185
+ function BlueprintDragPreview({ preview, sprites }) {
186
+ const layout = preview.blueprint.components?.Layout;
187
+ const width = Math.max(24, Math.min(80, layout?.width ?? 48));
188
+ const height = Math.max(24, Math.min(80, layout?.height ?? 48));
189
+ return (
190
+ <div
191
+ className={cx(styles.bpDragPreview, preview.overStage && styles.bpDragPreviewOverStage)}
192
+ style={{
193
+ left: preview.x,
194
+ top: preview.y,
195
+ width,
196
+ height,
197
+ transform: `translate(-50%, -50%) rotate(${layout?.rotation ?? 0}deg)`,
198
+ }}>
199
+ <BlueprintThumbnail blueprint={preview.blueprint} sprites={sprites} preview />
200
+ </div>
201
+ );
202
+ }
203
+
204
+ export function BlueprintThumbnail({ blueprint, sprites, preview = false }) {
205
+ const canvasRef = useRef(null);
206
+ const spritePath = blueprint.components?.Sprite?.file;
207
+ const sprite = spritePath ? sprites?.[spritePath] : null;
208
+ useEffect(() => {
209
+ const canvas = canvasRef.current;
210
+ if (!canvas || !sprite) return;
211
+ renderSpriteFrame(sprite, 0, canvas);
212
+ }, [sprite]);
213
+ if (!sprite) {
214
+ return (
215
+ <span className={styles.bpSlotFallback}>
216
+ <Icon name="clone" />
217
+ </span>
218
+ );
219
+ }
220
+ return (
221
+ <canvas
222
+ ref={canvasRef}
223
+ className={cx(styles.bpSlotThumb, preview && styles.bpPreviewThumb)}
224
+ aria-hidden="true"
225
+ />
226
+ );
227
+ }
228
+
229
+ function eventToStagePoint(event, canvasRef, editCameraRef) {
230
+ const canvas = canvasRef.current;
231
+ if (!canvas) return null;
232
+ const rect = canvas.getBoundingClientRect();
233
+ if (
234
+ event.clientX < rect.left ||
235
+ event.clientX > rect.right ||
236
+ event.clientY < rect.top ||
237
+ event.clientY > rect.bottom
238
+ ) {
239
+ return null;
240
+ }
241
+ const raw = screenToCard(canvas, event.clientX, event.clientY);
242
+ const camera = editCameraRef.current ?? { x: 0, y: 0 };
243
+ return {
244
+ x: raw.x + camera.x,
245
+ y: raw.y + camera.y,
246
+ };
247
+ }
@@ -0,0 +1,59 @@
1
+ // Deck-side error boundary for the panel routes. A throwing editor (these are
2
+ // agent-edited deck files -- they will throw) shows a small muted message inside
3
+ // its panel iframe instead of a blank / loud crash. Inline styles so it doesn't
4
+ // depend on whatever module may have failed.
5
+
6
+ import React from 'react';
7
+
8
+ export class ErrorBoundary extends React.Component {
9
+ state = { error: null };
10
+ static getDerivedStateFromError(error) {
11
+ return { error };
12
+ }
13
+ componentDidCatch(error) {
14
+ console.error('[deck panel error]', error);
15
+ }
16
+ render() {
17
+ if (!this.state.error) return this.props.children;
18
+ return (
19
+ <div
20
+ style={{
21
+ height: '100vh',
22
+ padding: '14px 16px',
23
+ overflow: 'auto',
24
+ color: '#6e7781',
25
+ font: '13px ui-sans-serif, system-ui, -apple-system, sans-serif',
26
+ background: '#ffffff',
27
+ }}>
28
+ <div style={{ color: '#57606a' }}>this panel hit an error</div>
29
+ <pre
30
+ style={{
31
+ margin: '8px 0 0',
32
+ whiteSpace: 'pre-wrap',
33
+ wordBreak: 'break-word',
34
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
35
+ fontSize: 12,
36
+ color: '#8c959f',
37
+ }}>
38
+ {String((this.state.error && this.state.error.message) || this.state.error)}
39
+ </pre>
40
+ <button
41
+ type="button"
42
+ onClick={() => this.setState({ error: null })}
43
+ style={{
44
+ marginTop: 8,
45
+ font: 'inherit',
46
+ fontSize: 12,
47
+ padding: '3px 10px',
48
+ border: '1px solid #cccccc',
49
+ borderRadius: 4,
50
+ background: '#ffffff',
51
+ color: '#57606a',
52
+ cursor: 'pointer',
53
+ }}>
54
+ retry
55
+ </button>
56
+ </div>
57
+ );
58
+ }
59
+ }
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { Lifecycle } from 'castle-web-sdk';
3
+ import { parseJsonFile } from '../engine/files';
4
+ import { useLiveDeckFiles } from '../engine/liveReload';
5
+ import { collectAssets } from '../engine/assets';
6
+ import { ScenePlayer } from '../engine/ScenePlayer';
7
+ import { behaviorClasses } from './behaviorRegistry';
8
+ // Play-mode entry point. Plays the scene named by `?scene=<path>` (the shell's
9
+ // Play panel sets this), defaulting to `scenes/main.scene`. It renders ONLY the
10
+ // game — the scene picker lives in the Play panel chrome (the shell), not here,
11
+ // so nothing floats over the game surface and steals input. Files are live:
12
+ // scene/drawing edits re-key the player against fresh data.
13
+ const DEFAULT_SCENE = 'scenes/main.scene';
14
+
15
+ export function PlayOnly({ initialScene } = {}) {
16
+ const { files, dataVersion } = useLiveDeckFiles();
17
+ const scenePath = initialScene && files[initialScene] !== undefined ? initialScene : DEFAULT_SCENE;
18
+ const { value: sceneData } = parseJsonFile(scenePath, files[scenePath] ?? '');
19
+ if (!sceneData) return null;
20
+ const { sprites } = collectAssets(files);
21
+ return (
22
+ <ScenePlayer
23
+ key={`${scenePath}:${dataVersion}`}
24
+ sceneData={sceneData}
25
+ sprites={sprites}
26
+ files={files}
27
+ behaviorClasses={behaviorClasses}
28
+ onFirstFrame={Lifecycle.ready}
29
+ />
30
+ );
31
+ }