| 1 | |
| 2 | |
| 3 | import type { CSSProperties } from 'react'; |
| 4 | import { cardArt } from './art'; |
| 5 | import { displayCardName } from '../../../src/client/utils/gameViewHelpers'; |
| 6 | |
| 7 | export interface Face { |
| 8 | name: string; |
| 9 | suit?: string; |
| 10 | rank?: string; |
| 11 | damageType?: string; |
| 12 | } |
| 13 | |
| 14 | const NATURE: Record<string, string> = { 火焰: 'fire', 雷电: 'thunder' }; |
| 15 | export const isRed = (suit?: string) => suit === '♥' || suit === '♦'; |
| 16 | |
| 17 | |
| 18 | export 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 | |
| 35 | export 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 | |
| 40 | export 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 | } |