From 6314a6f296f4824e8dae675a63569e4697407949 Mon Sep 17 00:00:00 2001 From: Sam Maselli Date: Mon, 30 Dec 2024 13:54:30 -0500 Subject: [PATCH] fix whisper notifications with informant --- client/src/game/gameState.d.tsx | 5 +++-- client/src/game/gameState.tsx | 5 +++-- client/src/game/messageListener.tsx | 8 ++++++-- .../menu/game/gameScreenContent/PlayerListMenu.tsx | 11 ++++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/client/src/game/gameState.d.tsx b/client/src/game/gameState.d.tsx index ccfdbe8ee..ef95961ed 100644 --- a/client/src/game/gameState.d.tsx +++ b/client/src/game/gameState.d.tsx @@ -78,8 +78,7 @@ type GameState = { clientState: PlayerGameState | {type: "spectator"}, host: boolean, - missedChatMessages: boolean, - missedWhispers: PlayerIndex[] + missedChatMessages: boolean } export default GameState; @@ -105,6 +104,8 @@ export type PlayerGameState = { sendChatGroups: ChatGroup[], insiderGroups: InsiderGroup[], + + missedWhispers: PlayerIndex[] } export type PlayerIndex = number; diff --git a/client/src/game/gameState.tsx b/client/src/game/gameState.tsx index f0e60e07d..399516938 100644 --- a/client/src/game/gameState.tsx +++ b/client/src/game/gameState.tsx @@ -62,8 +62,7 @@ export function createGameState(): GameState { clientState: createPlayerGameState(), host: false, - missedChatMessages: false, - missedWhispers: [], + missedChatMessages: false } } @@ -90,6 +89,8 @@ export function createPlayerGameState(): PlayerGameState { sendChatGroups: [], insiderGroups: [], + + missedWhispers: [] } } diff --git a/client/src/game/messageListener.tsx b/client/src/game/messageListener.tsx index 0fef89ba6..30109beca 100644 --- a/client/src/game/messageListener.tsx +++ b/client/src/game/messageListener.tsx @@ -472,8 +472,12 @@ export default function messageListener(packet: ToClientPacket){ GAME_MANAGER.state.missedChatMessages = true; for(let chatMessage of packet.chatMessages){ - if(chatMessage.variant.type === "whisper"){ - GAME_MANAGER.state.missedWhispers.push(chatMessage.variant.fromPlayerIndex); + if( + chatMessage.variant.type === "whisper" && + GAME_MANAGER.state.clientState.type === "player" && + chatMessage.variant.toPlayerIndex === GAME_MANAGER.state.clientState.myIndex + ){ + GAME_MANAGER.state.clientState.missedWhispers.push(chatMessage.variant.fromPlayerIndex); } } } diff --git a/client/src/menu/game/gameScreenContent/PlayerListMenu.tsx b/client/src/menu/game/gameScreenContent/PlayerListMenu.tsx index 53ce51596..df1a6225b 100644 --- a/client/src/menu/game/gameScreenContent/PlayerListMenu.tsx +++ b/client/src/menu/game/gameScreenContent/PlayerListMenu.tsx @@ -136,12 +136,13 @@ function PlayerCard(props: Readonly<{ ["addGrave"] )! - const whisperNotification = useGameState( + const whisperNotification = usePlayerState( gameState => gameState.missedWhispers.some(player => player === props.playerIndex) && !isPlayerSelf && !whisperChatOpen, - ["addChatMessages", "whisperChatOpenOrClose"] + ["addChatMessages", "whisperChatOpenOrClose"], + false ); return <>
{ // GAME_MANAGER.prependWhisper(props.playerIndex); return true; setWhisperChatOpen(!whisperChatOpen); - if(GAME_MANAGER.state.stateType === 'game'){ - GAME_MANAGER.state.missedWhispers = - GAME_MANAGER.state.missedWhispers.filter(player => player !== props.playerIndex); + if(GAME_MANAGER.state.stateType === 'game' && GAME_MANAGER.state.clientState.type === 'player'){ + GAME_MANAGER.state.clientState.missedWhispers = + GAME_MANAGER.state.clientState.missedWhispers.filter(player => player !== props.playerIndex); } GAME_MANAGER.invokeStateListeners("whisperChatOpenOrClose"); }}