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

방장이 아닌 사람도 방장과 같은 설정 화면(자세한 설정 포함)을 본다.
모든 버튼·입력은 잠겨 있고 "자세한 설정" 펼치기만 된다. 휴대폰은 [설정 보기],
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로 늘리지 않는다.
===================================================================== */