#!/usr/bin/env bash
# Rebuilds src/Audio/Warm.php: the voices each scene plays (a run of 30 s of every scene with three seeds), so that a game played live
# makes them in the background while the scene starts instead of in the middle of a bounce.
#   tools/warm-notes.sh            (from the project root: bin/jumphp runs the throw-away test tests/WarmGenTest.php)
set -euo pipefail
cd "$(dirname "$0")/.."
echo 1 > tests/.warmgen
trap 'rm -f tests/.warmgen' EXIT
../../bin/jumphp test satisfying-bounce tests/WarmGenTest.php >/dev/null
python3 - <<'P'
import json
d = json.load(open('var/warm.json'))
lines = []
for cls, notes in d.items():
    rows = ', '.join("['%s', %s, %s, %s]" % (w, repr(float(f)), repr(float(l)), repr(float(v))) for w, f, l, v in notes)
    lines.append("        \\%s::class => [%s]," % (cls.replace('\\\\', '\\'), rows))
src = open('src/Audio/Warm.php').read()
a = src.index('    private const NOTES = [')
b = src.index('];', a) + 2
src = src[:a] + "    private const NOTES = [\n" + "\n".join(lines) + "\n    ];" + src[b:]
open('src/Audio/Warm.php', 'w').write(src)
P
