Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/ISettings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export interface ILobbySettings {
publicLobby_on: boolean;
publicLobby_title: string;
publicLobby_language: string;
ghostsCanTalkIngame: boolean;
gracePeriod: number;
}

export interface SocketConfig {
Expand Down
66 changes: 60 additions & 6 deletions src/renderer/Voice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ const defaultlocalLobbySettings: ILobbySettings = {
publicLobby_on: false,
publicLobby_title: '',
publicLobby_language: 'en',
ghostsCanTalkIngame: false,
gracePeriod: 0,
};
const radioOnAudio = new Audio();
radioOnAudio.src = radioOnSound;
Expand All @@ -222,6 +224,7 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP
const settingsRef = useRef<ISettings>(settings);
const [lobbySettings, setHostLobbySettings] = useContext(HostSettingsContext);
const lobbySettingsRef = useRef(lobbySettings);
const gracePeriodRef = useRef<number>(0);
const maxDistanceRef = useRef(2);
const gameState = useContext(GameStateContext);
const playerColors = useContext(PlayerColorContext);
Expand Down Expand Up @@ -294,6 +297,7 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP
const { pan, gain, muffle, reverb, destination } = audio;
const audioContext = pan.context;
const useLightSource = true;
const lobbySettings = lobbySettingsRef.current;
let maxdistance = maxDistanceRef.current;
let panPos = [other.x - me.x, other.y - me.y];
let endGain = 0;
Expand All @@ -315,9 +319,31 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP
case GameState.TASKS:
endGain = 1;

if (lobbySettings.meetingGhostOnly) {
endGain = 0;
const gracePeriodMs = (lobbySettings.gracePeriod || 0) * 1000;
const isInGracePeriod = gracePeriodRef.current > 0 && Date.now() < gracePeriodRef.current + gracePeriodMs;

if (lobbySettings.meetingGhostOnly && lobbySettings.ghostsCanTalkIngame) {
if (me.isDead && other.isDead) {
panPos = [0, 0];
skipDistanceCheck = true;
endGain = 1;
} else if (!me.isDead && other.isDead) {
// Alive players should never hear ghosts, even during grace period
endGain = 0;
} else {
if (!isInGracePeriod) {
endGain = 0;
}
}
} else if (lobbySettings.meetingGhostOnly) {
if (!me.isDead && other.isDead) {
// Alive players should never hear ghosts, even during grace period
endGain = 0;
} else if (!isInGracePeriod) {
endGain = 0;
}
}

if (!me.isDead && lobbySettings.commsSabotage && state.comsSabotaged && !me.isImpostor) {
endGain = 0;
}
Expand Down Expand Up @@ -360,17 +386,26 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP
}
collided = false;
endGain = settings.ghostVolumeAsImpostor / 100;
} else {
if (other.isDead && !me.isDead) {
} else if (other.isDead && !me.isDead) {
if (!lobbySettings.meetingGhostOnly) {
endGain = 0;
}
}
break;
case GameState.DISCUSSION:
panPos = [0, 0];
endGain = 1;
if (!me.isDead && other.isDead) {
endGain = 0;

if (lobbySettings.meetingGhostOnly && lobbySettings.ghostsCanTalkIngame) {
if (!me.isDead && other.isDead) {
// Alive players should never hear ghosts, even during grace period
endGain = 0;
}
} else {
if (!me.isDead && other.isDead) {
// Alive players should never hear ghosts, even during grace period
endGain = 0;
}
}
break;

Expand Down Expand Up @@ -1269,6 +1304,25 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP
connectionStuff.current.socket?.emit('VAD', talking);
}, [talking])

useEffect(() => {
if (
lobbySettingsRef.current.meetingGhostOnly &&
lobbySettingsRef.current.gracePeriod > 0 &&
(gameState.gameState === GameState.TASKS || gameState.gameState === GameState.DISCUSSION) &&
(gameState.oldGameState === GameState.LOBBY || gameState.oldGameState === GameState.DISCUSSION || gameState.oldGameState === GameState.TASKS)
) {
if (
gameState.oldGameState === GameState.LOBBY ||
(gameState.oldGameState === GameState.DISCUSSION && gameState.gameState === GameState.TASKS) ||
(gameState.oldGameState === GameState.TASKS && gameState.gameState === GameState.DISCUSSION)
) {
gracePeriodRef.current = Date.now();
}
} else if (gameState.gameState === GameState.LOBBY || gameState.gameState === GameState.MENU) {
gracePeriodRef.current = 0;
}
}, [gameState.gameState, gameState.oldGameState]);

