clean up new game

This commit is contained in:
Adam 2024-08-15 00:14:47 -04:00
parent afaf695f2d
commit 87f814b7d8

View file

@ -107,32 +107,25 @@ impl GameHandler {
return; return;
} }
let manifest = NewGameManifest { // Get host pointer
name: new_game.name, let host = self
host: self
.state .state
.online_users .online_users
.read() .read()
.unwrap() .unwrap()
.get(&addr) .get(&addr)
.unwrap() .unwrap()
.clone(), .clone();
// Create manifest
let manifest = NewGameManifest {
name: new_game.name,
host: host.clone(),
packs: new_game.packs, packs: new_game.packs,
}; };
// Create game // Create game using manifest
if let Ok(new_game_object) = Game::new(self.state.clone(), manifest) { let new_game_object = Game::new(self.state.clone(), manifest);
let tx = self
.state
.online_users
.read()
.unwrap()
.get(&addr)
.unwrap()
.read()
.unwrap()
.tx
.clone();
// Create update for user's game view // Create update for user's game view
let meta = GameStateMeta { let meta = GameStateMeta {
@ -172,6 +165,7 @@ impl GameHandler {
}; };
// Send user's update // Send user's update
let tx = host.read().unwrap().tx.clone();
tx.send(serde_json::to_string(&meta).unwrap()) tx.send(serde_json::to_string(&meta).unwrap())
.await .await
.unwrap(); .unwrap();
@ -195,7 +189,6 @@ impl GameHandler {
.unwrap(); .unwrap();
} }
} }
}
/// Card Set /// Card Set
#[derive(Debug)] #[derive(Debug)]
@ -288,7 +281,7 @@ pub struct Game {
} }
impl Game { impl Game {
fn new(state: Arc<AppState>, request: NewGameManifest) -> Result<Self> { fn new(state: Arc<AppState>, request: NewGameManifest) -> Self {
tracing::debug!( tracing::debug!(
"Creating game {} with {} as host", "Creating game {} with {} as host",
&request.name, &request.name,
@ -320,7 +313,7 @@ impl Game {
white.shrink_to_fit(); white.shrink_to_fit();
black.shrink_to_fit(); black.shrink_to_fit();
Ok(Game { Game {
uuid: Uuid::now_v7(), uuid: Uuid::now_v7(),
name: request.name, name: request.name,
host: request.host.clone(), host: request.host.clone(),
@ -329,7 +322,7 @@ impl Game {
players: HashMap::new(), players: HashMap::new(),
current_black, current_black,
packs: request.packs.clone(), packs: request.packs.clone(),
}) }
} }
/// Draw one white card at random from play deck. /// Draw one white card at random from play deck.