import { isSymbolType } from '../core/model/AssetTypes'; import { sortByZ } from '../core/model/Properties'; import type { DrawItem } from './items'; /** * One thing sorted into the draw order: an object, or one layer of a placed tilemap (#174) – * `layerId` is empty for the object itself. A layer is sorted on its own, so a figure can walk * between the ground and the treetops of one map. */ export interface DrawSlot { id: string; layerId: string; z: number; } /** * Back to front: ascending `z`, ties in hierarchy order, and a map's layers right after the map in * their list order. With every layer at 0 that is exactly the order of before, where a map was one * piece. Symbols are left out, they are drawn above everything. */ export function drawSlots(items: readonly DrawItem[]): DrawSlot[] { const slots: DrawSlot[] = []; for (const item of items) { if (isSymbolType(item.type)) continue; slots.push({ id: item.id, layerId: '', z: item.z }); for (const layer of item.tilemap?.layers ?? []) slots.push({ id: item.id, layerId: layer.id, z: item.z + layer.z }); } return sortByZ(slots); }