animate all turns that have happened since last game state

This commit is contained in:
ntr 2020-01-13 16:58:40 +10:00
parent 71b7f0b2b4
commit 5940be499e

View File

@ -77,21 +77,24 @@ function registerEvents(store) {
if (game && currentGame) { if (game && currentGame) {
if (game.resolutions.length !== currentGame.resolutions.length) { if (game.resolutions.length !== currentGame.resolutions.length) {
// stop fetching the game state til animations are done
store.dispatch(actions.setAnimating(true)); store.dispatch(actions.setAnimating(true));
store.dispatch(actions.setGameSkillInfo(null)); store.dispatch(actions.setGameSkillInfo(null));
// stop fetching the game state til animations are done
const newRes = game.resolutions[game.resolutions.length - 1]; const newTurns = game.resolutions.slice(currentGame.resolutions.length);
return eachSeries(newRes, (r, cb) => { return eachSeries(newTurns, (turn, turnCb) => {
return eachSeries(turn, (r, cb) => {
if (r.delay === 0) return cb(); // TargetKo etc if (r.delay === 0) return cb(); // TargetKo etc
setAnimations(r, store); setAnimations(r, store);
return setTimeout(cb, r.delay); return setTimeout(cb, r.delay);
}, turnCb);
}, err => { }, err => {
if (err) return console.error(err); if (err) return console.error(err);
clearAnimations(store); clearAnimations(store);
// set the game state so resolutions don't fire twice // set the game state so resolutions don't fire twice
store.dispatch(actions.setGame(game)); store.dispatch(actions.setGame(game));
ws.sendGameState(game.id); ws.sendGameState(game.id);
return true; return false;
}); });
} }
} }