diff --git a/backend/src/game/mod.rs b/backend/src/game/mod.rs index 1ded9cf..84206b8 100644 --- a/backend/src/game/mod.rs +++ b/backend/src/game/mod.rs @@ -216,7 +216,7 @@ impl Game { #[cfg(test)] mod tests { - use std::{sync::Arc, u64}; + use std::sync::Arc; use crate::game::{location::Location, settings::PingStartCondition}; @@ -238,7 +238,7 @@ mod tests { } async fn send_message(&self, msg: GameEvent) { - for (_id, tx) in self.txs.iter().enumerate() { + for tx in self.txs.iter() { tx.send(msg.clone()).await.expect("Failed to send msg"); } } @@ -270,17 +270,14 @@ mod tests { impl MockMatch { pub fn new(settings: GameSettings, players: u32, seekers: u32) -> Self { let uuids = (0..players) - .into_iter() .map(|_| uuid::Uuid::new_v4()) .collect::>(); let channels = (0..players) - .into_iter() .map(|_| tokio::sync::mpsc::channel(10)) .collect::>(); let initial_caught_state = (0..players) - .into_iter() .map(|id| (uuids[id as usize], id < seekers)) .collect::>(); let txs = channels @@ -319,7 +316,7 @@ mod tests { } pub async fn start(&self) { - for (_id, game) in &self.games { + for game in self.games.values() { let game = game.clone(); tokio::spawn(async move { game.main_loop().await; @@ -333,7 +330,7 @@ mod tests { } pub async fn assert_all_states(&self, f: impl Fn(&GameState)) { - for (_, game) in &self.games { + for game in self.games.values() { let state = game.state.read().await; f(&state); } @@ -356,7 +353,7 @@ mod tests { } async fn tick_all(&self, now: UtcDT) { - for (_, game) in &self.games { + for game in self.games.values() { game.force_tick(now).await; } } @@ -478,7 +475,6 @@ mod tests { settings.powerup_minutes_cooldown = 1; settings.powerup_start = PingStartCondition::Instant; settings.powerup_locations = (1..1000) - .into_iter() .map(|x| Location { lat: x as f64, long: 1.0, diff --git a/backend/src/game/state.rs b/backend/src/game/state.rs index 490df6f..07f8649 100644 --- a/backend/src/game/state.rs +++ b/backend/src/game/state.rs @@ -280,8 +280,7 @@ impl GameState { /// Create a [PlayerPing] with the latest location as another player pub fn create_ping(&self, id: Id) -> Option { - self.get_loc() - .map(|loc| PlayerPing::new(loc.clone(), id, self.id)) + self.get_loc().map(|loc| PlayerPing::new(*loc, id, self.id)) } /// Player has gotten a powerup, rolls to see which powerup and stores it diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 87d01d4..a82ff62 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -31,8 +31,7 @@ type AppStateHandle = RwLock; fn generate_join_code() -> String { // 5 character sequence of A-Z (0..5) - .into_iter() - .map(|_| (('A' as u8) + rand::random_range(0..26)) as char) + .map(|_| (b'A' + rand::random_range(0..26)) as char) .collect::() } @@ -48,24 +47,21 @@ const fn server_url() -> &'static str { impl AppState { pub fn start_game(&mut self, app: AppHandle, my_id: Uuid, start: StartGameInfo) { - match self { - AppState::Lobby(lobby) => { - let transport = lobby.clone_transport(); - let location = TauriLocation::new(app.clone()); - let game = Arc::new(Game::new( - my_id, - GAME_TICK_RATE, - start.initial_caught_state, - start.settings, - transport, - location, - )); - *self = AppState::Game(game.clone()); - tokio::spawn(async move { - game.main_loop().await; - }); - } - _ => {} + if let AppState::Lobby(lobby) = self { + let transport = lobby.clone_transport(); + let location = TauriLocation::new(app.clone()); + let game = Arc::new(Game::new( + my_id, + GAME_TICK_RATE, + start.initial_caught_state, + start.settings, + transport, + location, + )); + *self = AppState::Game(game.clone()); + tokio::spawn(async move { + game.main_loop().await; + }); } } @@ -75,27 +71,24 @@ impl AppState { app: AppHandle, settings: GameSettings, ) { - match self { - AppState::Menu(profile) => { - let host = join_code.is_none(); - let room_code = join_code.unwrap_or_else(generate_join_code); - let lobby = Arc::new(Lobby::new( - server_url(), - &room_code, - host, - profile.clone(), - settings, - )); - *self = AppState::Lobby(lobby.clone()); - tokio::spawn(async move { - let (my_id, start) = lobby.open().await; - let app_game = app.clone(); - let state_handle = app.state::(); - let mut state = state_handle.write().await; - state.start_game(app_game, my_id, start); - }); - } - _ => {} + if let AppState::Menu(profile) = self { + let host = join_code.is_none(); + let room_code = join_code.unwrap_or_else(generate_join_code); + let lobby = Arc::new(Lobby::new( + server_url(), + &room_code, + host, + profile.clone(), + settings, + )); + *self = AppState::Lobby(lobby.clone()); + tokio::spawn(async move { + let (my_id, start) = lobby.open().await; + let app_game = app.clone(); + let state_handle = app.state::(); + let mut state = state_handle.write().await; + state.start_game(app_game, my_id, start); + }); } } }