实时对局选你的对手
加入
What shoal-games changes in this game
由 @shoal shoal 从 main 的 1b3bc26 分出 · 领先 1 个提交,比 main 落后 0 个
接续
贡献回去
46 行 · 1.8 KB 原始文件 永久链接 历史
1// A card as 无名杀 draws it: the theme's wood face, the card's art, its name in vertical brush script at the top left,
2// suit and rank at the top right; 火杀 and 雷杀 are 杀 with their colour. A card with no art shows its name large.
3import type { CSSProperties } from 'react';
4import { cardArt } from './art';
5import { displayCardName } from '../../../src/client/utils/gameViewHelpers';
6
7export interface Face {
8 name: string;
9 suit?: string;
10 rank?: string;
11 damageType?: string;
12}
13
14const NATURE: Record<string, string> = { 火焰: 'fire', 雷电: 'thunder' };
15export const isRed = (suit?: string) => suit === '♥' || suit === '♦';
16
17/** The card's inside, to fill a sized box (a hand card, a played card, a flying card). */
18export function CardInner({ name, suit, rank, damageType }: Face) {
19 const art = cardArt(name);
20 const label = displayCardName(name, damageType);
21 return (
22 <>
23 {art ? <div className="nm-card-art" style={{ backgroundImage: `url(${art})` }} /> : <div className="nm-card-big">{label.slice(0, 2)}</div>}
24 <div className={`nm-card-name${label.length > 3 ? ' long' : ''}`}>{label}</div>
25 {suit && (
26 <div className={`nm-card-info${isRed(suit) ? ' red' : ''}`}>
27 <span className="nm-suit">{suit}</span>
28 {rank}
29 </div>
30 )}
31 </>
32 );
33}
34
35export function cardClass({ suit, damageType }: Face, extra = '') {
36 const nature = damageType ? NATURE[damageType] : undefined;
37 return `nm-card${isRed(suit) ? ' red' : ''}${nature ? ` ${nature}` : ''}${extra ? ` ${extra}` : ''}`;
38}
39
40export function Card({ face, className = '', style, title }: { face: Face; className?: string; style?: CSSProperties; title?: string }) {
41 return (
42 <div className={cardClass(face, className)} style={style} title={title}>
43 <CardInner {...face} />
44 </div>
45 );
46}