implemented usePreviousPlayer, preparing to implement gold chip funcitonality
This commit is contained in:
19
src/hooks/useCurrentPlayer.tsx
Normal file
19
src/hooks/useCurrentPlayer.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { AppState, PlayerData } from "../util/types";
|
||||
|
||||
export const useCurrentPlayer = (state: AppState): PlayerData | null => {
|
||||
/**
|
||||
* takes in current app state and the current active player
|
||||
* @param state = current app state
|
||||
* @returns: @PlayerData if a matching player is found,
|
||||
* or @null if one is not found
|
||||
*/
|
||||
|
||||
const currentPlayers = state.players;
|
||||
if (!currentPlayers) return null;
|
||||
|
||||
for (let each of currentPlayers) {
|
||||
if (each.turnActive) return each;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user