// Connect to P2P negotiator, when game mode change
useEffect(() => {
if (
Expand Down
55 changes: 54 additions & 1 deletion src/renderer/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,14 @@ const Settings: React.FC<SettingsProps> = function ({ t, open, onClose }: Settin
openWarningDialog(
t('settings.warning'),
t('settings.lobbysettings.meetings_only_warning'),
() => updateLocalLobbySettingsBuffer({ meetingGhostOnly: newValue, deadOnly: false }),
() => {
updateLocalLobbySettingsBuffer({
meetingGhostOnly: newValue,
deadOnly: false,
ghostsCanTalkIngame: newValue ? localLobbySettingsBuffer.ghostsCanTalkIngame : false,
gracePeriod: newValue ? localLobbySettingsBuffer.gracePeriod : 0
});
},
newValue
);
}}
Expand All @@ -612,6 +619,52 @@ const Settings: React.FC<SettingsProps> = function ({ t, open, onClose }: Settin
control={<Checkbox />}
/>
</DisabledTooltip>
<DisabledTooltip
disabled={!canChangeLobbySettings || !(canChangeLobbySettings ? localLobbySettingsBuffer.meetingGhostOnly : hostLobbySettings.meetingGhostOnly)}
title={
!canChangeLobbySettings
? isInMenuOrLobby
? t('settings.lobbysettings.gamehostonly')
: t('settings.lobbysettings.inlobbyonly')
: t('settings.lobbysettings.meetings_only_warning3')
}
>
<FormControlLabel
className={classes.formLabel}
label={t('settings.lobbysettings.ghosts_can_talk_ingame')}
disabled={!canChangeLobbySettings || !(canChangeLobbySettings ? localLobbySettingsBuffer.meetingGhostOnly : hostLobbySettings.meetingGhostOnly)}
onChange={(_, newValue: boolean) => updateLocalLobbySettingsBuffer({ ghostsCanTalkIngame: newValue })}
value={canChangeLobbySettings ? localLobbySettingsBuffer.ghostsCanTalkIngame : hostLobbySettings.ghostsCanTalkIngame}
checked={canChangeLobbySettings ? localLobbySettingsBuffer.ghostsCanTalkIngame : hostLobbySettings.ghostsCanTalkIngame}
control={<Checkbox />}
/>
</DisabledTooltip>
<DisabledTooltip
disabled={!canChangeLobbySettings || !(canChangeLobbySettings ? localLobbySettingsBuffer.meetingGhostOnly : hostLobbySettings.meetingGhostOnly)}
title={
!canChangeLobbySettings
? isInMenuOrLobby
? t('settings.lobbysettings.gamehostonly')
: t('settings.lobbysettings.inlobbyonly')
: t('settings.lobbysettings.meetings_only_warning3')
}
>
<div style={{ marginTop: 16 }}>
<Typography id="grace-period-slider" gutterBottom>
{t('settings.lobbysettings.grace_period')}: {canChangeLobbySettings ? localLobbySettingsBuffer.gracePeriod : hostLobbySettings.gracePeriod}s
</Typography>
<Slider
size="small"
disabled={!canChangeLobbySettings || !(canChangeLobbySettings ? localLobbySettingsBuffer.meetingGhostOnly : hostLobbySettings.meetingGhostOnly)}
value={canChangeLobbySettings ? localLobbySettingsBuffer.gracePeriod : hostLobbySettings.gracePeriod}
min={0}
max={10}
step={0.5}
onChange={(_, newValue: number | number[]) => updateLocalLobbySettingsBuffer({ gracePeriod: newValue as number })}
aria-labelledby="grace-period-slider"
/>
</div>
</DisabledTooltip>
{/* </FormGroup> */}
</div>
<Divider />
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/settings/SettingsStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ export const SettingsStore = new Store<ISettings>({
type: 'string',
default: 'NONE',
},
ghostsCanTalkIngame: {
type: 'boolean',
default: false,
},
gracePeriod: {
type: 'number',
default: 0,
},
},
default: {
maxDistance: 5.32,
Expand All @@ -320,6 +328,8 @@ export const SettingsStore = new Store<ISettings>({
publicLobby_title: '',
publicLobby_language: 'en',
publicLobby_mods: 'NONE',
ghostsCanTalkIngame: false,
gracePeriod: 0,
},
},
launchPlatform: {
Expand Down
Loading