Implemented isReady & isConnected

This commit is contained in:
aronmal 2023-05-29 19:48:51 +02:00
parent 4fa3b9ae64
commit df315df8f4
Signed by: aronmal
GPG key ID: 816B7707426FC612
13 changed files with 347 additions and 80 deletions

View file

@ -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)
},