@@ -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: g ame options + room options. Inline on PC, in a sheet on narrow screens.
* E very change is sent right away, so [게임 시작] always uses what is on screen.
* G ame options + room options. Inline on PC, in a sheet on narrow screens.
* Host: e very 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 } ) {