39 lines
859 B
TypeScript
39 lines
859 B
TypeScript
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
|
|
|
export interface GameState {
|
|
playerId: number | null
|
|
gameStarted: boolean
|
|
money: number
|
|
currentRunner: boolean
|
|
chaseFreeTime: Date | null
|
|
penaltyStart: Date | null
|
|
penaltyEnd: Date | null
|
|
}
|
|
|
|
const initialState: GameState = {
|
|
playerId: null,
|
|
gameStarted: false,
|
|
money: 0,
|
|
currentRunner: false,
|
|
chaseFreeTime: null,
|
|
penaltyStart: null,
|
|
penaltyEnd: null,
|
|
}
|
|
|
|
export const gameSlice = createSlice({
|
|
name: 'game',
|
|
initialState: initialState,
|
|
reducers: {
|
|
setPlayerId: (state, action: PayloadAction<number>) => {
|
|
state.playerId = action.payload
|
|
},
|
|
updateMoney: (state, action: PayloadAction<number>) => {
|
|
state.money = action.payload
|
|
},
|
|
},
|
|
})
|
|
|
|
export const { setPlayerId, updateMoney } = gameSlice.actions
|
|
|
|
export default gameSlice.reducer
|