From 2f2beb79720ec9fd35b993e7ad907ecf32005cde Mon Sep 17 00:00:00 2001 From: Martin Hafskjold Thoresen Date: Fri, 10 Jan 2025 18:56:37 +0100 Subject: Permute sounds instead of randomly choosing Also add more sounds --- src/main.rs | 31 +++++++++++++++++++++++++++---- static/bike.mp3 | Bin 0 -> 33436 bytes static/cough.mp3 | Bin 0 -> 35108 bytes static/o.mp3 | Bin 0 -> 13440 bytes static/pop.mp3 | Bin 0 -> 12480 bytes static/wow.mp3 | Bin 0 -> 10080 bytes 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 static/bike.mp3 create mode 100644 static/cough.mp3 create mode 100644 static/o.mp3 create mode 100644 static/pop.mp3 create mode 100644 static/wow.mp3 diff --git a/src/main.rs b/src/main.rs index caf01c4..a6963c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,6 +87,7 @@ struct Game { next_rounds: Vec, /// Data for each round rounds: Vec, + user_to_sound: HashMap, /// Sender to broadcast things broadcast_tx: Sender, @@ -140,6 +141,26 @@ impl Game { info!("All users have submitted"); let users = self.submissions.keys().cloned(); self.next_rounds = users.collect(); + + let mut rng = rand::thread_rng(); + let sound_fx = [ + "cough.mp3", + "wow.mp3", + "cat.mp3", + "pop.mp3", + "car.mp3", + "bike.mp3", + "dog.mp3", + "o.mp3", + ] + .choose_multiple(&mut rng, self.next_rounds.len()); + self.user_to_sound = self + .next_rounds + .iter() + .zip(sound_fx) + .map(|(u, s)| (*u, s.to_string())) + .collect(); + self.new_round(); } else { self.message_screen(uid, self.screen_submitted()) @@ -154,10 +175,11 @@ impl Game { return; }; - let mut rng = rand::thread_rng(); - let sound_fx = ["dog.mp3", "cat.mp3", "car.mp3"] - .choose(&mut rng) - .expect("not empty"); + let sound_fx = self + .user_to_sound + .get(&uid) + .cloned() + .unwrap_or_else(|| format!("cough.mp3")); self.rounds.push(Round { author: uid, @@ -424,6 +446,7 @@ impl ServerState { active_users: HashSet::new(), submissions: HashMap::new(), next_rounds: Vec::new(), + user_to_sound: HashMap::new(), rounds: Vec::new(), broadcast_rx: rx, broadcast_tx: tx, diff --git a/static/bike.mp3 b/static/bike.mp3 new file mode 100644 index 0000000..666e194 Binary files /dev/null and b/static/bike.mp3 differ diff --git a/static/cough.mp3 b/static/cough.mp3 new file mode 100644 index 0000000..a499ad3 Binary files /dev/null and b/static/cough.mp3 differ diff --git a/static/o.mp3 b/static/o.mp3 new file mode 100644 index 0000000..58fd01e Binary files /dev/null and b/static/o.mp3 differ diff --git a/static/pop.mp3 b/static/pop.mp3 new file mode 100644 index 0000000..fff12a8 Binary files /dev/null and b/static/pop.mp3 differ diff --git a/static/wow.mp3 b/static/wow.mp3 new file mode 100644 index 0000000..f3e53dc Binary files /dev/null and b/static/wow.mp3 differ -- cgit v1.2.3