채팅 소리 기본 크기를 게임 소리의 80%로 올리고(60%는 너무 안 들린다는 의견), 관리자 사이트 설정에 "채팅 소리 크기"(게임 소리의 0~200%, 정수, 기본 80%)를 추가. 0%면 채팅 소리 없음. 각자의 소리 크기(0~100)는 그대로 곱해짐. 저장하면 /api/config와 방 정보(RoomView.chatSound)로 열린 방에도 바로 적용. 설정 화면에 저장 없이 그 값으로 울려 보는 "들어 보기" 버튼. feedback.test.ts·admin.test.ts·admin.e2e.ts에 확인 추가, docs/14-admin.md 표에 항목 추가
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,7 +57,7 @@ class FakeCtx {
|
||||
// The real settings store needs a page (document); only the sound settings matter here.
|
||||
let settings = { sound: true, volume: 100 };
|
||||
mock.module('../store/session', () => ({ useSession: { getState: () => ({ settings }) } }));
|
||||
const { CHAT_LEVEL, GAME_LEVEL, chatSound, sounds } = await import('./feedback');
|
||||
const { GAME_LEVEL, chatLevel, chatSound, setChatSound, sounds } = await import('./feedback');
|
||||
|
||||
const setVolume = (volume: number, sound = true) => {
|
||||
settings = { sound, volume };
|
||||
@@ -67,19 +67,19 @@ beforeEach(() => {
|
||||
notes = [];
|
||||
});
|
||||
|
||||
test('chat sound is 60% of the game sounds', () => {
|
||||
test('chat sound is 80% of the game sounds by default', () => {
|
||||
expect(GAME_LEVEL).toBe(0.15);
|
||||
expect(CHAT_LEVEL).toBeCloseTo(GAME_LEVEL * 0.6, 10);
|
||||
expect(chatLevel()).toBeCloseTo(GAME_LEVEL * 0.8, 10);
|
||||
setVolume(100);
|
||||
sounds.myTurn(); // a typical game sound at the usual level
|
||||
const game = Math.max(...notes.map((n) => n.peak));
|
||||
notes = [];
|
||||
chatSound();
|
||||
// Notes playing at the same moment add up; the loudest moment of the chat sound is 60% of a game sound.
|
||||
// Notes playing at the same moment add up; the loudest moment of the chat sound is 80% of a game sound.
|
||||
const byStart = new Map<number, number>();
|
||||
for (const n of notes) byStart.set(n.start, (byStart.get(n.start) ?? 0) + n.peak);
|
||||
const loudest = Math.max(...byStart.values());
|
||||
expect(loudest).toBeCloseTo(game * 0.6, 6);
|
||||
expect(loudest).toBeCloseTo(game * 0.8, 6);
|
||||
// One bubble ("뽁") gliding up from a low start.
|
||||
expect(notes.map((n) => n.freq)).toEqual([380]);
|
||||
expect(notes.map((n) => n.to)).toEqual([1150]);
|
||||
@@ -110,3 +110,28 @@ test('lines arriving in a burst share one sound', async () => {
|
||||
chatSound();
|
||||
expect(notes.length).toBe(one * 2);
|
||||
});
|
||||
|
||||
test('admin chat sound setting: 0~200% of a game sound, 0 is silent, preview does not change it', async () => {
|
||||
setVolume(100);
|
||||
for (const [pct, want] of [[200, 2], [150, 1.5], [999, 2], [-5, 0]] as const) {
|
||||
setChatSound(pct);
|
||||
expect(chatLevel()).toBeCloseTo(GAME_LEVEL * want, 10);
|
||||
}
|
||||
setChatSound(0);
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
notes = [];
|
||||
chatSound();
|
||||
expect(notes).toEqual([]);
|
||||
setChatSound(200);
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
chatSound();
|
||||
expect(Math.max(...notes.map((n) => n.peak))).toBeCloseTo(GAME_LEVEL * 2, 6);
|
||||
// Previewing another value in the admin page plays it once and leaves the setting alone.
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
notes = [];
|
||||
chatSound(50);
|
||||
expect(Math.max(...notes.map((n) => n.peak))).toBeCloseTo(GAME_LEVEL * 0.5, 6);
|
||||
expect(chatLevel()).toBeCloseTo(GAME_LEVEL * 2, 10);
|
||||
setChatSound(undefined); // missing from an old server → the default 80%
|
||||
expect(chatLevel()).toBeCloseTo(GAME_LEVEL * 0.8, 10);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* directly for something of their own.
|
||||
*/
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { CHAT_SOUND_DEFAULT, clampChatSound } from '@bg/shared/lite';
|
||||
import { useSession } from '../store/session';
|
||||
|
||||
let ctx: AudioContext | null = null;
|
||||
@@ -190,21 +191,30 @@ export const sounds = {
|
||||
|
||||
/** The usual level of a game sound at volume 100 (`tone`'s default). */
|
||||
export const GAME_LEVEL = 0.15;
|
||||
/** Chat sound: 60% of the game sounds (it follows the same volume setting); 90% hit the ears too hard. */
|
||||
export const CHAT_LEVEL = GAME_LEVEL * 0.6;
|
||||
/** Chat sound in % of a game sound (admin setting `chatSound`, 0~200, default 80); it also follows the volume setting. */
|
||||
let chatPercent = CHAT_SOUND_DEFAULT;
|
||||
/** Sets the chat sound percent from /api/config or the room view (out-of-range values are clamped). */
|
||||
export function setChatSound(x: unknown): void {
|
||||
chatPercent = clampChatSound(x);
|
||||
}
|
||||
/** Peak level of the chat sound at volume 100 (`percent`: the admin setting unless previewing another value). */
|
||||
export const chatLevel = (percent = chatPercent): number => (GAME_LEVEL * clampChatSound(percent)) / 100;
|
||||
let lastChatAt = -Infinity;
|
||||
|
||||
/**
|
||||
* Chat "뽁": one water-drop bubble like a messenger, a sine gliding up fast from low (about 0.08 s).
|
||||
* Kept apart from the UI/game sounds, which are steady notes (click, good, myTurn …), so it is not mistaken for one;
|
||||
* it also starts lower and is shorter and softer than the game "pop" (700→1400 Hz).
|
||||
* It peaks at CHAT_LEVEL and fades in over 12 ms so it does not snap. Lines arriving in a burst share one sound.
|
||||
* It peaks at `chatLevel()` (none at 0%) and fades in over 12 ms so it does not snap. Lines arriving in a burst share one sound.
|
||||
* `percent` previews another level (admin settings) without changing the setting.
|
||||
*/
|
||||
export function chatSound(): void {
|
||||
export function chatSound(percent?: number): void {
|
||||
const level = chatLevel(percent);
|
||||
if (level <= 0) return;
|
||||
const now = performance.now();
|
||||
if (now - lastChatAt < 80) return;
|
||||
lastChatAt = now;
|
||||
tone(380, 80, 'sine', CHAT_LEVEL, 0, { attack: 12, slideTo: 1150 });
|
||||
tone(380, 80, 'sine', level, 0, { attack: 12, slideTo: 1150 });
|
||||
}
|
||||
|
||||
/** Plays the chat sound whenever `lastKey` (the newest live chat line) changes after the first render. */
|
||||
|
||||
Reference in New Issue
Block a user