From 3fcbedb5e3a05cf551ec587fed774fca59e8d057 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 30 Jul 2019 13:18:47 +1000 Subject: [PATCH] join play and account team change' --- client/src/components/join.jsx | 50 ++++++++++++++ client/src/components/play.jsx | 121 +++++++++++++++++++++++++++++++++ server/src/account.rs | 4 +- server/src/instance.rs | 4 +- server/src/mtx.rs | 2 +- server/src/rpc.rs | 2 +- 6 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 client/src/components/join.jsx create mode 100644 client/src/components/play.jsx diff --git a/client/src/components/join.jsx b/client/src/components/join.jsx new file mode 100644 index 00000000..c77ebc39 --- /dev/null +++ b/client/src/components/join.jsx @@ -0,0 +1,50 @@ +const preact = require('preact'); +const { connect } = require('preact-redux'); + +const addState = connect( + function receiveState(state) { + const { ws } = state; + + function sendInstancePractice() { + ws.sendInstancePractice(); + } + + function sendInstanceQueue() { + ws.sendInstanceQueue(); + } + + return { + sendInstanceQueue, + sendInstancePractice, + }; + } +); + +function JoinButtons(args) { + const { + sendInstanceQueue, + sendInstancePractice, + } = args; + + return ( +
+

Join Game

+
+ + +
+
+ ); +} + +module.exports = addState(JoinButtons); diff --git a/client/src/components/play.jsx b/client/src/components/play.jsx new file mode 100644 index 00000000..13fa2adb --- /dev/null +++ b/client/src/components/play.jsx @@ -0,0 +1,121 @@ +const { connect } = require('preact-redux'); +const preact = require('preact'); + +const { stringSort } = require('./../utils'); +const { ConstructAvatar } = require('./construct'); +const actions = require('./../actions'); +const Join = require('./join'); +const Inventory = require('./inventory'); + +const idSort = stringSort('id'); + +const addState = connect( + function receiveState(state) { + const { + ws, + constructs, + constructRename, + team, + mtxActive, + } = state; + + function sendInstancePractice() { + return ws.sendInstancePractice(); + } + + function sendConstructAvatarReroll(id) { + console.log('using', mtxActive, 'on', id); + return ws.sendMtxApply(id, mtxActive, ''); + } + + function sendConstructRename(id, name) { + ws.sendMtxApply(id, 'Rename', name); + } + + return { + constructs, + mtxActive, + constructRename, + team, + sendConstructRename, + sendInstancePractice, + sendConstructAvatarReroll, + }; + }, + + function receiveDispatch(dispatch) { + function setConstructRename(id) { + dispatch(actions.setConstructRename(id)); + } + + function clearMtxRename() { + dispatch(actions.setConstructRename(null)); + dispatch(actions.setMtxActive(null)); + } + + return { + clearMtxRename, + setConstructRename, + }; + } + +); + +function Play(args) { + const { + team, + constructRename, + clearMtxRename, + setConstructRename, + sendConstructRename, + mtxActive, + sendConstructAvatarReroll, + } = args; + + const constructPanels = team + .map(construct => { + const constructName = constructRename === construct.id + ? + :

{construct.name}

; + + const confirm = constructRename === construct.id + ? + : false; + + const cancel = constructRename === construct.id + ? + : false; + return ( +
{ + if (!mtxActive) return false; + if (mtxActive === 'Rename') return setConstructRename(construct.id); + return sendConstructAvatarReroll(construct.id); + }} + class="menu-construct" > + + {constructName} + {confirm} + {cancel} +
+ ); + }); + + return ( +
+
+ {constructPanels} +
+ + +
+ ); +} + +module.exports = addState(Play); diff --git a/server/src/account.rs b/server/src/account.rs index 009ba195..16833c3a 100644 --- a/server/src/account.rs +++ b/server/src/account.rs @@ -296,7 +296,7 @@ pub fn constructs(tx: &mut Transaction, account: &Account) -> Result Result, Error> { +pub fn team(tx: &mut Transaction, account: &Account) -> Result, Error> { let query = " SELECT data FROM constructs @@ -350,7 +350,7 @@ pub fn set_team(tx: &mut Transaction, account: &Account, ids: Vec) -> Resu let _updated = tx .execute(query, &[&account.id, &ids])?; - account_team(tx, account) + team(tx, account) } pub fn account_instances(tx: &mut Transaction, account: &Account) -> Result, Error> { diff --git a/server/src/instance.rs b/server/src/instance.rs index e6c7ad11..bfe6420b 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -676,7 +676,7 @@ pub fn instance_practice(tx: &mut Transaction, account: &Account) -> Result Result Result { diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 1316d78f..6c4594de 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -237,7 +237,7 @@ impl Handler for Connection { let shop = mtx::account_shop(&mut tx, &a).unwrap(); self.ws.send(RpcMessage::AccountShop(shop)).unwrap(); - let team = account::account_team(&mut tx, &a).unwrap(); + let team = account::team(&mut tx, &a).unwrap(); self.ws.send(RpcMessage::AccountTeam(team)).unwrap(); // tx should do nothing