Skip to content

Commit

Permalink
결과 화면 자세하게 띄우기 (#205)
Browse files Browse the repository at this point in the history
* feat: 결과 상세

* docs: voiceProcessingResult 수정

* chore: 입력값 한글 자음도 포함
  • Loading branch information
student079 authored Nov 30, 2024
1 parent 11b91cf commit f045413
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 31 deletions.
15 changes: 15 additions & 0 deletions be/gameServer/src/modules/games/dto/voice-processing-result.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,19 @@ export class VoiceProcessingResultDto {
description: '결과',
})
result: string;

@ApiProperty({
example: '3옥도#',
type: String,
description: '음계',
required: false,
})
note?: string;

@ApiProperty({
example: 99,
type: Number,
description: '발음 게임 점수',
})
procounceScore?: number;
}
38 changes: 22 additions & 16 deletions be/gameServer/src/modules/games/games-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,29 @@ export function noteToNumber(note: string): number {
}

export function numberToNote(number: number): string {
const notes = [
'C',
'C#',
'D',
'D#',
'E',
'F',
'F#',
'G',
'G#',
'A',
'A#',
'B',
];
const koreanNoteNames = {
C: '도',
'C#': '도#',
D: '레',
'D#': '레#',
E: '미',
F: '파',
'F#': '파#',
G: '솔',
'G#': '솔#',
A: '라',
'A#': '라#',
B: '시',
};

const noteNames = Object.keys(koreanNoteNames);
const noteBase = number % 12;
const octave = Math.floor(number / 12) - 1;
const noteIndex = Math.round(number) % 12;
return `${notes[noteIndex]}${octave}`;

const noteName = noteNames[noteBase];
const koreanNote = koreanNoteNames[noteName];

return `${octave}${koreanNote}`;
}

export function updatePreviousPlayers(
Expand Down
15 changes: 2 additions & 13 deletions be/gameServer/src/modules/games/games.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,7 @@ export class GamesGateway implements OnGatewayDisconnect {
this.server.to(roomId).emit('voiceProcessingResult', {
result: 'PASS',
playerNickname,
note: averageNote,
preNote: numberToNote(gameData.previousPitch),
prelayerNickname:
gameData.previousPlayers.length === 0
? null
: gameData.previousPlayers[gameData.previousPlayers.length - 1],
previousPlayerNote: numberToNote(gameData.previousPitch),
note: numberToNote(note),
});
gameData.previousPitch = note;
} else {
Expand All @@ -253,12 +247,7 @@ export class GamesGateway implements OnGatewayDisconnect {
this.server.to(roomId).emit('voiceProcessingResult', {
result: 'FAIL',
playerNickname,
playerNote: averageNote,
previousPlayerNickname:
gameData.previousPlayers.length === 0
? null
: gameData.previousPlayers[gameData.previousPlayers.length - 1],
previousPlayerNote: numberToNote(gameData.previousPitch),
note: numberToNote(note),
});
removePlayerFromGame(gameData, playerNickname);
}
Expand Down
18 changes: 18 additions & 0 deletions be/gameServer/src/modules/games/games.websocket.emit.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ export class GamesWebSocketEmitController {
@ApiResponse({
description: '채점 결과',
type: VoiceProcessingResultDto,
examples: {
example1: {
summary: '클레오파트라게임 채점 결과',
value: {
result: 'PASS',
playerNickname: '호스트',
note: '3옥도#',
},
},
example2: {
summary: '발음게임 채점 결과',
value: {
result: 'PASS',
playerNickname: '플레이어',
pronounceScore: 99,
},
},
},
})
voiceProcessingResult() {
return;
Expand Down
2 changes: 1 addition & 1 deletion be/gameServer/src/modules/rooms/dto/create-room.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CreateRoomDto {
@IsString({ message: 'hostNickname은 문자열이어야 합니다.' })
@IsNotEmpty({ message: 'hostNickname은 필수 입력 항목입니다.' })
@Length(2, 8, { message: 'hostNickname은 2자에서 8자 사이여야 합니다.' })
@Matches(/^[a-zA-Z0-9가- ]+$/, {
@Matches(/^[a-zA-Z0-9가-힣ㄱ-ㅎ ]+$/, {
message: 'hostNickname은 한글, 알파벳, 숫자, 공백만 허용됩니다.',
})
@ApiProperty({
Expand Down
2 changes: 1 addition & 1 deletion be/gameServer/src/modules/rooms/dto/join-data.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class JoinRoomDto {
@IsString({ message: 'playerNickname은 문자열이어야 합니다.' })
@IsNotEmpty({ message: 'playerNickname은 필수 입력 항목입니다.' })
@Length(2, 8, { message: 'playerNickname은 2자에서 8자 사이여야 합니다.' })
@Matches(/^[a-zA-Z0-9가- ]+$/, {
@Matches(/^[a-zA-Z0-9가-힣ㄱ-ㅎ ]+$/, {
message: 'playerNickname은 한글, 알파벳, 숫자, 공백만 허용됩니다.',
})
@ApiProperty({
Expand Down

0 comments on commit f045413

Please sign in to comment.