timeout events
This commit is contained in:
parent
92007a8c37
commit
49a9db6d9b
@ -10,19 +10,6 @@ const InstanceContainer = require('./instance.container');
|
||||
const addState = connect(
|
||||
state => {
|
||||
const { game, instance, ws, account } = state;
|
||||
|
||||
if (!game) {
|
||||
ws.clearGameStateTimeout();
|
||||
} else {
|
||||
ws.startGameStateTimeout(game.id);
|
||||
}
|
||||
|
||||
if (!instance) {
|
||||
ws.clearInstanceStateTimeout();
|
||||
} else {
|
||||
ws.startInstanceStateTimeout(instance.id);
|
||||
}
|
||||
|
||||
return { game, instance, account };
|
||||
}
|
||||
);
|
||||
|
||||
@ -6,6 +6,15 @@ const { TIMES } = require('./constants');
|
||||
const { getCombatSequence } = require('./utils');
|
||||
|
||||
function registerEvents(store) {
|
||||
|
||||
// timeout handlers
|
||||
store.subscribe(() => {
|
||||
const { game, instance, ws} = store.getState();
|
||||
|
||||
if (!game) ws.clearGameStateTimeout();
|
||||
if (!instance) ws.clearInstanceStateTimeout();
|
||||
});
|
||||
|
||||
function setCryps(cryps) {
|
||||
console.log('EVENT ->', 'cryps', cryps);
|
||||
}
|
||||
@ -21,8 +30,7 @@ function registerEvents(store) {
|
||||
function setGame(game) {
|
||||
const { game: currentGame, ws } = store.getState();
|
||||
|
||||
if (!game) ws.clearGameStateTimeout();
|
||||
|
||||
if (game) ws.startGameStateTimeout(game.id);
|
||||
if (game && currentGame) {
|
||||
if (game.resolved.length !== currentGame.resolved.length) {
|
||||
// stop fetching the game state til animations are done
|
||||
@ -99,10 +107,8 @@ function registerEvents(store) {
|
||||
const { account, ws } = store.getState();
|
||||
const player = v.players.find(p => p.id === account.id);
|
||||
if (player) store.dispatch(actions.setPlayer(player));
|
||||
if (v) ws.startInstanceStateTimeout(v.id);
|
||||
|
||||
if (!v) {
|
||||
ws.clearInstanceStateTimeout();
|
||||
}
|
||||
return store.dispatch(actions.setInstance(v));
|
||||
}
|
||||
|
||||
|
||||
@ -218,19 +218,14 @@ function createSocket(events) {
|
||||
|
||||
function instanceState(response) {
|
||||
const [structName, i] = response;
|
||||
clearTimeout(instanceStateTimeout);
|
||||
instanceStateTimeout = setTimeout(() => sendInstanceState(i.id), 1000);
|
||||
console.log(instanceStateTimeout);
|
||||
events.setInstance(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
function clearInstanceStateTimeout() {
|
||||
console.log('instance state timeout cleared');
|
||||
clearTimeout(instanceStateTimeout);
|
||||
}
|
||||
|
||||
|
||||
function instanceScores(response) {
|
||||
const [structName, scores] = response;
|
||||
events.setScores(scores);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user