|
| 1 | +import { Card, Elevation } from '@blueprintjs/core' |
| 2 | + |
| 3 | +import clsx from 'clsx' |
| 4 | +import { FC } from 'react' |
| 5 | +import { ReactNode } from 'react-markdown/lib/ast-to-react' |
| 6 | +import { FCC } from 'types' |
| 7 | + |
| 8 | +import { CardTitle } from 'components/CardTitle' |
| 9 | +import { FactItem } from 'components/FactItem' |
| 10 | +import type { CopilotDocV1 } from 'models/copilot.schema' |
| 11 | +import { findActionType } from 'models/types' |
| 12 | + |
| 13 | +import { |
| 14 | + findOperatorDirection, |
| 15 | + findOperatorSkillUsage, |
| 16 | +} from '../models/operator' |
| 17 | +import { formatDuration } from '../utils/times' |
| 18 | + |
| 19 | +interface ActionCardProps { |
| 20 | + className?: string |
| 21 | + action: CopilotDocV1.Action |
| 22 | + title?: ReactNode |
| 23 | +} |
| 24 | + |
| 25 | +export const ActionCard: FC<ActionCardProps> = ({ |
| 26 | + className, |
| 27 | + action, |
| 28 | + title, |
| 29 | +}) => { |
| 30 | + const type = findActionType(action.type) |
| 31 | + |
| 32 | + title ??= ( |
| 33 | + <div className="flex items-center"> |
| 34 | + <CardTitle className="mb-0 flex-grow" icon={type.icon}> |
| 35 | + <span className="mr-2">{type.title}</span> |
| 36 | + </CardTitle> |
| 37 | + </div> |
| 38 | + ) |
| 39 | + |
| 40 | + return ( |
| 41 | + <Card |
| 42 | + elevation={Elevation.TWO} |
| 43 | + className={clsx(className, 'flex mb-2 last:mb-0 border-l-4', type.accent)} |
| 44 | + > |
| 45 | + <div className="flex-grow"> |
| 46 | + {title} |
| 47 | + |
| 48 | + <div className="flex flex-wrap gap-x-8 gap-y-2 mt-6 w-full"> |
| 49 | + {'name' in action && action.name && ( |
| 50 | + <FactItem |
| 51 | + dense |
| 52 | + title={action.name} |
| 53 | + icon="mugshot" |
| 54 | + className="font-bold" |
| 55 | + /> |
| 56 | + )} |
| 57 | + |
| 58 | + {'skillUsage' in action && ( |
| 59 | + <FactItem |
| 60 | + dense |
| 61 | + title={findOperatorSkillUsage(action.skillUsage).title} |
| 62 | + icon="swap-horizontal" |
| 63 | + /> |
| 64 | + )} |
| 65 | + |
| 66 | + {'location' in action && action.location && ( |
| 67 | + <FactItem dense title="坐标" icon="map-marker"> |
| 68 | + <span className="font-mono">{action.location.join(', ')}</span> |
| 69 | + </FactItem> |
| 70 | + )} |
| 71 | + |
| 72 | + {'direction' in action && ( |
| 73 | + <FactItem dense title="朝向" icon="compass"> |
| 74 | + <span className="font-mono"> |
| 75 | + {findOperatorDirection(action.direction).title} |
| 76 | + </span> |
| 77 | + </FactItem> |
| 78 | + )} |
| 79 | + |
| 80 | + {'distance' in action && action.distance && ( |
| 81 | + <FactItem dense title="距离" icon="camera"> |
| 82 | + <span className="font-mono">{action.distance.join(', ')}</span> |
| 83 | + </FactItem> |
| 84 | + )} |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + |
| 88 | + {/* direction:rtl is for the grid to place columns from right to left; need to set it back to ltr for the children */} |
| 89 | + <div className="grid grid-flow-row grid-cols-2 gap-y-2 text-right [direction:rtl] [&>*]:[direction:ltr]"> |
| 90 | + <InlineCondition title="击杀">{action.kills || '-'}</InlineCondition> |
| 91 | + <InlineCondition title="冷却中"> |
| 92 | + {action.cooling || '-'} |
| 93 | + </InlineCondition> |
| 94 | + <InlineCondition title="费用">{action.costs || '-'}</InlineCondition> |
| 95 | + <InlineCondition title="费用变化"> |
| 96 | + {action.costChanges || '-'} |
| 97 | + </InlineCondition> |
| 98 | + <InlineCondition title="前置"> |
| 99 | + {action.preDelay ? formatDuration(action.preDelay) : '-'} |
| 100 | + </InlineCondition> |
| 101 | + <InlineCondition title="后置"> |
| 102 | + {action.rearDelay ? formatDuration(action.rearDelay) : '-'} |
| 103 | + </InlineCondition> |
| 104 | + </div> |
| 105 | + </Card> |
| 106 | + ) |
| 107 | +} |
| 108 | + |
| 109 | +const InlineCondition: FCC<{ |
| 110 | + title?: string |
| 111 | +}> = ({ title, children }) => ( |
| 112 | + <div className="min-w-[5em] text-lg leading-none"> |
| 113 | + <span className="text-zinc-500 mr-0.5 tabular-nums font-bold"> |
| 114 | + {children} |
| 115 | + </span> |
| 116 | + <span className="text-zinc-400 text-xs">{title}</span> |
| 117 | + </div> |
| 118 | +) |
0 commit comments