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.
- package/dist/agent.d.ts +1 -0
- package/dist/agent.js +12 -4
- package/dist/api.d.ts +45 -1
- package/dist/api.js +34 -2
- package/dist/castle-host/host.d.ts +17 -0
- package/dist/castle-host/host.js +10 -7
- package/dist/castleJson.d.ts +15 -0
- package/dist/castleJson.js +36 -0
- package/dist/devSessionChild.d.ts +1 -0
- package/dist/devSessionChild.js +129 -0
- package/dist/devSessionServer.d.ts +19 -0
- package/dist/devSessionServer.js +511 -0
- package/dist/headlessCover.js +28 -0
- package/dist/index.js +8 -8
- package/dist/init.js +9 -1
- package/dist/list-decks.js +7 -6
- package/dist/native/playtest-remote.d.ts +3 -0
- package/dist/native/playtest-remote.js +113 -0
- package/dist/preview.d.ts +1 -1
- package/dist/preview.js +4 -2
- package/dist/save-deck.js +82 -16
- package/dist/serve.js +245 -88
- package/dist/serveSecurity.d.ts +7 -1
- package/dist/serveSecurity.js +61 -10
- package/dist/serverBundle.d.ts +8 -0
- package/dist/serverBundle.js +82 -0
- package/dist/shell/assets/{index-BzFzFtEP.js → index-Dlhc3eZW.js} +42 -42
- package/dist/shell/assets/index-DwezawBs.css +1 -0
- package/dist/shell/index.html +2 -2
- package/kits/blank/.castle/agent/children.json +1 -0
- package/kits/blank/.castle/agent/messages.json +9 -0
- package/kits/blank/.castle/agent/pending-sends.json +1 -0
- package/kits/blank/.castle/agent/tasks/index.md +2 -0
- package/kits/blank/.castle/docs/platform.md +36 -0
- package/kits/blank/castle.json +5 -2
- package/kits/blank/node_modules/.vite/deps/_metadata.json +8 -0
- package/kits/blank/node_modules/.vite/deps/package.json +3 -0
- package/kits/physics-2d/behaviors/Collider.jsx +1 -2
- package/kits/physics-2d/behaviors/Joints.jsx +1 -1
- package/kits/physics-2d/castle.json +1 -1
- package/kits/physics-2d/editors/BlueprintLibrary.jsx +33 -3
- package/kits/physics-2d/editors/SceneEditor.jsx +171 -57
- package/kits/physics-2d/editors/SingleEditor.jsx +6 -0
- package/kits/physics-2d/engine/blueprint.js +106 -14
- package/kits/physics-2d/engine/scene.js +9 -2
- package/kits/physics-2d/engine/ui.jsx +30 -2
- package/kits/physics-2d/engine/ui.module.css +59 -0
- package/package.json +1 -1
- package/dist/shell/assets/index-DN8HQBnW.css +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { onSaveReloadState, takeReloadState, writeFile } from 'castle-web-sdk';
|
|
2
|
+
import { onSaveReloadState, resolveDeckFile, takeReloadState, writeFile } from 'castle-web-sdk';
|
|
3
3
|
import * as castleSdk from 'castle-web-sdk';
|
|
4
4
|
|
|
5
5
|
// Same tolerance as SingleEditor's onSaveState/hasPendingSave: a deck that takes
|
|
@@ -32,12 +32,13 @@ import {
|
|
|
32
32
|
cascadeDeleteBlueprint,
|
|
33
33
|
countBlueprintInstances,
|
|
34
34
|
createBlueprint,
|
|
35
|
-
forkActorToBlueprint,
|
|
36
35
|
getBlueprintTemplate,
|
|
36
|
+
importAliasOf,
|
|
37
37
|
isBlueprintPath,
|
|
38
38
|
isImportedPath,
|
|
39
39
|
isInheritedProp,
|
|
40
40
|
migrateOrphanActors,
|
|
41
|
+
newBlueprintFromActor,
|
|
41
42
|
placeBlueprintInstance,
|
|
42
43
|
renameBlueprintCascade,
|
|
43
44
|
setBlueprintName,
|
|
@@ -153,9 +154,11 @@ function stripTemplateId(sceneData) {
|
|
|
153
154
|
// fire-and-forget (they're brand new files, nothing else references them
|
|
154
155
|
// yet) while the scene rewrite goes through this file's own `onChange` so it
|
|
155
156
|
// picks up the normal history/live-reload path.
|
|
156
|
-
function useMigrateOrphanActors({ isBlueprintFile, sceneData, files, text, onChange }) {
|
|
157
|
+
function useMigrateOrphanActors({ isBlueprintFile, sceneData, files, text, onChange, readOnly }) {
|
|
157
158
|
useEffect(() => {
|
|
158
|
-
|
|
159
|
+
// Rewriting a scene the deck can't write would mint the blueprint files and
|
|
160
|
+
// then drop the scene half, leaving orphans behind and new files stranded.
|
|
161
|
+
if (readOnly || isBlueprintFile || !sceneData) return;
|
|
159
162
|
const hasOrphans = (sceneData.actors ?? []).some((actor) => !actor.blueprint);
|
|
160
163
|
if (!hasOrphans) return;
|
|
161
164
|
const { sceneData: migrated, newBlueprintFiles } = migrateOrphanActors(
|
|
@@ -170,7 +173,7 @@ function useMigrateOrphanActors({ isBlueprintFile, sceneData, files, text, onCha
|
|
|
170
173
|
// write lands, or the user opens a different orphaned file) -- `files`
|
|
171
174
|
// changes on every keystroke elsewhere and would otherwise loop.
|
|
172
175
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
173
|
-
}, [text, isBlueprintFile]);
|
|
176
|
+
}, [text, isBlueprintFile, readOnly]);
|
|
174
177
|
}
|
|
175
178
|
export function SceneEditor({
|
|
176
179
|
path,
|
|
@@ -182,6 +185,16 @@ export function SceneEditor({
|
|
|
182
185
|
onToggleFiles,
|
|
183
186
|
filesOpen,
|
|
184
187
|
headerHost,
|
|
188
|
+
// The open scene can't be written: someone else's deck, and not forked here.
|
|
189
|
+
// The saver drops those writes anyway, so without this the canvas accepts a
|
|
190
|
+
// whole session of edits and loses them at reload with nothing said. Only
|
|
191
|
+
// about THIS file -- a blueprint selected in the hotbar is a different file
|
|
192
|
+
// and answers for itself.
|
|
193
|
+
readOnly = false,
|
|
194
|
+
// Answers for any file, which the blueprint inspector needs: it edits the
|
|
195
|
+
// selected blueprint, not this scene. Defaults permissive so a host that
|
|
196
|
+
// doesn't pass it behaves as it did before.
|
|
197
|
+
isWritable = () => true,
|
|
185
198
|
selectedActorIds,
|
|
186
199
|
onSelectActorIds: onSelectActorIdsRaw,
|
|
187
200
|
multiSelectMode,
|
|
@@ -265,7 +278,7 @@ export function SceneEditor({
|
|
|
265
278
|
// Disabled during play: the header undo/redo buttons are already disabled
|
|
266
279
|
// then, but without this the keyboard shortcut could still rewrite the
|
|
267
280
|
// scene file out from under the running play-mode runtime.
|
|
268
|
-
useUndoRedoShortcuts(history, !isPlaying);
|
|
281
|
+
useUndoRedoShortcuts(history, !isPlaying && !readOnly);
|
|
269
282
|
// Stash ephemeral editor state right before a reload so it survives an agent
|
|
270
283
|
// code edit. `editCamera` is read live from the ref at save time (a reload is
|
|
271
284
|
// imminent, so the latest value is what matters); isPlaying / blueprint
|
|
@@ -294,7 +307,14 @@ export function SceneEditor({
|
|
|
294
307
|
[isBlueprintFile]
|
|
295
308
|
);
|
|
296
309
|
const getRuntime = useCallback(() => runtimeRef.current, []);
|
|
297
|
-
|
|
310
|
+
// Every edit to THIS scene leaves through one of these three, so read-only is
|
|
311
|
+
// enforced here rather than at each gesture and handler. A guard missed at a
|
|
312
|
+
// call site would not refuse the edit -- it would let it render and then be
|
|
313
|
+
// dropped at save, which is the failure this whole prop exists to end.
|
|
314
|
+
const applyScene = readOnly ? () => {} : (next) => onChange(serialize(next));
|
|
315
|
+
const recordSceneSnapshot = readOnly ? () => {} : history.recordSnapshot;
|
|
316
|
+
const commitScene = readOnly ? () => {} : (next) => history.commit(serialize(next));
|
|
317
|
+
useMigrateOrphanActors({ isBlueprintFile, sceneData, files, text, onChange, readOnly });
|
|
298
318
|
useScenePlayLoop({
|
|
299
319
|
sceneData,
|
|
300
320
|
sprites,
|
|
@@ -335,8 +355,8 @@ export function SceneEditor({
|
|
|
335
355
|
editCameraRef,
|
|
336
356
|
pickRequestRef,
|
|
337
357
|
onPickTarget,
|
|
338
|
-
applyScene
|
|
339
|
-
recordSceneSnapshot
|
|
358
|
+
applyScene,
|
|
359
|
+
recordSceneSnapshot,
|
|
340
360
|
});
|
|
341
361
|
const playPointer = usePlayPointerGesture({ canvasRef, runtimeRef });
|
|
342
362
|
// Touch: one finger selects/drags actors, a second finger pinch-zooms about the
|
|
@@ -354,8 +374,8 @@ export function SceneEditor({
|
|
|
354
374
|
panGesture.panByScreenDelta(-dx, -dy);
|
|
355
375
|
},
|
|
356
376
|
// Procreate convention: two-finger tap undoes, three-finger tap redoes.
|
|
357
|
-
onUndo: () => history.undo(),
|
|
358
|
-
onRedo: () => history.redo(),
|
|
377
|
+
onUndo: readOnly ? undefined : () => history.undo(),
|
|
378
|
+
onRedo: readOnly ? undefined : () => history.redo(),
|
|
359
379
|
});
|
|
360
380
|
useSelectionKeyboard({
|
|
361
381
|
sceneData,
|
|
@@ -366,7 +386,7 @@ export function SceneEditor({
|
|
|
366
386
|
onSetMultiSelectMode,
|
|
367
387
|
isPlaying,
|
|
368
388
|
isBlueprintFile,
|
|
369
|
-
commitScene
|
|
389
|
+
commitScene,
|
|
370
390
|
});
|
|
371
391
|
if (!sceneData) {
|
|
372
392
|
return (
|
|
@@ -391,15 +411,28 @@ export function SceneEditor({
|
|
|
391
411
|
selectedActorIds.length === 1
|
|
392
412
|
? previewSceneData.actors.find((actor) => actor.id === selectedActorIds[0])
|
|
393
413
|
: undefined;
|
|
394
|
-
|
|
395
|
-
|
|
414
|
+
// An actor's `blueprint` is a ref as written in THIS scene, so it only names a
|
|
415
|
+
// file once resolved against it. In an import's scene a bare
|
|
416
|
+
// `blueprints/ball.scene` means that import's; resolved against the deck root
|
|
417
|
+
// instead it finds this deck's own same-named blueprint, a different file and
|
|
418
|
+
// an editable one. Resolved once here, so every read, write and comparison
|
|
419
|
+
// downstream has a whole-deck key.
|
|
420
|
+
const selectedActorBlueprint = rawSelectedActor?.blueprint
|
|
421
|
+
? resolveDeckFile(rawSelectedActor.blueprint, path)
|
|
422
|
+
: null;
|
|
423
|
+
const selectedBlueprintTemplate = selectedActorBlueprint
|
|
424
|
+
? getBlueprintTemplate(files, selectedActorBlueprint)
|
|
396
425
|
: undefined;
|
|
397
|
-
const selectedBlueprintName =
|
|
398
|
-
? (selectedBlueprintTemplate?.name ?? basename(
|
|
426
|
+
const selectedBlueprintName = selectedActorBlueprint
|
|
427
|
+
? (selectedBlueprintTemplate?.name ?? basename(selectedActorBlueprint))
|
|
399
428
|
: undefined;
|
|
400
429
|
// Hotbar-selected blueprint, resolved fresh from live files each render. A
|
|
401
430
|
// selection whose file vanished (cascade delete, external edit) degrades to
|
|
402
431
|
// "nothing selected" rather than a broken inspector.
|
|
432
|
+
//
|
|
433
|
+
// No `fromPath` here, and there must not be: `selectedBlueprintPath` is always
|
|
434
|
+
// a whole-deck key already, and resolving one a second time against an
|
|
435
|
+
// import's scene would prefix it twice.
|
|
403
436
|
const hotbarBlueprint =
|
|
404
437
|
!isBlueprintFile && selectedBlueprintPath
|
|
405
438
|
? getBlueprintTemplate(files, selectedBlueprintPath)
|
|
@@ -407,6 +440,11 @@ export function SceneEditor({
|
|
|
407
440
|
// Only dim for a blueprint that actually resolves to an inspectable template
|
|
408
441
|
// (mirrors the sidebar): a vanished/stale selection highlights nothing.
|
|
409
442
|
selectedBlueprintPathRef.current = hotbarBlueprint ? selectedBlueprintPath : null;
|
|
443
|
+
// The selected blueprint's own answer, which is not this scene's: an import's
|
|
444
|
+
// blueprint stays locked in a scene of yours, and one you forked stays
|
|
445
|
+
// editable in a scene of theirs. The saver already dropped these writes; this
|
|
446
|
+
// is so the inspector stops taking edits it can't keep.
|
|
447
|
+
const blueprintLocked = Boolean(hotbarBlueprint) && !isWritable(selectedBlueprintPath);
|
|
410
448
|
// Template edits from the sidebar write the BLUEPRINT file, not this scene:
|
|
411
449
|
// optimistic fold into live files state (instant merged-instance updates
|
|
412
450
|
// here) + debounced writeFile via SingleEditor's saver, which also makes
|
|
@@ -414,7 +452,7 @@ export function SceneEditor({
|
|
|
414
452
|
// per-property merge semantics as editing the blueprint's own file. Outside
|
|
415
453
|
// this scene file's undo history (accepted v1 cross-file gap, like fork).
|
|
416
454
|
const updateBlueprintTemplate = (mutate) => {
|
|
417
|
-
if (!selectedBlueprintPath || !hotbarBlueprint) return;
|
|
455
|
+
if (blueprintLocked || !selectedBlueprintPath || !hotbarBlueprint) return;
|
|
418
456
|
const components = structuredClone(hotbarBlueprint.components);
|
|
419
457
|
mutate(components);
|
|
420
458
|
const nextText = setBlueprintTemplateComponents(files, selectedBlueprintPath, components);
|
|
@@ -450,7 +488,7 @@ export function SceneEditor({
|
|
|
450
488
|
// per keystroke, which would strew `w.scene`, `wa.scene`, … across the deck.
|
|
451
489
|
// See `renameCommit`.
|
|
452
490
|
rename: (name) => {
|
|
453
|
-
if (!selectedBlueprintPath) return;
|
|
491
|
+
if (blueprintLocked || !selectedBlueprintPath) return;
|
|
454
492
|
const nextText = setBlueprintName(files, selectedBlueprintPath, name);
|
|
455
493
|
if (nextText == null) return;
|
|
456
494
|
if (onChangeFile) onChangeFile(selectedBlueprintPath, nextText);
|
|
@@ -459,9 +497,14 @@ export function SceneEditor({
|
|
|
459
497
|
// Move the file to the name's slug, bring its auto-minted drawing along, and
|
|
460
498
|
// repoint every instance in every scene.
|
|
461
499
|
renameCommit: async (name) => {
|
|
462
|
-
if (!editorFlags.renameBlueprintFiles || !selectedBlueprintPath) return;
|
|
500
|
+
if (blueprintLocked || !editorFlags.renameBlueprintFiles || !selectedBlueprintPath) return;
|
|
463
501
|
const result = renameBlueprintCascade(files, selectedBlueprintPath, name);
|
|
464
502
|
if (!result) return;
|
|
503
|
+
// The repoint spans every scene holding an instance. If this one is among
|
|
504
|
+
// them and can't be written, the file still moves and this scene is left
|
|
505
|
+
// naming a path that no longer exists. A rename that touches no instance
|
|
506
|
+
// here is unaffected, so this asks rather than refusing outright.
|
|
507
|
+
if (readOnly && result.writes.some((write) => write.path === path)) return;
|
|
465
508
|
// Moves first, then content: a write must never land on a path about to
|
|
466
509
|
// move out from under it.
|
|
467
510
|
for (const move of result.fileRenames) {
|
|
@@ -482,7 +525,7 @@ export function SceneEditor({
|
|
|
482
525
|
sceneData,
|
|
483
526
|
files,
|
|
484
527
|
serialize,
|
|
485
|
-
commit: history.commit,
|
|
528
|
+
commit: readOnly ? () => {} : history.commit,
|
|
486
529
|
selectedActorIds,
|
|
487
530
|
onSelectActorIds,
|
|
488
531
|
isBlueprintFile,
|
|
@@ -494,14 +537,18 @@ export function SceneEditor({
|
|
|
494
537
|
backgroundColor: darkenSceneBackground(sceneData.background),
|
|
495
538
|
};
|
|
496
539
|
const updateSceneSettings = (nextScene) => {
|
|
497
|
-
|
|
540
|
+
commitScene(setSceneSettings(sceneData, nextScene));
|
|
498
541
|
};
|
|
499
542
|
const updateSceneEditorSettings = (nextEditor) => {
|
|
500
|
-
|
|
543
|
+
commitScene(setSceneEditorSettings(sceneData, nextEditor));
|
|
501
544
|
};
|
|
502
545
|
// Lands on the BLUEPRINT inspector, not the actor one: the actor is a placed
|
|
503
546
|
// copy, and the blueprint is where the name and sprite are.
|
|
504
547
|
const commitNewBlueprint = ({ sceneData: next, newId, blueprintFile, drawingFile }) => {
|
|
548
|
+
// The point of a new blueprint here is the instance placed alongside it, and
|
|
549
|
+
// that lands in this scene. Minting the files anyway would leave a blueprint
|
|
550
|
+
// and a drawing in the deck with nothing referring to them.
|
|
551
|
+
if (readOnly) return undefined;
|
|
505
552
|
// Add both generated files to the live map before committing the instance.
|
|
506
553
|
// Otherwise another + click can mint the same numbered paths while the fs
|
|
507
554
|
// watcher's asynchronous echo of these direct writes is still pending.
|
|
@@ -557,7 +604,8 @@ export function SceneEditor({
|
|
|
557
604
|
// that predates the placement.
|
|
558
605
|
const dragPlace = {
|
|
559
606
|
enter: (blueprintPath, position) => {
|
|
560
|
-
|
|
607
|
+
if (readOnly) return;
|
|
608
|
+
recordSceneSnapshot();
|
|
561
609
|
const { sceneData: next, newId } = placeBlueprintInstance(
|
|
562
610
|
sceneData,
|
|
563
611
|
files,
|
|
@@ -573,7 +621,7 @@ export function SceneEditor({
|
|
|
573
621
|
x: layout.x,
|
|
574
622
|
y: layout.y,
|
|
575
623
|
};
|
|
576
|
-
|
|
624
|
+
applyScene(next);
|
|
577
625
|
onSelectActorIds([newId]);
|
|
578
626
|
},
|
|
579
627
|
move: (position) => {
|
|
@@ -586,13 +634,13 @@ export function SceneEditor({
|
|
|
586
634
|
if (!actor) return;
|
|
587
635
|
actor.components.Layout = { ...actor.components.Layout, x, y };
|
|
588
636
|
Object.assign(drag, { sceneData: next, x, y });
|
|
589
|
-
|
|
637
|
+
applyScene(next);
|
|
590
638
|
},
|
|
591
639
|
leave: () => {
|
|
592
640
|
const drag = dragPlaceRef.current;
|
|
593
641
|
if (!drag) return;
|
|
594
642
|
dragPlaceRef.current = null;
|
|
595
|
-
|
|
643
|
+
applyScene(removeActors(drag.sceneData, [drag.actorId]));
|
|
596
644
|
onSelectActorIds([]);
|
|
597
645
|
},
|
|
598
646
|
drop: () => {
|
|
@@ -603,21 +651,32 @@ export function SceneEditor({
|
|
|
603
651
|
},
|
|
604
652
|
};
|
|
605
653
|
const onDeleteBlueprint = (blueprintPath) => {
|
|
654
|
+
// The tombstone is a write to the blueprint itself, and these go straight to
|
|
655
|
+
// `writeFile` rather than through the saver's check. An import's blueprint
|
|
656
|
+
// refuses it, but the cascade has already stripped every instance from this
|
|
657
|
+
// deck's scenes by then: the actors are gone and the blueprint isn't.
|
|
658
|
+
if (!isWritable(blueprintPath)) return;
|
|
659
|
+
const cascade = cascadeDeleteBlueprint(files, blueprintPath);
|
|
660
|
+
// Same hazard as the rename: if this scene holds an instance and can't be
|
|
661
|
+
// written, the blueprint goes and this scene keeps referring to it.
|
|
662
|
+
if (readOnly && cascade.some((write) => write.path === path)) return;
|
|
606
663
|
// Every write here targets a plain `scenes/*.scene` (cascaded instance
|
|
607
664
|
// removal) or the blueprint file itself (tombstoned) -- never a
|
|
608
665
|
// blueprint's own template id, so no `serialize`/strip step is needed.
|
|
609
|
-
for (const write of
|
|
666
|
+
for (const write of cascade) {
|
|
610
667
|
if (write.path === path) history.commit(write.text);
|
|
611
668
|
else void writeFile(write.path, write.text);
|
|
612
669
|
}
|
|
613
670
|
onSelectActorIds([]);
|
|
614
671
|
};
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
672
|
+
const onNewBlueprintFromActor = () => {
|
|
673
|
+
// Repoints the actor at the blueprint it mints, and that edit is to this
|
|
674
|
+
// scene.
|
|
675
|
+
if (readOnly || isBlueprintFile || !rawSelectedActor?.blueprint) return;
|
|
676
|
+
const result = newBlueprintFromActor(files, behaviorClasses, sceneData, rawSelectedActor.id);
|
|
618
677
|
if (!result) return;
|
|
619
678
|
void writeFile(result.blueprintFile.path, result.blueprintFile.text);
|
|
620
|
-
|
|
679
|
+
commitScene(result.sceneData);
|
|
621
680
|
};
|
|
622
681
|
return (
|
|
623
682
|
<>
|
|
@@ -644,6 +703,7 @@ export function SceneEditor({
|
|
|
644
703
|
isPlaying={isPlaying}
|
|
645
704
|
setIsPlaying={setIsPlaying}
|
|
646
705
|
history={history}
|
|
706
|
+
readOnly={readOnly}
|
|
647
707
|
/>
|
|
648
708
|
}
|
|
649
709
|
onToggleFiles={onToggleFiles}
|
|
@@ -660,8 +720,10 @@ export function SceneEditor({
|
|
|
660
720
|
canvasRef={canvasRef}
|
|
661
721
|
editCameraRef={editCameraRef}
|
|
662
722
|
isPlaying={isPlaying}
|
|
723
|
+
readOnly={readOnly}
|
|
724
|
+
isWritable={isWritable}
|
|
663
725
|
selectedBlueprintPath={selectedBlueprintPath}
|
|
664
|
-
instanceBlueprintPath={
|
|
726
|
+
instanceBlueprintPath={selectedActorBlueprint}
|
|
665
727
|
onSelectBlueprint={onSelectBlueprint}
|
|
666
728
|
onAddActor={onAddActor}
|
|
667
729
|
dragPlace={dragPlace}
|
|
@@ -729,11 +791,11 @@ export function SceneEditor({
|
|
|
729
791
|
selectedActorIds={selectedActorIds}
|
|
730
792
|
selectedColliderShape={colliderShapeSel}
|
|
731
793
|
snap={snapSettings}
|
|
732
|
-
onArrange={isBlueprintFile ? undefined : actions.arrangeSelection}
|
|
733
|
-
onClone={isBlueprintFile ? undefined : actions.duplicateSelection}
|
|
734
|
-
onDelete={isBlueprintFile ? undefined : actions.deleteSelection}
|
|
735
|
-
applyScene={
|
|
736
|
-
recordSnapshot={
|
|
794
|
+
onArrange={isBlueprintFile || readOnly ? undefined : actions.arrangeSelection}
|
|
795
|
+
onClone={isBlueprintFile || readOnly ? undefined : actions.duplicateSelection}
|
|
796
|
+
onDelete={isBlueprintFile || readOnly ? undefined : actions.deleteSelection}
|
|
797
|
+
applyScene={applyScene}
|
|
798
|
+
recordSnapshot={recordSceneSnapshot}
|
|
737
799
|
/>
|
|
738
800
|
)}
|
|
739
801
|
</div>
|
|
@@ -743,13 +805,13 @@ export function SceneEditor({
|
|
|
743
805
|
icon="undo"
|
|
744
806
|
label="Undo"
|
|
745
807
|
onClick={history.undo}
|
|
746
|
-
disabled={!history.canUndo}
|
|
808
|
+
disabled={readOnly || !history.canUndo}
|
|
747
809
|
/>
|
|
748
810
|
<IconButton
|
|
749
811
|
icon="redo"
|
|
750
812
|
label="Redo"
|
|
751
813
|
onClick={history.redo}
|
|
752
|
-
disabled={!history.canRedo}
|
|
814
|
+
disabled={readOnly || !history.canRedo}
|
|
753
815
|
/>
|
|
754
816
|
</div>
|
|
755
817
|
)}
|
|
@@ -791,6 +853,8 @@ export function SceneEditor({
|
|
|
791
853
|
onAddBehavior={blueprintActions.addBehavior}
|
|
792
854
|
onRemoveBehavior={blueprintActions.removeBehavior}
|
|
793
855
|
onSelectShape={setColliderShapeSel}
|
|
856
|
+
scenePath={path}
|
|
857
|
+
readOnly={blueprintLocked}
|
|
794
858
|
/>
|
|
795
859
|
) : showMulti ? (
|
|
796
860
|
<MultiSelectInspector
|
|
@@ -815,15 +879,21 @@ export function SceneEditor({
|
|
|
815
879
|
onSetComponent={actions.updateComponent}
|
|
816
880
|
onAddBehavior={actions.addBehavior}
|
|
817
881
|
onRemoveBehavior={actions.removeBehavior}
|
|
818
|
-
|
|
882
|
+
onNewBlueprint={isBlueprintFile ? undefined : onNewBlueprintFromActor}
|
|
819
883
|
onEditBlueprint={
|
|
820
|
-
isBlueprintFile || !
|
|
884
|
+
isBlueprintFile || !selectedActorBlueprint
|
|
821
885
|
? undefined
|
|
822
|
-
: () => onSelectBlueprint(
|
|
886
|
+
: () => onSelectBlueprint(selectedActorBlueprint)
|
|
823
887
|
}
|
|
824
888
|
onBeginPick={beginPick}
|
|
825
889
|
pickActive={Boolean(pickRequest)}
|
|
826
890
|
onSelectShape={setColliderShapeSel}
|
|
891
|
+
// An instance's edits write THIS scene, so the scene's answer
|
|
892
|
+
// is the right one -- unlike the blueprint inspector below,
|
|
893
|
+
// which asks about the file it has selected. Without this the
|
|
894
|
+
// fields look live in an import's scene and the writes are
|
|
895
|
+
// dropped further down, at `applyScene`.
|
|
896
|
+
readOnly={readOnly}
|
|
827
897
|
/>
|
|
828
898
|
) : (
|
|
829
899
|
<SceneInspector
|
|
@@ -854,20 +924,20 @@ export function SceneEditor({
|
|
|
854
924
|
// THIS scene -- a separate, persistent preview alongside the editor (vs the
|
|
855
925
|
// in-panel play toggle). Defaults to an already-open preview for this scene,
|
|
856
926
|
// else opens a new one (handled shell-side, keyed by scene).
|
|
857
|
-
function HeaderPlaybackButtons({ isPlaying, setIsPlaying, history }) {
|
|
927
|
+
function HeaderPlaybackButtons({ isPlaying, setIsPlaying, history, readOnly }) {
|
|
858
928
|
return (
|
|
859
929
|
<>
|
|
860
930
|
<IconButton
|
|
861
931
|
icon="undo"
|
|
862
932
|
label="Undo"
|
|
863
933
|
onClick={history.undo}
|
|
864
|
-
disabled={!history.canUndo || isPlaying}
|
|
934
|
+
disabled={readOnly || !history.canUndo || isPlaying}
|
|
865
935
|
/>
|
|
866
936
|
<IconButton
|
|
867
937
|
icon="redo"
|
|
868
938
|
label="Redo"
|
|
869
939
|
onClick={history.redo}
|
|
870
|
-
disabled={!history.canRedo || isPlaying}
|
|
940
|
+
disabled={readOnly || !history.canRedo || isPlaying}
|
|
871
941
|
/>
|
|
872
942
|
<IconButton
|
|
873
943
|
icon={isPlaying ? 'stop' : 'play'}
|
|
@@ -1830,7 +1900,7 @@ function SceneInspector({ sceneData, snapSettings, onChangeScene, onChangeEditor
|
|
|
1830
1900
|
// Typing edits a LOCAL draft; nothing is written until blur/Enter. A
|
|
1831
1901
|
// per-keystroke write is debounced, and one still in flight when the cascade
|
|
1832
1902
|
// moves the file would land its text back at the old path.
|
|
1833
|
-
function BlueprintNameField({ name, autoFocus, onFocused, onRename, onRenameCommit }) {
|
|
1903
|
+
function BlueprintNameField({ name, autoFocus, onFocused, onRename, onRenameCommit, readOnly }) {
|
|
1834
1904
|
const deferred = editorFlags.renameBlueprintFiles;
|
|
1835
1905
|
const [draft, setDraft] = useState(name);
|
|
1836
1906
|
const inputRef = useRef(null);
|
|
@@ -1847,7 +1917,10 @@ function BlueprintNameField({ name, autoFocus, onFocused, onRename, onRenameComm
|
|
|
1847
1917
|
return (
|
|
1848
1918
|
<input
|
|
1849
1919
|
ref={inputRef}
|
|
1850
|
-
className={styles.blueprintNameInput}
|
|
1920
|
+
className={cx(styles.blueprintNameInput, readOnly && styles.blueprintNameInputLocked)}
|
|
1921
|
+
// `readOnly` rather than `disabled`: the name is still worth reading and
|
|
1922
|
+
// copying out of an import's blueprint, it just can't be changed here.
|
|
1923
|
+
readOnly={readOnly}
|
|
1851
1924
|
value={deferred ? draft : name}
|
|
1852
1925
|
onChange={(event) => {
|
|
1853
1926
|
if (deferred) setDraft(event.target.value);
|
|
@@ -1889,15 +1962,36 @@ function BlueprintInspector({
|
|
|
1889
1962
|
onAddBehavior,
|
|
1890
1963
|
onRemoveBehavior,
|
|
1891
1964
|
onSelectShape,
|
|
1965
|
+
scenePath,
|
|
1966
|
+
readOnly = false,
|
|
1892
1967
|
}) {
|
|
1893
1968
|
const templateActor = { id: '__blueprint__', components: template.components };
|
|
1894
|
-
const instanceCount = countBlueprintInstances(files, blueprintPath);
|
|
1969
|
+
const instanceCount = countBlueprintInstances(files, blueprintPath, scenePath);
|
|
1970
|
+
const alias = importAliasOf(blueprintPath);
|
|
1895
1971
|
// Editable only when the deck owns the sprite -- an import's art is read-only.
|
|
1896
1972
|
const spritePath = template.components?.Sprite?.file;
|
|
1897
1973
|
const canEditSprite =
|
|
1898
1974
|
Boolean(spritePath) && !isImportedPath(spritePath) && files?.[spritePath] !== undefined;
|
|
1899
1975
|
return (
|
|
1900
1976
|
<>
|
|
1977
|
+
{/* The hotbar lists an import's blueprints beside this deck's own, and the
|
|
1978
|
+
inspector looks the same for both. Says whose file this is, and stands
|
|
1979
|
+
in for the shell's banner, which describes the open scene rather than
|
|
1980
|
+
the blueprint selected inside it. Same wording as that banner. */}
|
|
1981
|
+
{alias ? (
|
|
1982
|
+
<div className={styles.blueprintProvenance} title={blueprintPath}>
|
|
1983
|
+
<span
|
|
1984
|
+
className={cx(
|
|
1985
|
+
styles.blueprintProvenanceChip,
|
|
1986
|
+
!readOnly && styles.blueprintProvenanceForked
|
|
1987
|
+
)}>
|
|
1988
|
+
{readOnly ? 'Read Only' : 'Forked'}
|
|
1989
|
+
</span>
|
|
1990
|
+
<span className={styles.blueprintProvenanceText}>
|
|
1991
|
+
{readOnly ? `Imported from ${alias}` : `Your version of a file from ${alias}`}
|
|
1992
|
+
</span>
|
|
1993
|
+
</div>
|
|
1994
|
+
) : null}
|
|
1901
1995
|
<div className={styles.instanceHeader}>
|
|
1902
1996
|
<div className={styles.instanceHeaderName}>
|
|
1903
1997
|
{canEditSprite ? (
|
|
@@ -1925,6 +2019,7 @@ function BlueprintInspector({
|
|
|
1925
2019
|
onFocused={onNameFocused}
|
|
1926
2020
|
onRename={onRename}
|
|
1927
2021
|
onRenameCommit={onRenameCommit}
|
|
2022
|
+
readOnly={readOnly}
|
|
1928
2023
|
/>
|
|
1929
2024
|
<span className={styles.instanceHeaderId}>
|
|
1930
2025
|
{instanceCount} {instanceCount === 1 ? 'actor' : 'actors'}
|
|
@@ -1945,6 +2040,7 @@ function BlueprintInspector({
|
|
|
1945
2040
|
onAddBehavior={(actorId, behaviorName) => onAddBehavior(behaviorName)}
|
|
1946
2041
|
onRemoveBehavior={(actorId, behaviorName) => onRemoveBehavior(behaviorName)}
|
|
1947
2042
|
onSelectShape={onSelectShape}
|
|
2043
|
+
readOnly={readOnly}
|
|
1948
2044
|
/>
|
|
1949
2045
|
</>
|
|
1950
2046
|
);
|
|
@@ -1984,13 +2080,19 @@ function ActorInspector({
|
|
|
1984
2080
|
onSetComponent,
|
|
1985
2081
|
onAddBehavior,
|
|
1986
2082
|
onRemoveBehavior,
|
|
1987
|
-
|
|
2083
|
+
onNewBlueprint,
|
|
1988
2084
|
onEditBlueprint,
|
|
1989
2085
|
onBeginPick,
|
|
1990
2086
|
pickActive,
|
|
1991
2087
|
onSelectShape,
|
|
1992
2088
|
onViewSource,
|
|
1993
2089
|
ownerKey = '',
|
|
2090
|
+
// The inspected file can't be written -- an import's blueprint. Only the
|
|
2091
|
+
// affordances that WRITE go: the fields, adding a behavior, removing one,
|
|
2092
|
+
// toggling one off. Reading stays, which is most of the reason to open
|
|
2093
|
+
// somebody else's blueprint at all: View source, collapsing a panel, and
|
|
2094
|
+
// reordering them (that is a local view preference, not a file edit).
|
|
2095
|
+
readOnly = false,
|
|
1994
2096
|
}) {
|
|
1995
2097
|
const isInstance = Boolean(rawActor?.blueprint);
|
|
1996
2098
|
const presentNames = new Set(
|
|
@@ -2066,19 +2168,21 @@ function ActorInspector({
|
|
|
2066
2168
|
<span>Edit blueprint</span>
|
|
2067
2169
|
</button>
|
|
2068
2170
|
) : null}
|
|
2069
|
-
{
|
|
2171
|
+
{onNewBlueprint ? (
|
|
2070
2172
|
<button
|
|
2071
2173
|
type="button"
|
|
2072
2174
|
className={styles.instanceForkButton}
|
|
2073
|
-
onClick={
|
|
2175
|
+
onClick={onNewBlueprint}
|
|
2074
2176
|
title="New blueprint from this actor">
|
|
2075
|
-
<Icon name="
|
|
2076
|
-
|
|
2177
|
+
<Icon name="clone" />
|
|
2178
|
+
{/* Not bare "New blueprint": that is the hotbar's plus button,
|
|
2179
|
+
which mints an empty one. This starts from the selection. */}
|
|
2180
|
+
<span>New blueprint from actor</span>
|
|
2077
2181
|
</button>
|
|
2078
2182
|
) : null}
|
|
2079
2183
|
</div>
|
|
2080
2184
|
) : null}
|
|
2081
|
-
{showAddBehavior ? (
|
|
2185
|
+
{showAddBehavior && !readOnly ? (
|
|
2082
2186
|
<AddBehaviorPicker
|
|
2083
2187
|
available={availableBehaviors}
|
|
2084
2188
|
onAdd={(behaviorName) => onAddBehavior(selectedActor.id, behaviorName)}
|
|
@@ -2105,6 +2209,7 @@ function ActorInspector({
|
|
|
2105
2209
|
onCollapseChanged={() => setOrderTick((tick) => tick + 1)}
|
|
2106
2210
|
onViewSource={onViewSource}
|
|
2107
2211
|
isLast={index === orderedEntries.length - 1 && !showReveal}
|
|
2212
|
+
readOnly={readOnly}
|
|
2108
2213
|
/>
|
|
2109
2214
|
))}
|
|
2110
2215
|
{showReveal ? (
|
|
@@ -2140,6 +2245,7 @@ function BehaviorRow({
|
|
|
2140
2245
|
onCollapseChanged,
|
|
2141
2246
|
onViewSource,
|
|
2142
2247
|
isLast,
|
|
2248
|
+
readOnly = false,
|
|
2143
2249
|
}) {
|
|
2144
2250
|
const { isDragging, rowProps, handleProps } = usePanelSortable(behaviorName);
|
|
2145
2251
|
const Behavior = behaviorClasses.find((candidate) => candidate.behaviorName === behaviorName);
|
|
@@ -2213,12 +2319,20 @@ function BehaviorRow({
|
|
|
2213
2319
|
onViewSource={
|
|
2214
2320
|
sourcePath ? { path: sourcePath, open: () => void onViewSource?.(sourcePath) } : null
|
|
2215
2321
|
}
|
|
2216
|
-
onRemove={
|
|
2322
|
+
onRemove={
|
|
2323
|
+
removable && !readOnly ? () => onRemoveBehavior(selectedActor.id, behaviorName) : null
|
|
2324
|
+
}
|
|
2325
|
+
// Still passed when read-only: the panel dims a disabled behavior's body
|
|
2326
|
+
// from this, which is worth seeing whether or not you can change it.
|
|
2217
2327
|
enabled={enabled}
|
|
2218
2328
|
onToggleEnabled={
|
|
2219
|
-
canToggle ? () => setComponent({ $enabled: enabled ? false : true }) : null
|
|
2329
|
+
canToggle && !readOnly ? () => setComponent({ $enabled: enabled ? false : true }) : null
|
|
2220
2330
|
}
|
|
2221
|
-
dragging={isDragging}
|
|
2331
|
+
dragging={isDragging}
|
|
2332
|
+
// Blocks the panel's body only. Not wrappable from here: `body` renders
|
|
2333
|
+
// the whole `<Panel>`, header included, so a wrapper around it would
|
|
2334
|
+
// take the collapse toggle and View source with it.
|
|
2335
|
+
readOnly={readOnly}>
|
|
2222
2336
|
{body}
|
|
2223
2337
|
</BehaviorPanel>
|
|
2224
2338
|
</div>
|
|
@@ -272,6 +272,12 @@ export function SingleEditor({ path, editor, editorModule }) {
|
|
|
272
272
|
sprites={sprites}
|
|
273
273
|
onChange={onChange}
|
|
274
274
|
onChangeFile={onChangeFile}
|
|
275
|
+
readOnly={readOnly}
|
|
276
|
+
// `readOnly` answers for the open scene. The blueprint inspector edits a
|
|
277
|
+
// DIFFERENT file, whose answer can differ either way: an import's scene
|
|
278
|
+
// can show a blueprint of your own, and your scene can show one of
|
|
279
|
+
// theirs.
|
|
280
|
+
isWritable={isWritable}
|
|
275
281
|
selectedActorIds={selectedActorIds}
|
|
276
282
|
onSelectActorIds={setSelectedActorIds}
|
|
277
283
|
multiSelectMode={multiSelectMode}
|