Skip to content

Commit

Permalink
Merge branch 'main' into feature/enhanced-role-list
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSammyM committed Jan 11, 2025
2 parents 1cede06 + 3dccd12 commit c77a7a0
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 12 deletions.
3 changes: 2 additions & 1 deletion client/src/components/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export function translateChatMessage(
);
}
case "playerQuit":
return translate("chatMessage.playerQuit",
return translate(`chatMessage.playerQuit${message.gameOver ? ".gameOver" : ""}`,
playerNames[message.playerIndex]
);
case "youDied":
Expand Down Expand Up @@ -834,6 +834,7 @@ export type ChatMessageVariant = {
} | {
type: "playerQuit",
playerIndex: PlayerIndex
gameOver: boolean,
} | {
type: "phaseChange",
phase: PhaseState,
Expand Down
46 changes: 46 additions & 0 deletions client/src/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,52 @@ export function dropdownPlacementFunction(dropdownElement: HTMLElement, buttonEl
dropdownElement.style.top = `${spaceAbove + buttonBounds.height + .25 * oneRem}px`;
dropdownElement.style.bottom = `unset`;
}

keepPopoverOnScreen(dropdownElement, buttonElement);
}

function keepPopoverOnScreen(dropdownElement: HTMLElement, buttonElement?: HTMLElement) {
const dropdownBounds = dropdownElement.getBoundingClientRect();

const modifyTop = dropdownElement.style.bottom === 'unset' || dropdownElement.style.bottom === "";
const modifyLeft = dropdownElement.style.right === 'unset' || dropdownElement.style.right === "";

const spaceAbove = dropdownBounds.top;
const spaceBelow = window.innerHeight - dropdownBounds.bottom;
const spaceToTheRight = window.innerWidth - dropdownBounds.right;
const spaceToTheLeft = dropdownBounds.left;

if (spaceToTheRight < 0) {
if (modifyLeft) {
dropdownElement.style.left = `${window.innerWidth - dropdownBounds.width}px`
} else {
dropdownElement.style.right = "0px"
}
}

if (spaceToTheLeft < 0) {
if (modifyLeft) {
dropdownElement.style.left = "0px"
} else {
dropdownElement.style.right = `${dropdownBounds.width}px`
}
}

if (spaceBelow < 0) {
if (modifyTop) {
dropdownElement.style.top = `${window.innerHeight - dropdownBounds.height}px`
} else {
dropdownElement.style.bottom = "0px"
}
}

if (spaceAbove < 0) {
if (modifyTop) {
dropdownElement.style.top = "0px"
} else {
dropdownElement.style.bottom = `${dropdownBounds.height}px`
}
}
}

function SelectOptions<K extends { toString(): string}>(props: Readonly<{
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/gameModeSettings/GameModeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function GameModeSelectorPanel(props: {

useEffect(() => {
const listener = (e: KeyboardEvent) => {
if (e.ctrlKey && e.key === 's') {
if (props.canModifySavedGameModes === true && e.ctrlKey && e.key === 's') {
e.preventDefault();

const result = saveGameMode(gameModeNameField);
Expand All @@ -112,7 +112,7 @@ function GameModeSelectorPanel(props: {
}
document.addEventListener('keydown', listener);
return () => document.removeEventListener('keydown', listener);
}, [gameModeNameField, anchorController, saveGameMode]);
}, [gameModeNameField, anchorController, saveGameMode, props.canModifySavedGameModes]);

// Caller must ensure location is valid
const loadGameMode = (location: GameModeLocation) => {
Expand Down
4 changes: 3 additions & 1 deletion client/src/game/gameState.d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ export type PlayerClientType = {
}

type GameState = {
stateType: "game"
stateType: "game",
roomCode: number,
lobbyName: string,

initialized: boolean,

myId: number | null,

Expand Down
2 changes: 2 additions & 0 deletions client/src/game/gameState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export function createGameState(): GameState {
roomCode: 0,
lobbyName: "",

initialized: false,

myId: null,

chatMessages : [],
Expand Down
11 changes: 7 additions & 4 deletions client/src/game/messageListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export default function messageListener(packet: ToClientPacket){
case "gameInitializationComplete":
if (GAME_MANAGER.state.stateType === "game") {
const isSpectator = GAME_MANAGER.state.clientState.type === "spectator";
GAME_MANAGER.state.initialized = true;
if(isSpectator){
ANCHOR_CONTROLLER?.setContent(<SpectatorGameScreen/>);
}else{
Expand Down Expand Up @@ -484,10 +485,12 @@ export default function messageListener(packet: ToClientPacket){
}
}

for(let chatMessage of packet.chatMessages){
let audioSrc = chatMessageToAudio(chatMessage);
if(audioSrc)
AudioController.queueFile(audioSrc);
if (GAME_MANAGER.state.stateType !== "game" || GAME_MANAGER.state.initialized === true) {
for(let chatMessage of packet.chatMessages){
let audioSrc = chatMessageToAudio(chatMessage);
if(audioSrc)
AudioController.queueFile(audioSrc);
}
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion client/src/menu/game/gameScreenContent/ChatMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function ChatTextInput(props: Readonly<{
const playerStrings = useLobbyOrGameState(
state => {
if (state.stateType === "game") {
return state.players.map(player => player.name)
return state.players.map(player => player.toString())
} else if (state.stateType === "lobby") {
return Array.from(state.players.values())
.filter(player => player.clientType.type === "player")
Expand Down
3 changes: 2 additions & 1 deletion client/src/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,8 @@
"chatMessage.gameOver.player.crumb": "\\0 \\1",
"chatMessage.playerWon":"\\0 won! They were the \\1.",
"chatMessage.playerLost":"\\0 lost! They were the \\1.",
"chatMessage.playerQuit": "\\0 has quit the game and will certainly die at the end of the next night.",
"chatMessage.playerQuit": "\\0 has left the lobby and will certainly die at the end of the next night.",
"chatMessage.playerQuit.gameOver": "\\0 has left the lobby.",

"chatMessage.trialInformation":"\\0 votes are needed for a trial. There are \\1 trials left today.",
"chatMessage.voted":"\\0 voted for \\1.",
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/chat/chat_message_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum ChatMessageVariant {
#[serde(rename_all = "camelCase")]
GameOver { synopsis: Synopsis },
#[serde(rename_all = "camelCase")]
PlayerQuit{player_index: PlayerIndex},
PlayerQuit{player_index: PlayerIndex, game_over: bool},



Expand Down
2 changes: 1 addition & 1 deletion server/src/game/player/player_send_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl PlayerReference{
if self.alive(game) {
game.add_message_to_chat_group(
crate::game::chat::ChatGroup::All,
ChatMessageVariant::PlayerQuit{player_index: self.index()}
ChatMessageVariant::PlayerQuit{player_index: self.index(), game_over: game.game_is_over()}
);
}
}
Expand Down

0 comments on commit c77a7a0

Please sign in to comment.