Skip to content

Commit

Permalink
[✨feat]: playSoundEffect 함수분리
Browse files Browse the repository at this point in the history
  • Loading branch information
yejinleee committed Apr 18, 2024
1 parent 17b0454 commit 17bbd83
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
7 changes: 2 additions & 5 deletions src/pages/GamePage/GameCode/GameCode.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Howl } from 'howler';
import { useCallback, useMemo, useRef } from 'react';
import soundEffect from '@/assets/audio/soundEffect.mp3';
import IngameHeader from '@/common/Ingame/IngameHeader';
import IngameRank from '@/common/Ingame/IngameRank';
import playSoundEffect from '@/pages/GamePage/common/playSoundEffect';
import useIngameStore from '@/store/useIngameStore';
import CanvasTrack from '../common/CanvasTrack';
import TrackLine from '../common/TrackLine';
Expand Down Expand Up @@ -91,11 +90,9 @@ const GameCode = ({ publishIngame, userId }: GameCodeProps) => {
);

const handleUpdateScore = useCallback(() => {
const sound = new Howl({
src: [soundEffect],
});
const newScore = currentScore + scorePerSubmit;
publishIngame('/info', { currentScore: newScore });
const sound = playSoundEffect();
sound.play();
}, [currentScore, scorePerSubmit]);

Expand Down
8 changes: 2 additions & 6 deletions src/pages/GamePage/GameSentence/GameSentence.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Howl } from 'howler';
import { useCallback, useMemo, useRef, useState } from 'react';
import soundEffect from '@/assets/audio/soundEffect.mp3';
import Dashboard from '@/common/Ingame/Dashboard';
import IngameHeader from '@/common/Ingame/IngameHeader';
import IngameRank from '@/common/Ingame/IngameRank';
import { SentenceNext } from '@/common/Ingame/SentenceBlocks';
import playSoundEffect from '@/pages/GamePage/common/playSoundEffect';
import useIngameStore from '@/store/useIngameStore';
import CanvasTrack from '../common/CanvasTrack';
import TrackLine from '../common/TrackLine';
Expand Down Expand Up @@ -89,15 +88,12 @@ const GameSentence = ({ publishIngame, userId }: GameSentenceProps) => {
);

const scorePerTrankLength = Math.ceil((1 / TotalSpacedWord) * 100);

const handleUpdateScore: UpdateScoreType = useCallback(() => {
const sound = new Howl({
src: [soundEffect],
});
const newScore = currentScore + scorePerTrankLength;
publishIngame('/info', {
currentScore: newScore,
});
const sound = playSoundEffect();
sound.play();
}, [currentScore, scorePerTrankLength]);

Expand Down
10 changes: 10 additions & 0 deletions src/pages/GamePage/common/playSoundEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Howl } from 'howler';
import soundEffect from '@/assets/audio/soundEffect.mp3';

const playSoundEffect = () => {
const sound = new Howl({
src: [soundEffect],
});
return sound;
};
export default playSoundEffect;

0 comments on commit 17bbd83

Please sign in to comment.