Files
feuerwerk/src/viewport/drawOrder.ts
T

31 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}