다른 사람 자리 줄: PC·태블릿에서 옆 스크롤 대신 여러 줄로 고르게 쌓기 (구십구·원카드·도블)

- lib/seat-rows.ts: 게임 칸 실제 폭으로 한 줄 칸 수를 정하고 줄마다 고르게 나눔(9 → 5 + 4)
- 720px 이상에서만 적용, 휴대폰은 한 줄 옆 밀기 그대로
- docs/07 3.5에 규칙 추가

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-11 01:13:07 +09:00
parent 0d43d9f9aa
commit c97fb4583e
6 changed files with 76 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import type { PublicUser } from '@bg/shared/lite';
import { Avatar } from '../../components/ui';
import { useServerNow } from '../../components/TurnTimer';
import { haptic, sounds } from '../../lib/feedback';
import { useSeatRows } from '../../lib/seat-rows';
import { socket, useRoom } from '../../net/socket';
import type { BoardProps, GameUI, OptionsProps } from '../types';
import { helpNow } from './help';
@@ -77,6 +78,12 @@ button.db-seat { cursor: pointer; }
@keyframes db-in { from { opacity: 0; transform: rotate(var(--rot)) scale(calc(var(--sc) * .5)); } to { opacity: 1; transform: rotate(var(--rot)) scale(var(--sc)); } }
@keyframes db-pop { 0% { transform: translateX(-50%) scale(.6); opacity: 0; } 70% { transform: translateX(-50%) scale(1.06); opacity: 1; } 100% { transform: translateX(-50%) scale(1); } }
@keyframes db-pulse { 0%,100% { box-shadow: 0 0 0 4px rgba(245,158,11,.9); } 50% { box-shadow: 0 0 0 8px rgba(245,158,11,.35); } }
/* PC/tablet: many players stack into even rows (7 → 4 + 3) instead of scrolling sideways. Phones keep one swipeable row. */
@media (min-width: 720px) {
.db-strip { flex-wrap: wrap; overflow: visible; width: 100%; max-width: calc(var(--cols) * 228px - 4px); margin: 0 auto; }
.db-strip > li { flex: 0 1 calc((100% - (var(--cols) - 1) * 8px) / var(--cols)); min-width: 0; max-width: 220px; display: flex; }
.db-strip .db-seat { flex: 1; min-width: 0; }
}
@media (max-width: 719px) {
.db { --cd: min(80vw, calc(50vh - 158px), 330px); gap: 6px; }
.db-slot { position: relative; }
@@ -258,6 +265,7 @@ function DobbleBoard({ view: v, me, players, act, pending }: BoardProps<DobbleVi
const targetMode = mode === 'hotPotato' || mode === 'poisonedGift';
const mine = v.seats.find((s) => s.id === me) ?? null;
const others = v.seats.filter((s) => s.id !== me);
const opps = useSeatRows<HTMLUListElement>(others.length, 150);
const pair: ClaimPair | null = targetMode ? (v.pairs.find((p) => p.target === sel) ?? v.pairs[0] ?? null) : (v.pairs[0] ?? null);
// The opponent whose card is shown big (also for spectators / while waiting).
const targetId = targetMode ? (pair?.target ?? (others.find((s) => s.id === sel && s.top) ?? others.find((s) => s.status === 'playing' && s.top) ?? others.find((s) => s.top))?.id ?? null) : null;
@@ -442,7 +450,7 @@ function DobbleBoard({ view: v, me, players, act, pending }: BoardProps<DobbleVi
</div>
{others.length > 0 && (
<ul className="db-strip" aria-label={targetMode ? '누구 카드에서 찾을지 고르기' : '다른 사람'}>
<ul className="db-strip" aria-label={targetMode ? '누구 카드에서 찾을지 고르기' : '다른 사람'} ref={opps.ref} style={opps.style}>
{others.map((s) => {
const tag = statusTag(s);
const canPick = targetMode && pickable.has(s.id);

View File

@@ -6,6 +6,7 @@ import { Avatar } from '../../components/ui';
import { TurnTimer } from '../../components/TurnTimer';
import { PlayingCard } from '../../components/cards/PlayingCard';
import { haptic, sounds } from '../../lib/feedback';
import { useSeatRows } from '../../lib/seat-rows';
import type { BoardProps, GameUI, OptionsProps } from '../types';
import { helpNow, resolvedHandSize } from './help';
import { quickStart } from './quick';
@@ -149,6 +150,11 @@ const CSS = `
.nn-rules .nn-art::before { inset: 3px; }
@keyframes nn-pop { 0% { transform: scale(.7); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes nn-break { 0% { transform: scale(1); color: #e11d48; opacity: 1; } 40% { transform: scale(1.5) rotate(-15deg); } 100% { transform: scale(1); } }
/* PC/tablet: many players stack into even rows (9 → 5 + 4) instead of scrolling sideways. Phones keep one swipeable row. */
@media (min-width: 720px) {
.nn-opps { flex-wrap: wrap; justify-content: center; overflow: visible; width: 100%; max-width: calc(var(--cols) * 184px - 4px); margin: 0 auto; }
.nn-seat { flex: 0 1 calc((100% - (var(--cols) - 1) * 8px) / var(--cols)); min-width: 0; max-width: 176px; }
}
@media (max-width: 719px) {
.nn-table { grid-template-columns: 1fr auto; grid-template-areas: 'dial left' 'right right'; padding: 10px; gap: 8px 10px; border-width: 6px; }
.nn-dial { grid-area: dial; }
@@ -551,11 +557,12 @@ function Board({ view: v, me, players, act, pending, deadline }: BoardProps<Nine
const myIdx = v.seats.findIndex((s) => s.id === me);
const others = myIdx < 0 ? v.seats : [...v.seats.slice(myIdx + 1), ...v.seats.slice(0, myIdx)];
const opps = useSeatRows<HTMLUListElement>(others.length);
const meSeat = v.seats.find((s) => s.id === me);
return (
<div className="nn">
<style>{CSS}</style>
<ul className="nn-opps" aria-label="다른 사람">
<ul className="nn-opps" aria-label="다른 사람" ref={opps.ref} style={opps.style}>
{others.map((s) => (
<SeatChip key={s.id} s={s} v={v} players={players} me={me} deadline={deadline} />
))}

View File

@@ -6,6 +6,7 @@ import { Avatar, Sheet } from '../../components/ui';
import { TurnTimer } from '../../components/TurnTimer';
import { PlayingCard } from '../../components/cards/PlayingCard';
import { haptic, sounds } from '../../lib/feedback';
import { useSeatRows } from '../../lib/seat-rows';
import type { BoardProps, GameUI, OptionsProps } from '../types';
import { helpNow } from './help';
import { quickStart } from './quick';
@@ -114,6 +115,11 @@ const CSS = `
@keyframes oc-fly { from { transform: translate(-40px, 30px) scale(.8); opacity: .3; } to { transform: none; opacity: 1; } }
@keyframes oc-pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes oc-shake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
/* PC/tablet: many players stack into even rows (9 → 5 + 4) instead of scrolling sideways. Phones keep one swipeable row. */
@media (min-width: 720px) {
.oc-opps { flex-wrap: wrap; justify-content: center; overflow: visible; width: 100%; max-width: calc(var(--cols) * 184px - 4px); margin: 0 auto; }
.oc-seat { flex: 0 1 calc((100% - (var(--cols) - 1) * 8px) / var(--cols)); min-width: 0; max-width: 176px; }
}
@media (max-width: 719px) {
.oc-table { grid-template-columns: auto auto; padding: 10px; gap: 10px; border-width: 6px; justify-content: center; }
.oc-info { grid-column: 1 / -1; align-items: center; }
@@ -664,12 +670,13 @@ function OneCardBoard({ view: v, me, players, act, pending, deadline }: BoardPro
// Opponents in turn order after me (spectators: seat order).
const myIdx = v.seats.findIndex((s) => s.id === me);
const others = myIdx < 0 ? v.seats : [...v.seats.slice(myIdx + 1), ...v.seats.slice(0, myIdx)];
const opps = useSeatRows<HTMLUListElement>(others.length);
const canDraw = !!v.my?.canDraw && !pending;
const meSeat = v.seats.find((s) => s.id === me);
return (
<div className="oc">
<style>{CSS}</style>
<ul className="oc-opps" aria-label="다른 사람">
<ul className="oc-opps" aria-label="다른 사람" ref={opps.ref} style={opps.style}>
{others.map((s) => (
<SeatChip key={s.id} s={s} v={v} players={players} me={me} deadline={deadline} />
))}

View File

@@ -0,0 +1,19 @@
import { expect, test } from 'bun:test';
import { seatCols, seatsPerRow } from './seat-rows';
test('seatCols keeps one row when it fits and balances rows when it wraps', () => {
expect(seatCols(0, 8)).toBe(1);
expect(seatCols(3, 8)).toBe(3);
expect(seatCols(8, 8)).toBe(8);
expect(seatCols(9, 8)).toBe(5);
expect(seatCols(9, 5)).toBe(5);
expect(seatCols(6, 5)).toBe(3);
expect(seatCols(7, 5)).toBe(4);
});
test('seatsPerRow counts whole seats including gaps', () => {
expect(seatsPerRow(1000, 118, 8)).toBe(8);
expect(seatsPerRow(999, 118, 8)).toBe(7);
expect(seatsPerRow(652, 118, 8)).toBe(5);
expect(seatsPerRow(50, 118, 8)).toBe(1);
});

View File

@@ -0,0 +1,31 @@
import { useLayoutEffect, useRef, useState, type CSSProperties } from 'react';
/** Seats per row for `n` seats when at most `max` fit in a row: rows are filled evenly (9 → 5 + 4, not 8 + 1). */
export function seatCols(n: number, max: number): number {
if (n <= max) return Math.max(n, 1);
return Math.ceil(n / Math.ceil(n / max));
}
/** How many seats of `minW` px (with `gap` px between) fit across `width` px. */
export function seatsPerRow(width: number, minW: number, gap: number): number {
return Math.max(1, Math.floor((width + gap) / (minW + gap)));
}
/**
* Opponent strip that stacks into even rows (on PC/tablet, see the game CSS) instead of scrolling sideways.
* `minW` leaves room for a name next to the turn timer. Measures the strip's parent, since the strip's own width shrinks to fit the chosen column count.
*/
export function useSeatRows<T extends HTMLElement>(n: number, minW = 136, gap = 8): { ref: React.RefObject<T | null>; style: CSSProperties } {
const ref = useRef<T>(null);
const [w, setW] = useState(0);
useLayoutEffect(() => {
const el = ref.current?.parentElement;
if (!el) return;
setW(el.clientWidth);
const ro = new ResizeObserver(() => setW(el.clientWidth));
ro.observe(el);
return () => ro.disconnect();
}, []);
const cols = seatCols(n, w ? seatsPerRow(w, minW, gap) : n);
return { ref, style: { '--cols': cols } as CSSProperties };
}

View File

@@ -109,6 +109,7 @@
```
- 오른쪽 패널 폭 360px, 판은 남은 공간에서 가장 큰 정사각형.
- 카드 게임: 판 자리에 원형 테이블, 나는 항상 아래, 내 패는 판 아래쪽 넓게.
- 다른 사람 자리 줄(구십구·원카드·도블): PC·태블릿(720px 이상)에서는 사람이 많아도 옆으로 스크롤하지 않고 판 위 빈 공간에 여러 줄로 쌓는다. 한 줄에 들어가면 한 줄, 넘치면 줄마다 고르게 나눈다(9명 → 5 + 4, 8 + 1이 아님). 한 줄에 몇 칸 들어가는지는 화면 폭이 아니라 게임 칸의 실제 폭으로 정한다(`lib/seat-rows.ts`). 휴대폰은 세로 공간이 모자라서 한 줄 그대로 옆으로 밀어 본다(2026-10-11).
- PC 조작: 마우스를 올리면 미리 보기 돌(반투명), 클릭 한 번에 착수(기본값). "두 번 눌러 확정"은 터치 기기의 기본값이고 설정에서 바꿀 수 있다.
- 단축키: `Enter` 채팅 입력, `Esc` 창 닫기, 방향키+`Enter` 판 조작.
- 방 막대 버튼은 마우스 환경에서 40px(막대 52px 안에 여유), 터치 기기에서는 48px.