Apply/revert buttons for overrides, container instances and child positions

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Opus 5 committed 2026-09-07 17:59:35 +02:00
1 parent 0b78382bcc
commit 3379232e64
7 files changed
+544 -37

No files matched your search

+40 -1
View File
@@ -1,8 +1,47 @@
import { newId } from '../ids';
import type { ContainerAsset } from './Asset';
import type { ContainerAsset, SceneAsset } from './Asset';
import { findObject, type ObjectTree } from './hierarchy';
import { findAsset, type Project } from './Project';
import type { SceneObject } from './SceneObject';
/** What a placed container's content object is linked to: the container and its template object. */
export interface TemplateLink {
containerObject: SceneObject;
asset: ContainerAsset;
template: SceneObject;
}
/**
* For an object that belongs to a placed container: the nearest container ancestor whose
* asset holds the template this object was instantiated from. Undefined for everything else
* (no template id, or the link is stale).
*/
export function templateLinkOf(project: Project, tree: ObjectTree, object: SceneObject): TemplateLink | undefined {
if (!object.templateId) return undefined;
const seen = new Set<string>([object.id]);
let current = object.parentId ? findObject(tree, object.parentId) : undefined;
while (current && !seen.has(current.id)) {
const asset = findAsset(project, current.assetId);
if (asset?.type === 'container') {
const template = asset.objects.find((t) => t.id === object.templateId);
if (template) return { containerObject: current, asset, template };
}
seen.add(current.id);
current = current.parentId ? findObject(tree, current.parentId) : undefined;
}
return undefined;
}
/** Every placed copy of a template object, across all scenes (template ids are unique per project). */
export function instancesOf(project: Project, templateId: string): { scene: SceneAsset; object: SceneObject }[] {
const result: { scene: SceneAsset; object: SceneObject }[] = [];
for (const asset of project.assets) {
if (asset.type !== 'scene') continue;
for (const object of asset.objects) if (object.templateId === templateId) result.push({ scene: asset, object });
}
return result;
}
/** Nesting depth at which a container inside a container inside … stops being expanded. */
const MAX_NESTING = 8;