diff options
author | jbion <joffrey.bion@amadeus.com> | 2019-02-23 05:03:31 +0100 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2019-02-23 05:42:16 +0100 |
commit | 10646b1fe23b89a139e9e013ddf047b5fc11b99f (patch) | |
tree | c254c10bcb03f113236f4e2bc0b7ede70f7c081f /frontend/src/redux | |
parent | Send last card prepared event (diff) | |
download | seven-wonders-10646b1fe23b89a139e9e013ddf047b5fc11b99f.tar.gz seven-wonders-10646b1fe23b89a139e9e013ddf047b5fc11b99f.tar.bz2 seven-wonders-10646b1fe23b89a139e9e013ddf047b5fc11b99f.zip |
Improve GameScene by showing the hand
Diffstat (limited to 'frontend/src/redux')
-rw-r--r-- | frontend/src/redux/currentGame.js | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/frontend/src/redux/currentGame.js b/frontend/src/redux/currentGame.js index cefabb6f..f4174eca 100644 --- a/frontend/src/redux/currentGame.js +++ b/frontend/src/redux/currentGame.js @@ -1,32 +1,39 @@ // @flow -import type { ApiPlayerTurnInfo } from '../api/model'; +import { List } from 'immutable'; +import { combineReducers } from 'redux'; +import type { ApiPlayerTurnInfo, ApiTable } from '../api/model'; import { CurrentGameState } from '../models/currentGame'; import type { Action } from './actions/all'; import { types } from './actions/game'; -export const currentGameReducer = (state: CurrentGameState = new CurrentGameState(), action: Action) => { - switch (action.type) { - case types.REQUEST_SAY_READY: - // TODO handle end of feedback between say ready and ready event received - return state; - case types.PLAYER_READY_RECEIVED: - // const newReadiness = state.playersReadiness.set(action.username, true); - // return { playersReadiness: newReadiness, ...state }; - return state; - case types.TABLE_UPDATE_RECEIVED: - // TODO - return state; - case types.PREPARED_CARD_RECEIVED: - // TODO - return state; - case types.TURN_INFO_RECEIVED: - // TODO find a better way to just update what's needed - const newState = new CurrentGameState(); - newState.turnInfo = action.turnInfo; - newState.playersReadiness = state.playersReadiness; - return newState; - default: - return state; +export function createCurrentGameReducer() { + return combineReducers({ + readyUsernames: readyUsernamesReducer, + turnInfo: turnInfoReducer, + }); +} + +const readyUsernamesReducer = (state: List<string> = new List(), action: Action) => { + if (action.type === types.PLAYER_READY_RECEIVED) { + return state.push(action.username); + } else { + return state; + } +}; + +const turnInfoReducer = (state: ApiPlayerTurnInfo | null = null, action: Action) => { + if (action.type === types.TURN_INFO_RECEIVED) { + return action.turnInfo; + } else { + return state; + } +}; + +const tableUpdatesReducer = (state: ApiTable, action: Action) => { + if (action.type === types.TABLE_UPDATE_RECEIVED) { + return action.table; + } else { + return state; } }; |