Skip to content

Commit

Permalink
feat: 패널티 메시지로 연관된 단어 모두 보여주도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ijun17 committed Feb 17, 2025
1 parent 89895d8 commit 5e354e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 3 additions & 3 deletions client/src/hooks/socket/useGameSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
15 changes: 6 additions & 9 deletions server/src/game/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
}
}

Expand Down

0 comments on commit 5e354e7

Please sign in to comment.