From c0303c5b61b579745b32471b269d0b6a93a97326 Mon Sep 17 00:00:00 2001 From: ntr Date: Thu, 11 Apr 2019 11:51:22 +1000 Subject: [PATCH] resolutions tick --- client/package.json | 1 + client/src/actions.jsx | 3 +++ client/src/components/game.component.jsx | 9 ++++++++- client/src/components/game.container.jsx | 2 ++ client/src/events.jsx | 21 +++++++++++++++++++-- client/src/main.jsx | 1 + client/src/reducers.jsx | 11 +++++++++++ server/WORKLOG.md | 2 ++ 8 files changed, 47 insertions(+), 3 deletions(-) diff --git a/client/package.json b/client/package.json index e5212454..623ba16b 100644 --- a/client/package.json +++ b/client/package.json @@ -12,6 +12,7 @@ "author": "", "license": "UNLICENSED", "dependencies": { + "async": "^2.6.2", "borc": "^2.0.3", "bulma-toast": "^1.2.0", "docco": "^0.7.0", diff --git a/client/src/actions.jsx b/client/src/actions.jsx index 5c2e6ff5..e0910258 100644 --- a/client/src/actions.jsx +++ b/client/src/actions.jsx @@ -13,6 +13,9 @@ export const setInstance = value => ({ type: SET_INSTANCE, value }); export const SET_GAME = 'SET_GAME'; export const setGame = value => ({ type: SET_GAME, value }); +export const SET_RESOLUTION = 'SET_RESOLUTION'; +export const setResolution = value => ({ type: SET_RESOLUTION, value }); + export const SET_SHOW_LOG = 'SET_SHOW_LOG'; export const setShowLog = value => ({ type: SET_SHOW_LOG, value }); diff --git a/client/src/components/game.component.jsx b/client/src/components/game.component.jsx index e1115ee6..c03bf782 100644 --- a/client/src/components/game.component.jsx +++ b/client/src/components/game.component.jsx @@ -10,6 +10,7 @@ const { STATS } = require('../utils'); function GamePanel(props) { const { game, + resolution, activeSkill, setActiveSkill, setActiveCryp, @@ -228,7 +229,13 @@ function GamePanel(props) { ); } - const selectedSkills = playerTeam.cryps.map((c, i) => stackElement(c, i)); + function resolutionEl(r) { + return
{JSON.stringify(resolution)}
; + } + + const selectedSkills = resolution + ? resolutionEl(resolution) + : playerTeam.cryps.map((c, i) => stackElement(c, i)); const mobileSkills = activeCryp ? range(0, 3).map(i => Skill(activeCryp, i, true)) diff --git a/client/src/components/game.container.jsx b/client/src/components/game.container.jsx index d436803e..395d3db5 100644 --- a/client/src/components/game.container.jsx +++ b/client/src/components/game.container.jsx @@ -15,6 +15,7 @@ const addState = connect( ws, game, account, + resolution, showLog, activeSkill, activeCryp, @@ -36,6 +37,7 @@ const addState = connect( game, showLog, account, + resolution, activeSkill, activeCryp, selectSkillTarget, diff --git a/client/src/events.jsx b/client/src/events.jsx index 25c6128b..cd846bd7 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -1,4 +1,5 @@ const toast = require('izitoast'); +const eachSeries = require('async/eachSeries'); const actions = require('./actions'); @@ -12,11 +13,27 @@ function registerEvents(store) { } function setWs(ws) { - console.log('EVENT ->', 'ws', ws); + store.dispatch(actions.setWs(ws)); } function setGame(game) { - store.dispatch(actions.setGame(game)); + const { game: currentGame } = store.getState(); + if (game && currentGame) { + if (game.resolved.length !== currentGame.resolved.length) { + const newRes = game.resolved.slice(currentGame.resolved.length); + return eachSeries(newRes, (r, cb) => { + store.dispatch(actions.setResolution(r)); + return setTimeout(cb, 500); + }, err => { + if (err) return console.error(err); + store.dispatch(actions.setResolution(null)); + store.dispatch(actions.setGame(game)); + return true; + }); + } + } + + return store.dispatch(actions.setGame(game)); // return console.log('EVENT ->', 'game', game); } diff --git a/client/src/main.jsx b/client/src/main.jsx index a1c6d984..3357cbda 100644 --- a/client/src/main.jsx +++ b/client/src/main.jsx @@ -23,6 +23,7 @@ const store = createStore( combiner: reducers.combinerReducer, cryps: reducers.crypsReducer, game: reducers.gameReducer, + resolution: reducers.resolutionReducer, showLog: reducers.showLogReducer, info: reducers.infoReducer, instance: reducers.instanceReducer, diff --git a/client/src/reducers.jsx b/client/src/reducers.jsx index 2734e4af..a46f052b 100644 --- a/client/src/reducers.jsx +++ b/client/src/reducers.jsx @@ -100,6 +100,16 @@ function gameReducer(state = defaultGame, action) { } } +const defaultResolution = null; +function resolutionReducer(state = defaultResolution, action) { + switch (action.type) { + case actions.SET_RESOLUTION: + return action.value; + default: + return state; + } +} + const defaultShowLog = false; function showLogReducer(state = defaultShowLog, action) { switch (action.type) { @@ -153,6 +163,7 @@ module.exports = { instancesReducer, reclaimingReducer, selectedCrypsReducer, + resolutionReducer, wsReducer, infoReducer, }; diff --git a/server/WORKLOG.md b/server/WORKLOG.md index 61b88c30..cb1d1d65 100644 --- a/server/WORKLOG.md +++ b/server/WORKLOG.md @@ -39,6 +39,8 @@ var / skill info rpc siphon might have a prob put ticks on stack at start of phase +push events + make strike *really* hit first / resolve at same time? ## SOON