Skip to content

Commit

Permalink
[✨feat]: 카운트다운 효과음 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yejinleee committed Apr 18, 2024
1 parent 17bbd83 commit 2f9dab8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
Binary file added src/assets/audio/countDown.mp3
Binary file not shown.
2 changes: 1 addition & 1 deletion src/pages/GamePage/GameCode/GameCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const GameCode = ({ publishIngame, userId }: GameCodeProps) => {
const handleUpdateScore = useCallback(() => {
const newScore = currentScore + scorePerSubmit;
publishIngame('/info', { currentScore: newScore });
const sound = playSoundEffect();
const sound = playSoundEffect('SCORE');
sound.play();
}, [currentScore, scorePerSubmit]);

Expand Down
4 changes: 3 additions & 1 deletion src/pages/GamePage/GameSentence/GameSentence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface I_RankInfoList {
}

const GameSentence = ({ publishIngame, userId }: GameSentenceProps) => {
const sound = playSoundEffect('SCORE');

const { ingameRoomRes, isRoundWaiting } = useIngameStore();

const currentScore = ingameRoomRes.allMembers.find(
Expand All @@ -41,6 +43,7 @@ const GameSentence = ({ publishIngame, userId }: GameSentenceProps) => {
const handleNextRound = useCallback(() => {
sentenceList.current = ingameRoomRes.questions!;
setSentenceIdx(0);
sound.play();
}, [ingameRoomRes.questions]);

const {
Expand Down Expand Up @@ -93,7 +96,6 @@ const GameSentence = ({ publishIngame, userId }: GameSentenceProps) => {
publishIngame('/info', {
currentScore: newScore,
});
const sound = playSoundEffect();
sound.play();
}, [currentScore, scorePerTrankLength]);

Expand Down
3 changes: 3 additions & 0 deletions src/pages/GamePage/GameWord/WordGameLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
I_IngameWsResponse,
PublishIngameType,
} from '../../GamePage/types/websocketType';
import playSoundEffect from '../common/playSoundEffect';
import useFocusInput from '../hooks/useFocusInput';
import WordCell from './WordCell';
import WordRankContainer from './WordRankContainer';
Expand Down Expand Up @@ -65,6 +66,7 @@ const WordGameLayout = ({
useEffect(() => {
onInputChange(0, 100, 150); //동기화..
}, [ingameRoomRes]);
const sound = playSoundEffect('SCORE');

return (
<>
Expand Down Expand Up @@ -99,6 +101,7 @@ const WordGameLayout = ({
setValue('wordInput', '');
initializeTyping();
submitCount.current += 1;
sound.play();
})}>
<input
autoFocus
Expand Down
8 changes: 6 additions & 2 deletions src/pages/GamePage/common/RoundWaitModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Dialog from '@radix-ui/react-dialog';
import { useEffect } from 'react';
import { convertTime } from '@/common/Timer/utils/convertTime';
import useTimer from '@/hooks/useTimer';
import playSoundEffect from './playSoundEffect';

interface RoundWaitModalProps {
isOpen: boolean;
Expand All @@ -17,9 +18,12 @@ const RoundWaitModal = ({ isOpen, onTimeFinish }: RoundWaitModalProps) => {
},
autoStart: false,
});

const sound = playSoundEffect('COUNTDOWN');
useEffect(() => {
isOpen && startTimer();
if (isOpen) {
startTimer();
sound.play();
}
}, [isOpen]);

return (
Expand Down
6 changes: 4 additions & 2 deletions src/pages/GamePage/common/playSoundEffect.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Howl } from 'howler';
import countDown from '@/assets/audio/countDown.mp3';
import soundEffect from '@/assets/audio/soundEffect.mp3';

const playSoundEffect = () => {
const playSoundEffect = (type: 'SCORE' | 'COUNTDOWN') => {
const src = type === 'SCORE' ? soundEffect : countDown;
const sound = new Howl({
src: [soundEffect],
src: [src],
});
return sound;
};
Expand Down

0 comments on commit 2f9dab8

Please sign in to comment.