Implemented isReady & isConnected
This commit is contained in:
parent
4fa3b9ae64
commit
df315df8f4
13 changed files with 347 additions and 80 deletions
|
@ -2,6 +2,7 @@ import { GameSettings } from "@components/Lobby/SettingsFrame/Setting"
|
|||
import { getPayloadwithChecksum } from "@lib/getPayloadwithChecksum"
|
||||
import { socket } from "@lib/socket"
|
||||
import { GamePropsSchema, PlayerSchema } from "@lib/zodSchemas"
|
||||
import { PlayerN } from "@prisma/client"
|
||||
import { produce } from "immer"
|
||||
import { toast } from "react-toastify"
|
||||
import { create } from "zustand"
|
||||
|
@ -21,6 +22,7 @@ export type Action = {
|
|||
}) => string | null
|
||||
full: (newProps: GamePropsSchema) => void
|
||||
leave: (cb: () => void) => void
|
||||
setIsReady: (payload: { index: PlayerN; isReady: boolean }) => void
|
||||
reset: () => void
|
||||
}
|
||||
|
||||
|
@ -104,6 +106,16 @@ export const useGameProps = create<State & Action>()(
|
|||
cb()
|
||||
})
|
||||
},
|
||||
setIsReady: ({ index, isReady }) =>
|
||||
set(
|
||||
produce((state: State) => {
|
||||
if (!state.payload) return
|
||||
const player = state.payload[index]
|
||||
if (!player) return
|
||||
player.isReady = isReady
|
||||
state.payload[index] = player
|
||||
})
|
||||
),
|
||||
reset: () => {
|
||||
set(initialState)
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue