|
1 | 1 | // Audio the host app supplied survives every pass that rebuilds audio_meta.json from the storyboard: an entry |
2 | 2 | // marked "source": "host" whose file exists. A frame the host scored takes no looked-up cue sound. |
3 | | -const isHost = (entry, path, exists) => |
4 | | - entry?.source === "host" && typeof path === "string" && exists(path); |
5 | | - |
6 | | -/** The host's own entries in an earlier audio_meta.json, and the host-marked paths dropped because their file is |
7 | | - * gone; `exists` resolves a path from the project root. A frame written as "1" is frame 1. */ |
| 3 | +/** The host's own entries in an earlier audio_meta.json, and why any other host-marked entry was dropped; `exists` |
| 4 | + * resolves a path from the project root. A frame written as "1" is frame 1. */ |
8 | 5 | export function hostAudio(previous, exists) { |
9 | | - const marked = [previous?.bgm?.path, ...(previous?.sfx ?? []).map((s) => s.file)]; |
10 | | - const bgm = isHost(previous?.bgm, previous?.bgm?.path, exists) ? previous.bgm : null; |
| 6 | + const marked = [[previous?.bgm, "path"], ...(previous?.sfx ?? []).map((s) => [s, "file"])].filter( |
| 7 | + ([entry]) => entry?.source === "host", |
| 8 | + ); |
| 9 | + const kept = new Set(); |
| 10 | + const dropped = []; |
| 11 | + for (const [entry, key] of marked) { |
| 12 | + const path = entry[key]; |
| 13 | + if (typeof path !== "string") dropped.push(`a host entry has no "${key}"`); |
| 14 | + else if (!exists(path)) dropped.push(`${path} is not on disk`); |
| 15 | + else kept.add(entry); |
| 16 | + } |
| 17 | + const bgm = kept.has(previous?.bgm) ? previous.bgm : null; |
11 | 18 | const sfx = (previous?.sfx ?? []) |
12 | | - .filter((s) => isHost(s, s.file, exists)) |
| 19 | + .filter((s) => kept.has(s)) |
13 | 20 | .map((s) => ({ ...s, frame: Number(s.frame) })); |
14 | | - const hostMarked = [previous?.bgm, ...(previous?.sfx ?? [])].filter((e) => e?.source === "host"); |
15 | | - const dropped = hostMarked.map((e) => e.path ?? e.file).filter((path) => !exists(path)); |
16 | 21 | return { bgm, sfx, frames: new Set(sfx.map((s) => s.frame)), dropped }; |
17 | 22 | } |
18 | 23 |
|
|
0 commit comments