151 lines
5.5 KiB
TypeScript
151 lines
5.5 KiB
TypeScript
import { Coins, Megaphone, RotateCcw, ShieldCheck, Sparkles, Tv, UserMinus, Users, type LucideIcon } from "lucide-react";
|
||
import { Avatar } from "../art/Avatar.tsx";
|
||
import { PARTY_RESOURCES, originBonusText, partyKind, type Background } from "@election2026/protocol";
|
||
import { partyColor } from "../parties.ts";
|
||
import type { Ability } from "../career/term/types.ts";
|
||
import { ABILITY_IDS, ABILITY_LABELS, MAX_LEVEL, toNext, type CareerState } from "./careerRules.ts";
|
||
|
||
/** 五項能力的圖示與顏色(和標題畫面選單同一組顏色) */
|
||
const ABILITY_LOOK: Record<Ability, { Icon: LucideIcon; color: string }> = {
|
||
eloquence: { Icon: Megaphone, color: "#d61f2c" },
|
||
organization: { Icon: Users, color: "#1f8a4c" },
|
||
media: { Icon: Tv, color: "#2f6fd1" },
|
||
finance: { Icon: Coins, color: "#c99400" },
|
||
integrity: { Icon: ShieldCheck, color: "#7a5cc4" },
|
||
};
|
||
|
||
/** 政黨色(tokens.css 的政黨槽位色;三大黨以外是灰色,見 parties.ts) */
|
||
export const partyTone = partyColor;
|
||
|
||
/**
|
||
* 角色卡(18 第 44、47 項):像遊戲的角色面板——頭像名牌、等級徽章、經驗條、技能點、五項能力。
|
||
* 有技能點時能力旁的+會亮;加過的點可以重新分配;最下面可以換人物(結束這段生涯)。
|
||
*/
|
||
export function CareerSheet({
|
||
career,
|
||
effects,
|
||
onPlus,
|
||
onReset,
|
||
onQuit,
|
||
}: {
|
||
career: CareerState;
|
||
effects: Map<string, string>;
|
||
onPlus: (a: Ability) => void;
|
||
onReset: () => void;
|
||
onQuit: () => void;
|
||
}) {
|
||
const need = toNext(career.level);
|
||
const spent = ABILITY_IDS.reduce((a, id) => a + career.abilities[id] - career.base[id], 0);
|
||
const c = career.character;
|
||
return (
|
||
<aside className="gs-panel cs" aria-label="角色">
|
||
<header className="cs-id" style={{ ["--party" as string]: partyTone(c.party) }}>
|
||
<div className="cs-portrait">
|
||
<Avatar spec={c.avatar} size={84} />
|
||
<span className="cs-lv" aria-label={`等級 ${career.level}`}>
|
||
<small>Lv</small>
|
||
<b>{career.level}</b>
|
||
</span>
|
||
</div>
|
||
<div className="cs-name">
|
||
<b>{c.name}</b>
|
||
<span className="cs-party">{c.party ?? "無黨籍"}</span>
|
||
<small>
|
||
{c.background}・家鄉{career.county.name}
|
||
</small>
|
||
</div>
|
||
</header>
|
||
|
||
<OriginPerks background={c.background} party={c.party} />
|
||
|
||
<div className="cs-xp" aria-label={`經驗 ${career.exp}/${need}`}>
|
||
<div className="cs-xp-bar">
|
||
<i style={{ transform: `scaleX(${Math.min(1, career.exp / need)})` }} />
|
||
</div>
|
||
<small>
|
||
<span>
|
||
Lv {career.level} → {career.level + 1}
|
||
</span>
|
||
<span>
|
||
經驗 <b>{career.exp}</b>/{need}
|
||
</span>
|
||
</small>
|
||
</div>
|
||
|
||
{career.skillPoints > 0 ? (
|
||
<p className="cs-sp">
|
||
<Sparkles size={18} aria-hidden />
|
||
<span>
|
||
<b>{career.skillPoints}</b> 個技能點可以加
|
||
</span>
|
||
<small>點能力旁邊的 +</small>
|
||
</p>
|
||
) : (
|
||
<p className="cs-sp is-idle">
|
||
<Sparkles size={16} aria-hidden /> 每升一級拿 1 個技能點
|
||
</p>
|
||
)}
|
||
|
||
<ul className="cs-abilities">
|
||
{ABILITY_IDS.map((id) => {
|
||
const lv = career.abilities[id];
|
||
const { Icon, color } = ABILITY_LOOK[id];
|
||
const can = career.skillPoints > 0 && lv < MAX_LEVEL;
|
||
return (
|
||
<li key={id} style={{ ["--ab" as string]: color }} title={effects.get(id)}>
|
||
<span className="cs-ab-ic" aria-hidden>
|
||
<Icon size={18} />
|
||
</span>
|
||
<div className="cs-ab-main">
|
||
<div className="cs-ab-top">
|
||
<b>{ABILITY_LABELS[id]}</b>
|
||
<span className="cs-bar" aria-label={`${lv}/${MAX_LEVEL} 級`}>
|
||
{Array.from({ length: MAX_LEVEL }, (_, i) => (
|
||
<i key={i} className={i < career.base[id] ? "is-base" : i < lv ? "is-on" : ""} />
|
||
))}
|
||
</span>
|
||
</div>
|
||
{effects.get(id) && <small>{effects.get(id)}</small>}
|
||
</div>
|
||
<button type="button" className={`cs-plus${can ? " is-hot" : ""}`} disabled={!can} onClick={() => onPlus(id)} aria-label={`${ABILITY_LABELS[id]}加一點`}>
|
||
+
|
||
</button>
|
||
</li>
|
||
);
|
||
})}
|
||
</ul>
|
||
|
||
<footer className="cs-foot">
|
||
{spent > 0 && (
|
||
<button type="button" className="cs-link" onClick={onReset}>
|
||
<RotateCcw size={15} aria-hidden /> 重新分配(退回 {spent} 點)
|
||
</button>
|
||
)}
|
||
<button type="button" className="cs-link is-quit" onClick={onQuit}>
|
||
<UserMinus size={15} aria-hidden /> 換人物(結束這段生涯)
|
||
</button>
|
||
</footer>
|
||
</aside>
|
||
);
|
||
}
|
||
|
||
/** 出身和黨的資源(不能自己點的加成,18 第 53 項):角色卡和捏人物都用這個 */
|
||
export function OriginPerks({ background, party }: { background: Background; party: string | null }) {
|
||
const res = PARTY_RESOURCES[partyKind(party)];
|
||
return (
|
||
<dl className="cs-perks">
|
||
<div>
|
||
<dt>出身・{background}</dt>
|
||
<dd>{originBonusText(background)}</dd>
|
||
</div>
|
||
<div>
|
||
<dt>黨的資源・{res.label}</dt>
|
||
<dd>
|
||
{res.perks.join("、")}
|
||
{res.costs.length > 0 && <span className="cs-cost">代價:{res.costs.join("、")}</span>}
|
||
</dd>
|
||
</div>
|
||
</dl>
|
||
);
|
||
}
|