import { takeLatest , put , select , all } from "redux-saga/effects" ; import { GamePhase } from "@creature-chess/models" ; import { GameEvents } from "@creature-chess/gamemode" ; import { clearSelectedPiece , openOverlay , closeOverlay , Overlay } from "../ui" ; import { AppState } from "../../store" ; import { PlayerListCommands } from "../module/playerList" ; export const uiSaga = function * ( ) { yield all ( [ takeLatest < GameEvents . GamePhaseStartedEvent > ( GameEvents . gamePhaseStartedEvent . toString ( ) , function * ( { payload : { phase } } ) { switch ( phase ) { case GamePhase . PREPARING : { const isDead = yield select ( ( state ) => state . game . playerInfo . health === 0 ) ; if ( ! isDead ) { yield put ( openOverlay ( Overlay . SHOP ) ) ; return ; } } case GamePhase . READY : { yield put ( closeOverlay ( ) ) ; yield put ( clearSelectedPiece ( ) ) ; return ; } default : return ; } } ) , takeLatest < GameEvents . PlayerListChangedEvent > ( GameEvents . playerListChangedEvent . toString ( ) , function * ( { payload : { players } } ) { yield put ( PlayerListCommands . updatePlayerListCommand ( players ) ) ; } ) ] ) ; } ;