diff options
| author | Martin Hafskjold Thoresen <martin@vind.ai> | 2025-01-10 18:56:37 +0100 |
|---|---|---|
| committer | Martin Hafskjold Thoresen <martin@vind.ai> | 2025-01-10 18:56:37 +0100 |
| commit | 2f2beb79720ec9fd35b993e7ad907ecf32005cde (patch) | |
| tree | dad61d7971fdf5492631402374581c47df4763e5 /src | |
| parent | 4b090965a2c76af9c997853c8cc16c643befdceb (diff) | |
| download | musicgame-2f2beb79720ec9fd35b993e7ad907ecf32005cde.tar.gz musicgame-2f2beb79720ec9fd35b993e7ad907ecf32005cde.zip | |
Permute sounds instead of randomly choosing
Also add more sounds
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 31 |
1 files changed, 27 insertions, 4 deletions
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<UserId>, /// Data for each round rounds: Vec<Round>, + user_to_sound: HashMap<UserId, String>, /// Sender to broadcast things broadcast_tx: Sender<String>, @@ -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, |
