Skip to content

Commit

Permalink
Merge branch 'main' into bug/fix-santa
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSammyM authored Jan 2, 2025
2 parents b2efcaf + a1e0003 commit dcbdc25
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function Counter(props: Readonly<{
}>): ReactElement {
const circles = [];

for (let i = 0; i < props.max; i++) {
for (let i = 0; i < Math.max(props.max, props.current); i++) {
const filled = i < props.current ? "filled" : "empty";

circles.push(<div key={filled + i} className={`counter-circle counter-circle-${filled}`} />)
Expand Down
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
32 changes: 22 additions & 10 deletions client/src/menu/game/gameScreenContent/AbilityMenu/RoleSpecific.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ export default function RoleSpecificSection(): ReactElement{
gameState => gameState.dayNumber,
["phase"]
)!;
const numPlayers = useGameState(
gameState => gameState.players.length,
["gamePlayers"]
)!;

const inner = roleSpecificSectionInner(phaseState, dayNumber, roleState);
const inner = roleSpecificSectionInner(phaseState, dayNumber, roleState, numPlayers);

return <>{inner===null ? null :
<DetailsSummary
Expand All @@ -42,11 +46,18 @@ export default function RoleSpecificSection(): ReactElement{
}</>;
}

function abilityChargesCounter(numPlayers: number): number{
return Math.ceil(numPlayers/5);
}

function roleSpecificSectionInner(
phaseState: PhaseState,
dayNumber: number,
roleState: RoleState
roleState: RoleState,
numPlayers: number
): ReactElement | null{
let chargesCounter = abilityChargesCounter(numPlayers);

switch(roleState.type){
case "auditor":
return <AuditorMenu roleState={roleState}/>;
Expand All @@ -56,7 +67,7 @@ function roleSpecificSectionInner(
return <LargeDoomsayerMenu/>;
case "jailor":
return <Counter
max={3}
max={chargesCounter}
current={roleState.executionsRemaining}
>
<StyledText>{translate("role.jailor.roleDataText.executionsRemaining", roleState.executionsRemaining)}</StyledText>
Expand Down Expand Up @@ -101,7 +112,7 @@ function roleSpecificSectionInner(
</div>
case "loaded":
return <Counter
max={3}
max={chargesCounter}
current={roleState.state.bullets}
>
<StyledText>{translate("role.vigilante.roleDataText", roleState.state.bullets)}</StyledText>
Expand All @@ -111,14 +122,14 @@ function roleSpecificSectionInner(
}
case "veteran":
return <Counter
max={3}
max={chargesCounter}
current={roleState.alertsRemaining}
>
<StyledText>{translate("role.veteran.roleDataText", roleState.alertsRemaining)}</StyledText>
</Counter>
case "armorsmith":
return <Counter
max={3}
max={chargesCounter}
current={roleState.openShopsRemaining}
>
<StyledText>{translate("role.armorsmith.roleDataText", roleState.openShopsRemaining)}</StyledText>
Expand All @@ -128,14 +139,14 @@ function roleSpecificSectionInner(
case "counterfeiter":
case "forger":
return <Counter
max={3}
max={chargesCounter}
current={roleState.forgesRemaining}
>
<StyledText>{translate("role.forger.roleDataText", roleState.forgesRemaining)}</StyledText>
</Counter>
case "mortician":
return <Counter
max={3}
max={chargesCounter}
current={roleState.cremationsRemaining}
>
<StyledText>{translate("role.mortician.roleDataText", roleState.cremationsRemaining)}</StyledText>
Expand All @@ -147,7 +158,8 @@ function roleSpecificSectionInner(
case "spiral":
return <SpiralMenu />;
case "puppeteer":
return <SmallPuppeteerMenu
return <SmallPuppeteerMenu
maxCharges={chargesCounter}
marionettesRemaining={roleState.marionettesRemaining}
phase={phaseState.type}
/>;
Expand All @@ -164,7 +176,7 @@ function roleSpecificSectionInner(
<StyledText>{translate("role.martyr.roleDataText.eccentric")}</StyledText>
</div>
<Counter
max={2}
max={chargesCounter}
current={roleState.state.bullets}
>
<StyledText>{translate("role.martyr.roleDataText", roleState.state.bullets)}</StyledText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import StyledText from "../../../../../components/StyledText";
import translate from "../../../../../game/lang";
import { PhaseType } from "../../../../../game/gameState.d";

export default function SmallPuppeteerMenu(props: {marionettesRemaining: number, phase: PhaseType}): ReactElement {
export default function SmallPuppeteerMenu(props: Readonly<{marionettesRemaining: number, maxCharges: number, phase: PhaseType}>): ReactElement {
return <>
<Counter
max={3}
max={props.maxCharges}
current={props.marionettesRemaining}
>
<StyledText>{translate("role.puppeteer.smallRoleMenu.marionettesRemaining", props.marionettesRemaining)}</StyledText>
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 dcbdc25

Please sign in to comment.