diff --git a/server/WORKLOG.md b/server/WORKLOG.md index c3d137ed..3e3effc5 100755 --- a/server/WORKLOG.md +++ b/server/WORKLOG.md @@ -1,6 +1,13 @@ +# Principles +* Experience something +* Express something +* Prove something + +# WORK WORK * QOL * auto login * ws reconnect ✔ + * Levelling ✔ * Global rolls @@ -18,7 +25,11 @@ * Scrabble grid * skills - * offensive -> choose target + * offensive -> choose target ✔ + * check for cryp ability ownership + * check for game participation + * write players row for every team+cryp added + * defensive * Items @@ -34,10 +45,9 @@ * Cryp Generation * -# Principles -* Experience something -* Express something -* Prove something +# Db maintenance +* delete games when a cryp is deleted + * does this need to happen? can have historical games # Mechanic Ideas teams diff --git a/server/src/game.rs b/server/src/game.rs index 30c2f500..f14c54f0 100755 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -329,11 +329,6 @@ impl Game { } } - -// add client function call -// check for cryp ability ownership -// check for game participation - pub fn game_ability(params: GameAbilityParams, tx: &mut Transaction, account: &Account) -> Result { let query = " SELECT * @@ -358,7 +353,7 @@ pub fn game_ability(params: GameAbilityParams, tx: &mut Transaction, account: &A return game_write(game, tx); } -pub fn game_new(game: Game, tx: &mut Transaction) -> Result { +pub fn game_new(game: &Game, tx: &mut Transaction) -> Result<(), Error> { let game_bytes = to_vec(&game)?; let query = " @@ -374,35 +369,32 @@ pub fn game_new(game: Game, tx: &mut Transaction) -> Result { println!("{:?} wrote game", game.id); - return Ok(game); + return Ok(()); } -pub fn players_write(game: Game, tx: &mut Transaction) -> Result { - let game_bytes = to_vec(&game)?; +/// write a row for every cryp in a team when added to a battle +pub fn players_write(team: &Team, game_id: Uuid, tx: &mut Transaction) -> Result<(), Error> { + // pve + if !team.id.is_nil() { + for cryp in &team.cryps { + let id = Uuid::new_v4(); - for team in &game.teams { - // pve - if !team.id.is_nil() { - for cryp in &team.cryps { - let id = Uuid::new_v4(); + let query = " + INSERT INTO players (id, game, cryp, account) + VALUES ($1, $2, $3, $4) + RETURNING id, account; + "; - let query = " - INSERT INTO players (id, game, cryp, account) - VALUES ($1, $2, $3, $4) - RETURNING id, account; - "; + let result = tx + .query(query, &[&id, &game_id, &cryp.id, &team.id])?; - let result = tx - .query(query, &[&id, &game.id, &cryp.id, &team.id])?; + let _returned = result.iter().next().expect("no row written"); - let _returned = result.iter().next().expect("no row written"); - - println!("wrote player entry game:{:?} cryp:{:?} account:{:?}", game.id, cryp.id, team.id); - } + println!("wrote player entry game:{:?} cryp:{:?} account:{:?}", game_id, cryp.id, team.id); } } - return Ok(game); + return Ok(()); } pub fn game_write(game: Game, tx: &mut Transaction) -> Result { @@ -471,6 +463,8 @@ pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account) let mut game = Game::new(); + let game_id = game.id; + game .set_team_num(2) .set_team_size(1); @@ -489,7 +483,11 @@ pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account) game.start(); - return game_new(game, tx); + // persist + game_new(&game, tx)?; + players_write(&game.team_by_id(account.id), game_id, tx)?; + + Ok(game) } #[cfg(test)]