instance finished flag in db

This commit is contained in:
ntr 2019-05-01 19:31:50 +10:00
parent 08b309de22
commit 92007a8c37
5 changed files with 32 additions and 18 deletions

View File

@ -646,8 +646,12 @@ table td svg {
}
/* GAME */
.game-back-btn {
flex: 0 0 20%;
.game-btn {
flex: 0 0 25%;
}
.game-btn:first-child {
margin-right: 0.5em;
}
.cryp-skill-btn[disabled] {

View File

@ -34,7 +34,7 @@ function GamePanel(props) {
<main className="game">
<div className="instance-hdr">
<button
className="game-back-btn instance-btn instance-ui-btn left"
className="game-btn instance-btn instance-ui-btn left"
onClick={() => toggleLog(!showLog)}>
Game
</button>
@ -57,20 +57,20 @@ function GamePanel(props) {
const header = (
<div className="instance-hdr">
<button
className="game-back-btn instance-btn instance-ui-btn left"
className="game-btn instance-btn instance-ui-btn left"
onClick={backClick}>
Back
</button>
<button
className="game-btn instance-btn instance-ui-btn left"
onClick={() => toggleLog(!showLog)}>
Log
</button>
<div className="spacer">
<div>&nbsp;</div>
</div>
<button
className="game-back-btn instance-btn instance-ui-btn left"
onClick={() => toggleLog(!showLog)}>
Log
</button>
<button
className="game-back-btn instance-btn instance-ui-btn right"
className="game-btn instance-btn instance-ui-btn right"
onClick={() => sendGameReady()}>
Ready
</button>
@ -169,7 +169,7 @@ function GamePanel(props) {
function OpponentTeam(team) {
const cryps = team.cryps.map(OpponentCryp);
return (
<div className="cryp-list" >
<div className="team-opponent cryp-list">
{cryps}
</div>
);
@ -194,9 +194,7 @@ function GamePanel(props) {
<div className="selected-skills">
{selectedSkills}
</div>
<div className="team-opponent cryp-list">
{otherTeams.map(OpponentTeam)}
</div>
{otherTeams.map(OpponentTeam)}
</main>
);
}

View File

@ -62,6 +62,7 @@ const addState = connect(
function quit() {
dispatch(actions.setGame(null));
dispatch(actions.setInstance(null));
}
function toggleLog(v) {

View File

@ -22,6 +22,12 @@ exports.up = async knex => {
.defaultTo(false)
.notNullable()
.index();
table.boolean('finished')
.defaultTo(false)
.notNullable()
.index();
});
await knex.schema.createTable('players', table => {

View File

@ -295,6 +295,10 @@ impl Instance {
self
}
fn finished(&self) -> bool {
self.phase == InstancePhase::Finished
}
fn bot_round_actions(&mut self) -> &mut Instance {
for bot in self.players.iter_mut().filter(|p| p.bot) {
bot.vbox.fill();
@ -501,13 +505,13 @@ pub fn instance_update(tx: &mut Transaction, instance: Instance) -> Result<Insta
let query = "
UPDATE instances
SET data = $1, open = $2, updated_at = now()
WHERE id = $3
SET data = $1, open = $2, finished = $3, updated_at = now()
WHERE id = $4
RETURNING id, data;
";
let result = tx
.query(query, &[&instance_bytes, &instance.open, &instance.id])?;
.query(query, &[&instance_bytes, &instance.open, &instance.finished(), &instance.id])?;
result.iter().next().ok_or(err_msg("no instance row returned"))?;
@ -582,7 +586,8 @@ pub fn instances_need_upkeep(tx: &mut Transaction) -> Result<Vec<Instance>, Erro
let query = "
SELECT data, id
FROM instances
WHERE id != '00000000-0000-0000-0000-000000000000'
WHERE finished = false
AND id != '00000000-0000-0000-0000-000000000000'
FOR UPDATE;
";