Skip to content

feat(audio): battle music layer with 5s linger#355

Merged
mokn merged 5 commits intodevfrom
feat/audio-zones
Apr 13, 2026
Merged

feat(audio): battle music layer with 5s linger#355
mokn merged 5 commits intodevfrom
feat/audio-zones

Conversation

@mokn
Copy link
Copy Markdown
Collaborator

@mokn mokn commented Apr 13, 2026

Summary

Per-zone battle music (battle-dark-cave-mix, battle-windy-peaks-mix) with a state machine that punches in fast on combat start (600ms) and exhales out slow after combat (3000ms). A 5s linger timer keeps battle music playing across back-to-back fights during grinding so the mood doesn't whiplash on every encounter gap.

  • Battle track selection keys off (currentZone, currentBattle) tuple
  • Zone change mid-battle switches to new zone's battle track
  • Unknown zones fall back to zone 1's track with a one-time warn
  • Fixes pre-existing autoplay bug: Howler.ctx.resume() on first pointer/key/touch gesture after auto-enable, so ambient actually plays without requiring the player to click the sound toggle
  • Reorder App.tsx providers (BattleProvider now wraps SoundProvider) so SoundContext can read combat state
  • Initialize battleMode from currentBattle to avoid a one-tick flash of ambient when loading mid-combat

Test plan

  • pnpm --filter client test -- SoundContext — 21/21 passing
  • pnpm --filter client build — clean
  • Beta smoke: load Dark Cave, confirm ambient plays after first click
  • Beta smoke: start a fight, confirm fast crossfade to battle track
  • Beta smoke: kill monster, immediately engage another within 5s — no music change
  • Beta smoke: kill monster, wait 6s — confirm slow fade back to ambient
  • Beta smoke: mute mid-battle, unmute — battle track resumes
  • Beta smoke: move Dark Cave → Windy Peaks mid-fight — track swaps to windy-peaks-battle

🤖 Generated with Claude Code

mokn and others added 4 commits April 13, 2026 08:10
Replace single cave-melody.ogg with per-zone MIX tracks (Dark Cave, Windy
Peaks). SoundContext now reads currentZone from MapContext and crossfades
between zone audio on transition. Moved SoundProvider inside MapProvider
to access zone state.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Adds per-zone battle music (battle-dark-cave-mix, battle-windy-peaks-mix)
with a state machine that punches in fast on combat start (600ms) and
exhales out slow after combat (3000ms). A 5s linger timer keeps battle
music playing across back-to-back fights during grinding, so the mood
doesn't whiplash on every encounter gap.

- Battle track selection keys off (currentZone, currentBattle) tuple
- Zone change mid-battle switches to new zone's battle track
- Fixes pre-existing autoplay bug: Howler.ctx.resume() on first pointer/
  key/touch gesture after auto-enable, so ambient actually plays without
  requiring the player to click the sound toggle
- Reorder App.tsx providers (BattleProvider now wraps SoundProvider) so
  SoundContext can read combat state

19 vitest cases cover: toggle/persistence, zone ambient, battle entry,
zone-2 battle track, zone change during combat, linger cancel-on-reentry,
linger-fires-after-timeout, mute mid-battle, autoplay unlock.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Two fixes from deep review:

1. battleMode was initialized to false even when currentBattle was
   already non-null on mount, causing a one-tick flash of ambient music
   when loading a page mid-combat. Initialize from currentBattle so
   the first playback effect run picks the correct track.

2. Unknown zones (e.g. when zone 3 ships before its music does) now
   fall back to zone 1's track with a one-time console.warn per
   (mode, zone) pair, instead of going silently off.

Adds two tests: battle track resumes on mute/unmute mid-combat, and
zone-99 combat falls back to the dark-cave battle track.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blog Ready Ready Preview, Comment Apr 13, 2026 9:20pm
ud Error Error Apr 13, 2026 9:20pm
ud-api Ready Ready Preview, Comment Apr 13, 2026 9:20pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ud-api-beta Ignored Ignored Preview Apr 13, 2026 9:20pm

Request Review

# Conflicts:
#	packages/client/src/App.tsx
#	packages/client/src/contexts/SoundContext.test.tsx
#	packages/client/src/contexts/SoundContext.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant