import { execFileSync } from 'node:child_process'; import { createHash } from 'node:crypto'; import { existsSync, readFileSync, readdirSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const root = join(dirname(fileURLToPath(import.meta.url)), '..'); const candidateDir = join(root, 'assets', 'audio', 'attack-candidates'); const expected = [ 'physical-swish-01.ogg', 'physical-swish-02.ogg', 'physical-swish-03.ogg', 'physical-swish-04.ogg', 'physical-swish-07.ogg', 'physical-swish-08.ogg', 'physical-swish-09.ogg', 'physical-swish-12.ogg', 'physical-knife-slice-alt.ogg', 'energy-phaser-rise.ogg', 'energy-phase-snap.ogg', 'energy-laser-short.ogg', 'energy-magic-01-short.ogg', 'energy-magic-02-short.ogg', 'energy-magic-03-short.ogg', 'layered-swish-phaser.ogg', 'layered-swish-magic.ogg', 'layered-knife-phase.ogg' ]; const problems = []; const htmlPath = join(candidateDir, 'index.html'); const html = existsSync(htmlPath) ? readFileSync(htmlPath, 'utf8') : ''; const hash = path => createHash('sha256').update(readFileSync(path)).digest('hex'); const baselinePath = join(root, 'assets', 'audio', 'sfx-attack.ogg'); const baselineHash = hash(baselinePath); const durations = []; const selected = 'layered-swish-phaser.ogg'; for (const file of expected) { const path = join(candidateDir, file); if (!existsSync(path)) { problems.push(`missing ${file}`); continue; } if (!html.includes(file)) problems.push(`audition page does not reference ${file}`); if (hash(path) === baselineHash && file !== selected) problems.push(`${file} unexpectedly duplicates the current attack sound`); const duration = Number(execFileSync('ffprobe', [ '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=nw=1:nk=1', path ], { encoding: 'utf8' }).trim()); durations.push([file, duration]); if (!(duration >= 0.05 && duration <= 0.75)) problems.push(`${file} duration ${duration.toFixed(3)}s is outside 0.05-0.75s`); } const actual = readdirSync(candidateDir).filter(name => name.endsWith('.ogg')).sort(); if (actual.length !== expected.length) problems.push(`expected ${expected.length} Ogg files, found ${actual.length}`); for (const required of ['README.md', 'LICENSES.md', 'index.html']) { if (!existsSync(join(candidateDir, required))) problems.push(`missing ${required}`); } if (hash(join(candidateDir, selected)) !== baselineHash) problems.push(`${selected} should match the selected in-game attack sound`); if (problems.length) { console.error(`Attack candidate validation failed:\n- ${problems.join('\n- ')}`); process.exit(1); } console.log(`Validated ${expected.length} attack candidates; ${selected} is the selected in-game sound.`); for (const [file, duration] of durations) console.log(`${file.padEnd(31)} ${duration.toFixed(3)}s`);