Skip to content

Commit

Permalink
fix whisper notifications with informant
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSammyM committed Dec 30, 2024
1 parent 45054b6 commit 6314a6f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions client/src/game/gameState.d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ type GameState = {
clientState: PlayerGameState | {type: "spectator"},
host: boolean,

missedChatMessages: boolean,
missedWhispers: PlayerIndex[]
missedChatMessages: boolean
}
export default GameState;

Expand All @@ -105,6 +104,8 @@ export type PlayerGameState = {

sendChatGroups: ChatGroup[],
insiderGroups: InsiderGroup[],

missedWhispers: PlayerIndex[]
}

export type PlayerIndex = number;
Expand Down
5 changes: 3 additions & 2 deletions client/src/game/gameState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export function createGameState(): GameState {
clientState: createPlayerGameState(),
host: false,

missedChatMessages: false,
missedWhispers: [],
missedChatMessages: false
}
}

Expand All @@ -90,6 +89,8 @@ export function createPlayerGameState(): PlayerGameState {

sendChatGroups: [],
insiderGroups: [],

missedWhispers: []
}
}

Expand Down
8 changes: 6 additions & 2 deletions client/src/game/messageListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions client/src/menu/game/gameScreenContent/PlayerListMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <><div
Expand Down Expand Up @@ -182,9 +183,9 @@ function PlayerCard(props: Readonly<{
onClick={()=>{
// 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");
}}
Expand Down

0 comments on commit 6314a6f

Please sign in to comment.