lobby list

This commit is contained in:
ntr 2019-04-25 14:43:29 +10:00
parent fcb224f341
commit eb2089cc17
10 changed files with 54 additions and 25 deletions

View File

@ -10,6 +10,9 @@ export const setInstances = value => ({ type: SET_INSTANCES, value });
export const SET_INSTANCE = 'SET_INSTANCE'; export const SET_INSTANCE = 'SET_INSTANCE';
export const setInstance = value => ({ type: SET_INSTANCE, value }); 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 SET_GAME = 'SET_GAME';
export const setGame = value => ({ type: SET_GAME, value }); export const setGame = value => ({ type: SET_GAME, value });

View File

@ -108,7 +108,7 @@ function Cryp(props) {
function InstanceComponent(args) { function InstanceComponent(args) {
const { const {
// account, account,
instance, instance,
quit, quit,
// clearInfo, // clearInfo,
@ -123,7 +123,9 @@ function InstanceComponent(args) {
if (!instance) return <div>...</div>; if (!instance) return <div>...</div>;
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, cryp: c, sendVboxApply, setInfo, activeVar, setActiveCryp,
})); }));
@ -134,7 +136,7 @@ function InstanceComponent(args) {
} }
function showTeam(e) { function showTeam(e) {
setActiveCryp(instance.cryps[0]); setActiveCryp(player.cryps[0]);
e.stopPropagation(); e.stopPropagation();
} }

View File

@ -9,11 +9,11 @@ const addState = connect(
const { ws, instance, account, activeVar, activeCryp } = state; const { ws, instance, account, activeVar, activeCryp } = state;
function sendInstanceReady() { function sendInstanceReady() {
return ws.sendInstanceReady(instance.instance); return ws.sendInstanceReady(instance.id);
} }
function sendVboxApply(crypId, i) { 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 }; return { instance, account, sendInstanceReady, sendVboxApply, activeVar, activeCryp };

View File

@ -21,7 +21,8 @@ function Vbox(args) {
const { const {
activeVar, activeVar,
activeCryp, activeCryp,
instance, player,
// instance,
combiner, combiner,
reclaiming, reclaiming,
sendVboxAccept, sendVboxAccept,
@ -34,8 +35,8 @@ function Vbox(args) {
setInfo, setInfo,
} = args; } = args;
const { vbox } = instance; if (!player) return false;
if (!instance.vbox) return false; const { vbox } = player;
// //
// VBOX // VBOX

View File

@ -9,6 +9,7 @@ const addState = connect(
const { const {
ws, ws,
instance, instance,
player,
combiner, combiner,
reclaiming, reclaiming,
activeVar, activeVar,
@ -17,23 +18,24 @@ const addState = connect(
} = state; } = state;
function sendVboxDiscard() { function sendVboxDiscard() {
return ws.sendVboxDiscard(instance.instance); return ws.sendVboxDiscard(instance.id);
} }
function sendVboxAccept(group, index) { function sendVboxAccept(group, index) {
return ws.sendVboxAccept(instance.instance, group, index); return ws.sendVboxAccept(instance.id, group, index);
} }
function sendVboxCombine() { function sendVboxCombine() {
return ws.sendVboxCombine(instance.instance, combiner); return ws.sendVboxCombine(instance.id, combiner);
} }
function sendVboxReclaim(i) { function sendVboxReclaim(i) {
return ws.sendVboxReclaim(instance.instance, i); return ws.sendVboxReclaim(instance.id, i);
} }
return { return {
instance, instance,
player,
combiner, combiner,
reclaiming, reclaiming,
activeVar, activeVar,

View File

@ -92,7 +92,10 @@ function registerEvents(store) {
return store.dispatch(actions.setInstances(v)); 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)); return store.dispatch(actions.setInstance(v));
} }
@ -108,7 +111,7 @@ function registerEvents(store) {
console.log('EVENT ->', 'crypStatusUpdate', { id, skill, target }); 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) { // events.on('SEND_SKILL', function skillActive(gameId, crypId, targetCrypId, skill) {
// ws.sendGameSkill(gameId, crypId, targetCrypId, skill); // ws.sendGameSkill(gameId, crypId, targetCrypId, skill);
@ -244,7 +247,7 @@ function registerEvents(store) {
setGame, setGame,
clearInfo, clearInfo,
setMenu, setMenu,
setPlayer, setInstance,
setInstanceList, setInstanceList,
setVbox, setVbox,
setWs, setWs,

View File

@ -27,6 +27,7 @@ const store = createStore(
showLog: reducers.showLogReducer, showLog: reducers.showLogReducer,
info: reducers.infoReducer, info: reducers.infoReducer,
instance: reducers.instanceReducer, instance: reducers.instanceReducer,
player: reducers.playerReducer,
instances: reducers.instancesReducer, instances: reducers.instancesReducer,
reclaiming: reducers.reclaimingReducer, reclaiming: reducers.reclaimingReducer,
selectedCryps: reducers.selectedCrypsReducer, selectedCryps: reducers.selectedCrypsReducer,

View File

@ -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]; const defaultSelectedCryps = [null, null, null];
function selectedCrypsReducer(state = defaultSelectedCryps, action) { function selectedCrypsReducer(state = defaultSelectedCryps, action) {
switch (action.type) { switch (action.type) {
@ -161,6 +171,7 @@ module.exports = {
showLogReducer, showLogReducer,
instanceReducer, instanceReducer,
instancesReducer, instancesReducer,
playerReducer,
reclaimingReducer, reclaimingReducer,
selectedCrypsReducer, selectedCrypsReducer,
resolutionReducer, resolutionReducer,

View File

@ -87,7 +87,7 @@ function createSocket(events) {
} }
function sendInstanceState(instanceId) { function sendInstanceState(instanceId) {
send({ method: 'instanceState', params: { instance_id: instanceId } }); send({ method: 'instance_state', params: { instance_id: instanceId } });
} }
function sendVboxAccept(instanceId, group, index) { function sendVboxAccept(instanceId, group, index) {
@ -206,8 +206,8 @@ function createSocket(events) {
} }
function instanceState(response) { function instanceState(response) {
const [structName, player] = response; const [structName, i] = response;
events.setPlayer(player); events.setInstance(i);
} }
function instanceScores(response) { function instanceScores(response) {
@ -234,7 +234,7 @@ function createSocket(events) {
zone_create: res => console.log(res), zone_create: res => console.log(res),
zone_state: zoneState, zone_state: zoneState,
zone_close: res => console.log(res), zone_close: res => console.log(res),
instanceState: instanceState, instance_state: instanceState,
}; };
function logout() { function logout() {

View File

@ -135,12 +135,18 @@ impl Instance {
self.players[i].set_ready(true); self.players[i].set_ready(true);
if self.all_ready() { match self.phase {
match self.phase { InstancePhase::Open => {
InstancePhase::Open => self.start(), if self.can_start() {
InstancePhase::Vbox => self.games_phase_start(), self.start();
_ => panic!("unhandled ready phase"), }
}; },
InstancePhase::Vbox =>
if self.all_ready() {
self.games_phase_start();
}
},
_ => panic!("unhandled ready phase"),
} }
Ok(self) Ok(self)