clean up new game
This commit is contained in:
parent
afaf695f2d
commit
87f814b7d8
1 changed files with 73 additions and 80 deletions
|
@ -107,32 +107,25 @@ impl GameHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
let manifest = NewGameManifest {
|
||||
name: new_game.name,
|
||||
host: self
|
||||
// Get host pointer
|
||||
let host = self
|
||||
.state
|
||||
.online_users
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&addr)
|
||||
.unwrap()
|
||||
.clone(),
|
||||
.clone();
|
||||
|
||||
// Create manifest
|
||||
let manifest = NewGameManifest {
|
||||
name: new_game.name,
|
||||
host: host.clone(),
|
||||
packs: new_game.packs,
|
||||
};
|
||||
|
||||
// Create game
|
||||
if let Ok(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 game using manifest
|
||||
let new_game_object = Game::new(self.state.clone(), manifest);
|
||||
|
||||
// Create update for user's game view
|
||||
let meta = GameStateMeta {
|
||||
|
@ -172,6 +165,7 @@ impl GameHandler {
|
|||
};
|
||||
|
||||
// Send user's update
|
||||
let tx = host.read().unwrap().tx.clone();
|
||||
tx.send(serde_json::to_string(&meta).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -194,7 +188,6 @@ impl GameHandler {
|
|||
.send(meta_server_summary_update(&self.state))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Card Set
|
||||
|
@ -288,7 +281,7 @@ pub struct Game {
|
|||
}
|
||||
|
||||
impl Game {
|
||||
fn new(state: Arc<AppState>, request: NewGameManifest) -> Result<Self> {
|
||||
fn new(state: Arc<AppState>, request: NewGameManifest) -> Self {
|
||||
tracing::debug!(
|
||||
"Creating game {} with {} as host",
|
||||
&request.name,
|
||||
|
@ -320,7 +313,7 @@ impl Game {
|
|||
white.shrink_to_fit();
|
||||
black.shrink_to_fit();
|
||||
|
||||
Ok(Game {
|
||||
Game {
|
||||
uuid: Uuid::now_v7(),
|
||||
name: request.name,
|
||||
host: request.host.clone(),
|
||||
|
@ -329,7 +322,7 @@ impl Game {
|
|||
players: HashMap::new(),
|
||||
current_black,
|
||||
packs: request.packs.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw one white card at random from play deck.
|
||||
|
|
Loading…
Add table
Reference in a new issue