feat(client_web): use a mp3 file for dice roll sound

This commit is contained in:
Henri Bourcereau 2026-04-17 20:04:40 +02:00
parent 43196bcef8
commit 9af672823e
5 changed files with 14 additions and 2 deletions

View file

@ -34,4 +34,5 @@ web-sys = { version = "0.3", features = [
"OscillatorNode",
"OscillatorType",
"BaseAudioContext",
"HtmlAudioElement",
] }

Binary file not shown.

View file

@ -6,6 +6,7 @@
<title>Trictrac</title>
<link data-trunk rel="rust" />
<link data-trunk rel="css" href="assets/style.css" />
<link data-trunk rel="copy-file" href="assets/diceroll.mp3" />
</head>
<body></body>
</html>

View file

@ -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() {

View file

@ -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() {}