Add a Container tab and propagate template edits
The Container tab reuses SceneViewport against any object holder, so a container template is edited exactly like a scene. Right-click no longer changes the selection, which previously made nesting impossible: opening the menu on a container loaded it, and "Place in container" then targeted itself. Template edits (move, rename, override) now reach already-placed instances per slot, through a shared templateSync used by both the apply path and the plain object commands. Copies the user has touched keep their own value. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6bedc948be
commit
9d93020bd8
35 files changed
+1452
-363
No files matched your search
@@ -37,8 +37,26 @@ export function listScenes(project: Project): SceneAsset[] {
|
||||
*/
|
||||
export type ObjectHolder = SceneAsset | ContainerAsset;
|
||||
|
||||
export function isObjectHolder(asset: Asset): asset is ObjectHolder {
|
||||
return asset.type === 'scene' || asset.type === 'container';
|
||||
}
|
||||
|
||||
export function objectHolders(project: Project): ObjectHolder[] {
|
||||
return project.assets.filter((a): a is ObjectHolder => a.type === 'scene' || a.type === 'container');
|
||||
return project.assets.filter(isObjectHolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* The scene or container asset an object belongs to. Editing a container's template is the same
|
||||
* work as editing a scene, so the object commands resolve their target through this rather than
|
||||
* through `findScene`.
|
||||
*/
|
||||
export function findObjectHolder(project: Project, holderId: string): ObjectHolder | undefined {
|
||||
const asset = findAsset(project, holderId);
|
||||
return asset && isObjectHolder(asset) ? asset : undefined;
|
||||
}
|
||||
|
||||
export function listContainers(project: Project): ContainerAsset[] {
|
||||
return project.assets.filter((a): a is ContainerAsset => a.type === 'container');
|
||||
}
|
||||
|
||||
export interface SceneObjectRef {
|
||||
|
||||
@@ -37,6 +37,27 @@ export function instancesOf(project: Project, templateId: string): SceneObjectRe
|
||||
return objectsWhere(project, (o) => o.templateId === templateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether `wantedId` is that container or sits somewhere in its content. Editing a container's
|
||||
* template can place containers into it, and a cycle would expand into thousands of objects the
|
||||
* moment one of them is placed.
|
||||
*/
|
||||
export function containerReaches(project: Project, asset: ContainerAsset, wantedId: string): boolean {
|
||||
if (asset.id === wantedId) return true;
|
||||
const seen = new Set([asset.id]);
|
||||
const queue = [asset];
|
||||
for (const current of queue) {
|
||||
for (const template of current.objects) {
|
||||
const nested = findAsset(project, template.assetId);
|
||||
if (nested?.type !== 'container' || seen.has(nested.id)) continue;
|
||||
if (nested.id === wantedId) return true;
|
||||
seen.add(nested.id);
|
||||
queue.push(nested);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const MAX_NESTING = 8;
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user