A scene now stores only the container object; its content is resolved from the template on every read, with deviations kept as sparse instanceEdits on the container object. This drops the propagation bookkeeping entirely -- templateSync.ts is gone and the three structural gaps (add, remove, reparent) cannot diverge any more. Values stay editable on an instance, structure does not; Unpack writes the content into the scene, keeping ids. Play mode bakes containers into the throwaway copy before entities are built. No migration: formatVersion is 2 and the seeders write the new format. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
24 lines
864 B
TypeScript
24 lines
864 B
TypeScript
import type { ContainerAsset } from './Asset';
|
|
import { findAsset, type Project } from './Project';
|
|
|
|
/**
|
|
* 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 forever the moment one of them
|
|
* is resolved.
|
|
*/
|
|
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;
|
|
}
|