From ca036ed9e019eda9e7710d7994b1941cd5aafc91 Mon Sep 17 00:00:00 2001 From: ntr Date: Fri, 31 May 2019 12:25:50 +1000 Subject: [PATCH 1/2] login and style fixes --- client/assets/styles/skeleton.css | 2 +- client/src/actions.jsx | 1 + client/src/components/info.component.jsx | 5 +- client/src/components/info.container.jsx | 2 + client/src/components/instance.component.jsx | 3 +- client/src/components/instance.constructs.jsx | 3 +- client/src/components/instance.equip.jsx | 3 +- client/src/components/login.component.jsx | 45 --------- client/src/components/login.container.jsx | 19 ---- client/src/components/login.jsx | 93 +++++++++++++++++++ client/src/components/main.jsx | 6 +- client/src/components/vbox.component.jsx | 3 +- client/src/events.jsx | 4 +- client/src/reducers.jsx | 1 + 14 files changed, 110 insertions(+), 80 deletions(-) delete mode 100644 client/src/components/login.component.jsx delete mode 100644 client/src/components/login.container.jsx create mode 100644 client/src/components/login.jsx diff --git a/client/assets/styles/skeleton.css b/client/assets/styles/skeleton.css index 1346c628..fcb295f9 100644 --- a/client/assets/styles/skeleton.css +++ b/client/assets/styles/skeleton.css @@ -172,7 +172,7 @@ input[type="reset"], input[type="button"] { display: inline-block; height: 38px; - padding: 0 30px; + /*padding: 0 2em;*/ color: #555; text-align: center; font-size: 11px; diff --git a/client/src/actions.jsx b/client/src/actions.jsx index f729d120..cfd94ee6 100644 --- a/client/src/actions.jsx +++ b/client/src/actions.jsx @@ -8,6 +8,7 @@ export const setNav = value => ({ type: 'SET_NAV', value }); export const setShowNav = value => ({ type: 'SET_SHOW_NAV', value }); export const setInstance = value => ({ type: 'SET_INSTANCE', value }); export const setPing = value => ({ type: 'SET_PING', value }); +export const setPlayer = value => ({ type: 'SET_PLAYER', value }); export const setGame = value => ({ type: 'SET_GAME', value }); export const setResolution = value => ({ type: 'SET_RESOLUTION', value }); export const setShowLog = value => ({ type: 'SET_SHOW_LOG', value }); diff --git a/client/src/components/info.component.jsx b/client/src/components/info.component.jsx index c70133e9..d94b6597 100644 --- a/client/src/components/info.component.jsx +++ b/client/src/components/info.component.jsx @@ -11,12 +11,9 @@ function InfoComponent(args) { itemInfo, combiner, - instance, - account, + player, } = args; - const player = instance.players.find(p => p.id === account.id); - function Info() { if (!info) return false; const fullInfo = itemInfo.items.find(i => i.item === info) || INFO[info]; diff --git a/client/src/components/info.container.jsx b/client/src/components/info.container.jsx index 9d460ff9..5f8639b8 100644 --- a/client/src/components/info.container.jsx +++ b/client/src/components/info.container.jsx @@ -11,6 +11,7 @@ const addState = connect( info, itemInfo, instance, + player, account, } = state; @@ -20,6 +21,7 @@ const addState = connect( info, itemInfo, instance, + player, account, }; }, diff --git a/client/src/components/instance.component.jsx b/client/src/components/instance.component.jsx index 36ed0727..457ba45a 100644 --- a/client/src/components/instance.component.jsx +++ b/client/src/components/instance.component.jsx @@ -10,8 +10,7 @@ const actions = require('../actions'); const addState = connect( function receiveState(state) { - const { ws, instance, account, nav } = state; - const player = instance.players.find(p => p.id === account.id); + const { ws, instance, player, account, nav } = state; function sendInstanceReady() { return ws.sendInstanceReady(instance.id); diff --git a/client/src/components/instance.constructs.jsx b/client/src/components/instance.constructs.jsx index fabb665e..cdaa8aab 100644 --- a/client/src/components/instance.constructs.jsx +++ b/client/src/components/instance.constructs.jsx @@ -8,8 +8,7 @@ const actions = require('../actions'); const addState = connect( function receiveState(state) { - const { ws, instance, account, itemInfo, itemEquip, activeConstruct } = state; - const player = instance.players.find(p => p.id === account.id); + const { ws, instance, player, account, itemInfo, itemEquip, activeConstruct } = state; function sendInstanceReady() { return ws.sendInstanceReady(instance.id); diff --git a/client/src/components/instance.equip.jsx b/client/src/components/instance.equip.jsx index bc44bc0c..f0e9874f 100644 --- a/client/src/components/instance.equip.jsx +++ b/client/src/components/instance.equip.jsx @@ -8,8 +8,7 @@ const { convertItem } = require('./../utils'); const addState = connect( function receiveState(state) { - const { account, activeConstruct, itemInfo, info, ws, instance, itemUnequip } = state; - const player = instance.players.find(p => p.id === account.id); + const { account, activeConstruct, itemInfo, info, ws, instance, player, itemUnequip } = state; function sendUnequip(constructId, item) { return ws.sendVboxUnequip(instance.id, constructId, item); diff --git a/client/src/components/login.component.jsx b/client/src/components/login.component.jsx deleted file mode 100644 index 43c7671f..00000000 --- a/client/src/components/login.component.jsx +++ /dev/null @@ -1,45 +0,0 @@ -// eslint-disable-next-line -const preact = require('preact'); - -function renderLogin({ submitLogin, submitRegister }) { - const details = { - name: '', - password: '', - }; - - return ( -
-
- (details.name = e.target.value)} - /> - (details.password = e.target.value)} - /> - - - -
-
- ); -} - -module.exports = renderLogin; diff --git a/client/src/components/login.container.jsx b/client/src/components/login.container.jsx deleted file mode 100644 index d0ca7fe4..00000000 --- a/client/src/components/login.container.jsx +++ /dev/null @@ -1,19 +0,0 @@ -const { connect } = require('preact-redux'); - -const Login = require('./login.component'); - -const addState = connect( - (state) => { - const { ws, account } = state; - function submitLogin(name, password) { - return ws.sendAccountLogin(name, password); - } - function submitRegister(name, password) { - console.log(name, password); - return ws.sendAccountCreate(name, password); - } - return { account, submitLogin, submitRegister }; - }, -); - -module.exports = addState(Login); diff --git a/client/src/components/login.jsx b/client/src/components/login.jsx new file mode 100644 index 00000000..18707013 --- /dev/null +++ b/client/src/components/login.jsx @@ -0,0 +1,93 @@ +// eslint-disable-next-line +const preact = require('preact'); +const { Component } = require('preact') +const { connect } = require('preact-redux'); + +const addState = connect( + (state) => { + const { ws, account } = state; + function submitLogin(name, password) { + return ws.sendAccountLogin(name, password); + } + function submitRegister(name, password) { + console.log(name, password); + return ws.sendAccountCreate(name, password); + } + return { account, submitLogin, submitRegister }; + }, +); + +class Login extends Component { + constructor(props) { + super(props); + + this.state = { name: '', password: '' }; + + this.nameInput = this.nameInput.bind(this); + this.passwordInput = this.passwordInput.bind(this); + this.loginSubmit = this.loginSubmit.bind(this); + this.registerSubmit = this.registerSubmit.bind(this); + } + + nameInput(event) { + console.log(event.target.value); + this.setState({ name: event.target.value }); + } + + passwordInput(event) { + this.setState({ password: event.target.value }); + } + + loginSubmit(event) { + event.preventDefault(); + console.log(this.state); + this.props.submitLogin(this.state.name, this.state.password); + this.setState({ name: '', password: '' }); + } + + registerSubmit(event) { + event.preventDefault(); + this.props.submitRegister(this.state.name, this.state.password); + console.log(this.state); + this.setState({ name: '', password: '' }); + } + + + render() { + return ( +
+
+ + + + + +
+
+ ); + } +} + +module.exports = addState(Login); diff --git a/client/src/components/main.jsx b/client/src/components/main.jsx index c38cd7cb..e8583398 100644 --- a/client/src/components/main.jsx +++ b/client/src/components/main.jsx @@ -2,7 +2,7 @@ const preact = require('preact'); const { connect } = require('preact-redux'); -const LoginContainer = require('./login.container'); +const Login = require('./login'); const GameContainer = require('./game.container'); const Instance = require('./instance.component'); const Team = require('./team'); @@ -24,7 +24,7 @@ function Main(props) { } = props; if (!account) { - return ; + return ; } if (game) { @@ -35,6 +35,8 @@ function Main(props) { return ; } + console.warn('nav', nav, instance, game) + if (nav === 'team') return ; if (nav === 'list') return ; diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx index df699660..1e520d73 100644 --- a/client/src/components/vbox.component.jsx +++ b/client/src/components/vbox.component.jsx @@ -12,14 +12,13 @@ const addState = connect( ws, account, instance, + player, combiner, reclaiming, vboxHighlight, itemInfo, } = state; - const player = instance.players.find(p => p.id === account.id); - function sendVboxDiscard() { return ws.sendVboxDiscard(instance.id); } diff --git a/client/src/events.jsx b/client/src/events.jsx index c0dcd3f2..be76916d 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -125,7 +125,9 @@ function registerEvents(store) { if (!instance || v.id !== instance.id) { store.dispatch(actions.setNav('vbox')); - const first = v.players.find(p => p.id === account.id).constructs[0]; + const player = v.players.find(p => p.id === account.id); + store.dispatch(actions.setPlayer(player)); + const first = player.constructs[0]; store.dispatch(actions.setActiveConstruct(first)); } } diff --git a/client/src/reducers.jsx b/client/src/reducers.jsx index 4e5baf16..54dab9e2 100644 --- a/client/src/reducers.jsx +++ b/client/src/reducers.jsx @@ -27,6 +27,7 @@ module.exports = { nav: createReducer(null, 'SET_NAV'), showNav: createReducer(null, 'SET_SHOW_NAV'), ping: createReducer(null, 'SET_PING'), + player: createReducer(null, 'SET_PLAYER'), reclaiming: createReducer(false, 'SET_RECLAIMING'), resolution: createReducer(null, 'SET_RESOLUTION'), showLog: createReducer(false, 'SET_SHOW_LOG'), From d6a3ca2eb4a3d93c2369a7c15a121da853ba7212 Mon Sep 17 00:00:00 2001 From: ntr Date: Fri, 31 May 2019 12:41:34 +1000 Subject: [PATCH 2/2] fix player bug --- client/src/components/vbox.component.jsx | 1 - client/src/events.jsx | 5 +++-- server/src/rpc.rs | 14 -------------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx index 1e520d73..4899b260 100644 --- a/client/src/components/vbox.component.jsx +++ b/client/src/components/vbox.component.jsx @@ -10,7 +10,6 @@ const addState = connect( function receiveState(state) { const { ws, - account, instance, player, combiner, diff --git a/client/src/events.jsx b/client/src/events.jsx index 9d666be3..38388cac 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -120,10 +120,11 @@ function registerEvents(store) { if (v) { ws.startInstanceStateTimeout(v.id); + const player = v.players.find(p => p.id === account.id); + store.dispatch(actions.setPlayer(player)); + if (!instance || v.id !== instance.id) { store.dispatch(actions.setNav('vbox')); - const player = v.players.find(p => p.id === account.id); - store.dispatch(actions.setPlayer(player)); const first = player.constructs[0]; store.dispatch(actions.setActiveConstruct(first)); } diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 464ff017..f6a2c8b7 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -4,11 +4,7 @@ use tungstenite::Message::Binary; use postgres::transaction::Transaction; use std::net::{TcpStream}; -// demo -use std::iter; use std::time::Instant; -use rand::{thread_rng, Rng}; -use rand::distributions::{Alphanumeric}; use serde_cbor::{from_slice, to_vec}; use uuid::Uuid; @@ -353,11 +349,6 @@ impl Rpc { params: RpcResult::InstanceState(vbox_apply(msg.params, tx, &account)?) }; - Rpc::send_msg(client, RpcResponse { - method: "account_constructs".to_string(), - params: RpcResult::ConstructList(account_constructs(tx, &account)?) - })?; - return Ok(response); } @@ -380,11 +371,6 @@ impl Rpc { params: RpcResult::InstanceState(vbox_unequip(msg.params, tx, &account)?) }; - Rpc::send_msg(client, RpcResponse { - method: "account_constructs".to_string(), - params: RpcResult::ConstructList(account_constructs(tx, &account)?) - })?; - return Ok(response); } }