- SpeciesId 从 10 项联合类型改为 string,动态从 @pkmn/sim Dex 加载 1025 只精灵 - getSpecies() 改用 Dex.species.get() 直接查找(gen wrapper 仅覆盖 733/1025) - SUPPLEMENT/DEX_TO_SPECIES 动态生成,未收录 species 使用默认值兜底 - names/fallback 改为 partial records,缺失时回退到 Dex 英文名/通用 sprite - 新增 SpeciesPicker 组件(基于 FuzzyPicker),支持中英文/编号搜索选择精灵 - BattleFlow configSelect 阶段替换为 SpeciesPicker,删除旧的上下翻页逻辑 - evolution 移除 ALL_SPECIES_IDS 限制,所有 Dex 物种均可进化 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { Dex } from '@pkmn/sim'
|
|
import { Generations } from '@pkmn/data'
|
|
import type { StatName } from '../types'
|
|
|
|
// Singleton Gen 9 data source
|
|
const gens = new Generations(Dex as unknown as import('@pkmn/data').Dex)
|
|
export const gen = gens.get(9)
|
|
|
|
// Stat name mapping: @pkmn/sim → our StatName
|
|
export const FROM_DEX_STAT: Record<string, StatName> = {
|
|
hp: 'hp', atk: 'attack', def: 'defense',
|
|
spa: 'spAtk', spd: 'spDef', spe: 'speed',
|
|
}
|
|
|
|
// Stat name mapping: our StatName → @pkmn/sim abbreviation
|
|
export const TO_DEX_STAT: Record<StatName, string> = {
|
|
hp: 'hp', attack: 'atk', defense: 'def',
|
|
spAtk: 'spa', spDef: 'spd', speed: 'spe',
|
|
}
|
|
|
|
/** Query species from Dex (uses Dex directly for full coverage) */
|
|
export function getSpecies(id: string) {
|
|
return Dex.species.get(id)
|
|
}
|
|
|
|
/** Map Dex baseStats to our StatName format */
|
|
export function mapBaseStats(dexStats: { hp: number; atk: number; def: number; spa: number; spd: number; spe: number }): Record<StatName, number> {
|
|
const result = {} as Record<StatName, number>
|
|
for (const [dexKey, ourKey] of Object.entries(FROM_DEX_STAT)) {
|
|
result[ourKey] = dexStats[dexKey as keyof typeof dexStats] ?? 0
|
|
}
|
|
return result
|
|
}
|
|
|
|
/** Get gender rate from Dex genderRatio (M/F ratio → our genderRate 0-8) */
|
|
export function mapGenderRatio(genderRatio?: { M: number; F: number } | string): number {
|
|
if (!genderRatio || typeof genderRatio === 'string') return -1 // genderless
|
|
return Math.round(genderRatio.F * 8)
|
|
}
|