fix: 修复 BattleView 渲染 @pkmn/sim 原始 move 对象导致的 React 报错

projectPokemon 中 moveSlots 的 name 字段可能为 undefined,
导致整个对象被当作 React child 渲染。现在优先从 Dex 查询招式名称。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-22 08:37:03 +08:00
parent f22caf0e97
commit bfd14206a9

View File

@@ -95,14 +95,17 @@ function projectPokemon(pkm: any): BattlePokemon {
hp,
maxHp,
types: species.types?.map((t: string) => t.toLowerCase()) ?? [],
moves: (pkm.moveSlots ?? pkm.baseMoveset ?? []).filter(Boolean).map((m: any) => ({
id: toID(m.name ?? m),
name: m.name ?? m,
type: m.type ?? 'Normal',
pp: m.pp ?? 0,
maxPp: m.maxPp ?? m.pp ?? 0,
disabled: m.disabled ?? false,
})),
moves: (pkm.moveSlots ?? pkm.baseMoveset ?? []).filter(Boolean).map((m: any) => {
const moveName = typeof m === 'string' ? m : (m.name ?? m.move?.name ?? Dex.moves.get(m.id ?? m.move)?.name ?? String(m.id ?? '???'))
return {
id: toID(moveName),
name: moveName,
type: m.type ?? Dex.moves.get(m.id ?? toID(moveName))?.type?.toLowerCase() ?? 'normal',
pp: m.pp ?? 0,
maxPp: m.maxPp ?? m.pp ?? 0,
disabled: m.disabled ?? false,
}
}),
ability: pkm.ability ?? '',
heldItem: pkm.item ?? null,
status: mapStatus(pkm.status),