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) {
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);
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) {
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 mmSet = (
<button
className={'menu-instance-btn left'}
disabled={instanceJoinHidden}
onClick={() => sendPlayerMmCrypsSet()}>
Set Matchmaking Team
</button>
);
// const mmSet = (
// <button
// className={'menu-instance-btn left'}
// disabled={instanceJoinHidden}
// onClick={() => sendPlayerMmCrypsSet()}>
// Set Matchmaking Team
// </button>
// );
return (
<section className="menu-instance-list" >
@ -85,7 +85,6 @@ function Menu(args) {
</tbody>
</table>
<InstanceCreateForm />
{mmSet}
</section>
);
}

View File

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

View File

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

View File

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