Skip to content

Commit

Permalink
- Added new sound to play when match is found notification is triggered.
Browse files Browse the repository at this point in the history
- Added tests and fixed existing typo in test.
  • Loading branch information
Trenair authored and Sheikah45 committed Jun 26, 2024
1 parent bcaf163 commit 106315a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/main/java/com/faforever/client/audio/AudioService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AudioService implements InitializingBean {
private static final String FRIEND_OFFLINE_SOUND = "theme/sounds/friendOfflineSound.mp3";
private static final String FRIEND_JOINS_GAME_SOUND = "theme/sounds/friendJoinsGameSound.mp3";
private static final String FRIEND_PLAYS_GAME_SOUND = "theme/sounds/friendPlaysGameSound.mp3";
private static final String MATCH_FOUND_SOUND = "theme/sounds/friendPlaysGameSound.mp3";

private final AudioClipPlayer audioClipPlayer;
private final ThemeService themeService;
Expand All @@ -44,6 +45,7 @@ public class AudioService implements InitializingBean {
private AudioClip friendOfflineSound;
private AudioClip friendJoinsGameSound;
private AudioClip friendPlaysGameSound;
private AudioClip playMatchFoundSound;

private long lastPlayedSoundTime;

Expand All @@ -65,6 +67,7 @@ private void loadSounds() throws IOException {
friendOfflineSound = loadSound(FRIEND_OFFLINE_SOUND);
friendJoinsGameSound = loadSound(FRIEND_JOINS_GAME_SOUND);
friendPlaysGameSound = loadSound(FRIEND_PLAYS_GAME_SOUND);
playMatchFoundSound = loadSound(FRIEND_PLAYS_GAME_SOUND);
}

private AudioClip loadSound(String sound) throws IOException {
Expand Down Expand Up @@ -148,6 +151,15 @@ public void playFriendPlaysGameSound() {
playSound(friendPlaysGameSound);
}


public void playMatchFoundSound() {
if (!notificationPrefs.isMatchFoundSoundEnabled()) {
return;
}
playSound(friendPlaysGameSound);
}


private void playSound(AudioClip audioClip) {
if (!playSounds.get()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class NotificationPrefs {
private final IntegerProperty toastDisplayTime = new SimpleIntegerProperty(5000);
private final IntegerProperty silenceBetweenSounds = new SimpleIntegerProperty(30000);
private final BooleanProperty afterGameReviewEnabled = new SimpleBooleanProperty(true);
private final BooleanProperty isMatchFoundSoundEnabled = new SimpleBooleanProperty(true);

public boolean isSoundsEnabled() {
return soundsEnabled.get();
Expand Down Expand Up @@ -285,6 +286,14 @@ public BooleanProperty afterGameReviewEnabledProperty() {
return afterGameReviewEnabled;
}

public void setIsMatchFoundSoundEnabled(boolean isMatchFoundSoundEnabled) {
this.isMatchFoundSoundEnabled.set(isMatchFoundSoundEnabled);
}

public boolean isMatchFoundSoundEnabled() {
return isMatchFoundSoundEnabled.get();
}

public int getSilenceBetweenSounds() {
return silenceBetweenSounds.get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.client.teammatchmaking;

import com.faforever.client.api.FafApiAccessor;
import com.faforever.client.audio.AudioService;
import com.faforever.client.chat.ChatService;
import com.faforever.client.domain.server.MatchmakerQueueInfo;
import com.faforever.client.domain.server.PartyInfo;
Expand Down Expand Up @@ -29,6 +30,7 @@
import com.faforever.client.player.PlayerService;
import com.faforever.client.player.ServerStatus;
import com.faforever.client.preferences.MatchmakerPrefs;
import com.faforever.client.preferences.NotificationPrefs;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.remote.FafServerAccessor;
import com.faforever.client.user.LoginService;
Expand Down Expand Up @@ -110,6 +112,8 @@ public class TeamMatchmakingService implements InitializingBean {
private final MatchmakerMapper matchmakerMapper;
private final MatchmakerPrefs matchmakerPrefs;
private final GamePathHandler gamePathHandler;
private final AudioService audioService;
private final NotificationPrefs notificationPrefs;

@Getter
private final PartyInfo party = new PartyInfo();
Expand Down Expand Up @@ -342,6 +346,10 @@ private void setTimedOutMatchingStatus(MatchmakerQueueInfo queue, MatchingStatus
}

private void notifyMatchFound() {
if (notificationPrefs.isMatchFoundSoundEnabled()) {
audioService.playMatchFoundSound();
}

notificationService.addNotification(
new TransientNotification(i18n.get("teammatchmaking.notification.matchFound.title"),
i18n.get("teammatchmaking.notification.matchFound.message")));
Expand Down
13 changes: 12 additions & 1 deletion src/test/java/com/faforever/client/audio/AudioServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void setUp() throws Exception {
notificationPrefs.setFriendOnlineSoundEnabled(true);
notificationPrefs.setFriendPlaysGameSoundEnabled(true);
notificationPrefs.setFriendOfflineSoundEnabled(true);
notificationPrefs.setIsMatchFoundSoundEnabled(true);
notificationPrefs.setSilenceBetweenSounds(SILENCE_BETWEEN_SOUNDS);

instance.afterPropertiesSet();
Expand All @@ -67,6 +68,7 @@ public void testNoSoundsWhenOff() {
instance.playFriendOnlineSound();
instance.playFriendOfflineSound();
instance.playFriendPlaysGameSound();
instance.playMatchFoundSound();
instance.playInfoNotificationSound();
verify(audioClipPlayer, never()).playSound(any());
}
Expand All @@ -82,6 +84,7 @@ public void testNoSoundsWhenIndividuallyOff() {
notificationPrefs.setFriendOnlineSoundEnabled(false);
notificationPrefs.setFriendPlaysGameSoundEnabled(false);
notificationPrefs.setPrivateMessageSoundEnabled(false);
notificationPrefs.setIsMatchFoundSoundEnabled(false);
instance.playChatMentionSound();
instance.playPrivateMessageSound();
instance.playInfoNotificationSound();
Expand All @@ -92,6 +95,7 @@ public void testNoSoundsWhenIndividuallyOff() {
instance.playFriendOfflineSound();
instance.playFriendPlaysGameSound();
instance.playInfoNotificationSound();
instance.playMatchFoundSound();
verify(audioClipPlayer, never()).playSound(any());
}

Expand Down Expand Up @@ -164,9 +168,16 @@ public void testPlayFriendPlaysGameSound() {
}

@Test
public void testPlayFriendJoinsGamSound() {
public void testPlayFriendJoinsGameSound() {
instance.playFriendJoinsGameSound();

verify(audioClipPlayer).playSound(any(AudioClip.class));
}

@Test
public void testMatchFoundSoundPlays() {
instance.playMatchFoundSound();

verify(audioClipPlayer).playSound(any(AudioClip.class));
}
}

0 comments on commit 106315a

Please sign in to comment.