Files
claude-code/packages/pokemon/src/dex/nature.ts
claude-code-best f22caf0e97 feat: 集成 Battle tab 到 BuddyPanel,重命名 data/ 为 dex/ 规避 gitignore
- BuddyPanel 新增 Battle tab,BattleFlow 加 isActive 控制
- BattleFlow configSelect 阶段支持 ↑↓ 选择物种
- packages/pokemon/src/data/ → dex/,解决根 .gitignore 匹配问题
- 全量 Tab→2空格 缩进转换

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-22 08:35:19 +08:00

40 lines
1.4 KiB
TypeScript

import { Dex } from '@pkmn/sim'
import { FROM_DEX_STAT } from './pkmn'
import type { NatureName, NatureEffect, NatureStat } from '../types'
// All 25 canonical nature names (Dex.natures is not iterable, so we list them)
const NATURE_IDS: NatureName[] = [
'hardy', 'lonely', 'brave', 'adamant', 'naughty',
'bold', 'docile', 'relaxed', 'impish', 'lax',
'timid', 'hasty', 'serious', 'jolly', 'naive',
'modest', 'mild', 'quiet', 'bashful', 'rash',
'calm', 'gentle', 'sassy', 'careful', 'quirky',
]
/** Get all nature names */
export function getAllNatureNames(): NatureName[] {
return NATURE_IDS.filter(name => Dex.natures.get(name)?.exists)
}
/** Randomly assign a nature */
export function randomNature(): NatureName {
const names = getAllNatureNames()
return names[Math.floor(Math.random() * names.length)]!
}
/** Map Dex stat abbreviation (atk, spa, spe, etc.) to our NatureStat format */
function mapDexStat(stat: string | undefined): NatureStat | null {
if (!stat) return null
return (FROM_DEX_STAT[stat] as NatureStat) ?? null
}
/** Get nature effect (plus/minus stat, or null for neutral) — delegates to Dex.natures */
export function getNatureEffect(nature: NatureName): NatureEffect {
const n = Dex.natures.get(nature)
if (!n?.exists) return { plus: null, minus: null }
return {
plus: mapDexStat(n.plus),
minus: mapDexStat(n.minus),
}
}