From eb2089cc176d25867c6ad55e1e20c410aef182e4 Mon Sep 17 00:00:00 2001 From: ntr Date: Thu, 25 Apr 2019 14:43:29 +1000 Subject: [PATCH] lobby list --- client/src/actions.jsx | 3 +++ client/src/components/instance.component.jsx | 8 +++++--- client/src/components/instance.container.jsx | 4 ++-- client/src/components/vbox.component.jsx | 7 ++++--- client/src/components/vbox.container.jsx | 10 ++++++---- client/src/events.jsx | 9 ++++++--- client/src/main.jsx | 1 + client/src/reducers.jsx | 11 +++++++++++ client/src/socket.jsx | 8 ++++---- server/src/instance.rs | 18 ++++++++++++------ 10 files changed, 54 insertions(+), 25 deletions(-) diff --git a/client/src/actions.jsx b/client/src/actions.jsx index e0910258..0e12ec2f 100644 --- a/client/src/actions.jsx +++ b/client/src/actions.jsx @@ -10,6 +10,9 @@ export const setInstances = value => ({ type: SET_INSTANCES, value }); export const SET_INSTANCE = 'SET_INSTANCE'; export const setInstance = value => ({ type: SET_INSTANCE, value }); +export const SET_PLAYER = 'SET_PLAYER'; +export const setPlayer = value => ({ type: SET_PLAYER, value }); + export const SET_GAME = 'SET_GAME'; export const setGame = value => ({ type: SET_GAME, value }); diff --git a/client/src/components/instance.component.jsx b/client/src/components/instance.component.jsx index 58ab814c..f04e151d 100644 --- a/client/src/components/instance.component.jsx +++ b/client/src/components/instance.component.jsx @@ -108,7 +108,7 @@ function Cryp(props) { function InstanceComponent(args) { const { - // account, + account, instance, quit, // clearInfo, @@ -123,7 +123,9 @@ function InstanceComponent(args) { if (!instance) return
...
; - const cryps = instance.cryps.map((c, i) => Cryp({ + const player = instance.players.find(p => p.account === account.id); + + const cryps = player.cryps.map((c, i) => Cryp({ cryp: c, sendVboxApply, setInfo, activeVar, setActiveCryp, })); @@ -134,7 +136,7 @@ function InstanceComponent(args) { } function showTeam(e) { - setActiveCryp(instance.cryps[0]); + setActiveCryp(player.cryps[0]); e.stopPropagation(); } diff --git a/client/src/components/instance.container.jsx b/client/src/components/instance.container.jsx index cbca9a30..e06b35af 100644 --- a/client/src/components/instance.container.jsx +++ b/client/src/components/instance.container.jsx @@ -9,11 +9,11 @@ const addState = connect( const { ws, instance, account, activeVar, activeCryp } = state; function sendInstanceReady() { - return ws.sendInstanceReady(instance.instance); + return ws.sendInstanceReady(instance.id); } function sendVboxApply(crypId, i) { - return ws.sendVboxApply(instance.instance, crypId, i); + return ws.sendVboxApply(instance.id, crypId, i); } return { instance, account, sendInstanceReady, sendVboxApply, activeVar, activeCryp }; diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx index c3d347fd..ba0de3f4 100644 --- a/client/src/components/vbox.component.jsx +++ b/client/src/components/vbox.component.jsx @@ -21,7 +21,8 @@ function Vbox(args) { const { activeVar, activeCryp, - instance, + player, + // instance, combiner, reclaiming, sendVboxAccept, @@ -34,8 +35,8 @@ function Vbox(args) { setInfo, } = args; - const { vbox } = instance; - if (!instance.vbox) return false; + if (!player) return false; + const { vbox } = player; // // VBOX diff --git a/client/src/components/vbox.container.jsx b/client/src/components/vbox.container.jsx index ed0305cf..d2e09ce4 100644 --- a/client/src/components/vbox.container.jsx +++ b/client/src/components/vbox.container.jsx @@ -9,6 +9,7 @@ const addState = connect( const { ws, instance, + player, combiner, reclaiming, activeVar, @@ -17,23 +18,24 @@ const addState = connect( } = state; function sendVboxDiscard() { - return ws.sendVboxDiscard(instance.instance); + return ws.sendVboxDiscard(instance.id); } function sendVboxAccept(group, index) { - return ws.sendVboxAccept(instance.instance, group, index); + return ws.sendVboxAccept(instance.id, group, index); } function sendVboxCombine() { - return ws.sendVboxCombine(instance.instance, combiner); + return ws.sendVboxCombine(instance.id, combiner); } function sendVboxReclaim(i) { - return ws.sendVboxReclaim(instance.instance, i); + return ws.sendVboxReclaim(instance.id, i); } return { instance, + player, combiner, reclaiming, activeVar, diff --git a/client/src/events.jsx b/client/src/events.jsx index 4aafa033..1de7be65 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -92,7 +92,10 @@ function registerEvents(store) { return store.dispatch(actions.setInstances(v)); } - function setPlayer(v) { + function setInstance(v) { + const { account } = store.getState(); + const player = v.players.find(p => p.account === account.id); + store.dispatch(actions.setPlayer(player)); return store.dispatch(actions.setInstance(v)); } @@ -108,7 +111,7 @@ function registerEvents(store) { console.log('EVENT ->', 'crypStatusUpdate', { id, skill, target }); } - // events.on('SET_PLAYER', setPlayer); + // events.on('SET_PLAYER', setInstance); // events.on('SEND_SKILL', function skillActive(gameId, crypId, targetCrypId, skill) { // ws.sendGameSkill(gameId, crypId, targetCrypId, skill); @@ -244,7 +247,7 @@ function registerEvents(store) { setGame, clearInfo, setMenu, - setPlayer, + setInstance, setInstanceList, setVbox, setWs, diff --git a/client/src/main.jsx b/client/src/main.jsx index 3357cbda..0d20257a 100644 --- a/client/src/main.jsx +++ b/client/src/main.jsx @@ -27,6 +27,7 @@ const store = createStore( showLog: reducers.showLogReducer, info: reducers.infoReducer, instance: reducers.instanceReducer, + player: reducers.playerReducer, instances: reducers.instancesReducer, reclaiming: reducers.reclaimingReducer, selectedCryps: reducers.selectedCrypsReducer, diff --git a/client/src/reducers.jsx b/client/src/reducers.jsx index a46f052b..c40d3dff 100644 --- a/client/src/reducers.jsx +++ b/client/src/reducers.jsx @@ -70,6 +70,16 @@ function instanceReducer(state = defaultInstance, action) { } } +const defaultPlayer = null; +function playerReducer(state = defaultPlayer, action) { + switch (action.type) { + case actions.SET_PLAYER: + return action.value; + default: + return state; + } +} + const defaultSelectedCryps = [null, null, null]; function selectedCrypsReducer(state = defaultSelectedCryps, action) { switch (action.type) { @@ -161,6 +171,7 @@ module.exports = { showLogReducer, instanceReducer, instancesReducer, + playerReducer, reclaimingReducer, selectedCrypsReducer, resolutionReducer, diff --git a/client/src/socket.jsx b/client/src/socket.jsx index a09e48c9..721bc284 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -87,7 +87,7 @@ function createSocket(events) { } function sendInstanceState(instanceId) { - send({ method: 'instanceState', params: { instance_id: instanceId } }); + send({ method: 'instance_state', params: { instance_id: instanceId } }); } function sendVboxAccept(instanceId, group, index) { @@ -206,8 +206,8 @@ function createSocket(events) { } function instanceState(response) { - const [structName, player] = response; - events.setPlayer(player); + const [structName, i] = response; + events.setInstance(i); } function instanceScores(response) { @@ -234,7 +234,7 @@ function createSocket(events) { zone_create: res => console.log(res), zone_state: zoneState, zone_close: res => console.log(res), - instanceState: instanceState, + instance_state: instanceState, }; function logout() { diff --git a/server/src/instance.rs b/server/src/instance.rs index 7351965d..d1c5cdec 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -135,12 +135,18 @@ impl Instance { self.players[i].set_ready(true); - if self.all_ready() { - match self.phase { - InstancePhase::Open => self.start(), - InstancePhase::Vbox => self.games_phase_start(), - _ => panic!("unhandled ready phase"), - }; + match self.phase { + InstancePhase::Open => { + if self.can_start() { + self.start(); + } + }, + InstancePhase::Vbox => + if self.all_ready() { + self.games_phase_start(); + } + }, + _ => panic!("unhandled ready phase"), } Ok(self)