default view games list

This commit is contained in:
ntr 2019-07-07 15:42:29 +10:00
parent ec4252d5c9
commit f24b5afd5c
11 changed files with 30 additions and 28 deletions

View File

@ -34,7 +34,7 @@
* invader set * invader set
* start with 3 constructs w/ random names * start with 3 constructs w/ random names
* storing construct costs 5cr * new construct costs 5cr
* eth adapter * eth adapter

View File

@ -302,9 +302,6 @@ module.exports = {
// disallow use of comma operator // disallow use of comma operator
'no-sequences': 'error', 'no-sequences': 'error',
// restrict what can be breakn as an exception
'no-break-literal': 'error',
// disallow unmodified conditions of loops // disallow unmodified conditions of loops
// https://eslint.org/docs/rules/no-unmodified-loop-condition // https://eslint.org/docs/rules/no-unmodified-loop-condition
'no-unmodified-loop-condition': 'off', 'no-unmodified-loop-condition': 'off',

View File

@ -3,6 +3,7 @@ const preact = require('preact');
const { Elements, injectStripe } = require('react-stripe-elements'); const { Elements, injectStripe } = require('react-stripe-elements');
const { saw } = require('./shapes'); const { saw } = require('./shapes');
const { postData } = require('./../utils');
function pingColour(ping) { function pingColour(ping) {
if (ping < 100) return 'forestgreen'; if (ping < 100) return 'forestgreen';

View File

@ -21,8 +21,6 @@ function Main(props) {
instance, instance,
account, account,
nav, nav,
team,
constructs,
} = props; } = props;
if (!account) { if (!account) {
@ -37,7 +35,7 @@ function Main(props) {
return <Instance />; return <Instance />;
} }
if (nav === 'team' || !team.some(t => t) || constructs.length < 3) return <Team />; if (nav === 'team') return <Team />;
if (nav === 'list') return <List />; if (nav === 'list') return <List />;
return ( return (

View File

@ -3,6 +3,7 @@ const preact = require('preact');
const { Fragment } = require('preact'); const { Fragment } = require('preact');
const { postData } = require('../utils'); const { postData } = require('../utils');
console.log(postData);
const actions = require('../actions'); const actions = require('../actions');
const AccountStatus = require('./account.status'); const AccountStatus = require('./account.status');
@ -33,10 +34,6 @@ const addState = connect(
return ws.sendInstanceList(); return ws.sendInstanceList();
} }
function logout() {
postData('/logout').then(() => window.location.reload(true));
}
return { return {
account, account,
instances, instances,
@ -46,7 +43,6 @@ const addState = connect(
sendInstanceState, sendInstanceState,
sendAccountInstances, sendAccountInstances,
sendInstanceList, sendInstanceList,
logout,
}; };
}, },
function receiveDispatch(dispatch) { function receiveDispatch(dispatch) {
@ -142,7 +138,6 @@ function Nav(args) {
<h1 class="header-title">mnml.gg</h1> <h1 class="header-title">mnml.gg</h1>
<AccountStatus /> <AccountStatus />
<hr /> <hr />
<button onClick={() => navTo('team')}>Select Team</button>
<button disabled={canJoin} onClick={() => navTo('list')}>Play</button> <button disabled={canJoin} onClick={() => navTo('list')}>Play</button>
<hr /> <hr />
{joined} {joined}

View File

@ -33,7 +33,12 @@ function registerEvents(store) {
// check team is in list // check team is in list
const { team } = store.getState(); const { team } = store.getState();
const ids = constructs.map(c => c.id); const ids = constructs.map(c => c.id);
if (!team.every(t => t && ids.includes(t))) store.dispatch(actions.setTeam([null, null, null]));
// team is fucked up, or just registered
// reset to the first 3 constructs
if (!team.every(t => t && ids.includes(t))) {
store.dispatch(actions.setTeam([ids[0], ids[1], ids[2]]));
}
store.dispatch(actions.setConstructs(constructs)); store.dispatch(actions.setConstructs(constructs));
} }

View File

@ -221,9 +221,7 @@ function createSocket(events) {
}; };
function logout() { function logout() {
localStorage.removeItem('account'); window.location.reload(true);
account = null;
event.setAccount(null);
} }
function errHandler(error) { function errHandler(error) {

View File

@ -8,7 +8,9 @@ use serde_cbor::{from_slice};
use postgres::transaction::Transaction; use postgres::transaction::Transaction;
use construct::{Construct, construct_recover}; use names::{name as generate_name};
use rpc::{ConstructSpawnParams};
use construct::{Construct, construct_recover, construct_spawn};
use instance::{Instance, instance_delete}; use instance::{Instance, instance_delete};
use failure::Error; use failure::Error;
@ -228,6 +230,13 @@ pub fn account_create(name: &String, password: &String, code: &String, tx: &mut
None => return Err(err_msg("account not created")), None => return Err(err_msg("account not created")),
}; };
// slow but neat
let account = Account::select(tx, id)?;
for _i in 0..3 {
construct_spawn(tx, ConstructSpawnParams { name: generate_name() }, account.id)?;
}
info!("registration account={:?}", name); info!("registration account={:?}", name);
Ok(token) Ok(token)

View File

@ -7,7 +7,6 @@ use postgres::transaction::Transaction;
use failure::Error; use failure::Error;
use failure::err_msg; use failure::err_msg;
use account::{Account};
use rpc::{ConstructSpawnParams}; use rpc::{ConstructSpawnParams};
use skill::{Skill, Cast, Immunity, Disable, Event}; use skill::{Skill, Cast, Immunity, Disable, Event};
use effect::{Cooldown, Effect, Colour}; use effect::{Cooldown, Effect, Colour};
@ -838,10 +837,10 @@ pub fn construct_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result
return Ok(construct); return Ok(construct);
} }
pub fn construct_spawn(params: ConstructSpawnParams, tx: &mut Transaction, account: &Account) -> Result<Construct, Error> { pub fn construct_spawn(tx: &mut Transaction, params: ConstructSpawnParams, account: Uuid) -> Result<Construct, Error> {
let construct = Construct::new() let construct = Construct::new()
.named(&params.name) .named(&params.name)
.set_account(account.id); .set_account(account);
let construct_bytes = to_vec(&construct)?; let construct_bytes = to_vec(&construct)?;
@ -852,7 +851,7 @@ pub fn construct_spawn(params: ConstructSpawnParams, tx: &mut Transaction, accou
"; ";
let result = tx let result = tx
.query(query, &[&construct.id, &account.id, &construct_bytes])?; .query(query, &[&construct.id, &account, &construct_bytes])?;
let _returned = result.iter().next().ok_or(err_msg("no row returned"))?; let _returned = result.iter().next().ok_or(err_msg("no row returned"))?;

View File

@ -1,7 +1,7 @@
use rand::prelude::*; use rand::prelude::*;
use rand::{thread_rng}; use rand::{thread_rng};
const FIRSTS: [&'static str; 22] = [ const FIRSTS: [&'static str; 23] = [
"fierce", "fierce",
"obscure", "obscure",
"mighty", "mighty",
@ -24,9 +24,10 @@ const FIRSTS: [&'static str; 22] = [
"purified", "purified",
"organic", "organic",
"distorted", "distorted",
"weary",
]; ];
const LASTS: [&'static str; 29] = [ const LASTS: [&'static str; 30] = [
"kaffe", "kaffe",
"foilage", "foilage",
"wildlife", "wildlife",
@ -56,6 +57,7 @@ const LASTS: [&'static str; 29] = [
"warning", "warning",
"information", "information",
"witness", "witness",
"traveller",
]; ];
pub fn name() -> String { pub fn name() -> String {

View File

@ -117,11 +117,10 @@ fn handle_game_ready(data: Vec<u8>, tx: &mut Transaction, account: &Account) ->
Ok(RpcResult::GameState(game_ready(msg.params, tx, &account)?)) Ok(RpcResult::GameState(game_ready(msg.params, tx, &account)?))
} }
fn handle_construct_spawn(data: Vec<u8>, tx: &mut Transaction, account: &Account) -> Result<RpcResult, Error> { fn handle_construct_spawn(data: Vec<u8>, tx: &mut Transaction, account: &Account) -> Result<RpcResult, Error> {
let msg = from_slice::<ConstructSpawnMsg>(&data).or(Err(err_msg("invalid params")))?; let msg = from_slice::<ConstructSpawnMsg>(&data).or(Err(err_msg("invalid params")))?;
construct_spawn(msg.params, tx, &account)?; construct_spawn(tx, msg.params, account.id)?;
Ok(RpcResult::AccountConstructs(account_constructs(tx, &account)?)) Ok(RpcResult::AccountConstructs(account_constructs(tx, account)?))
} }
fn handle_construct_delete(data: Vec<u8>, tx: &mut Transaction, account: &Account) -> Result<RpcResult, Error> { fn handle_construct_delete(data: Vec<u8>, tx: &mut Transaction, account: &Account) -> Result<RpcResult, Error> {
@ -130,7 +129,6 @@ fn handle_construct_delete(data: Vec<u8>, tx: &mut Transaction, account: &Accoun
Ok(RpcResult::AccountConstructs(account_constructs(tx, &account)?)) Ok(RpcResult::AccountConstructs(account_constructs(tx, &account)?))
} }
// fn handle_account_create(data: Vec<u8>, tx: &mut Transaction) -> Result<RpcResult, Error> { // fn handle_account_create(data: Vec<u8>, tx: &mut Transaction) -> Result<RpcResult, Error> {
// let msg = from_slice::<AccountCreateMsg>(&data).or(Err(err_msg("invalid params")))?; // let msg = from_slice::<AccountCreateMsg>(&data).or(Err(err_msg("invalid params")))?;
// let account = account_create(msg.params, tx)?; // let account = account_create(msg.params, tx)?;