Files
ActionBlock/actionBlocks_website/src/config/sound.ts
T
marvin 1996b9c83e Add sound effects, background music and a sound menu
Generate retro sound effects and music in the browser with the Web Audio
API, so no audio files are needed. Any sound can still be replaced by a
file.

Audio (src/audio/):
- 16 effects (move, rotate, hold, hard drop, lock, line clears, garbage,
  items, countdown, knockout, win/lose), triggered by comparing match
  snapshots, so the server is unchanged
- Background music as a shuffled playlist of any number of tracks,
  either synth songs or audio files; 3 original songs included, tempo
  rises with the level
- SoundPlayer interface, so the audio engine can be replaced
- Audio files and music tracks are registered in theme/assets.ts
  (soundFiles, musicTracks)
- All volume levels for developers are in config/sound.ts (master, sfx,
  music, per effect, per track, default slider positions)

UI:
- Speaker button fixed in the top right corner of every screen; opens an
  inline strip with a mute button and volume slider for SFX and music
  that doesn't cover the boards or pause the game
- Leave button below it in the lobby and the game; in a running match
  it asks for a second click because leaving gives up the match
- Lobby Music panel to switch single tracks on or off
- Keys: M all sound on/off, B music on/off, N next track
- Settings are saved in localStorage

Docs: audio section in frontend.md, sound and music guide in
extending.md, new keys in game-rules.md and the README.
2026-10-24 04:08:09 +02:00

45 lines
1.2 KiB
TypeScript

import type { SoundId } from '../audio/types';
/**
* Central mix for developers. Every value multiplies the level a sound was designed with:
* 1 = as designed, 0 = silent, above 1 = louder (up to about 2 is sensible).
* The players' volume sliders apply on top of this.
*/
export const soundMix = {
/** Applied to everything. */
master: 1,
/** All sound effects. */
sfx: 1,
/** All background music. */
music: 0.1,
/** Per sound effect. Every SoundId must be listed, so new effects can't be forgotten. */
effects: {
move: 1,
rotate: 1,
hold: 1,
hardDrop: 1,
lock: 1,
lineClear: 1,
quad: 1,
garbageIncoming: 1,
itemPickup: 1,
itemUse: 1,
itemHit: 1,
countdown: 1,
go: 1,
knockout: 1,
lose: 1,
win: 1,
} satisfies Record<SoundId, number>,
/** Per music track, by its id in `musicTracks` (theme/assets.ts). Tracks not listed use 1. */
tracks: {
pixel_rush: 1,
neon_stack: 1,
last_line: 1,
} as Partial<Record<string, number>>,
};
/** Initial slider positions (0..1) for players without saved settings. */
export const defaultSfxVolume = 0.6;
export const defaultMusicVolume = 0.35;