castle-web-cli 0.4.148 → 0.4.150
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/api.d.ts +14 -0
- package/dist/api.js +18 -0
- package/dist/castle-host/host.d.ts +17 -0
- package/dist/castle-host/host.js +58 -0
- 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/index.js +8 -8
- package/dist/init.js +10 -2
- package/dist/list-decks.js +7 -6
- package/dist/preview.d.ts +1 -1
- package/dist/preview.js +4 -2
- package/dist/save-deck.js +63 -14
- package/dist/serve.js +269 -108
- package/dist/serveSecurity.d.ts +7 -1
- package/dist/serveSecurity.js +65 -16
- package/dist/serverBundle.d.ts +8 -0
- package/dist/serverBundle.js +82 -0
- package/dist/shell/assets/{index-CL9TuLXb.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.json +5 -2
- 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 +319 -140
- 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/kits/physics-3d/castle.json +1 -1
- package/kits/physics-3d/engine3d/PxModelEditor.jsx +29 -13
- package/kits/physics-3d/engine3d/Scene3DEditor.jsx +26 -7
- package/kits/physics-3d/engine3d/editorChrome.jsx +26 -1
- package/package.json +1 -1
- package/dist/shell/assets/index-DN8HQBnW.css +0 -1
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { onSaveReloadState,
|
|
2
|
+
import { onSaveReloadState, resolveDeckFile, takeReloadState, writeFile } from 'castle-web-sdk';
|
|
3
|
+
import * as castleSdk from 'castle-web-sdk';
|
|
4
|
+
|
|
5
|
+
// Same tolerance as SingleEditor's onSaveState/hasPendingSave: a deck that takes
|
|
6
|
+
// a kit update keeps whatever SDK it already installed, so these may be absent.
|
|
7
|
+
// Without openFile, view-source/edit-sprite taps do nothing; without renameFile,
|
|
8
|
+
// a blueprint rename throws inside its try and keeps the old paths -- degraded,
|
|
9
|
+
// not broken.
|
|
10
|
+
const openFile = castleSdk.openFile ?? (() => undefined);
|
|
11
|
+
const renameFile =
|
|
12
|
+
castleSdk.renameFile ??
|
|
13
|
+
(() => {
|
|
14
|
+
throw new Error('renameFile needs a newer castle-web-sdk');
|
|
15
|
+
});
|
|
3
16
|
import { basename, formatJson, parseJsonFile } from '../engine/files';
|
|
4
17
|
import {
|
|
5
18
|
arrangeActors,
|
|
@@ -19,12 +32,13 @@ import {
|
|
|
19
32
|
cascadeDeleteBlueprint,
|
|
20
33
|
countBlueprintInstances,
|
|
21
34
|
createBlueprint,
|
|
22
|
-
forkActorToBlueprint,
|
|
23
35
|
getBlueprintTemplate,
|
|
36
|
+
importAliasOf,
|
|
24
37
|
isBlueprintPath,
|
|
25
38
|
isImportedPath,
|
|
26
39
|
isInheritedProp,
|
|
27
40
|
migrateOrphanActors,
|
|
41
|
+
newBlueprintFromActor,
|
|
28
42
|
placeBlueprintInstance,
|
|
29
43
|
renameBlueprintCascade,
|
|
30
44
|
setBlueprintName,
|
|
@@ -104,8 +118,7 @@ const MIN_EDIT_ZOOM = 0.4;
|
|
|
104
118
|
const MAX_EDIT_ZOOM = 6;
|
|
105
119
|
// Wheel-delta -> zoom-factor sensitivity for trackpad pinch (ctrl+wheel).
|
|
106
120
|
const ZOOM_WHEEL_SPEED = 0.01;
|
|
107
|
-
const clampZoom = (zoom) =>
|
|
108
|
-
Math.min(MAX_EDIT_ZOOM, Math.max(MIN_EDIT_ZOOM, Number(zoom) || 1));
|
|
121
|
+
const clampZoom = (zoom) => Math.min(MAX_EDIT_ZOOM, Math.max(MIN_EDIT_ZOOM, Number(zoom) || 1));
|
|
109
122
|
// Derive the effective edit viewport for a zoom level. Both extent and origin
|
|
110
123
|
// scale by 1/zoom, which keeps the canvas draw path, `screenToCard`, and the
|
|
111
124
|
// SelectionOverlay's `sx = box/card` projection mutually consistent (the overlay
|
|
@@ -141,19 +154,26 @@ function stripTemplateId(sceneData) {
|
|
|
141
154
|
// fire-and-forget (they're brand new files, nothing else references them
|
|
142
155
|
// yet) while the scene rewrite goes through this file's own `onChange` so it
|
|
143
156
|
// picks up the normal history/live-reload path.
|
|
144
|
-
function useMigrateOrphanActors({ isBlueprintFile, sceneData, files, text, onChange }) {
|
|
157
|
+
function useMigrateOrphanActors({ isBlueprintFile, sceneData, files, text, onChange, readOnly }) {
|
|
145
158
|
useEffect(() => {
|
|
146
|
-
|
|
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;
|
|
147
162
|
const hasOrphans = (sceneData.actors ?? []).some((actor) => !actor.blueprint);
|
|
148
163
|
if (!hasOrphans) return;
|
|
149
|
-
const { sceneData: migrated, newBlueprintFiles } = migrateOrphanActors(
|
|
150
|
-
|
|
164
|
+
const { sceneData: migrated, newBlueprintFiles } = migrateOrphanActors(
|
|
165
|
+
files,
|
|
166
|
+
behaviorClasses,
|
|
167
|
+
sceneData
|
|
168
|
+
);
|
|
169
|
+
for (const blueprintFile of newBlueprintFiles)
|
|
170
|
+
void writeFile(blueprintFile.path, blueprintFile.text);
|
|
151
171
|
onChange(formatJson(migrated));
|
|
152
172
|
// Re-run only when this file's own text changes (e.g. after the migration
|
|
153
173
|
// write lands, or the user opens a different orphaned file) -- `files`
|
|
154
174
|
// changes on every keystroke elsewhere and would otherwise loop.
|
|
155
175
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
156
|
-
}, [text, isBlueprintFile]);
|
|
176
|
+
}, [text, isBlueprintFile, readOnly]);
|
|
157
177
|
}
|
|
158
178
|
export function SceneEditor({
|
|
159
179
|
path,
|
|
@@ -165,6 +185,16 @@ export function SceneEditor({
|
|
|
165
185
|
onToggleFiles,
|
|
166
186
|
filesOpen,
|
|
167
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,
|
|
168
198
|
selectedActorIds,
|
|
169
199
|
onSelectActorIds: onSelectActorIdsRaw,
|
|
170
200
|
multiSelectMode,
|
|
@@ -248,7 +278,7 @@ export function SceneEditor({
|
|
|
248
278
|
// Disabled during play: the header undo/redo buttons are already disabled
|
|
249
279
|
// then, but without this the keyboard shortcut could still rewrite the
|
|
250
280
|
// scene file out from under the running play-mode runtime.
|
|
251
|
-
useUndoRedoShortcuts(history, !isPlaying);
|
|
281
|
+
useUndoRedoShortcuts(history, !isPlaying && !readOnly);
|
|
252
282
|
// Stash ephemeral editor state right before a reload so it survives an agent
|
|
253
283
|
// code edit. `editCamera` is read live from the ref at save time (a reload is
|
|
254
284
|
// imminent, so the latest value is what matters); isPlaying / blueprint
|
|
@@ -269,13 +299,22 @@ export function SceneEditor({
|
|
|
269
299
|
// Sparse per-instance overrides merged with each actor's blueprint template
|
|
270
300
|
// -- what hit-testing, drag-start snapshots, and the inspector should read.
|
|
271
301
|
// Never the basis for a write (see engine/blueprint.js).
|
|
272
|
-
const previewSceneData = sceneData
|
|
302
|
+
const previewSceneData = sceneData
|
|
303
|
+
? makeScene(sceneData, behaviorClasses, sprites, files, path).data
|
|
304
|
+
: null;
|
|
273
305
|
const serialize = useCallback(
|
|
274
306
|
(next) => formatJson(isBlueprintFile ? stripTemplateId(next) : next),
|
|
275
307
|
[isBlueprintFile]
|
|
276
308
|
);
|
|
277
309
|
const getRuntime = useCallback(() => runtimeRef.current, []);
|
|
278
|
-
|
|
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 });
|
|
279
318
|
useScenePlayLoop({
|
|
280
319
|
sceneData,
|
|
281
320
|
sprites,
|
|
@@ -316,8 +355,8 @@ export function SceneEditor({
|
|
|
316
355
|
editCameraRef,
|
|
317
356
|
pickRequestRef,
|
|
318
357
|
onPickTarget,
|
|
319
|
-
applyScene
|
|
320
|
-
recordSceneSnapshot
|
|
358
|
+
applyScene,
|
|
359
|
+
recordSceneSnapshot,
|
|
321
360
|
});
|
|
322
361
|
const playPointer = usePlayPointerGesture({ canvasRef, runtimeRef });
|
|
323
362
|
// Touch: one finger selects/drags actors, a second finger pinch-zooms about the
|
|
@@ -335,8 +374,8 @@ export function SceneEditor({
|
|
|
335
374
|
panGesture.panByScreenDelta(-dx, -dy);
|
|
336
375
|
},
|
|
337
376
|
// Procreate convention: two-finger tap undoes, three-finger tap redoes.
|
|
338
|
-
onUndo: () => history.undo(),
|
|
339
|
-
onRedo: () => history.redo(),
|
|
377
|
+
onUndo: readOnly ? undefined : () => history.undo(),
|
|
378
|
+
onRedo: readOnly ? undefined : () => history.redo(),
|
|
340
379
|
});
|
|
341
380
|
useSelectionKeyboard({
|
|
342
381
|
sceneData,
|
|
@@ -347,7 +386,7 @@ export function SceneEditor({
|
|
|
347
386
|
onSetMultiSelectMode,
|
|
348
387
|
isPlaying,
|
|
349
388
|
isBlueprintFile,
|
|
350
|
-
commitScene
|
|
389
|
+
commitScene,
|
|
351
390
|
});
|
|
352
391
|
if (!sceneData) {
|
|
353
392
|
return (
|
|
@@ -372,15 +411,28 @@ export function SceneEditor({
|
|
|
372
411
|
selectedActorIds.length === 1
|
|
373
412
|
? previewSceneData.actors.find((actor) => actor.id === selectedActorIds[0])
|
|
374
413
|
: undefined;
|
|
375
|
-
|
|
376
|
-
|
|
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)
|
|
377
425
|
: undefined;
|
|
378
|
-
const selectedBlueprintName =
|
|
379
|
-
? selectedBlueprintTemplate?.name ?? basename(
|
|
426
|
+
const selectedBlueprintName = selectedActorBlueprint
|
|
427
|
+
? (selectedBlueprintTemplate?.name ?? basename(selectedActorBlueprint))
|
|
380
428
|
: undefined;
|
|
381
429
|
// Hotbar-selected blueprint, resolved fresh from live files each render. A
|
|
382
430
|
// selection whose file vanished (cascade delete, external edit) degrades to
|
|
383
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.
|
|
384
436
|
const hotbarBlueprint =
|
|
385
437
|
!isBlueprintFile && selectedBlueprintPath
|
|
386
438
|
? getBlueprintTemplate(files, selectedBlueprintPath)
|
|
@@ -388,6 +440,11 @@ export function SceneEditor({
|
|
|
388
440
|
// Only dim for a blueprint that actually resolves to an inspectable template
|
|
389
441
|
// (mirrors the sidebar): a vanished/stale selection highlights nothing.
|
|
390
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);
|
|
391
448
|
// Template edits from the sidebar write the BLUEPRINT file, not this scene:
|
|
392
449
|
// optimistic fold into live files state (instant merged-instance updates
|
|
393
450
|
// here) + debounced writeFile via SingleEditor's saver, which also makes
|
|
@@ -395,7 +452,7 @@ export function SceneEditor({
|
|
|
395
452
|
// per-property merge semantics as editing the blueprint's own file. Outside
|
|
396
453
|
// this scene file's undo history (accepted v1 cross-file gap, like fork).
|
|
397
454
|
const updateBlueprintTemplate = (mutate) => {
|
|
398
|
-
if (!selectedBlueprintPath || !hotbarBlueprint) return;
|
|
455
|
+
if (blueprintLocked || !selectedBlueprintPath || !hotbarBlueprint) return;
|
|
399
456
|
const components = structuredClone(hotbarBlueprint.components);
|
|
400
457
|
mutate(components);
|
|
401
458
|
const nextText = setBlueprintTemplateComponents(files, selectedBlueprintPath, components);
|
|
@@ -431,7 +488,7 @@ export function SceneEditor({
|
|
|
431
488
|
// per keystroke, which would strew `w.scene`, `wa.scene`, … across the deck.
|
|
432
489
|
// See `renameCommit`.
|
|
433
490
|
rename: (name) => {
|
|
434
|
-
if (!selectedBlueprintPath) return;
|
|
491
|
+
if (blueprintLocked || !selectedBlueprintPath) return;
|
|
435
492
|
const nextText = setBlueprintName(files, selectedBlueprintPath, name);
|
|
436
493
|
if (nextText == null) return;
|
|
437
494
|
if (onChangeFile) onChangeFile(selectedBlueprintPath, nextText);
|
|
@@ -440,9 +497,14 @@ export function SceneEditor({
|
|
|
440
497
|
// Move the file to the name's slug, bring its auto-minted drawing along, and
|
|
441
498
|
// repoint every instance in every scene.
|
|
442
499
|
renameCommit: async (name) => {
|
|
443
|
-
if (!editorFlags.renameBlueprintFiles || !selectedBlueprintPath) return;
|
|
500
|
+
if (blueprintLocked || !editorFlags.renameBlueprintFiles || !selectedBlueprintPath) return;
|
|
444
501
|
const result = renameBlueprintCascade(files, selectedBlueprintPath, name);
|
|
445
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;
|
|
446
508
|
// Moves first, then content: a write must never land on a path about to
|
|
447
509
|
// move out from under it.
|
|
448
510
|
for (const move of result.fileRenames) {
|
|
@@ -463,7 +525,7 @@ export function SceneEditor({
|
|
|
463
525
|
sceneData,
|
|
464
526
|
files,
|
|
465
527
|
serialize,
|
|
466
|
-
commit: history.commit,
|
|
528
|
+
commit: readOnly ? () => {} : history.commit,
|
|
467
529
|
selectedActorIds,
|
|
468
530
|
onSelectActorIds,
|
|
469
531
|
isBlueprintFile,
|
|
@@ -475,14 +537,18 @@ export function SceneEditor({
|
|
|
475
537
|
backgroundColor: darkenSceneBackground(sceneData.background),
|
|
476
538
|
};
|
|
477
539
|
const updateSceneSettings = (nextScene) => {
|
|
478
|
-
|
|
540
|
+
commitScene(setSceneSettings(sceneData, nextScene));
|
|
479
541
|
};
|
|
480
542
|
const updateSceneEditorSettings = (nextEditor) => {
|
|
481
|
-
|
|
543
|
+
commitScene(setSceneEditorSettings(sceneData, nextEditor));
|
|
482
544
|
};
|
|
483
545
|
// Lands on the BLUEPRINT inspector, not the actor one: the actor is a placed
|
|
484
546
|
// copy, and the blueprint is where the name and sprite are.
|
|
485
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;
|
|
486
552
|
// Add both generated files to the live map before committing the instance.
|
|
487
553
|
// Otherwise another + click can mint the same numbered paths while the fs
|
|
488
554
|
// watcher's asynchronous echo of these direct writes is still pending.
|
|
@@ -538,11 +604,24 @@ export function SceneEditor({
|
|
|
538
604
|
// that predates the placement.
|
|
539
605
|
const dragPlace = {
|
|
540
606
|
enter: (blueprintPath, position) => {
|
|
541
|
-
|
|
542
|
-
|
|
607
|
+
if (readOnly) return;
|
|
608
|
+
recordSceneSnapshot();
|
|
609
|
+
const { sceneData: next, newId } = placeBlueprintInstance(
|
|
610
|
+
sceneData,
|
|
611
|
+
files,
|
|
612
|
+
blueprintPath,
|
|
613
|
+
position,
|
|
614
|
+
snapSettings
|
|
615
|
+
);
|
|
543
616
|
const layout = next.actors.find((actor) => actor.id === newId)?.components?.Layout ?? {};
|
|
544
|
-
dragPlaceRef.current = {
|
|
545
|
-
|
|
617
|
+
dragPlaceRef.current = {
|
|
618
|
+
actorId: newId,
|
|
619
|
+
blueprintPath,
|
|
620
|
+
sceneData: next,
|
|
621
|
+
x: layout.x,
|
|
622
|
+
y: layout.y,
|
|
623
|
+
};
|
|
624
|
+
applyScene(next);
|
|
546
625
|
onSelectActorIds([newId]);
|
|
547
626
|
},
|
|
548
627
|
move: (position) => {
|
|
@@ -555,13 +634,13 @@ export function SceneEditor({
|
|
|
555
634
|
if (!actor) return;
|
|
556
635
|
actor.components.Layout = { ...actor.components.Layout, x, y };
|
|
557
636
|
Object.assign(drag, { sceneData: next, x, y });
|
|
558
|
-
|
|
637
|
+
applyScene(next);
|
|
559
638
|
},
|
|
560
639
|
leave: () => {
|
|
561
640
|
const drag = dragPlaceRef.current;
|
|
562
641
|
if (!drag) return;
|
|
563
642
|
dragPlaceRef.current = null;
|
|
564
|
-
|
|
643
|
+
applyScene(removeActors(drag.sceneData, [drag.actorId]));
|
|
565
644
|
onSelectActorIds([]);
|
|
566
645
|
},
|
|
567
646
|
drop: () => {
|
|
@@ -572,21 +651,32 @@ export function SceneEditor({
|
|
|
572
651
|
},
|
|
573
652
|
};
|
|
574
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;
|
|
575
663
|
// Every write here targets a plain `scenes/*.scene` (cascaded instance
|
|
576
664
|
// removal) or the blueprint file itself (tombstoned) -- never a
|
|
577
665
|
// blueprint's own template id, so no `serialize`/strip step is needed.
|
|
578
|
-
for (const write of
|
|
666
|
+
for (const write of cascade) {
|
|
579
667
|
if (write.path === path) history.commit(write.text);
|
|
580
668
|
else void writeFile(write.path, write.text);
|
|
581
669
|
}
|
|
582
670
|
onSelectActorIds([]);
|
|
583
671
|
};
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
|
|
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);
|
|
587
677
|
if (!result) return;
|
|
588
678
|
void writeFile(result.blueprintFile.path, result.blueprintFile.text);
|
|
589
|
-
|
|
679
|
+
commitScene(result.sceneData);
|
|
590
680
|
};
|
|
591
681
|
return (
|
|
592
682
|
<>
|
|
@@ -598,7 +688,7 @@ export function SceneEditor({
|
|
|
598
688
|
{sceneData.name ?? basename(path)}
|
|
599
689
|
</span>
|
|
600
690
|
) : (
|
|
601
|
-
sceneData.name ?? basename(path)
|
|
691
|
+
(sceneData.name ?? basename(path))
|
|
602
692
|
)
|
|
603
693
|
}
|
|
604
694
|
subtitle={
|
|
@@ -613,6 +703,7 @@ export function SceneEditor({
|
|
|
613
703
|
isPlaying={isPlaying}
|
|
614
704
|
setIsPlaying={setIsPlaying}
|
|
615
705
|
history={history}
|
|
706
|
+
readOnly={readOnly}
|
|
616
707
|
/>
|
|
617
708
|
}
|
|
618
709
|
onToggleFiles={onToggleFiles}
|
|
@@ -629,8 +720,10 @@ export function SceneEditor({
|
|
|
629
720
|
canvasRef={canvasRef}
|
|
630
721
|
editCameraRef={editCameraRef}
|
|
631
722
|
isPlaying={isPlaying}
|
|
723
|
+
readOnly={readOnly}
|
|
724
|
+
isWritable={isWritable}
|
|
632
725
|
selectedBlueprintPath={selectedBlueprintPath}
|
|
633
|
-
instanceBlueprintPath={
|
|
726
|
+
instanceBlueprintPath={selectedActorBlueprint}
|
|
634
727
|
onSelectBlueprint={onSelectBlueprint}
|
|
635
728
|
onAddActor={onAddActor}
|
|
636
729
|
dragPlace={dragPlace}
|
|
@@ -698,11 +791,11 @@ export function SceneEditor({
|
|
|
698
791
|
selectedActorIds={selectedActorIds}
|
|
699
792
|
selectedColliderShape={colliderShapeSel}
|
|
700
793
|
snap={snapSettings}
|
|
701
|
-
onArrange={isBlueprintFile ? undefined : actions.arrangeSelection}
|
|
702
|
-
onClone={isBlueprintFile ? undefined : actions.duplicateSelection}
|
|
703
|
-
onDelete={isBlueprintFile ? undefined : actions.deleteSelection}
|
|
704
|
-
applyScene={
|
|
705
|
-
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}
|
|
706
799
|
/>
|
|
707
800
|
)}
|
|
708
801
|
</div>
|
|
@@ -712,13 +805,13 @@ export function SceneEditor({
|
|
|
712
805
|
icon="undo"
|
|
713
806
|
label="Undo"
|
|
714
807
|
onClick={history.undo}
|
|
715
|
-
disabled={!history.canUndo}
|
|
808
|
+
disabled={readOnly || !history.canUndo}
|
|
716
809
|
/>
|
|
717
810
|
<IconButton
|
|
718
811
|
icon="redo"
|
|
719
812
|
label="Redo"
|
|
720
813
|
onClick={history.redo}
|
|
721
|
-
disabled={!history.canRedo}
|
|
814
|
+
disabled={readOnly || !history.canRedo}
|
|
722
815
|
/>
|
|
723
816
|
</div>
|
|
724
817
|
)}
|
|
@@ -734,11 +827,7 @@ export function SceneEditor({
|
|
|
734
827
|
label="Zoom out"
|
|
735
828
|
onClick={() => panGesture.zoomAtCenter(0.8)}
|
|
736
829
|
/>
|
|
737
|
-
<IconButton
|
|
738
|
-
icon="fit"
|
|
739
|
-
label="Reset view"
|
|
740
|
-
onClick={() => panGesture.resetView()}
|
|
741
|
-
/>
|
|
830
|
+
<IconButton icon="fit" label="Reset view" onClick={() => panGesture.resetView()} />
|
|
742
831
|
</div>
|
|
743
832
|
)}
|
|
744
833
|
</div>
|
|
@@ -764,6 +853,8 @@ export function SceneEditor({
|
|
|
764
853
|
onAddBehavior={blueprintActions.addBehavior}
|
|
765
854
|
onRemoveBehavior={blueprintActions.removeBehavior}
|
|
766
855
|
onSelectShape={setColliderShapeSel}
|
|
856
|
+
scenePath={path}
|
|
857
|
+
readOnly={blueprintLocked}
|
|
767
858
|
/>
|
|
768
859
|
) : showMulti ? (
|
|
769
860
|
<MultiSelectInspector
|
|
@@ -788,15 +879,21 @@ export function SceneEditor({
|
|
|
788
879
|
onSetComponent={actions.updateComponent}
|
|
789
880
|
onAddBehavior={actions.addBehavior}
|
|
790
881
|
onRemoveBehavior={actions.removeBehavior}
|
|
791
|
-
|
|
882
|
+
onNewBlueprint={isBlueprintFile ? undefined : onNewBlueprintFromActor}
|
|
792
883
|
onEditBlueprint={
|
|
793
|
-
isBlueprintFile || !
|
|
884
|
+
isBlueprintFile || !selectedActorBlueprint
|
|
794
885
|
? undefined
|
|
795
|
-
: () => onSelectBlueprint(
|
|
886
|
+
: () => onSelectBlueprint(selectedActorBlueprint)
|
|
796
887
|
}
|
|
797
888
|
onBeginPick={beginPick}
|
|
798
889
|
pickActive={Boolean(pickRequest)}
|
|
799
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}
|
|
800
897
|
/>
|
|
801
898
|
) : (
|
|
802
899
|
<SceneInspector
|
|
@@ -827,20 +924,20 @@ export function SceneEditor({
|
|
|
827
924
|
// THIS scene -- a separate, persistent preview alongside the editor (vs the
|
|
828
925
|
// in-panel play toggle). Defaults to an already-open preview for this scene,
|
|
829
926
|
// else opens a new one (handled shell-side, keyed by scene).
|
|
830
|
-
function HeaderPlaybackButtons({ isPlaying, setIsPlaying, history }) {
|
|
927
|
+
function HeaderPlaybackButtons({ isPlaying, setIsPlaying, history, readOnly }) {
|
|
831
928
|
return (
|
|
832
929
|
<>
|
|
833
930
|
<IconButton
|
|
834
931
|
icon="undo"
|
|
835
932
|
label="Undo"
|
|
836
933
|
onClick={history.undo}
|
|
837
|
-
disabled={!history.canUndo || isPlaying}
|
|
934
|
+
disabled={readOnly || !history.canUndo || isPlaying}
|
|
838
935
|
/>
|
|
839
936
|
<IconButton
|
|
840
937
|
icon="redo"
|
|
841
938
|
label="Redo"
|
|
842
939
|
onClick={history.redo}
|
|
843
|
-
disabled={!history.canRedo || isPlaying}
|
|
940
|
+
disabled={readOnly || !history.canRedo || isPlaying}
|
|
844
941
|
/>
|
|
845
942
|
<IconButton
|
|
846
943
|
icon={isPlaying ? 'stop' : 'play'}
|
|
@@ -906,15 +1003,28 @@ function behaviorsToAdd(behaviorName, actor, seen = new Set()) {
|
|
|
906
1003
|
return out;
|
|
907
1004
|
}
|
|
908
1005
|
|
|
909
|
-
function makeSceneActions({
|
|
1006
|
+
function makeSceneActions({
|
|
1007
|
+
sceneData,
|
|
1008
|
+
files,
|
|
1009
|
+
serialize,
|
|
1010
|
+
commit,
|
|
1011
|
+
selectedActorIds,
|
|
1012
|
+
onSelectActorIds,
|
|
1013
|
+
isBlueprintFile,
|
|
1014
|
+
sprites,
|
|
1015
|
+
resolvedActors,
|
|
1016
|
+
}) {
|
|
910
1017
|
function commitScene(next, options) {
|
|
911
1018
|
commit(serialize(next), options);
|
|
912
1019
|
}
|
|
913
1020
|
return {
|
|
914
1021
|
updateComponent: (actorId, behaviorName, nextProps) =>
|
|
915
|
-
commitScene(
|
|
916
|
-
|
|
917
|
-
|
|
1022
|
+
commitScene(
|
|
1023
|
+
setInstanceComponent(files, behaviorClasses, sceneData, actorId, behaviorName, nextProps),
|
|
1024
|
+
{
|
|
1025
|
+
coalesceKey: componentCoalesceKey(actorId, behaviorName, nextProps),
|
|
1026
|
+
}
|
|
1027
|
+
),
|
|
918
1028
|
addBehavior: (actorId, behaviorName) => {
|
|
919
1029
|
if (!findBehaviorClass(behaviorName)) return;
|
|
920
1030
|
const resolved = resolvedActors?.find((actor) => actor.id === actorId);
|
|
@@ -923,7 +1033,12 @@ function makeSceneActions({ sceneData, files, serialize, commit, selectedActorId
|
|
|
923
1033
|
for (const name of behaviorsToAdd(behaviorName, resolved)) {
|
|
924
1034
|
const Behavior = findBehaviorClass(name);
|
|
925
1035
|
if (!Behavior) continue;
|
|
926
|
-
next = setActorComponent(
|
|
1036
|
+
next = setActorComponent(
|
|
1037
|
+
next,
|
|
1038
|
+
actorId,
|
|
1039
|
+
name,
|
|
1040
|
+
initialBehaviorProps(Behavior, resolved, sprites)
|
|
1041
|
+
);
|
|
927
1042
|
}
|
|
928
1043
|
if (next !== sceneData) commitScene(next);
|
|
929
1044
|
},
|
|
@@ -1015,7 +1130,13 @@ function useSelectionGesture(args) {
|
|
|
1015
1130
|
const cam = current.editCameraRef.current;
|
|
1016
1131
|
const point = { x: raw.x + cam.x, y: raw.y + cam.y };
|
|
1017
1132
|
current.canvasRef.current.setPointerCapture(event.pointerId);
|
|
1018
|
-
const scene = makeScene(
|
|
1133
|
+
const scene = makeScene(
|
|
1134
|
+
current.sceneData,
|
|
1135
|
+
behaviorClasses,
|
|
1136
|
+
current.sprites,
|
|
1137
|
+
current.files,
|
|
1138
|
+
current.path
|
|
1139
|
+
);
|
|
1019
1140
|
const stack = scene.actorsAt(point.x, point.y);
|
|
1020
1141
|
const stackIds = stack.map((a) => a.id);
|
|
1021
1142
|
const actor = stack[0] ?? null;
|
|
@@ -1119,12 +1240,7 @@ function useSelectionGesture(args) {
|
|
|
1119
1240
|
finalizeMarquee(drag, current);
|
|
1120
1241
|
} else if (drag.kind === 'idle' && !drag.movedFar && !drag.longPressFired) {
|
|
1121
1242
|
handleTap(drag, current);
|
|
1122
|
-
} else if (
|
|
1123
|
-
drag.kind === 'move' &&
|
|
1124
|
-
!drag.movedFar &&
|
|
1125
|
-
!drag.longPressFired &&
|
|
1126
|
-
drag.cycleStack
|
|
1127
|
-
) {
|
|
1243
|
+
} else if (drag.kind === 'move' && !drag.movedFar && !drag.longPressFired && drag.cycleStack) {
|
|
1128
1244
|
cycleSelection(drag, current);
|
|
1129
1245
|
}
|
|
1130
1246
|
current.marqueeRef.current = null;
|
|
@@ -1358,18 +1474,21 @@ function usePanGesture({ canvasRef, editCameraRef, isPlaying }) {
|
|
|
1358
1474
|
canvas.removeEventListener('gestureend', onGestureEnd, opts);
|
|
1359
1475
|
};
|
|
1360
1476
|
}, [canvasRef, panByScreenDelta, zoomByFactorAtPointer]);
|
|
1361
|
-
const onPointerDown = useCallback(
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1477
|
+
const onPointerDown = useCallback(
|
|
1478
|
+
(event) => {
|
|
1479
|
+
if (isPlaying) return;
|
|
1480
|
+
// Pan when Space is held (existing modifier), on a middle-button drag, or on
|
|
1481
|
+
// a ⌘+left-drag (metaKey) — matching the art editor. preventDefault also
|
|
1482
|
+
// suppresses the browser's middle-click autoscroll.
|
|
1483
|
+
const middle = event.button === 1;
|
|
1484
|
+
const cmdDrag = event.button === 0 && event.metaKey;
|
|
1485
|
+
if (!spaceDownRef.current && !middle && !cmdDrag) return;
|
|
1486
|
+
event.preventDefault();
|
|
1487
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
1488
|
+
dragRef.current = { id: event.pointerId, lastX: event.clientX, lastY: event.clientY };
|
|
1489
|
+
},
|
|
1490
|
+
[isPlaying]
|
|
1491
|
+
);
|
|
1373
1492
|
const onPointerMove = useCallback(
|
|
1374
1493
|
(event) => {
|
|
1375
1494
|
const drag = dragRef.current;
|
|
@@ -1495,7 +1614,13 @@ function finalizeMarquee(drag, current) {
|
|
|
1495
1614
|
const m = current.marqueeRef.current;
|
|
1496
1615
|
if (!m || !current.sceneData) return;
|
|
1497
1616
|
if (m.width === 0 && m.height === 0) return;
|
|
1498
|
-
const scene = makeScene(
|
|
1617
|
+
const scene = makeScene(
|
|
1618
|
+
current.sceneData,
|
|
1619
|
+
behaviorClasses,
|
|
1620
|
+
current.sprites,
|
|
1621
|
+
current.files,
|
|
1622
|
+
current.path
|
|
1623
|
+
);
|
|
1499
1624
|
const hits = scene.actorIdsInRect(m);
|
|
1500
1625
|
const merged = new Set(drag.selectionBeforeMarquee);
|
|
1501
1626
|
for (const id of hits) merged.add(id);
|
|
@@ -1538,7 +1663,11 @@ function useSelectionKeyboard(args) {
|
|
|
1538
1663
|
const current = ref.current;
|
|
1539
1664
|
if (current.isPlaying || isEditableTarget(event.target)) return;
|
|
1540
1665
|
if (event.key === 'Escape') {
|
|
1541
|
-
if (
|
|
1666
|
+
if (
|
|
1667
|
+
current.selectedActorIds.length ||
|
|
1668
|
+
current.multiSelectMode ||
|
|
1669
|
+
current.selectedBlueprintPath
|
|
1670
|
+
) {
|
|
1542
1671
|
event.preventDefault();
|
|
1543
1672
|
// The wrapped setter also clears any hotbar blueprint selection.
|
|
1544
1673
|
current.onSelectActorIds([]);
|
|
@@ -1553,7 +1682,8 @@ function useSelectionKeyboard(args) {
|
|
|
1553
1682
|
return;
|
|
1554
1683
|
}
|
|
1555
1684
|
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'd') {
|
|
1556
|
-
if (!current.sceneData || current.isBlueprintFile || current.selectedActorIds.length === 0)
|
|
1685
|
+
if (!current.sceneData || current.isBlueprintFile || current.selectedActorIds.length === 0)
|
|
1686
|
+
return;
|
|
1557
1687
|
event.preventDefault();
|
|
1558
1688
|
const { sceneData: next, newIds } = duplicateActors(
|
|
1559
1689
|
current.sceneData,
|
|
@@ -1564,7 +1694,8 @@ function useSelectionKeyboard(args) {
|
|
|
1564
1694
|
return;
|
|
1565
1695
|
}
|
|
1566
1696
|
if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
1567
|
-
if (!current.sceneData || current.isBlueprintFile || current.selectedActorIds.length === 0)
|
|
1697
|
+
if (!current.sceneData || current.isBlueprintFile || current.selectedActorIds.length === 0)
|
|
1698
|
+
return;
|
|
1568
1699
|
event.preventDefault();
|
|
1569
1700
|
current.commitScene(removeActors(current.sceneData, current.selectedActorIds));
|
|
1570
1701
|
current.onSelectActorIds([]);
|
|
@@ -1612,9 +1743,7 @@ function useScenePlayLoop({
|
|
|
1612
1743
|
const canvas = canvasRef.current;
|
|
1613
1744
|
const ctx = canvas.getContext('2d');
|
|
1614
1745
|
if (!ctx) return undefined;
|
|
1615
|
-
const viewport = isPlaying
|
|
1616
|
-
? undefined
|
|
1617
|
-
: editViewportForZoom(editCameraRef.current.zoom);
|
|
1746
|
+
const viewport = isPlaying ? undefined : editViewportForZoom(editCameraRef.current.zoom);
|
|
1618
1747
|
configureSceneCanvas(canvas, ctx, viewport);
|
|
1619
1748
|
let raf = 0;
|
|
1620
1749
|
let last = performance.now();
|
|
@@ -1623,9 +1752,7 @@ function useScenePlayLoop({
|
|
|
1623
1752
|
last = now;
|
|
1624
1753
|
// Recompute each frame so the edit zoom (mutated on the camera ref by the
|
|
1625
1754
|
// pinch gesture) takes effect without restarting the loop.
|
|
1626
|
-
const frameViewport = isPlaying
|
|
1627
|
-
? undefined
|
|
1628
|
-
: editViewportForZoom(editCameraRef.current.zoom);
|
|
1755
|
+
const frameViewport = isPlaying ? undefined : editViewportForZoom(editCameraRef.current.zoom);
|
|
1629
1756
|
const scene = isPlaying
|
|
1630
1757
|
? runtimeRef.current
|
|
1631
1758
|
: makeScene(sceneData, behaviorClasses, sprites, files, path);
|
|
@@ -1636,7 +1763,7 @@ function useScenePlayLoop({
|
|
|
1636
1763
|
configureSceneCanvas(canvas, ctx, frameViewport);
|
|
1637
1764
|
// Read selection from the ref each frame so the grid/box gating tracks
|
|
1638
1765
|
// the current selection without resetting this loop.
|
|
1639
|
-
const editSelectedActorIds = isPlaying ? [] : selectedActorIdsRef.current ?? [];
|
|
1766
|
+
const editSelectedActorIds = isPlaying ? [] : (selectedActorIdsRef.current ?? []);
|
|
1640
1767
|
scene.draw(ctx, {
|
|
1641
1768
|
selectedActorIds: [],
|
|
1642
1769
|
marquee: isPlaying ? null : marqueeRef.current,
|
|
@@ -1653,7 +1780,7 @@ function useScenePlayLoop({
|
|
|
1653
1780
|
dimBlueprintPath: isPlaying ? null : selectedBlueprintPathRef.current,
|
|
1654
1781
|
// Highlight the collider shape the blueprint inspector has selected on
|
|
1655
1782
|
// its lit instances.
|
|
1656
|
-
colliderShapeSel: isPlaying ? -1 : colliderShapeSelRef?.current ?? -1,
|
|
1783
|
+
colliderShapeSel: isPlaying ? -1 : (colliderShapeSelRef?.current ?? -1),
|
|
1657
1784
|
});
|
|
1658
1785
|
}
|
|
1659
1786
|
raf = requestAnimationFrame(frame);
|
|
@@ -1773,7 +1900,7 @@ function SceneInspector({ sceneData, snapSettings, onChangeScene, onChangeEditor
|
|
|
1773
1900
|
// Typing edits a LOCAL draft; nothing is written until blur/Enter. A
|
|
1774
1901
|
// per-keystroke write is debounced, and one still in flight when the cascade
|
|
1775
1902
|
// moves the file would land its text back at the old path.
|
|
1776
|
-
function BlueprintNameField({ name, autoFocus, onFocused, onRename, onRenameCommit }) {
|
|
1903
|
+
function BlueprintNameField({ name, autoFocus, onFocused, onRename, onRenameCommit, readOnly }) {
|
|
1777
1904
|
const deferred = editorFlags.renameBlueprintFiles;
|
|
1778
1905
|
const [draft, setDraft] = useState(name);
|
|
1779
1906
|
const inputRef = useRef(null);
|
|
@@ -1790,7 +1917,10 @@ function BlueprintNameField({ name, autoFocus, onFocused, onRename, onRenameComm
|
|
|
1790
1917
|
return (
|
|
1791
1918
|
<input
|
|
1792
1919
|
ref={inputRef}
|
|
1793
|
-
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}
|
|
1794
1924
|
value={deferred ? draft : name}
|
|
1795
1925
|
onChange={(event) => {
|
|
1796
1926
|
if (deferred) setDraft(event.target.value);
|
|
@@ -1832,15 +1962,36 @@ function BlueprintInspector({
|
|
|
1832
1962
|
onAddBehavior,
|
|
1833
1963
|
onRemoveBehavior,
|
|
1834
1964
|
onSelectShape,
|
|
1965
|
+
scenePath,
|
|
1966
|
+
readOnly = false,
|
|
1835
1967
|
}) {
|
|
1836
1968
|
const templateActor = { id: '__blueprint__', components: template.components };
|
|
1837
|
-
const instanceCount = countBlueprintInstances(files, blueprintPath);
|
|
1969
|
+
const instanceCount = countBlueprintInstances(files, blueprintPath, scenePath);
|
|
1970
|
+
const alias = importAliasOf(blueprintPath);
|
|
1838
1971
|
// Editable only when the deck owns the sprite -- an import's art is read-only.
|
|
1839
1972
|
const spritePath = template.components?.Sprite?.file;
|
|
1840
1973
|
const canEditSprite =
|
|
1841
1974
|
Boolean(spritePath) && !isImportedPath(spritePath) && files?.[spritePath] !== undefined;
|
|
1842
1975
|
return (
|
|
1843
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}
|
|
1844
1995
|
<div className={styles.instanceHeader}>
|
|
1845
1996
|
<div className={styles.instanceHeaderName}>
|
|
1846
1997
|
{canEditSprite ? (
|
|
@@ -1868,6 +2019,7 @@ function BlueprintInspector({
|
|
|
1868
2019
|
onFocused={onNameFocused}
|
|
1869
2020
|
onRename={onRename}
|
|
1870
2021
|
onRenameCommit={onRenameCommit}
|
|
2022
|
+
readOnly={readOnly}
|
|
1871
2023
|
/>
|
|
1872
2024
|
<span className={styles.instanceHeaderId}>
|
|
1873
2025
|
{instanceCount} {instanceCount === 1 ? 'actor' : 'actors'}
|
|
@@ -1882,10 +2034,13 @@ function BlueprintInspector({
|
|
|
1882
2034
|
rawActor={templateActor}
|
|
1883
2035
|
files={files}
|
|
1884
2036
|
sprites={sprites}
|
|
1885
|
-
onSetComponent={(actorId, behaviorName, nextProps) =>
|
|
2037
|
+
onSetComponent={(actorId, behaviorName, nextProps) =>
|
|
2038
|
+
onSetComponent(behaviorName, nextProps)
|
|
2039
|
+
}
|
|
1886
2040
|
onAddBehavior={(actorId, behaviorName) => onAddBehavior(behaviorName)}
|
|
1887
2041
|
onRemoveBehavior={(actorId, behaviorName) => onRemoveBehavior(behaviorName)}
|
|
1888
2042
|
onSelectShape={onSelectShape}
|
|
2043
|
+
readOnly={readOnly}
|
|
1889
2044
|
/>
|
|
1890
2045
|
</>
|
|
1891
2046
|
);
|
|
@@ -1925,13 +2080,19 @@ function ActorInspector({
|
|
|
1925
2080
|
onSetComponent,
|
|
1926
2081
|
onAddBehavior,
|
|
1927
2082
|
onRemoveBehavior,
|
|
1928
|
-
|
|
2083
|
+
onNewBlueprint,
|
|
1929
2084
|
onEditBlueprint,
|
|
1930
2085
|
onBeginPick,
|
|
1931
2086
|
pickActive,
|
|
1932
2087
|
onSelectShape,
|
|
1933
2088
|
onViewSource,
|
|
1934
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,
|
|
1935
2096
|
}) {
|
|
1936
2097
|
const isInstance = Boolean(rawActor?.blueprint);
|
|
1937
2098
|
const presentNames = new Set(
|
|
@@ -1962,7 +2123,11 @@ function ActorInspector({
|
|
|
1962
2123
|
// since the store is plain localStorage and not reactive on its own.
|
|
1963
2124
|
const [orderTick, setOrderTick] = useState(0);
|
|
1964
2125
|
const savedOrder = useMemo(
|
|
1965
|
-
() =>
|
|
2126
|
+
() =>
|
|
2127
|
+
applyOrder(
|
|
2128
|
+
ownerKey,
|
|
2129
|
+
visibleEntries.map(([behaviorName]) => behaviorName)
|
|
2130
|
+
),
|
|
1966
2131
|
// `orderTick` is the dependency that matters after a commit; the entry list
|
|
1967
2132
|
// is what matters when the actor changes.
|
|
1968
2133
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -2003,56 +2168,59 @@ function ActorInspector({
|
|
|
2003
2168
|
<span>Edit blueprint</span>
|
|
2004
2169
|
</button>
|
|
2005
2170
|
) : null}
|
|
2006
|
-
{
|
|
2171
|
+
{onNewBlueprint ? (
|
|
2007
2172
|
<button
|
|
2008
2173
|
type="button"
|
|
2009
2174
|
className={styles.instanceForkButton}
|
|
2010
|
-
onClick={
|
|
2175
|
+
onClick={onNewBlueprint}
|
|
2011
2176
|
title="New blueprint from this actor">
|
|
2012
|
-
<Icon name="
|
|
2013
|
-
|
|
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>
|
|
2014
2181
|
</button>
|
|
2015
2182
|
) : null}
|
|
2016
2183
|
</div>
|
|
2017
2184
|
) : null}
|
|
2018
|
-
{showAddBehavior ? (
|
|
2185
|
+
{showAddBehavior && !readOnly ? (
|
|
2019
2186
|
<AddBehaviorPicker
|
|
2020
2187
|
available={availableBehaviors}
|
|
2021
2188
|
onAdd={(behaviorName) => onAddBehavior(selectedActor.id, behaviorName)}
|
|
2022
2189
|
/>
|
|
2023
2190
|
) : null}
|
|
2024
2191
|
<PanelSortContext names={orderedNames} onReorder={commitOrder}>
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2192
|
+
{orderedEntries.map(([behaviorName, component], index) => (
|
|
2193
|
+
<BehaviorRow
|
|
2194
|
+
key={behaviorName}
|
|
2195
|
+
behaviorName={behaviorName}
|
|
2196
|
+
component={component}
|
|
2197
|
+
ownerKey={ownerKey}
|
|
2198
|
+
selectedActor={selectedActor}
|
|
2199
|
+
rawActor={rawActor}
|
|
2200
|
+
blueprintTemplate={blueprintTemplate}
|
|
2201
|
+
isInstance={isInstance}
|
|
2202
|
+
files={files}
|
|
2203
|
+
sprites={sprites}
|
|
2204
|
+
onSetComponent={onSetComponent}
|
|
2205
|
+
onRemoveBehavior={onRemoveBehavior}
|
|
2206
|
+
onBeginPick={onBeginPick}
|
|
2207
|
+
pickActive={pickActive}
|
|
2208
|
+
onSelectShape={onSelectShape}
|
|
2209
|
+
onCollapseChanged={() => setOrderTick((tick) => tick + 1)}
|
|
2210
|
+
onViewSource={onViewSource}
|
|
2211
|
+
isLast={index === orderedEntries.length - 1 && !showReveal}
|
|
2212
|
+
readOnly={readOnly}
|
|
2213
|
+
/>
|
|
2214
|
+
))}
|
|
2215
|
+
{showReveal ? (
|
|
2216
|
+
<button
|
|
2217
|
+
type="button"
|
|
2218
|
+
className={styles.revealOverridesButton}
|
|
2219
|
+
onClick={() => setShowAllBehaviors(true)}>
|
|
2220
|
+
<Icon name="chevron-down" />
|
|
2221
|
+
<span>Override behavior properties</span>
|
|
2222
|
+
</button>
|
|
2223
|
+
) : null}
|
|
2056
2224
|
</PanelSortContext>
|
|
2057
2225
|
</>
|
|
2058
2226
|
);
|
|
@@ -2077,6 +2245,7 @@ function BehaviorRow({
|
|
|
2077
2245
|
onCollapseChanged,
|
|
2078
2246
|
onViewSource,
|
|
2079
2247
|
isLast,
|
|
2248
|
+
readOnly = false,
|
|
2080
2249
|
}) {
|
|
2081
2250
|
const { isDragging, rowProps, handleProps } = usePanelSortable(behaviorName);
|
|
2082
2251
|
const Behavior = behaviorClasses.find((candidate) => candidate.behaviorName === behaviorName);
|
|
@@ -2147,13 +2316,23 @@ function BehaviorRow({
|
|
|
2147
2316
|
onCollapseChanged();
|
|
2148
2317
|
}}
|
|
2149
2318
|
handleProps={handleProps}
|
|
2150
|
-
onViewSource={
|
|
2151
|
-
|
|
2319
|
+
onViewSource={
|
|
2320
|
+
sourcePath ? { path: sourcePath, open: () => void onViewSource?.(sourcePath) } : null
|
|
2321
|
+
}
|
|
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.
|
|
2152
2327
|
enabled={enabled}
|
|
2153
2328
|
onToggleEnabled={
|
|
2154
|
-
canToggle ? () => setComponent({ $enabled: enabled ? false : true }) : null
|
|
2329
|
+
canToggle && !readOnly ? () => setComponent({ $enabled: enabled ? false : true }) : null
|
|
2155
2330
|
}
|
|
2156
|
-
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}>
|
|
2157
2336
|
{body}
|
|
2158
2337
|
</BehaviorPanel>
|
|
2159
2338
|
</div>
|