warden works

This commit is contained in:
ntr 2019-04-29 18:53:04 +10:00
parent 18aef974b6
commit 59a22b6122
5 changed files with 98 additions and 99 deletions

View File

@ -73,14 +73,14 @@ function GamePanel(props) {
); );
function findCryp(id) { function findCryp(id) {
const team = game.teams.find(t => t.cryps.find(c => c.id === id)); const team = game.players.find(t => t.cryps.find(c => c.id === id));
if (team) return team.cryps.find(c => c.id === id); if (team) return team.cryps.find(c => c.id === id);
return null; return null;
} }
const otherTeams = game.teams.filter(t => t.id !== account.id); const otherTeams = game.players.filter(t => t.id !== account.id);
const playerTeam = game.teams.find(t => t.id === account.id); const playerTeam = game.players.find(t => t.id === account.id);
function stackElement(c, i) { function stackElement(c, i) {
let skills = game.stack.filter(s => s.source_cryp_id === c.id).map((s, j) => { let skills = game.stack.filter(s => s.source_cryp_id === c.id).map((s, j) => {

View File

@ -58,14 +58,14 @@ function Menu(args) {
const instanceJoinHidden = !selectedCryps.every(c => !!c); const instanceJoinHidden = !selectedCryps.every(c => !!c);
const mmSet = ( // const mmSet = (
<button // <button
className={'menu-instance-btn left'} // className={'menu-instance-btn left'}
disabled={instanceJoinHidden} // disabled={instanceJoinHidden}
onClick={() => sendPlayerMmCrypsSet()}> // onClick={() => sendPlayerMmCrypsSet()}>
Set Matchmaking Team // Set Matchmaking Team
</button> // </button>
); // );
return ( return (
<section className="menu-instance-list" > <section className="menu-instance-list" >
@ -85,7 +85,6 @@ function Menu(args) {
</tbody> </tbody>
</table> </table>
<InstanceCreateForm /> <InstanceCreateForm />
{mmSet}
</section> </section>
); );
} }

View File

@ -692,89 +692,89 @@ pub fn game_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
return Ok(()); return Ok(());
} }
pub fn game_global_startup(tx: &mut Transaction) -> Result<(), Error> { // pub fn game_global_startup(tx: &mut Transaction) -> Result<(), Error> {
if game_global_get(tx).is_ok() { // if game_global_get(tx).is_ok() {
println!("global mm game exists"); // println!("global mm game exists");
return Ok(()); // return Ok(());
} // }
let mut game = Game::new(); // let mut game = Game::new();
game // game
.set_player_num(2) // .set_player_num(2)
.set_player_cryps(3) // .set_player_cryps(3)
.set_mode(GameMode::Pvp); // .set_mode(GameMode::Pvp);
game_write(tx, &game)?; // game_write(tx, &game)?;
let query = " // let query = "
INSERT INTO matchmaking (id, game) // INSERT INTO matchmaking (id, game)
VALUES ($1, $2) // VALUES ($1, $2)
RETURNING id; // RETURNING id;
"; // ";
let result = tx // let result = tx
.query(query, &[&Uuid::nil(), &game.id])?; // .query(query, &[&Uuid::nil(), &game.id])?;
result.iter().next().ok_or(format_err!("no game written"))?; // result.iter().next().ok_or(format_err!("no game written"))?;
println!("{:} wrote global mm startup", game.id); // println!("{:} wrote global mm startup", game.id);
return Ok(()); // return Ok(());
} // }
pub fn game_global_set(tx: &mut Transaction, game: &Game) -> Result<(), Error> { // pub fn game_global_set(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
let query = " // let query = "
UPDATE matchmaking // UPDATE matchmaking
SET game = $1 // SET game = $1
WHERE id = $2 // WHERE id = $2
RETURNING id, game; // RETURNING id, game;
"; // ";
let result = tx // let result = tx
.query(query, &[&game.id, &Uuid::nil()])?; // .query(query, &[&game.id, &Uuid::nil()])?;
result.iter() // result.iter()
.next() // .next()
.ok_or(err_msg("could not set global game mm"))?; // .ok_or(err_msg("could not set global game mm"))?;
return Ok(()); // return Ok(());
} // }
pub fn game_global_get(tx: &mut Transaction) -> Result<Game, Error> { // pub fn game_global_get(tx: &mut Transaction) -> Result<Game, Error> {
let query = " // let query = "
SELECT * from games // SELECT * from games
WHERE id = ( // WHERE id = (
SELECT game // SELECT game
FROM matchmaking // FROM matchmaking
WHERE id = $1 // WHERE id = $1
); // );
"; // ";
let delete_query = " // let delete_query = "
DELETE from matchmaking; // DELETE from matchmaking;
"; // ";
let result = tx // let result = tx
.query(query, &[&Uuid::nil()])?; // .query(query, &[&Uuid::nil()])?;
let returned = match result.iter().next() { // let returned = match result.iter().next() {
Some(row) => row, // Some(row) => row,
None => return Err(err_msg("game not found")), // None => return Err(err_msg("game not found")),
}; // };
// tells from_slice to cast into a cryp // // tells from_slice to cast into a cryp
let game_bytes: Vec<u8> = returned.get("data"); // let game_bytes: Vec<u8> = returned.get("data");
let game = match from_slice::<Game>(&game_bytes) { // let game = match from_slice::<Game>(&game_bytes) {
Ok(g) => g, // Ok(g) => g,
Err(_) => { // Err(_) => {
tx.query(delete_query, &[])?; // tx.query(delete_query, &[])?;
return Err(err_msg("matchmaking game was invalid")) // return Err(err_msg("matchmaking game was invalid"))
} // }
}; // };
return Ok(game); // return Ok(game);
} // }
pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> { pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> {

View File

@ -14,7 +14,7 @@ use account::Account;
use player::{Player, player_create, player_get, player_global_update}; use player::{Player, player_create, player_get, player_global_update};
use cryp::{Cryp, cryp_get}; use cryp::{Cryp, cryp_get};
use mob::{instance_mobs}; use mob::{instance_mobs};
use game::{Game, Phase, game_get, game_write, game_instance_new, game_instance_join, game_global_get, game_global_set}; use game::{Game, Phase, game_get, game_write, game_instance_new, game_instance_join};
use vbox::{Var}; use vbox::{Var};
use rpc::{RpcResult}; use rpc::{RpcResult};
use names::{name}; use names::{name};
@ -612,26 +612,26 @@ pub fn instance_join(params: InstanceJoinParams, tx: &mut Transaction, account:
instance_update(tx, instance) instance_update(tx, instance)
} }
pub fn instance_ready_global(tx: &mut Transaction, _account: &Account, player: Player) -> Result<Game, Error> { // pub fn instance_ready_global(tx: &mut Transaction, _account: &Account, player: Player) -> Result<Game, Error> {
// get the game // // get the game
let game = match game_global_get(tx) { // let game = match game_global_get(tx) {
Ok(g) => { // Ok(g) => {
println!("received global game {:?}", g.id); // println!("received global game {:?}", g.id);
// if there is one try to join // // if there is one try to join
match game_instance_join(tx, player.clone(), g.id) { // match game_instance_join(tx, player.clone(), g.id) {
Ok(g) => g, // Ok(g) => g,
// if fails make a new one // // if fails make a new one
Err(_e) => game_instance_new(tx, vec![player], Uuid::new_v4(), Uuid::nil())?, // Err(_e) => game_instance_new(tx, vec![player], Uuid::new_v4(), Uuid::nil())?,
} // }
}, // },
// if not found make a new one // // if not found make a new one
Err(_) => game_instance_new(tx, vec![player], Uuid::new_v4(), Uuid::nil())?, // Err(_) => game_instance_new(tx, vec![player], Uuid::new_v4(), Uuid::nil())?,
}; // };
// set the current game // // set the current game
game_global_set(tx, &game)?; // game_global_set(tx, &game)?;
Ok(game) // Ok(game)
} // }
pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> { pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
let mut instance = instance_get(tx, params.instance_id)?; let mut instance = instance_get(tx, params.instance_id)?;

View File

@ -2,14 +2,14 @@ use net::Db;
// Db Commons // Db Commons
use failure::Error; use failure::Error;
use game::{game_global_startup}; // use game::{game_global_startup};
pub fn startup(db: Db) -> Result<(), Error> { pub fn startup(db: Db) -> Result<(), Error> {
let mut tx = db.transaction()?; let mut tx = db.transaction()?;
println!("running startup fns"); println!("running startup fns");
game_global_startup(&mut tx)?; // game_global_startup(&mut tx)?;
match tx.commit() { match tx.commit() {
Ok(_) => { Ok(_) => {