게임 화면 공통 틀: 1600px 상한 없애고 창 폭 전체 사용, 판 크기 변수(--play-w/--play-h), 화면 채움 측정 스크립트

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-17 15:01:46 +09:00
parent 0335a09eef
commit adc3b5337a
5 changed files with 176 additions and 7 deletions

View File

@@ -0,0 +1,27 @@
import { useLayoutEffect, type RefObject } from 'react';
/**
* Keeps `--play-w` / `--play-h` (px) on the game column (.game-main) so every game can size its table to the space
* the room actually leaves it: PC uses the measured width and height; under 1100px the page scrolls, so only the
* width is measured and the height keeps the CSS default (the visible window under the room bar, global.css).
*/
export function usePlayArea(ref: RefObject<HTMLElement | null>) {
useLayoutEffect(() => {
const el = ref.current;
if (!el) return;
const wide = matchMedia('(min-width: 1100px)');
const update = () => {
el.style.setProperty('--play-w', `${el.clientWidth}px`);
if (wide.matches) el.style.setProperty('--play-h', `${el.clientHeight}px`);
else el.style.removeProperty('--play-h');
};
update();
const ro = new ResizeObserver(update);
ro.observe(el);
wide.addEventListener('change', update);
return () => {
ro.disconnect();
wide.removeEventListener('change', update);
};
}, [ref]);
}

View File

@@ -12,6 +12,7 @@ import { useSession } from '../store/session';
import { loadGameUI } from '../games/registry';
import type { GameUI } from '../games/types';
import { useWide } from '../lib/media';
import { usePlayArea } from '../lib/play-area';
import { fxMs, useMotionScope } from '../lib/motion';
const STEP_MS = 1000;
@@ -109,6 +110,8 @@ function Player({ data, ui, onBack }: { data: ReplayData; ui: GameUI; onBack: ()
const at = useRef(0);
const layout = useRef<HTMLDivElement>(null);
useMotionScope(layout);
const playArea = useRef<HTMLDivElement>(null);
usePlayArea(playArea);
const go = (n: number, keepPlaying = false) => {
const t = Math.max(0, Math.min(last, n));
@@ -240,7 +243,7 @@ function Player({ data, ui, onBack }: { data: ReplayData; ui: GameUI; onBack: ()
</div>
</nav>
<div className={`game-layout${wide ? '' : ' replay-narrow'}`} ref={layout}>
<div className="game-main">
<div className="game-main" ref={playArea}>
{!wide && status}
<div {...readOnly}>
<ui.Board key={mount} {...props} />

View File

@@ -18,6 +18,7 @@ import { ChatPanel, EmoteBubbles, useChatSeen } from '../components/ChatPanel';
import { BotActivity } from '../components/BotActivity';
import { VolumeControl } from '../components/VolumeControl';
import { useWide } from '../lib/media';
import { usePlayArea } from '../lib/play-area';
import { GameHelp } from '../components/GameHelp';
import { PlayerName } from '../components/PlayerCard';
import { useMotionScope } from '../lib/motion';
@@ -664,6 +665,8 @@ function GameView({ room, ui, me, players, pending, slow }: { room: RoomView; ui
const wide = useWide();
const layout = useRef<HTMLDivElement>(null);
useMotionScope(layout);
const playArea = useRef<HTMLDivElement>(null);
usePlayArea(playArea);
const myTurn = ui.isMyTurn(game.view, me.id);
const isPlayer = room.seats.some((s) => s?.user.id === me.id) && game.active !== undefined;
const props = {
@@ -717,7 +720,7 @@ function GameView({ room, ui, me, players, pending, slow }: { room: RoomView; ui
);
return (
<div className="game-layout" ref={layout}>
<div className="game-main">
<div className="game-main" ref={playArea}>
{!wide && statusRow}
<ui.Board {...props} />
</div>

View File

@@ -835,7 +835,6 @@ button.header-user {
border-bottom: 1px solid var(--border);
}
.room-bar-inner {
max-width: 1600px;
height: 100%;
margin: 0 auto;
padding: 0 24px;
@@ -862,11 +861,10 @@ button.header-user {
}
}
/* Game screen: board + right panel, fits the viewport height on PC */
/* Game screen: board + right panel, fits the viewport height on PC and uses the whole window width
(no max width: the board column takes everything the side panel leaves). */
.game-layout {
max-width: 1600px;
margin: 0 auto;
padding: 16px 24px;
padding: 16px 20px;
display: grid;
grid-template-columns: minmax(0, 1fr) 380px;
gap: 20px;
@@ -876,6 +874,10 @@ button.header-user {
.game-main {
min-width: 0;
min-height: 0;
/* Play area size for games to fit their table to (px; kept up to date by usePlayArea in lib/play-area.ts).
Under 1100px the page scrolls, so the height is the visible window under the room bar. */
--play-w: calc(100vw - 24px);
--play-h: calc(100dvh - var(--site-h) - 52px - 24px);
display: flex;
flex-direction: column;
align-items: center;