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
* start with 3 constructs w/ random names
* storing construct costs 5cr
* new construct costs 5cr
* eth adapter

View File

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

View File

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

View File

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

View File

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

View File

@ -33,7 +33,12 @@ function registerEvents(store) {
// check team is in list
const { team } = store.getState();
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));
}

View File

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

View File

@ -8,7 +8,9 @@ use serde_cbor::{from_slice};
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 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")),
};
// 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);
Ok(token)

View File

@ -7,7 +7,6 @@ use postgres::transaction::Transaction;
use failure::Error;
use failure::err_msg;
use account::{Account};
use rpc::{ConstructSpawnParams};
use skill::{Skill, Cast, Immunity, Disable, Event};
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);
}
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()
.named(&params.name)
.set_account(account.id);
.set_account(account);
let construct_bytes = to_vec(&construct)?;
@ -852,7 +851,7 @@ pub fn construct_spawn(params: ConstructSpawnParams, tx: &mut Transaction, accou
";
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"))?;

View File

@ -1,7 +1,7 @@
use rand::prelude::*;
use rand::{thread_rng};
const FIRSTS: [&'static str; 22] = [
const FIRSTS: [&'static str; 23] = [
"fierce",
"obscure",
"mighty",
@ -24,9 +24,10 @@ const FIRSTS: [&'static str; 22] = [
"purified",
"organic",
"distorted",
"weary",
];
const LASTS: [&'static str; 29] = [
const LASTS: [&'static str; 30] = [
"kaffe",
"foilage",
"wildlife",
@ -56,6 +57,7 @@ const LASTS: [&'static str; 29] = [
"warning",
"information",
"witness",
"traveller",
];
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)?))
}
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")))?;
construct_spawn(msg.params, tx, &account)?;
Ok(RpcResult::AccountConstructs(account_constructs(tx, &account)?))
construct_spawn(tx, msg.params, account.id)?;
Ok(RpcResult::AccountConstructs(account_constructs(tx, account)?))
}
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)?))
}
// 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 account = account_create(msg.params, tx)?;