From cb1222d9cf73370c7164d4b3362a716fe623cb7d Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sat, 14 Dec 2024 13:35:09 +0100 Subject: [PATCH] =?UTF-8?q?Les=20p=C3=A9nalit=C3=A9s=20ne=20se=20suivent?= =?UTF-8?q?=20pas=20d'une=20tentative=20=C3=A0=20une=20autre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/GameProvider.tsx | 2 +- .../utils/features/challengeActions/challengeActionsSlice.ts | 3 +++ client/utils/features/game/gameSlice.ts | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client/components/GameProvider.tsx b/client/components/GameProvider.tsx index 56e3b12..376e189 100644 --- a/client/components/GameProvider.tsx +++ b/client/components/GameProvider.tsx @@ -101,7 +101,7 @@ export default function GameProvider({ children }: { children: ReactNode }) { const activeChallenge: ChallengeAction | undefined = challengeActions .find(challengeAction => challengeAction.penaltyStart && challengeAction.penaltyEnd && challengeAction.penaltyStart <= now && now <= challengeAction.penaltyEnd) - if (!activeChallenge || !game.currentRunner) + if (!activeChallenge || !game.currentRunner || game.runId !== activeChallenge.runId) updatePenalty({ penaltyStart: null, penaltyEnd: null }) else if (activeChallenge && (activeChallenge.penaltyStart !== game.penaltyStart || activeChallenge.penaltyEnd)) { updatePenalty({ penaltyStart: activeChallenge.penaltyStart, penaltyEnd: activeChallenge.penaltyEnd }) diff --git a/client/utils/features/challengeActions/challengeActionsSlice.ts b/client/utils/features/challengeActions/challengeActionsSlice.ts index de5261a..c532b1a 100644 --- a/client/utils/features/challengeActions/challengeActionsSlice.ts +++ b/client/utils/features/challengeActions/challengeActionsSlice.ts @@ -9,6 +9,7 @@ export interface ChallengeAction { end: number | null, // date penaltyStart: number | null, // date penaltyEnd: number | null, // date + runId: number, } export interface ActionsState { @@ -28,6 +29,7 @@ export interface ChallengeActionPayload { end: string | null, penaltyStart: string | null, penaltyEnd: string | null, + runId: number, } export interface ChallengeActionsPayload { @@ -51,6 +53,7 @@ export const challengeActionsSlice = createSlice({ end: dlChallenge.action.end ? new Date(dlChallenge.action.end).getTime() : null, penaltyStart: dlChallenge.action.penaltyStart ? new Date(dlChallenge.action.penaltyStart).getTime() : null, penaltyEnd: dlChallenge.action.penaltyEnd ? new Date(dlChallenge.action.penaltyEnd).getTime() : null, + runId: dlChallenge.action.runId, }) } state.challengeActions.sort((c1, c2) => c2.id - c1.id) diff --git a/client/utils/features/game/gameSlice.ts b/client/utils/features/game/gameSlice.ts index 7c6cf5c..a91b2ce 100644 --- a/client/utils/features/game/gameSlice.ts +++ b/client/utils/features/game/gameSlice.ts @@ -22,6 +22,7 @@ export interface PenaltyPayload { export interface GameState { playerId: number | null + runId: number | null gameStarted: boolean money: number currentRunner: boolean @@ -33,6 +34,7 @@ export interface GameState { const initialState: GameState = { playerId: null, + runId: null, gameStarted: false, money: 0, currentRunner: false, @@ -58,6 +60,7 @@ export const gameSlice = createSlice({ updateGameState: (state, action: PayloadAction) => { const game: GamePayload = action.payload state.gameStarted = game.started + state.runId = game.currentRunId state.currentRunner = state.playerId === game.currentRun?.runnerId if (state.currentRunner) state.chaseFreeTime = null