write player entries
This commit is contained in:
parent
69fe6e8f55
commit
50cb9a574f
@ -1,6 +1,13 @@
|
|||||||
|
# Principles
|
||||||
|
* Experience something
|
||||||
|
* Express something
|
||||||
|
* Prove something
|
||||||
|
|
||||||
|
# WORK WORK
|
||||||
* QOL
|
* QOL
|
||||||
* auto login
|
* auto login
|
||||||
* ws reconnect ✔
|
* ws reconnect ✔
|
||||||
|
|
||||||
* Levelling ✔
|
* Levelling ✔
|
||||||
|
|
||||||
* Global rolls
|
* Global rolls
|
||||||
@ -18,7 +25,11 @@
|
|||||||
* Scrabble grid
|
* Scrabble grid
|
||||||
|
|
||||||
* skills
|
* 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
|
* defensive
|
||||||
|
|
||||||
* Items
|
* Items
|
||||||
@ -34,10 +45,9 @@
|
|||||||
* Cryp Generation
|
* Cryp Generation
|
||||||
*
|
*
|
||||||
|
|
||||||
# Principles
|
# Db maintenance
|
||||||
* Experience something
|
* delete games when a cryp is deleted
|
||||||
* Express something
|
* does this need to happen? can have historical games
|
||||||
* Prove something
|
|
||||||
|
|
||||||
# Mechanic Ideas
|
# Mechanic Ideas
|
||||||
teams
|
teams
|
||||||
|
|||||||
@ -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<Game, Error> {
|
pub fn game_ability(params: GameAbilityParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -358,7 +353,7 @@ pub fn game_ability(params: GameAbilityParams, tx: &mut Transaction, account: &A
|
|||||||
return game_write(game, tx);
|
return game_write(game, tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn game_new(game: Game, tx: &mut Transaction) -> Result<Game, Error> {
|
pub fn game_new(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
|
||||||
let game_bytes = to_vec(&game)?;
|
let game_bytes = to_vec(&game)?;
|
||||||
|
|
||||||
let query = "
|
let query = "
|
||||||
@ -374,35 +369,32 @@ pub fn game_new(game: Game, tx: &mut Transaction) -> Result<Game, Error> {
|
|||||||
|
|
||||||
println!("{:?} wrote game", game.id);
|
println!("{:?} wrote game", game.id);
|
||||||
|
|
||||||
return Ok(game);
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn players_write(game: Game, tx: &mut Transaction) -> Result<Game, Error> {
|
/// write a row for every cryp in a team when added to a battle
|
||||||
let game_bytes = to_vec(&game)?;
|
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 {
|
let query = "
|
||||||
// pve
|
INSERT INTO players (id, game, cryp, account)
|
||||||
if !team.id.is_nil() {
|
VALUES ($1, $2, $3, $4)
|
||||||
for cryp in &team.cryps {
|
RETURNING id, account;
|
||||||
let id = Uuid::new_v4();
|
";
|
||||||
|
|
||||||
let query = "
|
let result = tx
|
||||||
INSERT INTO players (id, game, cryp, account)
|
.query(query, &[&id, &game_id, &cryp.id, &team.id])?;
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING id, account;
|
|
||||||
";
|
|
||||||
|
|
||||||
let result = tx
|
let _returned = result.iter().next().expect("no row written");
|
||||||
.query(query, &[&id, &game.id, &cryp.id, &team.id])?;
|
|
||||||
|
|
||||||
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<Game, Error> {
|
pub fn game_write(game: Game, tx: &mut Transaction) -> Result<Game, Error> {
|
||||||
@ -471,6 +463,8 @@ pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account)
|
|||||||
|
|
||||||
let mut game = Game::new();
|
let mut game = Game::new();
|
||||||
|
|
||||||
|
let game_id = game.id;
|
||||||
|
|
||||||
game
|
game
|
||||||
.set_team_num(2)
|
.set_team_num(2)
|
||||||
.set_team_size(1);
|
.set_team_size(1);
|
||||||
@ -489,7 +483,11 @@ pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account)
|
|||||||
|
|
||||||
game.start();
|
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)]
|
#[cfg(test)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user