Live location tracking and playback for the game "manhunt"
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clippy lints

Ben C 91b12004 95d629f1

+40 -52
+5 -9
backend/src/game/mod.rs
··· 216 216 217 217 #[cfg(test)] 218 218 mod tests { 219 - use std::{sync::Arc, u64}; 219 + use std::sync::Arc; 220 220 221 221 use crate::game::{location::Location, settings::PingStartCondition}; 222 222 ··· 238 238 } 239 239 240 240 async fn send_message(&self, msg: GameEvent) { 241 - for (_id, tx) in self.txs.iter().enumerate() { 241 + for tx in self.txs.iter() { 242 242 tx.send(msg.clone()).await.expect("Failed to send msg"); 243 243 } 244 244 } ··· 270 270 impl MockMatch { 271 271 pub fn new(settings: GameSettings, players: u32, seekers: u32) -> Self { 272 272 let uuids = (0..players) 273 - .into_iter() 274 273 .map(|_| uuid::Uuid::new_v4()) 275 274 .collect::<Vec<_>>(); 276 275 277 276 let channels = (0..players) 278 - .into_iter() 279 277 .map(|_| tokio::sync::mpsc::channel(10)) 280 278 .collect::<Vec<_>>(); 281 279 282 280 let initial_caught_state = (0..players) 283 - .into_iter() 284 281 .map(|id| (uuids[id as usize], id < seekers)) 285 282 .collect::<HashMap<_, _>>(); 286 283 let txs = channels ··· 319 316 } 320 317 321 318 pub async fn start(&self) { 322 - for (_id, game) in &self.games { 319 + for game in self.games.values() { 323 320 let game = game.clone(); 324 321 tokio::spawn(async move { 325 322 game.main_loop().await; ··· 333 330 } 334 331 335 332 pub async fn assert_all_states(&self, f: impl Fn(&GameState)) { 336 - for (_, game) in &self.games { 333 + for game in self.games.values() { 337 334 let state = game.state.read().await; 338 335 f(&state); 339 336 } ··· 356 353 } 357 354 358 355 async fn tick_all(&self, now: UtcDT) { 359 - for (_, game) in &self.games { 356 + for game in self.games.values() { 360 357 game.force_tick(now).await; 361 358 } 362 359 } ··· 478 475 settings.powerup_minutes_cooldown = 1; 479 476 settings.powerup_start = PingStartCondition::Instant; 480 477 settings.powerup_locations = (1..1000) 481 - .into_iter() 482 478 .map(|x| Location { 483 479 lat: x as f64, 484 480 long: 1.0,
+1 -2
backend/src/game/state.rs
··· 280 280 281 281 /// Create a [PlayerPing] with the latest location as another player 282 282 pub fn create_ping(&self, id: Id) -> Option<PlayerPing> { 283 - self.get_loc() 284 - .map(|loc| PlayerPing::new(loc.clone(), id, self.id)) 283 + self.get_loc().map(|loc| PlayerPing::new(*loc, id, self.id)) 285 284 } 286 285 287 286 /// Player has gotten a powerup, rolls to see which powerup and stores it
+34 -41
backend/src/lib.rs
··· 31 31 fn generate_join_code() -> String { 32 32 // 5 character sequence of A-Z 33 33 (0..5) 34 - .into_iter() 35 - .map(|_| (('A' as u8) + rand::random_range(0..26)) as char) 34 + .map(|_| (b'A' + rand::random_range(0..26)) as char) 36 35 .collect::<String>() 37 36 } 38 37 ··· 48 47 49 48 impl AppState { 50 49 pub fn start_game(&mut self, app: AppHandle, my_id: Uuid, start: StartGameInfo) { 51 - match self { 52 - AppState::Lobby(lobby) => { 53 - let transport = lobby.clone_transport(); 54 - let location = TauriLocation::new(app.clone()); 55 - let game = Arc::new(Game::new( 56 - my_id, 57 - GAME_TICK_RATE, 58 - start.initial_caught_state, 59 - start.settings, 60 - transport, 61 - location, 62 - )); 63 - *self = AppState::Game(game.clone()); 64 - tokio::spawn(async move { 65 - game.main_loop().await; 66 - }); 67 - } 68 - _ => {} 50 + if let AppState::Lobby(lobby) = self { 51 + let transport = lobby.clone_transport(); 52 + let location = TauriLocation::new(app.clone()); 53 + let game = Arc::new(Game::new( 54 + my_id, 55 + GAME_TICK_RATE, 56 + start.initial_caught_state, 57 + start.settings, 58 + transport, 59 + location, 60 + )); 61 + *self = AppState::Game(game.clone()); 62 + tokio::spawn(async move { 63 + game.main_loop().await; 64 + }); 69 65 } 70 66 } 71 67 ··· 75 71 app: AppHandle, 76 72 settings: GameSettings, 77 73 ) { 78 - match self { 79 - AppState::Menu(profile) => { 80 - let host = join_code.is_none(); 81 - let room_code = join_code.unwrap_or_else(generate_join_code); 82 - let lobby = Arc::new(Lobby::new( 83 - server_url(), 84 - &room_code, 85 - host, 86 - profile.clone(), 87 - settings, 88 - )); 89 - *self = AppState::Lobby(lobby.clone()); 90 - tokio::spawn(async move { 91 - let (my_id, start) = lobby.open().await; 92 - let app_game = app.clone(); 93 - let state_handle = app.state::<AppStateHandle>(); 94 - let mut state = state_handle.write().await; 95 - state.start_game(app_game, my_id, start); 96 - }); 97 - } 98 - _ => {} 74 + if let AppState::Menu(profile) = self { 75 + let host = join_code.is_none(); 76 + let room_code = join_code.unwrap_or_else(generate_join_code); 77 + let lobby = Arc::new(Lobby::new( 78 + server_url(), 79 + &room_code, 80 + host, 81 + profile.clone(), 82 + settings, 83 + )); 84 + *self = AppState::Lobby(lobby.clone()); 85 + tokio::spawn(async move { 86 + let (my_id, start) = lobby.open().await; 87 + let app_game = app.clone(); 88 + let state_handle = app.state::<AppStateHandle>(); 89 + let mut state = state_handle.write().await; 90 + state.start_game(app_game, my_id, start); 91 + }); 99 92 } 100 93 } 101 94 }