- board.tsx: 판 폭(최대 1180px) 반원 테이블(딜러·카드 슈·인쇄 문구·앞쪽 호의 자리, 내 자리는 가운데 앞 크게) - 아래 조작판: 내 칩·시간 / 베팅(숫자 입력·Enter, −/+, 마우스 휠·↑↓(Shift 10배), 칩 버튼, 최소·절반·최대·지난 베팅, 막대) / 히트 H·스탠드 S·더블 D·스플릿 P·서렌더 R / 인슈어런스 / 결과·다음 판 - 옆 패널은 칩 순위와 놀이용 칩 안내만 - 카드는 나눠 주는 순서대로 450ms 간격으로 슈에서 날아오고 딜러 홀 카드는 뒤집힘, 합·결과는 카드가 놓인 뒤에 - 엔진: 처음 나눠 주기·딜러 차례에 장당 450ms를 다음 제한 시간에 더함(animLagMs) - PlayingCard width 속성, 도움말·문서·e2e 스크린샷 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
5.2 KiB
TypeScript
117 lines
5.2 KiB
TypeScript
/**
|
|
* Trump card drawn in SVG. Big corner index for readability on PC and phones. Number cards and the back are drawn here;
|
|
* J/Q/K and the two jokers show real card artwork by Dmitry Fomin (Wikimedia Commons, CC0 — ./court/ATTRIBUTION.txt),
|
|
* bundled from our own origin as small WebP files that load only when such a card is on screen.
|
|
*/
|
|
import type { CSSProperties } from 'react';
|
|
|
|
/** Credit for the court/joker artwork (CC0 needs none, but we say thanks); shown in the rules of the games using these cards. */
|
|
export const PLAYING_CARD_CREDIT =
|
|
'트럼프 그림카드(J·Q·K)·조커 그림: Dmitry Fomin — Wikimedia Commons "SVG English pattern playing cards", "Atlas deck joker", CC0 1.0(퍼블릭 도메인). 그림 부분만 잘라 작게 줄여 썼어요.';
|
|
|
|
/**
|
|
* URL of the court/joker picture ("JS".."KC", "X1" black joker, "X2" red joker). Vite turns this pattern into hashed
|
|
* /assets/ files; in tests it is just a file URL.
|
|
*/
|
|
export const courtSrc = (id: string): string => new URL(`./court/${id}.webp`, import.meta.url).href;
|
|
|
|
const SUIT_SYMBOL: Record<string, string> = { S: '♠', H: '♥', D: '◆', C: '♣' };
|
|
const SUIT_KO: Record<string, string> = { S: '스페이드', H: '하트', D: '다이아', C: '클로버' };
|
|
const RANK_LABEL: Record<string, string> = { T: '10', J: 'J', Q: 'Q', K: 'K', A: 'A' };
|
|
const FACE_KO: Record<string, string> = { J: '잭', Q: '퀸', K: '킹', A: '에이스' };
|
|
|
|
export type CardSize = 'sm' | 'md' | 'lg';
|
|
const WIDTH: Record<CardSize, number> = { sm: 44, md: 64, lg: 88 };
|
|
|
|
export interface PlayingCardProps {
|
|
/** e.g. "AS", "TD", "X1" (joker). null = face down. */
|
|
card: string | null;
|
|
size?: CardSize;
|
|
/** Exact width in px (overrides `size`). */
|
|
width?: number;
|
|
selected?: boolean;
|
|
dimmed?: boolean;
|
|
highlight?: boolean;
|
|
onClick?: () => void;
|
|
title?: string;
|
|
style?: CSSProperties;
|
|
/** Colour-blind friendly: 4-colour suits. */
|
|
fourColor?: boolean;
|
|
}
|
|
|
|
export function cardAria(card: string | null): string {
|
|
if (!card) return '뒤집힌 카드';
|
|
if (card.startsWith('X')) return '조커';
|
|
const r = card[0]!;
|
|
return `${SUIT_KO[card[1]!]} ${FACE_KO[r] ?? RANK_LABEL[r] ?? r}`;
|
|
}
|
|
|
|
export function PlayingCard({ card, size = 'md', width, selected, dimmed, highlight, onClick, title, style, fourColor }: PlayingCardProps) {
|
|
const w = width ?? WIDTH[size];
|
|
const h = Math.round(w * 1.4);
|
|
const lift = selected ? -Math.round(w * 0.22) : 0;
|
|
const common: CSSProperties = {
|
|
width: w,
|
|
height: h,
|
|
flex: 'none',
|
|
transform: `translateY(${lift}px)`,
|
|
transition: 'transform 0.12s ease',
|
|
cursor: onClick ? 'pointer' : 'default',
|
|
opacity: dimmed ? 0.45 : 1,
|
|
filter: highlight ? 'drop-shadow(0 0 6px #f59e0b)' : 'drop-shadow(0 1px 2px rgba(0,0,0,0.25))',
|
|
...style,
|
|
};
|
|
const Tag = onClick ? 'button' : 'span';
|
|
const btnReset: CSSProperties = onClick ? { padding: 0, border: 0, background: 'none' } : {};
|
|
if (!card) {
|
|
return (
|
|
<Tag style={{ ...common, ...btnReset }} onClick={onClick} aria-label={title ?? '뒤집힌 카드'} title={title}>
|
|
<svg viewBox="0 0 100 140" width={w} height={h} aria-hidden>
|
|
<rect x="1" y="1" width="98" height="138" rx="9" fill="#1e3a8a" stroke="#fff" strokeWidth="3" />
|
|
<rect x="9" y="9" width="82" height="122" rx="6" fill="none" stroke="#93c5fd" strokeWidth="2" />
|
|
<path d="M50 30 L70 70 L50 110 L30 70 Z" fill="#3b82f6" opacity="0.7" />
|
|
</svg>
|
|
</Tag>
|
|
);
|
|
}
|
|
const joker = card.startsWith('X');
|
|
const suit = card[1]!;
|
|
const rank = card[0]!;
|
|
const color = joker
|
|
? card === 'X1' ? '#111827' : '#dc2626'
|
|
: fourColor
|
|
? { S: '#111827', H: '#dc2626', D: '#2563eb', C: '#15803d' }[suit]!
|
|
: suit === 'H' || suit === 'D'
|
|
? '#dc2626'
|
|
: '#111827';
|
|
const label = joker ? '★' : (RANK_LABEL[rank] ?? rank);
|
|
const sym = joker ? '' : SUIT_SYMBOL[suit];
|
|
return (
|
|
<Tag style={{ ...common, ...btnReset }} onClick={onClick} aria-label={title ?? cardAria(card)} aria-pressed={onClick ? !!selected : undefined} title={title}>
|
|
<svg viewBox="0 0 100 140" width={w} height={h} aria-hidden>
|
|
<rect x="1" y="1" width="98" height="138" rx="9" fill="#fffef9" stroke={selected ? '#2563eb' : '#9ca3af'} strokeWidth={selected ? 5 : 2} />
|
|
{joker ? (
|
|
<image href={courtSrc(card === 'X1' ? 'X1' : 'X2')} x="22" y="30" width="72" height="104" preserveAspectRatio="xMidYMid meet" />
|
|
) : 'JQK'.includes(rank) ? (
|
|
<>
|
|
{/* picture frame like a real court card, with a notch at top-left so the big index stays readable */}
|
|
<image href={courtSrc(rank + suit)} x="10" y="5" width="80" height="130" preserveAspectRatio="xMidYMid slice" />
|
|
<path d="M10 5H36V65H10Z" fill="#fffef9" />
|
|
<path d="M36 5H90V135H10V65H36Z" fill="none" stroke={color} strokeOpacity="0.55" strokeWidth="1.2" />
|
|
</>
|
|
) : (
|
|
<text x="60" y="108" fontSize="54" textAnchor="middle" fill={color}>
|
|
{sym}
|
|
</text>
|
|
)}
|
|
<text x="9" y="33" fontSize="30" fontWeight="800" fill={color} fontFamily="Pretendard Variable, sans-serif">
|
|
{label}
|
|
</text>
|
|
<text x="11" y="60" fontSize="26" fill={color}>
|
|
{sym}
|
|
</text>
|
|
</svg>
|
|
</Tag>
|
|
);
|
|
}
|