From 5e354e7b09805c3b498dd3c3f8fe6e24aa86532e Mon Sep 17 00:00:00 2001 From: ijun17 Date: Mon, 17 Feb 2025 22:46:17 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=8C=A8=EB=84=90=ED=8B=B0=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=EB=A1=9C=20=EC=97=B0=EA=B4=80=EB=90=9C=20?= =?UTF-8?q?=EB=8B=A8=EC=96=B4=20=EB=AA=A8=EB=91=90=20=EB=B3=B4=EC=97=AC?= =?UTF-8?q?=EC=A3=BC=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/hooks/socket/useGameSocket.ts | 6 +++--- server/src/game/game.gateway.ts | 15 ++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/client/src/hooks/socket/useGameSocket.ts b/client/src/hooks/socket/useGameSocket.ts index a4f2a607..f2fc3db8 100644 --- a/client/src/hooks/socket/useGameSocket.ts +++ b/client/src/hooks/socket/useGameSocket.ts @@ -219,13 +219,13 @@ export const useGameSocket = () => { navigate(`/game/${roomId}/result`, { replace: true }); }, - penaltyMessage: async (response: { playerId: string; word: string }[]) => { - for (const { playerId, word } of response) { + penaltyMessage: async (response: { playerId: string; paneltyWords: string[] }[]) => { + for (const { playerId, paneltyWords } of response) { const playerName = useGameSocketStore.getState().players.find((e) => e.playerId === playerId)?.nickname; if (!playerName) continue; useToastStore.getState().actions.addToast({ title: 'μ•—! νŒ¨λ„ν‹° πŸ’₯', - description: `${playerName}λ‹˜, μ—°κ΄€ 단어("${word}") μž‘μ„±μœΌλ‘œ νŒ¨λ„ν‹° 당첨! λ‹€μŒμ—” μ‘°μ‹¬ν•˜μ„Έμš”! πŸ˜†`, + description: `${playerName}λ‹˜, μ—°κ΄€ 단어(${paneltyWords.map((e) => `"${e}"`).join(', ')}) μž‘μ„±μœΌλ‘œ νŒ¨λ„ν‹° 당첨! λ‹€μŒμ—” μ‘°μ‹¬ν•˜μ„Έμš”! πŸ˜†`, }); await new Promise((res) => setTimeout(res, 50)); } diff --git a/server/src/game/game.gateway.ts b/server/src/game/game.gateway.ts index f6a4ac8b..2f4ac0ba 100644 --- a/server/src/game/game.gateway.ts +++ b/server/src/game/game.gateway.ts @@ -170,13 +170,10 @@ export class GameGateway implements OnGatewayDisconnect { if (boundaries.length > 0) { // μΈμ‹λœ λ‹¨μ–΄λ§Œ μΆ”μΆœ const inferTexts = ocrResult.images[0].fields.map((field) => field.inferText); - const paneltyWord = await this.findRelatedWord(currentWord, inferTexts); - if (paneltyWord) { + const paneltyWords = await this.filterRelatedWord(currentWord, inferTexts); + if (paneltyWords.length > 0) { await this.gameService.applyPenalty(roomId, playerId); - paneltyList.push({ - playerId: playerId, - word: paneltyWord, - }); + paneltyList.push({ playerId, paneltyWords }); } await this.eraseMessage(roomId, playerId, boundaries); @@ -351,12 +348,12 @@ export class GameGateway implements OnGatewayDisconnect { ); } - // μΊ”λ²„μŠ€ λ‚΄ μΈμ‹λœ 단어 쀑 μ œμ‹œμ–΄μ™€ μ—°κ΄€λœ 첫번째 단어 λ°˜ν™˜. μ—†μœΌλ©΄ undefined - private async findRelatedWord(suggestedWord: string, inferTexts: string[]) { + // μΊ”λ²„μŠ€ λ‚΄ μΈμ‹λœ 단어 쀑 μ œμ‹œμ–΄μ™€ μ—°κ΄€λœ 단어듀을 λ°°μ—΄λ‘œ λ°˜ν™˜. + private async filterRelatedWord(suggestedWord: string, inferTexts: string[]) { const isRelatedList = await Promise.all( inferTexts.map((word) => this.clovaStudio.isRelatedWord(suggestedWord, word)), ); - return inferTexts.find((_, i) => isRelatedList[i]); + return inferTexts.filter((_, i) => isRelatedList[i]); } }