44 lines
2.2 KiB
JavaScript
44 lines
2.2 KiB
JavaScript
// Compile filename rules independently of geometry. Every step is seekable:
|
|
// visibility describes the entire scene, not a mutation of the previous frame.
|
|
export const numberedPartId = item => `p-${item.group.number}${item.subgroup ? `-${item.subgroup}` : ''}-${item.number}`;
|
|
|
|
export function numberedSchedule(ordered) {
|
|
const numbers = [...new Set(ordered.map(item => item.group.number))];
|
|
const groups = numbers.map(number => ({
|
|
id: `group-${number}`, label: ordered.find(item => item.group.number === number).group.path,
|
|
parts: ordered.filter(item => item.group.number === number).map(numberedPartId),
|
|
}));
|
|
const actions = new Map(), installed = [];
|
|
let groupStart = 0, scopeStart = 0, isolatedStart, previousGroup, previousDirectory;
|
|
let revealing = false;
|
|
for (const item of ordered) {
|
|
const id = numberedPartId(item), groupChanged = previousGroup !== item.group.number;
|
|
if (groupChanged) { groupStart = installed.length; revealing = false; }
|
|
if (previousDirectory !== item.directory) {
|
|
scopeStart = item.subgroup === 'finish' ? groupStart : installed.length;
|
|
isolatedStart = undefined;
|
|
}
|
|
isolatedStart = item.isolated ? isolatedStart ?? installed.length : undefined;
|
|
const reveal = !item.isolated && (item.revealAll || item.group.revealAll);
|
|
const joins = [];
|
|
if (reveal && !revealing) {
|
|
// Keep the current partial assembly as an anchor for an internal #.
|
|
// At an outer # folder boundary the stage starts empty instead.
|
|
const visible = installed.slice(groupStart);
|
|
for (const number of numbers.filter(n => n < item.group.number)) {
|
|
const group = groups.find(g => g.id === `group-${number}`);
|
|
visible.push(...group.parts);
|
|
joins.push({ id: `join-before-${id}-${group.id}`, type: 'join', groupId: group.id,
|
|
label: `${item.group.path} · 合装 ${group.label}`, parts: [...group.parts], visibleParts: [...visible] });
|
|
}
|
|
}
|
|
const start = isolatedStart ?? (reveal ? 0 : scopeStart);
|
|
actions.set(id, { joins, visibleParts: [...installed.slice(start), id] });
|
|
installed.push(id);
|
|
revealing = reveal;
|
|
previousGroup = item.group.number;
|
|
previousDirectory = item.directory;
|
|
}
|
|
return { groups, actions };
|
|
}
|