import type { Asset } from './Asset'; import { ASSET_TYPE_LABELS, isPlaceableType } from './AssetTypes'; import { containerReaches } from './container'; import type { ObjectHolder, Project } from './Project'; /** * Why `asset` cannot be placed into `holder`, or '' when it can. A drag needs the answer while * it hovers, `PlaceAssetCommand` needs it at the drop; both ask here so the preview cannot * promise a placement the command then refuses. */ export function placementRejection(project: Project, holder: ObjectHolder, asset: Asset): string { // A pattern or a sound is dragged out of the panel for a song (#334), and may pass over a scene. if (!isPlaceableType(asset.type)) return `A ${ASSET_TYPE_LABELS[asset.type].toLowerCase()} cannot be placed into a scene`; if (asset.type === 'container' && containerReaches(project, asset, holder.id)) return `${asset.name} cannot contain ${holder.name}: that nests forever`; if (asset.type === 'composition' && holder.type === 'composition') return 'A composition cannot be placed into a composition'; return ''; }