대기실 게임 설정: 참여자도 보기 전용으로 전체 설정 확인

방장이 아닌 사람도 방장과 같은 설정 화면(자세한 설정 포함)을 본다.
모든 버튼·입력은 잠겨 있고 "자세한 설정" 펼치기만 된다. 휴대폰은 [설정 보기],
PC는 카드 안에 바로 펼침. 서버는 이미 방장 외 config를 거절한다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-11 01:44:20 +09:00
parent ebf82fd105
commit 27ed513011
4 changed files with 77 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
/** 방: 대기실 ↔ 게임 ↔ 결과를 한 주소에서 전환 (docs/06 §5–§9). */
import { useEffect, useMemo, useRef, useState } from 'react';
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react';
import { Link, useNavigate, useParams } from 'react-router';
import { botsAllowed, formatRoomCode, isBotId, type PublicUser, type RoomView } from '@bg/shared/lite';
import { Avatar, CodeLabel, ConfirmSheet, CopyButton, ShareButton, Sheet, TopBar } from '../components/ui';
@@ -409,16 +409,17 @@ function Lobby({ room, ui, me }: { room: RoomView; ui: GameUI; me: PublicUser })
<h2>게임 설정</h2>
<p className="muted">{ui.optionsSummary(room.options)}</p>
</div>
{isHost && !wide && (
{!wide && (
<button className="btn btn-secondary btn-sm" onClick={() => setSettings(true)}>
설정 바꾸기
{isHost ? '설정 바꾸기' : '설정 보기'}
</button>
)}
</div>
{!isHost && <p className="muted small">👑 설정은 방장만 바꿀 수 있어요. 여기서는 볼 수만 있어요.</p>}
{practice && <p className="small">🤖 연습 게임이에요. 기록에는 남지 않아요.</p>}
{room.lockedOptions.length > 0 && <p className="muted small">🔒 일부 규칙은 관리자가 정해 두어서 바꿀 수 없어요.</p>}
<GameNotice gameId={room.gameId} />
{isHost && wide && <SettingsForm room={room} ui={ui} inline />}
{wide && <SettingsForm room={room} ui={ui} inline readOnly={!isHost} />}
</section>
);
const guestLine = me.kind === 'guest' && !practice && <GuestWarning short />;
@@ -466,7 +467,7 @@ function Lobby({ room, ui, me }: { room: RoomView; ui: GameUI; me: PublicUser })
</div>
{qr && <QrModal url={url} code={room.code} onClose={() => setQr(false)} />}
{settings && <SettingsSheet room={room} ui={ui} onClose={() => setSettings(false)} />}
{settings && <SettingsSheet room={room} ui={ui} readOnly={!isHost} onClose={() => setSettings(false)} />}
{askStart && (
<ConfirmSheet title="준비 안 된 사람이 있어요" body="그래도 시작할까요?" confirm="시작하기" onConfirm={() => socket.send({ t: 'start' })} onClose={() => setAskStart(false)} />
)}
@@ -508,20 +509,23 @@ function HostMenu({ room, target }: { room: RoomView; target: PublicUser }) {
);
}
function SettingsSheet({ room, ui, onClose }: { room: RoomView; ui: GameUI; onClose: () => void }) {
function SettingsSheet({ room, ui, readOnly, onClose }: { room: RoomView; ui: GameUI; readOnly: boolean; onClose: () => void }) {
return (
<Sheet onClose={onClose} label="게임 설정">
<h2>게임 설정</h2>
<SettingsForm room={room} ui={ui} onDone={onClose} />
{readOnly && <p className="muted small">👑 설정은 방장만 바꿀 수 있어요.</p>}
<SettingsForm room={room} ui={ui} readOnly={readOnly} onDone={onClose} />
</Sheet>
);
}
/**
* Host settings: game options + room options. Inline on PC, in a sheet on narrow screens.
* Every change is sent right away, so [게임 시작] always uses what is on screen.
* Game options + room options. Inline on PC, in a sheet on narrow screens.
* Host: every change is sent right away, so [게임 시작] always uses what is on screen.
* Everyone else (`readOnly`): the same form showing the room's current options, with every control locked
* (only "▼ 자세한 설정" still opens, so the hidden rules can be read too). The server refuses non-host config anyway.
*/
function SettingsForm({ room, ui, inline, onDone }: { room: RoomView; ui: GameUI; inline?: boolean; onDone?: () => void }) {
function SettingsForm({ room, ui, inline, readOnly, onDone }: { room: RoomView; ui: GameUI; inline?: boolean; readOnly?: boolean; onDone?: () => void }) {
const [options, setOptions] = useState(room.options);
const sync = useRef(new OptionSync());
useEffect(() => {
@@ -546,17 +550,23 @@ function SettingsForm({ room, ui, inline, onDone }: { room: RoomView; ui: GameUI
);
return (
<div className="stack" style={{ gap: 14 }}>
{room.lockedOptions.length > 0 && <p className="muted small">🔒 관리자가 고정한 규칙은 바꿔도 저장되지 않아요.</p>}
<ui.Options value={options} onChange={changeOptions} />
{!readOnly && room.lockedOptions.length > 0 && <p className="muted small">🔒 관리자가 고정한 규칙은 바꿔도 저장되지 않아요.</p>}
{readOnly ? (
<ReadOnlyControls>
<ui.Options value={room.options} onChange={() => {}} />
</ReadOnlyControls>
) : (
<ui.Options value={options} onChange={changeOptions} />
)}
<hr style={{ border: 0, borderTop: '1px solid var(--border)', width: '100%' }} />
<div style={{ display: 'grid', gridTemplateColumns: inline ? 'repeat(2, minmax(0, 1fr))' : '1fr', gap: 12 }}>
<div className="stack" style={{ gap: 6 }}>
<strong>관전</strong>
{seg(room.allowSpectators, (allowSpectators) => socket.send({ t: 'config', allowSpectators }), '허용', '안 됨')}
{readOnly ? <ReadOnlyControls>{seg(room.allowSpectators, () => {}, '허용', '안 됨')}</ReadOnlyControls> : seg(room.allowSpectators, (allowSpectators) => socket.send({ t: 'config', allowSpectators }), '허용', '안 됨')}
</div>
<div className="stack" style={{ gap: 6 }}>
<strong>채팅</strong>
{seg(room.chatEnabled, (chatEnabled) => socket.send({ t: 'config', chatEnabled }), '켜기', '끄기')}
{readOnly ? <ReadOnlyControls>{seg(room.chatEnabled, () => {}, '켜기', '끄기')}</ReadOnlyControls> : seg(room.chatEnabled, (chatEnabled) => socket.send({ t: 'config', chatEnabled }), '켜기', '끄기')}
</div>
</div>
{!inline && (
@@ -568,6 +578,32 @@ function SettingsForm({ room, ui, inline, onDone }: { room: RoomView; ui: GameUI
);
}
/**
* Locks every control inside (each game's options form has its own buttons, selects and inputs), except
* disclosure toggles (`aria-expanded`, e.g. "▼ 자세한 설정") so hidden rules can still be opened and read.
* Re-locks whatever the form renders later (opening "자세한 설정" adds new controls).
*/
function ReadOnlyControls({ children }: { children: ReactNode }) {
const ref = useRef<HTMLDivElement>(null);
useLayoutEffect(() => {
const root = ref.current!;
const lock = () => {
root.querySelectorAll<HTMLButtonElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>('button:not([aria-expanded]), input, select, textarea').forEach((el) => {
if (!el.disabled) el.disabled = true;
});
};
lock();
const mo = new MutationObserver(lock);
mo.observe(root, { childList: true, subtree: true, attributes: true, attributeFilter: ['disabled'] });
return () => mo.disconnect();
}, []);
return (
<div ref={ref} className="options-view">
{children}
</div>
);
}
// ---------------------------------------------------------------- game
function GameView({ room, ui, me, players, pending, slow }: { room: RoomView; ui: GameUI; me: PublicUser; players: Record<string, PublicUser>; pending: boolean; slow: boolean }) {

View File

@@ -1370,6 +1370,17 @@ button.header-user {
gap: 6px;
}
/* 참여자가 보는 게임 설정(보기 전용): 고른 값은 또렷하게, 나머지는 흐리게. 눌러도 안 바뀐다는 게 보이도록. */
.options-view :disabled {
cursor: default;
color: inherit;
opacity: 0.5;
}
.options-view [aria-pressed='true']:disabled,
.options-view :is(input, select, textarea):disabled {
opacity: 1;
}
/* =====================================================================
PC 정리 (2026-10-09, "PC버전을 좀더"): 넓은 화면에서 한 줄 화면을 1,200px로 늘리지 않는다.
===================================================================== */

View File

@@ -39,7 +39,7 @@
- 닉네임(자리, 관전자 목록, 결과 화면)을 누르면 기록 카드가 뜬다: 이 게임의 판·승·패·무·승률, 이 방 전적, 전체 게임 합계. 패 = 판 - 승 - 무(1등이 아니면 패). 컴퓨터는 누를 수 없다. `GET /api/users/:id/stats`(로그인 필요).
- 게스트에게는 [게임 시작]/[준비하기] 아래에 한 줄로 "⚠️ 게스트 기록은 하루 동안 안 들어오면 지워져요."를 보인다(연습 방 제외).
- 규칙 설명은 대기실에 펼쳐 두지 않는다. 방 막대의 [📖 규칙]으로 본다.
3. **게임 설정 요약**: "오목 · 렌주룰 · 한 수 30초" + 방장에게만 [설정 바꾸기].
3. **게임 설정**: 요약 "오목 · 렌주룰 · 한 수 30초" + 방장은 [설정 바꾸기], 나머지는 [설정 보기](PC는 카드 안에 바로 펼침). 참여자도 방장과 같은 설정 화면(자세한 설정 포함)을 보지만 모든 버튼이 잠겨 있어 바꿀 수 없다. "👑 설정은 방장만 바꿀 수 있어요" 안내. 방장이 바꾸면 바로 따라 바뀐다(2026-10-11). 서버도 방장 외 `config`를 거절한다.
4. **아래 고정 버튼**(엄지 닿는 곳):
- 방장: [게임 시작] — 최소 인원이 안 되면 비활성 + "1명 더 필요해요" 안내. 모두 준비가 아니어도 시작 가능하되 "준비 안 된 사람이 있어요. 시작할까요?" 확인.
- 나머지: [준비하기] / [준비 취소].

View File

@@ -96,6 +96,21 @@ try {
await a.getByText('자유룰 · 15줄 · 시간 제한 없음').waitFor();
await b.getByText('자유룰 · 15줄 · 시간 제한 없음').waitFor();
await a.screenshot({ path: join(SHOTS, '1-lobby-pc.png') });
// B (not host) can open the same settings, read-only: the host's choices show, nothing can be pressed,
// and "자세한 설정" still opens so the hidden rules can be read too.
await b.getByText('설정은 방장만 바꿀 수 있어요').first().waitFor();
if (await b.getByRole('button', { name: '설정 바꾸기' }).count()) throw new Error('non-host sees 설정 바꾸기');
await b.getByRole('button', { name: '설정 보기' }).click();
const sheet = b.getByRole('dialog', { name: '게임 설정' });
const free = sheet.getByRole('button', { name: '자유룰' });
if ((await free.getAttribute('aria-pressed')) !== 'true' || !(await free.isDisabled())) throw new Error('read-only 자유룰 not shown as chosen + locked');
if (!(await sheet.getByRole('button', { name: '렌주룰' }).isDisabled())) throw new Error('non-host can press 렌주룰');
if (!(await sheet.getByRole('button', { name: '허용' }).isDisabled())) throw new Error('non-host can press 관전 허용');
await sheet.getByRole('button', { name: '▼ 자세한 설정' }).click();
if (!(await sheet.getByRole('button', { name: '19줄' }).isDisabled())) throw new Error('non-host can press 19줄 (자세한 설정)');
await b.screenshot({ path: join(SHOTS, '5b-lobby-phone-settings-view.png') });
await sheet.getByRole('button', { name: '닫기', exact: true }).click();
await b.getByText('자유룰 · 15줄 · 시간 제한 없음').waitFor();
await a.getByRole('button', { name: '▶ 게임 시작' }).click();
await a.getByRole('button', { name: '시작하기' }).click();
await a.getByText('내 차례예요').waitFor();