diff --git a/client_web/Cargo.toml b/client_web/Cargo.toml index e911eaf..10d91b8 100644 --- a/client_web/Cargo.toml +++ b/client_web/Cargo.toml @@ -34,4 +34,5 @@ web-sys = { version = "0.3", features = [ "OscillatorNode", "OscillatorType", "BaseAudioContext", + "HtmlAudioElement", ] } diff --git a/client_web/assets/diceroll.mp3 b/client_web/assets/diceroll.mp3 new file mode 100644 index 0000000..b16adff Binary files /dev/null and b/client_web/assets/diceroll.mp3 differ diff --git a/client_web/index.html b/client_web/index.html index b661d76..7399dbc 100644 --- a/client_web/index.html +++ b/client_web/index.html @@ -6,6 +6,7 @@ Trictrac + diff --git a/client_web/src/components/game_screen.rs b/client_web/src/components/game_screen.rs index 24042be..4be98b8 100644 --- a/client_web/src/components/game_screen.rs +++ b/client_web/src/components/game_screen.rs @@ -179,7 +179,7 @@ pub fn GameScreen(state: GameUiState) -> impl IntoView { // ── Sound effects (fire once on mount = once per state snapshot) ────────── // Dice roll: dice just appeared (no preceding moves in this snapshot). if show_dice && last_moves.is_none() { - crate::sound::play_dice_roll_cinematic(); + crate::sound::play_dice_roll(); } // Checker move: moves were committed in the preceding action. if last_moves.is_some() { diff --git a/client_web/src/sound.rs b/client_web/src/sound.rs index 4e2c815..2de584a 100644 --- a/client_web/src/sound.rs +++ b/client_web/src/sound.rs @@ -128,6 +128,13 @@ mod inner { }); } + /// Play the pre-recorded dice-roll MP3 asset. + pub fn play_dice_roll() { + if let Ok(audio) = web_sys::HtmlAudioElement::new_with_src("/diceroll.mp3") { + let _ = audio.play(); + } + } + /// Ascending three-note chime (C5 – E5 – G5). pub fn play_points_scored() { with_ctx(|ctx| { @@ -158,12 +165,15 @@ mod inner { #[cfg(target_arch = "wasm32")] pub use inner::{ - play_checker_move, play_dice_roll_cinematic, play_hole_scored, play_points_scored, + play_checker_move, play_dice_roll, play_dice_roll_cinematic, play_hole_scored, + play_points_scored, }; #[cfg(not(target_arch = "wasm32"))] pub fn play_checker_move() {} #[cfg(not(target_arch = "wasm32"))] +pub fn play_dice_roll() {} +#[cfg(not(target_arch = "wasm32"))] pub fn play_dice_roll_cinematic() {} #[cfg(not(target_arch = "wasm32"))] pub fn play_points_scored() {}