This commit is contained in:
ntr 2019-04-17 12:32:58 +10:00
parent 9217cf2a91
commit 1874db2902
4 changed files with 22 additions and 3 deletions

View File

@ -12,8 +12,7 @@ const addState = connect(
const { game, instance, ws, account } = state;
if (!game) {
console.log('clear gs interval');
// ws.clearGameStateInterval();
ws.clearGameStateTimeout();
}
return { game, instance, account };

View File

@ -18,9 +18,11 @@ function registerEvents(store) {
}
function setGame(game) {
const { game: currentGame } = store.getState();
const { game: currentGame, ws } = store.getState();
if (game && currentGame) {
if (game.resolved.length !== currentGame.resolved.length) {
// stop fetching the game state til animations are done
ws.clearGameStateTimeout();
const newRes = game.resolved.slice(currentGame.resolved.length);
return eachSeries(newRes, (r, cb) => {
if (['Disable', 'TargetKo'].includes(r.event[0])) return cb();
@ -29,7 +31,10 @@ function registerEvents(store) {
}, err => {
if (err) return console.error(err);
store.dispatch(actions.setResolution(null));
// update the game
store.dispatch(actions.setGame(game));
// get the latest state and restart polling
ws.sendGameState(currentGame.id);
return true;
});
}

View File

@ -174,11 +174,18 @@ function createSocket(events) {
events.setCrypList(cryps);
}
let gameStateTimeout;
function gameState(response) {
const [structName, game] = response;
clearInterval(gameStateTimeout);
gameStateTimeout = setTimeout(() => sendGameState(game.id), 1000);
events.setGame(game);
}
function clearGameStateTimeout() {
clearTimeout(gameStateTimeout);
}
function crypSpawn(response) {
const [structName, cryp] = response;
}
@ -289,6 +296,7 @@ function createSocket(events) {
}
return {
clearGameStateTimeout,
sendAccountLogin,
sendAccountCreate,
sendAccountDemo,

View File

@ -25,6 +25,13 @@
* resolve animations + effects
*SERVER*
authentication endpoint
hit /auth with un/pw or token
invalidate previous token
generate new token and return
attach token to websocket
ez
consolidate buffs debuffs and disables
no more red/blue