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 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 });

View File

@ -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 <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,
}));
@ -134,7 +136,7 @@ function InstanceComponent(args) {
}
function showTeam(e) {
setActiveCryp(instance.cryps[0]);
setActiveCryp(player.cryps[0]);
e.stopPropagation();
}

View File

@ -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 };

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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,

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

View File

@ -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() {

View File

@ -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)