feat(client_web): use a mp3 file for dice roll sound
This commit is contained in:
parent
43196bcef8
commit
9af672823e
5 changed files with 14 additions and 2 deletions
|
|
@ -34,4 +34,5 @@ web-sys = { version = "0.3", features = [
|
||||||
"OscillatorNode",
|
"OscillatorNode",
|
||||||
"OscillatorType",
|
"OscillatorType",
|
||||||
"BaseAudioContext",
|
"BaseAudioContext",
|
||||||
|
"HtmlAudioElement",
|
||||||
] }
|
] }
|
||||||
|
|
|
||||||
BIN
client_web/assets/diceroll.mp3
Normal file
BIN
client_web/assets/diceroll.mp3
Normal file
Binary file not shown.
|
|
@ -6,6 +6,7 @@
|
||||||
<title>Trictrac</title>
|
<title>Trictrac</title>
|
||||||
<link data-trunk rel="rust" />
|
<link data-trunk rel="rust" />
|
||||||
<link data-trunk rel="css" href="assets/style.css" />
|
<link data-trunk rel="css" href="assets/style.css" />
|
||||||
|
<link data-trunk rel="copy-file" href="assets/diceroll.mp3" />
|
||||||
</head>
|
</head>
|
||||||
<body></body>
|
<body></body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ pub fn GameScreen(state: GameUiState) -> impl IntoView {
|
||||||
// ── Sound effects (fire once on mount = once per state snapshot) ──────────
|
// ── Sound effects (fire once on mount = once per state snapshot) ──────────
|
||||||
// Dice roll: dice just appeared (no preceding moves in this snapshot).
|
// Dice roll: dice just appeared (no preceding moves in this snapshot).
|
||||||
if show_dice && last_moves.is_none() {
|
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.
|
// Checker move: moves were committed in the preceding action.
|
||||||
if last_moves.is_some() {
|
if last_moves.is_some() {
|
||||||
|
|
|
||||||
|
|
@ -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).
|
/// Ascending three-note chime (C5 – E5 – G5).
|
||||||
pub fn play_points_scored() {
|
pub fn play_points_scored() {
|
||||||
with_ctx(|ctx| {
|
with_ctx(|ctx| {
|
||||||
|
|
@ -158,12 +165,15 @@ mod inner {
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub use inner::{
|
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"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn play_checker_move() {}
|
pub fn play_checker_move() {}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub fn play_dice_roll() {}
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn play_dice_roll_cinematic() {}
|
pub fn play_dice_roll_cinematic() {}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn play_points_scored() {}
|
pub fn play_points_scored() {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue